Chromium Code Reviews| 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..4927074fb3b7d818ca87417125c47da5fd3864d0 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/audio/PushPullFIFO.h |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2017 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 { |
| + |
| +// A configuration data container for PushPullFIFO unit test. |
| +struct PushPullFIFOStateForTest { |
| + const size_t fifoLength; |
| + const unsigned numberOfChannels; |
| + const size_t framesAvailable; |
| + const size_t indexRead; |
| + const size_t indexWrite; |
| + const unsigned overflowCount; |
| + const unsigned underflowCount; |
| +}; |
| + |
| +// 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 (RQ); thus FIFO is needed. |
|
Raymond Toy
2017/01/30 20:59:28
"128 frames of render quantum" is awkward. Rephra
hongchan
2017/02/01 18:07:28
Done.
|
| +// - The maximum FIFO length is 32768 frames (256 RQs). |
|
Raymond Toy
2017/01/30 20:59:28
Recall that we encountered an Android device with
hongchan
2017/02/01 18:07:27
Done.
|
| +// - The push size is 128 frames (1 RQ), fixed. |
| +// - The pull size can be flexible. |
| +// - In case of overflow (FIFO full while push), the existing frames in FIFO |
| +// will be overwritten and the read index will be forcibly moved to where the |
| +// write index is located. |
|
Raymond Toy
2017/01/30 20:59:28
That doesn't really tell me what happens with the
hongchan
2017/02/01 18:07:28
Done.
|
| +// - In case of underflow (FIFO empty while pull), the remaining space in the |
| +// output bus will be filled with silence. Thus it will fulfill the request |
|
Raymond Toy
2017/01/30 20:59:28
What does "remaining space" mean here? The FIFO i
hongchan
2017/02/01 18:07:28
"remaining space in the output bus" - that means t
|
| +// from the consumer without causing error, but with a glitch. |
|
hongchan
2017/01/27 22:39:14
Here's the contract of FIFO.
|
| +class BLINK_PLATFORM_EXPORT PushPullFIFO { |
| + USING_FAST_MALLOC(PushPullFIFO); |
| + WTF_MAKE_NONCOPYABLE(PushPullFIFO); |
| + |
| + public: |
| + // If |fifoLength| is greater than the maximum value allowed, it will be |
| + // clamped. |
|
Raymond Toy
2017/01/30 20:59:28
Clamped to what?
hongchan
2017/02/01 18:07:28
Done.
|
| + explicit PushPullFIFO(unsigned numberOfChannels, size_t fifoLength); |
| + ~PushPullFIFO(); |
| + |
| + // Pushing audio data is done by the WebAudio render-backing thread. The |
| + // priority of this thread is lower than the actual audio device thread, |
|
Raymond Toy
2017/01/30 20:59:28
How do we know the priorities already?
hongchan
2017/02/01 18:07:28
The comments are edited. No mention of multi-threa
|
| + // 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); |
| + |
| + size_t framesAvailable() const { return m_framesAvailable; } |
| + size_t length() const { return m_fifoLength; } |
| + unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); } |
| + AudioBus* bus() const { return m_fifoBus.get(); } |
| + |
| + // 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: |
| + // The size of the FIFO. |
| + const size_t m_fifoLength = 0; |
| + |
| + RefPtr<AudioBus> m_fifoBus; |
|
hongchan
2017/01/27 22:39:14
The order is changed because of the change in init
|
| + |
| + // The number of frames in the FIFO actually available for pulling. |
| + size_t m_framesAvailable; |
| + |
| + size_t m_indexRead; |
| + size_t m_indexWrite; |
| + |
| + unsigned m_overflowCount; |
| + unsigned m_underflowCount; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // PushPullFIFO_h |