Bug 1322799 part 9 - move AccurateSeekTask::CalculateNewCurrentTime(); r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Fri, 09 Dec 2016 13:48:02 -1000
changeset 449371 c9afe9aa19f2448af7045a1c0c27424e7e085050
parent 449370 180a3c47a5345c18b28ad57edc904fba502acee3
child 449372 00bcb9795444ee173abf67edcd9ca76be1ffb986
push id38552
push userbmo:kaku@mozilla.com
push dateWed, 14 Dec 2016 02:51:42 +0000
reviewersjwwang
bugs1322799
milestone53.0a1
Bug 1322799 part 9 - move AccurateSeekTask::CalculateNewCurrentTime(); r?jwwang MozReview-Commit-ID: 4HFAPzAfANl
dom/media/AccurateSeekTask.cpp
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/AccurateSeekTask.cpp
+++ b/dom/media/AccurateSeekTask.cpp
@@ -58,44 +58,16 @@ AccurateSeekTask::Discard()
 
   mIsDiscarded = true;
 }
 
 int64_t
 AccurateSeekTask::CalculateNewCurrentTime() const
 {
   AssertOwnerThread();
-
-  const int64_t seekTime = mTarget.GetTime().ToMicroseconds();
-
-  // For the accurate seek, we always set the newCurrentTime = seekTime so that
-  // the updated HTMLMediaElement.currentTime will always be the seek target;
-  // we rely on the MediaSink to handles the gap between the newCurrentTime and
-  // the real decoded samples' start time.
-  if (mTarget.IsAccurate()) {
-    return seekTime;
-  }
-
-  // For the fast seek, we update the newCurrentTime with the decoded audio and
-  // video samples, set it to be the one which is closet to the seekTime.
-  if (mTarget.IsFast()) {
-
-    // A situation that both audio and video approaches the end.
-    if (!mSeekedAudioData && !mSeekedVideoData) {
-      return seekTime;
-    }
-
-    const int64_t audioStart = mSeekedAudioData ? mSeekedAudioData->mTime : INT64_MAX;
-    const int64_t videoStart = mSeekedVideoData ? mSeekedVideoData->mTime : INT64_MAX;
-    const int64_t audioGap = std::abs(audioStart - seekTime);
-    const int64_t videoGap = std::abs(videoStart - seekTime);
-    return audioGap <= videoGap ? audioStart : videoStart;
-  }
-
-  MOZ_ASSERT(false, "AccurateSeekTask doesn't handle other seek types.");
   return 0;
 }
 
 void
 AccurateSeekTask::HandleAudioDecoded(MediaData* aAudio)
 {
 }
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1074,17 +1074,44 @@ private:
              },
              [this] (const SeekTaskRejectValue& aValue) {
                OnSeekTaskRejected(aValue);
              }));
   }
 
   int64_t CalculateNewCurrentTime() const override
   {
-    return mSeekTask->CalculateNewCurrentTime();
+    const int64_t seekTime = mTask->mTarget.GetTime().ToMicroseconds();
+
+    // For the accurate seek, we always set the newCurrentTime = seekTime so that
+    // the updated HTMLMediaElement.currentTime will always be the seek target;
+    // we rely on the MediaSink to handles the gap between the newCurrentTime and
+    // the real decoded samples' start time.
+    if (mTask->mTarget.IsAccurate()) {
+      return seekTime;
+    }
+
+    // For the fast seek, we update the newCurrentTime with the decoded audio and
+    // video samples, set it to be the one which is closet to the seekTime.
+    if (mTask->mTarget.IsFast()) {
+
+      // A situation that both audio and video approaches the end.
+      if (!mTask->mSeekedAudioData && !mTask->mSeekedVideoData) {
+        return seekTime;
+      }
+
+      const int64_t audioStart = mTask->mSeekedAudioData ? mTask->mSeekedAudioData->mTime : INT64_MAX;
+      const int64_t videoStart = mTask->mSeekedVideoData ? mTask->mSeekedVideoData->mTime : INT64_MAX;
+      const int64_t audioGap = std::abs(audioStart - seekTime);
+      const int64_t videoGap = std::abs(videoStart - seekTime);
+      return audioGap <= videoGap ? audioStart : videoStart;
+    }
+
+    MOZ_ASSERT(false, "AccurateSeekTask doesn't handle other seek types.");
+    return 0;
   }
 
   void OnSeekResolved(media::TimeUnit) {
     mSeekRequest.Complete();
 
     // We must decode the first samples of active streams, so we can determine
     // the new stream time. So dispatch tasks to do that.
     if (!mTask->mDoneVideoSeeking) {