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

Unified Diff: third_party/WebKit/Source/platform/audio/AudioDestination.cpp

Issue 2853923002: Improve thread creation in plaform/audio/AudioDestination (Closed)
Patch Set: Addressing feedback Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioDestination.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioDestination.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698