Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef AudioContext_h | 25 #ifndef AudioContext_h |
| 26 #define AudioContext_h | 26 #define AudioContext_h |
| 27 | 27 |
| 28 #include "bindings/v8/ScriptWrappable.h" | 28 #include "bindings/v8/ScriptWrappable.h" |
| 29 #include "core/dom/ActiveDOMObject.h" | 29 #include "core/dom/ActiveDOMObject.h" |
| 30 #include "core/events/EventListener.h" | 30 #include "core/events/EventListener.h" |
| 31 #include "core/events/EventTarget.h" | 31 #include "core/events/EventTarget.h" |
| 32 #include "platform/audio/AudioBus.h" | |
| 33 #include "modules/webaudio/AsyncAudioDecoder.h" | 32 #include "modules/webaudio/AsyncAudioDecoder.h" |
| 34 #include "modules/webaudio/AudioDestinationNode.h" | 33 #include "modules/webaudio/AudioDestinationNode.h" |
| 34 #include "platform/audio/AudioBus.h" | |
| 35 #include "platform/heap/Handle.h" | |
| 35 #include "wtf/HashSet.h" | 36 #include "wtf/HashSet.h" |
| 36 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
| 37 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
| 38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 39 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 41 #include "wtf/ThreadSafeRefCounted.h" | 42 #include "wtf/ThreadSafeRefCounted.h" |
| 42 #include "wtf/Threading.h" | 43 #include "wtf/Threading.h" |
| 43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 44 #include "wtf/text/AtomicStringHash.h" | 45 #include "wtf/text/AtomicStringHash.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 66 class MediaStreamAudioSourceNode; | 67 class MediaStreamAudioSourceNode; |
| 67 class OscillatorNode; | 68 class OscillatorNode; |
| 68 class PannerNode; | 69 class PannerNode; |
| 69 class PeriodicWave; | 70 class PeriodicWave; |
| 70 class ScriptProcessorNode; | 71 class ScriptProcessorNode; |
| 71 class WaveShaperNode; | 72 class WaveShaperNode; |
| 72 | 73 |
| 73 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. | 74 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. |
| 74 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. | 75 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. |
| 75 | 76 |
| 76 class AudioContext : public ActiveDOMObject, public ScriptWrappable, public Thre adSafeRefCounted<AudioContext>, public EventTargetWithInlineData { | 77 class AudioContext : public ThreadSafeRefCountedWillBeThreadSafeRefCountedGarbag eCollected<AudioContext>, public ActiveDOMObject, public ScriptWrappable, public EventTargetWithInlineData { |
| 77 DEFINE_EVENT_TARGET_REFCOUNTING(ThreadSafeRefCounted<AudioContext>); | 78 DEFINE_EVENT_TARGET_REFCOUNTING(ThreadSafeRefCountedWillBeThreadSafeRefCount edGarbageCollected<AudioContext>); |
| 78 public: | 79 public: |
| 79 // Create an AudioContext for rendering to the audio hardware. | 80 // Create an AudioContext for rendering to the audio hardware. |
| 80 static PassRefPtr<AudioContext> create(Document&, ExceptionState&); | 81 static PassRefPtrWillBeRawPtr<AudioContext> create(Document&, ExceptionState &); |
| 81 | 82 |
| 82 virtual ~AudioContext(); | 83 virtual ~AudioContext(); |
| 83 | 84 |
| 85 virtual void trace(Visitor*); | |
| 86 | |
| 84 bool isInitialized() const; | 87 bool isInitialized() const; |
| 85 // The constructor of an AudioNode must call this to initialize the context. | 88 // The constructor of an AudioNode must call this to initialize the context. |
| 86 void lazyInitialize(); | 89 void lazyInitialize(); |
| 87 | 90 |
| 88 bool isOfflineContext() { return m_isOfflineContext; } | 91 bool isOfflineContext() { return m_isOfflineContext; } |
| 89 | 92 |
| 90 // Document notification | 93 // Document notification |
| 91 virtual void stop() OVERRIDE FINAL; | 94 virtual void stop() OVERRIDE FINAL; |
| 92 virtual bool hasPendingActivity() const OVERRIDE; | 95 virtual bool hasPendingActivity() const OVERRIDE; |
| 93 | 96 |
| 94 AudioDestinationNode* destination() { return m_destinationNode.get(); } | 97 AudioDestinationNode* destination() { return m_destinationNode.get(); } |
| 95 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); } | 98 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF rame(); } |
| 96 double currentTime() const { return m_destinationNode->currentTime(); } | 99 double currentTime() const { return m_destinationNode->currentTime(); } |
| 97 float sampleRate() const { return m_destinationNode->sampleRate(); } | 100 float sampleRate() const { return m_destinationNode->sampleRate(); } |
| 98 | 101 |
| 99 PassRefPtr<AudioBuffer> createBuffer(unsigned numberOfChannels, size_t numbe rOfFrames, float sampleRate, ExceptionState&); | 102 PassRefPtrWillBeRawPtr<AudioBuffer> createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&); |
| 100 | 103 |
| 101 // Asynchronous audio file data decoding. | 104 // Asynchronous audio file data decoding. |
| 102 void decodeAudioData(ArrayBuffer*, PassOwnPtr<AudioBufferCallback>, PassOwnP tr<AudioBufferCallback>, ExceptionState&); | 105 void decodeAudioData(ArrayBuffer*, PassOwnPtr<AudioBufferCallback>, PassOwnP tr<AudioBufferCallback>, ExceptionState&); |
| 103 | 106 |
| 104 AudioListener* listener() { return m_listener.get(); } | 107 AudioListener* listener() { return m_listener.get(); } |
| 105 | 108 |
| 106 // The AudioNode create methods are called on the main thread (from JavaScri pt). | 109 // The AudioNode create methods are called on the main thread (from JavaScri pt). |
| 107 PassRefPtr<AudioBufferSourceNode> createBufferSource(); | 110 PassRefPtrWillBeRawPtr<AudioBufferSourceNode> createBufferSource(); |
| 108 PassRefPtr<MediaElementAudioSourceNode> createMediaElementSource(HTMLMediaEl ement*, ExceptionState&); | 111 PassRefPtrWillBeRawPtr<MediaElementAudioSourceNode> createMediaElementSource (HTMLMediaElement*, ExceptionState&); |
| 109 PassRefPtr<MediaStreamAudioSourceNode> createMediaStreamSource(MediaStream*, ExceptionState&); | 112 PassRefPtrWillBeRawPtr<MediaStreamAudioSourceNode> createMediaStreamSource(M ediaStream*, ExceptionState&); |
| 110 PassRefPtr<MediaStreamAudioDestinationNode> createMediaStreamDestination(); | 113 PassRefPtrWillBeRawPtr<MediaStreamAudioDestinationNode> createMediaStreamDes tination(); |
| 111 PassRefPtr<GainNode> createGain(); | 114 PassRefPtrWillBeRawPtr<GainNode> createGain(); |
| 112 PassRefPtr<BiquadFilterNode> createBiquadFilter(); | 115 PassRefPtrWillBeRawPtr<BiquadFilterNode> createBiquadFilter(); |
| 113 PassRefPtr<WaveShaperNode> createWaveShaper(); | 116 PassRefPtrWillBeRawPtr<WaveShaperNode> createWaveShaper(); |
| 114 PassRefPtr<DelayNode> createDelay(ExceptionState&); | 117 PassRefPtrWillBeRawPtr<DelayNode> createDelay(ExceptionState&); |
| 115 PassRefPtr<DelayNode> createDelay(double maxDelayTime, ExceptionState&); | 118 PassRefPtrWillBeRawPtr<DelayNode> createDelay(double maxDelayTime, Exception State&); |
| 116 PassRefPtr<PannerNode> createPanner(); | 119 PassRefPtrWillBeRawPtr<PannerNode> createPanner(); |
| 117 PassRefPtr<ConvolverNode> createConvolver(); | 120 PassRefPtrWillBeRawPtr<ConvolverNode> createConvolver(); |
| 118 PassRefPtr<DynamicsCompressorNode> createDynamicsCompressor(); | 121 PassRefPtrWillBeRawPtr<DynamicsCompressorNode> createDynamicsCompressor(); |
| 119 PassRefPtr<AnalyserNode> createAnalyser(); | 122 PassRefPtrWillBeRawPtr<AnalyserNode> createAnalyser(); |
| 120 PassRefPtr<ScriptProcessorNode> createScriptProcessor(ExceptionState&); | 123 PassRefPtrWillBeRawPtr<ScriptProcessorNode> createScriptProcessor(ExceptionS tate&); |
| 121 PassRefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, Exc eptionState&); | 124 PassRefPtrWillBeRawPtr<ScriptProcessorNode> createScriptProcessor(size_t buf ferSize, ExceptionState&); |
| 122 PassRefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, siz e_t numberOfInputChannels, ExceptionState&); | 125 PassRefPtrWillBeRawPtr<ScriptProcessorNode> createScriptProcessor(size_t buf ferSize, size_t numberOfInputChannels, ExceptionState&); |
| 123 PassRefPtr<ScriptProcessorNode> createScriptProcessor(size_t bufferSize, siz e_t numberOfInputChannels, size_t numberOfOutputChannels, ExceptionState&); | 126 PassRefPtrWillBeRawPtr<ScriptProcessorNode> createScriptProcessor(size_t buf ferSize, size_t numberOfInputChannels, size_t numberOfOutputChannels, ExceptionS tate&); |
| 124 PassRefPtr<ChannelSplitterNode> createChannelSplitter(ExceptionState&); | 127 PassRefPtrWillBeRawPtr<ChannelSplitterNode> createChannelSplitter(ExceptionS tate&); |
| 125 PassRefPtr<ChannelSplitterNode> createChannelSplitter(size_t numberOfOutputs , ExceptionState&); | 128 PassRefPtrWillBeRawPtr<ChannelSplitterNode> createChannelSplitter(size_t num berOfOutputs, ExceptionState&); |
| 126 PassRefPtr<ChannelMergerNode> createChannelMerger(ExceptionState&); | 129 PassRefPtrWillBeRawPtr<ChannelMergerNode> createChannelMerger(ExceptionState &); |
| 127 PassRefPtr<ChannelMergerNode> createChannelMerger(size_t numberOfInputs, Exc eptionState&); | 130 PassRefPtrWillBeRawPtr<ChannelMergerNode> createChannelMerger(size_t numberO fInputs, ExceptionState&); |
| 128 PassRefPtr<OscillatorNode> createOscillator(); | 131 PassRefPtrWillBeRawPtr<OscillatorNode> createOscillator(); |
| 129 PassRefPtr<PeriodicWave> createPeriodicWave(Float32Array* real, Float32Array * imag, ExceptionState&); | 132 PassRefPtrWillBeRawPtr<PeriodicWave> createPeriodicWave(Float32Array* real, Float32Array* imag, ExceptionState&); |
| 130 | 133 |
| 131 // When a source node has no more processing to do (has finished playing), t hen it tells the context to dereference it. | 134 // When a source node has no more processing to do (has finished playing), t hen it tells the context to dereference it. |
| 132 void notifyNodeFinishedProcessing(AudioNode*); | 135 void notifyNodeFinishedProcessing(AudioNode*); |
| 133 | 136 |
| 134 // Called at the start of each render quantum. | 137 // Called at the start of each render quantum. |
| 135 void handlePreRenderTasks(); | 138 void handlePreRenderTasks(); |
| 136 | 139 |
| 137 // Called at the end of each render quantum. | 140 // Called at the end of each render quantum. |
| 138 void handlePostRenderTasks(); | 141 void handlePostRenderTasks(); |
| 139 | 142 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 // In turn, these nodes reference all nodes they're connected to. All nodes are ultimately connected to the AudioDestinationNode. | 262 // In turn, these nodes reference all nodes they're connected to. All nodes are ultimately connected to the AudioDestinationNode. |
| 260 // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is | 263 // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is |
| 261 // uniquely connected to. See the AudioNode::ref() and AudioNode::deref() m ethods for more details. | 264 // uniquely connected to. See the AudioNode::ref() and AudioNode::deref() m ethods for more details. |
| 262 void refNode(AudioNode*); | 265 void refNode(AudioNode*); |
| 263 void derefNode(AudioNode*); | 266 void derefNode(AudioNode*); |
| 264 | 267 |
| 265 // When the context goes away, there might still be some sources which haven 't finished playing. | 268 // When the context goes away, there might still be some sources which haven 't finished playing. |
| 266 // Make sure to dereference them here. | 269 // Make sure to dereference them here. |
| 267 void derefUnfinishedSourceNodes(); | 270 void derefUnfinishedSourceNodes(); |
| 268 | 271 |
| 269 RefPtr<AudioDestinationNode> m_destinationNode; | 272 RefPtrWillBeMember<AudioDestinationNode> m_destinationNode; |
| 270 RefPtr<AudioListener> m_listener; | 273 RefPtrWillBeMember<AudioListener> m_listener; |
| 271 | 274 |
| 272 // Only accessed in the audio thread. | 275 // Only accessed in the audio thread. |
| 273 Vector<AudioNode*> m_finishedNodes; | 276 Vector<AudioNode*> m_finishedNodes; |
| 274 | 277 |
| 275 // We don't use RefPtr<AudioNode> here because AudioNode has a more complex ref() / deref() implementation | 278 // We don't use RefPtr<AudioNode> here because AudioNode has a more complex ref() / deref() implementation |
| 276 // with an optional argument for refType. We need to use the special refTyp e: RefTypeConnection | 279 // with an optional argument for refType. We need to use the special refTyp e: RefTypeConnection |
| 277 // Either accessed when the graph lock is held, or on the main thread when t he audio thread has finished. | 280 // Either accessed when the graph lock is held, or on the main thread when t he audio thread has finished. |
| 278 Vector<AudioNode*> m_referencedNodes; | 281 Vector<AudioNode*> m_referencedNodes; |
| 279 | 282 |
| 280 // Accumulate nodes which need to be deleted here. | 283 // Accumulate nodes which need to be deleted here. |
| 281 // This is copied to m_nodesToDelete at the end of a render cycle in handleP ostRenderTasks(), where we're assured of a stable graph | 284 // This is copied to m_nodesToDelete at the end of a render cycle in handleP ostRenderTasks(), where we're assured of a stable graph |
| 282 // state which will have no references to any of the nodes in m_nodesToDelet e once the context lock is released | 285 // state which will have no references to any of the nodes in m_nodesToDelet e once the context lock is released |
| 283 // (when handlePostRenderTasks() has completed). | 286 // (when handlePostRenderTasks() has completed). |
| 284 Vector<AudioNode*> m_nodesMarkedForDeletion; | 287 Vector<AudioNode*> m_nodesMarkedForDeletion; |
| 285 | 288 |
| 286 // They will be scheduled for deletion (on the main thread) at the end of a render cycle (in realtime thread). | 289 // They will be scheduled for deletion (on the main thread) at the end of a render cycle (in realtime thread). |
| 287 Vector<AudioNode*> m_nodesToDelete; | 290 Vector<AudioNode*> m_nodesToDelete; |
| 288 bool m_isDeletionScheduled; | 291 bool m_isDeletionScheduled; |
| 289 | 292 |
| 290 // Only accessed when the graph lock is held. | 293 // Only accessed when the graph lock is held. |
| 291 HashSet<AudioSummingJunction*> m_dirtySummingJunctions; | 294 HashSet<AudioSummingJunction* > m_dirtySummingJunctions; |
|
haraken
2014/05/07 04:02:16
This is mis-edit.
It looks safe to use raw pointe
keishi
2014/05/07 07:59:24
Done.
| |
| 292 HashSet<AudioNodeOutput*> m_dirtyAudioNodeOutputs; | 295 HashSet<AudioNodeOutput*> m_dirtyAudioNodeOutputs; |
|
haraken
2014/05/07 04:02:16
These raw pointers look safe as well, but let's mo
| |
| 293 void handleDirtyAudioSummingJunctions(); | 296 void handleDirtyAudioSummingJunctions(); |
| 294 void handleDirtyAudioNodeOutputs(); | 297 void handleDirtyAudioNodeOutputs(); |
| 295 | 298 |
| 296 // For the sake of thread safety, we maintain a seperate Vector of automatic pull nodes for rendering in m_renderingAutomaticPullNodes. | 299 // For the sake of thread safety, we maintain a seperate Vector of automatic pull nodes for rendering in m_renderingAutomaticPullNodes. |
| 297 // It will be copied from m_automaticPullNodes by updateAutomaticPullNodes() at the very start or end of the rendering quantum. | 300 // It will be copied from m_automaticPullNodes by updateAutomaticPullNodes() at the very start or end of the rendering quantum. |
| 298 HashSet<AudioNode*> m_automaticPullNodes; | 301 HashSet<AudioNode*> m_automaticPullNodes; |
| 299 Vector<AudioNode*> m_renderingAutomaticPullNodes; | 302 Vector<AudioNode*> m_renderingAutomaticPullNodes; |
| 300 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m odified. | 303 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m odified. |
| 301 bool m_automaticPullNodesNeedUpdating; | 304 bool m_automaticPullNodesNeedUpdating; |
| 302 void updateAutomaticPullNodes(); | 305 void updateAutomaticPullNodes(); |
| 303 | 306 |
| 304 unsigned m_connectionCount; | 307 unsigned m_connectionCount; |
| 305 | 308 |
| 306 // Graph locking. | 309 // Graph locking. |
| 307 Mutex m_contextGraphMutex; | 310 Mutex m_contextGraphMutex; |
| 308 volatile ThreadIdentifier m_audioThread; | 311 volatile ThreadIdentifier m_audioThread; |
| 309 volatile ThreadIdentifier m_graphOwnerThread; // if the lock is held then th is is the thread which owns it, otherwise == UndefinedThreadIdentifier | 312 volatile ThreadIdentifier m_graphOwnerThread; // if the lock is held then th is is the thread which owns it, otherwise == UndefinedThreadIdentifier |
| 310 | 313 |
| 311 // Only accessed in the audio thread. | 314 // Only accessed in the audio thread. |
| 312 Vector<AudioNode*> m_deferredFinishDerefList; | 315 Vector<AudioNode*> m_deferredFinishDerefList; |
| 313 | 316 |
| 314 RefPtr<AudioBuffer> m_renderTarget; | 317 RefPtrWillBeMember<AudioBuffer> m_renderTarget; |
| 315 | 318 |
| 316 bool m_isOfflineContext; | 319 bool m_isOfflineContext; |
| 317 | 320 |
| 318 AsyncAudioDecoder m_audioDecoder; | 321 AsyncAudioDecoder m_audioDecoder; |
| 319 | 322 |
| 320 // This is considering 32 is large enough for multiple channels audio. | 323 // This is considering 32 is large enough for multiple channels audio. |
| 321 // It is somewhat arbitrary and could be increased if necessary. | 324 // It is somewhat arbitrary and could be increased if necessary. |
| 322 enum { MaxNumberOfChannels = 32 }; | 325 enum { MaxNumberOfChannels = 32 }; |
| 323 }; | 326 }; |
| 324 | 327 |
| 325 } // WebCore | 328 } // WebCore |
| 326 | 329 |
| 327 #endif // AudioContext_h | 330 #endif // AudioContext_h |
| OLD | NEW |