Bug 1311872. Part 4 - exit dormant in response to user actions. r=cpearce,jya
authorJW Wang <jwwang@mozilla.com>
Fri, 21 Oct 2016 15:52:17 +0800
changeset 347475 159aabd71aaae58c90bdb3fe5058a8426a5d26dc
parent 347474 80ee79d7a32a5bc2f811f067e6f63e72f71eb14c
child 347476 6efd141313d472eda740931b77a2167f7eae2b4b
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, jya
bugs1311872
milestone52.0a1
Bug 1311872. Part 4 - exit dormant in response to user actions. r=cpearce,jya MozReview-Commit-ID: CTXUlpfLNBQ
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -417,17 +417,18 @@ private:
   bool mPendingDormant = false;
   SeekJob mPendingSeek;
 };
 
 /**
  * Purpose: release decoder resources to save memory and hardware resources.
  *
  * Transition to:
- *   DECODING_FIRSTFRAME when being asked to exit dormant.
+ *   DECODING_FIRSTFRAME when play state changes to PLAYING.
+ *   SEEKING if any seek request.
  */
 class MediaDecoderStateMachine::DormantState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit DormantState(Master* aPtr) : StateObject(aPtr) {}
 
   void Enter(SeekJob aPendingSeek)
@@ -449,34 +450,36 @@ public:
 
   State GetState() const override
   {
     return DECODER_STATE_DORMANT;
   }
 
   bool HandleDormant(bool aDormant) override;
 
-  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
-  {
-    SLOG("Not Enough Data to seek at this stage, queuing seek");
-    mPendingSeek.RejectIfExists(__func__);
-    mPendingSeek.mTarget = aTarget;
-    return mPendingSeek.mPromise.Ensure(__func__);
-  }
+  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override;
 
   void HandleVideoSuspendTimeout() override
   {
     // Do nothing since we've released decoders in Enter().
   }
 
   void HandleResumeVideoDecoding() override
   {
     // Do nothing since we won't resume decoding until exiting dormant.
   }
 
+  void HandlePlayStateChanged(MediaDecoder::PlayState aPlayState) override
+  {
+    if (aPlayState == MediaDecoder::PLAY_STATE_PLAYING) {
+      // Exit dormant when the user wants to play.
+      HandleDormant(false);
+    }
+  }
+
 private:
   SeekJob mPendingSeek;
 };
 
 /**
  * Purpose: decode the 1st audio and video frames to fire the 'loadeddata' event.
  *
  * Transition to:
@@ -1355,16 +1358,27 @@ DormantState::HandleDormant(bool aDorman
 {
   if (!aDormant) {
     MOZ_ASSERT(!Info().IsEncrypted() || mMaster->mCDMProxy);
     SetState<DecodingFirstFrameState>(Move(mPendingSeek));
   }
   return true;
 }
 
+RefPtr<MediaDecoder::SeekPromise>
+MediaDecoderStateMachine::
+DormantState::HandleSeek(SeekTarget aTarget)
+{
+  // Exit dormant when the user wants to seek.
+  mPendingSeek.RejectIfExists(__func__);
+  SeekJob seekJob;
+  seekJob.mTarget = aTarget;
+  return SetState<SeekingState>(Move(seekJob));
+}
+
 bool
 MediaDecoderStateMachine::
 WaitForCDMState::HandleCDMProxyReady()
 {
   if (mPendingDormant) {
     SetState<DormantState>(Move(mPendingSeek));
   } else {
     SetState<DecodingFirstFrameState>(Move(mPendingSeek));