Bug 1353607. P2 - let GetDecodedAudioDuration() return a TimeUnit. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Mar 2017 16:54:39 +0800
changeset 557649 9caf26301417702174bcc87caebf96d66843ff54
parent 557648 44b7f06e17c5c261741a9345c67e6e58b4955cf4
child 557650 0e0edc3033ba32806080b23b2ad605dd0b9ad348
push id52775
push userjwwang@mozilla.com
push dateFri, 07 Apr 2017 03:28:07 +0000
bugs1353607
milestone55.0a1
Bug 1353607. P2 - let GetDecodedAudioDuration() return a TimeUnit. MozReview-Commit-ID: 5pLyACshP3e
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -849,17 +849,17 @@ private:
   uint32_t VideoPrerollFrames() const
   {
     return mMaster->GetAmpleVideoFrames() / 2;
   }
 
   bool DonePrerollingAudio()
   {
     return !mMaster->IsAudioDecoding()
-           || mMaster->GetDecodedAudioDuration()
+           || mMaster->GetDecodedAudioDuration().ToMicroseconds()
               >= AudioPrerollThreshold().ToMicroseconds() * mMaster->mPlaybackRate;
   }
 
   bool DonePrerollingVideo()
   {
     return !mMaster->IsVideoDecoding()
            || static_cast<uint32_t>(mMaster->VideoQueue().GetSize())
               >= VideoPrerollFrames() * mMaster->mPlaybackRate + 1;
@@ -2315,17 +2315,17 @@ DecodingState::NeedToSkipToNextKeyframe(
   // we won't start keyframe skipping, as we'll be pausing playback to buffer
   // soon anyway and we'll want to be able to display frames immediately
   // after buffering finishes. We ignore the low audio calculations for
   // readers that are async, as since their audio decode runs on a different
   // task queue it should never run low and skipping won't help their decode.
   bool isLowOnDecodedAudio =
     !Reader()->IsAsync()
     && mMaster->IsAudioDecoding()
-    && (mMaster->GetDecodedAudioDuration()
+    && (mMaster->GetDecodedAudioDuration().ToMicroseconds()
         < mMaster->mLowAudioThreshold.ToMicroseconds() * mMaster->mPlaybackRate);
   bool isLowOnDecodedVideo =
     (mMaster->GetClock().ToMicroseconds() - mMaster->mDecodedVideoEndTime)
     * mMaster->mPlaybackRate
     > LOW_VIDEO_THRESHOLD.ToMicroseconds();
   bool lowBuffered = mMaster->HasLowBufferedData();
 
   if ((isLowOnDecodedAudio || isLowOnDecodedVideo) && !lowBuffered) {
@@ -2752,38 +2752,39 @@ MediaDecoderStateMachine::CreateMediaSin
 
   RefPtr<media::MediaSink> mediaSink =
     new VideoSink(mTaskQueue, audioSink, mVideoQueue,
                   mVideoFrameContainer, *mFrameStats,
                   sVideoQueueSendToCompositorSize);
   return mediaSink.forget();
 }
 
-int64_t
+TimeUnit
 MediaDecoderStateMachine::GetDecodedAudioDuration()
 {
   MOZ_ASSERT(OnTaskQueue());
   if (mMediaSink->IsStarted()) {
     // mDecodedAudioEndTime might be smaller than GetClock() when there is
     // overlap between 2 adjacent audio samples or when we are playing
     // a chained ogg file.
-    return std::max<int64_t>(
+    auto t = std::max<int64_t>(
       mDecodedAudioEndTime - GetClock().ToMicroseconds(), 0);
+    return TimeUnit::FromMicroseconds(t);
   }
   // MediaSink not started. All audio samples are in the queue.
-  return AudioQueue().Duration();
+  return TimeUnit::FromMicroseconds(AudioQueue().Duration());
 }
 
 bool
 MediaDecoderStateMachine::HaveEnoughDecodedAudio()
 {
   MOZ_ASSERT(OnTaskQueue());
   auto ampleAudioUSecs = mAmpleAudioThreshold.ToMicroseconds() * mPlaybackRate;
   return AudioQueue().GetSize() > 0
-         && GetDecodedAudioDuration() >= ampleAudioUSecs;
+         && GetDecodedAudioDuration().ToMicroseconds() >= ampleAudioUSecs;
 }
 
 bool MediaDecoderStateMachine::HaveEnoughDecodedVideo()
 {
   MOZ_ASSERT(OnTaskQueue());
   return VideoQueue().GetSize() >= GetAmpleVideoFrames() * mPlaybackRate + 1;
 }
 
@@ -3302,17 +3303,17 @@ MediaDecoderStateMachine::StartMediaSink
   }
 }
 
 bool
 MediaDecoderStateMachine::HasLowDecodedAudio()
 {
   MOZ_ASSERT(OnTaskQueue());
   return IsAudioDecoding()
-         && GetDecodedAudioDuration()
+         && GetDecodedAudioDuration().ToMicroseconds()
             < EXHAUSTED_DATA_MARGIN_USECS * mPlaybackRate;
 }
 
 bool
 MediaDecoderStateMachine::HasLowDecodedVideo()
 {
   MOZ_ASSERT(OnTaskQueue());
   return IsVideoDecoding()
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -454,17 +454,17 @@ protected:
 
   // Returns an upper bound on the number of microseconds of audio that is
   // decoded and playable. This is the sum of the number of usecs of audio which
   // is decoded and in the reader's audio queue, and the usecs of unplayed audio
   // which has been pushed to the audio hardware for playback. Note that after
   // calling this, the audio hardware may play some of the audio pushed to
   // hardware, so this can only be used as a upper bound. The decoder monitor
   // must be held when calling this. Called on the decode thread.
-  int64_t GetDecodedAudioDuration();
+  media::TimeUnit GetDecodedAudioDuration();
 
   void FinishDecodeFirstFrame();
 
   // Performs one "cycle" of the state machine.
   void RunStateMachine();
 
   bool IsStateMachineScheduled() const;