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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 { | 82 { |
83 // FIXME: It would be nice if the minimum sample-rate could be less than 44.
1KHz, | 83 // FIXME: It would be nice if the minimum sample-rate could be less than 44.
1KHz, |
84 // but that will require some fixes in HRTFPanner::fftSizeForSampleRate(), a
nd some testing there. | 84 // but that will require some fixes in HRTFPanner::fftSizeForSampleRate(), a
nd some testing there. |
85 return sampleRate >= 44100 && sampleRate <= 96000; | 85 return sampleRate >= 44100 && sampleRate <= 96000; |
86 } | 86 } |
87 | 87 |
88 // Don't allow more than this number of simultaneous AudioContexts talking to ha
rdware. | 88 // Don't allow more than this number of simultaneous AudioContexts talking to ha
rdware. |
89 const unsigned MaxHardwareContexts = 6; | 89 const unsigned MaxHardwareContexts = 6; |
90 unsigned AudioContext::s_hardwareContextCount = 0; | 90 unsigned AudioContext::s_hardwareContextCount = 0; |
91 | 91 |
92 PassRefPtr<AudioContext> AudioContext::create(Document& document, ExceptionState
& exceptionState) | 92 PassRefPtrWillBeRawPtr<AudioContext> AudioContext::create(Document& document, Ex
ceptionState& exceptionState) |
93 { | 93 { |
94 ASSERT(isMainThread()); | 94 ASSERT(isMainThread()); |
95 if (s_hardwareContextCount >= MaxHardwareContexts) { | 95 if (s_hardwareContextCount >= MaxHardwareContexts) { |
96 exceptionState.throwDOMException( | 96 exceptionState.throwDOMException( |
97 SyntaxError, | 97 SyntaxError, |
98 "number of hardware contexts reached maximum (" + String::number(Max
HardwareContexts) + ")."); | 98 "number of hardware contexts reached maximum (" + String::number(Max
HardwareContexts) + ")."); |
99 return nullptr; | 99 return nullptr; |
100 } | 100 } |
101 | 101 |
102 RefPtr<AudioContext> audioContext(adoptRef(new AudioContext(&document))); | 102 RefPtrWillBeRawPtr<AudioContext> audioContext(adoptRefWillBeRefCountedGarbag
eCollected(new AudioContext(&document))); |
103 audioContext->suspendIfNeeded(); | 103 audioContext->suspendIfNeeded(); |
104 return audioContext.release(); | 104 return audioContext.release(); |
105 } | 105 } |
106 | 106 |
107 PassRefPtr<AudioContext> AudioContext::create(Document& document, unsigned numbe
rOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionS
tate) | 107 PassRefPtrWillBeRawPtr<AudioContext> AudioContext::create(Document& document, un
signed numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState
& exceptionState) |
108 { | 108 { |
109 document.addConsoleMessage(JSMessageSource, WarningMessageLevel, "Deprecated
AudioContext constructor: use OfflineAudioContext instead"); | 109 document.addConsoleMessage(JSMessageSource, WarningMessageLevel, "Deprecated
AudioContext constructor: use OfflineAudioContext instead"); |
110 return OfflineAudioContext::create(&document, numberOfChannels, numberOfFram
es, sampleRate, exceptionState); | 110 return OfflineAudioContext::create(&document, numberOfChannels, numberOfFram
es, sampleRate, exceptionState); |
111 } | 111 } |
112 | 112 |
113 // Constructor for rendering to the audio hardware. | 113 // Constructor for rendering to the audio hardware. |
114 AudioContext::AudioContext(Document* document) | 114 AudioContext::AudioContext(Document* document) |
115 : ActiveDOMObject(document) | 115 : ActiveDOMObject(document) |
116 , m_isStopScheduled(false) | 116 , m_isStopScheduled(false) |
117 , m_isInitialized(false) | 117 , m_isInitialized(false) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return; | 269 return; |
270 m_isStopScheduled = true; | 270 m_isStopScheduled = true; |
271 | 271 |
272 // Don't call uninitialize() immediately here because the ExecutionContext i
s in the middle | 272 // Don't call uninitialize() immediately here because the ExecutionContext i
s in the middle |
273 // of dealing with all of its ActiveDOMObjects at this point. uninitialize()
can de-reference other | 273 // of dealing with all of its ActiveDOMObjects at this point. uninitialize()
can de-reference other |
274 // ActiveDOMObjects so let's schedule uninitialize() to be called later. | 274 // ActiveDOMObjects so let's schedule uninitialize() to be called later. |
275 // FIXME: see if there's a more direct way to handle this issue. | 275 // FIXME: see if there's a more direct way to handle this issue. |
276 callOnMainThread(stopDispatch, this); | 276 callOnMainThread(stopDispatch, this); |
277 } | 277 } |
278 | 278 |
279 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si
ze_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) | 279 PassRefPtrWillBeRawPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOf
Channels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionStat
e) |
280 { | 280 { |
281 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numb
erOfFrames, sampleRate); | 281 RefPtrWillBeRawPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfCh
annels, numberOfFrames, sampleRate); |
282 if (!audioBuffer.get()) { | 282 if (!audioBuffer.get()) { |
283 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | 283 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { |
284 exceptionState.throwDOMException( | 284 exceptionState.throwDOMException( |
285 NotSupportedError, | 285 NotSupportedError, |
286 "requested number of channels (" + String::number(numberOfChanne
ls) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels()
) + ")"); | 286 "requested number of channels (" + String::number(numberOfChanne
ls) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels()
) + ")"); |
287 } else if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRat
e > AudioBuffer::maxAllowedSampleRate()) { | 287 } else if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRat
e > AudioBuffer::maxAllowedSampleRate()) { |
288 exceptionState.throwDOMException( | 288 exceptionState.throwDOMException( |
289 NotSupportedError, | 289 NotSupportedError, |
290 "requested sample rate (" + String::number(sampleRate) | 290 "requested sample rate (" + String::number(sampleRate) |
291 + ") does not lie in the allowed range of " | 291 + ") does not lie in the allowed range of " |
292 + String::number(AudioBuffer::minAllowedSampleRate()) | 292 + String::number(AudioBuffer::minAllowedSampleRate()) |
293 + "-" + String::number(AudioBuffer::maxAllowedSampleRate()) + "
Hz"); | 293 + "-" + String::number(AudioBuffer::maxAllowedSampleRate()) + "
Hz"); |
294 } else if (!numberOfFrames) { | 294 } else if (!numberOfFrames) { |
295 exceptionState.throwDOMException( | 295 exceptionState.throwDOMException( |
296 NotSupportedError, | 296 NotSupportedError, |
297 "number of frames must be greater than 0."); | 297 "number of frames must be greater than 0."); |
298 } else { | 298 } else { |
299 exceptionState.throwDOMException( | 299 exceptionState.throwDOMException( |
300 NotSupportedError, | 300 NotSupportedError, |
301 "unable to create buffer of " + String::number(numberOfChannels) | 301 "unable to create buffer of " + String::number(numberOfChannels) |
302 + " channel(s) of " + String::number(numberOfFrames) | 302 + " channel(s) of " + String::number(numberOfFrames) |
303 + " frames each."); | 303 + " frames each."); |
304 } | 304 } |
305 return nullptr; | 305 return nullptr; |
306 } | 306 } |
307 | 307 |
308 return audioBuffer; | 308 return audioBuffer; |
309 } | 309 } |
310 | 310 |
311 PassRefPtr<AudioBuffer> AudioContext::createBuffer(ArrayBuffer* arrayBuffer, boo
l mixToMono, ExceptionState& exceptionState) | 311 PassRefPtrWillBeRawPtr<AudioBuffer> AudioContext::createBuffer(ArrayBuffer* arra
yBuffer, bool mixToMono, ExceptionState& exceptionState) |
312 { | 312 { |
313 ASSERT(arrayBuffer); | 313 ASSERT(arrayBuffer); |
314 if (!arrayBuffer) { | 314 if (!arrayBuffer) { |
315 exceptionState.throwDOMException( | 315 exceptionState.throwDOMException( |
316 SyntaxError, | 316 SyntaxError, |
317 "invalid ArrayBuffer."); | 317 "invalid ArrayBuffer."); |
318 return nullptr; | 318 return nullptr; |
319 } | 319 } |
320 | 320 |
321 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFileData(array
Buffer->data(), arrayBuffer->byteLength(), mixToMono, sampleRate()); | 321 RefPtrWillBeRawPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFi
leData(arrayBuffer->data(), arrayBuffer->byteLength(), mixToMono, sampleRate()); |
322 if (!audioBuffer.get()) { | 322 if (!audioBuffer.get()) { |
323 exceptionState.throwDOMException( | 323 exceptionState.throwDOMException( |
324 SyntaxError, | 324 SyntaxError, |
325 "invalid audio data in ArrayBuffer."); | 325 "invalid audio data in ArrayBuffer."); |
326 return nullptr; | 326 return nullptr; |
327 } | 327 } |
328 | 328 |
329 return audioBuffer; | 329 return audioBuffer; |
330 } | 330 } |
331 | 331 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 599 |
600 RefPtr<OscillatorNode> node = OscillatorNode::create(this, m_destinationNode
->sampleRate()); | 600 RefPtr<OscillatorNode> node = OscillatorNode::create(this, m_destinationNode
->sampleRate()); |
601 | 601 |
602 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. | 602 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. |
603 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). | 603 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). |
604 refNode(node.get()); | 604 refNode(node.get()); |
605 | 605 |
606 return node; | 606 return node; |
607 } | 607 } |
608 | 608 |
609 PassRefPtr<PeriodicWave> AudioContext::createPeriodicWave(Float32Array* real, Fl
oat32Array* imag, ExceptionState& exceptionState) | 609 PassRefPtrWillBeRawPtr<PeriodicWave> AudioContext::createPeriodicWave(Float32Arr
ay* real, Float32Array* imag, ExceptionState& exceptionState) |
610 { | 610 { |
611 ASSERT(isMainThread()); | 611 ASSERT(isMainThread()); |
612 | 612 |
613 if (!real) { | 613 if (!real) { |
614 exceptionState.throwDOMException( | 614 exceptionState.throwDOMException( |
615 SyntaxError, | 615 SyntaxError, |
616 "invalid real array"); | 616 "invalid real array"); |
617 return nullptr; | 617 return nullptr; |
618 } | 618 } |
619 | 619 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 void AudioContext::incrementActiveSourceCount() | 1036 void AudioContext::incrementActiveSourceCount() |
1037 { | 1037 { |
1038 atomicIncrement(&m_activeSourceCount); | 1038 atomicIncrement(&m_activeSourceCount); |
1039 } | 1039 } |
1040 | 1040 |
1041 void AudioContext::decrementActiveSourceCount() | 1041 void AudioContext::decrementActiveSourceCount() |
1042 { | 1042 { |
1043 atomicDecrement(&m_activeSourceCount); | 1043 atomicDecrement(&m_activeSourceCount); |
1044 } | 1044 } |
1045 | 1045 |
| 1046 void AudioContext::trace(Visitor* visitor) |
| 1047 { |
| 1048 visitor->trace(m_renderTarget); |
| 1049 visitor->trace(m_listener); |
| 1050 } |
| 1051 |
1046 } // namespace WebCore | 1052 } // namespace WebCore |
1047 | 1053 |
1048 #endif // ENABLE(WEB_AUDIO) | 1054 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |