| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 171 virtual ScriptPromise suspendContext(ScriptState*) = 0; | 171 virtual ScriptPromise suspendContext(ScriptState*) = 0; |
| 172 |
| 173 // Resume |
| 172 virtual ScriptPromise resumeContext(ScriptState*) = 0; | 174 virtual ScriptPromise resumeContext(ScriptState*) = 0; |
| 173 | 175 |
| 174 // When a source node has started processing and needs to be protected, | 176 // When a source node has started processing and needs to be protected, |
| 175 // this method tells the context to protect the node. | 177 // this method tells the context to protect the node. |
| 176 // | 178 // |
| 177 // The context itself keeps a reference to all source nodes. The source | 179 // 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 | 180 // 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 | 181 // nodes reference all nodes they're connected to. All nodes are ultimately |
| 180 // connected to the AudioDestinationNode. When the context release a source | 182 // connected to the AudioDestinationNode. When the context release a source |
| 181 // node, it will be deactivated from the rendering graph along with all | 183 // node, it will be deactivated from the rendering graph along with all |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 #endif | 222 #endif |
| 221 using AutoLocker = DeferredTaskHandler::AutoLocker; | 223 using AutoLocker = DeferredTaskHandler::AutoLocker; |
| 222 | 224 |
| 223 // Returns the maximum numuber of channels we can support. | 225 // Returns the maximum numuber of channels we can support. |
| 224 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} | 226 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} |
| 225 | 227 |
| 226 // EventTarget | 228 // EventTarget |
| 227 const AtomicString& interfaceName() const final; | 229 const AtomicString& interfaceName() const final; |
| 228 ExecutionContext* executionContext() const final; | 230 ExecutionContext* executionContext() const final; |
| 229 | 231 |
| 230 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | |
| 231 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 232 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
| 232 | 233 |
| 233 void startRendering(); | 234 void startRendering(); |
| 234 void fireCompletionEvent(); | |
| 235 void notifyStateChange(); | 235 void notifyStateChange(); |
| 236 | 236 |
| 237 // A context is considered closed if: | 237 // A context is considered closed if: |
| 238 // - closeContext() has been called. | 238 // - closeContext() has been called. |
| 239 // - it has been stopped by its execution context. | 239 // - it has been stopped by its execution context. |
| 240 virtual bool isContextClosed() const { return m_isCleared; } | 240 virtual bool isContextClosed() const { return m_isCleared; } |
| 241 | 241 |
| 242 // Get the security origin for this audio context. | 242 // Get the security origin for this audio context. |
| 243 SecurityOrigin* securityOrigin() const; | 243 SecurityOrigin* securityOrigin() const; |
| 244 | 244 |
| 245 protected: | 245 protected: |
| 246 explicit AbstractAudioContext(Document*); | 246 explicit AbstractAudioContext(Document*); |
| 247 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr
ames, float sampleRate); | 247 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr
ames, float sampleRate); |
| 248 | 248 |
| 249 void setContextState(AudioContextState); | 249 void initialize(); |
| 250 virtual void didClose() {} | |
| 251 void uninitialize(); | 250 void uninitialize(); |
| 252 | 251 |
| 253 Member<ScriptPromiseResolver> m_offlineResolver; | 252 void setContextState(AudioContextState); |
| 253 |
| 254 virtual void didClose() {} |
| 255 |
| 256 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never |
| 257 // connected. Because these never get pulled anymore, they will stay around
forever. So if we |
| 258 // can, try to stop them so they can be collected. |
| 259 void handleStoppableSourceNodes(); |
| 260 |
| 261 Member<AudioDestinationNode> m_destinationNode; |
| 254 | 262 |
| 255 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only | 263 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only |
| 256 // it creates these Promises. | 264 // it creates these Promises. |
| 257 // Vector of promises created by resume(). It takes time to handle them, so
we collect all of | 265 // 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. | 266 // the promises here until they can be resolved or rejected. |
| 259 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers; | 267 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers; |
| 268 |
| 260 private: | 269 private: |
| 261 void initialize(); | |
| 262 | |
| 263 bool m_isCleared; | 270 bool m_isCleared; |
| 264 void clear(); | 271 void clear(); |
| 265 | 272 |
| 266 void throwExceptionForClosedState(ExceptionState&); | 273 void throwExceptionForClosedState(ExceptionState&); |
| 267 | 274 |
| 268 // When the context goes away, there might still be some sources which | 275 // When the context goes away, there might still be some sources which |
| 269 // haven't finished playing. Make sure to release them here. | 276 // haven't finished playing. Make sure to release them here. |
| 270 void releaseActiveSourceNodes(); | 277 void releaseActiveSourceNodes(); |
| 271 | 278 |
| 272 Member<AudioDestinationNode> m_destinationNode; | |
| 273 Member<AudioListener> m_listener; | 279 Member<AudioListener> m_listener; |
| 274 | 280 |
| 275 // Only accessed in the audio thread. | 281 // Only accessed in the audio thread. |
| 276 // These raw pointers are safe because AudioSourceNodes in | 282 // These raw pointers are safe because AudioSourceNodes in |
| 277 // m_activeSourceNodes own them. | 283 // m_activeSourceNodes own them. |
| 278 Vector<AudioHandler*> m_finishedSourceHandlers; | 284 Vector<AudioHandler*> m_finishedSourceHandlers; |
| 279 | 285 |
| 280 // List of source nodes. This is either accessed when the graph lock is | 286 // 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. | 287 // held, or on the main thread when the audio thread has finished. |
| 282 // Oilpan: This Vector holds connection references. We must call | 288 // Oilpan: This Vector holds connection references. We must call |
| (...skipping 14 matching lines...) Expand all Loading... |
| 297 // 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 |
| 298 // excessive number of times. | 304 // excessive number of times. |
| 299 bool m_isResolvingResumePromises; | 305 bool m_isResolvingResumePromises; |
| 300 | 306 |
| 301 unsigned m_connectionCount; | 307 unsigned m_connectionCount; |
| 302 | 308 |
| 303 // Graph locking. | 309 // Graph locking. |
| 304 bool m_didInitializeContextGraphMutex; | 310 bool m_didInitializeContextGraphMutex; |
| 305 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; | 311 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; |
| 306 | 312 |
| 307 Member<AudioBuffer> m_renderTarget; | |
| 308 | |
| 309 // The state of the AbstractAudioContext. | 313 // The state of the AbstractAudioContext. |
| 310 AudioContextState m_contextState; | 314 AudioContextState m_contextState; |
| 311 | 315 |
| 312 AsyncAudioDecoder m_audioDecoder; | 316 AsyncAudioDecoder m_audioDecoder; |
| 313 | 317 |
| 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(); | |
| 318 | |
| 319 // This is considering 32 is large enough for multiple channels audio. | 318 // This is considering 32 is large enough for multiple channels audio. |
| 320 // It is somewhat arbitrary and could be increased if necessary. | 319 // It is somewhat arbitrary and could be increased if necessary. |
| 321 enum { MaxNumberOfChannels = 32 }; | 320 enum { MaxNumberOfChannels = 32 }; |
| 322 }; | 321 }; |
| 323 | 322 |
| 324 } // namespace blink | 323 } // namespace blink |
| 325 | 324 |
| 326 #endif // AbstractAudioContext_h | 325 #endif // AbstractAudioContext_h |
| OLD | NEW |