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 * 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 AudioContext_h | 25 #ifndef AudioContext_h |
26 #define AudioContext_h | 26 #define AudioContext_h |
27 | 27 |
28 #include "bindings/core/v8/ScriptPromise.h" | |
29 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
28 #include "core/dom/ActiveDOMObject.h" | 30 #include "core/dom/ActiveDOMObject.h" |
29 #include "core/events/EventListener.h" | 31 #include "core/events/EventListener.h" |
30 #include "modules/EventTargetModules.h" | 32 #include "modules/EventTargetModules.h" |
31 #include "modules/webaudio/AsyncAudioDecoder.h" | 33 #include "modules/webaudio/AsyncAudioDecoder.h" |
32 #include "modules/webaudio/AudioDestinationNode.h" | 34 #include "modules/webaudio/AudioDestinationNode.h" |
33 #include "platform/audio/AudioBus.h" | 35 #include "platform/audio/AudioBus.h" |
34 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
35 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
36 #include "wtf/MainThread.h" | 38 #include "wtf/MainThread.h" |
37 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 class WaveShaperNode; | 72 class WaveShaperNode; |
71 | 73 |
72 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. | 74 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. |
73 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. | 75 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. |
74 | 76 |
75 class AudioContext : public RefCountedGarbageCollectedWillBeGarbageCollectedFina lized<AudioContext>, public ActiveDOMObject, public EventTargetWithInlineData { | 77 class AudioContext : public RefCountedGarbageCollectedWillBeGarbageCollectedFina lized<AudioContext>, public ActiveDOMObject, public EventTargetWithInlineData { |
76 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A udioContext>); | 78 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A udioContext>); |
77 DEFINE_WRAPPERTYPEINFO(); | 79 DEFINE_WRAPPERTYPEINFO(); |
78 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); | 80 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); |
79 public: | 81 public: |
82 enum AudioContextState { | |
83 Paused, | |
84 Running, | |
85 Released | |
86 }; | |
87 | |
80 // Create an AudioContext for rendering to the audio hardware. | 88 // Create an AudioContext for rendering to the audio hardware. |
81 static AudioContext* create(Document&, ExceptionState&); | 89 static AudioContext* create(Document&, ExceptionState&); |
82 | 90 |
83 virtual ~AudioContext(); | 91 virtual ~AudioContext(); |
84 | 92 |
85 virtual void trace(Visitor*) override; | 93 virtual void trace(Visitor*) override; |
86 | 94 |
87 bool isInitialized() const { return m_isInitialized; } | 95 bool isInitialized() const { return m_isInitialized; } |
88 bool isOfflineContext() { return m_isOfflineContext; } | 96 bool isOfflineContext() { return m_isOfflineContext; } |
89 | 97 |
90 // Document notification | 98 // Document notification |
91 virtual void stop() override final; | 99 virtual void stop() override final; |
92 virtual bool hasPendingActivity() const override; | 100 virtual bool hasPendingActivity() const override; |
93 | 101 |
94 AudioDestinationNode* destination() { return m_destinationNode.get(); } | 102 AudioDestinationNode* destination() { return m_destinationNode.get(); } |
95 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); } | 103 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); } |
96 double currentTime() const { return m_destinationNode->currentTime(); } | 104 double currentTime() const { return m_destinationNode->currentTime(); } |
97 float sampleRate() const { return m_destinationNode->sampleRate(); } | 105 float sampleRate() const { return m_destinationNode->sampleRate(); } |
106 String state() const; | |
98 | 107 |
99 AudioBuffer* createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&); | 108 AudioBuffer* createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&); |
100 | 109 |
101 // Asynchronous audio file data decoding. | 110 // Asynchronous audio file data decoding. |
102 void decodeAudioData(ArrayBuffer*, AudioBufferCallback*, AudioBufferCallback *, ExceptionState&); | 111 void decodeAudioData(ArrayBuffer*, AudioBufferCallback*, AudioBufferCallback *, ExceptionState&); |
103 | 112 |
104 AudioListener* listener() { return m_listener.get(); } | 113 AudioListener* listener() { return m_listener.get(); } |
105 | 114 |
106 // The AudioNode create methods are called on the main thread (from JavaScri pt). | 115 // The AudioNode create methods are called on the main thread (from JavaScri pt). |
107 AudioBufferSourceNode* createBufferSource(); | 116 AudioBufferSourceNode* createBufferSource(); |
(...skipping 13 matching lines...) Expand all Loading... | |
121 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, ExceptionState &); | 130 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, ExceptionState &); |
122 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, ExceptionState&); | 131 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, ExceptionState&); |
123 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, size_t numberOfOutputChannels, ExceptionState&); | 132 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, size_t numberOfOutputChannels, ExceptionState&); |
124 ChannelSplitterNode* createChannelSplitter(ExceptionState&); | 133 ChannelSplitterNode* createChannelSplitter(ExceptionState&); |
125 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&); | 134 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&); |
126 ChannelMergerNode* createChannelMerger(ExceptionState&); | 135 ChannelMergerNode* createChannelMerger(ExceptionState&); |
127 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &); | 136 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &); |
128 OscillatorNode* createOscillator(); | 137 OscillatorNode* createOscillator(); |
129 PeriodicWave* createPeriodicWave(Float32Array* real, Float32Array* imag, Exc eptionState&); | 138 PeriodicWave* createPeriodicWave(Float32Array* real, Float32Array* imag, Exc eptionState&); |
130 | 139 |
140 // Pause/Resume | |
141 void suspendContext(ExceptionState&); | |
142 ScriptPromise resumeContext(ScriptState*); | |
143 | |
131 // When a source node has no more processing to do (has finished playing), t hen it tells the context to dereference it. | 144 // When a source node has no more processing to do (has finished playing), t hen it tells the context to dereference it. |
132 void notifyNodeFinishedProcessing(AudioNode*); | 145 void notifyNodeFinishedProcessing(AudioNode*); |
133 | 146 |
134 // Called at the start of each render quantum. | 147 // Called at the start of each render quantum. |
135 void handlePreRenderTasks(); | 148 void handlePreRenderTasks(); |
136 | 149 |
137 // Called at the end of each render quantum. | 150 // Called at the end of each render quantum. |
138 void handlePostRenderTasks(); | 151 void handlePostRenderTasks(); |
139 | 152 |
140 // Called periodically at the end of each render quantum to dereference fini shed source nodes. | 153 // Called periodically at the end of each render quantum to dereference fini shed source nodes. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 // Only accessed when the graph lock is held. Must be called on the main thr ead. | 229 // Only accessed when the graph lock is held. Must be called on the main thr ead. |
217 void removeMarkedSummingJunction(AudioSummingJunction*); | 230 void removeMarkedSummingJunction(AudioSummingJunction*); |
218 void markAudioNodeOutputDirty(AudioNodeOutput*); | 231 void markAudioNodeOutputDirty(AudioNodeOutput*); |
219 void removeMarkedAudioNodeOutput(AudioNodeOutput*); | 232 void removeMarkedAudioNodeOutput(AudioNodeOutput*); |
220 void disposeOutputs(AudioNode&); | 233 void disposeOutputs(AudioNode&); |
221 | 234 |
222 // EventTarget | 235 // EventTarget |
223 virtual const AtomicString& interfaceName() const override final; | 236 virtual const AtomicString& interfaceName() const override final; |
224 virtual ExecutionContext* executionContext() const override final; | 237 virtual ExecutionContext* executionContext() const override final; |
225 | 238 |
239 // Handle Promises for resume(). | |
240 void resolvePromisesForResume(); | |
241 void resolvePromisesForResumeOnMainThread(); | |
242 | |
226 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | 243 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); |
227 | 244 |
228 void startRendering(); | 245 void startRendering(); |
229 void fireCompletionEvent(); | 246 void fireCompletionEvent(); |
230 | 247 |
231 static unsigned s_hardwareContextCount; | 248 static unsigned s_hardwareContextCount; |
232 | 249 |
233 protected: | 250 protected: |
234 explicit AudioContext(Document*); | 251 explicit AudioContext(Document*); |
235 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); | 252 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 GC_PLUGIN_IGNORE("http://crbug.com/404527") | 284 GC_PLUGIN_IGNORE("http://crbug.com/404527") |
268 Vector<AudioNode*> m_finishedNodes; | 285 Vector<AudioNode*> m_finishedNodes; |
269 | 286 |
270 // List of source nodes. This is either accessed when the graph lock is | 287 // List of source nodes. This is either accessed when the graph lock is |
271 // held, or on the main thread when the audio thread has finished. | 288 // held, or on the main thread when the audio thread has finished. |
272 // Oilpan: This Vector holds connection references. We must call | 289 // Oilpan: This Vector holds connection references. We must call |
273 // AudioNode::makeConnection when we add an AudioNode to this, and must call | 290 // AudioNode::makeConnection when we add an AudioNode to this, and must call |
274 // AudioNode::breakConnection() when we remove an AudioNode from this. | 291 // AudioNode::breakConnection() when we remove an AudioNode from this. |
275 HeapVector<Member<AudioNode> > m_referencedNodes; | 292 HeapVector<Member<AudioNode> > m_referencedNodes; |
276 | 293 |
294 GC_PLUGIN_IGNORE("http://crbug.com/404527") | |
haraken
2014/10/15 15:36:26
ScriptPromiseResolver is not yet moved to Oilpan,
| |
295 Vector<RefPtr<ScriptPromiseResolver> > m_resumePromises; | |
296 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some | |
297 // time and the audio context process loop is very fast, so we don't want to call resolve an | |
298 // excessive number of times. | |
299 bool m_isResolvingResumePromises; | |
300 | |
277 class AudioNodeDisposer { | 301 class AudioNodeDisposer { |
278 public: | 302 public: |
279 explicit AudioNodeDisposer(AudioNode& node) : m_node(node) { } | 303 explicit AudioNodeDisposer(AudioNode& node) : m_node(node) { } |
280 ~AudioNodeDisposer(); | 304 ~AudioNodeDisposer(); |
281 | 305 |
282 private: | 306 private: |
283 AudioNode& m_node; | 307 AudioNode& m_node; |
284 }; | 308 }; |
285 HeapHashMap<WeakMember<AudioNode>, OwnPtr<AudioNodeDisposer> > m_liveNodes; | 309 HeapHashMap<WeakMember<AudioNode>, OwnPtr<AudioNodeDisposer> > m_liveNodes; |
286 | 310 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 // Only accessed in the audio thread. | 355 // Only accessed in the audio thread. |
332 // Oilpan: Since items are added to these vectors by the audio thread (not r egistered to Oilpan), | 356 // Oilpan: Since items are added to these vectors by the audio thread (not r egistered to Oilpan), |
333 // we cannot use HeapVectors. | 357 // we cannot use HeapVectors. |
334 GC_PLUGIN_IGNORE("http://crbug.com/404527") | 358 GC_PLUGIN_IGNORE("http://crbug.com/404527") |
335 Vector<AudioNode*> m_deferredBreakConnectionList; | 359 Vector<AudioNode*> m_deferredBreakConnectionList; |
336 | 360 |
337 Member<AudioBuffer> m_renderTarget; | 361 Member<AudioBuffer> m_renderTarget; |
338 | 362 |
339 bool m_isOfflineContext; | 363 bool m_isOfflineContext; |
340 | 364 |
365 AudioContextState m_state; | |
366 void setState(AudioContextState); | |
367 | |
341 AsyncAudioDecoder m_audioDecoder; | 368 AsyncAudioDecoder m_audioDecoder; |
342 | 369 |
343 // Collection of nodes where the channel count mode has changed. We want the channel count mode | 370 // Collection of nodes where the channel count mode has changed. We want the channel count mode |
344 // to change in the pre- or post-rendering phase so as not to disturb the ru nning audio thread. | 371 // to change in the pre- or post-rendering phase so as not to disturb the ru nning audio thread. |
345 GC_PLUGIN_IGNORE("http://crbug.com/404527") | 372 GC_PLUGIN_IGNORE("http://crbug.com/404527") |
346 HashSet<AudioNode*> m_deferredCountModeChange; | 373 HashSet<AudioNode*> m_deferredCountModeChange; |
347 | 374 |
348 // This is considering 32 is large enough for multiple channels audio. | 375 // This is considering 32 is large enough for multiple channels audio. |
349 // It is somewhat arbitrary and could be increased if necessary. | 376 // It is somewhat arbitrary and could be increased if necessary. |
350 enum { MaxNumberOfChannels = 32 }; | 377 enum { MaxNumberOfChannels = 32 }; |
351 }; | 378 }; |
352 | 379 |
353 } // namespace blink | 380 } // namespace blink |
354 | 381 |
355 #endif // AudioContext_h | 382 #endif // AudioContext_h |
OLD | NEW |