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

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

Issue 2549093009: Introduce PushPullFIFO class and remove other FIFOs (Closed)
Patch Set: Added FIFO contract and more CHECKs 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
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #ifndef AudioDestination_h 29 #ifndef AudioDestination_h
30 #define AudioDestination_h 30 #define AudioDestination_h
31 31
32 #include "platform/audio/AudioBus.h" 32 #include "platform/audio/AudioBus.h"
33 #include "platform/audio/AudioIOCallback.h" 33 #include "platform/audio/AudioIOCallback.h"
34 #include "platform/audio/AudioSourceProvider.h"
35 #include "public/platform/WebAudioDevice.h" 34 #include "public/platform/WebAudioDevice.h"
36 #include "public/platform/WebVector.h" 35 #include "public/platform/WebVector.h"
37 #include "wtf/Allocator.h" 36 #include "wtf/Allocator.h"
38 #include "wtf/Noncopyable.h" 37 #include "wtf/Noncopyable.h"
39 #include "wtf/text/WTFString.h" 38 #include "wtf/text/WTFString.h"
40 #include <memory> 39 #include <memory>
41 40
42 namespace blink { 41 namespace blink {
43 42
44 class AudioPullFIFO; 43 class PushPullFIFO;
45 class SecurityOrigin; 44 class SecurityOrigin;
46 45
47 // The AudioDestination class is an audio sink interface between the media 46 // The AudioDestination class is an audio sink interface between the media
48 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the 47 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the
49 // different processing block sizes of WebAudio renderer and actual hardware 48 // different processing block sizes of WebAudio renderer and actual hardware
50 // audio callback. 49 // audio callback.
51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, 50 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback {
52 public AudioSourceProvider {
53 USING_FAST_MALLOC(AudioDestination); 51 USING_FAST_MALLOC(AudioDestination);
54 WTF_MAKE_NONCOPYABLE(AudioDestination); 52 WTF_MAKE_NONCOPYABLE(AudioDestination);
55 53
56 public: 54 public:
57 AudioDestination(AudioIOCallback&, 55 AudioDestination(AudioIOCallback&,
58 unsigned numberOfOutputChannels, 56 unsigned numberOfOutputChannels,
59 float sampleRate, 57 float sampleRate,
60 PassRefPtr<SecurityOrigin>); 58 PassRefPtr<SecurityOrigin>);
61 ~AudioDestination() override; 59 ~AudioDestination() override;
62 60
63 static std::unique_ptr<AudioDestination> create( 61 static std::unique_ptr<AudioDestination> create(
64 AudioIOCallback&, 62 AudioIOCallback&,
65 unsigned numberOfOutputChannels, 63 unsigned numberOfOutputChannels,
66 float sampleRate, 64 float sampleRate,
67 PassRefPtr<SecurityOrigin>); 65 PassRefPtr<SecurityOrigin>);
68 66
69 // The actual render function (WebAudioDevice::RenderCallback) isochronously 67 // The actual render function (WebAudioDevice::RenderCallback) isochronously
70 // invoked by the media renderer. 68 // invoked by the media renderer.
71 void render(const WebVector<float*>& destinationData, 69 void render(const WebVector<float*>& destinationData,
72 size_t numberOfFrames, 70 size_t numberOfFrames,
73 double delay, 71 double delay,
74 double delayTimestamp, 72 double delayTimestamp,
75 size_t priorFramesSkipped) override; 73 size_t priorFramesSkipped) override;
76 74
77 // AudioSourceProvider (FIFO)
78 void provideInput(AudioBus* outputBus, size_t framesToProcess) override;
79
80 virtual void start(); 75 virtual void start();
81 virtual void stop(); 76 virtual void stop();
82 77
83 size_t callbackBufferSize() const { return m_callbackBufferSize; } 78 size_t callbackBufferSize() const { return m_callbackBufferSize; }
84 float sampleRate() const { return m_sampleRate; } 79 float sampleRate() const { return m_sampleRate; }
85 bool isPlaying() { return m_isPlaying; } 80 bool isPlaying() { return m_isPlaying; }
86 81
87 // The information from the actual audio hardware. (via Platform::current) 82 // The information from the actual audio hardware. (via Platform::current)
88 static float hardwareSampleRate(); 83 static float hardwareSampleRate();
89 static unsigned long maxChannelCount(); 84 static unsigned long maxChannelCount();
90 85
91 private: 86 private:
92 std::unique_ptr<WebAudioDevice> m_webAudioDevice; 87 std::unique_ptr<WebAudioDevice> m_webAudioDevice;
93 unsigned m_numberOfOutputChannels; 88 unsigned m_numberOfOutputChannels;
94 size_t m_callbackBufferSize; 89 size_t m_callbackBufferSize;
95 float m_sampleRate; 90 float m_sampleRate;
96 bool m_isPlaying; 91 bool m_isPlaying;
97 92
98 // The render callback function of WebAudio engine. (i.e. DestinationNode) 93 // The render callback function of WebAudio engine. (i.e. DestinationNode)
99 AudioIOCallback& m_callback; 94 AudioIOCallback& m_callback;
100 95
96 // To pass the data from FIFO to the audio device callback.
Raymond Toy 2017/01/30 20:59:27 nit: This comment is a bit unclear. Maybe say m_o
101 RefPtr<AudioBus> m_outputBus; 97 RefPtr<AudioBus> m_outputBus;
102 std::unique_ptr<AudioPullFIFO> m_fifo; 98
99 // To push the rendered result from WebAudio graph into the FIFO.
Raymond Toy 2017/01/30 20:59:27 Likewise, m_renderBus is used to hold the data tha
100 RefPtr<AudioBus> m_renderBus;
101
102 // Resolves the buffer size mismatch between the WebAudio engine and
103 // the callback function from the actual audio device.
Raymond Toy 2017/01/30 20:59:28 I think you can just say this is a FIFO between th
104 std::unique_ptr<PushPullFIFO> m_fifo;
103 105
104 size_t m_framesElapsed; 106 size_t m_framesElapsed;
105 AudioIOPosition m_outputPosition; 107 AudioIOPosition m_outputPosition;
106 base::TimeTicks m_outputPositionReceivedTimestamp; 108 base::TimeTicks m_outputPositionReceivedTimestamp;
107 109
108 // Calculate the optimum buffer size for a given platform. Return false if the 110 // Calculate the optimum buffer size for a given platform. Return false if the
109 // buffer size calculation fails. 111 // buffer size calculation fails.
110 bool calculateBufferSize(); 112 bool calculateBufferSize();
111 113
112 size_t hardwareBufferSize(); 114 size_t hardwareBufferSize();
113 }; 115 };
114 116
115 } // namespace blink 117 } // namespace blink
116 118
117 #endif // AudioDestination_h 119 #endif // AudioDestination_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698