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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioNodeInput.cpp

Issue 2159403002: Replace ASSERT with DCHECK in WebAudio (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
(...skipping 27 matching lines...) Expand all
38 m_internalSummingBus = AudioBus::create(1, AudioHandler::ProcessingSizeInFra mes); 38 m_internalSummingBus = AudioBus::create(1, AudioHandler::ProcessingSizeInFra mes);
39 } 39 }
40 40
41 std::unique_ptr<AudioNodeInput> AudioNodeInput::create(AudioHandler& handler) 41 std::unique_ptr<AudioNodeInput> AudioNodeInput::create(AudioHandler& handler)
42 { 42 {
43 return wrapUnique(new AudioNodeInput(handler)); 43 return wrapUnique(new AudioNodeInput(handler));
44 } 44 }
45 45
46 void AudioNodeInput::connect(AudioNodeOutput& output) 46 void AudioNodeInput::connect(AudioNodeOutput& output)
47 { 47 {
48 ASSERT(deferredTaskHandler().isGraphOwner()); 48 DCHECK(deferredTaskHandler().isGraphOwner());
49 49
50 // Check if we're already connected to this output. 50 // Check if we're already connected to this output.
51 if (m_outputs.contains(&output)) 51 if (m_outputs.contains(&output))
52 return; 52 return;
53 53
54 output.addInput(*this); 54 output.addInput(*this);
55 m_outputs.add(&output); 55 m_outputs.add(&output);
56 changedOutputs(); 56 changedOutputs();
57 } 57 }
58 58
59 void AudioNodeInput::disconnect(AudioNodeOutput& output) 59 void AudioNodeInput::disconnect(AudioNodeOutput& output)
60 { 60 {
61 ASSERT(deferredTaskHandler().isGraphOwner()); 61 DCHECK(deferredTaskHandler().isGraphOwner());
62 62
63 // First try to disconnect from "active" connections. 63 // First try to disconnect from "active" connections.
64 if (m_outputs.contains(&output)) { 64 if (m_outputs.contains(&output)) {
65 m_outputs.remove(&output); 65 m_outputs.remove(&output);
66 changedOutputs(); 66 changedOutputs();
67 output.removeInput(*this); 67 output.removeInput(*this);
68 // Note: it's important to return immediately after removeInput() calls 68 // Note: it's important to return immediately after removeInput() calls
69 // since the node may be deleted. 69 // since the node may be deleted.
70 return; 70 return;
71 } 71 }
72 72
73 // Otherwise, try to disconnect from disabled connections. 73 // Otherwise, try to disconnect from disabled connections.
74 if (m_disabledOutputs.contains(&output)) { 74 if (m_disabledOutputs.contains(&output)) {
75 m_disabledOutputs.remove(&output); 75 m_disabledOutputs.remove(&output);
76 output.removeInput(*this); 76 output.removeInput(*this);
77 // Note: it's important to return immediately after all removeInput() ca lls 77 // Note: it's important to return immediately after all removeInput() ca lls
78 // since the node may be deleted. 78 // since the node may be deleted.
79 return; 79 return;
80 } 80 }
81 81
82 ASSERT_NOT_REACHED(); 82 ASSERT_NOT_REACHED();
83 } 83 }
84 84
85 void AudioNodeInput::disable(AudioNodeOutput& output) 85 void AudioNodeInput::disable(AudioNodeOutput& output)
86 { 86 {
87 ASSERT(deferredTaskHandler().isGraphOwner()); 87 DCHECK(deferredTaskHandler().isGraphOwner());
88 ASSERT(m_outputs.contains(&output)); 88 DCHECK(m_outputs.contains(&output));
89 89
90 m_disabledOutputs.add(&output); 90 m_disabledOutputs.add(&output);
91 m_outputs.remove(&output); 91 m_outputs.remove(&output);
92 changedOutputs(); 92 changedOutputs();
93 93
94 // Propagate disabled state to outputs. 94 // Propagate disabled state to outputs.
95 handler().disableOutputsIfNecessary(); 95 handler().disableOutputsIfNecessary();
96 } 96 }
97 97
98 void AudioNodeInput::enable(AudioNodeOutput& output) 98 void AudioNodeInput::enable(AudioNodeOutput& output)
99 { 99 {
100 ASSERT(deferredTaskHandler().isGraphOwner()); 100 DCHECK(deferredTaskHandler().isGraphOwner());
101 ASSERT(m_disabledOutputs.contains(&output)); 101 DCHECK(m_disabledOutputs.contains(&output));
102 102
103 // Move output from disabled list to active list. 103 // Move output from disabled list to active list.
104 m_outputs.add(&output); 104 m_outputs.add(&output);
105 m_disabledOutputs.remove(&output); 105 m_disabledOutputs.remove(&output);
106 changedOutputs(); 106 changedOutputs();
107 107
108 // Propagate enabled state to outputs. 108 // Propagate enabled state to outputs.
109 handler().enableOutputsIfNecessary(); 109 handler().enableOutputsIfNecessary();
110 } 110 }
111 111
112 void AudioNodeInput::didUpdate() 112 void AudioNodeInput::didUpdate()
113 { 113 {
114 handler().checkNumberOfChannelsForInput(this); 114 handler().checkNumberOfChannelsForInput(this);
115 } 115 }
116 116
117 void AudioNodeInput::updateInternalBus() 117 void AudioNodeInput::updateInternalBus()
118 { 118 {
119 ASSERT(deferredTaskHandler().isAudioThread()); 119 DCHECK(deferredTaskHandler().isAudioThread());
120 ASSERT(deferredTaskHandler().isGraphOwner()); 120 DCHECK(deferredTaskHandler().isGraphOwner());
121 121
122 unsigned numberOfInputChannels = numberOfChannels(); 122 unsigned numberOfInputChannels = numberOfChannels();
123 123
124 if (numberOfInputChannels == m_internalSummingBus->numberOfChannels()) 124 if (numberOfInputChannels == m_internalSummingBus->numberOfChannels())
125 return; 125 return;
126 126
127 m_internalSummingBus = AudioBus::create(numberOfInputChannels, AudioHandler: :ProcessingSizeInFrames); 127 m_internalSummingBus = AudioBus::create(numberOfInputChannels, AudioHandler: :ProcessingSizeInFrames);
128 } 128 }
129 129
130 unsigned AudioNodeInput::numberOfChannels() const 130 unsigned AudioNodeInput::numberOfChannels() const
(...skipping 12 matching lines...) Expand all
143 } 143 }
144 144
145 if (mode == AudioHandler::ClampedMax) 145 if (mode == AudioHandler::ClampedMax)
146 maxChannels = std::min(maxChannels, static_cast<unsigned>(handler().chan nelCount())); 146 maxChannels = std::min(maxChannels, static_cast<unsigned>(handler().chan nelCount()));
147 147
148 return maxChannels; 148 return maxChannels;
149 } 149 }
150 150
151 AudioBus* AudioNodeInput::bus() 151 AudioBus* AudioNodeInput::bus()
152 { 152 {
153 ASSERT(deferredTaskHandler().isAudioThread()); 153 DCHECK(deferredTaskHandler().isAudioThread());
154 154
155 // Handle single connection specially to allow for in-place processing. 155 // Handle single connection specially to allow for in-place processing.
156 if (numberOfRenderingConnections() == 1 && handler().internalChannelCountMod e() == AudioHandler::Max) 156 if (numberOfRenderingConnections() == 1 && handler().internalChannelCountMod e() == AudioHandler::Max)
157 return renderingOutput(0)->bus(); 157 return renderingOutput(0)->bus();
158 158
159 // Multiple connections case or complex ChannelCountMode (or no connections) . 159 // Multiple connections case or complex ChannelCountMode (or no connections) .
160 return internalSummingBus(); 160 return internalSummingBus();
161 } 161 }
162 162
163 AudioBus* AudioNodeInput::internalSummingBus() 163 AudioBus* AudioNodeInput::internalSummingBus()
164 { 164 {
165 ASSERT(deferredTaskHandler().isAudioThread()); 165 DCHECK(deferredTaskHandler().isAudioThread());
166 166
167 return m_internalSummingBus.get(); 167 return m_internalSummingBus.get();
168 } 168 }
169 169
170 void AudioNodeInput::sumAllConnections(AudioBus* summingBus, size_t framesToProc ess) 170 void AudioNodeInput::sumAllConnections(AudioBus* summingBus, size_t framesToProc ess)
171 { 171 {
172 ASSERT(deferredTaskHandler().isAudioThread()); 172 DCHECK(deferredTaskHandler().isAudioThread());
173 173
174 // We shouldn't be calling this method if there's only one connection, since it's less efficient. 174 // We shouldn't be calling this method if there's only one connection, since it's less efficient.
175 ASSERT(numberOfRenderingConnections() > 1 || handler().internalChannelCountM ode() != AudioHandler::Max); 175 DCHECK_GT(numberOfRenderingConnections(), 1u);
176 DCHECK_NE(handler().internalChannelCountMode(), AudioHandler::Max);
176 177
177 ASSERT(summingBus); 178 DCHECK(summingBus);
178 if (!summingBus) 179 if (!summingBus)
179 return; 180 return;
180 181
181 summingBus->zero(); 182 summingBus->zero();
182 183
183 AudioBus::ChannelInterpretation interpretation = handler().internalChannelIn terpretation(); 184 AudioBus::ChannelInterpretation interpretation = handler().internalChannelIn terpretation();
184 185
185 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) { 186 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) {
186 AudioNodeOutput* output = renderingOutput(i); 187 AudioNodeOutput* output = renderingOutput(i);
187 ASSERT(output); 188 DCHECK(output);
188 189
189 // Render audio from this output. 190 // Render audio from this output.
190 AudioBus* connectionBus = output->pull(0, framesToProcess); 191 AudioBus* connectionBus = output->pull(0, framesToProcess);
191 192
192 // Sum, with unity-gain. 193 // Sum, with unity-gain.
193 summingBus->sumFrom(*connectionBus, interpretation); 194 summingBus->sumFrom(*connectionBus, interpretation);
194 } 195 }
195 } 196 }
196 197
197 AudioBus* AudioNodeInput::pull(AudioBus* inPlaceBus, size_t framesToProcess) 198 AudioBus* AudioNodeInput::pull(AudioBus* inPlaceBus, size_t framesToProcess)
198 { 199 {
199 ASSERT(deferredTaskHandler().isAudioThread()); 200 DCHECK(deferredTaskHandler().isAudioThread());
200 201
201 // Handle single connection case. 202 // Handle single connection case.
202 if (numberOfRenderingConnections() == 1 && handler().internalChannelCountMod e() == AudioHandler::Max) { 203 if (numberOfRenderingConnections() == 1 && handler().internalChannelCountMod e() == AudioHandler::Max) {
203 // The output will optimize processing using inPlaceBus if it's able. 204 // The output will optimize processing using inPlaceBus if it's able.
204 AudioNodeOutput* output = this->renderingOutput(0); 205 AudioNodeOutput* output = this->renderingOutput(0);
205 return output->pull(inPlaceBus, framesToProcess); 206 return output->pull(inPlaceBus, framesToProcess);
206 } 207 }
207 208
208 AudioBus* internalSummingBus = this->internalSummingBus(); 209 AudioBus* internalSummingBus = this->internalSummingBus();
209 210
210 if (!numberOfRenderingConnections()) { 211 if (!numberOfRenderingConnections()) {
211 // At least, generate silence if we're not connected to anything. 212 // At least, generate silence if we're not connected to anything.
212 // FIXME: if we wanted to get fancy, we could propagate a 'silent hint' here to optimize the downstream graph processing. 213 // FIXME: if we wanted to get fancy, we could propagate a 'silent hint' here to optimize the downstream graph processing.
213 internalSummingBus->zero(); 214 internalSummingBus->zero();
214 return internalSummingBus; 215 return internalSummingBus;
215 } 216 }
216 217
217 // Handle multiple connections case. 218 // Handle multiple connections case.
218 sumAllConnections(internalSummingBus, framesToProcess); 219 sumAllConnections(internalSummingBus, framesToProcess);
219 220
220 return internalSummingBus; 221 return internalSummingBus;
221 } 222 }
222 223
223 } // namespace blink 224 } // namespace blink
224 225
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698