Bug 1302006. Part 1 - Let DormantState handle dormant request. r=kikuo
authorJW Wang <jwwang@mozilla.com>
Tue, 06 Sep 2016 15:15:48 +0800
changeset 314430 7fb80e9897fa529df5925279623576fde86c195b
parent 314429 2db6d45d00706912f8671d485f3bc3fcd64e0ac3
child 314431 66359c23a6b6f49aeba4f6e88d9b53cc0a189a3d
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 1 - Let DormantState handle dormant request. r=kikuo 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);