Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 #include <memory> | 30 #include <memory> |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 inline AudioNodeOutput::AudioNodeOutput(AudioHandler* handler, unsigned numberOf Channels) | 34 inline AudioNodeOutput::AudioNodeOutput(AudioHandler* handler, unsigned numberOf Channels) |
| 35 : m_handler(*handler) | 35 : m_handler(*handler) |
| 36 , m_numberOfChannels(numberOfChannels) | 36 , m_numberOfChannels(numberOfChannels) |
| 37 , m_desiredNumberOfChannels(numberOfChannels) | 37 , m_desiredNumberOfChannels(numberOfChannels) |
| 38 , m_isInPlace(false) | 38 , m_isInPlace(false) |
| 39 , m_isEnabled(true) | 39 , m_isEnabled(true) |
| 40 #if ENABLE_ASSERT | |
| 41 , m_didCallDispose(false) | 40 , m_didCallDispose(false) |
| 42 #endif | |
| 43 , m_renderingFanOutCount(0) | 41 , m_renderingFanOutCount(0) |
| 44 , m_renderingParamFanOutCount(0) | 42 , m_renderingParamFanOutCount(0) |
| 45 { | 43 { |
| 46 DCHECK_LE(numberOfChannels, BaseAudioContext::maxNumberOfChannels()); | 44 DCHECK_LE(numberOfChannels, BaseAudioContext::maxNumberOfChannels()); |
| 47 | 45 |
| 48 m_internalBus = AudioBus::create(numberOfChannels, AudioHandler::ProcessingS izeInFrames); | 46 m_internalBus = AudioBus::create(numberOfChannels, AudioHandler::ProcessingS izeInFrames); |
| 49 } | 47 } |
| 50 | 48 |
| 51 std::unique_ptr<AudioNodeOutput> AudioNodeOutput::create(AudioHandler* handler, unsigned numberOfChannels) | 49 std::unique_ptr<AudioNodeOutput> AudioNodeOutput::create(AudioHandler* handler, unsigned numberOfChannels) |
| 52 { | 50 { |
| 53 return wrapUnique(new AudioNodeOutput(handler, numberOfChannels)); | 51 return wrapUnique(new AudioNodeOutput(handler, numberOfChannels)); |
| 54 } | 52 } |
| 55 | 53 |
| 56 void AudioNodeOutput::dispose() | 54 void AudioNodeOutput::dispose() |
| 57 { | 55 { |
| 58 #if ENABLE_ASSERT | |
| 59 m_didCallDispose = true; | 56 m_didCallDispose = true; |
| 60 #endif | 57 |
| 61 deferredTaskHandler().removeMarkedAudioNodeOutput(this); | 58 deferredTaskHandler().removeMarkedAudioNodeOutput(this); |
| 62 disconnectAll(); | 59 disconnectAll(); |
| 63 ASSERT(m_inputs.isEmpty()); | 60 DCHECK(m_inputs.isEmpty()); |
| 64 ASSERT(m_params.isEmpty()); | 61 DCHECK(m_params.isEmpty()); |
| 65 } | 62 } |
| 66 | 63 |
| 67 void AudioNodeOutput::setNumberOfChannels(unsigned numberOfChannels) | 64 void AudioNodeOutput::setNumberOfChannels(unsigned numberOfChannels) |
| 68 { | 65 { |
| 69 DCHECK_LE(numberOfChannels, BaseAudioContext::maxNumberOfChannels()); | 66 DCHECK_LE(numberOfChannels, BaseAudioContext::maxNumberOfChannels()); |
| 70 ASSERT(deferredTaskHandler().isGraphOwner()); | 67 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 71 | 68 |
| 72 m_desiredNumberOfChannels = numberOfChannels; | 69 m_desiredNumberOfChannels = numberOfChannels; |
| 73 | 70 |
| 74 if (deferredTaskHandler().isAudioThread()) { | 71 if (deferredTaskHandler().isAudioThread()) { |
| 75 // If we're in the audio thread then we can take care of it right away ( we should be at the very start or end of a rendering quantum). | 72 // If we're in the audio thread then we can take care of it right away ( we should be at the very start or end of a rendering quantum). |
| 76 updateNumberOfChannels(); | 73 updateNumberOfChannels(); |
| 77 } else { | 74 } else { |
| 78 ASSERT(!m_didCallDispose); | 75 DCHECK(!m_didCallDispose); |
| 79 // Let the context take care of it in the audio thread in the pre and po st render tasks. | 76 // Let the context take care of it in the audio thread in the pre and po st render tasks. |
| 80 deferredTaskHandler().markAudioNodeOutputDirty(this); | 77 deferredTaskHandler().markAudioNodeOutputDirty(this); |
| 81 } | 78 } |
| 82 } | 79 } |
| 83 | 80 |
| 84 void AudioNodeOutput::updateInternalBus() | 81 void AudioNodeOutput::updateInternalBus() |
| 85 { | 82 { |
| 86 if (numberOfChannels() == m_internalBus->numberOfChannels()) | 83 if (numberOfChannels() == m_internalBus->numberOfChannels()) |
| 87 return; | 84 return; |
| 88 | 85 |
| 89 m_internalBus = AudioBus::create(numberOfChannels(), AudioHandler::Processin gSizeInFrames); | 86 m_internalBus = AudioBus::create(numberOfChannels(), AudioHandler::Processin gSizeInFrames); |
| 90 } | 87 } |
| 91 | 88 |
| 92 void AudioNodeOutput::updateRenderingState() | 89 void AudioNodeOutput::updateRenderingState() |
| 93 { | 90 { |
| 94 updateNumberOfChannels(); | 91 updateNumberOfChannels(); |
| 95 m_renderingFanOutCount = fanOutCount(); | 92 m_renderingFanOutCount = fanOutCount(); |
| 96 m_renderingParamFanOutCount = paramFanOutCount(); | 93 m_renderingParamFanOutCount = paramFanOutCount(); |
| 97 } | 94 } |
| 98 | 95 |
| 99 void AudioNodeOutput::updateNumberOfChannels() | 96 void AudioNodeOutput::updateNumberOfChannels() |
| 100 { | 97 { |
| 101 ASSERT(deferredTaskHandler().isAudioThread()); | 98 DCHECK(deferredTaskHandler().isAudioThread()); |
| 102 ASSERT(deferredTaskHandler().isGraphOwner()); | 99 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 103 | 100 |
| 104 if (m_numberOfChannels != m_desiredNumberOfChannels) { | 101 if (m_numberOfChannels != m_desiredNumberOfChannels) { |
| 105 m_numberOfChannels = m_desiredNumberOfChannels; | 102 m_numberOfChannels = m_desiredNumberOfChannels; |
| 106 updateInternalBus(); | 103 updateInternalBus(); |
| 107 propagateChannelCount(); | 104 propagateChannelCount(); |
| 108 } | 105 } |
| 109 } | 106 } |
| 110 | 107 |
| 111 void AudioNodeOutput::propagateChannelCount() | 108 void AudioNodeOutput::propagateChannelCount() |
| 112 { | 109 { |
| 113 ASSERT(deferredTaskHandler().isAudioThread()); | 110 DCHECK(deferredTaskHandler().isAudioThread()); |
| 114 ASSERT(deferredTaskHandler().isGraphOwner()); | 111 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 115 | 112 |
| 116 if (isChannelCountKnown()) { | 113 if (isChannelCountKnown()) { |
| 117 // Announce to any nodes we're connected to that we changed our channel count for its input. | 114 // Announce to any nodes we're connected to that we changed our channel count for its input. |
| 118 for (AudioNodeInput* i : m_inputs) | 115 for (AudioNodeInput* i : m_inputs) |
| 119 i->handler().checkNumberOfChannelsForInput(i); | 116 i->handler().checkNumberOfChannelsForInput(i); |
| 120 } | 117 } |
| 121 } | 118 } |
| 122 | 119 |
| 123 AudioBus* AudioNodeOutput::pull(AudioBus* inPlaceBus, size_t framesToProcess) | 120 AudioBus* AudioNodeOutput::pull(AudioBus* inPlaceBus, size_t framesToProcess) |
| 124 { | 121 { |
| 125 ASSERT(deferredTaskHandler().isAudioThread()); | 122 DCHECK(deferredTaskHandler().isAudioThread()); |
| 126 ASSERT(m_renderingFanOutCount > 0 || m_renderingParamFanOutCount > 0); | 123 DCHECK_GT(m_renderingFanOutCount, 0u); |
| 124 DCHECK_GT(m_renderingParamFanOutCount, 0u); | |
|
Raymond Toy
2016/08/10 16:29:15
This is wrong. The original ASSERT was an OR, so
HyungwookLee
2016/08/11 08:35:15
Done.
| |
| 127 | 125 |
| 128 // Causes our AudioNode to process if it hasn't already for this render quan tum. | 126 // Causes our AudioNode to process if it hasn't already for this render quan tum. |
| 129 // We try to do in-place processing (using inPlaceBus) if at all possible, | 127 // We try to do in-place processing (using inPlaceBus) if at all possible, |
| 130 // but we can't process in-place if we're connected to more than one input ( fan-out > 1). | 128 // but we can't process in-place if we're connected to more than one input ( fan-out > 1). |
| 131 // In this case pull() is called multiple times per rendering quantum, and t he processIfNecessary() call below will | 129 // In this case pull() is called multiple times per rendering quantum, and t he processIfNecessary() call below will |
| 132 // cause our node to process() only the first time, caching the output in m_ internalOutputBus for subsequent calls. | 130 // cause our node to process() only the first time, caching the output in m_ internalOutputBus for subsequent calls. |
| 133 | 131 |
| 134 m_isInPlace = inPlaceBus && inPlaceBus->numberOfChannels() == numberOfChanne ls() && (m_renderingFanOutCount + m_renderingParamFanOutCount) == 1; | 132 m_isInPlace = inPlaceBus && inPlaceBus->numberOfChannels() == numberOfChanne ls() && (m_renderingFanOutCount + m_renderingParamFanOutCount) == 1; |
| 135 | 133 |
| 136 m_inPlaceBus = m_isInPlace ? inPlaceBus : 0; | 134 m_inPlaceBus = m_isInPlace ? inPlaceBus : 0; |
| 137 | 135 |
| 138 handler().processIfNecessary(framesToProcess); | 136 handler().processIfNecessary(framesToProcess); |
| 139 return bus(); | 137 return bus(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 AudioBus* AudioNodeOutput::bus() const | 140 AudioBus* AudioNodeOutput::bus() const |
| 143 { | 141 { |
| 144 ASSERT(deferredTaskHandler().isAudioThread()); | 142 DCHECK(deferredTaskHandler().isAudioThread()); |
| 145 return m_isInPlace ? m_inPlaceBus.get() : m_internalBus.get(); | 143 return m_isInPlace ? m_inPlaceBus.get() : m_internalBus.get(); |
| 146 } | 144 } |
| 147 | 145 |
| 148 unsigned AudioNodeOutput::fanOutCount() | 146 unsigned AudioNodeOutput::fanOutCount() |
| 149 { | 147 { |
| 150 ASSERT(deferredTaskHandler().isGraphOwner()); | 148 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 151 return m_inputs.size(); | 149 return m_inputs.size(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 unsigned AudioNodeOutput::paramFanOutCount() | 152 unsigned AudioNodeOutput::paramFanOutCount() |
| 155 { | 153 { |
| 156 ASSERT(deferredTaskHandler().isGraphOwner()); | 154 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 157 return m_params.size(); | 155 return m_params.size(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 unsigned AudioNodeOutput::renderingFanOutCount() const | 158 unsigned AudioNodeOutput::renderingFanOutCount() const |
| 161 { | 159 { |
| 162 return m_renderingFanOutCount; | 160 return m_renderingFanOutCount; |
| 163 } | 161 } |
| 164 | 162 |
| 165 void AudioNodeOutput::addInput(AudioNodeInput& input) | 163 void AudioNodeOutput::addInput(AudioNodeInput& input) |
| 166 { | 164 { |
| 167 ASSERT(deferredTaskHandler().isGraphOwner()); | 165 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 168 m_inputs.add(&input); | 166 m_inputs.add(&input); |
| 169 input.handler().makeConnection(); | 167 input.handler().makeConnection(); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void AudioNodeOutput::removeInput(AudioNodeInput& input) | 170 void AudioNodeOutput::removeInput(AudioNodeInput& input) |
| 173 { | 171 { |
| 174 ASSERT(deferredTaskHandler().isGraphOwner()); | 172 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 175 input.handler().breakConnection(); | 173 input.handler().breakConnection(); |
| 176 m_inputs.remove(&input); | 174 m_inputs.remove(&input); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void AudioNodeOutput::disconnectAllInputs() | 177 void AudioNodeOutput::disconnectAllInputs() |
| 180 { | 178 { |
| 181 ASSERT(deferredTaskHandler().isGraphOwner()); | 179 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 182 | 180 |
| 183 // AudioNodeInput::disconnect() changes m_inputs by calling removeInput(). | 181 // AudioNodeInput::disconnect() changes m_inputs by calling removeInput(). |
| 184 while (!m_inputs.isEmpty()) | 182 while (!m_inputs.isEmpty()) |
| 185 (*m_inputs.begin())->disconnect(*this); | 183 (*m_inputs.begin())->disconnect(*this); |
| 186 } | 184 } |
| 187 | 185 |
| 188 void AudioNodeOutput::disconnectInput(AudioNodeInput& input) | 186 void AudioNodeOutput::disconnectInput(AudioNodeInput& input) |
| 189 { | 187 { |
| 190 ASSERT(deferredTaskHandler().isGraphOwner()); | 188 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 191 ASSERT(isConnectedToInput(input)); | 189 DCHECK(isConnectedToInput(input)); |
| 192 input.disconnect(*this); | 190 input.disconnect(*this); |
| 193 } | 191 } |
| 194 | 192 |
| 195 void AudioNodeOutput::disconnectAudioParam(AudioParamHandler& param) | 193 void AudioNodeOutput::disconnectAudioParam(AudioParamHandler& param) |
| 196 { | 194 { |
| 197 ASSERT(deferredTaskHandler().isGraphOwner()); | 195 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 198 ASSERT(isConnectedToAudioParam(param)); | 196 DCHECK(isConnectedToAudioParam(param)); |
| 199 param.disconnect(*this); | 197 param.disconnect(*this); |
| 200 } | 198 } |
| 201 | 199 |
| 202 void AudioNodeOutput::addParam(AudioParamHandler& param) | 200 void AudioNodeOutput::addParam(AudioParamHandler& param) |
| 203 { | 201 { |
| 204 ASSERT(deferredTaskHandler().isGraphOwner()); | 202 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 205 m_params.add(¶m); | 203 m_params.add(¶m); |
| 206 } | 204 } |
| 207 | 205 |
| 208 void AudioNodeOutput::removeParam(AudioParamHandler& param) | 206 void AudioNodeOutput::removeParam(AudioParamHandler& param) |
| 209 { | 207 { |
| 210 ASSERT(deferredTaskHandler().isGraphOwner()); | 208 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 211 m_params.remove(¶m); | 209 m_params.remove(¶m); |
| 212 } | 210 } |
| 213 | 211 |
| 214 void AudioNodeOutput::disconnectAllParams() | 212 void AudioNodeOutput::disconnectAllParams() |
| 215 { | 213 { |
| 216 ASSERT(deferredTaskHandler().isGraphOwner()); | 214 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 217 | 215 |
| 218 // AudioParam::disconnect() changes m_params by calling removeParam(). | 216 // AudioParam::disconnect() changes m_params by calling removeParam(). |
| 219 while (!m_params.isEmpty()) | 217 while (!m_params.isEmpty()) |
| 220 (*m_params.begin())->disconnect(*this); | 218 (*m_params.begin())->disconnect(*this); |
| 221 } | 219 } |
| 222 | 220 |
| 223 void AudioNodeOutput::disconnectAll() | 221 void AudioNodeOutput::disconnectAll() |
| 224 { | 222 { |
| 225 disconnectAllInputs(); | 223 disconnectAllInputs(); |
| 226 disconnectAllParams(); | 224 disconnectAllParams(); |
| 227 } | 225 } |
| 228 | 226 |
| 229 bool AudioNodeOutput::isConnectedToInput(AudioNodeInput& input) | 227 bool AudioNodeOutput::isConnectedToInput(AudioNodeInput& input) |
| 230 { | 228 { |
| 231 ASSERT(deferredTaskHandler().isGraphOwner()); | 229 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 232 return m_inputs.contains(&input); | 230 return m_inputs.contains(&input); |
| 233 } | 231 } |
| 234 | 232 |
| 235 bool AudioNodeOutput::isConnectedToAudioParam(AudioParamHandler& param) | 233 bool AudioNodeOutput::isConnectedToAudioParam(AudioParamHandler& param) |
| 236 { | 234 { |
| 237 ASSERT(deferredTaskHandler().isGraphOwner()); | 235 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 238 return m_params.contains(¶m); | 236 return m_params.contains(¶m); |
| 239 } | 237 } |
| 240 | 238 |
| 241 void AudioNodeOutput::disable() | 239 void AudioNodeOutput::disable() |
| 242 { | 240 { |
| 243 ASSERT(deferredTaskHandler().isGraphOwner()); | 241 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 244 | 242 |
| 245 if (m_isEnabled) { | 243 if (m_isEnabled) { |
| 246 m_isEnabled = false; | 244 m_isEnabled = false; |
| 247 for (AudioNodeInput* i : m_inputs) | 245 for (AudioNodeInput* i : m_inputs) |
| 248 i->disable(*this); | 246 i->disable(*this); |
| 249 } | 247 } |
| 250 } | 248 } |
| 251 | 249 |
| 252 void AudioNodeOutput::enable() | 250 void AudioNodeOutput::enable() |
| 253 { | 251 { |
| 254 ASSERT(deferredTaskHandler().isGraphOwner()); | 252 DCHECK(deferredTaskHandler().isGraphOwner()); |
| 255 | 253 |
| 256 if (!m_isEnabled) { | 254 if (!m_isEnabled) { |
| 257 m_isEnabled = true; | 255 m_isEnabled = true; |
| 258 for (AudioNodeInput* i : m_inputs) | 256 for (AudioNodeInput* i : m_inputs) |
| 259 i->enable(*this); | 257 i->enable(*this); |
| 260 } | 258 } |
| 261 } | 259 } |
| 262 | 260 |
| 263 } // namespace blink | 261 } // namespace blink |
| 264 | 262 |
| OLD | NEW |