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

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

Issue 2854463002: Fix data race in AudioDestination.cpp (Closed)
Patch Set: 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
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..5565991515f91007a2f9bcb0d5fe7c8af30b4860 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(
new PushPullFIFO(number_of_output_channels, kFIFOSize))),
+ rendering_thread_(WTF::WrapUnique(
+ Platform::Current()->CreateThread("WebAudio Rendering Thread"))),
Raymond Toy 2017/04/28 19:53:56 Why change the order?
hongchan 2017/04/28 20:24:54 I rearranged the class member by the thread type.
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.
Raymond Toy 2017/04/28 19:53:56 Which checks are redundant? Both? Is it possible
hongchan 2017/04/28 20:24:54 Yes, theoretically it's possible when there is eno
nhiroki 2017/05/01 01:56:39 If |rendering_thread_| is nullptr here, DCHECK at
hongchan 2017/05/01 16:43:08 True, but it cannot be caught in the release build
nhiroki 2017/05/02 01:42:51 If it's valid to call Render() when |render_thread
+ 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,
@@ -179,8 +182,15 @@ void AudioDestination::Start() {
void AudioDestination::Stop() {
nhiroki 2017/05/01 01:56:39 ditto.
hongchan 2017/05/01 16:43:08 Done.
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();
Raymond Toy 2017/04/28 19:53:56 Is this synchronous? Are we guaranteed the thread
hongchan 2017/04/28 20:24:54 I believe so. FWIW, this is c++ unique_ptr's metho
nhiroki 2017/05/01 01:56:39 I'm not 100% sure but I think this is safe. Worker
hongchan 2017/05/01 16:43:07 Yes, that's my reference for this fix.
}
}

Powered by Google App Engine
This is Rietveld 408576698