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

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

Issue 2549093009: Introduce PushPullFIFO class and remove other FIFOs (Closed)
Patch Set: More comments Created 3 years, 11 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
new file mode 100644
index 0000000000000000000000000000000000000000..dd930015a046a796e9dd90c7161e59dfbff9cbc3
--- /dev/null
+++ b/third_party/WebKit/Source/platform/audio/PushPullFIFO.h
@@ -0,0 +1,61 @@
+// Copyright 2016 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.
+
+#ifndef PushPullFIFO_h
+#define PushPullFIFO_h
+
+#include "platform/audio/AudioBus.h"
+#include "public/platform/WebCommon.h"
+#include "wtf/Allocator.h"
+
+namespace blink {
+
+// PushPullFIFO class is an intermediate audio sample storage between
+// Blink-WebAudio and the renderer. The renderer's hardware callback buffer size
+// varies on the platform, but the WebAudio always operates by 128 frames of
+// render quantum; thus FIFO is needed.
+class BLINK_PLATFORM_EXPORT PushPullFIFO {
+ USING_FAST_MALLOC(PushPullFIFO);
+ WTF_MAKE_NONCOPYABLE(PushPullFIFO);
+
+ public:
+ PushPullFIFO(unsigned numberOfChannels, size_t fifoLength);
+ ~PushPullFIFO();
+
+ // Pushing audio data is done by the WebAudio render-backing thread. The
o1ka 2017/01/24 11:09:02 Do you plan to first finalize all the index calcul
hongchan 2017/01/26 22:33:18 Yes. That's the plan. The FIFO in this CL should
+ // priority of this thread is lower than the actual audio device thread,
+ // thus the thread can be blocked when the audio device thread is pulling
+ // data from the FIFO.
+ void push(const AudioBus* inputBus);
+
+ // Pulling audio data is done by the audio device thread. In the case of
+ // underflow, the rest will be filled up with zeros (thus glitches). Pulling
+ // an empty FIFO is a valid operation, and the consumer will get a block of
+ // silence.
+ void pull(AudioBus* outputBus, size_t framesRequested);
+
+ int framesAvailable() const { return m_framesAvailable; }
+ int length() const { return m_fifoLength; }
+ unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); }
+ AudioBus* bus() { return m_fifoBus.get(); }
+
+ private:
+ RefPtr<AudioBus> m_fifoBus;
+
+ // The size of the FIFO.
+ const int m_fifoLength;
o1ka 2017/01/24 11:09:02 You can use "= 0" initialization here.
hongchan 2017/01/26 22:33:18 Done.
+
+ // The number of frames in the FIFO actually available for pulling.
+ int m_framesAvailable;
+
+ int m_indexRead;
+ int m_indexWrite;
+
+ unsigned m_overflowCount;
o1ka 2017/01/24 11:09:02 We should not use a mix of size_t, int and unsigne
hongchan 2017/01/26 22:33:18 This is a great resource. Thanks and we will follo
+ unsigned m_underflowCount;
+};
+
+} // namespace blink
+
+#endif // PushPullFIFO_h

Powered by Google App Engine
This is Rietveld 408576698