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 ASSERT(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 ASSERT(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 ASSERT(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(static_cast<int>(m_renderingFanOutCount), 0); |
124 DCHECK_GT(static_cast<int>(m_renderingParamFanOutCount), 0); | |
Raymond Toy
2016/07/25 16:56:52
Use
DCHECK_GT(..., 0U)
HyungwookLee
2016/07/26 00:42:40
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 ASSERT(deferredTaskHandler().isGraphOwner()); |
151 return m_inputs.size(); | 149 return m_inputs.size(); |
152 } | 150 } |
153 | 151 |
154 unsigned AudioNodeOutput::paramFanOutCount() | 152 unsigned AudioNodeOutput::paramFanOutCount() |
(...skipping 26 matching lines...) Expand all Loading... | |
181 ASSERT(deferredTaskHandler().isGraphOwner()); | 179 ASSERT(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 ASSERT(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 ASSERT(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 ASSERT(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) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |