| 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..a7966e69d3bdfb66e3d044289b27f23d0347f2a8 100644
|
| --- a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp
|
| +++ b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp
|
| @@ -67,8 +67,6 @@ 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(
|
| new PushPullFIFO(number_of_output_channels, kFIFOSize))),
|
| output_bus_(AudioBus::Create(number_of_output_channels,
|
| @@ -121,12 +119,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,19 +172,44 @@ void AudioDestination::RequestRenderOnWebThread(size_t frames_requested,
|
| }
|
|
|
| void AudioDestination::Start() {
|
| + DCHECK(IsMainThread());
|
| +
|
| + // Start the "audio device" after the rendering thread is ready.
|
| if (web_audio_device_ && !is_playing_) {
|
| + rendering_thread_ = WTF::WrapUnique(
|
| + Platform::Current()->CreateThread("WebAudio Rendering Thread"));
|
| web_audio_device_->Start();
|
| is_playing_ = true;
|
| }
|
| }
|
|
|
| void AudioDestination::Stop() {
|
| + DCHECK(IsMainThread());
|
| +
|
| + // This assumes stopping the "audio device" is synchronous and dumping the
|
| + // rendering thread is safe after that.
|
| if (web_audio_device_ && is_playing_) {
|
| web_audio_device_->Stop();
|
| + rendering_thread_.reset();
|
| is_playing_ = false;
|
| }
|
| }
|
|
|
| +size_t AudioDestination::CallbackBufferSize() const {
|
| + DCHECK(IsMainThread());
|
| + return callback_buffer_size_;
|
| +}
|
| +
|
| +bool AudioDestination::IsPlaying() {
|
| + DCHECK(IsMainThread());
|
| + return is_playing_;
|
| +}
|
| +
|
| +int AudioDestination::FramesPerBuffer() const {
|
| + DCHECK(IsMainThread());
|
| + return web_audio_device_->FramesPerBuffer();
|
| +}
|
| +
|
| size_t AudioDestination::HardwareBufferSize() {
|
| return Platform::Current()->AudioHardwareBufferSize();
|
| }
|
|
|