| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 DCHECK(client_); | 157 DCHECK(client_); |
| 158 DCHECK_EQ(tee_filter_->channels(), bus_wrapper_->channels()); | 158 DCHECK_EQ(tee_filter_->channels(), bus_wrapper_->channels()); |
| 159 const int frames = tee_filter_->Render(bus_wrapper_.get(), 0, 0); | 159 const int frames = tee_filter_->Render(bus_wrapper_.get(), 0, 0); |
| 160 if (frames < incoming_number_of_frames) | 160 if (frames < incoming_number_of_frames) |
| 161 bus_wrapper_->ZeroFramesPartial(frames, incoming_number_of_frames - frames); | 161 bus_wrapper_->ZeroFramesPartial(frames, incoming_number_of_frames - frames); |
| 162 | 162 |
| 163 bus_wrapper_->Scale(volume_); | 163 bus_wrapper_->Scale(volume_); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void WebAudioSourceProviderImpl::Initialize(const AudioParameters& params, |
| 167 RenderCallback* renderer) { |
| 168 base::AutoLock auto_lock(sink_lock_); |
| 169 DCHECK_EQ(state_, kStopped); |
| 170 |
| 171 tee_filter_->Initialize(renderer, params.channels(), params.sample_rate()); |
| 172 |
| 173 sink_->Initialize(params, tee_filter_.get()); |
| 174 |
| 175 if (!set_format_cb_.is_null()) |
| 176 base::ResetAndReturn(&set_format_cb_).Run(); |
| 177 } |
| 178 |
| 166 void WebAudioSourceProviderImpl::Start() { | 179 void WebAudioSourceProviderImpl::Start() { |
| 167 base::AutoLock auto_lock(sink_lock_); | 180 base::AutoLock auto_lock(sink_lock_); |
| 168 DCHECK(tee_filter_); | 181 DCHECK(tee_filter_); |
| 169 DCHECK_EQ(state_, kStopped); | 182 DCHECK_EQ(state_, kStopped); |
| 170 state_ = kStarted; | 183 state_ = kStarted; |
| 171 if (!client_) | 184 if (!client_) |
| 172 sink_->Start(); | 185 sink_->Start(); |
| 173 } | 186 } |
| 174 | 187 |
| 175 void WebAudioSourceProviderImpl::Stop() { | 188 void WebAudioSourceProviderImpl::Stop() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 201 if (!client_) | 214 if (!client_) |
| 202 sink_->SetVolume(volume); | 215 sink_->SetVolume(volume); |
| 203 return true; | 216 return true; |
| 204 } | 217 } |
| 205 | 218 |
| 206 media::OutputDeviceInfo WebAudioSourceProviderImpl::GetOutputDeviceInfo() { | 219 media::OutputDeviceInfo WebAudioSourceProviderImpl::GetOutputDeviceInfo() { |
| 207 base::AutoLock auto_lock(sink_lock_); | 220 base::AutoLock auto_lock(sink_lock_); |
| 208 return sink_->GetOutputDeviceInfo(); | 221 return sink_->GetOutputDeviceInfo(); |
| 209 } | 222 } |
| 210 | 223 |
| 224 bool WebAudioSourceProviderImpl::CurrentThreadIsRenderingThread() { |
| 225 NOTIMPLEMENTED(); |
| 226 return false; |
| 227 } |
| 228 |
| 211 void WebAudioSourceProviderImpl::SwitchOutputDevice( | 229 void WebAudioSourceProviderImpl::SwitchOutputDevice( |
| 212 const std::string& device_id, | 230 const std::string& device_id, |
| 213 const url::Origin& security_origin, | 231 const url::Origin& security_origin, |
| 214 const OutputDeviceStatusCB& callback) { | 232 const OutputDeviceStatusCB& callback) { |
| 215 base::AutoLock auto_lock(sink_lock_); | 233 base::AutoLock auto_lock(sink_lock_); |
| 216 if (client_) | 234 if (client_) |
| 217 callback.Run(media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); | 235 callback.Run(media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); |
| 218 else | 236 else |
| 219 sink_->SwitchOutputDevice(device_id, security_origin, callback); | 237 sink_->SwitchOutputDevice(device_id, security_origin, callback); |
| 220 } | 238 } |
| 221 | 239 |
| 222 void WebAudioSourceProviderImpl::Initialize(const AudioParameters& params, | |
| 223 RenderCallback* renderer) { | |
| 224 base::AutoLock auto_lock(sink_lock_); | |
| 225 DCHECK_EQ(state_, kStopped); | |
| 226 | |
| 227 tee_filter_->Initialize(renderer, params.channels(), params.sample_rate()); | |
| 228 | |
| 229 sink_->Initialize(params, tee_filter_.get()); | |
| 230 | |
| 231 if (!set_format_cb_.is_null()) | |
| 232 base::ResetAndReturn(&set_format_cb_).Run(); | |
| 233 } | |
| 234 | |
| 235 void WebAudioSourceProviderImpl::SetCopyAudioCallback( | 240 void WebAudioSourceProviderImpl::SetCopyAudioCallback( |
| 236 const CopyAudioCB& callback) { | 241 const CopyAudioCB& callback) { |
| 237 DCHECK(!callback.is_null()); | 242 DCHECK(!callback.is_null()); |
| 238 | 243 |
| 239 // Use |sink_lock_| to protect |tee_filter_| too since they go in lockstep. | 244 // Use |sink_lock_| to protect |tee_filter_| too since they go in lockstep. |
| 240 base::AutoLock auto_lock(sink_lock_); | 245 base::AutoLock auto_lock(sink_lock_); |
| 241 | 246 |
| 242 DCHECK(tee_filter_); | 247 DCHECK(tee_filter_); |
| 243 tee_filter_->set_copy_audio_bus_callback(callback); | 248 tee_filter_->set_copy_audio_bus_callback(callback); |
| 244 } | 249 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 284 |
| 280 return num_rendered_frames; | 285 return num_rendered_frames; |
| 281 } | 286 } |
| 282 | 287 |
| 283 void WebAudioSourceProviderImpl::TeeFilter::OnRenderError() { | 288 void WebAudioSourceProviderImpl::TeeFilter::OnRenderError() { |
| 284 DCHECK(IsInitialized()); | 289 DCHECK(IsInitialized()); |
| 285 renderer_->OnRenderError(); | 290 renderer_->OnRenderError(); |
| 286 } | 291 } |
| 287 | 292 |
| 288 } // namespace media | 293 } // namespace media |
| OLD | NEW |