diff --git a/dom/media/webaudio/AudioBufferSourceNode.cpp b/dom/media/webaudio/AudioBufferSourceNode.cpp index 2878c8c628ec..9993b42dcb76 100644 --- a/dom/media/webaudio/AudioBufferSourceNode.cpp +++ b/dom/media/webaudio/AudioBufferSourceNode.cpp @@ -22,13 +22,15 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioBufferSourceNode, AudioNode, mBuffer, mPlaybackRate, mDetune) +NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioBufferSourceNode, + AudioScheduledSourceNode, mBuffer, + mPlaybackRate, mDetune) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioBufferSourceNode) -NS_INTERFACE_MAP_END_INHERITING(AudioNode) +NS_INTERFACE_MAP_END_INHERITING(AudioScheduledSourceNode) -NS_IMPL_ADDREF_INHERITED(AudioBufferSourceNode, AudioNode) -NS_IMPL_RELEASE_INHERITED(AudioBufferSourceNode, AudioNode) +NS_IMPL_ADDREF_INHERITED(AudioBufferSourceNode, AudioScheduledSourceNode) +NS_IMPL_RELEASE_INHERITED(AudioBufferSourceNode, AudioScheduledSourceNode) /** * Media-thread playback engine for AudioBufferSourceNode. @@ -588,10 +590,10 @@ public: }; AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext) - : AudioNode(aContext, - 2, - ChannelCountMode::Max, - ChannelInterpretation::Speakers) + : AudioScheduledSourceNode(aContext, + 2, + ChannelCountMode::Max, + ChannelInterpretation::Speakers) , mLoopStart(0.0) , mLoopEnd(0.0) // mOffset and mDuration are initialized in Start(). @@ -711,6 +713,12 @@ AudioBufferSourceNode::Start(double aWhen, double aOffset, } } +void +AudioBufferSourceNode::Start(double aWhen, ErrorResult& aRv) +{ + Start(aWhen, 0 /* offset */, Optional(), aRv); +} + void AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx) { diff --git a/dom/media/webaudio/AudioBufferSourceNode.h b/dom/media/webaudio/AudioBufferSourceNode.h index 1011cd219bab..f42136acc74f 100644 --- a/dom/media/webaudio/AudioBufferSourceNode.h +++ b/dom/media/webaudio/AudioBufferSourceNode.h @@ -7,7 +7,7 @@ #ifndef AudioBufferSourceNode_h_ #define AudioBufferSourceNode_h_ -#include "AudioNode.h" +#include "AudioScheduledSourceNode.h" #include "AudioBuffer.h" namespace mozilla { @@ -16,7 +16,7 @@ namespace dom { struct AudioBufferSourceOptions; class AudioParam; -class AudioBufferSourceNode final : public AudioNode +class AudioBufferSourceNode final : public AudioScheduledSourceNode , public MainThreadMediaStreamListener { public: @@ -35,7 +35,8 @@ public: return this; } NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, + AudioScheduledSourceNode) static already_AddRefed Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext, @@ -48,7 +49,9 @@ public: void Start(double aWhen, double aOffset, const Optional& aDuration, ErrorResult& aRv); - void Stop(double aWhen, ErrorResult& aRv); + + void Start(double aWhen, ErrorResult& aRv) override; + void Stop(double aWhen, ErrorResult& aRv) override; AudioBuffer* GetBuffer(JSContext* aCx) const { @@ -97,8 +100,6 @@ public: } void SendDopplerShiftToStream(double aDopplerShift); - IMPL_EVENT_HANDLER(ended) - void NotifyMainThreadStreamFinished() override; const char* NodeType() const override diff --git a/dom/media/webaudio/AudioScheduledSourceNode.cpp b/dom/media/webaudio/AudioScheduledSourceNode.cpp new file mode 100644 index 000000000000..4cb4e1514da7 --- /dev/null +++ b/dom/media/webaudio/AudioScheduledSourceNode.cpp @@ -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/. */ + +#include "AudioScheduledSourceNode.h" +#include "mozilla/dom/AudioScheduledSourceNodeBinding.h" + +namespace mozilla { +namespace dom { + +AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* aContext, + uint32_t aChannelCount, + ChannelCountMode aChannelCountMode, + ChannelInterpretation aChannelInterpretation) + : AudioNode(aContext, aChannelCount, aChannelCountMode, + aChannelInterpretation) +{} + +JSObject* +AudioScheduledSourceNode::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + return AudioScheduledSourceNodeBinding::Wrap(aCx, this, aGivenProto); +} + +} // dom namespace +} // mozilla namespace diff --git a/dom/media/webaudio/AudioScheduledSourceNode.h b/dom/media/webaudio/AudioScheduledSourceNode.h new file mode 100644 index 000000000000..6cea3d4797ab --- /dev/null +++ b/dom/media/webaudio/AudioScheduledSourceNode.h @@ -0,0 +1,40 @@ +/* -*- 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 AudioScheduledSourceNode_h_ +#define AudioScheduledSourceNode_h_ + +#include "AudioNode.h" +#include "mozilla/dom/AudioScheduledSourceNodeBinding.h" + +namespace mozilla { +namespace dom { + +class AudioContext; + +class AudioScheduledSourceNode : public AudioNode +{ +public: + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + virtual void Start(double aWhen, ErrorResult& aRv) = 0; + virtual void Stop(double aWhen, ErrorResult& aRv) = 0; + + IMPL_EVENT_HANDLER(ended) + +protected: + AudioScheduledSourceNode(AudioContext* aContext, + uint32_t aChannelCount, + ChannelCountMode aChannelCountMode, + ChannelInterpretation aChannelInterpretation); + virtual ~AudioScheduledSourceNode() = default; +}; + +} // namespace dom +} // namespace mozilla + +#endif diff --git a/dom/media/webaudio/ConstantSourceNode.cpp b/dom/media/webaudio/ConstantSourceNode.cpp index b6884105cf5a..bfcb7e743962 100644 --- a/dom/media/webaudio/ConstantSourceNode.cpp +++ b/dom/media/webaudio/ConstantSourceNode.cpp @@ -12,14 +12,14 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_INHERITED(ConstantSourceNode, AudioNode, +NS_IMPL_CYCLE_COLLECTION_INHERITED(ConstantSourceNode, AudioScheduledSourceNode, mOffset) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ConstantSourceNode) -NS_INTERFACE_MAP_END_INHERITING(AudioNode) +NS_INTERFACE_MAP_END_INHERITING(AudioScheduledSourceNode) -NS_IMPL_ADDREF_INHERITED(ConstantSourceNode, AudioNode) -NS_IMPL_RELEASE_INHERITED(ConstantSourceNode, AudioNode) +NS_IMPL_ADDREF_INHERITED(ConstantSourceNode, AudioScheduledSourceNode) +NS_IMPL_RELEASE_INHERITED(ConstantSourceNode, AudioScheduledSourceNode) class ConstantSourceNodeEngine final : public AudioNodeEngine { @@ -142,10 +142,10 @@ public: }; ConstantSourceNode::ConstantSourceNode(AudioContext* aContext) - : AudioNode(aContext, - 1, - ChannelCountMode::Max, - ChannelInterpretation::Speakers) + : AudioScheduledSourceNode(aContext, + 1, + ChannelCountMode::Max, + ChannelInterpretation::Speakers) , mOffset(new AudioParam(this, ConstantSourceNodeEngine::OFFSET, 1.0, "offset")) , mStartCalled(false) diff --git a/dom/media/webaudio/ConstantSourceNode.h b/dom/media/webaudio/ConstantSourceNode.h index 7b5e7197e93f..90e70be97b32 100644 --- a/dom/media/webaudio/ConstantSourceNode.h +++ b/dom/media/webaudio/ConstantSourceNode.h @@ -7,7 +7,7 @@ #ifndef ConstantSourceNode_h_ #define ConstantSourceNode_h_ -#include "AudioNode.h" +#include "AudioScheduledSourceNode.h" #include "AudioParam.h" #include "mozilla/dom/ConstantSourceNodeBinding.h" @@ -16,14 +16,14 @@ namespace dom { class AudioContext; -class ConstantSourceNode final : public AudioNode, - public MainThreadMediaStreamListener +class ConstantSourceNode final : public AudioScheduledSourceNode + , public MainThreadMediaStreamListener { public: explicit ConstantSourceNode(AudioContext* aContext); NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ConstantSourceNode, AudioNode) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ConstantSourceNode, AudioScheduledSourceNode) JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; @@ -45,10 +45,8 @@ public: return mOffset; } - void Start(double aWhen, ErrorResult& rv); - void Stop(double aWhen, ErrorResult& rv); - - IMPL_EVENT_HANDLER(ended) + void Start(double aWhen, ErrorResult& rv) override; + void Stop(double aWhen, ErrorResult& rv) override; void NotifyMainThreadStreamFinished() override; diff --git a/dom/media/webaudio/OscillatorNode.cpp b/dom/media/webaudio/OscillatorNode.cpp index 63a27d3345b0..54c6c48ab5db 100644 --- a/dom/media/webaudio/OscillatorNode.cpp +++ b/dom/media/webaudio/OscillatorNode.cpp @@ -15,14 +15,14 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_INHERITED(OscillatorNode, AudioNode, +NS_IMPL_CYCLE_COLLECTION_INHERITED(OscillatorNode, AudioScheduledSourceNode, mPeriodicWave, mFrequency, mDetune) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(OscillatorNode) -NS_INTERFACE_MAP_END_INHERITING(AudioNode) +NS_INTERFACE_MAP_END_INHERITING(AudioScheduledSourceNode) -NS_IMPL_ADDREF_INHERITED(OscillatorNode, AudioNode) -NS_IMPL_RELEASE_INHERITED(OscillatorNode, AudioNode) +NS_IMPL_ADDREF_INHERITED(OscillatorNode, AudioScheduledSourceNode) +NS_IMPL_RELEASE_INHERITED(OscillatorNode, AudioScheduledSourceNode) class OscillatorNodeEngine final : public AudioNodeEngine { @@ -408,10 +408,10 @@ public: }; OscillatorNode::OscillatorNode(AudioContext* aContext) - : AudioNode(aContext, - 2, - ChannelCountMode::Max, - ChannelInterpretation::Speakers) + : AudioScheduledSourceNode(aContext, + 2, + ChannelCountMode::Max, + ChannelInterpretation::Speakers) , mType(OscillatorType::Sine) , mFrequency(new AudioParam(this, OscillatorNodeEngine::FREQUENCY, 440.0f, "frequency")) diff --git a/dom/media/webaudio/OscillatorNode.h b/dom/media/webaudio/OscillatorNode.h index 580a22ca0529..24304e87e6b4 100644 --- a/dom/media/webaudio/OscillatorNode.h +++ b/dom/media/webaudio/OscillatorNode.h @@ -7,7 +7,7 @@ #ifndef OscillatorNode_h_ #define OscillatorNode_h_ -#include "AudioNode.h" +#include "AudioScheduledSourceNode.h" #include "AudioParam.h" #include "PeriodicWave.h" #include "mozilla/dom/OscillatorNodeBinding.h" @@ -18,8 +18,8 @@ namespace dom { class AudioContext; struct OscillatorOptions; -class OscillatorNode final : public AudioNode, - public MainThreadMediaStreamListener +class OscillatorNode final : public AudioScheduledSourceNode + , public MainThreadMediaStreamListener { public: static already_AddRefed @@ -27,7 +27,7 @@ public: ErrorResult& aRv); NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode, AudioNode) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode, AudioScheduledSourceNode) static already_AddRefed Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext, @@ -70,8 +70,9 @@ public: return mDetune; } - void Start(double aWhen, ErrorResult& aRv); - void Stop(double aWhen, ErrorResult& aRv); + void Start(double aWhen, ErrorResult& aRv) override; + void Stop(double aWhen, ErrorResult& aRv) override; + void SetPeriodicWave(PeriodicWave& aPeriodicWave) { mPeriodicWave = &aPeriodicWave; @@ -80,8 +81,6 @@ public: SendTypeToStream(); } - IMPL_EVENT_HANDLER(ended) - void NotifyMainThreadStreamFinished() override; const char* NodeType() const override diff --git a/dom/media/webaudio/moz.build b/dom/media/webaudio/moz.build index db064484113d..87e820bb920c 100644 --- a/dom/media/webaudio/moz.build +++ b/dom/media/webaudio/moz.build @@ -54,6 +54,7 @@ EXPORTS.mozilla.dom += [ 'AudioNode.h', 'AudioParam.h', 'AudioProcessingEvent.h', + 'AudioScheduledSourceNode.h', 'BiquadFilterNode.h', 'ChannelMergerNode.h', 'ChannelSplitterNode.h', @@ -89,6 +90,7 @@ UNIFIED_SOURCES += [ 'AudioNodeStream.cpp', 'AudioParam.cpp', 'AudioProcessingEvent.cpp', + 'AudioScheduledSourceNode.cpp', 'BiquadFilterNode.cpp', 'BufferDecoder.cpp', 'ChannelMergerNode.cpp', diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index cc2512f03996..0123040ac859 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -154,6 +154,8 @@ var interfaceNamesInGlobalScope = "AudioParam", // IMPORTANT: Do not change this list without review from a DOM peer! "AudioProcessingEvent", +// IMPORTANT: Do not change this list without review from a DOM peer! + "AudioScheduledSourceNode", // IMPORTANT: Do not change this list without review from a DOM peer! "AudioStreamTrack", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/AudioBufferSourceNode.webidl b/dom/webidl/AudioBufferSourceNode.webidl index abd6c38e33e0..455b269cf4a2 100644 --- a/dom/webidl/AudioBufferSourceNode.webidl +++ b/dom/webidl/AudioBufferSourceNode.webidl @@ -21,7 +21,7 @@ dictionary AudioBufferSourceOptions { [Pref="dom.webaudio.enabled", Constructor(BaseAudioContext context, optional AudioBufferSourceOptions options)] -interface AudioBufferSourceNode : AudioNode { +interface AudioBufferSourceNode : AudioScheduledSourceNode { attribute AudioBuffer? buffer; @@ -35,10 +35,6 @@ interface AudioBufferSourceNode : AudioNode { [Throws, UnsafeInPrerendering] void start(optional double when = 0, optional double grainOffset = 0, optional double grainDuration); - [Throws, UnsafeInPrerendering] - void stop(optional double when = 0); - - attribute EventHandler onended; }; // Mozilla extensions diff --git a/dom/webidl/AudioScheduledSourceNode.webidl b/dom/webidl/AudioScheduledSourceNode.webidl new file mode 100644 index 000000000000..6a5f381a06ee --- /dev/null +++ b/dom/webidl/AudioScheduledSourceNode.webidl @@ -0,0 +1,20 @@ +/* -*- 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://webaudio.github.io/web-audio-api/#idl-def-AudioScheduledSourceNode + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +interface AudioScheduledSourceNode : AudioNode { + attribute EventHandler onended; + [Throws, UnsafeInPrerendering] + void start (optional double when = 0); + + [Throws, UnsafeInPrerendering] + void stop (optional double when = 0); +}; diff --git a/dom/webidl/ConstantSourceNode.webidl b/dom/webidl/ConstantSourceNode.webidl index 598f1bbea960..cd005897aacd 100644 --- a/dom/webidl/ConstantSourceNode.webidl +++ b/dom/webidl/ConstantSourceNode.webidl @@ -16,11 +16,6 @@ dictionary ConstantSourceOptions { [Pref="dom.webaudio.enabled", Constructor(BaseAudioContext context, optional ConstantSourceOptions options)] -interface ConstantSourceNode : AudioNode { +interface ConstantSourceNode : AudioScheduledSourceNode { readonly attribute AudioParam offset; - attribute EventHandler onended; - [Throws, UnsafeInPrerendering] - void start (optional double when = 0); - [Throws, UnsafeInPrerendering] - void stop (optional double when = 0); }; diff --git a/dom/webidl/OscillatorNode.webidl b/dom/webidl/OscillatorNode.webidl index 8d88e6f44619..acf75a81812e 100644 --- a/dom/webidl/OscillatorNode.webidl +++ b/dom/webidl/OscillatorNode.webidl @@ -27,7 +27,7 @@ dictionary OscillatorOptions : AudioNodeOptions { [Pref="dom.webaudio.enabled", Constructor(BaseAudioContext context, optional OscillatorOptions options)] -interface OscillatorNode : AudioNode { +interface OscillatorNode : AudioScheduledSourceNode { [SetterThrows] attribute OscillatorType type; @@ -35,14 +35,7 @@ interface OscillatorNode : AudioNode { readonly attribute AudioParam frequency; // in Hertz readonly attribute AudioParam detune; // in Cents - [Throws, UnsafeInPrerendering] - void start(optional double when = 0); - [Throws, UnsafeInPrerendering] - void stop(optional double when = 0); void setPeriodicWave(PeriodicWave periodicWave); - - attribute EventHandler onended; - }; // Mozilla extensions diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index b744f6459998..5a4d3eafc2db 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -41,6 +41,7 @@ WEBIDL_FILES = [ 'AudioNode.webidl', 'AudioParam.webidl', 'AudioProcessingEvent.webidl', + 'AudioScheduledSourceNode.webidl', 'AudioStreamTrack.webidl', 'AudioTrack.webidl', 'AudioTrackList.webidl',