OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/blink/webaudiosourceprovider_impl.h" | 5 #include "media/blink/webaudiosourceprovider_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 }; | 46 }; |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl( | 50 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl( |
51 const scoped_refptr<RestartableAudioRendererSink>& sink) | 51 const scoped_refptr<RestartableAudioRendererSink>& sink) |
52 : channels_(0), | 52 : channels_(0), |
53 sample_rate_(0), | 53 sample_rate_(0), |
54 volume_(1.0), | 54 volume_(1.0), |
55 state_(kStopped), | 55 state_(kStopped), |
56 renderer_(NULL), | 56 renderer_(nullptr), |
57 client_(NULL), | 57 client_(nullptr), |
58 sink_(sink), | 58 sink_(sink), |
59 weak_factory_(this) {} | 59 weak_factory_(this) {} |
60 | 60 |
61 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() { | 61 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() { |
62 } | 62 } |
63 | 63 |
64 void WebAudioSourceProviderImpl::setClient( | 64 void WebAudioSourceProviderImpl::setClient( |
65 blink::WebAudioSourceProviderClient* client) { | 65 blink::WebAudioSourceProviderClient* client) { |
66 base::AutoLock auto_lock(sink_lock_); | 66 base::AutoLock auto_lock(sink_lock_); |
67 if (client && client != client_) { | 67 if (client && client != client_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 if (!auto_try_lock.locked() || state_ != kPlaying) { | 108 if (!auto_try_lock.locked() || state_ != kPlaying) { |
109 // Provide silence if we failed to acquire the lock or the source is not | 109 // Provide silence if we failed to acquire the lock or the source is not |
110 // running. | 110 // running. |
111 bus_wrapper_->Zero(); | 111 bus_wrapper_->Zero(); |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 DCHECK(renderer_); | 115 DCHECK(renderer_); |
116 DCHECK(client_); | 116 DCHECK(client_); |
117 DCHECK_EQ(channels_, bus_wrapper_->channels()); | 117 DCHECK_EQ(channels_, bus_wrapper_->channels()); |
118 const int frames = renderer_->Render(bus_wrapper_.get(), 0, 0); | 118 const int frames = renderer_->Render(bus_wrapper_.get(), 0, 0); |
DaleCurtis
2016/03/11 01:41:42
What do you expect to happen in this case?
mcasas
2016/03/11 04:06:23
Done.
| |
119 if (frames < static_cast<int>(number_of_frames)) { | 119 if (frames < static_cast<int>(number_of_frames)) { |
120 bus_wrapper_->ZeroFramesPartial( | 120 bus_wrapper_->ZeroFramesPartial( |
121 frames, | 121 frames, |
122 static_cast<int>(number_of_frames - frames)); | 122 static_cast<int>(number_of_frames - frames)); |
123 } | 123 } |
124 | 124 |
125 bus_wrapper_->Scale(volume_); | 125 bus_wrapper_->Scale(volume_); |
126 } | 126 } |
127 | 127 |
128 void WebAudioSourceProviderImpl::Start() { | 128 void WebAudioSourceProviderImpl::Start() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 OutputDevice* WebAudioSourceProviderImpl::GetOutputDevice() { | 168 OutputDevice* WebAudioSourceProviderImpl::GetOutputDevice() { |
169 base::AutoLock auto_lock(sink_lock_); | 169 base::AutoLock auto_lock(sink_lock_); |
170 return sink_->GetOutputDevice(); | 170 return sink_->GetOutputDevice(); |
171 } | 171 } |
172 | 172 |
173 void WebAudioSourceProviderImpl::Initialize( | 173 void WebAudioSourceProviderImpl::Initialize( |
174 const AudioParameters& params, | 174 const AudioParameters& params, |
175 RenderCallback* renderer) { | 175 AudioRendererSink::RenderCallback* renderer) { |
176 base::AutoLock auto_lock(sink_lock_); | 176 base::AutoLock auto_lock(sink_lock_); |
177 | |
177 renderer_ = renderer; | 178 renderer_ = renderer; |
178 | 179 |
179 DCHECK_EQ(state_, kStopped); | 180 DCHECK_EQ(state_, kStopped); |
180 sink_->Initialize(params, renderer); | 181 sink_->Initialize(params, this); // We act as forwarder to |renderer_|. |
181 | 182 |
182 // Keep track of the format in case the client hasn't yet been set. | 183 // Keep track of the format in case the client hasn't yet been set. |
183 channels_ = params.channels(); | 184 channels_ = params.channels(); |
184 sample_rate_ = params.sample_rate(); | 185 sample_rate_ = params.sample_rate(); |
185 | 186 |
186 if (!set_format_cb_.is_null()) | 187 if (!set_format_cb_.is_null()) |
187 base::ResetAndReturn(&set_format_cb_).Run(); | 188 base::ResetAndReturn(&set_format_cb_).Run(); |
188 } | 189 } |
189 | 190 |
191 int WebAudioSourceProviderImpl::Render(AudioBus* audio_bus, | |
192 uint32_t delay_milliseconds, | |
193 uint32_t frames_skipped) { | |
194 DCHECK(renderer_); | |
195 DCHECK(!frames_skipped); | |
DaleCurtis
2016/03/11 01:41:42
Is this reasonable?
mcasas
2016/03/11 04:06:23
Prob remainder of some test. Removed.
| |
196 | |
197 const int num_rendered_frames = | |
198 renderer_->Render(audio_bus, delay_milliseconds, frames_skipped); | |
199 | |
200 if (!onaudiobus_callback_.is_null()) { | |
201 scoped_ptr<AudioBus> bus_copy = | |
202 AudioBus::Create(audio_bus->channels(), audio_bus->frames()); | |
203 audio_bus->CopyTo(bus_copy.get()); | |
204 onaudiobus_callback_.Run(std::move(bus_copy), delay_milliseconds); | |
205 } | |
206 | |
207 return num_rendered_frames; | |
208 } | |
209 | |
210 void WebAudioSourceProviderImpl::OnRenderError() { | |
211 DCHECK(renderer_); | |
212 renderer_->OnRenderError(); | |
213 } | |
214 | |
215 void WebAudioSourceProviderImpl::RegisterOnAudioBusCallback( | |
216 const OnAudioBusCB& callback) { | |
217 DCHECK(!callback.is_null()); | |
218 DCHECK(onaudiobus_callback_.is_null()); | |
219 onaudiobus_callback_ = callback; | |
220 } | |
221 | |
222 void WebAudioSourceProviderImpl::ResetOnAudioBusCallback() { | |
223 DCHECK(!onaudiobus_callback_.is_null()); | |
224 onaudiobus_callback_.Reset(); | |
225 } | |
226 | |
190 void WebAudioSourceProviderImpl::OnSetFormat() { | 227 void WebAudioSourceProviderImpl::OnSetFormat() { |
191 base::AutoLock auto_lock(sink_lock_); | 228 base::AutoLock auto_lock(sink_lock_); |
192 if (!client_) | 229 if (!client_) |
193 return; | 230 return; |
194 | 231 |
195 // Inform Blink about the audio stream format. | 232 // Inform Blink about the audio stream format. |
196 client_->setFormat(channels_, sample_rate_); | 233 client_->setFormat(channels_, sample_rate_); |
197 } | 234 } |
198 | 235 |
199 } // namespace media | 236 } // namespace media |
OLD | NEW |