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

Side by Side Diff: Source/modules/webaudio/AudioNode.cpp

Issue 886173004: Fix AudioNode.disconnect() to support selective disconnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added comments and fixed exception messages Created 5 years, 10 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
295 // Sanity check on the output index.
296 if (outputIndex >= numberOfOutputs()) {
297 exceptionState.throwDOMException(
298 IndexSizeError,
299 ExceptionMessages::indexOutsideRange(
300 "output",
Raymond Toy 2015/02/12 19:45:53 Would the error message be better if you said "out
hongchan 2015/02/13 01:16:57 I went back and forth on this one. Now the whole m
301 outputIndex,
302 0u,
303 ExceptionMessages::InclusiveBound,
304 numberOfOutputs(),
305 ExceptionMessages::InclusiveBound));
306 return;
307 }
308
309 // Disconnect all outgoing connections from the given output.
310 AudioNodeOutput* output = this->output(outputIndex);
311 output->disconnectAll();
312 }
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 // Sanity check on output index.
349 if (outputIndex >= numberOfOutputs()) {
350 exceptionState.throwDOMException(
351 IndexSizeError,
352 ExceptionMessages::indexOutsideRange(
353 "output",
Raymond Toy 2015/02/12 19:45:53 Same comment as on line 300.
354 outputIndex,
355 0u,
356 ExceptionMessages::InclusiveBound,
357 numberOfOutputs(),
358 ExceptionMessages::InclusiveBound));
359 return;
360 }
361
362 unsigned numberOfDisconnections = 0;
363 AudioNodeOutput* output = this->output(outputIndex);
364
365 // Sanity check on destination inputs and disconnect when possible.
366 for (unsigned i = 0; i < destination->numberOfInputs(); ++i) {
367 AudioNodeInput* input = destination->input(i);
368 if (output->isConnectedToInput(*input)) {
369 output->disconnectInput(*input);
370 numberOfDisconnections++;
371 }
372 }
373
374 // If there is no connection to the destination, throw an exception.
375 if (numberOfDisconnections == 0) {
376 exceptionState.throwDOMException(
377 InvalidAccessError,
378 "output (" + String::number(outputIndex) + ") is not connected to th e given destination.");
379 return;
380 }
381 }
382
383 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, unsigne d inputIndex, ExceptionState& exceptionState)
384 {
385 ASSERT(isMainThread());
386 AudioContext::AutoLocker locker(context());
387
285 // Sanity check input and output indices. 388 // Sanity check input and output indices.
286 if (outputIndex >= numberOfOutputs()) { 389 if (outputIndex >= numberOfOutputs()) {
287 exceptionState.throwDOMException( 390 exceptionState.throwDOMException(
288 IndexSizeError, 391 IndexSizeError,
289 "output index (" + String::number(outputIndex) + ") exceeds number o f outputs (" + String::number(numberOfOutputs()) + ")."); 392 ExceptionMessages::indexOutsideRange(
290 return; 393 "output",
291 } 394 outputIndex,
292 395 0u,
293 AudioNodeOutput* output = this->output(outputIndex); 396 ExceptionMessages::InclusiveBound,
294 output->disconnectAll(); 397 numberOfOutputs(),
398 ExceptionMessages::InclusiveBound));
399 return;
400 }
401
402 if (inputIndex >= destination->numberOfInputs()) {
403 exceptionState.throwDOMException(
404 IndexSizeError,
405 ExceptionMessages::indexOutsideRange(
406 "input",
407 outputIndex,
408 0u,
409 ExceptionMessages::InclusiveBound,
410 destination->numberOfInputs(),
411 ExceptionMessages::InclusiveBound));
412 return;
413 }
414
415 AudioNodeOutput* output = this->output(outputIndex);
416 AudioNodeInput* input = destination->input(inputIndex);
417
418 // Sanity check on the connection between the output and the destination inp ut.
419 if (!output->isConnectedToInput(*input)) {
420 exceptionState.throwDOMException(
421 InvalidAccessError,
422 "output (" + String::number(outputIndex) + ") is not connected to th e input (" + String::number(inputIndex) + ") of the destination.");
423 return;
424 }
425
426 output->disconnectInput(*input);
427 }
428
429 void AudioNode::disconnect(AudioParam* destinationParam, ExceptionState& excepti onState)
430 {
431 ASSERT(isMainThread());
432 AudioContext::AutoLocker locker(context());
433
434 unsigned numberOfDisconnections = 0;
435
436 for (unsigned i = 0; i < numberOfOutputs(); ++i) {
437 AudioNodeOutput* output = this->output(i);
438 if (output->isConnectedToAudioParam(*destinationParam)) {
439 output->disconnectAudioParam(*destinationParam);
440 numberOfDisconnections++;
441 }
442 }
443
444 // Throw an exception when there is no valid connection to the destination.
445 if (numberOfDisconnections == 0) {
446 exceptionState.throwDOMException(
447 InvalidAccessError,
448 "the node and the given AudioParam are not connected.");
Raymond Toy 2015/02/12 19:45:53 Make this error message consistent with the error
hongchan 2015/02/13 01:16:57 Done.
449 return;
450 }
451 }
452
453 void AudioNode::disconnect(AudioParam* destinationParam, unsigned outputIndex, E xceptionState& exceptionState)
454 {
455 ASSERT(isMainThread());
456 AudioContext::AutoLocker locker(context());
457
458 // Sanity check on the output index.
459 if (outputIndex >= numberOfOutputs()) {
460 exceptionState.throwDOMException(
461 IndexSizeError,
462 ExceptionMessages::indexOutsideRange(
463 "output",
464 outputIndex,
465 0u,
466 ExceptionMessages::InclusiveBound,
467 numberOfOutputs(),
468 ExceptionMessages::InclusiveBound));
469 return;
470 }
471
472 AudioNodeOutput* output = this->output(outputIndex);
473
474 // Sanity check on the connection between the output and the destination.
475 if (!output->isConnectedToAudioParam(*destinationParam)) {
476 exceptionState.throwDOMException(
477 InvalidAccessError,
478 "specified destination AudioParam and node output (" + String::numbe r(outputIndex) + ") are not connected.");
479 return;
480 }
481
482 output->disconnectAudioParam(*destinationParam);
295 } 483 }
296 484
297 void AudioNode::disconnectWithoutException(unsigned outputIndex) 485 void AudioNode::disconnectWithoutException(unsigned outputIndex)
298 { 486 {
299 ASSERT(isMainThread()); 487 ASSERT(isMainThread());
300 AudioContext::AutoLocker locker(context()); 488 AudioContext::AutoLocker locker(context());
301 489
302 // Sanity check input and output indices. 490 // Sanity check input and output indices.
303 if (outputIndex < numberOfOutputs()) { 491 if (outputIndex < numberOfOutputs()) {
304 AudioNodeOutput* output = this->output(outputIndex); 492 AudioNodeOutput* output = this->output(outputIndex);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 791
604 void AudioNode::updateChannelCountMode() 792 void AudioNode::updateChannelCountMode()
605 { 793 {
606 m_channelCountMode = m_newChannelCountMode; 794 m_channelCountMode = m_newChannelCountMode;
607 updateChannelsForInputs(); 795 updateChannelsForInputs();
608 } 796 }
609 797
610 } // namespace blink 798 } // namespace blink
611 799
612 #endif // ENABLE(WEB_AUDIO) 800 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698