| 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 21 matching lines...) Expand all Loading... |
| 32 #include "wtf/OwnPtr.h" | 32 #include "wtf/OwnPtr.h" |
| 33 #include "wtf/PassOwnPtr.h" | 33 #include "wtf/PassOwnPtr.h" |
| 34 #include "wtf/RefPtr.h" | 34 #include "wtf/RefPtr.h" |
| 35 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 36 #include "wtf/build_config.h" | 36 #include "wtf/build_config.h" |
| 37 | 37 |
| 38 #define DEBUG_AUDIONODE_REFERENCES 0 | 38 #define DEBUG_AUDIONODE_REFERENCES 0 |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class AbstractAudioContext; | 42 class BaseAudioContext; |
| 43 class AudioNode; | 43 class AudioNode; |
| 44 class AudioNodeInput; | 44 class AudioNodeInput; |
| 45 class AudioNodeOutput; | 45 class AudioNodeOutput; |
| 46 class AudioParam; | 46 class AudioParam; |
| 47 class ExceptionState; | 47 class ExceptionState; |
| 48 | 48 |
| 49 // An AudioNode is the basic building block for handling audio within an Abstrac
tAudioContext. | 49 // An AudioNode is the basic building block for handling audio within an BaseAud
ioContext. |
| 50 // It may be an audio source, an intermediate processing module, or an audio des
tination. | 50 // It may be an audio source, an intermediate processing module, or an audio des
tination. |
| 51 // Each AudioNode can have inputs and/or outputs. An AudioSourceNode has no inpu
ts and a single output. | 51 // Each AudioNode can have inputs and/or outputs. An AudioSourceNode has no inpu
ts and a single output. |
| 52 // An AudioDestinationNode has one input and no outputs and represents the final
destination to the audio hardware. | 52 // An AudioDestinationNode has one input and no outputs and represents the final
destination to the audio hardware. |
| 53 // Most processing nodes such as filters will have one input and one output, alt
hough multiple inputs and outputs are possible. | 53 // Most processing nodes such as filters will have one input and one output, alt
hough multiple inputs and outputs are possible. |
| 54 | 54 |
| 55 // Each of AudioNode objects owns its dedicated AudioHandler object. AudioNode | 55 // Each of AudioNode objects owns its dedicated AudioHandler object. AudioNode |
| 56 // is responsible to provide IDL-accessible interface and its lifetime is | 56 // is responsible to provide IDL-accessible interface and its lifetime is |
| 57 // managed by Oilpan GC. AudioHandler is responsible for anything else. We must | 57 // managed by Oilpan GC. AudioHandler is responsible for anything else. We must |
| 58 // not touch AudioNode objects in an audio rendering thread. | 58 // not touch AudioNode objects in an audio rendering thread. |
| 59 | 59 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // dispose() is called when the owner AudioNode is about to be | 98 // dispose() is called when the owner AudioNode is about to be |
| 99 // destructed. This must be called in the main thread, and while the graph | 99 // destructed. This must be called in the main thread, and while the graph |
| 100 // lock is held. | 100 // lock is held. |
| 101 // Do not release resources used by an audio rendering thread in dispose(). | 101 // Do not release resources used by an audio rendering thread in dispose(). |
| 102 virtual void dispose(); | 102 virtual void dispose(); |
| 103 | 103 |
| 104 // node() returns a valid object until dispose() is called. This returns | 104 // node() returns a valid object until dispose() is called. This returns |
| 105 // nullptr after dispose(). We must not call node() in an audio rendering | 105 // nullptr after dispose(). We must not call node() in an audio rendering |
| 106 // thread. | 106 // thread. |
| 107 AudioNode* node() const; | 107 AudioNode* node() const; |
| 108 // context() returns a valid object until the AbstractAudioContext dies, and
returns | 108 // context() returns a valid object until the BaseAudioContext dies, and ret
urns |
| 109 // nullptr otherwise. This always returns a valid object in an audio | 109 // nullptr otherwise. This always returns a valid object in an audio |
| 110 // rendering thread, and inside dispose(). We must not call context() in | 110 // rendering thread, and inside dispose(). We must not call context() in |
| 111 // the destructor. | 111 // the destructor. |
| 112 virtual AbstractAudioContext* context() const; | 112 virtual BaseAudioContext* context() const; |
| 113 void clearContext() { m_context = nullptr; } | 113 void clearContext() { m_context = nullptr; } |
| 114 | 114 |
| 115 enum ChannelCountMode { | 115 enum ChannelCountMode { |
| 116 Max, | 116 Max, |
| 117 ClampedMax, | 117 ClampedMax, |
| 118 Explicit | 118 Explicit |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 NodeType getNodeType() const { return m_nodeType; } | 121 NodeType getNodeType() const { return m_nodeType; } |
| 122 String nodeTypeName() const; | 122 String nodeTypeName() const; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 volatile bool m_isInitialized; | 237 volatile bool m_isInitialized; |
| 238 NodeType m_nodeType; | 238 NodeType m_nodeType; |
| 239 | 239 |
| 240 // The owner AudioNode. This untraced member is safe because dispose() is | 240 // The owner AudioNode. This untraced member is safe because dispose() is |
| 241 // called before the AudioNode death, and it clears m_node. Do not access | 241 // called before the AudioNode death, and it clears m_node. Do not access |
| 242 // m_node directly, use node() instead. | 242 // m_node directly, use node() instead. |
| 243 // See http://crbug.com/404527 for the detail. | 243 // See http://crbug.com/404527 for the detail. |
| 244 UntracedMember<AudioNode> m_node; | 244 UntracedMember<AudioNode> m_node; |
| 245 | 245 |
| 246 // This untraced member is safe because this is cleared for all of live | 246 // This untraced member is safe because this is cleared for all of live |
| 247 // AudioHandlers when the AbstractAudioContext dies. Do not access m_contex
t | 247 // AudioHandlers when the BaseAudioContext dies. Do not access m_context |
| 248 // directly, use context() instead. | 248 // directly, use context() instead. |
| 249 // See http://crbug.com/404527 for the detail. | 249 // See http://crbug.com/404527 for the detail. |
| 250 UntracedMember<AbstractAudioContext> m_context; | 250 UntracedMember<BaseAudioContext> m_context; |
| 251 | 251 |
| 252 float m_sampleRate; | 252 float m_sampleRate; |
| 253 Vector<OwnPtr<AudioNodeInput>> m_inputs; | 253 Vector<OwnPtr<AudioNodeInput>> m_inputs; |
| 254 Vector<OwnPtr<AudioNodeOutput>> m_outputs; | 254 Vector<OwnPtr<AudioNodeOutput>> m_outputs; |
| 255 | 255 |
| 256 double m_lastProcessingTime; | 256 double m_lastProcessingTime; |
| 257 double m_lastNonSilentTime; | 257 double m_lastNonSilentTime; |
| 258 | 258 |
| 259 volatile int m_connectionRefCount; | 259 volatile int m_connectionRefCount; |
| 260 | 260 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 284 | 284 |
| 285 virtual AudioNode* connect(AudioNode*, unsigned outputIndex, unsigned inputI
ndex, ExceptionState&); | 285 virtual AudioNode* connect(AudioNode*, unsigned outputIndex, unsigned inputI
ndex, ExceptionState&); |
| 286 void connect(AudioParam*, unsigned outputIndex, ExceptionState&); | 286 void connect(AudioParam*, unsigned outputIndex, ExceptionState&); |
| 287 void disconnect(); | 287 void disconnect(); |
| 288 virtual void disconnect(unsigned outputIndex, ExceptionState&); | 288 virtual void disconnect(unsigned outputIndex, ExceptionState&); |
| 289 void disconnect(AudioNode*, ExceptionState&); | 289 void disconnect(AudioNode*, ExceptionState&); |
| 290 void disconnect(AudioNode*, unsigned outputIndex, ExceptionState&); | 290 void disconnect(AudioNode*, unsigned outputIndex, ExceptionState&); |
| 291 void disconnect(AudioNode*, unsigned outputIndex, unsigned inputIndex, Excep
tionState&); | 291 void disconnect(AudioNode*, unsigned outputIndex, unsigned inputIndex, Excep
tionState&); |
| 292 void disconnect(AudioParam*, ExceptionState&); | 292 void disconnect(AudioParam*, ExceptionState&); |
| 293 void disconnect(AudioParam*, unsigned outputIndex, ExceptionState&); | 293 void disconnect(AudioParam*, unsigned outputIndex, ExceptionState&); |
| 294 AbstractAudioContext* context() const; | 294 BaseAudioContext* context() const; |
| 295 unsigned numberOfInputs() const; | 295 unsigned numberOfInputs() const; |
| 296 unsigned numberOfOutputs() const; | 296 unsigned numberOfOutputs() const; |
| 297 unsigned long channelCount() const; | 297 unsigned long channelCount() const; |
| 298 void setChannelCount(unsigned long, ExceptionState&); | 298 void setChannelCount(unsigned long, ExceptionState&); |
| 299 String channelCountMode() const; | 299 String channelCountMode() const; |
| 300 void setChannelCountMode(const String&, ExceptionState&); | 300 void setChannelCountMode(const String&, ExceptionState&); |
| 301 String channelInterpretation() const; | 301 String channelInterpretation() const; |
| 302 void setChannelInterpretation(const String&, ExceptionState&); | 302 void setChannelInterpretation(const String&, ExceptionState&); |
| 303 | 303 |
| 304 // EventTarget | 304 // EventTarget |
| 305 const AtomicString& interfaceName() const final; | 305 const AtomicString& interfaceName() const final; |
| 306 ExecutionContext* getExecutionContext() const final; | 306 ExecutionContext* getExecutionContext() const final; |
| 307 | 307 |
| 308 // Called inside AudioHandler constructors. | 308 // Called inside AudioHandler constructors. |
| 309 void didAddOutput(unsigned numberOfOutputs); | 309 void didAddOutput(unsigned numberOfOutputs); |
| 310 // Like disconnect, but no exception is thrown if the outputIndex is invalid
. Just do nothing | 310 // Like disconnect, but no exception is thrown if the outputIndex is invalid
. Just do nothing |
| 311 // in that case. | 311 // in that case. |
| 312 void disconnectWithoutException(unsigned outputIndex); | 312 void disconnectWithoutException(unsigned outputIndex); |
| 313 | 313 |
| 314 protected: | 314 protected: |
| 315 explicit AudioNode(AbstractAudioContext&); | 315 explicit AudioNode(BaseAudioContext&); |
| 316 // This should be called in a constructor. | 316 // This should be called in a constructor. |
| 317 void setHandler(PassRefPtr<AudioHandler>); | 317 void setHandler(PassRefPtr<AudioHandler>); |
| 318 | 318 |
| 319 private: | 319 private: |
| 320 void dispose(); | 320 void dispose(); |
| 321 void disconnectAllFromOutput(unsigned outputIndex); | 321 void disconnectAllFromOutput(unsigned outputIndex); |
| 322 // Returns true if the specified AudioNodeInput was connected. | 322 // Returns true if the specified AudioNodeInput was connected. |
| 323 bool disconnectFromOutputIfConnected(unsigned outputIndex, AudioNode& destin
ation, unsigned inputIndexOfDestination); | 323 bool disconnectFromOutputIfConnected(unsigned outputIndex, AudioNode& destin
ation, unsigned inputIndexOfDestination); |
| 324 // Returns true if the specified AudioParam was connected. | 324 // Returns true if the specified AudioParam was connected. |
| 325 bool disconnectFromOutputIfConnected(unsigned outputIndex, AudioParam&); | 325 bool disconnectFromOutputIfConnected(unsigned outputIndex, AudioParam&); |
| 326 | 326 |
| 327 Member<AbstractAudioContext> m_context; | 327 Member<BaseAudioContext> m_context; |
| 328 RefPtr<AudioHandler> m_handler; | 328 RefPtr<AudioHandler> m_handler; |
| 329 // Represents audio node graph with Oilpan references. N-th HeapHashSet | 329 // Represents audio node graph with Oilpan references. N-th HeapHashSet |
| 330 // represents a set of AudioNode objects connected to this AudioNode's N-th | 330 // represents a set of AudioNode objects connected to this AudioNode's N-th |
| 331 // output. | 331 // output. |
| 332 HeapVector<Member<HeapHashSet<Member<AudioNode>>>> m_connectedNodes; | 332 HeapVector<Member<HeapHashSet<Member<AudioNode>>>> m_connectedNodes; |
| 333 // Represents audio node graph with Oilpan references. N-th HeapHashSet | 333 // Represents audio node graph with Oilpan references. N-th HeapHashSet |
| 334 // represents a set of AudioParam objects connected to this AudioNode's N-th | 334 // represents a set of AudioParam objects connected to this AudioNode's N-th |
| 335 // output. | 335 // output. |
| 336 HeapVector<Member<HeapHashSet<Member<AudioParam>>>> m_connectedParams; | 336 HeapVector<Member<HeapHashSet<Member<AudioParam>>>> m_connectedParams; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 } // namespace blink | 339 } // namespace blink |
| 340 | 340 |
| 341 #endif // AudioNode_h | 341 #endif // AudioNode_h |
| OLD | NEW |