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" | |
31 #include "public/platform/WebThread.h" | 30 #include "public/platform/WebThread.h" |
32 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
33 #include "wtf/RefPtr.h" | 32 #include "wtf/RefPtr.h" |
34 | 33 |
35 namespace blink { | 34 namespace blink { |
36 | 35 |
37 class AbstractAudioContext; | 36 class AbstractAudioContext; |
38 class AudioBus; | 37 class AudioBus; |
39 class OfflineAudioContext; | |
40 | 38 |
41 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { | 39 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { |
42 public: | 40 public: |
43 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu
ffer* renderTarget); | 41 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu
ffer* renderTarget); |
44 ~OfflineAudioDestinationHandler() override; | 42 ~OfflineAudioDestinationHandler() override; |
45 | 43 |
46 // AudioHandler | 44 // AudioHandler |
47 void dispose() override; | 45 void dispose() override; |
48 void initialize() override; | 46 void initialize() override; |
49 void uninitialize() override; | 47 void uninitialize() override; |
50 | 48 |
51 OfflineAudioContext* context() const final; | 49 // AudioDestinationHandler |
52 | |
53 // Override the one from AudioContext. Create a rendering thread and | |
54 // initiate rendering loop or resume rendering if already started and | |
55 // suspended. | |
56 void startRendering() override; | 50 void startRendering() override; |
57 | |
58 // There is no support of the explicit stopping in OfflineAudioContext. This | |
59 // is just to match the class method signature. | |
60 void stopRendering() override; | 51 void stopRendering() override; |
61 | 52 |
62 float sampleRate() const override { return m_renderTarget->sampleRate(); } | 53 float sampleRate() const override { return m_renderTarget->sampleRate(); } |
63 | |
64 // Return the frame position by quantizing the time (in seconds) and | |
65 // rounding it down to the nearest render quantum boundary. | |
66 size_t quantizeTimeToRenderQuantum(double when) const; | |
67 | |
68 WebThread* offlineRenderThread(); | |
69 | 54 |
70 private: | 55 private: |
71 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); | 56 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); |
72 | 57 void offlineRender(); |
73 // For start/suspend/resume rendering in the destination node. | 58 void offlineRenderInternal(); |
74 void startOfflineRendering(); | |
75 void runOfflineRendering(); | |
76 void finishOfflineRendering(); | |
77 | 59 |
78 // For completion callback on main thread. | 60 // For completion callback on main thread. |
79 void notifyComplete(); | 61 void notifyComplete(); |
80 | 62 |
81 // This AudioHandler renders into this AudioBuffer. | 63 // This AudioHandler renders into this AudioBuffer. |
82 // This Persistent doesn't make a reference cycle including the owner | 64 // This Persistent doesn't make a reference cycle including the owner |
83 // OfflineAudioDestinationNode. | 65 // OfflineAudioDestinationNode. |
84 Persistent<AudioBuffer> m_renderTarget; | 66 Persistent<AudioBuffer> m_renderTarget; |
85 // Temporary AudioBus for each render quantum. | 67 // Temporary AudioBus for each render quantum. |
86 RefPtr<AudioBus> m_renderBus; | 68 RefPtr<AudioBus> m_renderBus; |
87 | 69 |
88 // Rendering thread. | 70 // Rendering thread. |
89 OwnPtr<WebThread> m_renderThread; | 71 OwnPtr<WebThread> m_renderThread; |
90 | 72 bool m_startedRendering; |
91 size_t m_framesProcessed; | |
92 size_t m_framesToProcess; | |
93 | |
94 bool m_isRenderingStarted; | |
95 }; | 73 }; |
96 | 74 |
97 class OfflineAudioDestinationNode final : public AudioDestinationNode { | 75 class OfflineAudioDestinationNode final : public AudioDestinationNode { |
98 public: | 76 public: |
99 static OfflineAudioDestinationNode* create(AbstractAudioContext*, AudioBuffe
r* renderTarget); | 77 static OfflineAudioDestinationNode* create(AbstractAudioContext*, AudioBuffe
r* renderTarget); |
100 | 78 |
101 private: | 79 private: |
102 OfflineAudioDestinationNode(AbstractAudioContext&, AudioBuffer* renderTarget
); | 80 OfflineAudioDestinationNode(AbstractAudioContext&, AudioBuffer* renderTarget
); |
103 }; | 81 }; |
104 | 82 |
105 } // namespace blink | 83 } // namespace blink |
106 | 84 |
107 #endif // OfflineAudioDestinationNode_h | 85 #endif // OfflineAudioDestinationNode_h |
OLD | NEW |