Bug 892492 - Fix automation on AudioBufferSourceNode.playbackRate. r=ehsan, a=webaudio
authorPaul Adenot <paul@paul.cx>
Fri, 12 Jul 2013 11:23:21 +0200
changeset 143640 7207a85189f18eacbc5fe79b33477c6bc7bf7c07
parent 143639 5e7172fc9aa4bc7131cd8cdf383c253dfd03871f
child 143641 e18d6a0ab17c42e86c3d62036165afdf832c9371
push id4018
push userryanvm@gmail.com
push dateMon, 22 Jul 2013 21:43:09 +0000
treeherdermozilla-aurora@e18d6a0ab17c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, webaudio
bugs892492
milestone24.0a2
Bug 892492 - Fix automation on AudioBufferSourceNode.playbackRate. r=ehsan, a=webaudio
content/media/webaudio/AudioBufferSourceNode.cpp
content/media/webaudio/WebAudioUtils.cpp
--- a/content/media/webaudio/AudioBufferSourceNode.cpp
+++ b/content/media/webaudio/AudioBufferSourceNode.cpp
@@ -65,33 +65,38 @@ public:
 
   ~AudioBufferSourceNodeEngine()
   {
     if (mResampler) {
       speex_resampler_destroy(mResampler);
     }
   }
 
+  void SetSourceStream(AudioNodeStream* aSource)
+  {
+    mSource = aSource;
+  }
+
   virtual void SetTimelineParameter(uint32_t aIndex,
                                     const dom::AudioParamTimeline& aValue,
                                     TrackRate aSampleRate) MOZ_OVERRIDE
   {
     switch (aIndex) {
     case AudioBufferSourceNode::PLAYBACKRATE:
       mPlaybackRateTimeline = aValue;
       // If we have a simple value that is 1.0 (i.e. intrinsic speed), and our
       // input buffer is already at the ideal audio rate, and we have a
       // resampler, we can release it.
       if (mResampler && mPlaybackRateTimeline.HasSimpleValue() &&
           mPlaybackRateTimeline.GetValue() == 1.0 &&
           mBufferSampleRate == aSampleRate) {
         speex_resampler_destroy(mResampler);
         mResampler = nullptr;
       }
-      WebAudioUtils::ConvertAudioParamToTicks(mPlaybackRateTimeline, nullptr, mDestination);
+      WebAudioUtils::ConvertAudioParamToTicks(mPlaybackRateTimeline, mSource, mDestination);
       break;
     default:
       NS_ERROR("Bad AudioBufferSourceNodeEngine TimelineParameter");
     }
   }
   virtual void SetStreamTimeParameter(uint32_t aIndex, TrackTicks aParam)
   {
     switch (aIndex) {
@@ -419,16 +424,17 @@ public:
   int32_t mLoopStart;
   int32_t mLoopEnd;
   int32_t mBufferSampleRate;
   uint32_t mPosition;
   uint32_t mChannels;
   float mPlaybackRate;
   float mDopplerShift;
   AudioNodeStream* mDestination;
+  AudioNodeStream* mSource;
   AudioParamTimeline mPlaybackRateTimeline;
   bool mLoop;
 };
 
 AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
@@ -437,19 +443,19 @@ AudioBufferSourceNode::AudioBufferSource
   , mLoopEnd(0.0)
   , mOffset(0.0)
   , mDuration(std::numeric_limits<double>::min())
   , mPlaybackRate(new AudioParam(this, SendPlaybackRateToStream, 1.0f))
   , mLoop(false)
   , mStartCalled(false)
   , mStopped(false)
 {
-  mStream = aContext->Graph()->CreateAudioNodeStream(
-      new AudioBufferSourceNodeEngine(this, aContext->Destination()),
-      MediaStreamGraph::SOURCE_STREAM);
+  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);
 }
 
 AudioBufferSourceNode::~AudioBufferSourceNode()
 {
   if (Context()) {
     Context()->UnregisterAudioBufferSourceNode(this);
   }
--- a/content/media/webaudio/WebAudioUtils.cpp
+++ b/content/media/webaudio/WebAudioUtils.cpp
@@ -14,25 +14,19 @@ namespace dom {
 struct ConvertTimeToTickHelper
 {
   AudioNodeStream* mSourceStream;
   AudioNodeStream* mDestinationStream;
 
   static int64_t Convert(double aTime, void* aClosure)
   {
     ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
-    if (This->mSourceStream) {
-      MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate());
-      return WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(
-          aTime, This->mSourceStream, This->mDestinationStream);
-    } else {
-      StreamTime streamTime = This->mDestinationStream->GetCurrentPosition();
-      TrackRate sampleRate = This->mDestinationStream->SampleRate();
-      return TimeToTicksRoundUp(sampleRate, streamTime + SecondsToMediaTime(aTime));
-    }
+    MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate());
+    return WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(
+        aTime, This->mSourceStream, This->mDestinationStream);
   }
 };
 
 TrackTicks
 WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(double aTime,
                                                               AudioNodeStream* aSource,
                                                               MediaStream* aDestination)
 {