Bug 1309516 part 7 - modify the seek operation;r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Fri, 14 Oct 2016 20:27:06 +0800
changeset 428006 2ed9421e15fdd10f45bdd7b8cb7361e9ede1f4cc
parent 428005 123d5075947d2e5912f860b243cf55c838b4f393
child 534632 aa76248eba0b6b3f4a08a68c9c778aa822a5c98e
push id33202
push userbmo:kaku@mozilla.com
push dateFri, 21 Oct 2016 11:11:30 +0000
reviewersjwwang
bugs1309516
milestone52.0a1
Bug 1309516 part 7 - modify the seek operation;r?jwwang MozReview-Commit-ID: EVKwqoSPcMO
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -885,40 +885,29 @@ private:
     }
 
     mMaster->DecodeError(aValue.mError);
   }
 
   void SeekCompleted()
   {
     int64_t seekTime = mSeekTask->GetSeekTarget().GetTime().ToMicroseconds();
-    int64_t newCurrentTime = seekTime;
-
-    // Setup timestamp state.
+    int64_t newCurrentTime;
+
     RefPtr<MediaData> video = mMaster->VideoQueue().PeekFront();
-    if (seekTime == mMaster->Duration().ToMicroseconds()) {
+    if (mSeekTask->GetSeekTarget().IsAccurate()) {
       newCurrentTime = seekTime;
-    } else if (mMaster->HasAudio()) {
+    } else {
       RefPtr<MediaData> audio = mMaster->AudioQueue().PeekFront();
-      // Though we adjust the newCurrentTime in audio-based, and supplemented
-      // by video. For better UX, should NOT bind the slide position to
-      // the first audio data timestamp directly.
-      // While seeking to a position where there's only either audio or video, or
-      // seeking to a position lies before audio or video, we need to check if
-      // seekTime is bounded in suitable duration. See Bug 1112438.
-      int64_t audioStart = audio ? audio->mTime : seekTime;
-      // We only pin the seek time to the video start time if the video frame
-      // contains the seek time.
-      if (video && video->mTime <= seekTime && video->GetEndTime() > seekTime) {
-        newCurrentTime = std::min(audioStart, video->mTime);
-      } else {
-        newCurrentTime = audioStart;
+      const int64_t audioStart = audio ? audio->mTime : INT64_MAX;
+      const int64_t videoStart = video ? video->mTime : INT64_MAX;
+      newCurrentTime = std::min(audioStart, videoStart);
+      if (newCurrentTime == INT64_MAX) {
+        newCurrentTime = seekTime;
       }
-    } else {
-      newCurrentTime = video ? video->mTime : seekTime;
     }
 
     // Change state to DECODING or COMPLETED now.
     bool isLiveStream = Resource()->IsLiveStream();
     State nextState;
     if (newCurrentTime == mMaster->Duration().ToMicroseconds() && !isLiveStream) {
       // Seeked to end of media, move to COMPLETED state. Note we don't do
       // this when playing a live stream, since the end of media will advance
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1664,26 +1664,18 @@ MediaFormatReader::Seek(SeekTarget aTarg
   return p;
 }
 
 void
 MediaFormatReader::SetSeekTarget(const SeekTarget& aTarget)
 {
   MOZ_ASSERT(OnTaskQueue());
 
-  SeekTarget target = aTarget;
-
-  // Transform the seek target time to the demuxer timeline.
-  if (!ForceZeroStartTime()) {
-    target.SetTime(aTarget.GetTime() - TimeUnit::FromMicroseconds(StartTime())
-                   + mInfo.mStartTime);
-  }
-
-  mOriginalSeekTarget = target;
-  mFallbackSeekTime = mPendingSeekTime = Some(target.GetTime());
+  mOriginalSeekTarget = aTarget;
+  mFallbackSeekTime = mPendingSeekTime = Some(aTarget.GetTime());
 }
 
 void
 MediaFormatReader::ScheduleSeek()
 {
   if (mSeekScheduled) {
     return;
   }