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

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

Issue 2885483002: Expose WebThread rendering only when AudioWorklet flag is enabled (Closed)
Patch Set: Created 3 years, 7 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
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 39d569fd56ae9f8ab1156cca8e02ef89622fce06..35cee1312d161545c0c14f2c98c6537eaa723f46 100644
--- a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp
+++ b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp
@@ -31,6 +31,7 @@
#include <memory>
#include "platform/CrossThreadFunctional.h"
#include "platform/Histogram.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "platform/WebTaskRunner.h"
#include "platform/audio/AudioUtilities.h"
#include "platform/audio/PushPullFIFO.h"
@@ -76,7 +77,8 @@ AudioDestination::AudioDestination(AudioIOCallback& callback,
render_bus_(AudioBus::Create(number_of_output_channels,
AudioUtilities::kRenderQuantumFrames)),
callback_(callback),
- frames_elapsed_(0) {
+ frames_elapsed_(0),
+ is_audio_worklet_enabled(RuntimeEnabledFeatures::audioWorkletEnabled()) {
// Create WebAudioDevice. blink::WebAudioDevice is designed to support the
// local input (e.g. loopback from OS audio system), but Chromium's media
// renderer does not support it currently. Thus, we use zero for the number
@@ -90,6 +92,9 @@ AudioDestination::AudioDestination(AudioIOCallback& callback,
if (!CheckBufferSize()) {
NOTREACHED();
}
+
+ LOG(INFO) << "AudioDestination::IsAudioWorkletEnabled() = "
+ << IsAudioWorkletEnabled();
}
AudioDestination::~AudioDestination() {
@@ -104,8 +109,7 @@ void AudioDestination::Render(const WebVector<float*>& destination_data,
TRACE_EVENT1("webaudio", "AudioDestination::Render",
"callback_buffer_size", number_of_frames);
- // This method is called by AudioDeviceThread.
- DCHECK(!IsRenderingThread());
+ DCHECK(!IsMainThread());
CHECK_EQ(destination_data.size(), number_of_output_channels_);
CHECK_EQ(number_of_frames, callback_buffer_size_);
@@ -123,28 +127,32 @@ void AudioDestination::Render(const WebVector<float*>& destination_data,
size_t frames_to_render = fifo_->Pull(output_bus_.Get(), number_of_frames);
- // 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));
+ // If AudioWorklet is enabled, use dual thread rendering.
+ if (IsAudioWorkletEnabled()) {
+ // 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::RequestRender,
+ CrossThreadUnretained(this), number_of_frames,
+ frames_to_render, delay, delay_timestamp,
+ prior_frames_skipped));
+ }
+ } else {
+ RequestRender(number_of_frames, frames_to_render, delay, delay_timestamp,
+ prior_frames_skipped);
}
}
-void AudioDestination::RequestRenderOnWebThread(size_t frames_requested,
- size_t frames_to_render,
- double delay,
- double delay_timestamp,
- size_t prior_frames_skipped) {
- TRACE_EVENT1("webaudio", "AudioDestination::RequestRenderOnWebThread",
+void AudioDestination::RequestRender(size_t frames_requested,
+ size_t frames_to_render,
+ double delay,
+ double delay_timestamp,
+ size_t prior_frames_skipped) {
+ TRACE_EVENT1("webaudio", "AudioDestination::RequestRender",
"frames_to_render", frames_to_render);
- // This method is called by WebThread.
- DCHECK(IsRenderingThread());
-
frames_elapsed_ -= std::min(frames_elapsed_, prior_frames_skipped);
AudioIOPosition output_position;
output_position.position =
@@ -184,8 +192,12 @@ void AudioDestination::Start() {
// Start the "audio device" after the rendering thread is ready.
if (web_audio_device_ && !is_playing_) {
TRACE_EVENT0("webaudio", "AudioDestination::Start");
- rendering_thread_ =
- Platform::Current()->CreateThread("WebAudio Rendering Thread");
+
+ if (IsAudioWorkletEnabled()) {
+ rendering_thread_ =
+ Platform::Current()->CreateThread("WebAudio Rendering Thread");
+ }
+
web_audio_device_->Start();
is_playing_ = true;
}
@@ -199,7 +211,11 @@ void AudioDestination::Stop() {
if (web_audio_device_ && is_playing_) {
TRACE_EVENT0("webaudio", "AudioDestination::Stop");
web_audio_device_->Stop();
- rendering_thread_.reset();
+
+ if (IsAudioWorkletEnabled()) {
+ rendering_thread_.reset();
+ }
+
is_playing_ = false;
}
}
@@ -254,9 +270,4 @@ bool AudioDestination::CheckBufferSize() {
return is_buffer_size_valid;
}
-bool AudioDestination::IsRenderingThread() {
- return static_cast<ThreadIdentifier>(rendering_thread_->ThreadId()) ==
- CurrentThread();
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698