| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 if (!s_isNodeCountInitialized) { | 58 if (!s_isNodeCountInitialized) { |
| 59 s_isNodeCountInitialized = true; | 59 s_isNodeCountInitialized = true; |
| 60 atexit(AudioHandler::printNodeCounts); | 60 atexit(AudioHandler::printNodeCounts); |
| 61 } | 61 } |
| 62 #endif | 62 #endif |
| 63 InstanceCounters::incrementCounter(InstanceCounters::AudioHandlerCounter); | 63 InstanceCounters::incrementCounter(InstanceCounters::AudioHandlerCounter); |
| 64 } | 64 } |
| 65 | 65 |
| 66 AudioHandler::~AudioHandler() | 66 AudioHandler::~AudioHandler() |
| 67 { | 67 { |
| 68 ASSERT(isMainThread()); | 68 DCHECK(isMainThread()); |
| 69 // dispose() should be called. | 69 // dispose() should be called. |
| 70 ASSERT(!node()); | 70 DCHECK(!node()); |
| 71 InstanceCounters::decrementCounter(InstanceCounters::AudioHandlerCounter); | 71 InstanceCounters::decrementCounter(InstanceCounters::AudioHandlerCounter); |
| 72 #if DEBUG_AUDIONODE_REFERENCES | 72 #if DEBUG_AUDIONODE_REFERENCES |
| 73 --s_nodeCount[getNodeType()]; | 73 --s_nodeCount[getNodeType()]; |
| 74 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::~AudioHandler() %d [%d]\n"
, | 74 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::~AudioHandler() %d [%d]\n"
, |
| 75 context(), this, getNodeType(), m_connectionRefCount, s_nodeCount[getNod
eType()]); | 75 context(), this, getNodeType(), m_connectionRefCount, s_nodeCount[getNod
eType()]); |
| 76 #endif | 76 #endif |
| 77 } | 77 } |
| 78 | 78 |
| 79 void AudioHandler::initialize() | 79 void AudioHandler::initialize() |
| 80 { | 80 { |
| 81 m_isInitialized = true; | 81 m_isInitialized = true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void AudioHandler::uninitialize() | 84 void AudioHandler::uninitialize() |
| 85 { | 85 { |
| 86 m_isInitialized = false; | 86 m_isInitialized = false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void AudioHandler::clearInternalStateWhenDisabled() | 89 void AudioHandler::clearInternalStateWhenDisabled() |
| 90 { | 90 { |
| 91 } | 91 } |
| 92 | 92 |
| 93 void AudioHandler::dispose() | 93 void AudioHandler::dispose() |
| 94 { | 94 { |
| 95 ASSERT(isMainThread()); | 95 DCHECK(isMainThread()); |
| 96 ASSERT(context()->isGraphOwner()); | 96 ASSERT(context()->isGraphOwner()); |
| 97 | 97 |
| 98 context()->deferredTaskHandler().removeAutomaticPullNode(this); | 98 context()->deferredTaskHandler().removeAutomaticPullNode(this); |
| 99 for (auto& output : m_outputs) | 99 for (auto& output : m_outputs) |
| 100 output->dispose(); | 100 output->dispose(); |
| 101 m_node = nullptr; | 101 m_node = nullptr; |
| 102 } | 102 } |
| 103 | 103 |
| 104 AudioNode* AudioHandler::node() const | 104 AudioNode* AudioHandler::node() const |
| 105 { | 105 { |
| 106 ASSERT(isMainThread()); | 106 DCHECK(isMainThread()); |
| 107 return m_node; | 107 return m_node; |
| 108 } | 108 } |
| 109 | 109 |
| 110 BaseAudioContext* AudioHandler::context() const | 110 BaseAudioContext* AudioHandler::context() const |
| 111 { | 111 { |
| 112 return m_context; | 112 return m_context; |
| 113 } | 113 } |
| 114 | 114 |
| 115 String AudioHandler::nodeTypeName() const | 115 String AudioHandler::nodeTypeName() const |
| 116 { | 116 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 default: | 156 default: |
| 157 ASSERT_NOT_REACHED(); | 157 ASSERT_NOT_REACHED(); |
| 158 return "UnknownNode"; | 158 return "UnknownNode"; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 void AudioHandler::setNodeType(NodeType type) | 162 void AudioHandler::setNodeType(NodeType type) |
| 163 { | 163 { |
| 164 // Don't allow the node type to be changed to a different node type, after i
t's already been | 164 // Don't allow the node type to be changed to a different node type, after i
t's already been |
| 165 // set! And the new type can't be unknown or end! | 165 // set! And the new type can't be unknown or end! |
| 166 ASSERT(m_nodeType == NodeTypeUnknown); | 166 DCHECK_EQ(m_nodeType, NodeTypeUnknown); |
| 167 ASSERT(type != NodeTypeUnknown); | 167 DCHECK_NE(type, NodeTypeUnknown); |
| 168 ASSERT(type != NodeTypeEnd); | 168 DCHECK_NE(type, NodeTypeEnd); |
| 169 | 169 |
| 170 m_nodeType = type; | 170 m_nodeType = type; |
| 171 | 171 |
| 172 #if DEBUG_AUDIONODE_REFERENCES | 172 #if DEBUG_AUDIONODE_REFERENCES |
| 173 ++s_nodeCount[type]; | 173 ++s_nodeCount[type]; |
| 174 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::AudioHandler [%3d]\n", | 174 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::AudioHandler [%3d]\n", |
| 175 context(), this, getNodeType(), s_nodeCount[getNodeType()]); | 175 context(), this, getNodeType(), s_nodeCount[getNodeType()]); |
| 176 #endif | 176 #endif |
| 177 } | 177 } |
| 178 | 178 |
| 179 void AudioHandler::addInput() | 179 void AudioHandler::addInput() |
| 180 { | 180 { |
| 181 m_inputs.append(AudioNodeInput::create(*this)); | 181 m_inputs.append(AudioNodeInput::create(*this)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void AudioHandler::addOutput(unsigned numberOfChannels) | 184 void AudioHandler::addOutput(unsigned numberOfChannels) |
| 185 { | 185 { |
| 186 ASSERT(isMainThread()); | 186 DCHECK(isMainThread()); |
| 187 m_outputs.append(AudioNodeOutput::create(this, numberOfChannels)); | 187 m_outputs.append(AudioNodeOutput::create(this, numberOfChannels)); |
| 188 node()->didAddOutput(numberOfOutputs()); | 188 node()->didAddOutput(numberOfOutputs()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 AudioNodeInput& AudioHandler::input(unsigned i) | 191 AudioNodeInput& AudioHandler::input(unsigned i) |
| 192 { | 192 { |
| 193 return *m_inputs[i]; | 193 return *m_inputs[i]; |
| 194 } | 194 } |
| 195 | 195 |
| 196 AudioNodeOutput& AudioHandler::output(unsigned i) | 196 AudioNodeOutput& AudioHandler::output(unsigned i) |
| 197 { | 197 { |
| 198 return *m_outputs[i]; | 198 return *m_outputs[i]; |
| 199 } | 199 } |
| 200 | 200 |
| 201 unsigned long AudioHandler::channelCount() | 201 unsigned long AudioHandler::channelCount() |
| 202 { | 202 { |
| 203 return m_channelCount; | 203 return m_channelCount; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void AudioHandler::setChannelCount(unsigned long channelCount, ExceptionState& e
xceptionState) | 206 void AudioHandler::setChannelCount(unsigned long channelCount, ExceptionState& e
xceptionState) |
| 207 { | 207 { |
| 208 ASSERT(isMainThread()); | 208 DCHECK(isMainThread()); |
| 209 BaseAudioContext::AutoLocker locker(context()); | 209 BaseAudioContext::AutoLocker locker(context()); |
| 210 | 210 |
| 211 if (channelCount > 0 && channelCount <= BaseAudioContext::maxNumberOfChannel
s()) { | 211 if (channelCount > 0 && channelCount <= BaseAudioContext::maxNumberOfChannel
s()) { |
| 212 if (m_channelCount != channelCount) { | 212 if (m_channelCount != channelCount) { |
| 213 m_channelCount = channelCount; | 213 m_channelCount = channelCount; |
| 214 if (internalChannelCountMode() != Max) | 214 if (internalChannelCountMode() != Max) |
| 215 updateChannelsForInputs(); | 215 updateChannelsForInputs(); |
| 216 } | 216 } |
| 217 } else { | 217 } else { |
| 218 exceptionState.throwDOMException( | 218 exceptionState.throwDOMException( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 236 return "clamped-max"; | 236 return "clamped-max"; |
| 237 case Explicit: | 237 case Explicit: |
| 238 return "explicit"; | 238 return "explicit"; |
| 239 } | 239 } |
| 240 ASSERT_NOT_REACHED(); | 240 ASSERT_NOT_REACHED(); |
| 241 return ""; | 241 return ""; |
| 242 } | 242 } |
| 243 | 243 |
| 244 void AudioHandler::setChannelCountMode(const String& mode, ExceptionState& excep
tionState) | 244 void AudioHandler::setChannelCountMode(const String& mode, ExceptionState& excep
tionState) |
| 245 { | 245 { |
| 246 ASSERT(isMainThread()); | 246 DCHECK(isMainThread()); |
| 247 BaseAudioContext::AutoLocker locker(context()); | 247 BaseAudioContext::AutoLocker locker(context()); |
| 248 | 248 |
| 249 if (mode == "max") { | 249 if (mode == "max") { |
| 250 setInternalChannelCountMode(Max); | 250 setInternalChannelCountMode(Max); |
| 251 } else if (mode == "clamped-max") { | 251 } else if (mode == "clamped-max") { |
| 252 setInternalChannelCountMode(ClampedMax); | 252 setInternalChannelCountMode(ClampedMax); |
| 253 } else if (mode == "explicit") { | 253 } else if (mode == "explicit") { |
| 254 setInternalChannelCountMode(Explicit); | 254 setInternalChannelCountMode(Explicit); |
| 255 } else { | 255 } else { |
| 256 ASSERT_NOT_REACHED(); | 256 ASSERT_NOT_REACHED(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 268 return "speakers"; | 268 return "speakers"; |
| 269 case AudioBus::Discrete: | 269 case AudioBus::Discrete: |
| 270 return "discrete"; | 270 return "discrete"; |
| 271 } | 271 } |
| 272 ASSERT_NOT_REACHED(); | 272 ASSERT_NOT_REACHED(); |
| 273 return ""; | 273 return ""; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void AudioHandler::setChannelInterpretation(const String& interpretation, Except
ionState& exceptionState) | 276 void AudioHandler::setChannelInterpretation(const String& interpretation, Except
ionState& exceptionState) |
| 277 { | 277 { |
| 278 ASSERT(isMainThread()); | 278 DCHECK(isMainThread()); |
| 279 BaseAudioContext::AutoLocker locker(context()); | 279 BaseAudioContext::AutoLocker locker(context()); |
| 280 | 280 |
| 281 if (interpretation == "speakers") { | 281 if (interpretation == "speakers") { |
| 282 setInternalChannelInterpretation(AudioBus::Speakers); | 282 setInternalChannelInterpretation(AudioBus::Speakers); |
| 283 } else if (interpretation == "discrete") { | 283 } else if (interpretation == "discrete") { |
| 284 setInternalChannelInterpretation(AudioBus::Discrete); | 284 setInternalChannelInterpretation(AudioBus::Discrete); |
| 285 } else { | 285 } else { |
| 286 ASSERT_NOT_REACHED(); | 286 ASSERT_NOT_REACHED(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Changing the channel interpretation doesn't change the number of output | 289 // Changing the channel interpretation doesn't change the number of output |
| 290 // channels, so we don't need to do any update here. The contents of each | 290 // channels, so we don't need to do any update here. The contents of each |
| 291 // channel may change, of course, but that doesn't require updating the | 291 // channel may change, of course, but that doesn't require updating the |
| 292 // nodes for a different number of channels. | 292 // nodes for a different number of channels. |
| 293 } | 293 } |
| 294 | 294 |
| 295 void AudioHandler::updateChannelsForInputs() | 295 void AudioHandler::updateChannelsForInputs() |
| 296 { | 296 { |
| 297 for (auto& input : m_inputs) | 297 for (auto& input : m_inputs) |
| 298 input->changedOutputs(); | 298 input->changedOutputs(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void AudioHandler::processIfNecessary(size_t framesToProcess) | 301 void AudioHandler::processIfNecessary(size_t framesToProcess) |
| 302 { | 302 { |
| 303 ASSERT(context()->isAudioThread()); | 303 DCHECK(context()->isAudioThread()); |
| 304 | 304 |
| 305 if (!isInitialized()) | 305 if (!isInitialized()) |
| 306 return; | 306 return; |
| 307 | 307 |
| 308 // Ensure that we only process once per rendering quantum. | 308 // Ensure that we only process once per rendering quantum. |
| 309 // This handles the "fanout" problem where an output is connected to multipl
e inputs. | 309 // This handles the "fanout" problem where an output is connected to multipl
e inputs. |
| 310 // The first time we're called during this time slice we process, but after
that we don't want to re-process, | 310 // The first time we're called during this time slice we process, but after
that we don't want to re-process, |
| 311 // instead our output(s) will already have the results cached in their bus; | 311 // instead our output(s) will already have the results cached in their bus; |
| 312 double currentTime = context()->currentTime(); | 312 double currentTime = context()->currentTime(); |
| 313 if (m_lastProcessingTime != currentTime) { | 313 if (m_lastProcessingTime != currentTime) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 326 // to go silent and we want to propagate that hint to the downstream
nodes! (For | 326 // to go silent and we want to propagate that hint to the downstream
nodes! (For |
| 327 // example, a Gain node with a gain of 0 will want to silence its ou
tput.) | 327 // example, a Gain node with a gain of 0 will want to silence its ou
tput.) |
| 328 unsilenceOutputs(); | 328 unsilenceOutputs(); |
| 329 process(framesToProcess); | 329 process(framesToProcess); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 void AudioHandler::checkNumberOfChannelsForInput(AudioNodeInput* input) | 334 void AudioHandler::checkNumberOfChannelsForInput(AudioNodeInput* input) |
| 335 { | 335 { |
| 336 ASSERT(context()->isAudioThread()); | 336 DCHECK(context()->isAudioThread()); |
| 337 ASSERT(context()->isGraphOwner()); | 337 ASSERT(context()->isGraphOwner()); |
| 338 | 338 |
| 339 ASSERT(m_inputs.contains(input)); | 339 DCHECK(m_inputs.contains(input)); |
| 340 if (!m_inputs.contains(input)) | 340 if (!m_inputs.contains(input)) |
| 341 return; | 341 return; |
| 342 | 342 |
| 343 input->updateInternalBus(); | 343 input->updateInternalBus(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 double AudioHandler::tailTime() const | 346 double AudioHandler::tailTime() const |
| 347 { | 347 { |
| 348 return 0; | 348 return 0; |
| 349 } | 349 } |
| 350 | 350 |
| 351 double AudioHandler::latencyTime() const | 351 double AudioHandler::latencyTime() const |
| 352 { | 352 { |
| 353 return 0; | 353 return 0; |
| 354 } | 354 } |
| 355 | 355 |
| 356 bool AudioHandler::propagatesSilence() const | 356 bool AudioHandler::propagatesSilence() const |
| 357 { | 357 { |
| 358 return m_lastNonSilentTime + latencyTime() + tailTime() < context()->current
Time(); | 358 return m_lastNonSilentTime + latencyTime() + tailTime() < context()->current
Time(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void AudioHandler::pullInputs(size_t framesToProcess) | 361 void AudioHandler::pullInputs(size_t framesToProcess) |
| 362 { | 362 { |
| 363 ASSERT(context()->isAudioThread()); | 363 DCHECK(context()->isAudioThread()); |
| 364 | 364 |
| 365 // Process all of the AudioNodes connected to our inputs. | 365 // Process all of the AudioNodes connected to our inputs. |
| 366 for (auto& input : m_inputs) | 366 for (auto& input : m_inputs) |
| 367 input->pull(0, framesToProcess); | 367 input->pull(0, framesToProcess); |
| 368 } | 368 } |
| 369 | 369 |
| 370 bool AudioHandler::inputsAreSilent() | 370 bool AudioHandler::inputsAreSilent() |
| 371 { | 371 { |
| 372 for (auto& input : m_inputs) { | 372 for (auto& input : m_inputs) { |
| 373 if (!input->bus()->isSilent()) | 373 if (!input->bus()->isSilent()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 384 | 384 |
| 385 void AudioHandler::unsilenceOutputs() | 385 void AudioHandler::unsilenceOutputs() |
| 386 { | 386 { |
| 387 for (auto& output : m_outputs) | 387 for (auto& output : m_outputs) |
| 388 output->bus()->clearSilentFlag(); | 388 output->bus()->clearSilentFlag(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void AudioHandler::enableOutputsIfNecessary() | 391 void AudioHandler::enableOutputsIfNecessary() |
| 392 { | 392 { |
| 393 if (m_isDisabled && m_connectionRefCount > 0) { | 393 if (m_isDisabled && m_connectionRefCount > 0) { |
| 394 ASSERT(isMainThread()); | 394 DCHECK(isMainThread()); |
| 395 BaseAudioContext::AutoLocker locker(context()); | 395 BaseAudioContext::AutoLocker locker(context()); |
| 396 | 396 |
| 397 m_isDisabled = false; | 397 m_isDisabled = false; |
| 398 for (auto& output : m_outputs) | 398 for (auto& output : m_outputs) |
| 399 output->enable(); | 399 output->enable(); |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 | 402 |
| 403 void AudioHandler::disableOutputsIfNecessary() | 403 void AudioHandler::disableOutputsIfNecessary() |
| 404 { | 404 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 context()->lock(); | 458 context()->lock(); |
| 459 hasLock = true; | 459 hasLock = true; |
| 460 } | 460 } |
| 461 | 461 |
| 462 if (hasLock) { | 462 if (hasLock) { |
| 463 breakConnectionWithLock(); | 463 breakConnectionWithLock(); |
| 464 context()->unlock(); | 464 context()->unlock(); |
| 465 } else { | 465 } else { |
| 466 // We were unable to get the lock, so put this in a list to finish up | 466 // We were unable to get the lock, so put this in a list to finish up |
| 467 // later. | 467 // later. |
| 468 ASSERT(context()->isAudioThread()); | 468 DCHECK(context()->isAudioThread()); |
| 469 context()->deferredTaskHandler().addDeferredBreakConnection(*this); | 469 context()->deferredTaskHandler().addDeferredBreakConnection(*this); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 void AudioHandler::breakConnectionWithLock() | 473 void AudioHandler::breakConnectionWithLock() |
| 474 { | 474 { |
| 475 atomicDecrement(&m_connectionRefCount); | 475 atomicDecrement(&m_connectionRefCount); |
| 476 | 476 |
| 477 #if DEBUG_AUDIONODE_REFERENCES | 477 #if DEBUG_AUDIONODE_REFERENCES |
| 478 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::deref %3d [%3d]\n", | 478 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::deref %3d [%3d]\n", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 515 |
| 516 AudioNode::AudioNode(BaseAudioContext& context) | 516 AudioNode::AudioNode(BaseAudioContext& context) |
| 517 : m_context(context) | 517 : m_context(context) |
| 518 , m_handler(nullptr) | 518 , m_handler(nullptr) |
| 519 { | 519 { |
| 520 ThreadState::current()->registerPreFinalizer(this); | 520 ThreadState::current()->registerPreFinalizer(this); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void AudioNode::dispose() | 523 void AudioNode::dispose() |
| 524 { | 524 { |
| 525 ASSERT(isMainThread()); | 525 DCHECK(isMainThread()); |
| 526 #if DEBUG_AUDIONODE_REFERENCES | 526 #if DEBUG_AUDIONODE_REFERENCES |
| 527 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::dispose %16p\n", | 527 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::dispose %16p\n", |
| 528 context(), this, handler().getNodeType(), m_handler.get()); | 528 context(), this, handler().getNodeType(), m_handler.get()); |
| 529 #endif | 529 #endif |
| 530 BaseAudioContext::AutoLocker locker(context()); | 530 BaseAudioContext::AutoLocker locker(context()); |
| 531 handler().dispose(); | 531 handler().dispose(); |
| 532 if (context()->contextState() == BaseAudioContext::Running) | 532 if (context()->contextState() == BaseAudioContext::Running) |
| 533 context()->deferredTaskHandler().addRenderingOrphanHandler(m_handler.rel
ease()); | 533 context()->deferredTaskHandler().addRenderingOrphanHandler(m_handler.rel
ease()); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void AudioNode::setHandler(PassRefPtr<AudioHandler> handler) | 536 void AudioNode::setHandler(PassRefPtr<AudioHandler> handler) |
| 537 { | 537 { |
| 538 ASSERT(handler); | 538 DCHECK(handler); |
| 539 m_handler = handler; | 539 m_handler = handler; |
| 540 | 540 |
| 541 #if DEBUG_AUDIONODE_REFERENCES | 541 #if DEBUG_AUDIONODE_REFERENCES |
| 542 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::AudioNode %16p\n", | 542 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::AudioNode %16p\n", |
| 543 context(), this, m_handler->getNodeType(), m_handler.get()); | 543 context(), this, m_handler->getNodeType(), m_handler.get()); |
| 544 #endif | 544 #endif |
| 545 } | 545 } |
| 546 | 546 |
| 547 AudioHandler& AudioNode::handler() const | 547 AudioHandler& AudioNode::handler() const |
| 548 { | 548 { |
| 549 return *m_handler; | 549 return *m_handler; |
| 550 } | 550 } |
| 551 | 551 |
| 552 DEFINE_TRACE(AudioNode) | 552 DEFINE_TRACE(AudioNode) |
| 553 { | 553 { |
| 554 visitor->trace(m_context); | 554 visitor->trace(m_context); |
| 555 visitor->trace(m_connectedNodes); | 555 visitor->trace(m_connectedNodes); |
| 556 visitor->trace(m_connectedParams); | 556 visitor->trace(m_connectedParams); |
| 557 EventTargetWithInlineData::trace(visitor); | 557 EventTargetWithInlineData::trace(visitor); |
| 558 } | 558 } |
| 559 | 559 |
| 560 BaseAudioContext* AudioNode::context() const | 560 BaseAudioContext* AudioNode::context() const |
| 561 { | 561 { |
| 562 return m_context; | 562 return m_context; |
| 563 } | 563 } |
| 564 | 564 |
| 565 AudioNode* AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsi
gned inputIndex, ExceptionState& exceptionState) | 565 AudioNode* AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsi
gned inputIndex, ExceptionState& exceptionState) |
| 566 { | 566 { |
| 567 ASSERT(isMainThread()); | 567 DCHECK(isMainThread()); |
| 568 BaseAudioContext::AutoLocker locker(context()); | 568 BaseAudioContext::AutoLocker locker(context()); |
| 569 | 569 |
| 570 if (context()->isContextClosed()) { | 570 if (context()->isContextClosed()) { |
| 571 exceptionState.throwDOMException( | 571 exceptionState.throwDOMException( |
| 572 InvalidStateError, | 572 InvalidStateError, |
| 573 "Cannot connect after the context has been closed."); | 573 "Cannot connect after the context has been closed."); |
| 574 return nullptr; | 574 return nullptr; |
| 575 } | 575 } |
| 576 | 576 |
| 577 if (!destination) { | 577 if (!destination) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 m_connectedNodes[outputIndex]->add(destination); | 619 m_connectedNodes[outputIndex]->add(destination); |
| 620 | 620 |
| 621 // Let context know that a connection has been made. | 621 // Let context know that a connection has been made. |
| 622 context()->incrementConnectionCount(); | 622 context()->incrementConnectionCount(); |
| 623 | 623 |
| 624 return destination; | 624 return destination; |
| 625 } | 625 } |
| 626 | 626 |
| 627 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState&
exceptionState) | 627 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState&
exceptionState) |
| 628 { | 628 { |
| 629 ASSERT(isMainThread()); | 629 DCHECK(isMainThread()); |
| 630 BaseAudioContext::AutoLocker locker(context()); | 630 BaseAudioContext::AutoLocker locker(context()); |
| 631 | 631 |
| 632 if (context()->isContextClosed()) { | 632 if (context()->isContextClosed()) { |
| 633 exceptionState.throwDOMException( | 633 exceptionState.throwDOMException( |
| 634 InvalidStateError, | 634 InvalidStateError, |
| 635 "Cannot connect after the context has been closed."); | 635 "Cannot connect after the context has been closed."); |
| 636 return; | 636 return; |
| 637 } | 637 } |
| 638 | 638 |
| 639 if (!param) { | 639 if (!param) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 AudioNodeOutput& output = handler().output(outputIndex); | 686 AudioNodeOutput& output = handler().output(outputIndex); |
| 687 if (!output.isConnectedToAudioParam(param.handler())) | 687 if (!output.isConnectedToAudioParam(param.handler())) |
| 688 return false; | 688 return false; |
| 689 output.disconnectAudioParam(param.handler()); | 689 output.disconnectAudioParam(param.handler()); |
| 690 m_connectedParams[outputIndex]->remove(¶m); | 690 m_connectedParams[outputIndex]->remove(¶m); |
| 691 return true; | 691 return true; |
| 692 } | 692 } |
| 693 | 693 |
| 694 void AudioNode::disconnect() | 694 void AudioNode::disconnect() |
| 695 { | 695 { |
| 696 ASSERT(isMainThread()); | 696 DCHECK(isMainThread()); |
| 697 BaseAudioContext::AutoLocker locker(context()); | 697 BaseAudioContext::AutoLocker locker(context()); |
| 698 | 698 |
| 699 // Disconnect all outgoing connections. | 699 // Disconnect all outgoing connections. |
| 700 for (unsigned i = 0; i < numberOfOutputs(); ++i) | 700 for (unsigned i = 0; i < numberOfOutputs(); ++i) |
| 701 disconnectAllFromOutput(i); | 701 disconnectAllFromOutput(i); |
| 702 } | 702 } |
| 703 | 703 |
| 704 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& exceptionState) | 704 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& exceptionState) |
| 705 { | 705 { |
| 706 ASSERT(isMainThread()); | 706 DCHECK(isMainThread()); |
| 707 BaseAudioContext::AutoLocker locker(context()); | 707 BaseAudioContext::AutoLocker locker(context()); |
| 708 | 708 |
| 709 // Sanity check on the output index. | 709 // Sanity check on the output index. |
| 710 if (outputIndex >= numberOfOutputs()) { | 710 if (outputIndex >= numberOfOutputs()) { |
| 711 exceptionState.throwDOMException( | 711 exceptionState.throwDOMException( |
| 712 IndexSizeError, | 712 IndexSizeError, |
| 713 ExceptionMessages::indexOutsideRange( | 713 ExceptionMessages::indexOutsideRange( |
| 714 "output index", | 714 "output index", |
| 715 outputIndex, | 715 outputIndex, |
| 716 0u, | 716 0u, |
| 717 ExceptionMessages::InclusiveBound, | 717 ExceptionMessages::InclusiveBound, |
| 718 numberOfOutputs() - 1, | 718 numberOfOutputs() - 1, |
| 719 ExceptionMessages::InclusiveBound)); | 719 ExceptionMessages::InclusiveBound)); |
| 720 return; | 720 return; |
| 721 } | 721 } |
| 722 // Disconnect all outgoing connections from the given output. | 722 // Disconnect all outgoing connections from the given output. |
| 723 disconnectAllFromOutput(outputIndex); | 723 disconnectAllFromOutput(outputIndex); |
| 724 } | 724 } |
| 725 | 725 |
| 726 void AudioNode::disconnect(AudioNode* destination, ExceptionState& exceptionStat
e) | 726 void AudioNode::disconnect(AudioNode* destination, ExceptionState& exceptionStat
e) |
| 727 { | 727 { |
| 728 ASSERT(isMainThread()); | 728 DCHECK(isMainThread()); |
| 729 BaseAudioContext::AutoLocker locker(context()); | 729 BaseAudioContext::AutoLocker locker(context()); |
| 730 | 730 |
| 731 unsigned numberOfDisconnections = 0; | 731 unsigned numberOfDisconnections = 0; |
| 732 | 732 |
| 733 // FIXME: Can this be optimized? ChannelSplitter and ChannelMerger can have | 733 // FIXME: Can this be optimized? ChannelSplitter and ChannelMerger can have |
| 734 // 32 ports and that requires 1024 iterations to validate entire connections
. | 734 // 32 ports and that requires 1024 iterations to validate entire connections
. |
| 735 for (unsigned outputIndex = 0; outputIndex < numberOfOutputs(); ++outputInde
x) { | 735 for (unsigned outputIndex = 0; outputIndex < numberOfOutputs(); ++outputInde
x) { |
| 736 for (unsigned inputIndex = 0; inputIndex < destination->handler().number
OfInputs(); ++inputIndex) { | 736 for (unsigned inputIndex = 0; inputIndex < destination->handler().number
OfInputs(); ++inputIndex) { |
| 737 if (disconnectFromOutputIfConnected(outputIndex, *destination, input
Index)) | 737 if (disconnectFromOutputIfConnected(outputIndex, *destination, input
Index)) |
| 738 numberOfDisconnections++; | 738 numberOfDisconnections++; |
| 739 } | 739 } |
| 740 } | 740 } |
| 741 | 741 |
| 742 // If there is no connection to the destination, throw an exception. | 742 // If there is no connection to the destination, throw an exception. |
| 743 if (numberOfDisconnections == 0) { | 743 if (numberOfDisconnections == 0) { |
| 744 exceptionState.throwDOMException( | 744 exceptionState.throwDOMException( |
| 745 InvalidAccessError, | 745 InvalidAccessError, |
| 746 "the given destination is not connected."); | 746 "the given destination is not connected."); |
| 747 return; | 747 return; |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 | 750 |
| 751 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, Excepti
onState& exceptionState) | 751 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, Excepti
onState& exceptionState) |
| 752 { | 752 { |
| 753 ASSERT(isMainThread()); | 753 DCHECK(isMainThread()); |
| 754 BaseAudioContext::AutoLocker locker(context()); | 754 BaseAudioContext::AutoLocker locker(context()); |
| 755 | 755 |
| 756 if (outputIndex >= numberOfOutputs()) { | 756 if (outputIndex >= numberOfOutputs()) { |
| 757 // The output index is out of range. Throw an exception. | 757 // The output index is out of range. Throw an exception. |
| 758 exceptionState.throwDOMException( | 758 exceptionState.throwDOMException( |
| 759 IndexSizeError, | 759 IndexSizeError, |
| 760 ExceptionMessages::indexOutsideRange( | 760 ExceptionMessages::indexOutsideRange( |
| 761 "output index", | 761 "output index", |
| 762 outputIndex, | 762 outputIndex, |
| 763 0u, | 763 0u, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 778 // If there is no connection to the destination, throw an exception. | 778 // If there is no connection to the destination, throw an exception. |
| 779 if (numberOfDisconnections == 0) { | 779 if (numberOfDisconnections == 0) { |
| 780 exceptionState.throwDOMException( | 780 exceptionState.throwDOMException( |
| 781 InvalidAccessError, | 781 InvalidAccessError, |
| 782 "output (" + String::number(outputIndex) + ") is not connected to th
e given destination."); | 782 "output (" + String::number(outputIndex) + ") is not connected to th
e given destination."); |
| 783 } | 783 } |
| 784 } | 784 } |
| 785 | 785 |
| 786 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, unsigne
d inputIndex, ExceptionState& exceptionState) | 786 void AudioNode::disconnect(AudioNode* destination, unsigned outputIndex, unsigne
d inputIndex, ExceptionState& exceptionState) |
| 787 { | 787 { |
| 788 ASSERT(isMainThread()); | 788 DCHECK(isMainThread()); |
| 789 BaseAudioContext::AutoLocker locker(context()); | 789 BaseAudioContext::AutoLocker locker(context()); |
| 790 | 790 |
| 791 if (outputIndex >= numberOfOutputs()) { | 791 if (outputIndex >= numberOfOutputs()) { |
| 792 exceptionState.throwDOMException( | 792 exceptionState.throwDOMException( |
| 793 IndexSizeError, | 793 IndexSizeError, |
| 794 ExceptionMessages::indexOutsideRange( | 794 ExceptionMessages::indexOutsideRange( |
| 795 "output index", | 795 "output index", |
| 796 outputIndex, | 796 outputIndex, |
| 797 0u, | 797 0u, |
| 798 ExceptionMessages::InclusiveBound, | 798 ExceptionMessages::InclusiveBound, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 818 if (!disconnectFromOutputIfConnected(outputIndex, *destination, inputIndex))
{ | 818 if (!disconnectFromOutputIfConnected(outputIndex, *destination, inputIndex))
{ |
| 819 exceptionState.throwDOMException( | 819 exceptionState.throwDOMException( |
| 820 InvalidAccessError, | 820 InvalidAccessError, |
| 821 "output (" + String::number(outputIndex) + ") is not connected to th
e input (" + String::number(inputIndex) + ") of the destination."); | 821 "output (" + String::number(outputIndex) + ") is not connected to th
e input (" + String::number(inputIndex) + ") of the destination."); |
| 822 return; | 822 return; |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 | 825 |
| 826 void AudioNode::disconnect(AudioParam* destinationParam, ExceptionState& excepti
onState) | 826 void AudioNode::disconnect(AudioParam* destinationParam, ExceptionState& excepti
onState) |
| 827 { | 827 { |
| 828 ASSERT(isMainThread()); | 828 DCHECK(isMainThread()); |
| 829 BaseAudioContext::AutoLocker locker(context()); | 829 BaseAudioContext::AutoLocker locker(context()); |
| 830 | 830 |
| 831 // The number of disconnection made. | 831 // The number of disconnection made. |
| 832 unsigned numberOfDisconnections = 0; | 832 unsigned numberOfDisconnections = 0; |
| 833 | 833 |
| 834 // Check if the node output is connected the destination AudioParam. | 834 // Check if the node output is connected the destination AudioParam. |
| 835 // Disconnect if connected and increase |numberOfDisconnectios| by 1. | 835 // Disconnect if connected and increase |numberOfDisconnectios| by 1. |
| 836 for (unsigned outputIndex = 0; outputIndex < handler().numberOfOutputs(); ++
outputIndex) { | 836 for (unsigned outputIndex = 0; outputIndex < handler().numberOfOutputs(); ++
outputIndex) { |
| 837 if (disconnectFromOutputIfConnected(outputIndex, *destinationParam)) | 837 if (disconnectFromOutputIfConnected(outputIndex, *destinationParam)) |
| 838 numberOfDisconnections++; | 838 numberOfDisconnections++; |
| 839 } | 839 } |
| 840 | 840 |
| 841 // Throw an exception when there is no valid connection to the destination. | 841 // Throw an exception when there is no valid connection to the destination. |
| 842 if (numberOfDisconnections == 0) { | 842 if (numberOfDisconnections == 0) { |
| 843 exceptionState.throwDOMException( | 843 exceptionState.throwDOMException( |
| 844 InvalidAccessError, | 844 InvalidAccessError, |
| 845 "the given AudioParam is not connected."); | 845 "the given AudioParam is not connected."); |
| 846 return; | 846 return; |
| 847 } | 847 } |
| 848 } | 848 } |
| 849 | 849 |
| 850 void AudioNode::disconnect(AudioParam* destinationParam, unsigned outputIndex, E
xceptionState& exceptionState) | 850 void AudioNode::disconnect(AudioParam* destinationParam, unsigned outputIndex, E
xceptionState& exceptionState) |
| 851 { | 851 { |
| 852 ASSERT(isMainThread()); | 852 DCHECK(isMainThread()); |
| 853 BaseAudioContext::AutoLocker locker(context()); | 853 BaseAudioContext::AutoLocker locker(context()); |
| 854 | 854 |
| 855 if (outputIndex >= handler().numberOfOutputs()) { | 855 if (outputIndex >= handler().numberOfOutputs()) { |
| 856 // The output index is out of range. Throw an exception. | 856 // The output index is out of range. Throw an exception. |
| 857 exceptionState.throwDOMException( | 857 exceptionState.throwDOMException( |
| 858 IndexSizeError, | 858 IndexSizeError, |
| 859 ExceptionMessages::indexOutsideRange( | 859 ExceptionMessages::indexOutsideRange( |
| 860 "output index", | 860 "output index", |
| 861 outputIndex, | 861 outputIndex, |
| 862 0u, | 862 0u, |
| 863 ExceptionMessages::InclusiveBound, | 863 ExceptionMessages::InclusiveBound, |
| 864 numberOfOutputs() - 1, | 864 numberOfOutputs() - 1, |
| 865 ExceptionMessages::InclusiveBound)); | 865 ExceptionMessages::InclusiveBound)); |
| 866 return; | 866 return; |
| 867 } | 867 } |
| 868 | 868 |
| 869 // If the output index is valid, proceed to disconnect. | 869 // If the output index is valid, proceed to disconnect. |
| 870 if (!disconnectFromOutputIfConnected(outputIndex, *destinationParam)) { | 870 if (!disconnectFromOutputIfConnected(outputIndex, *destinationParam)) { |
| 871 exceptionState.throwDOMException( | 871 exceptionState.throwDOMException( |
| 872 InvalidAccessError, | 872 InvalidAccessError, |
| 873 "specified destination AudioParam and node output (" + String::numbe
r(outputIndex) + ") are not connected."); | 873 "specified destination AudioParam and node output (" + String::numbe
r(outputIndex) + ") are not connected."); |
| 874 return; | 874 return; |
| 875 } | 875 } |
| 876 } | 876 } |
| 877 | 877 |
| 878 void AudioNode::disconnectWithoutException(unsigned outputIndex) | 878 void AudioNode::disconnectWithoutException(unsigned outputIndex) |
| 879 { | 879 { |
| 880 ASSERT(isMainThread()); | 880 DCHECK(isMainThread()); |
| 881 BaseAudioContext::AutoLocker locker(context()); | 881 BaseAudioContext::AutoLocker locker(context()); |
| 882 | 882 |
| 883 // Sanity check input and output indices. | 883 // Sanity check input and output indices. |
| 884 if (outputIndex >= handler().numberOfOutputs()) | 884 if (outputIndex >= handler().numberOfOutputs()) |
| 885 return; | 885 return; |
| 886 disconnectAllFromOutput(outputIndex); | 886 disconnectAllFromOutput(outputIndex); |
| 887 } | 887 } |
| 888 | 888 |
| 889 unsigned AudioNode::numberOfInputs() const | 889 unsigned AudioNode::numberOfInputs() const |
| 890 { | 890 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 } | 932 } |
| 933 | 933 |
| 934 ExecutionContext* AudioNode::getExecutionContext() const | 934 ExecutionContext* AudioNode::getExecutionContext() const |
| 935 { | 935 { |
| 936 return context()->getExecutionContext(); | 936 return context()->getExecutionContext(); |
| 937 } | 937 } |
| 938 | 938 |
| 939 void AudioNode::didAddOutput(unsigned numberOfOutputs) | 939 void AudioNode::didAddOutput(unsigned numberOfOutputs) |
| 940 { | 940 { |
| 941 m_connectedNodes.append(nullptr); | 941 m_connectedNodes.append(nullptr); |
| 942 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedNodes.size()); | 942 DCHECK_EQ(numberOfOutputs, m_connectedNodes.size()); |
| 943 m_connectedParams.append(nullptr); | 943 m_connectedParams.append(nullptr); |
| 944 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedParams.size()); | 944 DCHECK_EQ(numberOfOutputs, m_connectedParams.size()); |
| 945 } | 945 } |
| 946 | 946 |
| 947 } // namespace blink | 947 } // namespace blink |
| 948 | 948 |
| OLD | NEW |