| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "modules/webaudio/MediaStreamAudioSourceNode.h" | 25 #include "modules/webaudio/MediaStreamAudioSourceNode.h" |
| 26 #include "modules/webaudio/AbstractAudioContext.h" | |
| 27 #include "modules/webaudio/AudioNodeOutput.h" | 26 #include "modules/webaudio/AudioNodeOutput.h" |
| 27 #include "modules/webaudio/BaseAudioContext.h" |
| 28 #include "platform/Logging.h" | 28 #include "platform/Logging.h" |
| 29 #include "wtf/Locker.h" | 29 #include "wtf/Locker.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) | 33 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) |
| 34 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) | 34 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) |
| 35 , m_mediaStream(mediaStream) | 35 , m_mediaStream(mediaStream) |
| 36 , m_audioTrack(audioTrack) | 36 , m_audioTrack(audioTrack) |
| 37 , m_audioSourceProvider(audioSourceProvider) | 37 , m_audioSourceProvider(audioSourceProvider) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 | 51 |
| 52 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() | 52 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() |
| 53 { | 53 { |
| 54 uninitialize(); | 54 uninitialize(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) | 57 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) |
| 58 { | 58 { |
| 59 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != samp
leRate()) { | 59 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != samp
leRate()) { |
| 60 // The sample-rate must be equal to the context's sample-rate. | 60 // The sample-rate must be equal to the context's sample-rate. |
| 61 if (!numberOfChannels || numberOfChannels > AbstractAudioContext::maxNum
berOfChannels() || sourceSampleRate != sampleRate()) { | 61 if (!numberOfChannels || numberOfChannels > BaseAudioContext::maxNumberO
fChannels() || sourceSampleRate != sampleRate()) { |
| 62 // process() will generate silence for these uninitialized values. | 62 // process() will generate silence for these uninitialized values. |
| 63 WTF_LOG(Media, "MediaStreamAudioSourceNode::setFormat(%u, %f) - unha
ndled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate)
; | 63 WTF_LOG(Media, "MediaStreamAudioSourceNode::setFormat(%u, %f) - unha
ndled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate)
; |
| 64 m_sourceNumberOfChannels = 0; | 64 m_sourceNumberOfChannels = 0; |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Synchronize with process(). | 68 // Synchronize with process(). |
| 69 MutexLocker locker(m_processLock); | 69 MutexLocker locker(m_processLock); |
| 70 | 70 |
| 71 m_sourceNumberOfChannels = numberOfChannels; | 71 m_sourceNumberOfChannels = numberOfChannels; |
| 72 | 72 |
| 73 { | 73 { |
| 74 // The context must be locked when changing the number of output cha
nnels. | 74 // The context must be locked when changing the number of output cha
nnels. |
| 75 AbstractAudioContext::AutoLocker contextLocker(context()); | 75 BaseAudioContext::AutoLocker contextLocker(context()); |
| 76 | 76 |
| 77 // Do any necesssary re-configuration to the output's number of chan
nels. | 77 // Do any necesssary re-configuration to the output's number of chan
nels. |
| 78 output(0).setNumberOfChannels(numberOfChannels); | 78 output(0).setNumberOfChannels(numberOfChannels); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 void MediaStreamAudioSourceHandler::process(size_t numberOfFrames) | 83 void MediaStreamAudioSourceHandler::process(size_t numberOfFrames) |
| 84 { | 84 { |
| 85 AudioBus* outputBus = output(0).bus(); | 85 AudioBus* outputBus = output(0).bus(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 101 if (tryLocker.locked()) { | 101 if (tryLocker.locked()) { |
| 102 getAudioSourceProvider()->provideInput(outputBus, numberOfFrames); | 102 getAudioSourceProvider()->provideInput(outputBus, numberOfFrames); |
| 103 } else { | 103 } else { |
| 104 // We failed to acquire the lock. | 104 // We failed to acquire the lock. |
| 105 outputBus->zero(); | 105 outputBus->zero(); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 // ---------------------------------------------------------------- | 109 // ---------------------------------------------------------------- |
| 110 | 110 |
| 111 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con
text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo
urceProvider> audioSourceProvider) | 111 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(BaseAudioContext& context
, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSource
Provider> audioSourceProvider) |
| 112 : AudioSourceNode(context) | 112 : AudioSourceNode(context) |
| 113 { | 113 { |
| 114 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, audioSourceProvider)); | 114 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, audioSourceProvider)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont
ext& context, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr
<AudioSourceProvider> audioSourceProvider) | 117 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(BaseAudioContext&
context, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<Aud
ioSourceProvider> audioSourceProvider) |
| 118 { | 118 { |
| 119 return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, audi
oSourceProvider); | 119 return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, audi
oSourceProvider); |
| 120 } | 120 } |
| 121 | 121 |
| 122 DEFINE_TRACE(MediaStreamAudioSourceNode) | 122 DEFINE_TRACE(MediaStreamAudioSourceNode) |
| 123 { | 123 { |
| 124 AudioSourceProviderClient::trace(visitor); | 124 AudioSourceProviderClient::trace(visitor); |
| 125 AudioSourceNode::trace(visitor); | 125 AudioSourceNode::trace(visitor); |
| 126 } | 126 } |
| 127 | 127 |
| 128 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc
eHandler() const | 128 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc
eHandler() const |
| 129 { | 129 { |
| 130 return static_cast<MediaStreamAudioSourceHandler&>(handler()); | 130 return static_cast<MediaStreamAudioSourceHandler&>(handler()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 MediaStream* MediaStreamAudioSourceNode::getMediaStream() const | 133 MediaStream* MediaStreamAudioSourceNode::getMediaStream() const |
| 134 { | 134 { |
| 135 return mediaStreamAudioSourceHandler().getMediaStream(); | 135 return mediaStreamAudioSourceHandler().getMediaStream(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) | 138 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) |
| 139 { | 139 { |
| 140 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); | 140 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace blink | 143 } // namespace blink |
| 144 | 144 |
| OLD | NEW |