Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp b/third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp |
| index 860dd15b712c2289b834bdc08f51a65cc7068928..536db5f82f9bbf0f83f8f4514f4a19fd86ddad34 100644 |
| --- a/third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp |
| +++ b/third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp |
| @@ -23,6 +23,8 @@ |
| */ |
| #include "modules/webaudio/MediaStreamAudioSourceNode.h" |
| + |
| +#include "core/dom/ExceptionCode.h" |
| #include "modules/webaudio/AbstractAudioContext.h" |
| #include "modules/webaudio/AudioNodeOutput.h" |
| #include "platform/Logging.h" |
| @@ -114,9 +116,37 @@ MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AbstractAudioContext& con |
| setHandler(MediaStreamAudioSourceHandler::create(*this, mediaStream, audioTrack, std::move(audioSourceProvider))); |
| } |
| -MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioContext& context, MediaStream& mediaStream, MediaStreamTrack* audioTrack, PassOwnPtr<AudioSourceProvider> audioSourceProvider) |
| +MediaStreamAudioSourceNode* MediaStreamAudioSourceNode::create(AbstractAudioContext& context, MediaStream& mediaStream, ExceptionState& exceptionState) |
| { |
| - return new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, std::move(audioSourceProvider)); |
| + ASSERT(isMainThread()); |
|
hongchan
2016/05/13 01:20:12
DCHECK.
Raymond Toy
2016/05/20 23:12:00
Done.
|
| + |
| + if (context.isContextClosed()) { |
| + context.throwExceptionForClosedState(exceptionState); |
| + return nullptr; |
| + } |
| + |
| + MediaStreamTrackVector audioTracks = mediaStream.getAudioTracks(); |
| + if (audioTracks.isEmpty()) { |
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + "MediaStream has no audio track"); |
| + return nullptr; |
| + } |
| + |
| + // Use the first audio track in the media stream. |
| + MediaStreamTrack* audioTrack = audioTracks[0]; |
| + OwnPtr<AudioSourceProvider> provider = audioTrack->createWebAudioSource(); |
| + |
| + MediaStreamAudioSourceNode* node = new MediaStreamAudioSourceNode(context, mediaStream, audioTrack, provider.release()); |
|
hongchan
2016/05/13 01:20:12
Over 80 cols. Let's wrap these arguments.
|
| + |
| + if (node) { |
| + // FIXME: Only stereo streams are supported right now. We should be able to accept multi-channel streams. |
|
hongchan
2016/05/13 01:20:12
Over 80 cols. Let's change it to 'TODO'. You can p
Raymond Toy
2016/05/20 23:12:00
Done.
|
| + node->setFormat(2, context.sampleRate()); |
| + // context keeps reference until node is disconnected |
| + context.notifySourceNodeStartedProcessing(node); |
| + } |
| + |
| + return node; |
|
hongchan
2016/05/13 01:20:12
We should return nullptr when |node| is invalid an
|
| } |
| DEFINE_TRACE(MediaStreamAudioSourceNode) |