Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: content/renderer/media/render_audiosourceprovider.cc

Issue 9655018: Make AudioParameters a class instead of a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright years Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/render_audiosourceprovider.h" 5 #include "content/renderer/media/render_audiosourceprovider.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide rClient.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide rClient.h"
10 10
11 using std::vector; 11 using std::vector;
12 using WebKit::WebVector; 12 using WebKit::WebVector;
13 13
14 RenderAudioSourceProvider::RenderAudioSourceProvider() 14 RenderAudioSourceProvider::RenderAudioSourceProvider()
15 : is_initialized_(false), 15 : is_initialized_(false),
16 channels_(0), 16 channels_(0),
17 sample_rate_(0.0), 17 sample_rate_(0),
18 is_running_(false), 18 is_running_(false),
19 volume_(1.0), 19 volume_(1.0),
20 renderer_(NULL), 20 renderer_(NULL),
21 client_(NULL) { 21 client_(NULL) {
22 // We create the AudioDevice here because it must be created in the 22 // We create the AudioDevice here because it must be created in the
23 // main thread. But we don't yet know the audio format (sample-rate, etc.) 23 // main thread. But we don't yet know the audio format (sample-rate, etc.)
24 // at this point. Later, when Initialize() is called, we have 24 // at this point. Later, when Initialize() is called, we have
25 // the audio format information and call the AudioDevice::Initialize() 25 // the audio format information and call the AudioDevice::Initialize()
26 // method to fully initialize it. 26 // method to fully initialize it.
27 default_sink_ = new AudioDevice(); 27 default_sink_ = new AudioDevice();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 void RenderAudioSourceProvider::GetVolume(double* volume) { 68 void RenderAudioSourceProvider::GetVolume(double* volume) {
69 if (!client_) 69 if (!client_)
70 default_sink_->GetVolume(volume); 70 default_sink_->GetVolume(volume);
71 else if (volume) 71 else if (volume)
72 *volume = volume_; 72 *volume = volume_;
73 } 73 }
74 74
75 void RenderAudioSourceProvider::Initialize( 75 void RenderAudioSourceProvider::Initialize(
76 size_t buffer_size, 76 const AudioParameters& params, RenderCallback* renderer) {
77 int channels,
78 double sample_rate,
79 AudioParameters::Format latency_format,
80 RenderCallback* renderer) {
81 base::AutoLock auto_lock(sink_lock_); 77 base::AutoLock auto_lock(sink_lock_);
82 CHECK(!is_initialized_); 78 CHECK(!is_initialized_);
83 renderer_ = renderer; 79 renderer_ = renderer;
84 80
85 default_sink_->Initialize(buffer_size, 81 default_sink_->Initialize(params, renderer);
86 channels, 82
87 sample_rate, 83 // Keep track of the format in case the client hasn't yet been set.
88 latency_format, 84 channels_ = params.channels();
89 renderer); 85 sample_rate_ = params.sample_rate();
90 86
91 if (client_) { 87 if (client_) {
92 // Inform WebKit about the audio stream format. 88 // Inform WebKit about the audio stream format.
93 client_->setFormat(channels, sample_rate); 89 client_->setFormat(channels_, sample_rate_);
94 } 90 }
95 91
96 // Keep track of the format in case the client hasn't yet been set.
97 channels_ = channels;
98 sample_rate_ = sample_rate;
99 is_initialized_ = true; 92 is_initialized_ = true;
100 } 93 }
101 94
102 void RenderAudioSourceProvider::setClient( 95 void RenderAudioSourceProvider::setClient(
103 WebKit::WebAudioSourceProviderClient* client) { 96 WebKit::WebAudioSourceProviderClient* client) {
104 // Synchronize with other uses of client_ and default_sink_. 97 // Synchronize with other uses of client_ and default_sink_.
105 base::AutoLock auto_lock(sink_lock_); 98 base::AutoLock auto_lock(sink_lock_);
106 99
107 if (client && client != client_) { 100 if (client && client != client_) {
108 // Detach the audio renderer from normal playback. 101 // Detach the audio renderer from normal playback.
(...skipping 30 matching lines...) Expand all
139 132
140 // TODO(crogers): figure out if we should volume scale here or in common 133 // TODO(crogers): figure out if we should volume scale here or in common
141 // WebAudio code. In any case we need to take care of volume. 134 // WebAudio code. In any case we need to take care of volume.
142 renderer_->Render(v, number_of_frames, 0); 135 renderer_->Render(v, number_of_frames, 0);
143 } else { 136 } else {
144 // Provide silence if the source is not running. 137 // Provide silence if the source is not running.
145 for (size_t i = 0; i < audio_data.size(); ++i) 138 for (size_t i = 0; i < audio_data.size(); ++i)
146 memset(audio_data[i], 0, sizeof(float) * number_of_frames); 139 memset(audio_data[i], 0, sizeof(float) * number_of_frames);
147 } 140 }
148 } 141 }
OLDNEW
« no previous file with comments | « content/renderer/media/render_audiosourceprovider.h ('k') | content/renderer/media/renderer_webaudiodevice_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698