Bug 1314524. Part 3 - add DecodingState::EnterDormant(). draft
authorJW Wang <jwwang@mozilla.com>
Fri, 28 Oct 2016 16:05:52 +0800
changeset 433065 522a60f93b7e204907970074fafe0bddc9272ce4
parent 433064 9ae7bbdd5b8c88ebd9fd1e410552a0fe4a0ccc9d
child 433066 732fbc32d217dae870b50710790aaa7ebdab345e
push id34474
push userjwwang@mozilla.com
push dateThu, 03 Nov 2016 03:26:05 +0000
bugs1314524
milestone52.0a1
Bug 1314524. Part 3 - add DecodingState::EnterDormant(). MozReview-Commit-ID: 6YbO61mWqnj
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -725,35 +725,49 @@ private:
         (DonePrerollingAudio() || Reader()->IsWaitingAudioData()) &&
         (DonePrerollingVideo() || Reader()->IsWaitingVideoData())) {
       mIsPrerolling = false;
       // Check if we can start playback.
       mMaster->ScheduleStateMachine();
     }
   }
 
+  void EnterDormant()
+  {
+    auto t = mMaster->mMediaSink->IsStarted()
+      ? mMaster->GetClock()
+      : mMaster->GetMediaTime();
+    SeekJob seekJob;
+    seekJob.mTarget = SeekTarget(t, SeekTarget::Accurate,
+                                 MediaDecoderEventVisibility::Suppressed);
+    // SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
+    // need to create the promise even it is not used at all.
+    RefPtr<MediaDecoder::SeekPromise> unused = seekJob.mPromise.Ensure(__func__);
+    SetState<DormantState>(Move(seekJob));
+  }
+
   void StartDormantTimer()
   {
     auto timeout = MediaPrefs::DormantOnPauseTimeout();
     if (timeout < 0) {
       // Disabled when timeout is negative.
       return;
     } else if (timeout == 0) {
       // Enter dormant immediately without scheduling a timer.
-      HandleDormant(true);
+      EnterDormant();
       return;
     }
 
     TimeStamp target = TimeStamp::Now() +
       TimeDuration::FromMilliseconds(timeout);
 
     mDormantTimer.Ensure(target,
       [this] () {
         mDormantTimer.CompleteRequest();
-        HandleDormant(true);
+        EnterDormant();
       }, [this] () {
         mDormantTimer.CompleteRequest();
       });
   }
 
   // Time at which we started decoding.
   TimeStamp mDecodeStartTime;