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 "config.h" | 25 #include "config.h" |
26 #if ENABLE(WEB_AUDIO) | 26 #if ENABLE(WEB_AUDIO) |
27 #include "modules/webaudio/MediaStreamAudioSourceNode.h" | 27 #include "modules/webaudio/MediaStreamAudioSourceNode.h" |
28 | 28 |
29 #include "modules/webaudio/AudioContext.h" | 29 #include "modules/webaudio/AbstractAudioContext.h" |
30 #include "modules/webaudio/AudioNodeOutput.h" | 30 #include "modules/webaudio/AudioNodeOutput.h" |
31 #include "platform/Logging.h" | 31 #include "platform/Logging.h" |
32 #include "wtf/Locker.h" | 32 #include "wtf/Locker.h" |
33 | 33 |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) | 36 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) |
37 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) | 37 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) |
38 , m_mediaStream(mediaStream) | 38 , m_mediaStream(mediaStream) |
39 , m_audioTrack(audioTrack) | 39 , m_audioTrack(audioTrack) |
(...skipping 14 matching lines...) Expand all Loading... |
54 | 54 |
55 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() | 55 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() |
56 { | 56 { |
57 uninitialize(); | 57 uninitialize(); |
58 } | 58 } |
59 | 59 |
60 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) | 60 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) |
61 { | 61 { |
62 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != samp
leRate()) { | 62 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != samp
leRate()) { |
63 // The sample-rate must be equal to the context's sample-rate. | 63 // The sample-rate must be equal to the context's sample-rate. |
64 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfCha
nnels() || sourceSampleRate != sampleRate()) { | 64 if (!numberOfChannels || numberOfChannels > AbstractAudioContext::maxNum
berOfChannels() || sourceSampleRate != sampleRate()) { |
65 // process() will generate silence for these uninitialized values. | 65 // process() will generate silence for these uninitialized values. |
66 WTF_LOG(Media, "MediaStreamAudioSourceNode::setFormat(%u, %f) - unha
ndled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate)
; | 66 WTF_LOG(Media, "MediaStreamAudioSourceNode::setFormat(%u, %f) - unha
ndled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate)
; |
67 m_sourceNumberOfChannels = 0; | 67 m_sourceNumberOfChannels = 0; |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 // Synchronize with process(). | 71 // Synchronize with process(). |
72 MutexLocker locker(m_processLock); | 72 MutexLocker locker(m_processLock); |
73 | 73 |
74 m_sourceNumberOfChannels = numberOfChannels; | 74 m_sourceNumberOfChannels = numberOfChannels; |
75 | 75 |
76 { | 76 { |
77 // The context must be locked when changing the number of output cha
nnels. | 77 // The context must be locked when changing the number of output cha
nnels. |
78 AudioContext::AutoLocker contextLocker(context()); | 78 AbstractAudioContext::AutoLocker contextLocker(context()); |
79 | 79 |
80 // Do any necesssary re-configuration to the output's number of chan
nels. | 80 // Do any necesssary re-configuration to the output's number of chan
nels. |
81 output(0).setNumberOfChannels(numberOfChannels); | 81 output(0).setNumberOfChannels(numberOfChannels); |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void MediaStreamAudioSourceHandler::process(size_t numberOfFrames) | 86 void MediaStreamAudioSourceHandler::process(size_t numberOfFrames) |
87 { | 87 { |
88 AudioBus* outputBus = output(0).bus(); | 88 AudioBus* outputBus = output(0).bus(); |
(...skipping 15 matching lines...) Expand all Loading... |
104 if (tryLocker.locked()) { | 104 if (tryLocker.locked()) { |
105 audioSourceProvider()->provideInput(outputBus, numberOfFrames); | 105 audioSourceProvider()->provideInput(outputBus, numberOfFrames); |
106 } else { | 106 } else { |
107 // We failed to acquire the lock. | 107 // We failed to acquire the lock. |
108 outputBus->zero(); | 108 outputBus->zero(); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 // ---------------------------------------------------------------- | 112 // ---------------------------------------------------------------- |
113 | 113 |
114 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext& context, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) | 114 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con
text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo
urceProvider> audioSourceProvider) |
115 : AudioSourceNode(context) | 115 : AudioSourceNode(context) |
116 { | 116 { |
117 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, audioSourceProvider)); | 117 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, audioSourceProvider)); |
118 } | 118 } |
119 | 119 |
120 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AudioContext& con
text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo
urceProvider> audioSourceProvider) | 120 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont
ext& context, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr
<AudioSourceProvider> audioSourceProvider) |
121 { | 121 { |
122 return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, audi
oSourceProvider); | 122 return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, audi
oSourceProvider); |
123 } | 123 } |
124 | 124 |
125 DEFINE_TRACE(MediaStreamAudioSourceNode) | 125 DEFINE_TRACE(MediaStreamAudioSourceNode) |
126 { | 126 { |
127 AudioSourceProviderClient::trace(visitor); | 127 AudioSourceProviderClient::trace(visitor); |
128 AudioSourceNode::trace(visitor); | 128 AudioSourceNode::trace(visitor); |
129 } | 129 } |
130 | 130 |
131 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc
eHandler() const | 131 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc
eHandler() const |
132 { | 132 { |
133 return static_cast<MediaStreamAudioSourceHandler&>(handler()); | 133 return static_cast<MediaStreamAudioSourceHandler&>(handler()); |
134 } | 134 } |
135 | 135 |
136 MediaStream* MediaStreamAudioSourceNode::mediaStream() const | 136 MediaStream* MediaStreamAudioSourceNode::mediaStream() const |
137 { | 137 { |
138 return mediaStreamAudioSourceHandler().mediaStream(); | 138 return mediaStreamAudioSourceHandler().mediaStream(); |
139 } | 139 } |
140 | 140 |
141 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) | 141 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) |
142 { | 142 { |
143 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); | 143 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); |
144 } | 144 } |
145 | 145 |
146 } // namespace blink | 146 } // namespace blink |
147 | 147 |
148 #endif // ENABLE(WEB_AUDIO) | 148 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |