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

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp

Issue 2929283002: Avoid AudioBufferSourceHandler data race. (Closed)
Patch Set: minimize lock taking Created 3 years, 6 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/modules/webaudio/AudioBufferSourceNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp b/third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp
index 569440ff33b49d2101d2b482dd801f090bc7ce86..054d9f92d3a362d178d3a2b467a636b003791433 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp
@@ -590,12 +590,20 @@ double AudioBufferSourceHandler::ComputePlaybackRate() {
if (!is_playback_rate_valid)
final_playback_rate = 1.0;
- // Record the minimum playback rate for use by handleStoppableSourceNode.
- min_playback_rate_ = std::min(final_playback_rate, min_playback_rate_);
+ // Record the minimum playback rate for use by HandleStoppableSourceNode.
+ if (final_playback_rate < min_playback_rate_) {
+ MutexLocker locker(min_playback_rate_mutex_);
+ min_playback_rate_ = final_playback_rate;
+ }
return final_playback_rate;
}
+double AudioBufferSourceHandler::MinPlaybackRate() {
hongchan 2017/06/12 14:09:17 I think we prefer Get...() as a getter name.
sof 2017/06/12 14:51:57 Done (a naming outlier for this class.)
+ MutexLocker locker(min_playback_rate_mutex_);
hongchan 2017/06/12 14:09:17 Can we have DCHECK(isMainThread()) here?
sof 2017/06/12 14:51:57 Done.
+ return min_playback_rate_;
+}
+
bool AudioBufferSourceHandler::PropagatesSilence() const {
return !IsPlayingOrScheduled() || HasFinished() || !buffer_;
}
@@ -611,12 +619,13 @@ void AudioBufferSourceHandler::HandleStoppableSourceNode() {
// If looping was ever done (m_didSetLooping = true), give up. We can't
// easily determine how long we looped so we don't know the actual duration
// thus far, so don't try to do anything fancy.
+ double min_playback_rate = MinPlaybackRate();
if (!DidSetLooping() && Buffer() && IsPlayingOrScheduled() &&
- min_playback_rate_ > 0) {
+ min_playback_rate > 0) {
// Adjust the duration to include the playback rate. Only need to account
// for rate < 1 which makes the sound last longer. For rate >= 1, the
// source stops sooner, but that's ok.
- double actual_duration = Buffer()->duration() / min_playback_rate_;
+ double actual_duration = Buffer()->duration() / min_playback_rate;
double stop_time = start_time_ + actual_duration;

Powered by Google App Engine
This is Rietveld 408576698