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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ChannelSplitterNode* createChannelSplitter(ExceptionState&); | 153 ChannelSplitterNode* createChannelSplitter(ExceptionState&); |
154 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception
State&); | 154 ChannelSplitterNode* createChannelSplitter(size_t numberOfOutputs, Exception
State&); |
155 ChannelMergerNode* createChannelMerger(ExceptionState&); | 155 ChannelMergerNode* createChannelMerger(ExceptionState&); |
156 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState
&); | 156 ChannelMergerNode* createChannelMerger(size_t numberOfInputs, ExceptionState
&); |
157 OscillatorNode* createOscillator(ExceptionState&); | 157 OscillatorNode* createOscillator(ExceptionState&); |
158 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima
g, ExceptionState&); | 158 PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* ima
g, ExceptionState&); |
159 | 159 |
160 // Close | 160 // Close |
161 virtual ScriptPromise closeContext(ScriptState*) = 0; | 161 virtual ScriptPromise closeContext(ScriptState*) = 0; |
162 | 162 |
163 // Suspend/Resume | 163 // Suspend for online audio context. |
164 virtual ScriptPromise suspendContext(ScriptState*) = 0; | 164 virtual ScriptPromise suspendContext(ScriptState*) = 0; |
| 165 |
| 166 // Suspend for offline audio context. |
| 167 virtual ScriptPromise suspendContext(ScriptState*, double) = 0; |
| 168 |
| 169 // Resume |
165 virtual ScriptPromise resumeContext(ScriptState*) = 0; | 170 virtual ScriptPromise resumeContext(ScriptState*) = 0; |
166 | 171 |
167 // When a source node has started processing and needs to be protected, | 172 // When a source node has started processing and needs to be protected, |
168 // this method tells the context to protect the node. | 173 // this method tells the context to protect the node. |
169 // | 174 // |
170 // The context itself keeps a reference to all source nodes. The source | 175 // The context itself keeps a reference to all source nodes. The source |
171 // nodes, then reference all nodes they're connected to. In turn, these | 176 // nodes, then reference all nodes they're connected to. In turn, these |
172 // nodes reference all nodes they're connected to. All nodes are ultimately | 177 // nodes reference all nodes they're connected to. All nodes are ultimately |
173 // connected to the AudioDestinationNode. When the context release a source | 178 // connected to the AudioDestinationNode. When the context release a source |
174 // node, it will be deactivated from the rendering graph along with all | 179 // 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... |
213 #endif | 218 #endif |
214 using AutoLocker = DeferredTaskHandler::AutoLocker; | 219 using AutoLocker = DeferredTaskHandler::AutoLocker; |
215 | 220 |
216 // Returns the maximum numuber of channels we can support. | 221 // Returns the maximum numuber of channels we can support. |
217 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} | 222 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} |
218 | 223 |
219 // EventTarget | 224 // EventTarget |
220 const AtomicString& interfaceName() const final; | 225 const AtomicString& interfaceName() const final; |
221 ExecutionContext* executionContext() const final; | 226 ExecutionContext* executionContext() const final; |
222 | 227 |
223 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | |
224 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 228 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
225 | 229 |
226 void startRendering(); | 230 void startRendering(); |
227 void fireCompletionEvent(); | |
228 void notifyStateChange(); | 231 void notifyStateChange(); |
229 | 232 |
| 233 // TODO(hongchan): move this to OfflineAudioContext. |
| 234 AudioBuffer* renderTarget() const { return m_renderTarget.get(); } |
| 235 |
230 // A context is considered closed if: | 236 // A context is considered closed if: |
231 // - closeContext() has been called. | 237 // - closeContext() has been called. |
232 // - it has been stopped by its execution context. | 238 // - it has been stopped by its execution context. |
233 virtual bool isContextClosed() const { return m_isCleared; } | 239 virtual bool isContextClosed() const { return m_isCleared; } |
234 | 240 |
235 // Get the security origin for this audio context. | 241 // Get the security origin for this audio context. |
236 SecurityOrigin* securityOrigin() const; | 242 SecurityOrigin* securityOrigin() const; |
237 | 243 |
238 protected: | 244 protected: |
239 explicit AbstractAudioContext(Document*); | 245 explicit AbstractAudioContext(Document*); |
240 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr
ames, float sampleRate); | 246 AbstractAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFr
ames, float sampleRate); |
241 | 247 |
242 void setContextState(AudioContextState); | 248 void setContextState(AudioContextState); |
243 virtual void didClose() {} | 249 virtual void didClose() {} |
244 void uninitialize(); | 250 void uninitialize(); |
245 | 251 |
246 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; | |
247 | |
248 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only | 252 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only |
249 // it creates these Promises. | 253 // it creates these Promises. |
250 // Vector of promises created by resume(). It takes time to handle them, so
we collect all of | 254 // Vector of promises created by resume(). It takes time to handle them, so
we collect all of |
251 // the promises here until they can be resolved or rejected. | 255 // the promises here until they can be resolved or rejected. |
252 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver
s; | 256 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_resumeResolver
s; |
253 private: | 257 private: |
254 void initialize(); | 258 void initialize(); |
255 | 259 |
256 bool m_isCleared; | 260 bool m_isCleared; |
257 void clear(); | 261 void clear(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // time and the audio context process loop is very fast, so we don't want to
call resolve an | 297 // time and the audio context process loop is very fast, so we don't want to
call resolve an |
294 // excessive number of times. | 298 // excessive number of times. |
295 bool m_isResolvingResumePromises; | 299 bool m_isResolvingResumePromises; |
296 | 300 |
297 unsigned m_connectionCount; | 301 unsigned m_connectionCount; |
298 | 302 |
299 // Graph locking. | 303 // Graph locking. |
300 bool m_didInitializeContextGraphMutex; | 304 bool m_didInitializeContextGraphMutex; |
301 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; | 305 RefPtr<DeferredTaskHandler> m_deferredTaskHandler; |
302 | 306 |
| 307 // For offline audio context. |
| 308 // TODO(hongchan): move this to OfflineAudioContext class. |
303 Member<AudioBuffer> m_renderTarget; | 309 Member<AudioBuffer> m_renderTarget; |
304 | 310 |
305 // The state of the AbstractAudioContext. | 311 // The state of the AbstractAudioContext. |
306 AudioContextState m_contextState; | 312 AudioContextState m_contextState; |
307 | 313 |
308 AsyncAudioDecoder m_audioDecoder; | 314 AsyncAudioDecoder m_audioDecoder; |
309 | 315 |
310 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never | 316 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never |
311 // connected. Because these never get pulled anymore, they will stay around
forever. So if we | 317 // connected. Because these never get pulled anymore, they will stay around
forever. So if we |
312 // can, try to stop them so they can be collected. | 318 // can, try to stop them so they can be collected. |
313 void handleStoppableSourceNodes(); | 319 void handleStoppableSourceNodes(); |
314 | 320 |
| 321 // Perform common tasks after the render quantum. Called by handlePostRender
Tasks(). |
| 322 void performPostRenderTasks(); |
| 323 |
315 // This is considering 32 is large enough for multiple channels audio. | 324 // This is considering 32 is large enough for multiple channels audio. |
316 // It is somewhat arbitrary and could be increased if necessary. | 325 // It is somewhat arbitrary and could be increased if necessary. |
317 enum { MaxNumberOfChannels = 32 }; | 326 enum { MaxNumberOfChannels = 32 }; |
318 }; | 327 }; |
319 | 328 |
320 } // namespace blink | 329 } // namespace blink |
321 | 330 |
322 #endif // AbstractAudioContext_h | 331 #endif // AbstractAudioContext_h |
OLD | NEW |