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/AudioContext.h" | |
29 #include "modules/webaudio/AudioDestinationNode.h" | 30 #include "modules/webaudio/AudioDestinationNode.h" |
31 #include "modules/webaudio/OfflineAudioContext.h" | |
30 #include "public/platform/WebThread.h" | 32 #include "public/platform/WebThread.h" |
31 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
32 #include "wtf/RefPtr.h" | 34 #include "wtf/RefPtr.h" |
33 | 35 |
34 namespace blink { | 36 namespace blink { |
35 | 37 |
36 class AudioBus; | 38 class AudioBus; |
37 class AudioContext; | 39 class AudioContext; |
40 class OfflineAudioContext; | |
38 | 41 |
39 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { | 42 class OfflineAudioDestinationHandler final : public AudioDestinationHandler { |
40 public: | 43 public: |
41 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu ffer* renderTarget); | 44 static PassRefPtr<OfflineAudioDestinationHandler> create(AudioNode&, AudioBu ffer* renderTarget); |
42 virtual ~OfflineAudioDestinationHandler(); | 45 virtual ~OfflineAudioDestinationHandler(); |
43 | 46 |
44 // AudioHandler | 47 // AudioHandler |
45 virtual void dispose() override; | 48 virtual void dispose() override; |
46 virtual void initialize() override; | 49 virtual void initialize() override; |
47 virtual void uninitialize() override; | 50 virtual void uninitialize() override; |
48 | 51 |
49 // AudioDestinationHandler | 52 // Override the one from AudioContext. Create a rendering thread and |
53 // initiate rendering loop or resume rendering if already started and | |
54 // suspended. | |
50 virtual void startRendering() override; | 55 virtual void startRendering() override; |
56 | |
57 // This should NOT be called within OfflineAudioContext. | |
Raymond Toy
2015/05/28 16:37:37
Explain why.
hongchan
2015/06/09 20:50:00
Done.
| |
51 virtual void stopRendering() override; | 58 virtual void stopRendering() override; |
52 | 59 |
53 virtual float sampleRate() const override { return m_renderTarget->sampleRa te(); } | 60 virtual float sampleRate() const override { return m_renderTarget->sampleRat e(); } |
61 | |
62 // Quantize time (in seconds) to the nearest block boundary in the past. | |
63 virtual size_t quantizeTime(double when) const override; | |
54 | 64 |
55 private: | 65 private: |
56 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); | 66 OfflineAudioDestinationHandler(AudioNode&, AudioBuffer* renderTarget); |
57 void offlineRender(); | 67 |
58 void offlineRenderInternal(); | 68 // For start/suspend/resume rendering in the destination node. |
69 void startOfflineRendering(); | |
70 void runOfflineRendering(); | |
71 void finishOfflineRendering(); | |
59 | 72 |
60 // For completion callback on main thread. | 73 // For completion callback on main thread. |
61 void notifyComplete(); | 74 void notifyComplete(); |
62 | 75 |
63 // This AudioHandler renders into this AudioBuffer. | 76 // This AudioHandler renders into this AudioBuffer. |
64 // This Persistent doesn't make a reference cycle including the owner | 77 // This Persistent doesn't make a reference cycle including the owner |
65 // OfflineAudioDestinationNode. | 78 // OfflineAudioDestinationNode. |
66 Persistent<AudioBuffer> m_renderTarget; | 79 Persistent<AudioBuffer> m_renderTarget; |
67 // Temporary AudioBus for each render quantum. | 80 // Temporary AudioBus for each render quantum. |
68 RefPtr<AudioBus> m_renderBus; | 81 RefPtr<AudioBus> m_renderBus; |
69 | 82 |
70 // Rendering thread. | 83 // Rendering thread. |
71 OwnPtr<WebThread> m_renderThread; | 84 OwnPtr<WebThread> m_renderThread; |
72 bool m_startedRendering; | 85 |
Raymond Toy
2015/05/28 16:37:37
Don't need this anymore? Or was this renamed to m_
hongchan
2015/06/09 20:50:00
This is removed.
| |
86 size_t m_framesProcessed; | |
87 size_t m_framesToProcess; | |
73 }; | 88 }; |
74 | 89 |
75 class OfflineAudioDestinationNode final : public AudioDestinationNode { | 90 class OfflineAudioDestinationNode final : public AudioDestinationNode { |
76 public: | 91 public: |
77 static OfflineAudioDestinationNode* create(AudioContext*, AudioBuffer* rende rTarget); | 92 static OfflineAudioDestinationNode* create(AudioContext*, AudioBuffer* rende rTarget); |
78 | 93 |
79 private: | 94 private: |
80 OfflineAudioDestinationNode(AudioContext&, AudioBuffer* renderTarget); | 95 OfflineAudioDestinationNode(AudioContext&, AudioBuffer* renderTarget); |
81 }; | 96 }; |
82 | 97 |
83 } // namespace blink | 98 } // namespace blink |
84 | 99 |
85 #endif // OfflineAudioDestinationNode_h | 100 #endif // OfflineAudioDestinationNode_h |
OLD | NEW |