OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PushPullFIFO_h | |
6 #define PushPullFIFO_h | |
7 | |
8 #include "platform/audio/AudioBus.h" | |
9 #include "public/platform/WebCommon.h" | |
10 #include "wtf/Allocator.h" | |
11 | |
12 namespace blink { | |
13 | |
14 // A configuration data container for PushPullFIFO unit test. | |
15 struct PushPullFIFOStateForTest { | |
16 const size_t fifoLength; | |
17 const unsigned numberOfChannels; | |
18 const size_t framesAvailable; | |
19 const size_t indexRead; | |
20 const size_t indexWrite; | |
21 const unsigned overflowCount; | |
22 const unsigned underflowCount; | |
23 }; | |
24 | |
25 // PushPullFIFO class is an intermediate audio sample storage between | |
26 // Blink-WebAudio and the renderer. The renderer's hardware callback buffer size | |
27 // varies on the platform, but the WebAudio always operates by 128 frames of | |
28 // 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.
| |
29 // - 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.
| |
30 // - The push size is 128 frames (1 RQ), fixed. | |
31 // - The pull size can be flexible. | |
32 // - In case of overflow (FIFO full while push), the existing frames in FIFO | |
33 // will be overwritten and the read index will be forcibly moved to where the | |
34 // 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.
| |
35 // - In case of underflow (FIFO empty while pull), the remaining space in the | |
36 // 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
| |
37 // from the consumer without causing error, but with a glitch. | |
hongchan
2017/01/27 22:39:14
Here's the contract of FIFO.
| |
38 class BLINK_PLATFORM_EXPORT PushPullFIFO { | |
39 USING_FAST_MALLOC(PushPullFIFO); | |
40 WTF_MAKE_NONCOPYABLE(PushPullFIFO); | |
41 | |
42 public: | |
43 // If |fifoLength| is greater than the maximum value allowed, it will be | |
44 // clamped. | |
Raymond Toy
2017/01/30 20:59:28
Clamped to what?
hongchan
2017/02/01 18:07:28
Done.
| |
45 explicit PushPullFIFO(unsigned numberOfChannels, size_t fifoLength); | |
46 ~PushPullFIFO(); | |
47 | |
48 // Pushing audio data is done by the WebAudio render-backing thread. The | |
49 // 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
| |
50 // thus the thread can be blocked when the audio device thread is pulling | |
51 // data from the FIFO. | |
52 void push(const AudioBus* inputBus); | |
53 | |
54 // Pulling audio data is done by the audio device thread. In the case of | |
55 // underflow, the rest will be filled up with zeros (thus glitches). Pulling | |
56 // an empty FIFO is a valid operation, and the consumer will get a block of | |
57 // silence. | |
58 void pull(AudioBus* outputBus, size_t framesRequested); | |
59 | |
60 size_t framesAvailable() const { return m_framesAvailable; } | |
61 size_t length() const { return m_fifoLength; } | |
62 unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); } | |
63 AudioBus* bus() const { return m_fifoBus.get(); } | |
64 | |
65 // For unit test. Get the current configuration that consists of FIFO length, | |
66 // number of channels, read/write index position and under/overflow count. | |
67 const PushPullFIFOStateForTest getStateForTest() const; | |
68 | |
69 private: | |
70 // The size of the FIFO. | |
71 const size_t m_fifoLength = 0; | |
72 | |
73 RefPtr<AudioBus> m_fifoBus; | |
hongchan
2017/01/27 22:39:14
The order is changed because of the change in init
| |
74 | |
75 // The number of frames in the FIFO actually available for pulling. | |
76 size_t m_framesAvailable; | |
77 | |
78 size_t m_indexRead; | |
79 size_t m_indexWrite; | |
80 | |
81 unsigned m_overflowCount; | |
82 unsigned m_underflowCount; | |
83 }; | |
84 | |
85 } // namespace blink | |
86 | |
87 #endif // PushPullFIFO_h | |
OLD | NEW |