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

Unified Diff: third_party/WebKit/Source/modules/webaudio/MediaStreamAudioSourceNode.cpp

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
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 a1b62a1bcd806dfc7356071c11b0faa6f140d9f1..0a911f619d79063884dfe5cb5c4bd4b8209e7f53 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,39 @@ 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));
+ DCHECK(isMainThread());
+
+ 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, std::move(provider));
+
+ if (!node)
+ return nullptr;
+
+ // TODO(hongchan): Only stereo streams are supported right now. We should be
+ // able to accept multi-channel streams.
+ node->setFormat(2, context.sampleRate());
+ // context keeps reference until node is disconnected
+ context.notifySourceNodeStartedProcessing(node);
+
+ return node;
}
DEFINE_TRACE(MediaStreamAudioSourceNode)

Powered by Google App Engine
This is Rietveld 408576698