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 |
(...skipping 11 matching lines...) Expand all Loading... |
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 | 26 |
27 #include "core/dom/ExceptionCode.h" | 27 #include "core/dom/ExceptionCode.h" |
28 #include "modules/webaudio/AbstractAudioContext.h" | 28 #include "modules/webaudio/AbstractAudioContext.h" |
29 #include "modules/webaudio/AudioNodeOutput.h" | 29 #include "modules/webaudio/AudioNodeOutput.h" |
30 #include "platform/Logging.h" | 30 #include "platform/Logging.h" |
31 #include "wtf/Locker.h" | 31 #include "wtf/Locker.h" |
32 #include <memory> | |
33 | 32 |
34 namespace blink { | 33 namespace blink { |
35 | 34 |
36 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, std::unique_ptr<AudioSourc
eProvider> audioSourceProvider) | 35 MediaStreamAudioSourceHandler::MediaStreamAudioSourceHandler(AudioNode& node, Me
diaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProv
ider> audioSourceProvider) |
37 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) | 36 : AudioHandler(NodeTypeMediaStreamAudioSource, node, node.context()->sampleR
ate()) |
38 , m_mediaStream(mediaStream) | 37 , m_mediaStream(mediaStream) |
39 , m_audioTrack(audioTrack) | 38 , m_audioTrack(audioTrack) |
40 , m_audioSourceProvider(std::move(audioSourceProvider)) | 39 , m_audioSourceProvider(std::move(audioSourceProvider)) |
41 , m_sourceNumberOfChannels(0) | 40 , m_sourceNumberOfChannels(0) |
42 { | 41 { |
43 // Default to stereo. This could change depending on the format of the | 42 // Default to stereo. This could change depending on the format of the |
44 // MediaStream's audio track. | 43 // MediaStream's audio track. |
45 addOutput(2); | 44 addOutput(2); |
46 | 45 |
47 initialize(); | 46 initialize(); |
48 } | 47 } |
49 | 48 |
50 PassRefPtr<MediaStreamAudioSourceHandler> MediaStreamAudioSourceHandler::create(
AudioNode& node, MediaStream& mediaStream, MediaStreamTrack* audioTrack, std::un
ique_ptr<AudioSourceProvider> audioSourceProvider) | 49 PassRefPtr<MediaStreamAudioSourceHandler> MediaStreamAudioSourceHandler::create(
AudioNode& node, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwn
Ptr<AudioSourceProvider> audioSourceProvider) |
51 { | 50 { |
52 return adoptRef(new MediaStreamAudioSourceHandler(node, mediaStream, audioTr
ack, std::move(audioSourceProvider))); | 51 return adoptRef(new MediaStreamAudioSourceHandler(node, mediaStream, audioTr
ack, std::move(audioSourceProvider))); |
53 } | 52 } |
54 | 53 |
55 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() | 54 MediaStreamAudioSourceHandler::~MediaStreamAudioSourceHandler() |
56 { | 55 { |
57 uninitialize(); | 56 uninitialize(); |
58 } | 57 } |
59 | 58 |
60 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) | 59 void MediaStreamAudioSourceHandler::setFormat(size_t numberOfChannels, float sou
rceSampleRate) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (tryLocker.locked()) { | 103 if (tryLocker.locked()) { |
105 getAudioSourceProvider()->provideInput(outputBus, numberOfFrames); | 104 getAudioSourceProvider()->provideInput(outputBus, numberOfFrames); |
106 } else { | 105 } else { |
107 // We failed to acquire the lock. | 106 // We failed to acquire the lock. |
108 outputBus->zero(); | 107 outputBus->zero(); |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 // ---------------------------------------------------------------- | 111 // ---------------------------------------------------------------- |
113 | 112 |
114 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con
text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, std::unique_ptr<Au
dioSourceProvider> audioSourceProvider) | 113 MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con
text, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSo
urceProvider> audioSourceProvider) |
115 : AudioSourceNode(context) | 114 : AudioSourceNode(context) |
116 { | 115 { |
117 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, std::move(audioSourceProvider))); | 116 setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTr
ack, std::move(audioSourceProvider))); |
118 } | 117 } |
119 | 118 |
120 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont
ext& context, MediaStream& mediaStream, ExceptionState& exceptionState) | 119 MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioCont
ext& context, MediaStream& mediaStream, ExceptionState& exceptionState) |
121 { | 120 { |
122 DCHECK(isMainThread()); | 121 DCHECK(isMainThread()); |
123 | 122 |
124 if (context.isContextClosed()) { | 123 if (context.isContextClosed()) { |
125 context.throwExceptionForClosedState(exceptionState); | 124 context.throwExceptionForClosedState(exceptionState); |
126 return nullptr; | 125 return nullptr; |
127 } | 126 } |
128 | 127 |
129 MediaStreamTrackVector audioTracks = mediaStream.getAudioTracks(); | 128 MediaStreamTrackVector audioTracks = mediaStream.getAudioTracks(); |
130 if (audioTracks.isEmpty()) { | 129 if (audioTracks.isEmpty()) { |
131 exceptionState.throwDOMException( | 130 exceptionState.throwDOMException( |
132 InvalidStateError, | 131 InvalidStateError, |
133 "MediaStream has no audio track"); | 132 "MediaStream has no audio track"); |
134 return nullptr; | 133 return nullptr; |
135 } | 134 } |
136 | 135 |
137 // Use the first audio track in the media stream. | 136 // Use the first audio track in the media stream. |
138 MediaStreamTrack* audioTrack = audioTracks[0]; | 137 MediaStreamTrack* audioTrack = audioTracks[0]; |
139 std::unique_ptr<AudioSourceProvider> provider = audioTrack->createWebAudioSo
urce(); | 138 OwnPtr<AudioSourceProvider> provider = audioTrack->createWebAudioSource(); |
140 | 139 |
141 MediaStreamAudioSourceNode* node = new MediaStreamAudioSourceNode(context, m
ediaStream, audioTrack, std::move(provider)); | 140 MediaStreamAudioSourceNode* node = new MediaStreamAudioSourceNode(context, m
ediaStream, audioTrack, std::move(provider)); |
142 | 141 |
143 if (!node) | 142 if (!node) |
144 return nullptr; | 143 return nullptr; |
145 | 144 |
146 // TODO(hongchan): Only stereo streams are supported right now. We should be | 145 // TODO(hongchan): Only stereo streams are supported right now. We should be |
147 // able to accept multi-channel streams. | 146 // able to accept multi-channel streams. |
148 node->setFormat(2, context.sampleRate()); | 147 node->setFormat(2, context.sampleRate()); |
149 // context keeps reference until node is disconnected | 148 // context keeps reference until node is disconnected |
(...skipping 18 matching lines...) Expand all Loading... |
168 return mediaStreamAudioSourceHandler().getMediaStream(); | 167 return mediaStreamAudioSourceHandler().getMediaStream(); |
169 } | 168 } |
170 | 169 |
171 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) | 170 void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float source
SampleRate) |
172 { | 171 { |
173 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); | 172 mediaStreamAudioSourceHandler().setFormat(numberOfChannels, sourceSampleRate
); |
174 } | 173 } |
175 | 174 |
176 } // namespace blink | 175 } // namespace blink |
177 | 176 |
OLD | NEW |