Bug 1298217. Part 2 - Move some code to the entry action of DECODER_STATE_DORMANT. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 26 Aug 2016 05:58:12 +1200
changeset 406595 a06ac309b2ecffc5843471b6345f93172defbd8b
parent 406594 5a420682aafffc8e3e1fd0b26aec3bfc3be19e6b
child 406596 aefdc0ad3607a84effebc66c8865b559a471b924
push id27772
push userjwwang@mozilla.com
push dateMon, 29 Aug 2016 06:35:00 +0000
bugs1298217
milestone51.0a1
Bug 1298217. Part 2 - Move some code to the entry action of DECODER_STATE_DORMANT. MozReview-Commit-ID: 9q35AhxS5IP
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1094,16 +1094,24 @@ void
 MediaDecoderStateMachine::EnterState(State aState)
 {
   MOZ_ASSERT(OnTaskQueue());
   switch (aState) {
     case DECODER_STATE_DECODING_METADATA:
       mDecodingFirstFrame = true;
       ReadMetadata();
       break;
+    case DECODER_STATE_DORMANT:
+      DiscardSeekTaskIfExist();
+      if (IsPlaying()) {
+        StopPlayback();
+      }
+      Reset();
+      mReader->ReleaseResources();
+      break;
     case DECODER_STATE_ERROR:
     case DECODER_STATE_SHUTDOWN:
       mIsShutdown = true;
       break;
     default:
       break;
   }
 }
@@ -1198,34 +1206,16 @@ MediaDecoderStateMachine::SetDormant(boo
                                        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);
-
-    // Discard the current seek task.
-    DiscardSeekTaskIfExist();
-
-    if (IsPlaying()) {
-      StopPlayback();
-    }
-
-    Reset();
-
-    // Note that we do not wait for the decode task queue to go idle before
-    // queuing the ReleaseResources task - instead, we disconnect promises,
-    // reset state, and put a ResetDecode in the decode task queue. Any tasks
-    // that run after ResetDecode are supposed to run with a clean slate. We
-    // rely on that in other places (i.e. seeking), so it seems reasonable to
-    // rely on it here as well.
-    mReader->ReleaseResources();
-
     return;
   }
 
   // Exit dormant state.
   SetState(DECODER_STATE_DECODING_METADATA);
 }
 
 RefPtr<ShutdownPromise>