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