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..2668fc50bda67f2affb275851287c0ce4f680b2b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/audio/PushPullFIFO.h |
| @@ -0,0 +1,52 @@ |
| +// 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 { |
| + |
| +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 |
| + // 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. This process must |
| + // 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
|
| + void pull(AudioBus* outputBus, size_t framesToPull); |
| + |
| + int framesAvailable() const { return std::max(0, 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; |
| + |
| + // The number of frames in the FIFO actually available for pulling. |
| + int m_framesAvailable; |
| + |
| + int m_indexRead; |
| + int m_indexWrite; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // PushPullFIFO_h |