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

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: Made AudioNode an EventTarget 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 "AudioBus.h" 28 #include "AudioBus.h"
29 #include "EventTarget.h"
29 #include <wtf/Forward.h> 30 #include <wtf/Forward.h>
30 #include <wtf/OwnPtr.h> 31 #include <wtf/OwnPtr.h>
31 #include <wtf/PassOwnPtr.h> 32 #include <wtf/PassOwnPtr.h>
32 #include <wtf/RefPtr.h> 33 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h> 34 #include <wtf/Vector.h>
34 35
35 #define DEBUG_AUDIONODE_REFERENCES 0 36 #define DEBUG_AUDIONODE_REFERENCES 0
36 37
37 namespace WebCore { 38 namespace WebCore {
38 39
39 class AudioContext; 40 class AudioContext;
40 class AudioNodeInput; 41 class AudioNodeInput;
41 class AudioNodeOutput; 42 class AudioNodeOutput;
42 class AudioParam; 43 class AudioParam;
43 44
44 typedef int ExceptionCode; 45 typedef int ExceptionCode;
45 46
46 // An AudioNode is the basic building block for handling audio within an AudioCo ntext. 47 // 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. 48 // 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. 49 // 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. 50 // 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. 51 // Most processing nodes such as filters will have one input and one output, alt hough multiple inputs and outputs are possible.
51 52
52 class AudioNode { 53 class AudioNode : public EventTarget {
53 public: 54 public:
54 enum { ProcessingSizeInFrames = 128 }; 55 enum { ProcessingSizeInFrames = 128 };
55 56
56 AudioNode(AudioContext*, float sampleRate); 57 AudioNode(AudioContext*, float sampleRate);
57 virtual ~AudioNode(); 58 virtual ~AudioNode();
58 59
59 AudioContext* context() { return m_context.get(); } 60 AudioContext* context() { return m_context.get(); }
60 const AudioContext* context() const { return m_context.get(); } 61 const AudioContext* context() const { return m_context.get(); }
61 62
62 enum NodeType { 63 enum NodeType {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 #if DEBUG_AUDIONODE_REFERENCES 147 #if DEBUG_AUDIONODE_REFERENCES
147 static void printNodeCounts(); 148 static void printNodeCounts();
148 #endif 149 #endif
149 150
150 bool isMarkedForDeletion() const { return m_isMarkedForDeletion; } 151 bool isMarkedForDeletion() const { return m_isMarkedForDeletion; }
151 152
152 // tailTime() is the length of time (not counting latency time) where non-ze ro output may occur after continuous silent input. 153 // 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; 154 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 155 // 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 156 // 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. 157 // example, a "delay" effect is expected to delay the signal, and thus would not be considered latency.
157 virtual double latencyTime() const = 0; 158 virtual double latencyTime() const = 0;
158 159
159 // propagatesSilence() should return true if the node will generate silent o utput when given silent input. By default, AudioNode 160 // 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. 161 // will take tailTime() and latencyTime() into account when determining whet her the node will propagate silence.
161 virtual bool propagatesSilence() const; 162 virtual bool propagatesSilence() const;
162 bool inputsAreSilent(); 163 bool inputsAreSilent();
163 void silenceOutputs(); 164 void silenceOutputs();
164 void unsilenceOutputs(); 165 void unsilenceOutputs();
165 166
166 void enableOutputsIfNecessary(); 167 void enableOutputsIfNecessary();
167 void disableOutputsIfNecessary(); 168 void disableOutputsIfNecessary();
168 169
169 void reportMemoryUsage(MemoryObjectInfo*) const; 170 void reportMemoryUsage(MemoryObjectInfo*) const;
170 171
171 unsigned long channelCount(); 172 unsigned long channelCount();
172 virtual void setChannelCount(unsigned long, ExceptionCode&); 173 virtual void setChannelCount(unsigned long, ExceptionCode&);
173 174
174 String channelCountMode(); 175 String channelCountMode();
175 void setChannelCountMode(const String&, ExceptionCode&); 176 void setChannelCountMode(const String&, ExceptionCode&);
176 177
177 String channelInterpretation(); 178 String channelInterpretation();
178 void setChannelInterpretation(const String&, ExceptionCode&); 179 void setChannelInterpretation(const String&, ExceptionCode&);
179 180
180 ChannelCountMode internalChannelCountMode() const { return m_channelCountMod e; } 181 ChannelCountMode internalChannelCountMode() const { return m_channelCountMod e; }
181 AudioBus::ChannelInterpretation internalChannelInterpretation() const { retu rn m_channelInterpretation; } 182 AudioBus::ChannelInterpretation internalChannelInterpretation() const { retu rn m_channelInterpretation; }
182 183
184 // EventTarget
185 virtual const AtomicString& interfaceName() const OVERRIDE;
186 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
187 virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetD ata; }
188 virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventT argetData; }
189
183 protected: 190 protected:
184 // Inputs and outputs must be created before the AudioNode is initialized. 191 // Inputs and outputs must be created before the AudioNode is initialized.
185 void addInput(PassOwnPtr<AudioNodeInput>); 192 void addInput(PassOwnPtr<AudioNodeInput>);
186 void addOutput(PassOwnPtr<AudioNodeOutput>); 193 void addOutput(PassOwnPtr<AudioNodeOutput>);
187 194
188 // Called by processIfNecessary() to cause all parts of the rendering graph connected to us to process. 195 // 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. 196 // 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. 197 // Called from context's audio thread.
191 virtual void pullInputs(size_t framesToProcess); 198 virtual void pullInputs(size_t framesToProcess);
192 199
193 // Force all inputs to take any channel interpretation changes into account. 200 // Force all inputs to take any channel interpretation changes into account.
194 void updateChannelsForInputs(); 201 void updateChannelsForInputs();
195 202
196 private: 203 private:
197 volatile bool m_isInitialized; 204 volatile bool m_isInitialized;
198 NodeType m_nodeType; 205 NodeType m_nodeType;
199 RefPtr<AudioContext> m_context; 206 RefPtr<AudioContext> m_context;
200 float m_sampleRate; 207 float m_sampleRate;
201 Vector<OwnPtr<AudioNodeInput> > m_inputs; 208 Vector<OwnPtr<AudioNodeInput> > m_inputs;
202 Vector<OwnPtr<AudioNodeOutput> > m_outputs; 209 Vector<OwnPtr<AudioNodeOutput> > m_outputs;
203 210
211 EventTargetData m_eventTargetData;
212
204 double m_lastProcessingTime; 213 double m_lastProcessingTime;
205 double m_lastNonSilentTime; 214 double m_lastNonSilentTime;
206 215
207 // Ref-counting 216 // Ref-counting
208 volatile int m_normalRefCount; 217 volatile int m_normalRefCount;
209 volatile int m_connectionRefCount; 218 volatile int m_connectionRefCount;
210 219
211 bool m_isMarkedForDeletion; 220 bool m_isMarkedForDeletion;
212 bool m_isDisabled; 221 bool m_isDisabled;
213 222
214 #if DEBUG_AUDIONODE_REFERENCES 223 #if DEBUG_AUDIONODE_REFERENCES
215 static bool s_isNodeCountInitialized; 224 static bool s_isNodeCountInitialized;
216 static int s_nodeCount[NodeTypeEnd]; 225 static int s_nodeCount[NodeTypeEnd];
217 #endif 226 #endif
218 227
228 virtual void refEventTarget() OVERRIDE { ref(); }
229 virtual void derefEventTarget() OVERRIDE { deref(); }
230
219 protected: 231 protected:
232
Chris Rogers 2013/04/16 21:03:03 extra blank line?
220 unsigned m_channelCount; 233 unsigned m_channelCount;
221 ChannelCountMode m_channelCountMode; 234 ChannelCountMode m_channelCountMode;
222 AudioBus::ChannelInterpretation m_channelInterpretation; 235 AudioBus::ChannelInterpretation m_channelInterpretation;
223 }; 236 };
224 237
225 } // namespace WebCore 238 } // namespace WebCore
226 239
227 #endif // AudioNode_h 240 #endif // AudioNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698