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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 class AudioNodeOutput final { | 42 class AudioNodeOutput final { |
43 USING_FAST_MALLOC(AudioNodeOutput); | 43 USING_FAST_MALLOC(AudioNodeOutput); |
44 | 44 |
45 public: | 45 public: |
46 // It's OK to pass 0 for numberOfChannels in which case | 46 // It's OK to pass 0 for numberOfChannels in which case |
47 // setNumberOfChannels() must be called later on. | 47 // setNumberOfChannels() must be called later on. |
48 static std::unique_ptr<AudioNodeOutput> create(AudioHandler*, | 48 static std::unique_ptr<AudioNodeOutput> create(AudioHandler*, |
49 unsigned numberOfChannels); | 49 unsigned numberOfChannels); |
50 void dispose(); | 50 void dispose(); |
51 | 51 |
52 // Causes our AudioNode to process if it hasn't already for this render quantu
m. | 52 // Causes our AudioNode to process if it hasn't already for this render |
53 // It returns the bus containing the processed audio for this output, returnin
g inPlaceBus if in-place processing was possible. | 53 // quantum. It returns the bus containing the processed audio for this |
54 // Called from context's audio thread. | 54 // output, returning inPlaceBus if in-place processing was possible. Called |
| 55 // from context's audio thread. |
55 AudioBus* pull(AudioBus* inPlaceBus, size_t framesToProcess); | 56 AudioBus* pull(AudioBus* inPlaceBus, size_t framesToProcess); |
56 | 57 |
57 // bus() will contain the rendered audio after pull() is called for each rende
ring time quantum. | 58 // bus() will contain the rendered audio after pull() is called for each |
| 59 // rendering time quantum. |
58 // Called from context's audio thread. | 60 // Called from context's audio thread. |
59 AudioBus* bus() const; | 61 AudioBus* bus() const; |
60 | 62 |
61 // renderingFanOutCount() is the number of AudioNodeInputs that we're connecte
d to during rendering. | 63 // renderingFanOutCount() is the number of AudioNodeInputs that we're |
62 // Unlike fanOutCount() it will not change during the course of a render quant
um. | 64 // connected to during rendering. Unlike fanOutCount() it will not change |
| 65 // during the course of a render quantum. |
63 unsigned renderingFanOutCount() const; | 66 unsigned renderingFanOutCount() const; |
64 | 67 |
65 // Must be called with the context's graph lock. | 68 // Must be called with the context's graph lock. |
66 void disconnectAll(); | 69 void disconnectAll(); |
67 | 70 |
68 // Disconnect a specific input or AudioParam. | 71 // Disconnect a specific input or AudioParam. |
69 void disconnectInput(AudioNodeInput&); | 72 void disconnectInput(AudioNodeInput&); |
70 void disconnectAudioParam(AudioParamHandler&); | 73 void disconnectAudioParam(AudioParamHandler&); |
71 | 74 |
72 void setNumberOfChannels(unsigned); | 75 void setNumberOfChannels(unsigned); |
73 unsigned numberOfChannels() const { return m_numberOfChannels; } | 76 unsigned numberOfChannels() const { return m_numberOfChannels; } |
74 bool isChannelCountKnown() const { return numberOfChannels() > 0; } | 77 bool isChannelCountKnown() const { return numberOfChannels() > 0; } |
75 | 78 |
76 bool isConnected() { return fanOutCount() > 0 || paramFanOutCount() > 0; } | 79 bool isConnected() { return fanOutCount() > 0 || paramFanOutCount() > 0; } |
77 | 80 |
78 // Probe if the output node is connected with a certain input or AudioParam | 81 // Probe if the output node is connected with a certain input or AudioParam |
79 bool isConnectedToInput(AudioNodeInput&); | 82 bool isConnectedToInput(AudioNodeInput&); |
80 bool isConnectedToAudioParam(AudioParamHandler&); | 83 bool isConnectedToAudioParam(AudioParamHandler&); |
81 | 84 |
82 // Disable/Enable happens when there are still JavaScript references to a node
, but it has otherwise "finished" its work. | 85 // Disable/Enable happens when there are still JavaScript references to a |
83 // For example, when a note has finished playing. It is kept around, because
it may be played again at a later time. | 86 // node, but it has otherwise "finished" its work. For example, when a note |
84 // They must be called with the context's graph lock. | 87 // has finished playing. It is kept around, because it may be played again at |
| 88 // a later time. They must be called with the context's graph lock. |
85 void disable(); | 89 void disable(); |
86 void enable(); | 90 void enable(); |
87 | 91 |
88 // updateRenderingState() is called in the audio thread at the start or end of
the render quantum to handle any recent changes to the graph state. | 92 // updateRenderingState() is called in the audio thread at the start or end of |
| 93 // the render quantum to handle any recent changes to the graph state. |
89 // It must be called with the context's graph lock. | 94 // It must be called with the context's graph lock. |
90 void updateRenderingState(); | 95 void updateRenderingState(); |
91 | 96 |
92 private: | 97 private: |
93 AudioNodeOutput(AudioHandler*, unsigned numberOfChannels); | 98 AudioNodeOutput(AudioHandler*, unsigned numberOfChannels); |
94 // Can be called from any thread. | 99 // Can be called from any thread. |
95 AudioHandler& handler() const { return m_handler; } | 100 AudioHandler& handler() const { return m_handler; } |
96 DeferredTaskHandler& deferredTaskHandler() const { | 101 DeferredTaskHandler& deferredTaskHandler() const { |
97 return m_handler.context()->deferredTaskHandler(); | 102 return m_handler.context()->deferredTaskHandler(); |
98 } | 103 } |
99 | 104 |
100 // This reference is safe because the AudioHandler owns this AudioNodeOutput | 105 // This reference is safe because the AudioHandler owns this AudioNodeOutput |
101 // object. | 106 // object. |
102 AudioHandler& m_handler; | 107 AudioHandler& m_handler; |
103 | 108 |
104 friend class AudioNodeInput; | 109 friend class AudioNodeInput; |
105 friend class AudioParamHandler; | 110 friend class AudioParamHandler; |
106 | 111 |
107 // These are called from AudioNodeInput. | 112 // These are called from AudioNodeInput. |
108 // They must be called with the context's graph lock. | 113 // They must be called with the context's graph lock. |
109 void addInput(AudioNodeInput&); | 114 void addInput(AudioNodeInput&); |
110 void removeInput(AudioNodeInput&); | 115 void removeInput(AudioNodeInput&); |
111 void addParam(AudioParamHandler&); | 116 void addParam(AudioParamHandler&); |
112 void removeParam(AudioParamHandler&); | 117 void removeParam(AudioParamHandler&); |
113 | 118 |
114 // fanOutCount() is the number of AudioNodeInputs that we're connected to. | 119 // fanOutCount() is the number of AudioNodeInputs that we're connected to. |
115 // This method should not be called in audio thread rendering code, instead re
nderingFanOutCount() should be used. | 120 // This method should not be called in audio thread rendering code, instead |
| 121 // renderingFanOutCount() should be used. |
116 // It must be called with the context's graph lock. | 122 // It must be called with the context's graph lock. |
117 unsigned fanOutCount(); | 123 unsigned fanOutCount(); |
118 | 124 |
119 // Similar to fanOutCount(), paramFanOutCount() is the number of AudioParams t
hat we're connected to. | 125 // Similar to fanOutCount(), paramFanOutCount() is the number of AudioParams |
120 // This method should not be called in audio thread rendering code, instead re
nderingParamFanOutCount() should be used. | 126 // that we're connected to. This method should not be called in audio thread |
| 127 // rendering code, instead renderingParamFanOutCount() should be used. |
121 // It must be called with the context's graph lock. | 128 // It must be called with the context's graph lock. |
122 unsigned paramFanOutCount(); | 129 unsigned paramFanOutCount(); |
123 | 130 |
124 // Must be called with the context's graph lock. | 131 // Must be called with the context's graph lock. |
125 void disconnectAllInputs(); | 132 void disconnectAllInputs(); |
126 void disconnectAllParams(); | 133 void disconnectAllParams(); |
127 | 134 |
128 // updateInternalBus() updates m_internalBus appropriately for the number of c
hannels. | 135 // updateInternalBus() updates m_internalBus appropriately for the number of |
129 // It is called in the constructor or in the audio thread with the context's g
raph lock. | 136 // channels. It is called in the constructor or in the audio thread with the |
| 137 // context's graph lock. |
130 void updateInternalBus(); | 138 void updateInternalBus(); |
131 | 139 |
132 // Announce to any nodes we're connected to that we changed our channel count
for its input. | 140 // Announce to any nodes we're connected to that we changed our channel count |
| 141 // for its input. |
133 // It must be called in the audio thread with the context's graph lock. | 142 // It must be called in the audio thread with the context's graph lock. |
134 void propagateChannelCount(); | 143 void propagateChannelCount(); |
135 | 144 |
136 // updateNumberOfChannels() is called in the audio thread at the start or end
of the render quantum to pick up channel changes. | 145 // updateNumberOfChannels() is called in the audio thread at the start or end |
| 146 // of the render quantum to pick up channel changes. |
137 // It must be called with the context's graph lock. | 147 // It must be called with the context's graph lock. |
138 void updateNumberOfChannels(); | 148 void updateNumberOfChannels(); |
139 | 149 |
140 // m_numberOfChannels will only be changed in the audio thread. | 150 // m_numberOfChannels will only be changed in the audio thread. |
141 // The main thread sets m_desiredNumberOfChannels which will later get picked
up in the audio thread in updateNumberOfChannels(). | 151 // The main thread sets m_desiredNumberOfChannels which will later get picked |
| 152 // up in the audio thread in updateNumberOfChannels(). |
142 unsigned m_numberOfChannels; | 153 unsigned m_numberOfChannels; |
143 unsigned m_desiredNumberOfChannels; | 154 unsigned m_desiredNumberOfChannels; |
144 | 155 |
145 // m_internalBus and m_inPlaceBus must only be changed in the audio thread wit
h the context's graph lock (or constructor). | 156 // m_internalBus and m_inPlaceBus must only be changed in the audio thread |
| 157 // with the context's graph lock (or constructor). |
146 RefPtr<AudioBus> m_internalBus; | 158 RefPtr<AudioBus> m_internalBus; |
147 RefPtr<AudioBus> m_inPlaceBus; | 159 RefPtr<AudioBus> m_inPlaceBus; |
148 // If m_isInPlace is true, use m_inPlaceBus as the valid AudioBus; If false, u
se the default m_internalBus. | 160 // If m_isInPlace is true, use m_inPlaceBus as the valid AudioBus; If false, |
| 161 // use the default m_internalBus. |
149 bool m_isInPlace; | 162 bool m_isInPlace; |
150 | 163 |
151 // This HashSet holds connection references. We must call | 164 // This HashSet holds connection references. We must call |
152 // AudioNode::makeConnection when we add an AudioNodeInput to this, and must | 165 // AudioNode::makeConnection when we add an AudioNodeInput to this, and must |
153 // call AudioNode::breakConnection() when we remove an AudioNodeInput from | 166 // call AudioNode::breakConnection() when we remove an AudioNodeInput from |
154 // this. | 167 // this. |
155 HashSet<AudioNodeInput*> m_inputs; | 168 HashSet<AudioNodeInput*> m_inputs; |
156 bool m_isEnabled; | 169 bool m_isEnabled; |
157 | 170 |
158 bool m_didCallDispose; | 171 bool m_didCallDispose; |
159 | 172 |
160 // For the purposes of rendering, keeps track of the number of inputs and Audi
oParams we're connected to. | 173 // For the purposes of rendering, keeps track of the number of inputs and |
161 // These value should only be changed at the very start or end of the renderin
g quantum. | 174 // AudioParams we're connected to. These value should only be changed at the |
| 175 // very start or end of the rendering quantum. |
162 unsigned m_renderingFanOutCount; | 176 unsigned m_renderingFanOutCount; |
163 unsigned m_renderingParamFanOutCount; | 177 unsigned m_renderingParamFanOutCount; |
164 | 178 |
165 // This collection of raw pointers is safe because they are retained by | 179 // This collection of raw pointers is safe because they are retained by |
166 // AudioParam objects retained by m_connectedParams of the owner AudioNode. | 180 // AudioParam objects retained by m_connectedParams of the owner AudioNode. |
167 HashSet<AudioParamHandler*> m_params; | 181 HashSet<AudioParamHandler*> m_params; |
168 }; | 182 }; |
169 | 183 |
170 } // namespace blink | 184 } // namespace blink |
171 | 185 |
172 #endif // AudioNodeOutput_h | 186 #endif // AudioNodeOutput_h |
OLD | NEW |