Bug 1314884. Part 1 - move the calculation of seek target into DormantState::Enter() so we don't need to pass a SeekJob to the function. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 03 Nov 2016 14:54:40 +0800
changeset 434659 4ced360b44ec42404fa2d7d8da3952372affef38
parent 434658 1105d2ca9b647504fac3f364c9631fab49dfae44
child 434660 702fdef0b3da6f1a01f26397f4e6364f495966db
push id34784
push userjwwang@mozilla.com
push dateMon, 07 Nov 2016 03:12:00 +0000
bugs1314884
milestone52.0a1
Bug 1314884. Part 1 - move the calculation of seek target into DormantState::Enter() so we don't need to pass a SeekJob to the function. MozReview-Commit-ID: FyFp509dxwl
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -398,22 +398,32 @@ private:
  *   SEEKING if any seek request.
  */
 class MediaDecoderStateMachine::DormantState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit DormantState(Master* aPtr) : StateObject(aPtr) {}
 
-  void Enter(SeekJob aPendingSeek)
+  void Enter()
   {
-    mPendingSeek = Move(aPendingSeek);
     if (mMaster->IsPlaying()) {
       mMaster->StopPlayback();
     }
+
+    // Calculate the position to seek to when exiting dormant.
+    auto t = mMaster->mMediaSink->IsStarted()
+      ? mMaster->GetClock()
+      : mMaster->GetMediaTime();
+    mPendingSeek.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> x = mPendingSeek.mPromise.Ensure(__func__);
+
     mMaster->Reset();
     mMaster->mReader->ReleaseResources();
   }
 
   void Exit() override
   {
     // mPendingSeek is either moved when exiting dormant or
     // should be rejected here before transition to SHUTDOWN.
@@ -681,26 +691,17 @@ private:
       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));
+    SetState<DormantState>();
   }
 
   void StartDormantTimer()
   {
     auto timeout = MediaPrefs::DormantOnPauseTimeout();
     if (timeout < 0) {
       // Disabled when timeout is negative.
       return;