Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 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 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
| 28 | 28 |
| 29 #include "modules/webaudio/AudioNode.h" | 29 #include "modules/webaudio/AudioNode.h" |
| 30 | 30 |
| 31 #include "bindings/v8/ExceptionMessages.h" | |
| 31 #include "bindings/v8/ExceptionState.h" | 32 #include "bindings/v8/ExceptionState.h" |
| 32 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 33 #include "modules/webaudio/AudioContext.h" | 34 #include "modules/webaudio/AudioContext.h" |
| 34 #include "modules/webaudio/AudioNodeInput.h" | 35 #include "modules/webaudio/AudioNodeInput.h" |
| 35 #include "modules/webaudio/AudioNodeOutput.h" | 36 #include "modules/webaudio/AudioNodeOutput.h" |
| 36 #include "modules/webaudio/AudioParam.h" | 37 #include "modules/webaudio/AudioParam.h" |
| 37 #include "wtf/Atomics.h" | 38 #include "wtf/Atomics.h" |
| 38 #include "wtf/MainThread.h" | 39 #include "wtf/MainThread.h" |
| 39 | 40 |
| 40 #if DEBUG_AUDIONODE_REFERENCES | 41 #if DEBUG_AUDIONODE_REFERENCES |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 return m_outputs[i].get(); | 124 return m_outputs[i].get(); |
| 124 return 0; | 125 return 0; |
| 125 } | 126 } |
| 126 | 127 |
| 127 void AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsigned i nputIndex, ExceptionState& es) | 128 void AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsigned i nputIndex, ExceptionState& es) |
| 128 { | 129 { |
| 129 ASSERT(isMainThread()); | 130 ASSERT(isMainThread()); |
| 130 AudioContext::AutoLocker locker(context()); | 131 AudioContext::AutoLocker locker(context()); |
| 131 | 132 |
| 132 if (!destination) { | 133 if (!destination) { |
| 133 es.throwUninformativeAndGenericDOMException(SyntaxError); | 134 es.throwDOMException( |
| 135 SyntaxError, | |
| 136 ExceptionMessages::failedToExecute( | |
| 137 "connect", | |
| 138 "AudioNode", | |
| 139 "invalid destination node.")); | |
| 134 return; | 140 return; |
| 135 } | 141 } |
| 136 | 142 |
| 137 // Sanity check input and output indices. | 143 // Sanity check input and output indices. |
| 138 if (outputIndex >= numberOfOutputs()) { | 144 if (outputIndex >= numberOfOutputs()) { |
| 139 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 145 es.throwDOMException( |
| 146 IndexSizeError, | |
| 147 ExceptionMessages::failedToExecute( | |
| 148 "connect", | |
| 149 "AudioNode", | |
| 150 "invalid output index.")); | |
|
Mike West
2013/09/27 06:44:39
"The provided output index (8) is larger than the
| |
| 140 return; | 151 return; |
| 141 } | 152 } |
| 142 | 153 |
| 143 if (destination && inputIndex >= destination->numberOfInputs()) { | 154 if (destination && inputIndex >= destination->numberOfInputs()) { |
| 144 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 155 es.throwDOMException( |
| 156 IndexSizeError, | |
| 157 ExceptionMessages::failedToExecute( | |
| 158 "connect", | |
| 159 "AudioNode", | |
| 160 "invalid input index.")); | |
|
Mike West
2013/09/27 06:44:39
Same as above.
| |
| 145 return; | 161 return; |
| 146 } | 162 } |
| 147 | 163 |
| 148 if (context() != destination->context()) { | 164 if (context() != destination->context()) { |
| 149 es.throwUninformativeAndGenericDOMException(SyntaxError); | 165 es.throwDOMException( |
| 166 SyntaxError, | |
| 167 ExceptionMessages::failedToExecute( | |
| 168 "connect", | |
| 169 "AudioNode", | |
| 170 "invalid destination context.")); | |
| 150 return; | 171 return; |
| 151 } | 172 } |
| 152 | 173 |
| 153 AudioNodeInput* input = destination->input(inputIndex); | 174 AudioNodeInput* input = destination->input(inputIndex); |
| 154 AudioNodeOutput* output = this->output(outputIndex); | 175 AudioNodeOutput* output = this->output(outputIndex); |
| 155 input->connect(output); | 176 input->connect(output); |
| 156 | 177 |
| 157 // Let context know that a connection has been made. | 178 // Let context know that a connection has been made. |
| 158 context()->incrementConnectionCount(); | 179 context()->incrementConnectionCount(); |
| 159 } | 180 } |
| 160 | 181 |
| 161 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState& es) | 182 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState& es) |
| 162 { | 183 { |
| 163 ASSERT(isMainThread()); | 184 ASSERT(isMainThread()); |
| 164 AudioContext::AutoLocker locker(context()); | 185 AudioContext::AutoLocker locker(context()); |
| 165 | 186 |
| 166 if (!param) { | 187 if (!param) { |
| 167 es.throwUninformativeAndGenericDOMException(SyntaxError); | 188 es.throwDOMException( |
| 189 SyntaxError, | |
| 190 ExceptionMessages::failedToExecute( | |
| 191 "connect", | |
| 192 "AudioNode", | |
| 193 "invalid AudioParam.")); | |
| 168 return; | 194 return; |
| 169 } | 195 } |
| 170 | 196 |
| 171 if (outputIndex >= numberOfOutputs()) { | 197 if (outputIndex >= numberOfOutputs()) { |
| 172 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 198 es.throwDOMException( |
| 199 IndexSizeError, | |
| 200 ExceptionMessages::failedToExecute( | |
| 201 "connect", | |
| 202 "AudioNode", | |
| 203 "invalid output index.")); | |
| 173 return; | 204 return; |
| 174 } | 205 } |
| 175 | 206 |
| 176 if (context() != param->context()) { | 207 if (context() != param->context()) { |
| 177 es.throwUninformativeAndGenericDOMException(SyntaxError); | 208 es.throwDOMException( |
| 209 SyntaxError, | |
| 210 ExceptionMessages::failedToExecute( | |
| 211 "connect", | |
| 212 "AudioNode", | |
| 213 "destination context is different.")); | |
| 178 return; | 214 return; |
| 179 } | 215 } |
| 180 | 216 |
| 181 AudioNodeOutput* output = this->output(outputIndex); | 217 AudioNodeOutput* output = this->output(outputIndex); |
| 182 param->connect(output); | 218 param->connect(output); |
| 183 } | 219 } |
| 184 | 220 |
| 185 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& es) | 221 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& es) |
| 186 { | 222 { |
| 187 ASSERT(isMainThread()); | 223 ASSERT(isMainThread()); |
| 188 AudioContext::AutoLocker locker(context()); | 224 AudioContext::AutoLocker locker(context()); |
| 189 | 225 |
| 190 // Sanity check input and output indices. | 226 // Sanity check input and output indices. |
| 191 if (outputIndex >= numberOfOutputs()) { | 227 if (outputIndex >= numberOfOutputs()) { |
| 192 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 228 es.throwDOMException( |
| 229 IndexSizeError, | |
| 230 ExceptionMessages::failedToExecute( | |
| 231 "disconnect", | |
| 232 "AudioNode", | |
| 233 "invalid output index.")); | |
|
Mike West
2013/09/27 06:44:39
Same as above.
| |
| 193 return; | 234 return; |
| 194 } | 235 } |
| 195 | 236 |
| 196 AudioNodeOutput* output = this->output(outputIndex); | 237 AudioNodeOutput* output = this->output(outputIndex); |
| 197 output->disconnectAll(); | 238 output->disconnectAll(); |
| 198 } | 239 } |
| 199 | 240 |
| 200 unsigned long AudioNode::channelCount() | 241 unsigned long AudioNode::channelCount() |
| 201 { | 242 { |
| 202 return m_channelCount; | 243 return m_channelCount; |
| 203 } | 244 } |
| 204 | 245 |
| 205 void AudioNode::setChannelCount(unsigned long channelCount, ExceptionState& es) | 246 void AudioNode::setChannelCount(unsigned long channelCount, ExceptionState& es) |
| 206 { | 247 { |
| 207 ASSERT(isMainThread()); | 248 ASSERT(isMainThread()); |
| 208 AudioContext::AutoLocker locker(context()); | 249 AudioContext::AutoLocker locker(context()); |
| 209 | 250 |
| 210 if (channelCount > 0 && channelCount <= AudioContext::maxNumberOfChannels()) { | 251 if (channelCount > 0 && channelCount <= AudioContext::maxNumberOfChannels()) { |
| 211 if (m_channelCount != channelCount) { | 252 if (m_channelCount != channelCount) { |
| 212 m_channelCount = channelCount; | 253 m_channelCount = channelCount; |
| 213 if (m_channelCountMode != Max) | 254 if (m_channelCountMode != Max) |
| 214 updateChannelsForInputs(); | 255 updateChannelsForInputs(); |
| 215 } | 256 } |
| 216 } else { | 257 } else { |
| 217 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 258 es.throwDOMException( |
| 259 InvalidStateError, | |
| 260 ExceptionMessages::failedToSet( | |
| 261 "channelCount", | |
| 262 "AudioNode", | |
| 263 "invalid number of channels.")); | |
|
Mike West
2013/09/27 06:44:39
Perhaps split this into "The channel count may not
| |
| 218 } | 264 } |
| 219 } | 265 } |
| 220 | 266 |
| 221 String AudioNode::channelCountMode() | 267 String AudioNode::channelCountMode() |
| 222 { | 268 { |
| 223 switch (m_channelCountMode) { | 269 switch (m_channelCountMode) { |
| 224 case Max: | 270 case Max: |
| 225 return "max"; | 271 return "max"; |
| 226 case ClampedMax: | 272 case ClampedMax: |
| 227 return "clamped-max"; | 273 return "clamped-max"; |
| 228 case Explicit: | 274 case Explicit: |
| 229 return "explicit"; | 275 return "explicit"; |
| 230 } | 276 } |
| 231 ASSERT_NOT_REACHED(); | 277 ASSERT_NOT_REACHED(); |
| 232 return ""; | 278 return ""; |
| 233 } | 279 } |
| 234 | 280 |
| 235 void AudioNode::setChannelCountMode(const String& mode, ExceptionState& es) | 281 void AudioNode::setChannelCountMode(const String& mode, ExceptionState& es) |
| 236 { | 282 { |
| 237 ASSERT(isMainThread()); | 283 ASSERT(isMainThread()); |
| 238 AudioContext::AutoLocker locker(context()); | 284 AudioContext::AutoLocker locker(context()); |
| 239 | 285 |
| 240 ChannelCountMode oldMode = m_channelCountMode; | 286 ChannelCountMode oldMode = m_channelCountMode; |
| 241 | 287 |
| 242 if (mode == "max") | 288 if (mode == "max") { |
| 243 m_channelCountMode = Max; | 289 m_channelCountMode = Max; |
| 244 else if (mode == "clamped-max") | 290 } else if (mode == "clamped-max") { |
| 245 m_channelCountMode = ClampedMax; | 291 m_channelCountMode = ClampedMax; |
| 246 else if (mode == "explicit") | 292 } else if (mode == "explicit") { |
| 247 m_channelCountMode = Explicit; | 293 m_channelCountMode = Explicit; |
| 248 else | 294 } else { |
| 249 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 295 es.throwDOMException( |
| 296 InvalidStateError, | |
| 297 ExceptionMessages::failedToSet( | |
| 298 "channelCountMode", | |
| 299 "AudioNode", | |
| 300 "must be \"max\", \"clamped-max\", or \"explicit\".")); | |
|
Mike West
2013/09/27 06:44:39
I'd suggest including the developer's input here:
Raymond Toy (Google)
2013/09/27 16:24:10
Agreed.
| |
| 301 } | |
| 250 | 302 |
| 251 if (m_channelCountMode != oldMode) | 303 if (m_channelCountMode != oldMode) |
| 252 updateChannelsForInputs(); | 304 updateChannelsForInputs(); |
| 253 } | 305 } |
| 254 | 306 |
| 255 String AudioNode::channelInterpretation() | 307 String AudioNode::channelInterpretation() |
| 256 { | 308 { |
| 257 switch (m_channelInterpretation) { | 309 switch (m_channelInterpretation) { |
| 258 case AudioBus::Speakers: | 310 case AudioBus::Speakers: |
| 259 return "speakers"; | 311 return "speakers"; |
| 260 case AudioBus::Discrete: | 312 case AudioBus::Discrete: |
| 261 return "discrete"; | 313 return "discrete"; |
| 262 } | 314 } |
| 263 ASSERT_NOT_REACHED(); | 315 ASSERT_NOT_REACHED(); |
| 264 return ""; | 316 return ""; |
| 265 } | 317 } |
| 266 | 318 |
| 267 void AudioNode::setChannelInterpretation(const String& interpretation, Exception State& es) | 319 void AudioNode::setChannelInterpretation(const String& interpretation, Exception State& es) |
| 268 { | 320 { |
| 269 ASSERT(isMainThread()); | 321 ASSERT(isMainThread()); |
| 270 AudioContext::AutoLocker locker(context()); | 322 AudioContext::AutoLocker locker(context()); |
| 271 | 323 |
| 272 if (interpretation == "speakers") | 324 if (interpretation == "speakers") { |
| 273 m_channelInterpretation = AudioBus::Speakers; | 325 m_channelInterpretation = AudioBus::Speakers; |
| 274 else if (interpretation == "discrete") | 326 } else if (interpretation == "discrete") { |
| 275 m_channelInterpretation = AudioBus::Discrete; | 327 m_channelInterpretation = AudioBus::Discrete; |
| 276 else | 328 } else { |
| 277 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 329 es.throwDOMException( |
| 330 InvalidStateError, | |
| 331 ExceptionMessages::failedToSet( | |
| 332 "channelInterpretation", | |
| 333 "AudioNode", | |
| 334 "must be \"speakers\" or \"discrete\".")); | |
|
Mike West
2013/09/27 06:44:39
Same as above.
| |
| 335 } | |
| 278 } | 336 } |
| 279 | 337 |
| 280 void AudioNode::updateChannelsForInputs() | 338 void AudioNode::updateChannelsForInputs() |
| 281 { | 339 { |
| 282 for (unsigned i = 0; i < m_inputs.size(); ++i) | 340 for (unsigned i = 0; i < m_inputs.size(); ++i) |
| 283 input(i)->changedOutputs(); | 341 input(i)->changedOutputs(); |
| 284 } | 342 } |
| 285 | 343 |
| 286 const AtomicString& AudioNode::interfaceName() const | 344 const AtomicString& AudioNode::interfaceName() const |
| 287 { | 345 { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 fprintf(stderr, "%d: %d\n", i, s_nodeCount[i]); | 577 fprintf(stderr, "%d: %d\n", i, s_nodeCount[i]); |
| 520 | 578 |
| 521 fprintf(stderr, "===========================\n\n\n"); | 579 fprintf(stderr, "===========================\n\n\n"); |
| 522 } | 580 } |
| 523 | 581 |
| 524 #endif // DEBUG_AUDIONODE_REFERENCES | 582 #endif // DEBUG_AUDIONODE_REFERENCES |
| 525 | 583 |
| 526 } // namespace WebCore | 584 } // namespace WebCore |
| 527 | 585 |
| 528 #endif // ENABLE(WEB_AUDIO) | 586 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |