Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| 101 RefPtr<AudioBus> m_outputBus; | 96 RefPtr<AudioBus> m_outputBus; |
| 102 std::unique_ptr<AudioPullFIFO> m_fifo; | 97 RefPtr<AudioBus> m_renderBus; |
| 98 std::unique_ptr<PushPullFIFO> m_fifo; | |
|
Raymond Toy
2017/01/06 22:22:03
Please add comments on what m_renderBus and m_fifo
hongchan
2017/01/09 21:53:15
Done.
| |
| 103 | 99 |
| 104 size_t m_framesElapsed; | 100 size_t m_framesElapsed; |
| 105 AudioIOPosition m_outputPosition; | 101 AudioIOPosition m_outputPosition; |
| 106 base::TimeTicks m_outputPositionReceivedTimestamp; | 102 base::TimeTicks m_outputPositionReceivedTimestamp; |
| 107 | 103 |
| 108 // Calculate the optimum buffer size for a given platform. Return false if the | 104 // Calculate the optimum buffer size for a given platform. Return false if the |
| 109 // buffer size calculation fails. | 105 // buffer size calculation fails. |
| 110 bool calculateBufferSize(); | 106 bool calculateBufferSize(); |
| 111 | 107 |
| 112 size_t hardwareBufferSize(); | 108 size_t hardwareBufferSize(); |
| 113 }; | 109 }; |
| 114 | 110 |
| 115 } // namespace blink | 111 } // namespace blink |
| 116 | 112 |
| 117 #endif // AudioDestination_h | 113 #endif // AudioDestination_h |
| OLD | NEW |