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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (context() != param->context()) { | 270 if (context() != param->context()) { |
271 exceptionState.throwDOMException( | 271 exceptionState.throwDOMException( |
272 SyntaxError, | 272 SyntaxError, |
273 "cannot connect to an AudioParam belonging to a different audio cont
ext."); | 273 "cannot connect to an AudioParam belonging to a different audio cont
ext."); |
274 return; | 274 return; |
275 } | 275 } |
276 | 276 |
277 param->connect(*output(outputIndex)); | 277 param->connect(*output(outputIndex)); |
278 } | 278 } |
279 | 279 |
| 280 void AudioNode::disconnect() |
| 281 { |
| 282 ASSERT(isMainThread()); |
| 283 AudioContext::AutoLocker locker(context()); |
| 284 |
| 285 // Disconnect all outgoing connections. |
| 286 for (unsigned i = 0; i < numberOfOutputs(); ++i) |
| 287 this->output(i)->disconnectAll(); |
| 288 } |
| 289 |
280 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& exceptionState) | 290 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& exceptionState) |
281 { | 291 { |
282 ASSERT(isMainThread()); | 292 ASSERT(isMainThread()); |
283 AudioContext::AutoLocker locker(context()); | 293 AudioContext::AutoLocker locker(context()); |
284 | 294 |
285 // Sanity check input and output indices. | 295 // Sanity check on the output index. |
286 if (outputIndex >= numberOfOutputs()) { | 296 if (outputIndex >= numberOfOutputs()) { |
287 exceptionState.throwDOMException( | 297 exceptionState.throwDOMException( |
288 IndexSizeError, | 298 IndexSizeError, |
289 "output index (" + String::number(outputIndex) + ") exceeds number o
f outputs (" + String::number(numberOfOutputs()) + ")."); | 299 ExceptionMessages::indexOutsideRange( |
290 return; | 300 "output index", |
291 } | 301 outputIndex, |
292 | 302 0u, |
| 303 ExceptionMessages::InclusiveBound, |
| 304 numberOfOutputs(), |
| 305 ExceptionMessages::InclusiveBound)); |
| 306 return; |
| 307 } |
| 308 |
| 309 // Disconnect all outgoing connections from the given output. |
293 AudioNodeOutput* output = this->output(outputIndex); | 310 AudioNodeOutput* output = this->output(outputIndex); |
294 output->disconnectAll(); | 311 output->disconnectAll(); |
295 } | 312 } |
296 | 313 |
| 314 void AudioNode::disconnect(AudioNode* destination, ExceptionState& exceptionStat
e) |
| 315 { |
| 316 ASSERT(isMainThread()); |
| 317 AudioContext::AutoLocker locker(context()); |
| 318 |
| 319 unsigned numberOfDisconnections = 0; |
| 320 |
| 321 // FIXME: Can this be optimized? ChannelSplitter and ChannelMerger can have |
| 322 // 32 ports and that requires 1024 iterations to validate entire connections
. |
| 323 for (unsigned i = 0; i < numberOfOutputs(); ++i) { |
| 324 AudioNodeOutput* output = this->output(i); |
| 325 for (unsigned j = 0; j < destination->numberOfInputs(); ++j) { |
| 326 AudioNodeInput* input = destination->input(j); |
| 327 if (output->isConnectedToInput(*input)) { |
| 328 output->disconnectInput(*input); |
| 329 numberOfDisconnections++; |
| 330 } |
| 331 } |
| 332 } |
| 333 |
| 334 // If there is no connection to the destination, throw an exception. |
| 335 if (numberOfDisconnections == 0) { |
| 336 exceptionState.throwDOMException( |
| 337 InvalidAccessError, |
| 338 "the given destination is not connected."); |
| 339 return; |
| 340 } |
| 341 } |
| 342 |
| 343 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, Excepti
onState& exceptionState) |
| 344 { |
| 345 ASSERT(isMainThread()); |
| 346 AudioContext::AutoLocker locker(context()); |
| 347 |
| 348 bool isOutputIndexInRange = outputIndex < numberOfOutputs(); |
| 349 |
| 350 // If the output index is valid, proceed to disconnect. |
| 351 if (isOutputIndexInRange) { |
| 352 unsigned numberOfDisconnections = 0; |
| 353 AudioNodeOutput* output = this->output(outputIndex); |
| 354 |
| 355 // Sanity check on destination inputs and disconnect when possible. |
| 356 for (unsigned i = 0; i < destination->numberOfInputs(); ++i) { |
| 357 AudioNodeInput* input = destination->input(i); |
| 358 if (output->isConnectedToInput(*input)) { |
| 359 output->disconnectInput(*input); |
| 360 numberOfDisconnections++; |
| 361 } |
| 362 } |
| 363 |
| 364 // If there is no connection to the destination, throw an exception. |
| 365 if (numberOfDisconnections == 0) { |
| 366 exceptionState.throwDOMException( |
| 367 InvalidAccessError, |
| 368 "output (" + String::number(outputIndex) + ") is not connected t
o the given destination."); |
| 369 return; |
| 370 } |
| 371 |
| 372 } else { |
| 373 |
| 374 // The output index is out of range. Throw an exception. |
| 375 exceptionState.throwDOMException( |
| 376 IndexSizeError, |
| 377 ExceptionMessages::indexOutsideRange( |
| 378 "output index", |
| 379 outputIndex, |
| 380 0u, |
| 381 ExceptionMessages::InclusiveBound, |
| 382 numberOfOutputs(), |
| 383 ExceptionMessages::InclusiveBound)); |
| 384 return; |
| 385 } |
| 386 } |
| 387 |
| 388 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, unsigne
d inputIndex, ExceptionState& exceptionState) |
| 389 { |
| 390 ASSERT(isMainThread()); |
| 391 AudioContext::AutoLocker locker(context()); |
| 392 |
| 393 bool isOutputIndexInRange = outputIndex < numberOfOutputs(); |
| 394 bool isInputIndexInRange = inputIndex < destination->numberOfInputs(); |
| 395 |
| 396 // If both indices are valid, proceed to disconnect. |
| 397 if (isOutputIndexInRange && isInputIndexInRange) { |
| 398 AudioNodeOutput* output = this->output(outputIndex); |
| 399 AudioNodeInput* input = destination->input(inputIndex); |
| 400 |
| 401 // Sanity check on the connection between the output and the destination
input. |
| 402 if (!output->isConnectedToInput(*input)) { |
| 403 exceptionState.throwDOMException( |
| 404 InvalidAccessError, |
| 405 "output (" + String::number(outputIndex) + ") is not connected t
o the input (" + String::number(inputIndex) + ") of the destination."); |
| 406 return; |
| 407 } |
| 408 |
| 409 output->disconnectInput(*input); |
| 410 } |
| 411 |
| 412 // Sanity check input and output indices. |
| 413 if (!isOutputIndexInRange) { |
| 414 exceptionState.throwDOMException( |
| 415 IndexSizeError, |
| 416 ExceptionMessages::indexOutsideRange( |
| 417 "output index", |
| 418 outputIndex, |
| 419 0u, |
| 420 ExceptionMessages::InclusiveBound, |
| 421 numberOfOutputs(), |
| 422 ExceptionMessages::InclusiveBound)); |
| 423 return; |
| 424 } |
| 425 |
| 426 if (!isInputIndexInRange) { |
| 427 exceptionState.throwDOMException( |
| 428 IndexSizeError, |
| 429 ExceptionMessages::indexOutsideRange( |
| 430 "input index", |
| 431 inputIndex, |
| 432 0u, |
| 433 ExceptionMessages::InclusiveBound, |
| 434 destination->numberOfInputs(), |
| 435 ExceptionMessages::InclusiveBound)); |
| 436 return; |
| 437 } |
| 438 } |
| 439 |
| 440 void AudioNode::disconnect(AudioParam* destinationParam, ExceptionState& excepti
onState) |
| 441 { |
| 442 ASSERT(isMainThread()); |
| 443 AudioContext::AutoLocker locker(context()); |
| 444 |
| 445 // The number of disconnection made. |
| 446 unsigned numberOfDisconnections = 0; |
| 447 |
| 448 // Check if the node output is connected the destination AudioParam. |
| 449 // Disconnect if connected and increase |numberOfDisconnectios| by 1. |
| 450 for (unsigned i = 0; i < numberOfOutputs(); ++i) { |
| 451 AudioNodeOutput* output = this->output(i); |
| 452 if (output->isConnectedToAudioParam(*destinationParam)) { |
| 453 output->disconnectAudioParam(*destinationParam); |
| 454 numberOfDisconnections++; |
| 455 } |
| 456 } |
| 457 |
| 458 // Throw an exception when there is no valid connection to the destination. |
| 459 if (numberOfDisconnections == 0) { |
| 460 exceptionState.throwDOMException( |
| 461 InvalidAccessError, |
| 462 "the given AudioParam is not connected."); |
| 463 return; |
| 464 } |
| 465 } |
| 466 |
| 467 void AudioNode::disconnect(AudioParam* destinationParam, unsigned outputIndex, E
xceptionState& exceptionState) |
| 468 { |
| 469 ASSERT(isMainThread()); |
| 470 AudioContext::AutoLocker locker(context()); |
| 471 |
| 472 bool isOutputIndexInRange = outputIndex < numberOfOutputs(); |
| 473 |
| 474 // If the output index is valid, proceed to disconnect. |
| 475 if (isOutputIndexInRange) { |
| 476 AudioNodeOutput* output = this->output(outputIndex); |
| 477 |
| 478 // Sanity check on the connection between the output and the destination
. |
| 479 if (!output->isConnectedToAudioParam(*destinationParam)) { |
| 480 exceptionState.throwDOMException( |
| 481 InvalidAccessError, |
| 482 "specified destination AudioParam and node output (" + String::n
umber(outputIndex) + ") are not connected."); |
| 483 return; |
| 484 } |
| 485 |
| 486 output->disconnectAudioParam(*destinationParam); |
| 487 } else { |
| 488 |
| 489 // The output index is out of range. Throw an exception. |
| 490 exceptionState.throwDOMException( |
| 491 IndexSizeError, |
| 492 ExceptionMessages::indexOutsideRange( |
| 493 "output index", |
| 494 outputIndex, |
| 495 0u, |
| 496 ExceptionMessages::InclusiveBound, |
| 497 numberOfOutputs(), |
| 498 ExceptionMessages::InclusiveBound)); |
| 499 return; |
| 500 } |
| 501 } |
| 502 |
297 void AudioNode::disconnectWithoutException(unsigned outputIndex) | 503 void AudioNode::disconnectWithoutException(unsigned outputIndex) |
298 { | 504 { |
299 ASSERT(isMainThread()); | 505 ASSERT(isMainThread()); |
300 AudioContext::AutoLocker locker(context()); | 506 AudioContext::AutoLocker locker(context()); |
301 | 507 |
302 // Sanity check input and output indices. | 508 // Sanity check input and output indices. |
303 if (outputIndex < numberOfOutputs()) { | 509 if (outputIndex < numberOfOutputs()) { |
304 AudioNodeOutput* output = this->output(outputIndex); | 510 AudioNodeOutput* output = this->output(outputIndex); |
305 output->disconnectAll(); | 511 output->disconnectAll(); |
306 } | 512 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 809 |
604 void AudioNode::updateChannelCountMode() | 810 void AudioNode::updateChannelCountMode() |
605 { | 811 { |
606 m_channelCountMode = m_newChannelCountMode; | 812 m_channelCountMode = m_newChannelCountMode; |
607 updateChannelsForInputs(); | 813 updateChannelsForInputs(); |
608 } | 814 } |
609 | 815 |
610 } // namespace blink | 816 } // namespace blink |
611 | 817 |
612 #endif // ENABLE(WEB_AUDIO) | 818 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |