Bug 892492 - Fix automation on AudioBufferSourceNode.playbackRate. r=ehsan
authorPaul Adenot <paul@paul.cx>
Fri, 12 Jul 2013 11:23:21 +0200
changeset 138282 216b74874ef03d10ae23b763501b126bc73a2b1d
parent 138281 c8a145206e8d4c6b7dc0d2796babf4af9fb45d33
child 138283 4056151eb62b5947800f464283768a7ed9d8771b
push id30915
push userpaul@paul.cx
push dateFri, 12 Jul 2013 09:23:37 +0000
treeherdermozilla-inbound@216b74874ef0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs892492
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 892492 - Fix automation on AudioBufferSourceNode.playbackRate. r=ehsan
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) {
@@ -420,16 +425,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,
@@ -439,19 +445,19 @@ AudioBufferSourceNode::AudioBufferSource
   , mOffset(0.0)
   , mDuration(std::numeric_limits<double>::min())
   , mPlaybackRate(new AudioParam(MOZ_THIS_IN_INITIALIZER_LIST(),
                   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)
 {