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