Bug 1314524. Part 3 - add DecodingState::EnterDormant(). r=kaku
authorJW Wang <jwwang@mozilla.com>
Fri, 28 Oct 2016 16:05:52 +0800
changeset 351538 16b66da551806a3a7d0b9006d20a665e5297c678
parent 351537 5e7a0cfc6d9c63d17e31666a1876060483a1c1fe
child 351539 a92a74c529f9488f08b58473dcb856610a7aefd3
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1314524
milestone52.0a1
Bug 1314524. Part 3 - add DecodingState::EnterDormant(). r=kaku 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;