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 "config.h" | 25 #include "config.h" |
| 26 #if ENABLE(WEB_AUDIO) | 26 #if ENABLE(WEB_AUDIO) |
| 27 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" | 27 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionMessages.h" | |
| 30 #include "bindings/core/v8/ExceptionState.h" | |
| 31 #include "core/dom/ExceptionCode.h" | |
| 29 #include "modules/webaudio/AbstractAudioContext.h" | 32 #include "modules/webaudio/AbstractAudioContext.h" |
| 30 #include "modules/webaudio/AudioNodeInput.h" | 33 #include "modules/webaudio/AudioNodeInput.h" |
| 31 #include "platform/UUID.h" | 34 #include "platform/UUID.h" |
| 32 #include "platform/mediastream/MediaStreamCenter.h" | 35 #include "platform/mediastream/MediaStreamCenter.h" |
| 33 #include "public/platform/WebRTCPeerConnectionHandler.h" | 36 #include "public/platform/WebRTCPeerConnectionHandler.h" |
| 34 #include "wtf/Locker.h" | 37 #include "wtf/Locker.h" |
| 35 | 38 |
| 36 namespace blink { | 39 namespace blink { |
| 37 | 40 |
| 41 // WebAudioCapturerSource ignores the channel count beyond 8, so we set the | |
| 42 // block here to avoid anything can cause the crash. | |
| 43 static unsigned long kMaxChannelCount = 8; | |
| 44 | |
| 38 MediaStreamAudioDestinationHandler::MediaStreamAudioDestinationHandler(AudioNode & node, size_t numberOfChannels) | 45 MediaStreamAudioDestinationHandler::MediaStreamAudioDestinationHandler(AudioNode & node, size_t numberOfChannels) |
| 39 : AudioBasicInspectorHandler(NodeTypeMediaStreamAudioDestination, node, node .context()->sampleRate(), numberOfChannels) | 46 : AudioBasicInspectorHandler(NodeTypeMediaStreamAudioDestination, node, node .context()->sampleRate(), numberOfChannels) |
| 40 , m_mixBus(AudioBus::create(numberOfChannels, ProcessingSizeInFrames)) | 47 , m_mixBus(AudioBus::create(numberOfChannels, ProcessingSizeInFrames)) |
| 41 { | 48 { |
| 42 m_source = MediaStreamSource::create("WebAudio-" + createCanonicalUUIDString (), MediaStreamSource::TypeAudio, "MediaStreamAudioDestinationNode", false, true , MediaStreamSource::ReadyStateLive, true); | 49 m_source = MediaStreamSource::create("WebAudio-" + createCanonicalUUIDString (), MediaStreamSource::TypeAudio, "MediaStreamAudioDestinationNode", false, true , MediaStreamSource::ReadyStateLive, true); |
| 43 MediaStreamSourceVector audioSources; | 50 MediaStreamSourceVector audioSources; |
| 44 audioSources.append(m_source.get()); | 51 audioSources.append(m_source.get()); |
| 45 MediaStreamSourceVector videoSources; | 52 MediaStreamSourceVector videoSources; |
| 46 m_stream = MediaStream::create(node.context()->executionContext(), MediaStre amDescriptor::create(audioSources, videoSources)); | 53 m_stream = MediaStream::create(node.context()->executionContext(), MediaStre amDescriptor::create(audioSources, videoSources)); |
| 47 MediaStreamCenter::instance().didCreateMediaStreamAndTracks(m_stream->descri ptor()); | 54 MediaStreamCenter::instance().didCreateMediaStreamAndTracks(m_stream->descri ptor()); |
| 48 | 55 |
| 49 m_source->setAudioFormat(numberOfChannels, node.context()->sampleRate()); | 56 m_source->setAudioFormat(numberOfChannels, node.context()->sampleRate()); |
| 50 | 57 |
| 51 initialize(); | 58 initialize(); |
| 52 } | 59 } |
| 53 | 60 |
| 54 PassRefPtr<MediaStreamAudioDestinationHandler> MediaStreamAudioDestinationHandle r::create(AudioNode& node, size_t numberOfChannels) | 61 PassRefPtr<MediaStreamAudioDestinationHandler> MediaStreamAudioDestinationHandle r::create(AudioNode& node, size_t numberOfChannels) |
| 55 { | 62 { |
| 56 return adoptRef(new MediaStreamAudioDestinationHandler(node, numberOfChannel s)); | 63 return adoptRef(new MediaStreamAudioDestinationHandler(node, numberOfChannel s)); |
| 57 } | 64 } |
| 58 | 65 |
| 59 MediaStreamAudioDestinationHandler::~MediaStreamAudioDestinationHandler() | 66 MediaStreamAudioDestinationHandler::~MediaStreamAudioDestinationHandler() |
| 60 { | 67 { |
| 61 uninitialize(); | 68 uninitialize(); |
| 62 } | 69 } |
| 63 | 70 |
| 64 void MediaStreamAudioDestinationHandler::process(size_t numberOfFrames) | 71 void MediaStreamAudioDestinationHandler::process(size_t numberOfFrames) |
| 65 { | 72 { |
| 73 // Conform the input bus into the internal mix bus, which represents | |
| 74 // MediaStreamDestination's channel count. | |
| 66 m_mixBus->copyFrom(*input(0).bus()); | 75 m_mixBus->copyFrom(*input(0).bus()); |
| 76 | |
|
Raymond Toy
2015/11/20 14:47:18
Why a new blank line here?
hongchan
2015/11/20 18:02:59
Because the comment above only applies to the line
Raymond Toy
2015/11/30 18:06:09
Acknowledged.
| |
| 67 m_source->consumeAudio(m_mixBus.get(), numberOfFrames); | 77 m_source->consumeAudio(m_mixBus.get(), numberOfFrames); |
| 68 } | 78 } |
| 69 | 79 |
| 80 void MediaStreamAudioDestinationHandler::setChannelCount(unsigned long channelCo unt, ExceptionState& exceptionState) | |
| 81 { | |
| 82 ASSERT(isMainThread()); | |
| 83 | |
| 84 // Currently the maximum channel count supported for this node is 8, | |
| 85 // which is constrained by m_source (WebAudioCapturereSource). Although | |
| 86 // it has its own safety check for the excessive channels, throwing an | |
| 87 // exception here is useful to developers. | |
| 88 if (channelCount > maxChannelCount()) { | |
| 89 exceptionState.throwDOMException( | |
| 90 IndexSizeError, | |
| 91 ExceptionMessages::indexOutsideRange<unsigned>("channel count", | |
| 92 channelCount, | |
| 93 1, | |
| 94 ExceptionMessages::InclusiveBound, | |
| 95 maxChannelCount(), | |
| 96 ExceptionMessages::InclusiveBound)); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 unsigned long oldChannelCount = this->channelCount(); | |
| 101 AudioHandler::setChannelCount(channelCount, exceptionState); | |
| 102 | |
| 103 // Update the pipeline wit the new channel count only if absolutely | |
|
Raymond Toy
2015/11/20 14:47:18
Typo: "wit" -> "with"
hongchan
2015/11/20 18:02:59
Done.
| |
| 104 // necessary. | |
| 105 // | |
| 106 // TODO(hongchan): There might be a data race here since both threads | |
| 107 // have access to m_mixBus. | |
|
Raymond Toy
2015/11/20 14:47:18
I think you should lock the context here. Or maybe
hongchan
2015/11/20 18:02:59
Yes I agree. I will add the lock here. However, no
| |
| 108 if (!exceptionState.hadException() && this->channelCount() != oldChannelCoun t && isInitialized()) { | |
| 109 m_mixBus = AudioBus::create(channelCount, ProcessingSizeInFrames); | |
| 110 m_source->setAudioFormat(channelCount, context()->sampleRate()); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 unsigned long MediaStreamAudioDestinationHandler::maxChannelCount() const | |
|
Raymond Toy
2015/11/20 14:47:18
Is this used anywhere else? If not, is there a re
hongchan
2015/11/20 18:02:59
I don't have a strong opinion on this and I am sim
Raymond Toy
2015/11/30 18:06:09
Up to you. This isn't speed-critical, so I'm fine
| |
| 115 { | |
| 116 return kMaxChannelCount; | |
| 117 } | |
| 118 | |
| 70 // ---------------------------------------------------------------- | 119 // ---------------------------------------------------------------- |
| 71 | 120 |
| 72 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AbstractAudioCo ntext& context, size_t numberOfChannels) | 121 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AbstractAudioCo ntext& context, size_t numberOfChannels) |
| 73 : AudioBasicInspectorNode(context) | 122 : AudioBasicInspectorNode(context) |
| 74 { | 123 { |
| 75 setHandler(MediaStreamAudioDestinationHandler::create(*this, numberOfChannel s)); | 124 setHandler(MediaStreamAudioDestinationHandler::create(*this, numberOfChannel s)); |
| 76 } | 125 } |
| 77 | 126 |
| 78 MediaStreamAudioDestinationNode* MediaStreamAudioDestinationNode::create(Abstrac tAudioContext& context, size_t numberOfChannels) | 127 MediaStreamAudioDestinationNode* MediaStreamAudioDestinationNode::create(Abstrac tAudioContext& context, size_t numberOfChannels) |
| 79 { | 128 { |
| 80 return new MediaStreamAudioDestinationNode(context, numberOfChannels); | 129 return new MediaStreamAudioDestinationNode(context, numberOfChannels); |
| 81 } | 130 } |
| 82 | 131 |
| 83 MediaStream* MediaStreamAudioDestinationNode::stream() const | 132 MediaStream* MediaStreamAudioDestinationNode::stream() const |
| 84 { | 133 { |
| 85 return static_cast<MediaStreamAudioDestinationHandler&>(handler()).stream(); | 134 return static_cast<MediaStreamAudioDestinationHandler&>(handler()).stream(); |
| 86 } | 135 } |
| 87 | 136 |
| 88 } // namespace blink | 137 } // namespace blink |
| 89 | 138 |
| 90 #endif // ENABLE(WEB_AUDIO) | 139 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |