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

Unified Diff: third_party/WebKit/Source/platform/audio/PushPullFIFO.h

Issue 2777903005: Add WebThread in AudioDestination to support AudioWorkletThread (Closed)
Patch Set: Addressing feedback Created 3 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
Index: third_party/WebKit/Source/platform/audio/PushPullFIFO.h
diff --git a/third_party/WebKit/Source/platform/audio/PushPullFIFO.h b/third_party/WebKit/Source/platform/audio/PushPullFIFO.h
index 2341372f35ab452fb8814dc22208ff3c24e9cd87..ca8f96d0c8a8e7a5eb6fb7232f58935925b22bf4 100644
--- a/third_party/WebKit/Source/platform/audio/PushPullFIFO.h
+++ b/third_party/WebKit/Source/platform/audio/PushPullFIFO.h
@@ -8,6 +8,7 @@
#include "platform/audio/AudioBus.h"
#include "public/platform/WebCommon.h"
#include "wtf/Allocator.h"
+#include "wtf/ThreadingPrimitives.h"
namespace blink {
@@ -26,6 +27,14 @@ struct PushPullFIFOStateForTest {
// Blink-WebAudio and the renderer. The renderer's hardware callback buffer size
// varies on the platform, but the WebAudio always renders 128 frames (render
// quantum, RQ) thus FIFO is needed to handle the general case.
+//
+// Note that this object is concurrently accessed by two threads; WebAudio
+// rendering thread (WebThread) in Blink and the audio device thread
+// (AudioDeviceThread) from the media renderer. The push/pull operations touch
+// most of variables in the class (m_indexWrite, m_indexRead, m_framesAvailable,
+// and m_fifoBus) so the thread safety must be handled with care.
+//
+// TODO(hongchan): add a unit test for multi-thread access.
class BLINK_PLATFORM_EXPORT PushPullFIFO {
USING_FAST_MALLOC(PushPullFIFO);
WTF_MAKE_NONCOPYABLE(PushPullFIFO);
@@ -38,7 +47,7 @@ class BLINK_PLATFORM_EXPORT PushPullFIFO {
explicit PushPullFIFO(unsigned numberOfChannels, size_t fifoLength);
~PushPullFIFO();
- // Pushes the rendered frames by WebAudio engine.
+ // Pushes the rendered frames by WebAudio rendering thread.
// - The |inputBus| length is 128 frames (1 render quantum), fixed.
// - In case of overflow (FIFO full while push), the existing frames in FIFO
// will be overwritten and |indexRead| will be forcibly moved to
@@ -55,16 +64,20 @@ class BLINK_PLATFORM_EXPORT PushPullFIFO {
// the request from the consumer without causing error, but with a glitch.
void pull(AudioBus* outputBus, size_t framesRequested);
- size_t framesAvailable() const { return m_framesAvailable; }
+ size_t framesAvailable() const;
size_t length() const { return m_fifoLength; }
unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); }
- AudioBus* bus() const { return m_fifoBus.get(); }
+ AudioBus* getFIFOBusForTest() const;
// For unit test. Get the current configuration that consists of FIFO length,
// number of channels, read/write index position and under/overflow count.
const PushPullFIFOStateForTest getStateForTest() const;
private:
+ // This lock protects all members in this class from being accessed by two
o1ka 2017/03/30 13:17:05 This is technically not quite correct: see length(
hongchan 2017/03/30 18:36:00 Done.
+ // threads simultaneously.
+ mutable Mutex m_threadMutex;
o1ka 2017/03/30 13:17:05 I'm not sure if this rename is useful.
hongchan 2017/03/30 18:36:00 Done.
+
// The size of the FIFO.
const size_t m_fifoLength = 0;

Powered by Google App Engine
This is Rietveld 408576698