Bug 1134034 - Add a chrome-only parentId and name on AudioParam for devtools. r=ehsan
authorPaul Adenot <paul@paul.cx>
Tue, 14 Apr 2015 17:03:52 +0200
changeset 257921 060479d9d865696417121cf906ade90e848ca925
parent 257920 06ecc22ef9d57ad56783e25c9586b12f62b33ac2
child 257922 c526e674ca3fa7941208125ae403ac6c2d1fe315
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1134034
milestone40.0a1
Bug 1134034 - Add a chrome-only parentId and name on AudioParam for devtools. r=ehsan
dom/media/webaudio/AudioBufferSourceNode.cpp
dom/media/webaudio/AudioParam.cpp
dom/media/webaudio/AudioParam.h
dom/media/webaudio/BiquadFilterNode.cpp
dom/media/webaudio/DelayNode.cpp
dom/media/webaudio/DynamicsCompressorNode.cpp
dom/media/webaudio/GainNode.cpp
dom/media/webaudio/OscillatorNode.cpp
dom/media/webaudio/StereoPannerNode.cpp
dom/media/webaudio/test/chrome.ini
dom/media/webaudio/test/test_AudioParamDevtoolsAPI.html
dom/webidl/AudioParam.webidl
--- a/dom/media/webaudio/AudioBufferSourceNode.cpp
+++ b/dom/media/webaudio/AudioBufferSourceNode.cpp
@@ -553,18 +553,18 @@ public:
 AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
   , mLoopStart(0.0)
   , mLoopEnd(0.0)
   // mOffset and mDuration are initialized in Start().
-  , mPlaybackRate(new AudioParam(this, SendPlaybackRateToStream, 1.0f))
-  , mDetune(new AudioParam(this, SendDetuneToStream, 0.0f))
+  , mPlaybackRate(new AudioParam(this, SendPlaybackRateToStream, 1.0f, "playbackRate"))
+  , mDetune(new AudioParam(this, SendDetuneToStream, 0.0f, "detune"))
   , mLoop(false)
   , mStartCalled(false)
   , mStopped(false)
 {
   AudioBufferSourceNodeEngine* engine = new AudioBufferSourceNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::SOURCE_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*>(mStream.get()));
   mStream->AddMainThreadListener(this);
--- a/dom/media/webaudio/AudioParam.cpp
+++ b/dom/media/webaudio/AudioParam.cpp
@@ -40,21 +40,23 @@ AudioParam::Release()
   NS_IMPL_CC_NATIVE_RELEASE_BODY(AudioParam)
 }
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioParam, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioParam, Release)
 
 AudioParam::AudioParam(AudioNode* aNode,
                        AudioParam::CallbackType aCallback,
-                       float aDefaultValue)
+                       float aDefaultValue,
+                       const char* aName)
   : AudioParamTimeline(aDefaultValue)
   , mNode(aNode)
   , mCallback(aCallback)
   , mDefaultValue(aDefaultValue)
+  , mName(aName)
 {
 }
 
 AudioParam::~AudioParam()
 {
   MOZ_ASSERT(mInputNodes.IsEmpty());
 }
 
--- a/dom/media/webaudio/AudioParam.h
+++ b/dom/media/webaudio/AudioParam.h
@@ -25,17 +25,18 @@ class AudioParam final : public nsWrappe
 {
   virtual ~AudioParam();
 
 public:
   typedef void (*CallbackType)(AudioNode*);
 
   AudioParam(AudioNode* aNode,
              CallbackType aCallback,
-             float aDefaultValue);
+             float aDefaultValue,
+             const char* aName);
 
   NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
   NS_IMETHOD_(MozExternalRefCountType) Release(void);
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioParam)
 
   AudioContext* GetParentObject() const
   {
     return mNode->Context();
@@ -116,16 +117,26 @@ public:
     if (!WebAudioUtils::IsTimeValid(aStartTime)) {
       aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
       return;
     }
     AudioParamTimeline::CancelScheduledValues(DOMTimeToStreamTime(aStartTime));
     mCallback(mNode);
   }
 
+  uint32_t ParentNodeId()
+  {
+    return mNode->Id();
+  }
+
+  void GetName(nsAString& aName)
+  {
+    aName.AssignASCII(mName);
+  }
+
   float DefaultValue() const
   {
     return mDefaultValue;
   }
 
   AudioNode* Node() const
   {
     return mNode;
@@ -178,16 +189,17 @@ protected:
 
 private:
   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;
 };
 
 }
 }
 
 #endif
--- a/dom/media/webaudio/BiquadFilterNode.cpp
+++ b/dom/media/webaudio/BiquadFilterNode.cpp
@@ -239,20 +239,20 @@ private:
 };
 
 BiquadFilterNode::BiquadFilterNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
   , mType(BiquadFilterType::Lowpass)
-  , mFrequency(new AudioParam(this, SendFrequencyToStream, 350.f))
-  , mDetune(new AudioParam(this, SendDetuneToStream, 0.f))
-  , mQ(new AudioParam(this, SendQToStream, 1.f))
-  , mGain(new AudioParam(this, SendGainToStream, 0.f))
+  , 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"))
 {
   BiquadFilterNodeEngine* engine = new BiquadFilterNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
 }
 
 BiquadFilterNode::~BiquadFilterNode()
 {
--- a/dom/media/webaudio/DelayNode.cpp
+++ b/dom/media/webaudio/DelayNode.cpp
@@ -185,17 +185,17 @@ public:
   int32_t mLeftOverData;
 };
 
 DelayNode::DelayNode(AudioContext* aContext, double aMaxDelay)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
-  , mDelay(new AudioParam(this, SendDelayToStream, 0.0f))
+  , mDelay(new AudioParam(this, SendDelayToStream, 0.0f, "delayTime"))
 {
   DelayNodeEngine* engine =
     new DelayNodeEngine(this, aContext->Destination(),
                         aContext->SampleRate() * aMaxDelay);
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
 }
 
--- a/dom/media/webaudio/DynamicsCompressorNode.cpp
+++ b/dom/media/webaudio/DynamicsCompressorNode.cpp
@@ -196,22 +196,22 @@ private:
   nsAutoPtr<DynamicsCompressor> mCompressor;
 };
 
 DynamicsCompressorNode::DynamicsCompressorNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Explicit,
               ChannelInterpretation::Speakers)
-  , mThreshold(new AudioParam(this, SendThresholdToStream, -24.f))
-  , mKnee(new AudioParam(this, SendKneeToStream, 30.f))
-  , mRatio(new AudioParam(this, SendRatioToStream, 12.f))
+  , mThreshold(new AudioParam(this, SendThresholdToStream, -24.f, "threshold"))
+  , mKnee(new AudioParam(this, SendKneeToStream, 30.f, "knee"))
+  , mRatio(new AudioParam(this, SendRatioToStream, 12.f, "ratio"))
   , mReduction(0)
-  , mAttack(new AudioParam(this, SendAttackToStream, 0.003f))
-  , mRelease(new AudioParam(this, SendReleaseToStream, 0.25f))
+  , mAttack(new AudioParam(this, SendAttackToStream, 0.003f, "attack"))
+  , mRelease(new AudioParam(this, SendReleaseToStream, 0.25f, "release"))
 {
   DynamicsCompressorNodeEngine* engine = new DynamicsCompressorNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
 }
 
 DynamicsCompressorNode::~DynamicsCompressorNode()
 {
--- a/dom/media/webaudio/GainNode.cpp
+++ b/dom/media/webaudio/GainNode.cpp
@@ -120,17 +120,17 @@ public:
   AudioParamTimeline mGain;
 };
 
 GainNode::GainNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
-  , mGain(new AudioParam(this, SendGainToStream, 1.0f))
+  , mGain(new AudioParam(this, SendGainToStream, 1.0f, "gain"))
 {
   GainNodeEngine* engine = new GainNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
 }
 
 GainNode::~GainNode()
 {
--- a/dom/media/webaudio/OscillatorNode.cpp
+++ b/dom/media/webaudio/OscillatorNode.cpp
@@ -376,18 +376,18 @@ public:
 };
 
 OscillatorNode::OscillatorNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
   , mType(OscillatorType::Sine)
-  , mFrequency(new AudioParam(this, SendFrequencyToStream, 440.0f))
-  , mDetune(new AudioParam(this, SendDetuneToStream, 0.0f))
+  , mFrequency(new AudioParam(this, SendFrequencyToStream, 440.0f, "frequency"))
+  , mDetune(new AudioParam(this, SendDetuneToStream, 0.0f, "detune"))
   , mStartCalled(false)
   , mStopped(false)
 {
   OscillatorNodeEngine* engine = new OscillatorNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::SOURCE_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
   mStream->AddMainThreadListener(this);
 }
--- a/dom/media/webaudio/StereoPannerNode.cpp
+++ b/dom/media/webaudio/StereoPannerNode.cpp
@@ -171,17 +171,17 @@ public:
   AudioParamTimeline mPan;
 };
 
 StereoPannerNode::StereoPannerNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Clamped_max,
               ChannelInterpretation::Speakers)
-  , mPan(new AudioParam(this, SendPanToStream, 0.f))
+  , mPan(new AudioParam(this, SendPanToStream, 0.f, "pan"))
 {
   StereoPannerNodeEngine* engine = new StereoPannerNodeEngine(this, aContext->Destination());
   mStream = aContext->Graph()->CreateAudioNodeStream(engine,
                                                      MediaStreamGraph::INTERNAL_STREAM);
   engine->SetSourceStream(static_cast<AudioNodeStream*>(mStream.get()));
 }
 
 StereoPannerNode::~StereoPannerNode()
--- a/dom/media/webaudio/test/chrome.ini
+++ b/dom/media/webaudio/test/chrome.ini
@@ -1,4 +1,5 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g'
 
 [test_AudioNodeDevtoolsAPI.html]
+[test_AudioParamDevtoolsAPI.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_AudioParamDevtoolsAPI.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test the devtool AudioParam API</title>
+  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+  Components.utils.import('resource://gre/modules/Services.jsm');
+
+  function checkIdAndName(node, name) {
+    is(node.id, node[name].parentNodeId, "The parent id should be correct");
+    is(node[name].name, name, "The name of the AudioParam should be correct.");
+  }
+
+  var ac = new AudioContext(),
+      gain = ac.createGain(),
+      osc = ac.createOscillator(),
+      del = ac.createDelay(),
+      source = ac.createBufferSource(),
+      stereoPanner = ac.createStereoPanner(),
+      comp = ac.createDynamicsCompressor(),
+      biquad = ac.createBiquadFilter();
+
+  checkIdAndName(gain, "gain");
+  checkIdAndName(osc, "frequency");
+  checkIdAndName(osc, "detune");
+  checkIdAndName(del, "delayTime");
+  checkIdAndName(source, "playbackRate");
+  checkIdAndName(source, "detune");
+  checkIdAndName(stereoPanner, "pan");
+  checkIdAndName(comp, "threshold");
+  checkIdAndName(comp, "knee");
+  checkIdAndName(comp, "ratio");
+  checkIdAndName(comp, "attack");
+  checkIdAndName(comp, "release");
+  checkIdAndName(biquad, "frequency");
+  checkIdAndName(biquad, "detune");
+  checkIdAndName(biquad, "Q");
+  checkIdAndName(biquad, "gain");
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/AudioParam.webidl
+++ b/dom/webidl/AudioParam.webidl
@@ -32,8 +32,18 @@ interface AudioParam {
     [Throws]
     void setValueCurveAtTime(Float32Array values, double startTime, double duration);
 
     // Cancels all scheduled parameter changes with times greater than or equal to startTime. 
     [Throws]
     void cancelScheduledValues(double startTime);
 
 };
+
+// Mozilla extension
+partial interface AudioParam {
+  // The ID of the AudioNode this AudioParam belongs to.
+  [ChromeOnly]
+  readonly attribute unsigned long parentNodeId;
+  // The name of the AudioParam
+  [ChromeOnly]
+  readonly attribute DOMString name;
+};