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

Side by Side Diff: Source/modules/webaudio/AudioContext.h

Issue 1006963003: AudioContext.decodeAudioData returns a Promise (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update for review Created 5 years, 8 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 | Annotate | Revision Log
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 size_t currentSampleFrame() const; 230 size_t currentSampleFrame() const;
231 double currentTime() const; 231 double currentTime() const;
232 232
233 float sampleRate() const { return m_destinationNode ? m_destinationNode->han dler().sampleRate() : 0; } 233 float sampleRate() const { return m_destinationNode ? m_destinationNode->han dler().sampleRate() : 0; }
234 234
235 String state() const; 235 String state() const;
236 236
237 AudioBuffer* createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&); 237 AudioBuffer* createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&);
238 238
239 // Asynchronous audio file data decoding. 239 // Asynchronous audio file data decoding.
240 void decodeAudioData(DOMArrayBuffer*, AudioBufferCallback*, AudioBufferCallb ack*, ExceptionState&); 240 ScriptPromise decodeAudioData(ScriptState*, DOMArrayBuffer*, AudioBufferCall back*, AudioBufferCallback*, ExceptionState&);
241 241
242 AudioListener* listener() { return m_listener.get(); } 242 AudioListener* listener() { return m_listener.get(); }
243 243
244 // The AudioNode create methods are called on the main thread (from JavaScri pt). 244 // The AudioNode create methods are called on the main thread (from JavaScri pt).
245 AudioBufferSourceNode* createBufferSource(ExceptionState&); 245 AudioBufferSourceNode* createBufferSource(ExceptionState&);
246 MediaElementAudioSourceNode* createMediaElementSource(HTMLMediaElement*, Exc eptionState&); 246 MediaElementAudioSourceNode* createMediaElementSource(HTMLMediaElement*, Exc eptionState&);
247 MediaStreamAudioSourceNode* createMediaStreamSource(MediaStream*, ExceptionS tate&); 247 MediaStreamAudioSourceNode* createMediaStreamSource(MediaStream*, ExceptionS tate&);
248 MediaStreamAudioDestinationNode* createMediaStreamDestination(ExceptionState &); 248 MediaStreamAudioDestinationNode* createMediaStreamDestination(ExceptionState &);
249 GainNode* createGain(ExceptionState&); 249 GainNode* createGain(ExceptionState&);
250 BiquadFilterNode* createBiquadFilter(ExceptionState&); 250 BiquadFilterNode* createBiquadFilter(ExceptionState&);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // A context is considered closed if closeContext() has been called, even if the audio HW has 341 // A context is considered closed if closeContext() has been called, even if the audio HW has
342 // not yet been stopped. It will be stopped eventually. 342 // not yet been stopped. It will be stopped eventually.
343 bool isContextClosed() const { return m_closeResolver; } 343 bool isContextClosed() const { return m_closeResolver; }
344 344
345 static unsigned s_hardwareContextCount; 345 static unsigned s_hardwareContextCount;
346 static unsigned s_contextId; 346 static unsigned s_contextId;
347 347
348 // Get the security origin for this audio context. 348 // Get the security origin for this audio context.
349 SecurityOrigin* securityOrigin() const; 349 SecurityOrigin* securityOrigin() const;
350 350
351 void removeAudioDecoderResolver(ScriptPromiseResolver*);
351 protected: 352 protected:
352 explicit AudioContext(Document*); 353 explicit AudioContext(Document*);
353 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate); 354 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl oat sampleRate);
354 355
355 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; 356 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver;
356 private: 357 private:
357 void initialize(); 358 void initialize();
358 void uninitialize(); 359 void uninitialize();
359 360
360 // ExecutionContext calls stop twice. 361 // ExecutionContext calls stop twice.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 428
428 Member<AudioBuffer> m_renderTarget; 429 Member<AudioBuffer> m_renderTarget;
429 430
430 bool m_isOfflineContext; 431 bool m_isOfflineContext;
431 432
432 // The state of the AudioContext. 433 // The state of the AudioContext.
433 AudioContextState m_contextState; 434 AudioContextState m_contextState;
434 void setContextState(AudioContextState); 435 void setContextState(AudioContextState);
435 436
436 AsyncAudioDecoder m_audioDecoder; 437 AsyncAudioDecoder m_audioDecoder;
438 // A vector of the ScriptPromiseResolvers the decodeAudioData method uses.
439 WillBeHeapVector<RefPtrWillBeMember<ScriptPromiseResolver>> m_audioDecoderRe solvers;
437 440
438 // The Promise that is returned by close(); 441 // The Promise that is returned by close();
439 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver; 442 RefPtrWillBeMember<ScriptPromiseResolver> m_closeResolver;
440 443
441 // Follows the destination's currentSampleFrame, but might be slightly behin d due to locking. 444 // Follows the destination's currentSampleFrame, but might be slightly behin d due to locking.
442 size_t m_cachedSampleFrame; 445 size_t m_cachedSampleFrame;
443 446
447 // When a context is closed, the sample rate is cleared. But decodeAudioDat a can be called
448 // after the context has been closed and it needs the sample rate. When the context is closed,
449 // the sample rate is saved here.
450 float m_closedContextSampleRate;
451
444 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never 452 // Tries to handle AudioBufferSourceNodes that were started but became disco nnected or was never
445 // connected. Because these never get pulled anymore, they will stay around forever. So if we 453 // connected. Because these never get pulled anymore, they will stay around forever. So if we
446 // can, try to stop them so they can be collected. 454 // can, try to stop them so they can be collected.
447 void handleStoppableSourceNodes(); 455 void handleStoppableSourceNodes();
448 456
449 // This is considering 32 is large enough for multiple channels audio. 457 // This is considering 32 is large enough for multiple channels audio.
450 // It is somewhat arbitrary and could be increased if necessary. 458 // It is somewhat arbitrary and could be increased if necessary.
451 enum { MaxNumberOfChannels = 32 }; 459 enum { MaxNumberOfChannels = 32 };
452 460
453 unsigned m_contextId; 461 unsigned m_contextId;
454 }; 462 };
455 463
456 } // namespace blink 464 } // namespace blink
457 465
458 #endif // AudioContext_h 466 #endif // AudioContext_h
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioBufferCallback.idl ('k') | Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698