From d6eeb2dccdebda71d2af4a38beb788d3f52f7b1d Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 25 Jul 2013 15:01:49 +1200 Subject: [PATCH] Bug 855568 - Implement MediaElementAudioSourceNode X-Git-Commit-ID: 52f1fcdd561e8214e6820a3f2478d9e8b9623430 --HG-- extra : rebase_source : c40cd0c7070dec9e0273093499228f13906f8fc5 --- content/media/webaudio/AudioContext.cpp | 24 ++++++- content/media/webaudio/AudioContext.h | 4 ++ .../webaudio/MediaElementAudioSourceNode.cpp | 27 ++++++++ .../webaudio/MediaElementAudioSourceNode.h | 29 ++++++++ content/media/webaudio/moz.build | 2 + content/media/webaudio/test/Makefile.in | 1 + .../test_mediaElementAudioSourceNode.html | 69 +++++++++++++++++++ dom/webidl/AudioContext.webidl | 2 + dom/webidl/MediaElementAudioSourceNode.webidl | 17 +++++ dom/webidl/WebIDL.mk | 1 + 10 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 content/media/webaudio/MediaElementAudioSourceNode.cpp create mode 100644 content/media/webaudio/MediaElementAudioSourceNode.h create mode 100644 content/media/webaudio/test/test_mediaElementAudioSourceNode.html create mode 100644 dom/webidl/MediaElementAudioSourceNode.webidl diff --git a/content/media/webaudio/AudioContext.cpp b/content/media/webaudio/AudioContext.cpp index 8f12ebd908f..cb99363459b 100644 --- a/content/media/webaudio/AudioContext.cpp +++ b/content/media/webaudio/AudioContext.cpp @@ -8,14 +8,16 @@ #include "nsContentUtils.h" #include "nsPIDOMWindow.h" #include "mozilla/ErrorResult.h" +#include "mozilla/dom/AnalyserNode.h" #include "mozilla/dom/AudioContextBinding.h" +#include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/OfflineAudioContextBinding.h" #include "MediaStreamGraph.h" -#include "mozilla/dom/AnalyserNode.h" #include "AudioDestinationNode.h" #include "AudioBufferSourceNode.h" #include "AudioBuffer.h" #include "GainNode.h" +#include "MediaElementAudioSourceNode.h" #include "MediaStreamAudioSourceNode.h" #include "DelayNode.h" #include "PannerNode.h" @@ -254,6 +256,23 @@ AudioContext::CreateAnalyser() return analyserNode.forget(); } +already_AddRefed +AudioContext::CreateMediaElementSource(HTMLMediaElement& aMediaElement, + ErrorResult& aRv) +{ + if (mIsOffline) { + aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return nullptr; + } + nsRefPtr stream = aMediaElement.MozCaptureStream(aRv); + if (aRv.Failed()) { + return nullptr; + } + nsRefPtr mediaElementAudioSourceNode = + new MediaElementAudioSourceNode(this, stream); + return mediaElementAudioSourceNode.forget(); +} + already_AddRefed AudioContext::CreateMediaStreamSource(DOMMediaStream& aMediaStream, ErrorResult& aRv) @@ -262,7 +281,8 @@ AudioContext::CreateMediaStreamSource(DOMMediaStream& aMediaStream, aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } - nsRefPtr mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(this, &aMediaStream); + nsRefPtr mediaStreamAudioSourceNode = + new MediaStreamAudioSourceNode(this, &aMediaStream); return mediaStreamAudioSourceNode.forget(); } diff --git a/content/media/webaudio/AudioContext.h b/content/media/webaudio/AudioContext.h index 557cc35f449..ef111b229b2 100644 --- a/content/media/webaudio/AudioContext.h +++ b/content/media/webaudio/AudioContext.h @@ -52,6 +52,8 @@ class DelayNode; class DynamicsCompressorNode; class GainNode; class GlobalObject; +class HTMLMediaElement; +class MediaElementAudioSourceNode; class MediaStreamAudioDestinationNode; class MediaStreamAudioSourceNode; class OfflineRenderSuccessCallback; @@ -162,6 +164,8 @@ public: return CreateGain(); } + already_AddRefed + CreateMediaElementSource(HTMLMediaElement& aMediaElement, ErrorResult& aRv); already_AddRefed CreateMediaStreamSource(DOMMediaStream& aMediaStream, ErrorResult& aRv); diff --git a/content/media/webaudio/MediaElementAudioSourceNode.cpp b/content/media/webaudio/MediaElementAudioSourceNode.cpp new file mode 100644 index 00000000000..4389650c167 --- /dev/null +++ b/content/media/webaudio/MediaElementAudioSourceNode.cpp @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "MediaElementAudioSourceNode.h" +#include "mozilla/dom/MediaElementAudioSourceNodeBinding.h" +#include "mozilla/dom/HTMLMediaElement.h" + +namespace mozilla { +namespace dom { + +MediaElementAudioSourceNode::MediaElementAudioSourceNode(AudioContext* aContext, + DOMMediaStream* aStream) + : MediaStreamAudioSourceNode(aContext, aStream) +{ +} + +JSObject* +MediaElementAudioSourceNode::WrapObject(JSContext* aCx, JS::Handle aScope) +{ + return MediaElementAudioSourceNodeBinding::Wrap(aCx, aScope, this); +} + +} +} diff --git a/content/media/webaudio/MediaElementAudioSourceNode.h b/content/media/webaudio/MediaElementAudioSourceNode.h new file mode 100644 index 00000000000..de8d9d583b4 --- /dev/null +++ b/content/media/webaudio/MediaElementAudioSourceNode.h @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MediaElementAudioSourceNode_h_ +#define MediaElementAudioSourceNode_h_ + +#include "MediaStreamAudioSourceNode.h" + +namespace mozilla { +namespace dom { + +class HTMLMediaElement; + +class MediaElementAudioSourceNode : public MediaStreamAudioSourceNode +{ +public: + MediaElementAudioSourceNode(AudioContext* aContext, + DOMMediaStream* aStream); + + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; +}; + +} +} + +#endif diff --git a/content/media/webaudio/moz.build b/content/media/webaudio/moz.build index 77799dbe252..98c1ff61f57 100644 --- a/content/media/webaudio/moz.build +++ b/content/media/webaudio/moz.build @@ -39,6 +39,7 @@ EXPORTS.mozilla.dom += [ 'DynamicsCompressorNode.h', 'EnableWebAudioCheck.h', 'GainNode.h', + 'MediaElementAudioSourceNode.h', 'MediaStreamAudioDestinationNode.h', 'MediaStreamAudioSourceNode.h', 'OfflineAudioCompletionEvent.h', @@ -67,6 +68,7 @@ CPP_SOURCES += [ 'EnableWebAudioCheck.cpp', 'GainNode.cpp', 'MediaBufferDecoder.cpp', + 'MediaElementAudioSourceNode.cpp', 'MediaStreamAudioDestinationNode.cpp', 'MediaStreamAudioSourceNode.cpp', 'OfflineAudioCompletionEvent.cpp', diff --git a/content/media/webaudio/test/Makefile.in b/content/media/webaudio/test/Makefile.in index 723fba40647..bb202536f38 100644 --- a/content/media/webaudio/test/Makefile.in +++ b/content/media/webaudio/test/Makefile.in @@ -67,6 +67,7 @@ MOCHITEST_FILES := \ test_gainNodeInLoop.html \ test_maxChannelCount.html \ test_mediaDecoding.html \ + test_mediaElementAudioSourceNode.html \ test_mediaStreamAudioDestinationNode.html \ test_mediaStreamAudioSourceNode.html \ test_mediaStreamAudioSourceNodeCrossOrigin.html \ diff --git a/content/media/webaudio/test/test_mediaElementAudioSourceNode.html b/content/media/webaudio/test/test_mediaElementAudioSourceNode.html new file mode 100644 index 00000000000..7f242f202b9 --- /dev/null +++ b/content/media/webaudio/test/test_mediaElementAudioSourceNode.html @@ -0,0 +1,69 @@ + + + + + Test MediaElementAudioSourceNode + + + + +
+
+
+ + diff --git a/dom/webidl/AudioContext.webidl b/dom/webidl/AudioContext.webidl index 99c8240a9f6..4447f82541d 100644 --- a/dom/webidl/AudioContext.webidl +++ b/dom/webidl/AudioContext.webidl @@ -43,6 +43,8 @@ interface AudioContext : EventTarget { [Creator] AnalyserNode createAnalyser(); [Creator, Throws] + MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement); + [Creator, Throws] MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream); [Creator] GainNode createGain(); diff --git a/dom/webidl/MediaElementAudioSourceNode.webidl b/dom/webidl/MediaElementAudioSourceNode.webidl new file mode 100644 index 00000000000..052e375add8 --- /dev/null +++ b/dom/webidl/MediaElementAudioSourceNode.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +[PrefControlled] +interface MediaElementAudioSourceNode : AudioNode { + +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 5239a0840b5..8d8554f3538 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -183,6 +183,7 @@ webidl_files = \ LinkStyle.webidl \ LocalMediaStream.webidl \ Location.webidl \ + MediaElementAudioSourceNode.webidl \ MediaError.webidl \ MediaRecorder.webidl \ MediaSource.webidl \