| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef OfflineAudioDestinationNode_h | 25 #ifndef OfflineAudioDestinationNode_h |
| 26 #define OfflineAudioDestinationNode_h | 26 #define OfflineAudioDestinationNode_h |
| 27 | 27 |
| 28 #include "modules/webaudio/AudioBuffer.h" | 28 #include "modules/webaudio/AudioBuffer.h" |
| 29 #include "modules/webaudio/AudioDestinationNode.h" | 29 #include "modules/webaudio/AudioDestinationNode.h" |
| 30 #include "modules/webaudio/OfflineAudioContext.h" |
| 30 #include "public/platform/WebThread.h" | 31 #include "public/platform/WebThread.h" |
| 31 #include "wtf/PassRefPtr.h" | 32 #include "wtf/PassRefPtr.h" |
| 32 #include "wtf/RefPtr.h" | 33 #include "wtf/RefPtr.h" |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 class AbstractAudioContext; | 37 class AbstractAudioContext; |
| 37 class AudioBus; | 38 class AudioBus; |
| 39 class OfflineAudioContext; |
| 38 | 40 |
| 39 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { | 41 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { |
| 40 public: | 42 public: |
| 41 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu
ffer* renderTarget); | 43 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu
ffer* renderTarget); |
| 42 ~OfflineAudioDestinationHandler() override; | 44 ~OfflineAudioDestinationHandler() override; |
| 43 | 45 |
| 44 // AudioHandler | 46 // AudioHandler |
| 45 void dispose() override; | 47 void dispose() override; |
| 46 void initialize() override; | 48 void initialize() override; |
| 47 void uninitialize() override; | 49 void uninitialize() override; |
| 48 | 50 |
| 51 OfflineAudioContext* context() const final; |
| 52 |
| 49 // AudioDestinationHandler | 53 // AudioDestinationHandler |
| 50 void startRendering() override; | 54 void startRendering() override; |
| 51 void stopRendering() override; | 55 void stopRendering() override; |
| 52 | 56 |
| 53 float sampleRate() const override { return m_renderTarget->sampleRate(); } | 57 float sampleRate() const override { return m_renderTarget->sampleRate(); } |
| 54 | 58 |
| 59 size_t renderQuantumFrames() const { return renderQuantumSize; } |
| 60 |
| 61 WebThread* offlineRenderThread(); |
| 62 |
| 55 private: | 63 private: |
| 56 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); | 64 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); |
| 57 void offlineRender(); | |
| 58 void offlineRenderInternal(); | |
| 59 | 65 |
| 60 // For completion callback on main thread. | 66 static const size_t renderQuantumSize; |
| 67 |
| 68 // Set up the rendering and start. After setting the context up, it will |
| 69 // eventually call |doOfflineRendering|. |
| 70 void startOfflineRendering(); |
| 71 |
| 72 // Suspend the rendering loop and notify the main thread to resolve the |
| 73 // associated promise. |
| 74 void suspendOfflineRendering(); |
| 75 |
| 76 // Start the rendering loop. |
| 77 void doOfflineRendering(); |
| 78 |
| 79 // Finish the rendering loop and notify the main thread to resolve the |
| 80 // promise with the rendered buffer. |
| 81 void finishOfflineRendering(); |
| 82 |
| 83 // Suspend/completion callbacks for the main thread. |
| 84 void notifySuspend(); |
| 61 void notifyComplete(); | 85 void notifyComplete(); |
| 62 | 86 |
| 87 // The offline version of render() method. If the rendering needs to be |
| 88 // suspended after checking, this stops the rendering and returns true. |
| 89 // Otherwise, it returns false after rendering one quantum. |
| 90 bool renderIfNotSuspended(AudioBus* sourceBus, AudioBus* destinationBus, siz
e_t numberOfFrames); |
| 91 |
| 63 // This AudioHandler renders into this AudioBuffer. | 92 // This AudioHandler renders into this AudioBuffer. |
| 64 // This Persistent doesn't make a reference cycle including the owner | 93 // This Persistent doesn't make a reference cycle including the owner |
| 65 // OfflineAudioDestinationNode. | 94 // OfflineAudioDestinationNode. |
| 66 Persistent<AudioBuffer> m_renderTarget; | 95 Persistent<AudioBuffer> m_renderTarget; |
| 67 // Temporary AudioBus for each render quantum. | 96 // Temporary AudioBus for each render quantum. |
| 68 RefPtr<AudioBus> m_renderBus; | 97 RefPtr<AudioBus> m_renderBus; |
| 69 | 98 |
| 70 // Rendering thread. | 99 // Rendering thread. |
| 71 OwnPtr<WebThread> m_renderThread; | 100 OwnPtr<WebThread> m_renderThread; |
| 72 bool m_startedRendering; | 101 |
| 102 // These variables are for counting the number of frames for the current |
| 103 // progress and the remaining frames to be processed. |
| 104 size_t m_framesProcessed; |
| 105 size_t m_framesToProcess; |
| 106 |
| 107 // This flag is necessary to distinguish the state of the context between |
| 108 // 'created' and 'suspended'. If this flag is false and the current state |
| 109 // is 'suspended', it means the context is created and have not started yet. |
| 110 bool m_isRenderingStarted; |
| 111 |
| 112 // This flag indicates whether the rendering should be suspended or not. |
| 113 bool m_shouldSuspend; |
| 73 }; | 114 }; |
| 74 | 115 |
| 75 class OfflineAudioDestinationNode final : public AudioDestinationNode { | 116 class OfflineAudioDestinationNode final : public AudioDestinationNode { |
| 76 public: | 117 public: |
| 77 static OfflineAudioDestinationNode* create(AbstractAudioContext*, AudioBuffe
r* renderTarget); | 118 static OfflineAudioDestinationNode* create(AbstractAudioContext*, AudioBuffe
r* renderTarget); |
| 78 | 119 |
| 79 private: | 120 private: |
| 80 OfflineAudioDestinationNode(AbstractAudioContext&, AudioBuffer* renderTarget
); | 121 OfflineAudioDestinationNode(AbstractAudioContext&, AudioBuffer* renderTarget
); |
| 81 }; | 122 }; |
| 82 | 123 |
| 83 } // namespace blink | 124 } // namespace blink |
| 84 | 125 |
| 85 #endif // OfflineAudioDestinationNode_h | 126 #endif // OfflineAudioDestinationNode_h |
| OLD | NEW |