Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: Source/modules/webaudio/AudioContext.h

Issue 625363004: Implement suspend/resume for AudioContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, ExceptionState &); 123 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, ExceptionState &);
122 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, ExceptionState&); 124 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, ExceptionState&);
123 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, size_t numberOfOutputChannels, ExceptionState&); 125 ScriptProcessorNode* createScriptProcessor(size_t bufferSize, size_t numberO fInputChannels, size_t numberOfOutputChannels, ExceptionState&);
124 ChannelSplitterNode* createChannelSplitter(ExceptionState&); 126 ChannelSplitterNode* createChannelSplitter(ExceptionState&);
125 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&); 127 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&);
126 ChannelMergerNode* createChannelMerger(ExceptionState&); 128 ChannelMergerNode* createChannelMerger(ExceptionState&);
127 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &); 129 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &);
128 OscillatorNode* createOscillator(); 130 OscillatorNode* createOscillator();
129 PeriodicWave* createPeriodicWave(Float32Array* real, Float32Array* imag, Exc eptionState&); 131 PeriodicWave* createPeriodicWave(Float32Array* real, Float32Array* imag, Exc eptionState&);
130 132
133 // Pause/Resume
134 void suspendContext();
135 ScriptPromise resumeContext(ScriptState*);
136
131 // When a source node has no more processing to do (has finished playing), t hen it tells the context to dereference it. 137 // 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*); 138 void notifyNodeFinishedProcessing(AudioNode*);
133 139
134 // Called at the start of each render quantum. 140 // Called at the start of each render quantum.
135 void handlePreRenderTasks(); 141 void handlePreRenderTasks();
136 142
137 // Called at the end of each render quantum. 143 // Called at the end of each render quantum.
138 void handlePostRenderTasks(); 144 void handlePostRenderTasks();
139 145
140 // Called periodically at the end of each render quantum to dereference fini shed source nodes. 146 // Called periodically at the end of each render quantum to dereference fini shed source nodes.
(...skipping 18 matching lines...) Expand all
159 165
160 // Keeps track of the number of connections made. 166 // Keeps track of the number of connections made.
161 void incrementConnectionCount() 167 void incrementConnectionCount()
162 { 168 {
163 ASSERT(isMainThread()); 169 ASSERT(isMainThread());
164 m_connectionCount++; 170 m_connectionCount++;
165 } 171 }
166 172
167 unsigned connectionCount() const { return m_connectionCount; } 173 unsigned connectionCount() const { return m_connectionCount; }
168 174
175 void resolvePromisesForResume();
176 void resolvePromisesForResumeOnMainThread();
yhirano 2014/10/08 01:12:14 These function can be private.
177
169 // 178 //
170 // Thread Safety and Graph Locking: 179 // Thread Safety and Graph Locking:
171 // 180 //
172 181
173 void setAudioThread(ThreadIdentifier thread) { m_audioThread = thread; } // FIXME: check either not initialized or the same 182 void setAudioThread(ThreadIdentifier thread) { m_audioThread = thread; } // FIXME: check either not initialized or the same
174 ThreadIdentifier audioThread() const { return m_audioThread; } 183 ThreadIdentifier audioThread() const { return m_audioThread; }
175 bool isAudioThread() const; 184 bool isAudioThread() const;
176 185
177 void lock(); 186 void lock();
178 bool tryLock(); 187 bool tryLock();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 GC_PLUGIN_IGNORE("http://crbug.com/404527") 276 GC_PLUGIN_IGNORE("http://crbug.com/404527")
268 Vector<AudioNode*> m_finishedNodes; 277 Vector<AudioNode*> m_finishedNodes;
269 278
270 // List of source nodes. This is either accessed when the graph lock is 279 // 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. 280 // held, or on the main thread when the audio thread has finished.
272 // Oilpan: This Vector holds connection references. We must call 281 // Oilpan: This Vector holds connection references. We must call
273 // AudioNode::makeConnection when we add an AudioNode to this, and must call 282 // AudioNode::makeConnection when we add an AudioNode to this, and must call
274 // AudioNode::breakConnection() when we remove an AudioNode from this. 283 // AudioNode::breakConnection() when we remove an AudioNode from this.
275 HeapVector<Member<AudioNode> > m_referencedNodes; 284 HeapVector<Member<AudioNode> > m_referencedNodes;
276 285
286 GC_PLUGIN_IGNORE("http://crbug.com/404527")
287 Vector<RefPtr<ScriptPromiseResolver> > m_resumePromises;
288 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some
289 // time and the audio context process loop is very fast, so we don't want to call resolve an
290 // excessive number of times.
291 bool m_isResolvingResumePromises;
292
277 class AudioNodeDisposer { 293 class AudioNodeDisposer {
278 public: 294 public:
279 explicit AudioNodeDisposer(AudioNode& node) : m_node(node) { } 295 explicit AudioNodeDisposer(AudioNode& node) : m_node(node) { }
280 ~AudioNodeDisposer(); 296 ~AudioNodeDisposer();
281 297
282 private: 298 private:
283 AudioNode& m_node; 299 AudioNode& m_node;
284 }; 300 };
285 HeapHashMap<WeakMember<AudioNode>, OwnPtr<AudioNodeDisposer> > m_liveNodes; 301 HeapHashMap<WeakMember<AudioNode>, OwnPtr<AudioNodeDisposer> > m_liveNodes;
286 302
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 HashSet<AudioNode*> m_deferredCountModeChange; 362 HashSet<AudioNode*> m_deferredCountModeChange;
347 363
348 // This is considering 32 is large enough for multiple channels audio. 364 // This is considering 32 is large enough for multiple channels audio.
349 // It is somewhat arbitrary and could be increased if necessary. 365 // It is somewhat arbitrary and could be increased if necessary.
350 enum { MaxNumberOfChannels = 32 }; 366 enum { MaxNumberOfChannels = 32 };
351 }; 367 };
352 368
353 } // namespace blink 369 } // namespace blink
354 370
355 #endif // AudioContext_h 371 #endif // AudioContext_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/webaudio/AudioContext.cpp » ('j') | Source/modules/webaudio/AudioContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698