Bug 1302006. Part 1 - Let DormantState handle dormant request. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 06 Sep 2016 15:15:48 +0800
changeset 414778 d1f13c9cf5c100f164632f7e0e78f90668de2aed
parent 414763 f0f15b7c6aa77a0c5750918aa0a1cb3dc82185bc
child 414779 79a195917c885752a09fdfba367ac22724669066
push id29760
push userjwwang@mozilla.com
push dateMon, 19 Sep 2016 02:32:14 +0000
bugs1302006
milestone51.0a1
Bug 1302006. Part 1 - Let DormantState handle dormant request. MozReview-Commit-ID: 8JqqAnlXzh4
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -403,16 +403,25 @@ public:
     mMaster->Reset();
     mMaster->mReader->ReleaseResources();
   }
 
   State GetState() const override
   {
     return DECODER_STATE_DORMANT;
   }
+
+  bool HandleDormant(bool aDormant) override
+  {
+    if (!aDormant) {
+      // Exit dormant state.
+      SetState(DECODER_STATE_DECODING_METADATA);
+    }
+    return true;
+  }
 };
 
 class MediaDecoderStateMachine::DecodingFirstFrameState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit DecodingFirstFrameState(Master* aPtr) : StateObject(aPtr) {}
 
@@ -1492,52 +1501,49 @@ MediaDecoderStateMachine::SetDormant(boo
   if (IsShutdown()) {
     return;
   }
 
   if (mStateObj->HandleDormant(aDormant)) {
     return;
   }
 
-  bool wasDormant = mState == DECODER_STATE_DORMANT;
-  if (wasDormant == aDormant) {
+  // |mState == DECODER_STATE_DORMANT| is already
+  // handled by |mStateObj->HandleDormant| above.
+  MOZ_ASSERT(mState != DECODER_STATE_DORMANT);
+
+  // Nothing to do for we are not in dormant state.
+  if (!aDormant) {
     return;
   }
 
-  DECODER_LOG("SetDormant=%d", aDormant);
-
-  // Enter dormant state.
-  if (aDormant) {
-    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__);
+  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);
     }
-
-    SetState(DECODER_STATE_DORMANT);
-    return;
+    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__);
   }
 
-  // Exit dormant state.
-  SetState(DECODER_STATE_DECODING_METADATA);
+  SetState(DECODER_STATE_DORMANT);
 }
 
 RefPtr<ShutdownPromise>
 MediaDecoderStateMachine::Shutdown()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   SetState(DECODER_STATE_SHUTDOWN);