Bug 1322799 part 6 - move AccurateSeekTask::AdjustFastSeekIfNeeded(); r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Fri, 09 Dec 2016 12:34:44 -1000
changeset 449368 5c354288bb00e7cb9ecfd892ff670a398e5e2404
parent 449367 3b7fd1027253b9ac2eb807136e0f5e76ec897c49
child 449369 3006aa6e219412bb7363b5fa12790fe107ca144a
push id38552
push userbmo:kaku@mozilla.com
push dateWed, 14 Dec 2016 02:51:42 +0000
reviewersjwwang
bugs1322799
milestone53.0a1
Bug 1322799 part 6 - move AccurateSeekTask::AdjustFastSeekIfNeeded(); r?jwwang MozReview-Commit-ID: LwvRNpfbrFI
dom/media/AccurateSeekTask.cpp
dom/media/AccurateSeekTask.h
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/AccurateSeekTask.cpp
+++ b/dom/media/AccurateSeekTask.cpp
@@ -254,26 +254,9 @@ void
 AccurateSeekTask::MaybeFinishSeek()
 {
   AssertOwnerThread();
   if (mDoneAudioSeeking && mDoneVideoSeeking) {
     Resolve(__func__); // Call to MDSM::SeekCompleted();
   }
 }
 
-void
-AccurateSeekTask::AdjustFastSeekIfNeeded(MediaData* aSample)
-{
-  AssertOwnerThread();
-  if (mTarget.IsFast() &&
-      mTarget.GetTime() > mCurrentTimeBeforeSeek &&
-      aSample->mTime < mCurrentTimeBeforeSeek.ToMicroseconds()) {
-    // We are doing a fastSeek, but we ended up *before* the previous
-    // playback position. This is surprising UX, so switch to an accurate
-    // seek and decode to the seek target. This is not conformant to the
-    // spec, fastSeek should always be fast, but until we get the time to
-    // change all Readers to seek to the keyframe after the currentTime
-    // in this case, we'll just decode forward. Bug 1026330.
-    mTarget.SetType(SeekTarget::Accurate);
-  }
-}
-
 } // namespace mozilla
--- a/dom/media/AccurateSeekTask.h
+++ b/dom/media/AccurateSeekTask.h
@@ -44,18 +44,16 @@ public:
   ~AccurateSeekTask();
 
   nsresult DropAudioUpToSeekTarget(MediaData* aSample);
 
   nsresult DropVideoUpToSeekTarget(MediaData* aSample);
 
   void MaybeFinishSeek();
 
-  void AdjustFastSeekIfNeeded(MediaData* aSample);
-
   /*
    * Internal state.
    */
   const media::TimeUnit mCurrentTimeBeforeSeek;
   const uint32_t mAudioRate;  // Audio sample rate.
   bool mDoneAudioSeeking;
   bool mDoneVideoSeeking;
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -905,17 +905,17 @@ public:
     // Video-only seek doesn't reset audio decoder. There might be pending audio
     // requests when AccurateSeekTask::Seek() begins. We will just store the data
     // without checking |mDiscontinuity| or calling DropAudioUpToSeekTarget().
     if (mTask->mTarget.IsVideoOnly()) {
       mTask->mSeekedAudioData = audio.forget();
       return;
     }
 
-    mTask->AdjustFastSeekIfNeeded(audio);
+    AdjustFastSeekIfNeeded(audio);
 
     if (mTask->mTarget.IsFast()) {
       // Non-precise seek; we can stop the seek at the first sample.
       mTask->mSeekedAudioData = audio;
       mTask->mDoneAudioSeeking = true;
     } else {
       nsresult rv = mTask->DropAudioUpToSeekTarget(audio);
       if (NS_FAILED(rv)) {
@@ -938,17 +938,17 @@ public:
     RefPtr<MediaData> video(aVideo);
     MOZ_ASSERT(video);
 
     // The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
     // resolved.
 
     SSAMPLELOG("HandleVideoDecoded [%lld,%lld]", video->mTime, video->GetEndTime());
 
-    mTask->AdjustFastSeekIfNeeded(video);
+    AdjustFastSeekIfNeeded(video);
 
     if (mTask->mTarget.IsFast()) {
       // Non-precise seek. We can stop the seek at the first sample.
       mTask->mSeekedVideoData = video;
       mTask->mDoneVideoSeeking = true;
     } else {
       nsresult rv = mTask->DropVideoUpToSeekTarget(video.get());
       if (NS_FAILED(rv)) {
@@ -1113,16 +1113,31 @@ private:
   void RequestVideoData()
   {
     MOZ_ASSERT(!mTask->mDoneVideoSeeking);
     MOZ_ASSERT(!Reader()->IsRequestingVideoData());
     MOZ_ASSERT(!Reader()->IsWaitingVideoData());
     Reader()->RequestVideoData(false, media::TimeUnit());
   }
 
+  void AdjustFastSeekIfNeeded(MediaData* aSample)
+  {
+    if (mTask->mTarget.IsFast() &&
+        mTask->mTarget.GetTime() > mTask->mCurrentTimeBeforeSeek &&
+        aSample->mTime < mTask->mCurrentTimeBeforeSeek.ToMicroseconds()) {
+      // We are doing a fastSeek, but we ended up *before* the previous
+      // playback position. This is surprising UX, so switch to an accurate
+      // seek and decode to the seek target. This is not conformant to the
+      // spec, fastSeek should always be fast, but until we get the time to
+      // change all Readers to seek to the keyframe after the currentTime
+      // in this case, we'll just decode forward. Bug 1026330.
+      mTask->mTarget.SetType(SeekTarget::Accurate);
+    }
+  }
+
   void OnSeekTaskResolved(const SeekTaskResolveValue& aValue)
   {
     mSeekTaskRequest.Complete();
 
     if (aValue.mSeekedAudioData) {
       mMaster->Push(aValue.mSeekedAudioData);
       mMaster->mDecodedAudioEndTime = std::max(
         aValue.mSeekedAudioData->GetEndTime(), mMaster->mDecodedAudioEndTime);