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

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

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Initial Design Created 5 years, 7 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} 213 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;}
214 214
215 // EventTarget 215 // EventTarget
216 virtual const AtomicString& interfaceName() const override final; 216 virtual const AtomicString& interfaceName() const override final;
217 virtual ExecutionContext* executionContext() const override final; 217 virtual ExecutionContext* executionContext() const override final;
218 218
219 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); 219 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
220 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); 220 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
221 221
222 void startRendering(); 222 void startRendering();
223 void notifyStateChange();
224
225 // From offline rendering.
226 void fireSuspendEvent();
223 void fireCompletionEvent(); 227 void fireCompletionEvent();
224 void notifyStateChange(); 228 virtual bool suspendIfNecessary();
225 229
226 // A context is considered closed if: 230 // A context is considered closed if:
227 // - closeContext() has been called, even if the audio HW has not yet been 231 // - closeContext() has been called, even if the audio HW has not yet been
228 // stopped. It will be stopped eventually. 232 // stopped. It will be stopped eventually.
229 // - it has been stopped (or is stopping) by its execution context. 233 // - it has been stopped (or is stopping) by its execution context.
230 bool isContextClosed() const { return m_closeResolver || m_isStopScheduled | | m_isCleared; } 234 bool isContextClosed() const { return m_closeResolver || m_isStopScheduled | | m_isCleared; }
231 235
232 static unsigned s_hardwareContextCount; 236 static unsigned s_hardwareContextCount;
233 static unsigned s_contextId; 237 static unsigned s_contextId;
234 238
235 // Get the security origin for this audio context. 239 // Get the security origin for this audio context.
236 SecurityOrigin* securityOrigin() const; 240 SecurityOrigin* securityOrigin() const;
237 241
238 protected: 242 protected:
239 explicit AudioContext(Document*); 243 explicit AudioContext(Document*);
240 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); 244 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate);
241 245
242 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; 246 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver;
247 Member<AudioDestinationNode> m_destinationNode;
248 bool m_didInitializeContextGraphMutex;
249 Member<AudioBuffer> m_renderTarget;
250
251 // The state of the AudioContext.
252 void setContextState(AudioContextState);
253 AudioContextState m_contextState;
254
243 private: 255 private:
244 void initialize(); 256 void initialize();
245 void uninitialize(); 257 void uninitialize();
246 258
247 // ExecutionContext calls stop twice. 259 // ExecutionContext calls stop twice.
248 // We'd like to schedule only one stop action for them. 260 // We'd like to schedule only one stop action for them.
249 bool m_isStopScheduled; 261 bool m_isStopScheduled;
250 bool m_isCleared; 262 bool m_isCleared;
251 void clear(); 263 void clear();
252 264
253 void throwExceptionForClosedState(ExceptionState&); 265 void throwExceptionForClosedState(ExceptionState&);
254 266
255 // Set to true when the destination node has been initialized and is ready t o process data. 267 // Set to true when the destination node has been initialized and is ready t o process data.
256 bool m_isInitialized; 268 bool m_isInitialized;
257 269
258 // When the context goes away, there might still be some sources which 270 // When the context goes away, there might still be some sources which
259 // haven't finished playing. Make sure to release them here. 271 // haven't finished playing. Make sure to release them here.
260 void releaseActiveSourceNodes(); 272 void releaseActiveSourceNodes();
261 273
262 Member<AudioDestinationNode> m_destinationNode; 274
Raymond Toy 2015/05/13 17:16:08 Try not to move things around. It makes it hard t
hongchan 2015/05/13 17:30:53 Yes, this relocation was not necessary. However, t
263 Member<AudioListener> m_listener; 275 Member<AudioListener> m_listener;
264 276
265 // Only accessed in the audio thread. 277 // Only accessed in the audio thread.
266 // These raw pointers are safe because AudioSourceNodes in 278 // These raw pointers are safe because AudioSourceNodes in
267 // m_activeSourceNodes own them. 279 // m_activeSourceNodes own them.
268 Vector<AudioHandler*> m_finishedSourceHandlers; 280 Vector<AudioHandler*> m_finishedSourceHandlers;
269 281
270 // List of source nodes. This is either accessed when the graph lock is 282 // 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. 283 // held, or on the main thread when the audio thread has finished.
272 // Oilpan: This Vector holds connection references. We must call 284 // Oilpan: This Vector holds connection references. We must call
(...skipping 19 matching lines...) Expand all
292 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_suspendResolve rs; 304 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_suspendResolve rs;
293 void rejectPendingResolvers(); 305 void rejectPendingResolvers();
294 306
295 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some 307 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some
296 // time and the audio context process loop is very fast, so we don't want to call resolve an 308 // time and the audio context process loop is very fast, so we don't want to call resolve an
297 // excessive number of times. 309 // excessive number of times.
298 bool m_isResolvingResumePromises; 310 bool m_isResolvingResumePromises;
299 311
300 unsigned m_connectionCount; 312 unsigned m_connectionCount;
301 313
302 // Graph locking.
303 bool m_didInitializeContextGraphMutex;
304 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; 314 RefPtr<DeferredTaskHandler> m_deferredTaskHandler;
305 315
306 Member<AudioBuffer> m_renderTarget;
307
308 bool m_isOfflineContext; 316 bool m_isOfflineContext;
309 317
310 // The state of the AudioContext.
311 AudioContextState m_contextState;
312 void setContextState(AudioContextState);
313
314 AsyncAudioDecoder m_audioDecoder; 318 AsyncAudioDecoder m_audioDecoder;
315 319
316 // The Promise that is returned by close(); 320 // The Promise that is returned by close();
317 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver; 321 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver;
318 322
319 // Follows the destination's currentSampleFrame, but might be slightly behin d due to locking. 323 // Follows the destination's currentSampleFrame, but might be slightly behin d due to locking.
320 size_t m_cachedSampleFrame; 324 size_t m_cachedSampleFrame;
321 325
322 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never 326 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
323 // connected. Because these never get pulled anymore, they will stay around forever. So if we 327 // connected. Because these never get pulled anymore, they will stay around forever. So if we
324 // can, try to stop them so they can be collected. 328 // can, try to stop them so they can be collected.
325 void handleStoppableSourceNodes(); 329 void handleStoppableSourceNodes();
326 330
327 // This is considering 32 is large enough for multiple channels audio. 331 // This is considering 32 is large enough for multiple channels audio.
328 // It is somewhat arbitrary and could be increased if necessary. 332 // It is somewhat arbitrary and could be increased if necessary.
329 enum { MaxNumberOfChannels = 32 }; 333 enum { MaxNumberOfChannels = 32 };
330 334
331 unsigned m_contextId; 335 unsigned m_contextId;
332 }; 336 };
333 337
334 } // namespace blink 338 } // namespace blink
335 339
336 #endif // AudioContext_h 340 #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