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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.h

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&); 160 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception State&);
161 ChannelMergerNode* createChannelMerger(ExceptionState&); 161 ChannelMergerNode* createChannelMerger(ExceptionState&);
162 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &); 162 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState &);
163 OscillatorNode* createOscillator(ExceptionState&); 163 OscillatorNode* createOscillator(ExceptionState&);
164 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima g, ExceptionState&); 164 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima g, ExceptionState&);
165 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima g, const Dictionary&, ExceptionState&); 165 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima g, const Dictionary&, ExceptionState&);
166 166
167 // Close 167 // Close
168 virtual ScriptPromise closeContext(ScriptState*) = 0; 168 virtual ScriptPromise closeContext(ScriptState*) = 0;
169 169
170 // Suspend/Resume 170 // Suspend for online and offline context.
171 virtual ScriptPromise suspendContext(ScriptState*) = 0; 171 virtual ScriptPromise suspendContext(ScriptState*) = 0;
172 virtual ScriptPromise suspendContext(ScriptState*, double) = 0;
173
174 // Resume
172 virtual ScriptPromise resumeContext(ScriptState*) = 0; 175 virtual ScriptPromise resumeContext(ScriptState*) = 0;
173 176
174 // When a source node has started processing and needs to be protected, 177 // When a source node has started processing and needs to be protected,
175 // this method tells the context to protect the node. 178 // this method tells the context to protect the node.
176 // 179 //
177 // The context itself keeps a reference to all source nodes. The source 180 // The context itself keeps a reference to all source nodes. The source
178 // nodes, then reference all nodes they're connected to. In turn, these 181 // nodes, then reference all nodes they're connected to. In turn, these
179 // nodes reference all nodes they're connected to. All nodes are ultimately 182 // nodes reference all nodes they're connected to. All nodes are ultimately
180 // connected to the AudioDestinationNode. When the context release a source 183 // connected to the AudioDestinationNode. When the context release a source
181 // node, it will be deactivated from the rendering graph along with all 184 // node, it will be deactivated from the rendering graph along with all
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 #endif 223 #endif
221 using AutoLocker = DeferredTaskHandler::AutoLocker; 224 using AutoLocker = DeferredTaskHandler::AutoLocker;
222 225
223 // Returns the maximum numuber of channels we can support. 226 // Returns the maximum numuber of channels we can support.
224 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} 227 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;}
225 228
226 // EventTarget 229 // EventTarget
227 const AtomicString& interfaceName() const final; 230 const AtomicString& interfaceName() const final;
228 ExecutionContext* executionContext() const final; 231 ExecutionContext* executionContext() const final;
229 232
230 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
231 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); 233 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
232 234
233 void startRendering(); 235 void startRendering();
234 void fireCompletionEvent();
235 void notifyStateChange(); 236 void notifyStateChange();
236 237
237 // A context is considered closed if: 238 // A context is considered closed if:
238 // - closeContext() has been called. 239 // - closeContext() has been called.
239 // - it has been stopped by its execution context. 240 // - it has been stopped by its execution context.
240 virtual bool isContextClosed() const { return m_isCleared; } 241 virtual bool isContextClosed() const { return m_isCleared; }
241 242
242 // Get the security origin for this audio context. 243 // Get the security origin for this audio context.
243 SecurityOrigin* securityOrigin() const; 244 SecurityOrigin* securityOrigin() const;
244 245
245 protected: 246 protected:
246 explicit AbstractAudioContext(Document*); 247 explicit AbstractAudioContext(Document*);
247 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr ames, float sampleRate); 248 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr ames, float sampleRate);
248 249
249 void setContextState(AudioContextState); 250 void initialize();
250 virtual void didClose() {}
251 void uninitialize(); 251 void uninitialize();
252 252
253 Member<ScriptPromiseResolver> m_offlineResolver; 253 void setContextState(AudioContextState);
254
255 virtual void didClose() {}
256
257 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
258 // connected. Because these never get pulled anymore, they will stay around forever. So if we
259 // can, try to stop them so they can be collected.
260 void handleStoppableSourceNodes();
261
262 Member<AudioDestinationNode> m_destinationNode;
254 263
255 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only 264 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only
256 // it creates these Promises. 265 // it creates these Promises.
257 // Vector of promises created by resume(). It takes time to handle them, so we collect all of 266 // Vector of promises created by resume(). It takes time to handle them, so we collect all of
258 // the promises here until they can be resolved or rejected. 267 // the promises here until they can be resolved or rejected.
259 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers; 268 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers;
269
260 private: 270 private:
261 void initialize();
Raymond Toy 2015/10/16 23:32:36 Where did initialize() go? Is it no longer needed
hongchan 2015/10/19 20:08:12 1. initialize() has been moved to 'protected' sect
262
263 bool m_isCleared; 271 bool m_isCleared;
264 void clear(); 272 void clear();
265 273
266 void throwExceptionForClosedState(ExceptionState&); 274 void throwExceptionForClosedState(ExceptionState&);
267 275
268 // When the context goes away, there might still be some sources which 276 // When the context goes away, there might still be some sources which
269 // haven't finished playing. Make sure to release them here. 277 // haven't finished playing. Make sure to release them here.
270 void releaseActiveSourceNodes(); 278 void releaseActiveSourceNodes();
271 279
272 Member<AudioDestinationNode> m_destinationNode;
273 Member<AudioListener> m_listener; 280 Member<AudioListener> m_listener;
274 281
275 // Only accessed in the audio thread. 282 // Only accessed in the audio thread.
276 // These raw pointers are safe because AudioSourceNodes in 283 // These raw pointers are safe because AudioSourceNodes in
277 // m_activeSourceNodes own them. 284 // m_activeSourceNodes own them.
278 Vector<AudioHandler*> m_finishedSourceHandlers; 285 Vector<AudioHandler*> m_finishedSourceHandlers;
279 286
280 // 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
281 // 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.
282 // Oilpan: This Vector holds connection references. We must call 289 // Oilpan: This Vector holds connection references. We must call
(...skipping 14 matching lines...) Expand all
297 // time and the audio context process loop is very fast, so we don't want to call resolve an 304 // time and the audio context process loop is very fast, so we don't want to call resolve an
298 // excessive number of times. 305 // excessive number of times.
299 bool m_isResolvingResumePromises; 306 bool m_isResolvingResumePromises;
300 307
301 unsigned m_connectionCount; 308 unsigned m_connectionCount;
302 309
303 // Graph locking. 310 // Graph locking.
304 bool m_didInitializeContextGraphMutex; 311 bool m_didInitializeContextGraphMutex;
305 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; 312 RefPtr<DeferredTaskHandler> m_deferredTaskHandler;
306 313
307 Member<AudioBuffer> m_renderTarget;
308
309 // The state of the AbstractAudioContext. 314 // The state of the AbstractAudioContext.
310 AudioContextState m_contextState; 315 AudioContextState m_contextState;
311 316
312 AsyncAudioDecoder m_audioDecoder; 317 AsyncAudioDecoder m_audioDecoder;
313 318
314 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
315 // connected. Because these never get pulled anymore, they will stay around forever. So if we
316 // can, try to stop them so they can be collected.
317 void handleStoppableSourceNodes();
Raymond Toy 2015/10/16 23:32:36 Where is this now?
hongchan 2015/10/19 20:08:12 See the protected section as well. In this patch,
318
319 // This is considering 32 is large enough for multiple channels audio. 319 // This is considering 32 is large enough for multiple channels audio.
320 // It is somewhat arbitrary and could be increased if necessary. 320 // It is somewhat arbitrary and could be increased if necessary.
321 enum { MaxNumberOfChannels = 32 }; 321 enum { MaxNumberOfChannels = 32 };
322 }; 322 };
323 323
324 } // namespace blink 324 } // namespace blink
325 325
326 #endif // AbstractAudioContext_h 326 #endif // AbstractAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698