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

Unified Diff: media/base/audio_renderer_mixer_input.h

Issue 1748183006: Add lock to fix race in AudioRendererMixerInput. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better thread safety comments Created 4 years, 9 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 | « no previous file | media/base/audio_renderer_mixer_input.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_renderer_mixer_input.h
diff --git a/media/base/audio_renderer_mixer_input.h b/media/base/audio_renderer_mixer_input.h
index 34f37c5ee00a3c0d0803ef4f807992942bbf8401..9d91b1481892afc8d734f4f271989ffa7baf860f 100644
--- a/media/base/audio_renderer_mixer_input.h
+++ b/media/base/audio_renderer_mixer_input.h
@@ -1,6 +1,17 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+//
+// THREAD SAFETY
+//
+// This class is generally not thread safe. Callers should ensure thread safety.
+// For instance, the |sink_lock_| in WebAudioSourceProvider synchronizes access
+// to this object across the main thread (for WebAudio APIs) and the
+// media thread (for HTMLMediaElement APIs).
+//
+// The one exception is protection for |volume_| via |volume_lock_|. This lock
+// prevents races between SetVolume() (called on any thread) and ProvideInput
+// (called on audio device thread). See http://crbug.com/588992.
#ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
#define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
@@ -9,6 +20,7 @@
#include "base/callback.h"
#include "base/macros.h"
+#include "base/synchronization/lock.h"
#include "media/base/audio_converter.h"
#include "media/base/audio_renderer_sink.h"
#include "media/base/output_device.h"
@@ -69,6 +81,10 @@ class MEDIA_EXPORT AudioRendererMixerInput
private:
friend class AudioRendererMixerInputTest;
+ // Protect |volume_|, accessed by separate threads in ProvideInput() and
+ // SetVolume().
+ base::Lock volume_lock_;
+
bool started_;
bool playing_;
double volume_;
« no previous file with comments | « no previous file | media/base/audio_renderer_mixer_input.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698