Bug 1126465 - Factor out the seeking phases into helper methods. r=mattwoodrow
authorBobby Holley <bobbyholley@gmail.com>
Thu, 29 Jan 2015 22:11:11 -0800
changeset 253880 2f9a8ce6ad9e29f46a12989377fffc770b4f88cc
parent 253879 784042074702a9f32538ed8f37244d832986c8f8
child 253881 07ae1aee71213494969bbd75cc683cb6726efd5c
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1126465
milestone38.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 1126465 - Factor out the seeking phases into helper methods. r=mattwoodrow
dom/media/mediasource/MediaSourceReader.cpp
dom/media/mediasource/MediaSourceReader.h
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -745,27 +745,33 @@ void
 MediaSourceReader::OnVideoSeekCompleted(int64_t aTime)
 {
   MOZ_ASSERT(mVideoIsSeeking);
   MOZ_ASSERT(!mAudioIsSeeking);
   mVideoIsSeeking = false;
 
   if (mAudioTrack) {
     mPendingSeekTime = aTime;
+    DoAudioSeek();
+  } else {
+    mPendingSeekTime = -1;
+    mSeekPromise.Resolve(aTime, __func__);
+  }
+}
+
+void
+MediaSourceReader::DoAudioSeek()
+{
     mAudioIsSeeking = true;
     SwitchAudioReader(mPendingSeekTime);
     mAudioReader->Seek(mPendingSeekTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::OnAudioSeekCompleted,
                        &MediaSourceReader::OnSeekFailed);
-    MSE_DEBUG("MediaSourceReader(%p)::Seek audio reader=%p", this, mAudioReader.get());
-    return;
-  }
-  mPendingSeekTime = -1;
-  mSeekPromise.Resolve(aTime, __func__);
+    MSE_DEBUG("MediaSourceReader(%p)::DoAudioSeek reader=%p", this, mAudioReader.get());
 }
 
 void
 MediaSourceReader::OnAudioSeekCompleted(int64_t aTime)
 {
   mPendingSeekTime = aTime;
   MOZ_ASSERT(mAudioIsSeeking);
   MOZ_ASSERT(!mVideoIsSeeking);
@@ -812,28 +818,36 @@ MediaSourceReader::AttemptSeek()
     mTrackBuffers[i]->ResetDecode();
   }
 
   // Decoding discontinuity upon seek, reset last times to seek target.
   mLastAudioTime = mPendingSeekTime;
   mLastVideoTime = mPendingSeekTime;
 
   if (mVideoTrack) {
-    mVideoIsSeeking = true;
-    SwitchVideoReader(mPendingSeekTime);
-    mVideoReader->Seek(mPendingSeekTime, 0)
-                ->Then(GetTaskQueue(), __func__, this,
-                       &MediaSourceReader::OnVideoSeekCompleted,
-                       &MediaSourceReader::OnSeekFailed);
-    MSE_DEBUG("MediaSourceReader(%p)::Seek video reader=%p", this, mVideoReader.get());
+    DoVideoSeek();
+  } else if (mAudioTrack) {
+    DoAudioSeek();
   } else {
-    OnVideoSeekCompleted(mPendingSeekTime);
+    MOZ_CRASH();
   }
 }
 
+void
+MediaSourceReader::DoVideoSeek()
+{
+  mVideoIsSeeking = true;
+  SwitchVideoReader(mPendingSeekTime);
+  mVideoReader->Seek(mPendingSeekTime, 0)
+              ->Then(GetTaskQueue(), __func__, this,
+                     &MediaSourceReader::OnVideoSeekCompleted,
+                     &MediaSourceReader::OnSeekFailed);
+  MSE_DEBUG("MediaSourceReader(%p)::DoVideoSeek reader=%p", this, mVideoReader.get());
+}
+
 nsresult
 MediaSourceReader::GetBuffered(dom::TimeRanges* aBuffered)
 {
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
   MOZ_ASSERT(aBuffered->Length() == 0);
   if (mTrackBuffers.IsEmpty()) {
     return NS_OK;
   }
--- a/dom/media/mediasource/MediaSourceReader.h
+++ b/dom/media/mediasource/MediaSourceReader.h
@@ -56,16 +56,18 @@ public:
   virtual bool IsDormantNeeded() MOZ_OVERRIDE;
   virtual void ReleaseMediaResources() MOZ_OVERRIDE;
 
   void OnAudioDecoded(AudioData* aSample);
   void OnAudioNotDecoded(NotDecodedReason aReason);
   void OnVideoDecoded(VideoData* aSample);
   void OnVideoNotDecoded(NotDecodedReason aReason);
 
+  void DoVideoSeek();
+  void DoAudioSeek();
   void OnVideoSeekCompleted(int64_t aTime);
   void OnAudioSeekCompleted(int64_t aTime);
   void OnSeekFailed(nsresult aResult);
 
   virtual bool IsWaitForDataSupported() MOZ_OVERRIDE { return true; }
   virtual nsRefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType) MOZ_OVERRIDE;
   void MaybeNotifyHaveData();