Chromium Code Reviews| 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 | |
| 27 #include "core/dom/ExceptionCode.h" | |
| 26 #include "modules/webaudio/AbstractAudioContext.h" | 28 #include "modules/webaudio/AbstractAudioContext.h" |
| 27 #include "modules/webaudio/AudioNodeOutput.h" | 29 #include "modules/webaudio/AudioNodeOutput.h" |
| 28 #include "platform/Logging.h" | 30 #include "platform/Logging.h" |
| 29 #include "wtf/Locker.h" | 31 #include "wtf/Locker.h" |
| 30 | 32 |
| 31 namespace blink { | 33 namespace blink { |
| 32 | 34 |
| 33 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv ider> audioSourceProvider) | 35 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv ider> audioSourceProvider) |
| 34 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR ate()) | 36 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR ate()) |
| 35 , m_mediaStream(mediaStream) | 37 , m_mediaStream(mediaStream) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 } | 109 } |
| 108 | 110 |
| 109 // ---------------------------------------------------------------- | 111 // ---------------------------------------------------------------- |
| 110 | 112 |
| 111 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo urceProvider> audioSourceProvider) | 113 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo urceProvider> audioSourceProvider) |
| 112 : AudioSourceNode(context) | 114 : AudioSourceNode(context) |
| 113 { | 115 { |
| 114 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr ack, std::move(audioSourceProvider))); | 116 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr ack, std::move(audioSourceProvider))); |
| 115 } | 117 } |
| 116 | 118 |
| 117 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont ext& context, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr <AudioSourceProvider> audioSourceProvider) | 119 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont ext& context, MediaStream& mediaStream, ExceptionState& exceptionState) |
| 118 { | 120 { |
| 119 return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, std: :move(audioSourceProvider)); | 121 DCHECK(isMainThread()); |
| 122 | |
| 123 if (context.isContextClosed()) { | |
| 124 context.throwExceptionForClosedState(exceptionState); | |
| 125 return nullptr; | |
| 126 } | |
| 127 | |
| 128 MediaStreamTrackVector audioTracks = mediaStream.getAudioTracks(); | |
| 129 if (audioTracks.isEmpty()) { | |
| 130 exceptionState.throwDOMException( | |
| 131 InvalidStateError, | |
| 132 "MediaStream has no audio track"); | |
| 133 return nullptr; | |
| 134 } | |
| 135 | |
| 136 // Use the first audio track in the media stream. | |
| 137 MediaStreamTrack* audioTrack = audioTracks[0]; | |
| 138 OwnPtr<AudioSourceProvider> provider = audioTrack->createWebAudioSource(); | |
| 139 | |
| 140 MediaStreamAudioSourceNode* node = new MediaStreamAudioSourceNode(context, m ediaStream, audioTrack, provider.release()); | |
| 141 | |
| 142 if (!node) | |
| 143 return nullptr; | |
| 144 | |
| 145 // TODO(hongchan): Only stereo streams are supported right now. We should be able to accept | |
|
hongchan
2016/05/20 21:28:32
I think we agreed to wrap the comment at 80 cols.
| |
| 146 // multi-channel streams. | |
| 147 node->setFormat(2, context.sampleRate()); | |
| 148 // context keeps reference until node is disconnected | |
| 149 context.notifySourceNodeStartedProcessing(node); | |
| 150 | |
| 151 return node; | |
| 120 } | 152 } |
| 121 | 153 |
| 122 DEFINE_TRACE(MediaStreamAudioSourceNode) | 154 DEFINE_TRACE(MediaStreamAudioSourceNode) |
| 123 { | 155 { |
| 124 AudioSourceProviderClient::trace(visitor); | 156 AudioSourceProviderClient::trace(visitor); |
| 125 AudioSourceNode::trace(visitor); | 157 AudioSourceNode::trace(visitor); |
| 126 } | 158 } |
| 127 | 159 |
| 128 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc eHandler() const | 160 MediaStreamAudioSourceHandler& MediaStreamAudioSourceNode::mediaStreamAudioSourc eHandler() const |
| 129 { | 161 { |
| 130 return static_cast<MediaStreamAudioSourceHandler&>(handler()); | 162 return static_cast<MediaStreamAudioSourceHandler&>(handler()); |
| 131 } | 163 } |
| 132 | 164 |
| 133 MediaStream* MediaStreamAudioSourceNode::getMediaStream() const | 165 MediaStream* MediaStreamAudioSourceNode::getMediaStream() const |
| 134 { | 166 { |
| 135 return mediaStreamAudioSourceHandler().getMediaStream(); | 167 return mediaStreamAudioSourceHandler().getMediaStream(); |
| 136 } | 168 } |
| 137 | 169 |
| 138 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source SampleRate) | 170 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source SampleRate) |
| 139 { | 171 { |
| 140 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate ); | 172 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate ); |
| 141 } | 173 } |
| 142 | 174 |
| 143 } // namespace blink | 175 } // namespace blink |
| 144 | 176 |
| OLD | NEW |