| 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" |
| 34 #include "public/platform/WebAudioDevice.h" | 35 #include "public/platform/WebAudioDevice.h" |
| 35 #include "public/platform/WebVector.h" | 36 #include "public/platform/WebVector.h" |
| 36 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
| 37 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
| 38 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
| 39 #include <memory> | 40 #include <memory> |
| 40 | 41 |
| 41 namespace blink { | 42 namespace blink { |
| 42 | 43 |
| 43 class PushPullFIFO; | 44 class AudioPullFIFO; |
| 44 class SecurityOrigin; | 45 class SecurityOrigin; |
| 45 | 46 |
| 46 // The AudioDestination class is an audio sink interface between the media | 47 // The AudioDestination class is an audio sink interface between the media |
| 47 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the | 48 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the |
| 48 // different processing block sizes of WebAudio renderer and actual hardware | 49 // different processing block sizes of WebAudio renderer and actual hardware |
| 49 // audio callback. | 50 // audio callback. |
| 50 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { | 51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback, |
| 52 public AudioSourceProvider { |
| 51 USING_FAST_MALLOC(AudioDestination); | 53 USING_FAST_MALLOC(AudioDestination); |
| 52 WTF_MAKE_NONCOPYABLE(AudioDestination); | 54 WTF_MAKE_NONCOPYABLE(AudioDestination); |
| 53 | 55 |
| 54 public: | 56 public: |
| 55 AudioDestination(AudioIOCallback&, | 57 AudioDestination(AudioIOCallback&, |
| 56 unsigned numberOfOutputChannels, | 58 unsigned numberOfOutputChannels, |
| 57 float sampleRate, | 59 float sampleRate, |
| 58 PassRefPtr<SecurityOrigin>); | 60 PassRefPtr<SecurityOrigin>); |
| 59 ~AudioDestination() override; | 61 ~AudioDestination() override; |
| 60 | 62 |
| 61 static std::unique_ptr<AudioDestination> create( | 63 static std::unique_ptr<AudioDestination> create( |
| 62 AudioIOCallback&, | 64 AudioIOCallback&, |
| 63 unsigned numberOfOutputChannels, | 65 unsigned numberOfOutputChannels, |
| 64 float sampleRate, | 66 float sampleRate, |
| 65 PassRefPtr<SecurityOrigin>); | 67 PassRefPtr<SecurityOrigin>); |
| 66 | 68 |
| 67 // The actual render function (WebAudioDevice::RenderCallback) isochronously | 69 // The actual render function (WebAudioDevice::RenderCallback) isochronously |
| 68 // invoked by the media renderer. | 70 // invoked by the media renderer. |
| 69 void render(const WebVector<float*>& destinationData, | 71 void render(const WebVector<float*>& destinationData, |
| 70 size_t numberOfFrames, | 72 size_t numberOfFrames, |
| 71 double delay, | 73 double delay, |
| 72 double delayTimestamp, | 74 double delayTimestamp, |
| 73 size_t priorFramesSkipped) override; | 75 size_t priorFramesSkipped) override; |
| 74 | 76 |
| 77 // AudioSourceProvider (FIFO) |
| 78 void provideInput(AudioBus* outputBus, size_t framesToProcess) override; |
| 79 |
| 75 virtual void start(); | 80 virtual void start(); |
| 76 virtual void stop(); | 81 virtual void stop(); |
| 77 | 82 |
| 78 size_t callbackBufferSize() const { return m_callbackBufferSize; } | 83 size_t callbackBufferSize() const { return m_callbackBufferSize; } |
| 79 float sampleRate() const { return m_sampleRate; } | 84 float sampleRate() const { return m_sampleRate; } |
| 80 bool isPlaying() { return m_isPlaying; } | 85 bool isPlaying() { return m_isPlaying; } |
| 81 | 86 |
| 82 // The information from the actual audio hardware. (via Platform::current) | 87 // The information from the actual audio hardware. (via Platform::current) |
| 83 static float hardwareSampleRate(); | 88 static float hardwareSampleRate(); |
| 84 static unsigned long maxChannelCount(); | 89 static unsigned long maxChannelCount(); |
| 85 | 90 |
| 86 private: | 91 private: |
| 87 std::unique_ptr<WebAudioDevice> m_webAudioDevice; | 92 std::unique_ptr<WebAudioDevice> m_webAudioDevice; |
| 88 unsigned m_numberOfOutputChannels; | 93 unsigned m_numberOfOutputChannels; |
| 89 size_t m_callbackBufferSize; | 94 size_t m_callbackBufferSize; |
| 90 float m_sampleRate; | 95 float m_sampleRate; |
| 91 bool m_isPlaying; | 96 bool m_isPlaying; |
| 92 | 97 |
| 93 // The render callback function of WebAudio engine. (i.e. DestinationNode) | 98 // The render callback function of WebAudio engine. (i.e. DestinationNode) |
| 94 AudioIOCallback& m_callback; | 99 AudioIOCallback& m_callback; |
| 95 | 100 |
| 96 // To pass the data from FIFO to the audio device callback. | |
| 97 RefPtr<AudioBus> m_outputBus; | 101 RefPtr<AudioBus> m_outputBus; |
| 98 | 102 std::unique_ptr<AudioPullFIFO> m_fifo; |
| 99 // To push the rendered result from WebAudio graph into the FIFO. | |
| 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. | |
| 104 std::unique_ptr<PushPullFIFO> m_fifo; | |
| 105 | 103 |
| 106 size_t m_framesElapsed; | 104 size_t m_framesElapsed; |
| 107 AudioIOPosition m_outputPosition; | 105 AudioIOPosition m_outputPosition; |
| 108 base::TimeTicks m_outputPositionReceivedTimestamp; | 106 base::TimeTicks m_outputPositionReceivedTimestamp; |
| 109 | 107 |
| 110 // Calculate the optimum buffer size for a given platform. Return false if the | 108 // Calculate the optimum buffer size for a given platform. Return false if the |
| 111 // buffer size calculation fails. | 109 // buffer size calculation fails. |
| 112 bool calculateBufferSize(); | 110 bool calculateBufferSize(); |
| 113 | 111 |
| 114 size_t hardwareBufferSize(); | 112 size_t hardwareBufferSize(); |
| 115 }; | 113 }; |
| 116 | 114 |
| 117 } // namespace blink | 115 } // namespace blink |
| 118 | 116 |
| 119 #endif // AudioDestination_h | 117 #endif // AudioDestination_h |
| OLD | NEW |