Bug 1324568 - Implement AudioScheduledSourceNode, r=padenot

This commit is contained in:
Andrea Marchesini 2016-12-21 10:53:17 +01:00
Родитель de7438cf52
Коммит 60364b27c9
15 изменённых файлов: 149 добавлений и 65 удалений

Просмотреть файл

@ -22,13 +22,15 @@
namespace mozilla { namespace mozilla {
namespace dom { 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_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_ADDREF_INHERITED(AudioBufferSourceNode, AudioScheduledSourceNode)
NS_IMPL_RELEASE_INHERITED(AudioBufferSourceNode, AudioNode) NS_IMPL_RELEASE_INHERITED(AudioBufferSourceNode, AudioScheduledSourceNode)
/** /**
* Media-thread playback engine for AudioBufferSourceNode. * Media-thread playback engine for AudioBufferSourceNode.
@ -588,10 +590,10 @@ public:
}; };
AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext) AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
: AudioNode(aContext, : AudioScheduledSourceNode(aContext,
2, 2,
ChannelCountMode::Max, ChannelCountMode::Max,
ChannelInterpretation::Speakers) ChannelInterpretation::Speakers)
, mLoopStart(0.0) , mLoopStart(0.0)
, mLoopEnd(0.0) , mLoopEnd(0.0)
// mOffset and mDuration are initialized in Start(). // 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<double>(), aRv);
}
void void
AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx) AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx)
{ {

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef AudioBufferSourceNode_h_ #ifndef AudioBufferSourceNode_h_
#define AudioBufferSourceNode_h_ #define AudioBufferSourceNode_h_
#include "AudioNode.h" #include "AudioScheduledSourceNode.h"
#include "AudioBuffer.h" #include "AudioBuffer.h"
namespace mozilla { namespace mozilla {
@ -16,7 +16,7 @@ namespace dom {
struct AudioBufferSourceOptions; struct AudioBufferSourceOptions;
class AudioParam; class AudioParam;
class AudioBufferSourceNode final : public AudioNode class AudioBufferSourceNode final : public AudioScheduledSourceNode
, public MainThreadMediaStreamListener , public MainThreadMediaStreamListener
{ {
public: public:
@ -35,7 +35,8 @@ public:
return this; return this;
} }
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode,
AudioScheduledSourceNode)
static already_AddRefed<AudioBufferSourceNode> static already_AddRefed<AudioBufferSourceNode>
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext, Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
@ -48,7 +49,9 @@ public:
void Start(double aWhen, double aOffset, void Start(double aWhen, double aOffset,
const Optional<double>& aDuration, ErrorResult& aRv); const Optional<double>& 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 AudioBuffer* GetBuffer(JSContext* aCx) const
{ {
@ -97,8 +100,6 @@ public:
} }
void SendDopplerShiftToStream(double aDopplerShift); void SendDopplerShiftToStream(double aDopplerShift);
IMPL_EVENT_HANDLER(ended)
void NotifyMainThreadStreamFinished() override; void NotifyMainThreadStreamFinished() override;
const char* NodeType() const override const char* NodeType() const override

Просмотреть файл

@ -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<JSObject*> aGivenProto)
{
return AudioScheduledSourceNodeBinding::Wrap(aCx, this, aGivenProto);
}
} // dom namespace
} // mozilla namespace

Просмотреть файл

@ -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<JSObject*> 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

Просмотреть файл

@ -12,14 +12,14 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(ConstantSourceNode, AudioNode, NS_IMPL_CYCLE_COLLECTION_INHERITED(ConstantSourceNode, AudioScheduledSourceNode,
mOffset) mOffset)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ConstantSourceNode) 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_ADDREF_INHERITED(ConstantSourceNode, AudioScheduledSourceNode)
NS_IMPL_RELEASE_INHERITED(ConstantSourceNode, AudioNode) NS_IMPL_RELEASE_INHERITED(ConstantSourceNode, AudioScheduledSourceNode)
class ConstantSourceNodeEngine final : public AudioNodeEngine class ConstantSourceNodeEngine final : public AudioNodeEngine
{ {
@ -142,10 +142,10 @@ public:
}; };
ConstantSourceNode::ConstantSourceNode(AudioContext* aContext) ConstantSourceNode::ConstantSourceNode(AudioContext* aContext)
: AudioNode(aContext, : AudioScheduledSourceNode(aContext,
1, 1,
ChannelCountMode::Max, ChannelCountMode::Max,
ChannelInterpretation::Speakers) ChannelInterpretation::Speakers)
, mOffset(new AudioParam(this, ConstantSourceNodeEngine::OFFSET, , mOffset(new AudioParam(this, ConstantSourceNodeEngine::OFFSET,
1.0, "offset")) 1.0, "offset"))
, mStartCalled(false) , mStartCalled(false)

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef ConstantSourceNode_h_ #ifndef ConstantSourceNode_h_
#define ConstantSourceNode_h_ #define ConstantSourceNode_h_
#include "AudioNode.h" #include "AudioScheduledSourceNode.h"
#include "AudioParam.h" #include "AudioParam.h"
#include "mozilla/dom/ConstantSourceNodeBinding.h" #include "mozilla/dom/ConstantSourceNodeBinding.h"
@ -16,14 +16,14 @@ namespace dom {
class AudioContext; class AudioContext;
class ConstantSourceNode final : public AudioNode, class ConstantSourceNode final : public AudioScheduledSourceNode
public MainThreadMediaStreamListener , public MainThreadMediaStreamListener
{ {
public: public:
explicit ConstantSourceNode(AudioContext* aContext); explicit ConstantSourceNode(AudioContext* aContext);
NS_DECL_ISUPPORTS_INHERITED 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<JSObject*> aGivenProto) override; JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -45,10 +45,8 @@ public:
return mOffset; return mOffset;
} }
void Start(double aWhen, ErrorResult& rv); void Start(double aWhen, ErrorResult& rv) override;
void Stop(double aWhen, ErrorResult& rv); void Stop(double aWhen, ErrorResult& rv) override;
IMPL_EVENT_HANDLER(ended)
void NotifyMainThreadStreamFinished() override; void NotifyMainThreadStreamFinished() override;

Просмотреть файл

@ -15,14 +15,14 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(OscillatorNode, AudioNode, NS_IMPL_CYCLE_COLLECTION_INHERITED(OscillatorNode, AudioScheduledSourceNode,
mPeriodicWave, mFrequency, mDetune) mPeriodicWave, mFrequency, mDetune)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(OscillatorNode) 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_ADDREF_INHERITED(OscillatorNode, AudioScheduledSourceNode)
NS_IMPL_RELEASE_INHERITED(OscillatorNode, AudioNode) NS_IMPL_RELEASE_INHERITED(OscillatorNode, AudioScheduledSourceNode)
class OscillatorNodeEngine final : public AudioNodeEngine class OscillatorNodeEngine final : public AudioNodeEngine
{ {
@ -408,10 +408,10 @@ public:
}; };
OscillatorNode::OscillatorNode(AudioContext* aContext) OscillatorNode::OscillatorNode(AudioContext* aContext)
: AudioNode(aContext, : AudioScheduledSourceNode(aContext,
2, 2,
ChannelCountMode::Max, ChannelCountMode::Max,
ChannelInterpretation::Speakers) ChannelInterpretation::Speakers)
, mType(OscillatorType::Sine) , mType(OscillatorType::Sine)
, mFrequency(new AudioParam(this, OscillatorNodeEngine::FREQUENCY, , mFrequency(new AudioParam(this, OscillatorNodeEngine::FREQUENCY,
440.0f, "frequency")) 440.0f, "frequency"))

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef OscillatorNode_h_ #ifndef OscillatorNode_h_
#define OscillatorNode_h_ #define OscillatorNode_h_
#include "AudioNode.h" #include "AudioScheduledSourceNode.h"
#include "AudioParam.h" #include "AudioParam.h"
#include "PeriodicWave.h" #include "PeriodicWave.h"
#include "mozilla/dom/OscillatorNodeBinding.h" #include "mozilla/dom/OscillatorNodeBinding.h"
@ -18,8 +18,8 @@ namespace dom {
class AudioContext; class AudioContext;
struct OscillatorOptions; struct OscillatorOptions;
class OscillatorNode final : public AudioNode, class OscillatorNode final : public AudioScheduledSourceNode
public MainThreadMediaStreamListener , public MainThreadMediaStreamListener
{ {
public: public:
static already_AddRefed<OscillatorNode> static already_AddRefed<OscillatorNode>
@ -27,7 +27,7 @@ public:
ErrorResult& aRv); ErrorResult& aRv);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode, AudioNode) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode, AudioScheduledSourceNode)
static already_AddRefed<OscillatorNode> static already_AddRefed<OscillatorNode>
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext, Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
@ -70,8 +70,9 @@ public:
return mDetune; return mDetune;
} }
void Start(double aWhen, ErrorResult& aRv); void Start(double aWhen, ErrorResult& aRv) override;
void Stop(double aWhen, ErrorResult& aRv); void Stop(double aWhen, ErrorResult& aRv) override;
void SetPeriodicWave(PeriodicWave& aPeriodicWave) void SetPeriodicWave(PeriodicWave& aPeriodicWave)
{ {
mPeriodicWave = &aPeriodicWave; mPeriodicWave = &aPeriodicWave;
@ -80,8 +81,6 @@ public:
SendTypeToStream(); SendTypeToStream();
} }
IMPL_EVENT_HANDLER(ended)
void NotifyMainThreadStreamFinished() override; void NotifyMainThreadStreamFinished() override;
const char* NodeType() const override const char* NodeType() const override

Просмотреть файл

@ -54,6 +54,7 @@ EXPORTS.mozilla.dom += [
'AudioNode.h', 'AudioNode.h',
'AudioParam.h', 'AudioParam.h',
'AudioProcessingEvent.h', 'AudioProcessingEvent.h',
'AudioScheduledSourceNode.h',
'BiquadFilterNode.h', 'BiquadFilterNode.h',
'ChannelMergerNode.h', 'ChannelMergerNode.h',
'ChannelSplitterNode.h', 'ChannelSplitterNode.h',
@ -89,6 +90,7 @@ UNIFIED_SOURCES += [
'AudioNodeStream.cpp', 'AudioNodeStream.cpp',
'AudioParam.cpp', 'AudioParam.cpp',
'AudioProcessingEvent.cpp', 'AudioProcessingEvent.cpp',
'AudioScheduledSourceNode.cpp',
'BiquadFilterNode.cpp', 'BiquadFilterNode.cpp',
'BufferDecoder.cpp', 'BufferDecoder.cpp',
'ChannelMergerNode.cpp', 'ChannelMergerNode.cpp',

Просмотреть файл

@ -154,6 +154,8 @@ var interfaceNamesInGlobalScope =
"AudioParam", "AudioParam",
// IMPORTANT: Do not change this list without review from a DOM peer! // IMPORTANT: Do not change this list without review from a DOM peer!
"AudioProcessingEvent", "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! // IMPORTANT: Do not change this list without review from a DOM peer!
"AudioStreamTrack", "AudioStreamTrack",
// IMPORTANT: Do not change this list without review from a DOM peer! // IMPORTANT: Do not change this list without review from a DOM peer!

Просмотреть файл

@ -21,7 +21,7 @@ dictionary AudioBufferSourceOptions {
[Pref="dom.webaudio.enabled", [Pref="dom.webaudio.enabled",
Constructor(BaseAudioContext context, optional AudioBufferSourceOptions options)] Constructor(BaseAudioContext context, optional AudioBufferSourceOptions options)]
interface AudioBufferSourceNode : AudioNode { interface AudioBufferSourceNode : AudioScheduledSourceNode {
attribute AudioBuffer? buffer; attribute AudioBuffer? buffer;
@ -35,10 +35,6 @@ interface AudioBufferSourceNode : AudioNode {
[Throws, UnsafeInPrerendering] [Throws, UnsafeInPrerendering]
void start(optional double when = 0, optional double grainOffset = 0, void start(optional double when = 0, optional double grainOffset = 0,
optional double grainDuration); optional double grainDuration);
[Throws, UnsafeInPrerendering]
void stop(optional double when = 0);
attribute EventHandler onended;
}; };
// Mozilla extensions // Mozilla extensions

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -16,11 +16,6 @@ dictionary ConstantSourceOptions {
[Pref="dom.webaudio.enabled", [Pref="dom.webaudio.enabled",
Constructor(BaseAudioContext context, optional ConstantSourceOptions options)] Constructor(BaseAudioContext context, optional ConstantSourceOptions options)]
interface ConstantSourceNode : AudioNode { interface ConstantSourceNode : AudioScheduledSourceNode {
readonly attribute AudioParam offset; readonly attribute AudioParam offset;
attribute EventHandler onended;
[Throws, UnsafeInPrerendering]
void start (optional double when = 0);
[Throws, UnsafeInPrerendering]
void stop (optional double when = 0);
}; };

Просмотреть файл

@ -27,7 +27,7 @@ dictionary OscillatorOptions : AudioNodeOptions {
[Pref="dom.webaudio.enabled", [Pref="dom.webaudio.enabled",
Constructor(BaseAudioContext context, optional OscillatorOptions options)] Constructor(BaseAudioContext context, optional OscillatorOptions options)]
interface OscillatorNode : AudioNode { interface OscillatorNode : AudioScheduledSourceNode {
[SetterThrows] [SetterThrows]
attribute OscillatorType type; attribute OscillatorType type;
@ -35,14 +35,7 @@ interface OscillatorNode : AudioNode {
readonly attribute AudioParam frequency; // in Hertz readonly attribute AudioParam frequency; // in Hertz
readonly attribute AudioParam detune; // in Cents 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); void setPeriodicWave(PeriodicWave periodicWave);
attribute EventHandler onended;
}; };
// Mozilla extensions // Mozilla extensions

Просмотреть файл

@ -41,6 +41,7 @@ WEBIDL_FILES = [
'AudioNode.webidl', 'AudioNode.webidl',
'AudioParam.webidl', 'AudioParam.webidl',
'AudioProcessingEvent.webidl', 'AudioProcessingEvent.webidl',
'AudioScheduledSourceNode.webidl',
'AudioStreamTrack.webidl', 'AudioStreamTrack.webidl',
'AudioTrack.webidl', 'AudioTrack.webidl',
'AudioTrackList.webidl', 'AudioTrackList.webidl',