| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 // Returns the maximum numuber of channels we can support. | 238 // Returns the maximum numuber of channels we can support. |
| 239 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} | 239 static unsigned maxNumberOfChannels() { return MaxNumberOfChannels;} |
| 240 | 240 |
| 241 // EventTarget | 241 // EventTarget |
| 242 const AtomicString& interfaceName() const final; | 242 const AtomicString& interfaceName() const final; |
| 243 ExecutionContext* getExecutionContext() const final; | 243 ExecutionContext* getExecutionContext() const final; |
| 244 | 244 |
| 245 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 245 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
| 246 | 246 |
| 247 // Start the AudioContext. `isAllowedToStart()` MUST be called before. |
| 247 void startRendering(); | 248 void startRendering(); |
| 249 |
| 248 void notifyStateChange(); | 250 void notifyStateChange(); |
| 249 | 251 |
| 250 // A context is considered closed if: | 252 // A context is considered closed if: |
| 251 // - closeContext() has been called. | 253 // - closeContext() has been called. |
| 252 // - it has been stopped by its execution context. | 254 // - it has been stopped by its execution context. |
| 253 virtual bool isContextClosed() const { return m_isCleared; } | 255 virtual bool isContextClosed() const { return m_isCleared; } |
| 254 | 256 |
| 255 // Get the security origin for this audio context. | 257 // Get the security origin for this audio context. |
| 256 SecurityOrigin* getSecurityOrigin() const; | 258 SecurityOrigin* getSecurityOrigin() const; |
| 257 | 259 |
| 258 // Get the PeriodicWave for the specified oscillator type. The table is ini
tialized internally | 260 // Get the PeriodicWave for the specified oscillator type. The table is ini
tialized internally |
| 259 // if necessary. | 261 // if necessary. |
| 260 PeriodicWave* periodicWave(int type); | 262 PeriodicWave* periodicWave(int type); |
| 261 | 263 |
| 262 // Check whether the AudioContext requires a user gesture and whether the | |
| 263 // current stack is processing user gesture and record these information in | |
| 264 // a histogram. | |
| 265 void recordUserGestureState(); | |
| 266 | |
| 267 protected: | 264 protected: |
| 268 explicit BaseAudioContext(Document*); | 265 explicit BaseAudioContext(Document*); |
| 269 BaseAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames
, float sampleRate); | 266 BaseAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames
, float sampleRate); |
| 270 | 267 |
| 271 void initialize(); | 268 void initialize(); |
| 272 void uninitialize(); | 269 void uninitialize(); |
| 273 | 270 |
| 274 void setContextState(AudioContextState); | 271 void setContextState(AudioContextState); |
| 275 | 272 |
| 276 virtual void didClose() {} | 273 virtual void didClose() {} |
| 277 | 274 |
| 278 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never | 275 // Tries to handle AudioBufferSourceNodes that were started but became disco
nnected or was never |
| 279 // connected. Because these never get pulled anymore, they will stay around
forever. So if we | 276 // connected. Because these never get pulled anymore, they will stay around
forever. So if we |
| 280 // can, try to stop them so they can be collected. | 277 // can, try to stop them so they can be collected. |
| 281 void handleStoppableSourceNodes(); | 278 void handleStoppableSourceNodes(); |
| 282 | 279 |
| 283 Member<AudioDestinationNode> m_destinationNode; | 280 Member<AudioDestinationNode> m_destinationNode; |
| 284 | 281 |
| 285 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only | 282 // FIXME(dominicc): Move m_resumeResolvers to AudioContext, because only |
| 286 // it creates these Promises. | 283 // it creates these Promises. |
| 287 // Vector of promises created by resume(). It takes time to handle them, so
we collect all of | 284 // Vector of promises created by resume(). It takes time to handle them, so
we collect all of |
| 288 // the promises here until they can be resolved or rejected. | 285 // the promises here until they can be resolved or rejected. |
| 289 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers; | 286 HeapVector<Member<ScriptPromiseResolver>> m_resumeResolvers; |
| 290 | 287 |
| 291 void setClosedContextSampleRate(float newSampleRate) { m_closedContextSample
Rate = newSampleRate; } | 288 void setClosedContextSampleRate(float newSampleRate) { m_closedContextSample
Rate = newSampleRate; } |
| 292 float closedContextSampleRate() const { return m_closedContextSampleRate; } | 289 float closedContextSampleRate() const { return m_closedContextSampleRate; } |
| 293 | 290 |
| 294 void rejectPendingDecodeAudioDataResolvers(); | 291 void rejectPendingDecodeAudioDataResolvers(); |
| 295 | 292 |
| 293 // If any, unlock user gesture requirements if a user gesture is being |
| 294 // processed. |
| 295 void maybeUnlockUserGesture(); |
| 296 |
| 297 // Returns whether the AudioContext is allowed to start rendering. |
| 298 bool isAllowedToStart() const; |
| 299 |
| 296 private: | 300 private: |
| 297 bool m_isCleared; | 301 bool m_isCleared; |
| 298 void clear(); | 302 void clear(); |
| 299 | 303 |
| 300 // When the context goes away, there might still be some sources which | 304 // When the context goes away, there might still be some sources which |
| 301 // haven't finished playing. Make sure to release them here. | 305 // haven't finished playing. Make sure to release them here. |
| 302 void releaseActiveSourceNodes(); | 306 void releaseActiveSourceNodes(); |
| 303 | 307 |
| 304 void removeFinishedSourceNodes(); | 308 void removeFinishedSourceNodes(); |
| 305 | 309 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 Member<PeriodicWave> m_periodicWaveTriangle; | 374 Member<PeriodicWave> m_periodicWaveTriangle; |
| 371 | 375 |
| 372 // This is considering 32 is large enough for multiple channels audio. | 376 // This is considering 32 is large enough for multiple channels audio. |
| 373 // It is somewhat arbitrary and could be increased if necessary. | 377 // It is somewhat arbitrary and could be increased if necessary. |
| 374 enum { MaxNumberOfChannels = 32 }; | 378 enum { MaxNumberOfChannels = 32 }; |
| 375 }; | 379 }; |
| 376 | 380 |
| 377 } // namespace blink | 381 } // namespace blink |
| 378 | 382 |
| 379 #endif // BaseAudioContext_h | 383 #endif // BaseAudioContext_h |
| OLD | NEW |