Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/MediaStreamAudioDestinationNode.cpp

Issue 1464673002: Support multichannel audio stream more than 2 in MediaStreamDestinationNode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed intdentation Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/MediaStreamAudioDestinationNode.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 with the new channel count only if absolutely
104 // necessary. This process requires the graph lock.
105 //
106 // TODO(hongchan): There might be a data race here since both threads
107 // have access to m_mixBus.
108 if (!exceptionState.hadException() && this->channelCount() != oldChannelCoun t && isInitialized()) {
109 AbstractAudioContext::AutoLocker locker(context());
110 m_mixBus = AudioBus::create(channelCount, ProcessingSizeInFrames);
111 m_source->setAudioFormat(channelCount, context()->sampleRate());
112 }
113 }
114
115 unsigned long MediaStreamAudioDestinationHandler::maxChannelCount() const
116 {
117 return kMaxChannelCount;
118 }
119
70 // ---------------------------------------------------------------- 120 // ----------------------------------------------------------------
71 121
72 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AbstractAudioCo ntext& context, size_t numberOfChannels) 122 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AbstractAudioCo ntext& context, size_t numberOfChannels)
73 : AudioBasicInspectorNode(context) 123 : AudioBasicInspectorNode(context)
74 { 124 {
75 setHandler(MediaStreamAudioDestinationHandler::create(*this, numberOfChannel s)); 125 setHandler(MediaStreamAudioDestinationHandler::create(*this, numberOfChannel s));
76 } 126 }
77 127
78 MediaStreamAudioDestinationNode* MediaStreamAudioDestinationNode::create(Abstrac tAudioContext& context, size_t numberOfChannels) 128 MediaStreamAudioDestinationNode* MediaStreamAudioDestinationNode::create(Abstrac tAudioContext& context, size_t numberOfChannels)
79 { 129 {
80 return new MediaStreamAudioDestinationNode(context, numberOfChannels); 130 return new MediaStreamAudioDestinationNode(context, numberOfChannels);
81 } 131 }
82 132
83 MediaStream* MediaStreamAudioDestinationNode::stream() const 133 MediaStream* MediaStreamAudioDestinationNode::stream() const
84 { 134 {
85 return static_cast<MediaStreamAudioDestinationHandler&>(handler()).stream(); 135 return static_cast<MediaStreamAudioDestinationHandler&>(handler()).stream();
86 } 136 }
87 137
88 } // namespace blink 138 } // namespace blink
89 139
90 #endif // ENABLE(WEB_AUDIO) 140 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/MediaStreamAudioDestinationNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698