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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioNodeOutput.cpp

Issue 2159403002: Replace ASSERT with DCHECK in WebAudio (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 19 matching lines...) Expand all
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(m_renderingFanOutCount > 0 || m_renderingParamFanOutCount > 0);
127 124
128 // Causes our AudioNode to process if it hasn't already for this render quan tum. 125 // 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, 126 // 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). 127 // 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 128 // 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. 129 // cause our node to process() only the first time, caching the output in m_ internalOutputBus for subsequent calls.
133 130
134 m_isInPlace = inPlaceBus && inPlaceBus->numberOfChannels() == numberOfChanne ls() && (m_renderingFanOutCount + m_renderingParamFanOutCount) == 1; 131 m_isInPlace = inPlaceBus && inPlaceBus->numberOfChannels() == numberOfChanne ls() && (m_renderingFanOutCount + m_renderingParamFanOutCount) == 1;
135 132
136 m_inPlaceBus = m_isInPlace ? inPlaceBus : 0; 133 m_inPlaceBus = m_isInPlace ? inPlaceBus : 0;
137 134
138 handler().processIfNecessary(framesToProcess); 135 handler().processIfNecessary(framesToProcess);
139 return bus(); 136 return bus();
140 } 137 }
141 138
142 AudioBus* AudioNodeOutput::bus() const 139 AudioBus* AudioNodeOutput::bus() const
143 { 140 {
144 ASSERT(deferredTaskHandler().isAudioThread()); 141 DCHECK(deferredTaskHandler().isAudioThread());
145 return m_isInPlace ? m_inPlaceBus.get() : m_internalBus.get(); 142 return m_isInPlace ? m_inPlaceBus.get() : m_internalBus.get();
146 } 143 }
147 144
148 unsigned AudioNodeOutput::fanOutCount() 145 unsigned AudioNodeOutput::fanOutCount()
149 { 146 {
150 ASSERT(deferredTaskHandler().isGraphOwner()); 147 ASSERT(deferredTaskHandler().isGraphOwner());
151 return m_inputs.size(); 148 return m_inputs.size();
152 } 149 }
153 150
154 unsigned AudioNodeOutput::paramFanOutCount() 151 unsigned AudioNodeOutput::paramFanOutCount()
(...skipping 26 matching lines...) Expand all
181 ASSERT(deferredTaskHandler().isGraphOwner()); 178 ASSERT(deferredTaskHandler().isGraphOwner());
182 179
183 // AudioNodeInput::disconnect() changes m_inputs by calling removeInput(). 180 // AudioNodeInput::disconnect() changes m_inputs by calling removeInput().
184 while (!m_inputs.isEmpty()) 181 while (!m_inputs.isEmpty())
185 (*m_inputs.begin())->disconnect(*this); 182 (*m_inputs.begin())->disconnect(*this);
186 } 183 }
187 184
188 void AudioNodeOutput::disconnectInput(AudioNodeInput& input) 185 void AudioNodeOutput::disconnectInput(AudioNodeInput& input)
189 { 186 {
190 ASSERT(deferredTaskHandler().isGraphOwner()); 187 ASSERT(deferredTaskHandler().isGraphOwner());
191 ASSERT(isConnectedToInput(input)); 188 DCHECK(isConnectedToInput(input));
192 input.disconnect(*this); 189 input.disconnect(*this);
193 } 190 }
194 191
195 void AudioNodeOutput::disconnectAudioParam(AudioParamHandler& param) 192 void AudioNodeOutput::disconnectAudioParam(AudioParamHandler& param)
196 { 193 {
197 ASSERT(deferredTaskHandler().isGraphOwner()); 194 ASSERT(deferredTaskHandler().isGraphOwner());
198 ASSERT(isConnectedToAudioParam(param)); 195 DCHECK(isConnectedToAudioParam(param));
199 param.disconnect(*this); 196 param.disconnect(*this);
200 } 197 }
201 198
202 void AudioNodeOutput::addParam(AudioParamHandler& param) 199 void AudioNodeOutput::addParam(AudioParamHandler& param)
203 { 200 {
204 ASSERT(deferredTaskHandler().isGraphOwner()); 201 ASSERT(deferredTaskHandler().isGraphOwner());
205 m_params.add(&param); 202 m_params.add(&param);
206 } 203 }
207 204
208 void AudioNodeOutput::removeParam(AudioParamHandler& param) 205 void AudioNodeOutput::removeParam(AudioParamHandler& param)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 252
256 if (!m_isEnabled) { 253 if (!m_isEnabled) {
257 m_isEnabled = true; 254 m_isEnabled = true;
258 for (AudioNodeInput* i : m_inputs) 255 for (AudioNodeInput* i : m_inputs)
259 i->enable(*this); 256 i->enable(*this);
260 } 257 }
261 } 258 }
262 259
263 } // namespace blink 260 } // namespace blink
264 261
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698