Chromium Code Reviews| Index: third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| diff --git a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| index e71d5ec1d0382f3196048e39545da9686cd543b4..7044f6cc9b522a46c5f1b23b355c1cdd7a893527 100644 |
| --- a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| +++ b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| @@ -67,10 +67,10 @@ AudioDestination::AudioDestination(AudioIOCallback& callback, |
| PassRefPtr<SecurityOrigin> security_origin) |
| : number_of_output_channels_(number_of_output_channels), |
| is_playing_(false), |
| - rendering_thread_(WTF::WrapUnique( |
| - Platform::Current()->CreateThread("WebAudio Rendering Thread"))), |
| fifo_(WTF::WrapUnique( |
|
nhiroki
2017/05/02 01:42:51
MakeUnique?
|
| new PushPullFIFO(number_of_output_channels, kFIFOSize))), |
| + rendering_thread_(WTF::WrapUnique( |
| + Platform::Current()->CreateThread("WebAudio Rendering Thread"))), |
| output_bus_(AudioBus::Create(number_of_output_channels, |
| AudioUtilities::kRenderQuantumFrames, |
| false)), |
| @@ -121,12 +121,15 @@ void AudioDestination::Render(const WebVector<float*>& destination_data, |
| size_t frames_to_render = fifo_->Pull(output_bus_.Get(), number_of_frames); |
| - rendering_thread_->GetWebTaskRunner()->PostTask( |
| - BLINK_FROM_HERE, |
| - CrossThreadBind(&AudioDestination::RequestRenderOnWebThread, |
| - CrossThreadUnretained(this), |
| - number_of_frames, frames_to_render, |
| - delay, delay_timestamp, prior_frames_skipped)); |
| + // TODO(hongchan): this check might be redundant, so consider removing later. |
| + if (frames_to_render != 0 && rendering_thread_) { |
| + rendering_thread_->GetWebTaskRunner()->PostTask( |
| + BLINK_FROM_HERE, |
| + CrossThreadBind(&AudioDestination::RequestRenderOnWebThread, |
| + CrossThreadUnretained(this), number_of_frames, |
| + frames_to_render, delay, delay_timestamp, |
| + prior_frames_skipped)); |
| + } |
| } |
| void AudioDestination::RequestRenderOnWebThread(size_t frames_requested, |
| @@ -171,6 +174,7 @@ void AudioDestination::RequestRenderOnWebThread(size_t frames_requested, |
| } |
| void AudioDestination::Start() { |
| + DCHECK(WTF::IsMainThread()); |
| if (web_audio_device_ && !is_playing_) { |
| web_audio_device_->Start(); |
| is_playing_ = true; |
| @@ -178,12 +182,35 @@ void AudioDestination::Start() { |
| } |
| void AudioDestination::Stop() { |
| + DCHECK(WTF::IsMainThread()); |
| if (web_audio_device_ && is_playing_) { |
| + // This stops the callback from the device thread synchronously. |
| web_audio_device_->Stop(); |
| + |
| is_playing_ = false; |
| + |
| + // Disable the WebAudio rendering thread. This is safe because the device |
| + // thread is stopped at this point and |rendering_thread_| will not be |
| + // accessed by it anymore. |
| + rendering_thread_.reset(); |
| } |
| } |
| +size_t AudioDestination::CallbackBufferSize() const { |
| + DCHECK(WTF::IsMainThread()); |
| + return callback_buffer_size_; |
| +} |
| + |
| +bool AudioDestination::IsPlaying() { |
| + DCHECK(WTF::IsMainThread()); |
| + return is_playing_; |
| +} |
| + |
| +int AudioDestination::FramesPerBuffer() const { |
| + DCHECK(WTF::IsMainThread()); |
| + return web_audio_device_->FramesPerBuffer(); |
| +} |
| + |
| size_t AudioDestination::HardwareBufferSize() { |
| return Platform::Current()->AudioHardwareBufferSize(); |
| } |