From 040ca23f4ece78376bfb31be06610c4cd528efd4 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 15 Dec 2016 19:24:43 +0100 Subject: [PATCH] Bug 1322883 - AudioNode constructors - part 17 - MediaStreamAudioSourceNode, r=padenot --- dom/media/webaudio/AudioContext.cpp | 13 ++++-------- .../webaudio/MediaStreamAudioSourceNode.cpp | 20 ++++++++++++++----- .../webaudio/MediaStreamAudioSourceNode.h | 13 +++++++++++- .../test/test_mediaStreamAudioSourceNode.html | 2 +- .../MediaStreamAudioDestinationNode.webidl | 2 -- dom/webidl/MediaStreamAudioSourceNode.webidl | 7 ++++++- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index b3c5ff0c983b..af773be8ad3d 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -25,6 +25,7 @@ #include "mozilla/dom/IIRFilterNodeBinding.h" #include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/MediaElementAudioSourceNodeBinding.h" +#include "mozilla/dom/MediaStreamAudioSourceNodeBinding.h" #include "mozilla/dom/OfflineAudioContextBinding.h" #include "mozilla/dom/OscillatorNodeBinding.h" #include "mozilla/dom/PannerNodeBinding.h" @@ -374,16 +375,10 @@ already_AddRefed AudioContext::CreateMediaStreamSource(DOMMediaStream& aMediaStream, ErrorResult& aRv) { - if (mIsOffline) { - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return nullptr; - } + MediaStreamAudioSourceOptions options; + options.mMediaStream = aMediaStream; - if (CheckClosed(aRv)) { - return nullptr; - } - - return MediaStreamAudioSourceNode::Create(this, &aMediaStream, aRv); + return MediaStreamAudioSourceNode::Create(*this, options, aRv); } already_AddRefed diff --git a/dom/media/webaudio/MediaStreamAudioSourceNode.cpp b/dom/media/webaudio/MediaStreamAudioSourceNode.cpp index beedd5300476..a64b7f9ef1a9 100644 --- a/dom/media/webaudio/MediaStreamAudioSourceNode.cpp +++ b/dom/media/webaudio/MediaStreamAudioSourceNode.cpp @@ -43,13 +43,23 @@ MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext* aContext) } /* static */ already_AddRefed -MediaStreamAudioSourceNode::Create(AudioContext* aContext, - DOMMediaStream* aStream, ErrorResult& aRv) +MediaStreamAudioSourceNode::Create(AudioContext& aAudioContext, + const MediaStreamAudioSourceOptions& aOptions, + ErrorResult& aRv) { - RefPtr node = - new MediaStreamAudioSourceNode(aContext); + if (aAudioContext.IsOffline()) { + aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return nullptr; + } - node->Init(aStream, aRv); + if (aAudioContext.CheckClosed(aRv)) { + return nullptr; + } + + RefPtr node = + new MediaStreamAudioSourceNode(&aAudioContext); + + node->Init(aOptions.mMediaStream, aRv); if (aRv.Failed()) { return nullptr; } diff --git a/dom/media/webaudio/MediaStreamAudioSourceNode.h b/dom/media/webaudio/MediaStreamAudioSourceNode.h index 5383eb2c6a77..8f3f7a5781bf 100644 --- a/dom/media/webaudio/MediaStreamAudioSourceNode.h +++ b/dom/media/webaudio/MediaStreamAudioSourceNode.h @@ -15,6 +15,9 @@ namespace mozilla { namespace dom { +class AudioContext; +struct MediaStreamAudioSourceOptions; + class MediaStreamAudioSourceNodeEngine final : public AudioNodeEngine { public: @@ -46,11 +49,19 @@ class MediaStreamAudioSourceNode : public AudioNode, { public: static already_AddRefed - Create(AudioContext* aContext, DOMMediaStream* aStream, ErrorResult& aRv); + Create(AudioContext& aContext, const MediaStreamAudioSourceOptions& aOptions, + ErrorResult& aRv); NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamAudioSourceNode, AudioNode) + static already_AddRefed + Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext, + const MediaStreamAudioSourceOptions& aOptions, ErrorResult& aRv) + { + return Create(aAudioContext, aOptions, aRv); + } + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; void DestroyMediaStream() override; diff --git a/dom/media/webaudio/test/test_mediaStreamAudioSourceNode.html b/dom/media/webaudio/test/test_mediaStreamAudioSourceNode.html index 85d96d3e8a8a..753ca8e1987b 100644 --- a/dom/media/webaudio/test/test_mediaStreamAudioSourceNode.html +++ b/dom/media/webaudio/test/test_mediaStreamAudioSourceNode.html @@ -31,7 +31,7 @@ var gTest = { source.connect(dest); source.start(0); - var mediaStreamSource = context.createMediaStreamSource(dest.stream); + var mediaStreamSource = new MediaStreamAudioSourceNode(context, { mediaStream: dest.stream }); // channelCount and channelCountMode should have no effect mediaStreamSource.channelCount = 1; mediaStreamSource.channelCountMode = "explicit"; diff --git a/dom/webidl/MediaStreamAudioDestinationNode.webidl b/dom/webidl/MediaStreamAudioDestinationNode.webidl index aafff964eea4..4b5def3926ee 100644 --- a/dom/webidl/MediaStreamAudioDestinationNode.webidl +++ b/dom/webidl/MediaStreamAudioDestinationNode.webidl @@ -12,7 +12,5 @@ [Pref="dom.webaudio.enabled"] interface MediaStreamAudioDestinationNode : AudioNode { - readonly attribute MediaStream stream; - }; diff --git a/dom/webidl/MediaStreamAudioSourceNode.webidl b/dom/webidl/MediaStreamAudioSourceNode.webidl index e717ef2543f1..06727a5dadd2 100644 --- a/dom/webidl/MediaStreamAudioSourceNode.webidl +++ b/dom/webidl/MediaStreamAudioSourceNode.webidl @@ -10,7 +10,12 @@ * liability, trademark and document use rules apply. */ -[Pref="dom.webaudio.enabled"] +dictionary MediaStreamAudioSourceOptions { + required MediaStream mediaStream; +}; + +[Pref="dom.webaudio.enabled", + Constructor(AudioContext context, MediaStreamAudioSourceOptions options)] interface MediaStreamAudioSourceNode : AudioNode { };