Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
Raymond Toy
2017/01/27 17:39:44
2016 or 2017?
hongchan
2017/01/27 22:39:14
A good question. I'll take 2017.
| |
| 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; | |
|
o1ka
2017/01/27 13:47:54
is "unsigned" a part of WebKit style guide? Chromi
hongchan
2017/01/27 22:39:14
Yes, I have seen it in many files in WebKit.
http
| |
| 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; thus FIFO is needed. | |
|
Raymond Toy
2017/01/27 17:39:44
I think there have been quite a few comments on wh
hongchan
2017/01/27 22:39:14
I agree. I will add few constraints in the comment
| |
| 29 class BLINK_PLATFORM_EXPORT PushPullFIFO { | |
| 30 USING_FAST_MALLOC(PushPullFIFO); | |
| 31 WTF_MAKE_NONCOPYABLE(PushPullFIFO); | |
| 32 | |
| 33 public: | |
| 34 explicit PushPullFIFO(unsigned numberOfChannels, size_t fifoLength); | |
| 35 ~PushPullFIFO(); | |
| 36 | |
| 37 // Pushing audio data is done by the WebAudio render-backing thread. The | |
| 38 // priority of this thread is lower than the actual audio device thread, | |
| 39 // thus the thread can be blocked when the audio device thread is pulling | |
| 40 // data from the FIFO. | |
| 41 void push(const AudioBus* inputBus); | |
| 42 | |
| 43 // Pulling audio data is done by the audio device thread. In the case of | |
| 44 // underflow, the rest will be filled up with zeros (thus glitches). Pulling | |
| 45 // an empty FIFO is a valid operation, and the consumer will get a block of | |
| 46 // silence. | |
| 47 void pull(AudioBus* outputBus, size_t framesRequested); | |
| 48 | |
| 49 size_t framesAvailable() const { return m_framesAvailable; } | |
| 50 size_t length() const { return m_fifoLength; } | |
| 51 unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); } | |
| 52 AudioBus* bus() { return m_fifoBus.get(); } | |
|
o1ka
2017/01/27 13:47:54
const
hongchan
2017/01/27 22:39:14
Done.
| |
| 53 | |
| 54 // For unit test. Get the current configuration that consists of FIFO length, | |
| 55 // number of channels, read/write index position and under/overflow count. | |
| 56 const PushPullFIFOStateForTest getStateForTest() const; | |
| 57 | |
| 58 private: | |
| 59 RefPtr<AudioBus> m_fifoBus; | |
| 60 | |
| 61 // The size of the FIFO. | |
| 62 const size_t m_fifoLength = 0; | |
| 63 | |
| 64 // The number of frames in the FIFO actually available for pulling. | |
| 65 size_t m_framesAvailable; | |
| 66 | |
| 67 size_t m_indexRead; | |
| 68 size_t m_indexWrite; | |
| 69 | |
| 70 unsigned m_overflowCount; | |
|
o1ka
2017/01/27 13:47:54
just int? you count up to ~100 only
hongchan
2017/01/27 22:39:14
I am using unsigned for the same reason explained
| |
| 71 unsigned m_underflowCount; | |
| 72 }; | |
| 73 | |
| 74 } // namespace blink | |
| 75 | |
| 76 #endif // PushPullFIFO_h | |
| OLD | NEW |