| 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 16 matching lines...) Expand all Loading... |
| 27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
| 28 | 28 |
| 29 #include "modules/webaudio/AudioContext.h" | 29 #include "modules/webaudio/AudioContext.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ExceptionMessages.h" | 31 #include "bindings/core/v8/ExceptionMessages.h" |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/html/HTMLMediaElement.h" | 35 #include "core/html/HTMLMediaElement.h" |
| 36 #include "core/inspector/ScriptCallStack.h" | 36 #include "core/inspector/ScriptCallStack.h" |
| 37 #include "platform/audio/FFTFrame.h" | |
| 38 #include "platform/audio/HRTFPanner.h" | |
| 39 #include "modules/mediastream/MediaStream.h" | 37 #include "modules/mediastream/MediaStream.h" |
| 40 #include "modules/webaudio/AnalyserNode.h" | 38 #include "modules/webaudio/AnalyserNode.h" |
| 41 #include "modules/webaudio/AudioBuffer.h" | 39 #include "modules/webaudio/AudioBuffer.h" |
| 42 #include "modules/webaudio/AudioBufferCallback.h" | 40 #include "modules/webaudio/AudioBufferCallback.h" |
| 43 #include "modules/webaudio/AudioBufferSourceNode.h" | 41 #include "modules/webaudio/AudioBufferSourceNode.h" |
| 44 #include "modules/webaudio/AudioListener.h" | 42 #include "modules/webaudio/AudioListener.h" |
| 45 #include "modules/webaudio/AudioNodeInput.h" | 43 #include "modules/webaudio/AudioNodeInput.h" |
| 46 #include "modules/webaudio/AudioNodeOutput.h" | 44 #include "modules/webaudio/AudioNodeOutput.h" |
| 47 #include "modules/webaudio/BiquadFilterNode.h" | 45 #include "modules/webaudio/BiquadFilterNode.h" |
| 48 #include "modules/webaudio/ChannelMergerNode.h" | 46 #include "modules/webaudio/ChannelMergerNode.h" |
| 49 #include "modules/webaudio/ChannelSplitterNode.h" | 47 #include "modules/webaudio/ChannelSplitterNode.h" |
| 50 #include "modules/webaudio/ConvolverNode.h" | 48 #include "modules/webaudio/ConvolverNode.h" |
| 51 #include "modules/webaudio/DefaultAudioDestinationNode.h" | 49 #include "modules/webaudio/DefaultAudioDestinationNode.h" |
| 52 #include "modules/webaudio/DelayNode.h" | 50 #include "modules/webaudio/DelayNode.h" |
| 53 #include "modules/webaudio/DynamicsCompressorNode.h" | 51 #include "modules/webaudio/DynamicsCompressorNode.h" |
| 54 #include "modules/webaudio/GainNode.h" | 52 #include "modules/webaudio/GainNode.h" |
| 55 #include "modules/webaudio/MediaElementAudioSourceNode.h" | 53 #include "modules/webaudio/MediaElementAudioSourceNode.h" |
| 56 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" | 54 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" |
| 57 #include "modules/webaudio/MediaStreamAudioSourceNode.h" | 55 #include "modules/webaudio/MediaStreamAudioSourceNode.h" |
| 58 #include "modules/webaudio/OfflineAudioCompletionEvent.h" | 56 #include "modules/webaudio/OfflineAudioCompletionEvent.h" |
| 59 #include "modules/webaudio/OfflineAudioContext.h" | 57 #include "modules/webaudio/OfflineAudioContext.h" |
| 60 #include "modules/webaudio/OfflineAudioDestinationNode.h" | 58 #include "modules/webaudio/OfflineAudioDestinationNode.h" |
| 61 #include "modules/webaudio/OscillatorNode.h" | 59 #include "modules/webaudio/OscillatorNode.h" |
| 62 #include "modules/webaudio/PannerNode.h" | 60 #include "modules/webaudio/PannerNode.h" |
| 63 #include "modules/webaudio/PeriodicWave.h" | 61 #include "modules/webaudio/PeriodicWave.h" |
| 64 #include "modules/webaudio/ScriptProcessorNode.h" | 62 #include "modules/webaudio/ScriptProcessorNode.h" |
| 65 #include "modules/webaudio/WaveShaperNode.h" | 63 #include "modules/webaudio/WaveShaperNode.h" |
| 64 #include "platform/audio/FFTFrame.h" |
| 65 #include "platform/audio/HRTFPanner.h" |
| 66 #include "wtf/Atomics.h" |
| 67 #include "wtf/PassOwnPtr.h" |
| 68 #include "wtf/text/WTFString.h" |
| 66 | 69 |
| 67 #if DEBUG_AUDIONODE_REFERENCES | 70 #if DEBUG_AUDIONODE_REFERENCES |
| 68 #include <stdio.h> | 71 #include <stdio.h> |
| 69 #endif | 72 #endif |
| 70 | 73 |
| 71 #include "wtf/ArrayBuffer.h" | |
| 72 #include "wtf/Atomics.h" | |
| 73 #include "wtf/PassOwnPtr.h" | |
| 74 #include "wtf/text/WTFString.h" | |
| 75 | |
| 76 namespace blink { | 74 namespace blink { |
| 77 | 75 |
| 78 // Don't allow more than this number of simultaneous AudioContexts talking to ha
rdware. | 76 // Don't allow more than this number of simultaneous AudioContexts talking to ha
rdware. |
| 79 const unsigned MaxHardwareContexts = 6; | 77 const unsigned MaxHardwareContexts = 6; |
| 80 unsigned AudioContext::s_hardwareContextCount = 0; | 78 unsigned AudioContext::s_hardwareContextCount = 0; |
| 81 | 79 |
| 82 AudioContext* AudioContext::create(Document& document, ExceptionState& exception
State) | 80 AudioContext* AudioContext::create(Document& document, ExceptionState& exception
State) |
| 83 { | 81 { |
| 84 ASSERT(isMainThread()); | 82 ASSERT(isMainThread()); |
| 85 if (s_hardwareContextCount >= MaxHardwareContexts) { | 83 if (s_hardwareContextCount >= MaxHardwareContexts) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 { | 220 { |
| 223 // According to spec AudioContext must die only after page navigates. | 221 // According to spec AudioContext must die only after page navigates. |
| 224 return !m_isCleared; | 222 return !m_isCleared; |
| 225 } | 223 } |
| 226 | 224 |
| 227 AudioBuffer* AudioContext::createBuffer(unsigned numberOfChannels, size_t number
OfFrames, float sampleRate, ExceptionState& exceptionState) | 225 AudioBuffer* AudioContext::createBuffer(unsigned numberOfChannels, size_t number
OfFrames, float sampleRate, ExceptionState& exceptionState) |
| 228 { | 226 { |
| 229 return AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exc
eptionState); | 227 return AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exc
eptionState); |
| 230 } | 228 } |
| 231 | 229 |
| 232 void AudioContext::decodeAudioData(ArrayBuffer* audioData, AudioBufferCallback*
successCallback, AudioBufferCallback* errorCallback, ExceptionState& exceptionSt
ate) | 230 void AudioContext::decodeAudioData(DOMArrayBuffer* audioData, AudioBufferCallbac
k* successCallback, AudioBufferCallback* errorCallback, ExceptionState& exceptio
nState) |
| 233 { | 231 { |
| 234 if (!audioData) { | 232 if (!audioData) { |
| 235 exceptionState.throwDOMException( | 233 exceptionState.throwDOMException( |
| 236 SyntaxError, | 234 SyntaxError, |
| 237 "invalid ArrayBuffer for audioData."); | 235 "invalid ArrayBuffer for audioData."); |
| 238 return; | 236 return; |
| 239 } | 237 } |
| 240 m_audioDecoder.decodeAsync(audioData, sampleRate(), successCallback, errorCa
llback); | 238 m_audioDecoder.decodeAsync(audioData->buffer(), sampleRate(), successCallbac
k, errorCallback); |
| 241 } | 239 } |
| 242 | 240 |
| 243 AudioBufferSourceNode* AudioContext::createBufferSource() | 241 AudioBufferSourceNode* AudioContext::createBufferSource() |
| 244 { | 242 { |
| 245 ASSERT(isMainThread()); | 243 ASSERT(isMainThread()); |
| 246 AudioBufferSourceNode* node = AudioBufferSourceNode::create(this, m_destinat
ionNode->sampleRate()); | 244 AudioBufferSourceNode* node = AudioBufferSourceNode::create(this, m_destinat
ionNode->sampleRate()); |
| 247 | 245 |
| 248 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. | 246 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. |
| 249 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). | 247 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). |
| 250 refNode(node); | 248 refNode(node); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 476 |
| 479 OscillatorNode* node = OscillatorNode::create(this, m_destinationNode->sampl
eRate()); | 477 OscillatorNode* node = OscillatorNode::create(this, m_destinationNode->sampl
eRate()); |
| 480 | 478 |
| 481 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. | 479 // Because this is an AudioScheduledSourceNode, the context keeps a referenc
e until it has finished playing. |
| 482 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). | 480 // When this happens, AudioScheduledSourceNode::finish() calls AudioContext:
:notifyNodeFinishedProcessing(). |
| 483 refNode(node); | 481 refNode(node); |
| 484 | 482 |
| 485 return node; | 483 return node; |
| 486 } | 484 } |
| 487 | 485 |
| 488 PeriodicWave* AudioContext::createPeriodicWave(Float32Array* real, Float32Array*
imag, ExceptionState& exceptionState) | 486 PeriodicWave* AudioContext::createPeriodicWave(DOMFloat32Array* real, DOMFloat32
Array* imag, ExceptionState& exceptionState) |
| 489 { | 487 { |
| 490 ASSERT(isMainThread()); | 488 ASSERT(isMainThread()); |
| 491 | 489 |
| 492 if (!real) { | 490 if (!real) { |
| 493 exceptionState.throwDOMException( | 491 exceptionState.throwDOMException( |
| 494 SyntaxError, | 492 SyntaxError, |
| 495 "invalid real array"); | 493 "invalid real array"); |
| 496 return 0; | 494 return 0; |
| 497 } | 495 } |
| 498 | 496 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 521 } | 519 } |
| 522 | 520 |
| 523 if (imag->length() > 4096) { | 521 if (imag->length() > 4096) { |
| 524 exceptionState.throwDOMException( | 522 exceptionState.throwDOMException( |
| 525 IndexSizeError, | 523 IndexSizeError, |
| 526 "length of imaginary array (" + String::number(imag->length()) | 524 "length of imaginary array (" + String::number(imag->length()) |
| 527 + ") exceeds allowed maximum of 4096"); | 525 + ") exceeds allowed maximum of 4096"); |
| 528 return 0; | 526 return 0; |
| 529 } | 527 } |
| 530 | 528 |
| 531 return PeriodicWave::create(sampleRate(), real, imag); | 529 return PeriodicWave::create(sampleRate(), real->view(), imag->view()); |
| 532 } | 530 } |
| 533 | 531 |
| 534 void AudioContext::notifyNodeFinishedProcessing(AudioNode* node) | 532 void AudioContext::notifyNodeFinishedProcessing(AudioNode* node) |
| 535 { | 533 { |
| 536 ASSERT(isAudioThread()); | 534 ASSERT(isAudioThread()); |
| 537 m_finishedNodes.append(node); | 535 m_finishedNodes.append(node); |
| 538 } | 536 } |
| 539 | 537 |
| 540 void AudioContext::derefFinishedSourceNodes() | 538 void AudioContext::derefFinishedSourceNodes() |
| 541 { | 539 { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 | 865 |
| 868 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k
!= m_deferredCountModeChange.end(); ++k) | 866 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k
!= m_deferredCountModeChange.end(); ++k) |
| 869 (*k)->updateChannelCountMode(); | 867 (*k)->updateChannelCountMode(); |
| 870 | 868 |
| 871 m_deferredCountModeChange.clear(); | 869 m_deferredCountModeChange.clear(); |
| 872 } | 870 } |
| 873 | 871 |
| 874 } // namespace blink | 872 } // namespace blink |
| 875 | 873 |
| 876 #endif // ENABLE(WEB_AUDIO) | 874 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |