Bug 1302006. Part 3 - Let SeekingState handle dormant request. r=kikuo
authorJW Wang <jwwang@mozilla.com>
Mon, 12 Sep 2016 10:41:20 +0800
changeset 314432 c12f64bf259899d61108e556ac7bd437cd1d03d7
parent 314431 66359c23a6b6f49aeba4f6e88d9b53cc0a189a3d
child 314433 e1bf663363fd84b7c7c9f3c08bc22bce4874dede
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskikuo
bugs1302006
milestone52.0a1
Bug 1302006. Part 3 - Let SeekingState handle dormant request. r=kikuo MozReview-Commit-ID: ADVsUSpE8Az
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -463,16 +463,36 @@ class MediaDecoderStateMachine::SeekingS
 {
 public:
   explicit SeekingState(Master* aPtr) : StateObject(aPtr) {}
 
   State GetState() const override
   {
     return DECODER_STATE_SEEKING;
   }
+
+  bool HandleDormant(bool aDormant) override
+  {
+    if (!aDormant) {
+      return true;
+    }
+    MOZ_ASSERT(!mMaster->mQueuedSeek.Exists());
+    MOZ_ASSERT(mMaster->mCurrentSeek.Exists());
+    // Because both audio and video decoders are going to be reset in this
+    // method later, we treat a VideoOnly seek task as a normal Accurate
+    // seek task so that while it is resumed, both audio and video playback
+    // are handled.
+    if (mMaster->mCurrentSeek.mTarget.IsVideoOnly()) {
+      mMaster->mCurrentSeek.mTarget.SetType(SeekTarget::Accurate);
+      mMaster->mCurrentSeek.mTarget.SetVideoOnly(false);
+    }
+    mMaster->mQueuedSeek = Move(mMaster->mCurrentSeek);
+    SetState(DECODER_STATE_DORMANT);
+    return true;
+  }
 };
 
 class MediaDecoderStateMachine::BufferingState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit BufferingState(Master* aPtr) : StateObject(aPtr) {}
 
@@ -1502,47 +1522,33 @@ void
 MediaDecoderStateMachine::SetDormant(bool aDormant)
 {
   MOZ_ASSERT(OnTaskQueue());
 
   if (mStateObj->HandleDormant(aDormant)) {
     return;
   }
 
-  // |mState == DECODER_STATE_DORMANT| is already
-  // handled by |mStateObj->HandleDormant| above.
-  MOZ_ASSERT(mState != DECODER_STATE_DORMANT);
+  // These states are already handled by |mStateObj->HandleDormant| above.
+  MOZ_ASSERT(mState != DECODER_STATE_DORMANT &&
+             mState != DECODER_STATE_SEEKING);
 
   // Nothing to do for we are not in dormant state.
   if (!aDormant) {
     return;
   }
 
   DECODER_LOG("Enter dormant state");
 
-  if (mState == DECODER_STATE_SEEKING) {
-    MOZ_ASSERT(!mQueuedSeek.Exists());
-    MOZ_ASSERT(mCurrentSeek.Exists());
-    // Because both audio and video decoders are going to be reset in this
-    // method later, we treat a VideoOnly seek task as a normal Accurate
-    // seek task so that while it is resumed, both audio and video playback
-    // are handled.
-    if (mCurrentSeek.mTarget.IsVideoOnly()) {
-      mCurrentSeek.mTarget.SetType(SeekTarget::Accurate);
-      mCurrentSeek.mTarget.SetVideoOnly(false);
-    }
-    mQueuedSeek = Move(mCurrentSeek);
-  } else {
-    mQueuedSeek.mTarget = SeekTarget(mCurrentPosition,
-                                     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 = mQueuedSeek.mPromise.Ensure(__func__);
-  }
+  mQueuedSeek.mTarget = SeekTarget(mCurrentPosition,
+                                   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 = mQueuedSeek.mPromise.Ensure(__func__);
 
   SetState(DECODER_STATE_DORMANT);
 }
 
 RefPtr<ShutdownPromise>
 MediaDecoderStateMachine::Shutdown()
 {
   MOZ_ASSERT(OnTaskQueue());