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