Skip to content

Commit

Permalink
Bug 1324568 - Implement AudioScheduledSourceNode, r=padenot
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed Dec 20, 2016
1 parent ad79ef8 commit bd93c7b
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 65 deletions.
24 changes: 16 additions & 8 deletions dom/media/webaudio/AudioBufferSourceNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -588,10 +590,10 @@ class AudioBufferSourceNodeEngine final : public AudioNodeEngine
};

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().
Expand Down Expand Up @@ -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
AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx)
{
Expand Down
13 changes: 7 additions & 6 deletions dom/media/webaudio/AudioBufferSourceNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef AudioBufferSourceNode_h_
#define AudioBufferSourceNode_h_

#include "AudioNode.h"
#include "AudioScheduledSourceNode.h"
#include "AudioBuffer.h"

namespace mozilla {
Expand All @@ -16,7 +16,7 @@ namespace dom {
struct AudioBufferSourceOptions;
class AudioParam;

class AudioBufferSourceNode final : public AudioNode
class AudioBufferSourceNode final : public AudioScheduledSourceNode
, public MainThreadMediaStreamListener
{
public:
Expand All @@ -35,7 +35,8 @@ class AudioBufferSourceNode final : public AudioNode
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<AudioBufferSourceNode>
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
Expand All @@ -48,7 +49,9 @@ class AudioBufferSourceNode final : public AudioNode

void Start(double aWhen, double aOffset,
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
{
Expand Down Expand Up @@ -97,8 +100,6 @@ class AudioBufferSourceNode final : public AudioNode
}
void SendDopplerShiftToStream(double aDopplerShift);

IMPL_EVENT_HANDLER(ended)

void NotifyMainThreadStreamFinished() override;

const char* NodeType() const override
Expand Down
29 changes: 29 additions & 0 deletions dom/media/webaudio/AudioScheduledSourceNode.cpp
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions dom/media/webaudio/AudioScheduledSourceNode.h
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions dom/media/webaudio/ConstantSourceNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -142,10 +142,10 @@ class ConstantSourceNodeEngine final : public AudioNodeEngine
};

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)
Expand Down
14 changes: 6 additions & 8 deletions dom/media/webaudio/ConstantSourceNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ConstantSourceNode_h_
#define ConstantSourceNode_h_

#include "AudioNode.h"
#include "AudioScheduledSourceNode.h"
#include "AudioParam.h"
#include "mozilla/dom/ConstantSourceNodeBinding.h"

Expand All @@ -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<JSObject*> aGivenProto) override;

Expand All @@ -45,10 +45,8 @@ class ConstantSourceNode final : public AudioNode,
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;

Expand Down
16 changes: 8 additions & 8 deletions dom/media/webaudio/OscillatorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -408,10 +408,10 @@ class OscillatorNodeEngine final : public AudioNodeEngine
};

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"))
Expand Down
15 changes: 7 additions & 8 deletions dom/media/webaudio/OscillatorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,16 +18,16 @@ namespace dom {
class AudioContext;
struct OscillatorOptions;

class OscillatorNode final : public AudioNode,
public MainThreadMediaStreamListener
class OscillatorNode final : public AudioScheduledSourceNode
, public MainThreadMediaStreamListener
{
public:
static already_AddRefed<OscillatorNode>
Create(AudioContext& aAudioContext, const OscillatorOptions& aOptions,
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<OscillatorNode>
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
Expand Down Expand Up @@ -70,8 +70,9 @@ class OscillatorNode final : public AudioNode,
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;
Expand All @@ -80,8 +81,6 @@ class OscillatorNode final : public AudioNode,
SendTypeToStream();
}

IMPL_EVENT_HANDLER(ended)

void NotifyMainThreadStreamFinished() override;

const char* NodeType() const override
Expand Down
2 changes: 2 additions & 0 deletions dom/media/webaudio/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ EXPORTS.mozilla.dom += [
'AudioNode.h',
'AudioParam.h',
'AudioProcessingEvent.h',
'AudioScheduledSourceNode.h',
'BiquadFilterNode.h',
'ChannelMergerNode.h',
'ChannelSplitterNode.h',
Expand Down Expand Up @@ -89,6 +90,7 @@ UNIFIED_SOURCES += [
'AudioNodeStream.cpp',
'AudioParam.cpp',
'AudioProcessingEvent.cpp',
'AudioScheduledSourceNode.cpp',
'BiquadFilterNode.cpp',
'BufferDecoder.cpp',
'ChannelMergerNode.cpp',
Expand Down
6 changes: 1 addition & 5 deletions dom/webidl/AudioBufferSourceNode.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions dom/webidl/AudioScheduledSourceNode.webidl
Original file line number Diff line number Diff line change
@@ -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);
};
7 changes: 1 addition & 6 deletions dom/webidl/ConstantSourceNode.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Loading

0 comments on commit bd93c7b

Please sign in to comment.