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 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
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 14 matching lines...) Expand all Loading... |
287 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver
s; | 299 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver
s; |
288 void rejectPendingResolvers(); | 300 void rejectPendingResolvers(); |
289 | 301 |
290 // True if we're in the process of resolving promises for resume(). Resolvi
ng can take some | 302 // True if we're in the process of resolving promises for resume(). Resolvi
ng can take some |
291 // time and the audio context process loop is very fast, so we don't want to
call resolve an | 303 // time and the audio context process loop is very fast, so we don't want to
call resolve an |
292 // excessive number of times. | 304 // excessive number of times. |
293 bool m_isResolvingResumePromises; | 305 bool m_isResolvingResumePromises; |
294 | 306 |
295 unsigned m_connectionCount; | 307 unsigned m_connectionCount; |
296 | 308 |
297 // Graph locking. | |
298 bool m_didInitializeContextGraphMutex; | |
299 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; | 309 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; |
300 | 310 |
301 Member<AudioBuffer> m_renderTarget; | |
302 | |
303 bool m_isOfflineContext; | 311 bool m_isOfflineContext; |
304 | 312 |
305 // The state of the AudioContext. | |
306 AudioContextState m_contextState; | |
307 void setContextState(AudioContextState); | |
308 | |
309 AsyncAudioDecoder m_audioDecoder; | 313 AsyncAudioDecoder m_audioDecoder; |
310 | 314 |
311 // The Promise that is returned by close(); | 315 // The Promise that is returned by close(); |
312 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver; | 316 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver; |
313 | 317 |
314 // Follows the destination's currentSampleFrame, but might be slightly behin
d due to locking. | 318 // Follows the destination's currentSampleFrame, but might be slightly behin
d due to locking. |
315 size_t m_cachedSampleFrame; | 319 size_t m_cachedSampleFrame; |
316 | 320 |
317 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never | 321 // 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 | 322 // 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. | 323 // can, try to stop them so they can be collected. |
320 void handleStoppableSourceNodes(); | 324 void handleStoppableSourceNodes(); |
321 | 325 |
322 // This is considering 32 is large enough for multiple channels audio. | 326 // This is considering 32 is large enough for multiple channels audio. |
323 // It is somewhat arbitrary and could be increased if necessary. | 327 // It is somewhat arbitrary and could be increased if necessary. |
324 enum { MaxNumberOfChannels = 32 }; | 328 enum { MaxNumberOfChannels = 32 }; |
325 | 329 |
326 unsigned m_contextId; | 330 unsigned m_contextId; |
327 }; | 331 }; |
328 | 332 |
329 } // namespace blink | 333 } // namespace blink |
330 | 334 |
331 #endif // AudioContext_h | 335 #endif // AudioContext_h |
OLD | NEW |