bug 1210266 use parameter index instead of node callback for sending timeline events r=padenot

--HG--
extra : rebase_source : 27a8ac26a83788c057a225fca47c49af1a021401
This commit is contained in:
Karl Tomlinson 2015-10-01 15:48:20 +13:00
parent 8d75533f8d
commit 4799b667a3
18 changed files with 46 additions and 212 deletions

View File

@ -580,8 +580,8 @@ AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
, mLoopStart(0.0)
, mLoopEnd(0.0)
// mOffset and mDuration are initialized in Start().
, mPlaybackRate(new AudioParam(this, SendPlaybackRateToStream, 1.0f, "playbackRate"))
, mDetune(new AudioParam(this, SendDetuneToStream, 0.0f, "detune"))
, mPlaybackRate(new AudioParam(this, PLAYBACKRATE, 1.0f, "playbackRate"))
, mDetune(new AudioParam(this, DETUNE, 0.0f, "detune"))
, mLoop(false)
, mStartCalled(false)
{
@ -784,28 +784,6 @@ AudioBufferSourceNode::NotifyMainThreadStreamFinished()
MarkInactive();
}
void
AudioBufferSourceNode::SendPlaybackRateToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
AudioBufferSourceNode* This = static_cast<AudioBufferSourceNode*>(aNode);
if (!This->mStream) {
return;
}
SendTimelineEventToStream(This, PLAYBACKRATE, aEvent);
}
void
AudioBufferSourceNode::SendDetuneToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
AudioBufferSourceNode* This = static_cast<AudioBufferSourceNode*>(aNode);
if (!This->mStream) {
return;
}
SendTimelineEventToStream(This, DETUNE, aEvent);
}
void
AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift)
{

View File

@ -129,10 +129,6 @@ private:
void SendLoopParametersToStream();
void SendBufferParameterToStream(JSContext* aCx);
void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream);
static void SendPlaybackRateToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendDetuneToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
private:
double mLoopStart;

View File

@ -303,15 +303,6 @@ AudioNode::SendChannelMixingParametersToStream()
}
}
void
AudioNode::SendTimelineEventToStream(AudioNode* aNode, uint32_t aIndex,
const AudioTimelineEvent& aEvent)
{
AudioNodeStream* ns = aNode->mStream;
MOZ_ASSERT(ns, "How come we don't have a stream here?");
ns->SendTimelineEvent(aIndex, aEvent);
}
void
AudioNode::Disconnect(uint32_t aOutput, ErrorResult& aRv)
{

View File

@ -28,7 +28,6 @@ class AudioBufferSourceNode;
class AudioParam;
class AudioParamTimeline;
struct ThreeDPoint;
struct AudioTimelineEvent;
/**
* The DOM object representing a Web Audio AudioNode.
@ -224,8 +223,6 @@ protected:
void SendInt32ParameterToStream(uint32_t aIndex, int32_t aValue);
void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue);
void SendChannelMixingParametersToStream();
static void SendTimelineEventToStream(AudioNode* aNode, uint32_t aIndex,
const dom::AudioTimelineEvent& aEvent);
private:
nsRefPtr<AudioContext> mContext;

View File

@ -44,14 +44,14 @@ NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioParam, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioParam, Release)
AudioParam::AudioParam(AudioNode* aNode,
AudioParam::CallbackType aCallback,
uint32_t aIndex,
float aDefaultValue,
const char* aName)
: AudioParamTimeline(aDefaultValue)
, mNode(aNode)
, mCallback(aCallback)
, mDefaultValue(aDefaultValue)
, mName(aName)
, mIndex(aIndex)
, mDefaultValue(aDefaultValue)
{
}
@ -120,12 +120,20 @@ AudioParam::Stream()
// Send the stream to the timeline on the MSG side.
AudioTimelineEvent event(mStream);
mCallback(mNode, event);
SendEventToEngine(event);
return mStream;
}
void
AudioParam::SendEventToEngine(const AudioTimelineEvent& aEvent)
{
AudioNodeStream* stream = mNode->GetStream();
if (stream) {
stream->SendTimelineEvent(mIndex, aEvent);
}
}
float
AudioParamTimeline::AudioNodeInputValue(size_t aCounter) const
{

View File

@ -26,10 +26,8 @@ class AudioParam final : public nsWrapperCache,
virtual ~AudioParam();
public:
typedef void (*CallbackType)(AudioNode* aNode, const AudioTimelineEvent&);
AudioParam(AudioNode* aNode,
CallbackType aCallback,
uint32_t aIndex,
float aDefaultValue,
const char* aName);
@ -72,7 +70,7 @@ public:
AudioParamTimeline::SetValue(aValue);
mCallback(mNode, event);
SendEventToEngine(event);
}
void SetValueAtTime(float aValue, double aStartTime, ErrorResult& aRv)
@ -129,7 +127,7 @@ public:
AudioTimelineEvent event(AudioTimelineEvent::Cancel, aStartTime, 0.0f);
mCallback(mNode, event);
SendEventToEngine(event);
}
uint32_t ParentNodeId()
@ -193,10 +191,6 @@ public:
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
protected:
nsCycleCollectingAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
private:
void EventInsertionHelper(ErrorResult& aRv,
AudioTimelineEvent::Type aType,
@ -215,18 +209,22 @@ private:
AudioEventTimeline::InsertEvent<double>(event);
mCallback(mNode, event);
SendEventToEngine(event);
}
void SendEventToEngine(const AudioTimelineEvent& aEvent);
nsCycleCollectingAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
nsRefPtr<AudioNode> mNode;
// For every InputNode, there is a corresponding entry in mOutputParams of the
// InputNode's mInputNode.
nsTArray<AudioNode::InputNode> mInputNodes;
CallbackType mCallback;
const float mDefaultValue;
const char* mName;
// The input port used to connect the AudioParam's stream to its node's stream
nsRefPtr<MediaInputPort> mNodeStreamPort;
const uint32_t mIndex;
const float mDefaultValue;
};
} // namespace dom

View File

@ -242,10 +242,11 @@ BiquadFilterNode::BiquadFilterNode(AudioContext* aContext)
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mType(BiquadFilterType::Lowpass)
, mFrequency(new AudioParam(this, SendFrequencyToStream, 350.f, "frequency"))
, mDetune(new AudioParam(this, SendDetuneToStream, 0.f, "detune"))
, mQ(new AudioParam(this, SendQToStream, 1.f, "Q"))
, mGain(new AudioParam(this, SendGainToStream, 0.f, "gain"))
, mFrequency(new AudioParam(this, BiquadFilterNodeEngine::FREQUENCY,
350.f, "frequency"))
, mDetune(new AudioParam(this, BiquadFilterNodeEngine::DETUNE, 0.f, "detune"))
, mQ(new AudioParam(this, BiquadFilterNodeEngine::Q, 1.f, "Q"))
, mGain(new AudioParam(this, BiquadFilterNodeEngine::GAIN, 0.f, "gain"))
{
BiquadFilterNodeEngine* engine = new BiquadFilterNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,
@ -336,33 +337,5 @@ BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz,
biquad.getFrequencyResponse(int(length), frequencies, aMagResponse.Data(), aPhaseResponse.Data());
}
void
BiquadFilterNode::SendFrequencyToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
BiquadFilterNode* This = static_cast<BiquadFilterNode*>(aNode);
SendTimelineEventToStream(This, BiquadFilterNodeEngine::FREQUENCY, aEvent);
}
void
BiquadFilterNode::SendDetuneToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
BiquadFilterNode* This = static_cast<BiquadFilterNode*>(aNode);
SendTimelineEventToStream(This, BiquadFilterNodeEngine::DETUNE, aEvent);
}
void
BiquadFilterNode::SendQToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
BiquadFilterNode* This = static_cast<BiquadFilterNode*>(aNode);
SendTimelineEventToStream(This, BiquadFilterNodeEngine::Q, aEvent);
}
void
BiquadFilterNode::SendGainToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
BiquadFilterNode* This = static_cast<BiquadFilterNode*>(aNode);
SendTimelineEventToStream(This, BiquadFilterNodeEngine::GAIN, aEvent);
}
} // namespace dom
} // namespace mozilla

View File

@ -15,7 +15,6 @@ namespace mozilla {
namespace dom {
class AudioContext;
struct AudioTimelineEvent;
class BiquadFilterNode final : public AudioNode
{
@ -68,16 +67,6 @@ public:
protected:
virtual ~BiquadFilterNode();
private:
static void SendFrequencyToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendDetuneToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvente);
static void SendQToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendGainToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
private:
BiquadFilterType mType;
nsRefPtr<AudioParam> mFrequency;

View File

@ -196,7 +196,7 @@ DelayNode::DelayNode(AudioContext* aContext, double aMaxDelay)
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mDelay(new AudioParam(this, SendDelayToStream, 0.0f, "delayTime"))
, mDelay(new AudioParam(this, DelayNodeEngine::DELAY, 0.0f, "delayTime"))
{
DelayNodeEngine* engine =
new DelayNodeEngine(this, aContext->Destination(),
@ -229,12 +229,5 @@ DelayNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return DelayNodeBinding::Wrap(aCx, this, aGivenProto);
}
void
DelayNode::SendDelayToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
DelayNode* This = static_cast<DelayNode*>(aNode);
SendTimelineEventToStream(This, DelayNodeEngine::DELAY, aEvent);
}
} // namespace dom
} // namespace mozilla

View File

@ -42,8 +42,6 @@ protected:
virtual ~DelayNode();
private:
static void SendDelayToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
friend class DelayNodeEngine;
private:

View File

@ -186,12 +186,17 @@ DynamicsCompressorNode::DynamicsCompressorNode(AudioContext* aContext)
2,
ChannelCountMode::Explicit,
ChannelInterpretation::Speakers)
, mThreshold(new AudioParam(this, SendThresholdToStream, -24.f, "threshold"))
, mKnee(new AudioParam(this, SendKneeToStream, 30.f, "knee"))
, mRatio(new AudioParam(this, SendRatioToStream, 12.f, "ratio"))
, mThreshold(new AudioParam(this, DynamicsCompressorNodeEngine::THRESHOLD,
-24.f, "threshold"))
, mKnee(new AudioParam(this, DynamicsCompressorNodeEngine::KNEE,
30.f, "knee"))
, mRatio(new AudioParam(this, DynamicsCompressorNodeEngine::RATIO,
12.f, "ratio"))
, mReduction(0)
, mAttack(new AudioParam(this, SendAttackToStream, 0.003f, "attack"))
, mRelease(new AudioParam(this, SendReleaseToStream, 0.25f, "release"))
, mAttack(new AudioParam(this, DynamicsCompressorNodeEngine::ATTACK,
0.003f, "attack"))
, mRelease(new AudioParam(this, DynamicsCompressorNodeEngine::RELEASE,
0.25f, "release"))
{
DynamicsCompressorNodeEngine* engine = new DynamicsCompressorNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,
@ -226,45 +231,5 @@ DynamicsCompressorNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenP
return DynamicsCompressorNodeBinding::Wrap(aCx, this, aGivenProto);
}
void
DynamicsCompressorNode::SendThresholdToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
DynamicsCompressorNode* This = static_cast<DynamicsCompressorNode*>(aNode);
SendTimelineEventToStream(This, DynamicsCompressorNodeEngine::THRESHOLD, aEvent);
}
void
DynamicsCompressorNode::SendKneeToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
DynamicsCompressorNode* This = static_cast<DynamicsCompressorNode*>(aNode);
SendTimelineEventToStream(This, DynamicsCompressorNodeEngine::KNEE, aEvent);
}
void
DynamicsCompressorNode::SendRatioToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
DynamicsCompressorNode* This = static_cast<DynamicsCompressorNode*>(aNode);
SendTimelineEventToStream(This, DynamicsCompressorNodeEngine::RATIO, aEvent);
}
void
DynamicsCompressorNode::SendAttackToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
DynamicsCompressorNode* This = static_cast<DynamicsCompressorNode*>(aNode);
SendTimelineEventToStream(This, DynamicsCompressorNodeEngine::ATTACK, aEvent);
}
void
DynamicsCompressorNode::SendReleaseToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent)
{
DynamicsCompressorNode* This = static_cast<DynamicsCompressorNode*>(aNode);
SendTimelineEventToStream(This, DynamicsCompressorNodeEngine::RELEASE, aEvent);
}
} // namespace dom
} // namespace mozilla

View File

@ -73,18 +73,6 @@ public:
protected:
virtual ~DynamicsCompressorNode();
private:
static void SendThresholdToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendKneeToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendRatioToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendAttackToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
static void SendReleaseToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
private:
nsRefPtr<AudioParam> mThreshold;
nsRefPtr<AudioParam> mKnee;

View File

@ -117,7 +117,7 @@ GainNode::GainNode(AudioContext* aContext)
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mGain(new AudioParam(this, SendGainToStream, 1.0f, "gain"))
, mGain(new AudioParam(this, GainNodeEngine::GAIN, 1.0f, "gain"))
{
GainNodeEngine* engine = new GainNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,
@ -148,12 +148,5 @@ GainNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return GainNodeBinding::Wrap(aCx, this, aGivenProto);
}
void
GainNode::SendGainToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
GainNode* This = static_cast<GainNode*>(aNode);
SendTimelineEventToStream(This, GainNodeEngine::GAIN, aEvent);
}
} // namespace dom
} // namespace mozilla

View File

@ -41,9 +41,6 @@ public:
protected:
virtual ~GainNode();
private:
static void SendGainToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent);
private:
nsRefPtr<AudioParam> mGain;
};

View File

@ -402,8 +402,9 @@ OscillatorNode::OscillatorNode(AudioContext* aContext)
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mType(OscillatorType::Sine)
, mFrequency(new AudioParam(this, SendFrequencyToStream, 440.0f, "frequency"))
, mDetune(new AudioParam(this, SendDetuneToStream, 0.0f, "detune"))
, mFrequency(new AudioParam(this, OscillatorNodeEngine::FREQUENCY,
440.0f, "frequency"))
, mDetune(new AudioParam(this, OscillatorNodeEngine::DETUNE, 0.0f, "detune"))
, mStartCalled(false)
{
OscillatorNodeEngine* engine = new OscillatorNodeEngine(this, aContext->Destination());
@ -452,26 +453,6 @@ OscillatorNode::DestroyMediaStream()
AudioNode::DestroyMediaStream();
}
void
OscillatorNode::SendFrequencyToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
OscillatorNode* This = static_cast<OscillatorNode*>(aNode);
if (!This->mStream) {
return;
}
SendTimelineEventToStream(This, OscillatorNodeEngine::FREQUENCY, aEvent);
}
void
OscillatorNode::SendDetuneToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
OscillatorNode* This = static_cast<OscillatorNode*>(aNode);
if (!This->mStream) {
return;
}
SendTimelineEventToStream(This, OscillatorNodeEngine::DETUNE, aEvent);
}
void
OscillatorNode::SendTypeToStream()
{

View File

@ -87,8 +87,6 @@ protected:
virtual ~OscillatorNode();
private:
static void SendFrequencyToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent);
static void SendDetuneToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent);
void SendTypeToStream();
void SendPeriodicWaveToStream();

View File

@ -171,7 +171,7 @@ StereoPannerNode::StereoPannerNode(AudioContext* aContext)
2,
ChannelCountMode::Clamped_max,
ChannelInterpretation::Speakers)
, mPan(new AudioParam(this, SendPanToStream, 0.f, "pan"))
, mPan(new AudioParam(this, StereoPannerNodeEngine::PAN, 0.f, "pan"))
{
StereoPannerNodeEngine* engine = new StereoPannerNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,
@ -202,12 +202,5 @@ StereoPannerNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return StereoPannerNodeBinding::Wrap(aCx, this, aGivenProto);
}
void
StereoPannerNode::SendPanToStream(AudioNode* aNode, const AudioTimelineEvent& aEvent)
{
StereoPannerNode* This = static_cast<StereoPannerNode*>(aNode);
SendTimelineEventToStream(This, StereoPannerNodeEngine::PAN, aEvent);
}
} // namespace dom
} // namespace mozilla

View File

@ -60,8 +60,6 @@ protected:
virtual ~StereoPannerNode();
private:
static void SendPanToStream(AudioNode* aNode,
const AudioTimelineEvent& aEvent);
nsRefPtr<AudioParam> mPan;
};