OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 class BLINK_PLATFORM_EXPORT PushPullFIFO { | |
15 USING_FAST_MALLOC(PushPullFIFO); | |
16 WTF_MAKE_NONCOPYABLE(PushPullFIFO); | |
17 | |
18 public: | |
19 PushPullFIFO(unsigned numberOfChannels, size_t fifoLength); | |
20 ~PushPullFIFO(); | |
21 | |
22 // Pushing audio data is done by the WebAudio render-backing thread. The | |
23 // priority of this thread is lower than the actual audio device thread, | |
24 // thus the thread can be blocked when the audio device thread is pulling | |
25 // data from the FIFO. | |
26 void push(const AudioBus* inputBus); | |
27 | |
28 // Pulling audio data is done by the audio device thread. This process must | |
29 // be non-blocking to ensure the glitch-less audio playback. | |
o1ka
2017/01/13 11:23:44
What are the plans regarding thread safety?
hongchan
2017/01/13 23:29:23
Giving a higher priority to pulling operation is o
| |
30 void pull(AudioBus* outputBus, size_t framesToPull); | |
31 | |
32 int framesAvailable() const { return std::max(0, m_framesAvailable); } | |
33 int length() const { return m_fifoLength; } | |
34 unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); } | |
35 AudioBus* bus() { return m_fifoBus.get(); } | |
36 | |
37 private: | |
38 RefPtr<AudioBus> m_fifoBus; | |
39 | |
40 // The size of the FIFO. | |
41 const int m_fifoLength; | |
42 | |
43 // The number of frames in the FIFO actually available for pulling. | |
44 int m_framesAvailable; | |
45 | |
46 int m_indexRead; | |
47 int m_indexWrite; | |
48 }; | |
49 | |
50 } // namespace blink | |
51 | |
52 #endif // PushPullFIFO_h | |
OLD | NEW |