| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 , m_node(&node) | 44 , m_node(&node) |
| 45 , m_context(node.context()) | 45 , m_context(node.context()) |
| 46 , m_sampleRate(sampleRate) | 46 , m_sampleRate(sampleRate) |
| 47 , m_lastProcessingTime(-1) | 47 , m_lastProcessingTime(-1) |
| 48 , m_lastNonSilentTime(-1) | 48 , m_lastNonSilentTime(-1) |
| 49 , m_connectionRefCount(0) | 49 , m_connectionRefCount(0) |
| 50 , m_isDisabled(false) | 50 , m_isDisabled(false) |
| 51 , m_channelCount(2) | 51 , m_channelCount(2) |
| 52 , m_channelCountMode(Max) | 52 , m_channelCountMode(Max) |
| 53 , m_channelInterpretation(AudioBus::Speakers) | 53 , m_channelInterpretation(AudioBus::Speakers) |
| 54 , m_newChannelCountMode(Max) | |
| 55 { | 54 { |
| 56 setNodeType(nodeType); | 55 setNodeType(nodeType); |
| 57 | 56 |
| 58 #if DEBUG_AUDIONODE_REFERENCES | 57 #if DEBUG_AUDIONODE_REFERENCES |
| 59 if (!s_isNodeCountInitialized) { | 58 if (!s_isNodeCountInitialized) { |
| 60 s_isNodeCountInitialized = true; | 59 s_isNodeCountInitialized = true; |
| 61 atexit(AudioHandler::printNodeCounts); | 60 atexit(AudioHandler::printNodeCounts); |
| 62 } | 61 } |
| 63 #endif | 62 #endif |
| 64 InstanceCounters::incrementCounter(InstanceCounters::AudioHandlerCounter); | 63 InstanceCounters::incrementCounter(InstanceCounters::AudioHandlerCounter); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 89 | 88 |
| 90 void AudioHandler::clearInternalStateWhenDisabled() | 89 void AudioHandler::clearInternalStateWhenDisabled() |
| 91 { | 90 { |
| 92 } | 91 } |
| 93 | 92 |
| 94 void AudioHandler::dispose() | 93 void AudioHandler::dispose() |
| 95 { | 94 { |
| 96 ASSERT(isMainThread()); | 95 ASSERT(isMainThread()); |
| 97 ASSERT(context()->isGraphOwner()); | 96 ASSERT(context()->isGraphOwner()); |
| 98 | 97 |
| 99 context()->deferredTaskHandler().removeChangedChannelCountMode(this); | |
| 100 context()->deferredTaskHandler().removeChangedChannelInterpretation(this); | |
| 101 context()->deferredTaskHandler().removeAutomaticPullNode(this); | 98 context()->deferredTaskHandler().removeAutomaticPullNode(this); |
| 102 for (auto& output : m_outputs) | 99 for (auto& output : m_outputs) |
| 103 output->dispose(); | 100 output->dispose(); |
| 104 m_node = nullptr; | 101 m_node = nullptr; |
| 105 } | 102 } |
| 106 | 103 |
| 107 AudioNode* AudioHandler::node() const | 104 AudioNode* AudioHandler::node() const |
| 108 { | 105 { |
| 109 ASSERT(isMainThread()); | 106 ASSERT(isMainThread()); |
| 110 return m_node; | 107 return m_node; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 203 } |
| 207 | 204 |
| 208 void AudioHandler::setChannelCount(unsigned long channelCount, ExceptionState& e
xceptionState) | 205 void AudioHandler::setChannelCount(unsigned long channelCount, ExceptionState& e
xceptionState) |
| 209 { | 206 { |
| 210 ASSERT(isMainThread()); | 207 ASSERT(isMainThread()); |
| 211 BaseAudioContext::AutoLocker locker(context()); | 208 BaseAudioContext::AutoLocker locker(context()); |
| 212 | 209 |
| 213 if (channelCount > 0 && channelCount <= BaseAudioContext::maxNumberOfChannel
s()) { | 210 if (channelCount > 0 && channelCount <= BaseAudioContext::maxNumberOfChannel
s()) { |
| 214 if (m_channelCount != channelCount) { | 211 if (m_channelCount != channelCount) { |
| 215 m_channelCount = channelCount; | 212 m_channelCount = channelCount; |
| 216 if (m_channelCountMode != Max) | 213 if (internalChannelCountMode() != Max) |
| 217 updateChannelsForInputs(); | 214 updateChannelsForInputs(); |
| 218 } | 215 } |
| 219 } else { | 216 } else { |
| 220 exceptionState.throwDOMException( | 217 exceptionState.throwDOMException( |
| 221 NotSupportedError, | 218 NotSupportedError, |
| 222 ExceptionMessages::indexOutsideRange<unsigned long>( | 219 ExceptionMessages::indexOutsideRange<unsigned long>( |
| 223 "channel count", | 220 "channel count", |
| 224 channelCount, | 221 channelCount, |
| 225 1, | 222 1, |
| 226 ExceptionMessages::InclusiveBound, | 223 ExceptionMessages::InclusiveBound, |
| 227 BaseAudioContext::maxNumberOfChannels(), | 224 BaseAudioContext::maxNumberOfChannels(), |
| 228 ExceptionMessages::InclusiveBound)); | 225 ExceptionMessages::InclusiveBound)); |
| 229 } | 226 } |
| 230 } | 227 } |
| 231 | 228 |
| 232 String AudioHandler::channelCountMode() | 229 String AudioHandler::channelCountMode() |
| 233 { | 230 { |
| 234 switch (m_channelCountMode) { | 231 switch (internalChannelCountMode()) { |
| 235 case Max: | 232 case Max: |
| 236 return "max"; | 233 return "max"; |
| 237 case ClampedMax: | 234 case ClampedMax: |
| 238 return "clamped-max"; | 235 return "clamped-max"; |
| 239 case Explicit: | 236 case Explicit: |
| 240 return "explicit"; | 237 return "explicit"; |
| 241 } | 238 } |
| 242 ASSERT_NOT_REACHED(); | 239 ASSERT_NOT_REACHED(); |
| 243 return ""; | 240 return ""; |
| 244 } | 241 } |
| 245 | 242 |
| 246 void AudioHandler::setChannelCountMode(const String& mode, ExceptionState& excep
tionState) | 243 void AudioHandler::setChannelCountMode(const String& mode, ExceptionState& excep
tionState) |
| 247 { | 244 { |
| 248 ASSERT(isMainThread()); | 245 ASSERT(isMainThread()); |
| 249 BaseAudioContext::AutoLocker locker(context()); | 246 BaseAudioContext::AutoLocker locker(context()); |
| 250 | 247 |
| 251 ChannelCountMode oldMode = m_channelCountMode; | |
| 252 | |
| 253 if (mode == "max") { | 248 if (mode == "max") { |
| 254 m_newChannelCountMode = Max; | 249 setInternalChannelCountMode(Max); |
| 255 } else if (mode == "clamped-max") { | 250 } else if (mode == "clamped-max") { |
| 256 m_newChannelCountMode = ClampedMax; | 251 setInternalChannelCountMode(ClampedMax); |
| 257 } else if (mode == "explicit") { | 252 } else if (mode == "explicit") { |
| 258 m_newChannelCountMode = Explicit; | 253 setInternalChannelCountMode(Explicit); |
| 259 } else { | 254 } else { |
| 260 ASSERT_NOT_REACHED(); | 255 ASSERT_NOT_REACHED(); |
| 261 } | 256 } |
| 262 | 257 |
| 263 if (m_newChannelCountMode != oldMode) | 258 // Changing the channel count mode can affect the number of output channels; |
| 264 context()->deferredTaskHandler().addChangedChannelCountMode(this); | 259 // Propagate this change. |
| 260 updateChannelsForInputs(); |
| 265 } | 261 } |
| 266 | 262 |
| 267 String AudioHandler::channelInterpretation() | 263 String AudioHandler::channelInterpretation() |
| 268 { | 264 { |
| 269 switch (m_channelInterpretation) { | 265 switch (internalChannelInterpretation()) { |
| 270 case AudioBus::Speakers: | 266 case AudioBus::Speakers: |
| 271 return "speakers"; | 267 return "speakers"; |
| 272 case AudioBus::Discrete: | 268 case AudioBus::Discrete: |
| 273 return "discrete"; | 269 return "discrete"; |
| 274 } | 270 } |
| 275 ASSERT_NOT_REACHED(); | 271 ASSERT_NOT_REACHED(); |
| 276 return ""; | 272 return ""; |
| 277 } | 273 } |
| 278 | 274 |
| 279 void AudioHandler::setChannelInterpretation(const String& interpretation, Except
ionState& exceptionState) | 275 void AudioHandler::setChannelInterpretation(const String& interpretation, Except
ionState& exceptionState) |
| 280 { | 276 { |
| 281 ASSERT(isMainThread()); | 277 ASSERT(isMainThread()); |
| 282 BaseAudioContext::AutoLocker locker(context()); | 278 BaseAudioContext::AutoLocker locker(context()); |
| 283 | 279 |
| 284 AudioBus::ChannelInterpretation oldMode = m_channelInterpretation; | |
| 285 | |
| 286 if (interpretation == "speakers") { | 280 if (interpretation == "speakers") { |
| 287 m_newChannelInterpretation = AudioBus::Speakers; | 281 setInternalChannelInterpretation(AudioBus::Speakers); |
| 288 } else if (interpretation == "discrete") { | 282 } else if (interpretation == "discrete") { |
| 289 m_newChannelInterpretation = AudioBus::Discrete; | 283 setInternalChannelInterpretation(AudioBus::Discrete); |
| 290 } else { | 284 } else { |
| 291 ASSERT_NOT_REACHED(); | 285 ASSERT_NOT_REACHED(); |
| 292 } | 286 } |
| 293 | 287 |
| 294 if (m_newChannelInterpretation != oldMode) | 288 // Changing the channel interpretation doesn't change the number of output |
| 295 context()->deferredTaskHandler().addChangedChannelInterpretation(this); | 289 // channels, so we don't need to do any update here. The contents of each |
| 290 // channel may change, of course, but that doesn't require updating the |
| 291 // nodes for a different number of channels. |
| 296 } | 292 } |
| 297 | 293 |
| 298 void AudioHandler::updateChannelsForInputs() | 294 void AudioHandler::updateChannelsForInputs() |
| 299 { | 295 { |
| 300 for (auto& input : m_inputs) | 296 for (auto& input : m_inputs) |
| 301 input->changedOutputs(); | 297 input->changedOutputs(); |
| 302 } | 298 } |
| 303 | 299 |
| 304 void AudioHandler::processIfNecessary(size_t framesToProcess) | 300 void AudioHandler::processIfNecessary(size_t framesToProcess) |
| 305 { | 301 { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 fprintf(stderr, "===========================\n"); | 495 fprintf(stderr, "===========================\n"); |
| 500 | 496 |
| 501 for (unsigned i = 0; i < NodeTypeEnd; ++i) | 497 for (unsigned i = 0; i < NodeTypeEnd; ++i) |
| 502 fprintf(stderr, "%2d: %d\n", i, s_nodeCount[i]); | 498 fprintf(stderr, "%2d: %d\n", i, s_nodeCount[i]); |
| 503 | 499 |
| 504 fprintf(stderr, "===========================\n\n\n"); | 500 fprintf(stderr, "===========================\n\n\n"); |
| 505 } | 501 } |
| 506 | 502 |
| 507 #endif // DEBUG_AUDIONODE_REFERENCES | 503 #endif // DEBUG_AUDIONODE_REFERENCES |
| 508 | 504 |
| 509 void AudioHandler::updateChannelCountMode() | |
| 510 { | |
| 511 m_channelCountMode = m_newChannelCountMode; | |
| 512 updateChannelsForInputs(); | |
| 513 } | |
| 514 | |
| 515 void AudioHandler::updateChannelInterpretation() | |
| 516 { | |
| 517 m_channelInterpretation = m_newChannelInterpretation; | |
| 518 } | |
| 519 | |
| 520 unsigned AudioHandler::numberOfOutputChannels() const | 505 unsigned AudioHandler::numberOfOutputChannels() const |
| 521 { | 506 { |
| 522 // This should only be called for ScriptProcessorNodes which are the only no
des where you can | 507 // This should only be called for ScriptProcessorNodes which are the only no
des where you can |
| 523 // have an output with 0 channels. All other nodes have have at least one o
utput channel, so | 508 // have an output with 0 channels. All other nodes have have at least one o
utput channel, so |
| 524 // there's no reason other nodes should ever call this function. | 509 // there's no reason other nodes should ever call this function. |
| 525 DCHECK(0) << "numberOfOutputChannels() not valid for node type " << getNodeT
ype(); | 510 DCHECK(0) << "numberOfOutputChannels() not valid for node type " << getNodeT
ype(); |
| 526 return 1; | 511 return 1; |
| 527 } | 512 } |
| 528 // ---------------------------------------------------------------- | 513 // ---------------------------------------------------------------- |
| 529 | 514 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 void AudioNode::didAddOutput(unsigned numberOfOutputs) | 929 void AudioNode::didAddOutput(unsigned numberOfOutputs) |
| 945 { | 930 { |
| 946 m_connectedNodes.append(nullptr); | 931 m_connectedNodes.append(nullptr); |
| 947 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedNodes.size()); | 932 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedNodes.size()); |
| 948 m_connectedParams.append(nullptr); | 933 m_connectedParams.append(nullptr); |
| 949 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedParams.size()); | 934 ASSERT_UNUSED(numberOfOutputs, numberOfOutputs == m_connectedParams.size()); |
| 950 } | 935 } |
| 951 | 936 |
| 952 } // namespace blink | 937 } // namespace blink |
| 953 | 938 |
| OLD | NEW |