Bug 1350819 - Replace use of int64_t for microseconds by TimeUnit in VideoSink. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 27 Mar 2017 14:35:42 +0800
changeset 552826 248d774f20b10d97154f81e27b7efd1eddd581e2
parent 552158 3a30ff4ca2fd0f1d772523c9cf095a12697c4f8d
child 552827 8d504462c497bbb487a2237dcb73877796100197
push id51479
push userjwwang@mozilla.com
push dateWed, 29 Mar 2017 03:02:02 +0000
bugs1350819
milestone55.0a1
Bug 1350819 - Replace use of int64_t for microseconds by TimeUnit in VideoSink. MozReview-Commit-ID: DAx0p7x2RLx
dom/media/mediasink/VideoSink.cpp
dom/media/mediasink/VideoSink.h
--- a/dom/media/mediasink/VideoSink.cpp
+++ b/dom/media/mediasink/VideoSink.cpp
@@ -36,17 +36,16 @@ VideoSink::VideoSink(AbstractThread* aTh
                      FrameStatistics& aFrameStats,
                      uint32_t aVQueueSentToCompositerSize)
   : mOwnerThread(aThread)
   , mAudioSink(aAudioSink)
   , mVideoQueue(aVideoQueue)
   , mContainer(aContainer)
   , mProducerID(ImageContainer::AllocateProducerID())
   , mFrameStats(aFrameStats)
-  , mVideoFrameEndTime(0)
   , mHasVideo(false)
   , mUpdateScheduler(aThread)
   , mVideoQueueSendToCompositorSize(aVQueueSentToCompositerSize)
   , mMinVideoQueueSize(MediaPrefs::RuinAvSync() ? 1 : 0)
 {
   MOZ_ASSERT(mAudioSink, "AudioSink should exist.");
 }
 
@@ -86,28 +85,27 @@ VideoSink::OnEnded(TrackType aType)
 
 int64_t
 VideoSink::GetEndTime(TrackType aType) const
 {
   AssertOwnerThread();
   MOZ_ASSERT(mAudioSink->IsStarted(), "Must be called after playback starts.");
 
   if (aType == TrackInfo::kVideoTrack) {
-    return mVideoFrameEndTime;
+    return mVideoFrameEndTime.ToMicroseconds();
   } else if (aType == TrackInfo::kAudioTrack) {
     return mAudioSink->GetEndTime(aType);
   }
   return 0;
 }
 
 int64_t
 VideoSink::GetPosition(TimeStamp* aTimeStamp) const
 {
   AssertOwnerThread();
-
   return mAudioSink->GetPosition(aTimeStamp);
 }
 
 bool
 VideoSink::HasUnplayedFrames(TrackType aType) const
 {
   AssertOwnerThread();
   MOZ_ASSERT(aType == TrackInfo::kAudioTrack, "Not implemented for non audio tracks.");
@@ -220,17 +218,17 @@ VideoSink::Stop()
 
   mUpdateScheduler.Reset();
   if (mHasVideo) {
     DisconnectListener();
     mVideoSinkEndRequest.DisconnectIfExists();
     mEndPromiseHolder.ResolveIfExists(true, __func__);
     mEndPromise = nullptr;
   }
-  mVideoFrameEndTime = 0;
+  mVideoFrameEndTime = TimeUnit::Zero();
 }
 
 bool
 VideoSink::IsStarted() const
 {
   AssertOwnerThread();
 
   return mAudioSink->IsStarted();
@@ -429,18 +427,18 @@ VideoSink::UpdateRenderedVideoFrames()
                   frame->mTime, clockTime);
     }
   }
 
   // The presentation end time of the last video frame displayed is either
   // the end time of the current frame, or if we dropped all frames in the
   // queue, the end time of the last frame we removed from the queue.
   RefPtr<VideoData> currentFrame = VideoQueue().PeekFront();
-  mVideoFrameEndTime = std::max(mVideoFrameEndTime,
-    currentFrame ? currentFrame->GetEndTime() : lastFrameEndTime);
+  mVideoFrameEndTime = std::max(mVideoFrameEndTime, TimeUnit::FromMicroseconds(
+    currentFrame ? currentFrame->GetEndTime() : lastFrameEndTime));
 
   MaybeResolveEndPromise();
 
   RenderVideoFrames(mVideoQueueSendToCompositorSize, clockTime, nowTime);
 
   // Get the timestamp of the next frame. Schedule the next update at
   // the start time of the next frame. If we don't have a next frame,
   // we will run render loops again upon incoming frames.
@@ -479,15 +477,15 @@ nsCString
 VideoSink::GetDebugInfo()
 {
   AssertOwnerThread();
   return nsPrintfCString(
     "VideoSink Status: IsStarted=%d IsPlaying=%d VideoQueue(finished=%d "
     "size=%" PRIuSIZE ") mVideoFrameEndTime=%" PRId64 " mHasVideo=%d "
     "mVideoSinkEndRequest.Exists()=%d mEndPromiseHolder.IsEmpty()=%d\n",
     IsStarted(), IsPlaying(), VideoQueue().IsFinished(),
-    VideoQueue().GetSize(), mVideoFrameEndTime, mHasVideo,
+    VideoQueue().GetSize(), mVideoFrameEndTime.ToMicroseconds(), mHasVideo,
     mVideoSinkEndRequest.Exists(), mEndPromiseHolder.IsEmpty())
     + mAudioSink->GetDebugInfo();
 }
 
 } // namespace media
 } // namespace mozilla
--- a/dom/media/mediasink/VideoSink.h
+++ b/dom/media/mediasink/VideoSink.h
@@ -121,19 +121,18 @@ private:
 
   // Used to notify MediaDecoder's frame statistics
   FrameStatistics& mFrameStats;
 
   RefPtr<GenericPromise> mEndPromise;
   MozPromiseHolder<GenericPromise> mEndPromiseHolder;
   MozPromiseRequestHolder<GenericPromise> mVideoSinkEndRequest;
 
-  // The presentation end time of the last video frame which has been displayed
-  // in microseconds.
-  int64_t mVideoFrameEndTime;
+  // The presentation end time of the last video frame which has been displayed.
+  TimeUnit mVideoFrameEndTime;
 
   // Event listeners for VideoQueue
   MediaEventListener mPushListener;
   MediaEventListener mFinishListener;
 
   // True if this sink is going to handle video track.
   bool mHasVideo;