Bug 1352319. P12 - let CalculateNewCurrentTime() return a TimeUnit. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Mar 2017 16:44:40 +0800
changeset 554261 72d36673452a10c2ab1a5c2fcf5e339e034ab7f8
parent 554260 a80f845542be140572fa816b5e3903ffea639890
child 622289 4df1cb6da33044370af5b11a831ef4b78988ef2f
push id51883
push userjwwang@mozilla.com
push dateFri, 31 Mar 2017 09:16:07 +0000
bugs1352319
milestone55.0a1
Bug 1352319. P12 - let CalculateNewCurrentTime() return a TimeUnit. MozReview-Commit-ID: 6bQdKvw0VEN
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1006,17 +1006,17 @@ public:
 protected:
   SeekJob mSeekJob;
 
   void SeekCompleted();
 
 private:
   virtual void DoSeek() = 0;
 
-  virtual int64_t CalculateNewCurrentTime() const = 0;
+  virtual TimeUnit CalculateNewCurrentTime() const = 0;
 };
 
 class MediaDecoderStateMachine::AccurateSeekingState
   : public MediaDecoderStateMachine::SeekingState
 {
 public:
   explicit AccurateSeekingState(Master* aPtr) : SeekingState(aPtr)
   {
@@ -1200,19 +1200,19 @@ private:
     } else {
       mMaster->ResetDecode();
       mMaster->StopMediaSink();
     }
 
     DemuxerSeek();
   }
 
-  int64_t CalculateNewCurrentTime() const override
+  TimeUnit CalculateNewCurrentTime() const override
   {
-    const int64_t seekTime = mSeekJob.mTarget->GetTime().ToMicroseconds();
+    const auto seekTime = mSeekJob.mTarget->GetTime();
 
     // 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 (mSeekJob.mTarget->IsAccurate()) {
       return seekTime;
     }
@@ -1225,23 +1225,24 @@ private:
 
       // A situation that both audio and video approaches the end.
       if (!audio && !video) {
         return seekTime;
       }
 
       const int64_t audioStart = audio ? audio->mTime : INT64_MAX;
       const int64_t videoStart = video ? video->mTime : INT64_MAX;
-      const int64_t audioGap = std::abs(audioStart - seekTime);
-      const int64_t videoGap = std::abs(videoStart - seekTime);
-      return audioGap <= videoGap ? audioStart : videoStart;
+      const int64_t audioGap = std::abs(audioStart - seekTime.ToMicroseconds());
+      const int64_t videoGap = std::abs(videoStart - seekTime.ToMicroseconds());
+      return TimeUnit::FromMicroseconds(
+        audioGap <= videoGap ? audioStart : videoStart);
     }
 
     MOZ_ASSERT(false, "AccurateSeekTask doesn't handle other seek types.");
-    return 0;
+    return TimeUnit::Zero();
   }
 
   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.
@@ -1625,21 +1626,21 @@ private:
 
   void HandleVideoWaited(MediaData::Type aType) override
   {
     MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
     MOZ_ASSERT(NeedMoreVideo());
     RequestVideoData();
   }
 
-  int64_t CalculateNewCurrentTime() const override
+  TimeUnit CalculateNewCurrentTime() const override
   {
     // The HTMLMediaElement.currentTime should be updated to the seek target
     // which has been updated to the next frame's time.
-    return mSeekJob.mTarget->GetTime().ToMicroseconds();
+    return mSeekJob.mTarget->GetTime();
   }
 
   void RequestVideoData()
   {
     mMaster->RequestVideoData(false, media::TimeUnit());
   }
 
   bool NeedMoreVideo() const
@@ -2364,20 +2365,20 @@ DecodingState::MaybeStartBuffering()
     SetState<BufferingState>();
   }
 }
 
 void
 MediaDecoderStateMachine::
 SeekingState::SeekCompleted()
 {
-  const int64_t newCurrentTime = CalculateNewCurrentTime();
+  const auto newCurrentTime = CalculateNewCurrentTime();
 
   bool isLiveStream = Resource()->IsLiveStream();
-  if (newCurrentTime == mMaster->Duration().ToMicroseconds() && !isLiveStream) {
+  if (newCurrentTime == mMaster->Duration() && !isLiveStream) {
     // Seeked to end of media. Explicitly finish the queues so DECODING
     // will transition to COMPLETED immediately. Note we don't do
     // this when playing a live stream, since the end of media will advance
     // once we download more data!
     AudioQueue().Finish();
     VideoQueue().Finish();
 
     // We won't start MediaSink when paused. m{Audio,Video}Completed will
@@ -2405,18 +2406,17 @@ SeekingState::SeekCompleted()
     mMaster->FinishDecodeFirstFrame();
   }
 
   // Ensure timestamps are up to date.
   if (!target.IsVideoOnly()) {
     // Don't update playback position for video-only seek.
     // Otherwise we might have |newCurrentTime > mMediaSink->GetPosition()|
     // and fail the assertion in GetClock() since we didn't stop MediaSink.
-    mMaster->UpdatePlaybackPositionInternal(
-      TimeUnit::FromMicroseconds(newCurrentTime));
+    mMaster->UpdatePlaybackPositionInternal(newCurrentTime);
   }
 
   // Dispatch an event so that the UI can change in response to the end of
   // video-only seek
   if (target.IsVideoOnly()) {
     mMaster->mOnPlaybackEvent.Notify(MediaEventType::VideoOnlySeekCompleted);
   }