Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: third_party/WebKit/Source/platform/audio/PushPullFIFO.h

Issue 2549093009: Introduce PushPullFIFO class and remove other FIFOs (Closed)
Patch Set: Refining unit tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // Maximum FIFO length. (512 RQs)
26 static const size_t kMaxFIFOLength = 65536;
o1ka 2017/02/02 16:30:25 Shouldn't the constant should only be declared her
hongchan 2017/02/02 19:55:23 Done.
27
28 // PushPullFIFO class is an intermediate audio sample storage between
29 // Blink-WebAudio and the renderer. The renderer's hardware callback buffer size
30 // varies on the platform, but the WebAudio always renders 128 frames (render
31 // quantum, RQ) thus FIFO is needed to handle the general case.
32 class BLINK_PLATFORM_EXPORT PushPullFIFO {
33 USING_FAST_MALLOC(PushPullFIFO);
34 WTF_MAKE_NONCOPYABLE(PushPullFIFO);
35
36 public:
37 // |fifoLength| cannot exceed |kMaxFIFOLength|. Otherwise it crashes.
38 explicit PushPullFIFO(unsigned numberOfChannels, size_t fifoLength);
39 ~PushPullFIFO();
40
41 // By design, the length of |inputBus| is 128 frames.
42 // - The |inputBus| length is 128 frames (1 RQ), fixed.
o1ka 2017/02/02 16:30:24 Duplication of the previous line?
hongchan 2017/02/02 19:55:23 Done.
43 // - In case of overflow (FIFO full while push), the existing frames in FIFO
44 // will be overwritten and |indexRead| will be forcibly moved to
45 // |indexWrite| to avoid reading overwritten frames.
46 void push(const AudioBus* inputBus);
47
48 // Pulling |framesRequested| by the audio device thread.
49 // - If |framesRequested| is bigger than the length of |outputBus|, it
50 // violates SECURITY_CHECK().
51 // - If |framesRequested| is bigger than FIFO length, it violates
52 // SECURITY_CHECK().
53 // - In case of underflow (FIFO empty while pull), the remaining space in the
54 // requested output bus will be filled with silence. Thus it will fulfill
55 // the request from the consumer without causing error, but with a glitch.
56 void pull(AudioBus* outputBus, size_t framesRequested);
57
58 size_t framesAvailable() const { return m_framesAvailable; }
59 size_t length() const { return m_fifoLength; }
60 unsigned numberOfChannels() const { return m_fifoBus->numberOfChannels(); }
61 AudioBus* bus() const { return m_fifoBus.get(); }
62
63 // For unit test. Get the current configuration that consists of FIFO length,
64 // number of channels, read/write index position and under/overflow count.
65 const PushPullFIFOStateForTest getStateForTest() const;
66
67 private:
68 // The size of the FIFO.
69 const size_t m_fifoLength = 0;
70
71 RefPtr<AudioBus> m_fifoBus;
72
73 // The number of frames in the FIFO actually available for pulling.
74 size_t m_framesAvailable;
75
76 size_t m_indexRead;
77 size_t m_indexWrite;
78
79 unsigned m_overflowCount;
80 unsigned m_underflowCount;
81 };
82
83 } // namespace blink
84
85 #endif // PushPullFIFO_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698