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

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 review + layout tests 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 #endif 212 #endif
213 using AutoLocker = DeferredTaskHandler::AutoLocker; 213 using AutoLocker = DeferredTaskHandler::AutoLocker;
214 214
215 // Returns the maximum numuber of channels we can support. 215 // Returns the maximum numuber of channels we can support.
216 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} 216 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;}
217 217
218 // EventTarget 218 // EventTarget
219 virtual const AtomicString& interfaceName() const override final; 219 virtual const AtomicString& interfaceName() const override final;
220 virtual ExecutionContext* executionContext() const override final; 220 virtual ExecutionContext* executionContext() const override final;
221 221
222 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
223 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); 222 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
224 223
225 void startRendering(); 224 void startRendering();
226 void fireCompletionEvent(); 225 virtual void fireCompletionEvent();
227 void notifyStateChange(); 226 void notifyStateChange();
227 virtual bool shouldSuspendNow();
Raymond Toy 2015/05/28 16:37:35 Isn't this only used by an offline context?
hongchan 2015/06/09 20:49:59 This is used by OfflineAudioDestinatioNode. That's
Raymond Toy 2015/06/09 22:34:59 Then why not make it a private method in OfflineAu
228 228
229 // A context is considered closed if: 229 // A context is considered closed if:
230 // - closeContext() has been called, even if the audio HW has not yet been 230 // - closeContext() has been called, even if the audio HW has not yet been
231 // stopped. It will be stopped eventually. 231 // stopped. It will be stopped eventually.
232 // - it has been stopped (or is stopping) by its execution context. 232 // - it has been stopped (or is stopping) by its execution context.
233 bool isContextClosed() const { return m_closeResolver || m_isStopScheduled | | m_isCleared; } 233 bool isContextClosed() const { return m_closeResolver || m_isStopScheduled | | m_isCleared; }
234 234
235 static unsigned s_hardwareContextCount; 235 static unsigned s_hardwareContextCount;
236 static unsigned s_contextId; 236 static unsigned s_contextId;
237 237
238 // Get the security origin for this audio context. 238 // Get the security origin for this audio context.
239 SecurityOrigin* securityOrigin() const; 239 SecurityOrigin* securityOrigin() const;
240 240
241 protected: 241 protected:
242 explicit AudioContext(Document*); 242 explicit AudioContext(Document*);
243 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); 243 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate);
244 244
245 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; 245 // Shared with OfflineAudioContext.
246 void setContextState(AudioContextState);
247 bool m_didInitializeContextGraphMutex;
248 bool m_isOfflineContext;
249 Member<AudioBuffer> m_renderTarget;
250 Member<AudioDestinationNode> m_destinationNode;
Raymond Toy 2015/05/28 16:37:35 I think an offline context should use destination(
hongchan 2015/06/09 20:49:59 Seems like a good idea. Will look into it.
251
246 private: 252 private:
247 void initialize(); 253 void initialize();
248 void uninitialize(); 254 void uninitialize();
249 255
250 // ExecutionContext calls stop twice. 256 // ExecutionContext calls stop twice.
251 // We'd like to schedule only one stop action for them. 257 // We'd like to schedule only one stop action for them.
252 bool m_isStopScheduled; 258 bool m_isStopScheduled;
253 bool m_isCleared; 259 bool m_isCleared;
254 void clear(); 260 void clear();
255 261
256 void throwExceptionForClosedState(ExceptionState&); 262 void throwExceptionForClosedState(ExceptionState&);
257 263
258 // Set to true when the destination node has been initialized and is ready t o process data. 264 // Set to true when the destination node has been initialized and is ready t o process data.
259 bool m_isInitialized; 265 bool m_isInitialized;
260 266
261 // When the context goes away, there might still be some sources which 267 // When the context goes away, there might still be some sources which
262 // haven't finished playing. Make sure to release them here. 268 // haven't finished playing. Make sure to release them here.
263 void releaseActiveSourceNodes(); 269 void releaseActiveSourceNodes();
264 270
265 Member<AudioDestinationNode> m_destinationNode;
266 Member<AudioListener> m_listener; 271 Member<AudioListener> m_listener;
267 272
268 // Only accessed in the audio thread. 273 // Only accessed in the audio thread.
269 // These raw pointers are safe because AudioSourceNodes in 274 // These raw pointers are safe because AudioSourceNodes in
270 // m_activeSourceNodes own them. 275 // m_activeSourceNodes own them.
271 Vector<AudioHandler*> m_finishedSourceHandlers; 276 Vector<AudioHandler*> m_finishedSourceHandlers;
272 277
273 // List of source nodes. This is either accessed when the graph lock is 278 // List of source nodes. This is either accessed when the graph lock is
274 // held, or on the main thread when the audio thread has finished. 279 // held, or on the main thread when the audio thread has finished.
275 // Oilpan: This Vector holds connection references. We must call 280 // Oilpan: This Vector holds connection references. We must call
(...skipping 14 matching lines...) Expand all
290 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver s; 295 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver s;
291 void rejectPendingResolvers(); 296 void rejectPendingResolvers();
292 297
293 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some 298 // True if we're in the process of resolving promises for resume(). Resolvi ng can take some
294 // time and the audio context process loop is very fast, so we don't want to call resolve an 299 // time and the audio context process loop is very fast, so we don't want to call resolve an
295 // excessive number of times. 300 // excessive number of times.
296 bool m_isResolvingResumePromises; 301 bool m_isResolvingResumePromises;
297 302
298 unsigned m_connectionCount; 303 unsigned m_connectionCount;
299 304
300 // Graph locking.
Raymond Toy 2015/05/28 16:37:35 Preserve these comments with the variable that you
hongchan 2015/06/09 20:49:59 Will do!
301 bool m_didInitializeContextGraphMutex;
302 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; 305 RefPtr<DeferredTaskHandler> m_deferredTaskHandler;
303 306
304 Member<AudioBuffer> m_renderTarget;
305
306 bool m_isOfflineContext;
307
308 // The state of the AudioContext.
309 AudioContextState m_contextState; 307 AudioContextState m_contextState;
310 void setContextState(AudioContextState);
311 308
312 AsyncAudioDecoder m_audioDecoder; 309 AsyncAudioDecoder m_audioDecoder;
313 310
314 // The Promise that is returned by close(); 311 // The Promise that is returned by close();
315 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver; 312 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver;
316 313
317 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never 314 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
318 // connected. Because these never get pulled anymore, they will stay around forever. So if we 315 // connected. Because these never get pulled anymore, they will stay around forever. So if we
319 // can, try to stop them so they can be collected. 316 // can, try to stop them so they can be collected.
320 void handleStoppableSourceNodes(); 317 void handleStoppableSourceNodes();
321 318
322 // This is considering 32 is large enough for multiple channels audio. 319 // This is considering 32 is large enough for multiple channels audio.
323 // It is somewhat arbitrary and could be increased if necessary. 320 // It is somewhat arbitrary and could be increased if necessary.
324 enum { MaxNumberOfChannels = 32 }; 321 enum { MaxNumberOfChannels = 32 };
325 322
326 unsigned m_contextId; 323 unsigned m_contextId;
327 }; 324 };
328 325
329 } // namespace blink 326 } // namespace blink
330 327
331 #endif // AudioContext_h 328 #endif // AudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698