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

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

Issue 14028011: Made AudioNode an EventTarget (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
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 AudioNode_h 25 #ifndef AudioNode_h
26 #define AudioNode_h 26 #define AudioNode_h
27 27
28 #include "ActiveDOMObject.h"
28 #include "AudioBus.h" 29 #include "AudioBus.h"
30 #include "EventTarget.h"
29 #include <wtf/Forward.h> 31 #include <wtf/Forward.h>
30 #include <wtf/OwnPtr.h> 32 #include <wtf/OwnPtr.h>
31 #include <wtf/PassOwnPtr.h> 33 #include <wtf/PassOwnPtr.h>
32 #include <wtf/RefPtr.h> 34 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h> 35 #include <wtf/Vector.h>
34 36
35 #define DEBUG_AUDIONODE_REFERENCES 0 37 #define DEBUG_AUDIONODE_REFERENCES 0
36 38
37 namespace WebCore { 39 namespace WebCore {
38 40
39 class AudioContext; 41 class AudioContext;
40 class AudioNodeInput; 42 class AudioNodeInput;
41 class AudioNodeOutput; 43 class AudioNodeOutput;
42 class AudioParam; 44 class AudioParam;
43 45
44 typedef int ExceptionCode; 46 typedef int ExceptionCode;
45 47
46 // An AudioNode is the basic building block for handling audio within an AudioCo ntext. 48 // An AudioNode is the basic building block for handling audio within an AudioCo ntext.
47 // It may be an audio source, an intermediate processing module, or an audio des tination. 49 // It may be an audio source, an intermediate processing module, or an audio des tination.
48 // Each AudioNode can have inputs and/or outputs. An AudioSourceNode has no inpu ts and a single output. 50 // Each AudioNode can have inputs and/or outputs. An AudioSourceNode has no inpu ts and a single output.
49 // An AudioDestinationNode has one input and no outputs and represents the final destination to the audio hardware. 51 // An AudioDestinationNode has one input and no outputs and represents the final destination to the audio hardware.
50 // Most processing nodes such as filters will have one input and one output, alt hough multiple inputs and outputs are possible. 52 // Most processing nodes such as filters will have one input and one output, alt hough multiple inputs and outputs are possible.
51 53
52 class AudioNode { 54 class AudioNode : public ActiveDOMObject, public EventTarget {
53 public: 55 public:
54 enum { ProcessingSizeInFrames = 128 }; 56 enum { ProcessingSizeInFrames = 128 };
55 57
56 AudioNode(AudioContext*, float sampleRate); 58 AudioNode(AudioContext*, float sampleRate);
57 virtual ~AudioNode(); 59 virtual ~AudioNode();
58 60
59 AudioContext* context() { return m_context.get(); } 61 AudioContext* context() { return m_context.get(); }
60 const AudioContext* context() const { return m_context.get(); } 62 const AudioContext* context() const { return m_context.get(); }
61 63
62 enum NodeType { 64 enum NodeType {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 147
146 #if DEBUG_AUDIONODE_REFERENCES 148 #if DEBUG_AUDIONODE_REFERENCES
147 static void printNodeCounts(); 149 static void printNodeCounts();
148 #endif 150 #endif
149 151
150 bool isMarkedForDeletion() const { return m_isMarkedForDeletion; } 152 bool isMarkedForDeletion() const { return m_isMarkedForDeletion; }
151 153
152 // tailTime() is the length of time (not counting latency time) where non-ze ro output may occur after continuous silent input. 154 // tailTime() is the length of time (not counting latency time) where non-ze ro output may occur after continuous silent input.
153 virtual double tailTime() const = 0; 155 virtual double tailTime() const = 0;
154 // latencyTime() is the length of time it takes for non-zero output to appea r after non-zero input is provided. This only applies to 156 // latencyTime() is the length of time it takes for non-zero output to appea r after non-zero input is provided. This only applies to
155 // processing delay which is an artifact of the processing algorithm chosen and is *not* part of the intrinsic desired effect. For 157 // processing delay which is an artifact of the processing algorithm chosen and is *not* part of the intrinsic desired effect. For
156 // example, a "delay" effect is expected to delay the signal, and thus would not be considered latency. 158 // example, a "delay" effect is expected to delay the signal, and thus would not be considered latency.
157 virtual double latencyTime() const = 0; 159 virtual double latencyTime() const = 0;
158 160
159 // propagatesSilence() should return true if the node will generate silent o utput when given silent input. By default, AudioNode 161 // propagatesSilence() should return true if the node will generate silent o utput when given silent input. By default, AudioNode
160 // will take tailTime() and latencyTime() into account when determining whet her the node will propagate silence. 162 // will take tailTime() and latencyTime() into account when determining whet her the node will propagate silence.
161 virtual bool propagatesSilence() const; 163 virtual bool propagatesSilence() const;
162 bool inputsAreSilent(); 164 bool inputsAreSilent();
163 void silenceOutputs(); 165 void silenceOutputs();
164 void unsilenceOutputs(); 166 void unsilenceOutputs();
165 167
166 void enableOutputsIfNecessary(); 168 void enableOutputsIfNecessary();
167 void disableOutputsIfNecessary(); 169 void disableOutputsIfNecessary();
168 170
169 void reportMemoryUsage(MemoryObjectInfo*) const; 171 void reportMemoryUsage(MemoryObjectInfo*) const;
170 172
171 unsigned long channelCount(); 173 unsigned long channelCount();
172 virtual void setChannelCount(unsigned long, ExceptionCode&); 174 virtual void setChannelCount(unsigned long, ExceptionCode&);
173 175
174 String channelCountMode(); 176 String channelCountMode();
175 void setChannelCountMode(const String&, ExceptionCode&); 177 void setChannelCountMode(const String&, ExceptionCode&);
176 178
177 String channelInterpretation(); 179 String channelInterpretation();
178 void setChannelInterpretation(const String&, ExceptionCode&); 180 void setChannelInterpretation(const String&, ExceptionCode&);
179 181
180 ChannelCountMode internalChannelCountMode() const { return m_channelCountMod e; } 182 ChannelCountMode internalChannelCountMode() const { return m_channelCountMod e; }
181 AudioBus::ChannelInterpretation internalChannelInterpretation() const { retu rn m_channelInterpretation; } 183 AudioBus::ChannelInterpretation internalChannelInterpretation() const { retu rn m_channelInterpretation; }
182 184
185 // EventTarget
186 virtual const AtomicString& interfaceName() const;
187 virtual ScriptExecutionContext* scriptExecutionContext() const;
188 virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
189 virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetDat a; }
haraken 2013/04/15 00:01:25 Please add OVERRIDE to these virtual methods.
190
191 // ActiveDOMObject
192 virtual bool hasPendingActivity() const OVERRIDE;
193
183 protected: 194 protected:
184 // Inputs and outputs must be created before the AudioNode is initialized. 195 // Inputs and outputs must be created before the AudioNode is initialized.
185 void addInput(PassOwnPtr<AudioNodeInput>); 196 void addInput(PassOwnPtr<AudioNodeInput>);
186 void addOutput(PassOwnPtr<AudioNodeOutput>); 197 void addOutput(PassOwnPtr<AudioNodeOutput>);
187 198
188 // Called by processIfNecessary() to cause all parts of the rendering graph connected to us to process. 199 // Called by processIfNecessary() to cause all parts of the rendering graph connected to us to process.
189 // Each rendering quantum, the audio data for each of the AudioNode's inputs will be available after this method is called. 200 // Each rendering quantum, the audio data for each of the AudioNode's inputs will be available after this method is called.
190 // Called from context's audio thread. 201 // Called from context's audio thread.
191 virtual void pullInputs(size_t framesToProcess); 202 virtual void pullInputs(size_t framesToProcess);
192 203
193 // Force all inputs to take any channel interpretation changes into account. 204 // Force all inputs to take any channel interpretation changes into account.
194 void updateChannelsForInputs(); 205 void updateChannelsForInputs();
195 206
196 private: 207 private:
197 volatile bool m_isInitialized; 208 volatile bool m_isInitialized;
198 NodeType m_nodeType; 209 NodeType m_nodeType;
199 RefPtr<AudioContext> m_context; 210 RefPtr<AudioContext> m_context;
200 float m_sampleRate; 211 float m_sampleRate;
201 Vector<OwnPtr<AudioNodeInput> > m_inputs; 212 Vector<OwnPtr<AudioNodeInput> > m_inputs;
202 Vector<OwnPtr<AudioNodeOutput> > m_outputs; 213 Vector<OwnPtr<AudioNodeOutput> > m_outputs;
203 214
215 EventTargetData m_eventTargetData;
216
204 double m_lastProcessingTime; 217 double m_lastProcessingTime;
205 double m_lastNonSilentTime; 218 double m_lastNonSilentTime;
206 219
207 // Ref-counting 220 // Ref-counting
208 volatile int m_normalRefCount; 221 volatile int m_normalRefCount;
209 volatile int m_connectionRefCount; 222 volatile int m_connectionRefCount;
210 223
211 bool m_isMarkedForDeletion; 224 bool m_isMarkedForDeletion;
212 bool m_isDisabled; 225 bool m_isDisabled;
213 226
214 #if DEBUG_AUDIONODE_REFERENCES 227 #if DEBUG_AUDIONODE_REFERENCES
215 static bool s_isNodeCountInitialized; 228 static bool s_isNodeCountInitialized;
216 static int s_nodeCount[NodeTypeEnd]; 229 static int s_nodeCount[NodeTypeEnd];
217 #endif 230 #endif
218 231
232 virtual void refEventTarget() { ref(); }
233 virtual void derefEventTarget() { deref(); }
haraken 2013/04/15 00:01:25 Ditto. OVERRIDE.
234
219 protected: 235 protected:
236
220 unsigned m_channelCount; 237 unsigned m_channelCount;
221 ChannelCountMode m_channelCountMode; 238 ChannelCountMode m_channelCountMode;
222 AudioBus::ChannelInterpretation m_channelInterpretation; 239 AudioBus::ChannelInterpretation m_channelInterpretation;
223 }; 240 };
224 241
225 } // namespace WebCore 242 } // namespace WebCore
226 243
227 #endif // AudioNode_h 244 #endif // AudioNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698