Bug 1310140. Part 6 - have DecodingState handle suspend-video-decoding. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 18 Oct 2016 10:48:46 +0800
changeset 426831 9ef8b894bafcb683c8cd9b8acc5bed000cd6efdf
parent 426830 89d7c1df5e50705646f5d72be13b906e61894594
child 426832 039d8c0cee73099a57f14b8f0a9f7e4ed4fcbc75
push id32814
push userjwwang@mozilla.com
push dateWed, 19 Oct 2016 06:32:41 +0000
bugs1310140
milestone52.0a1
Bug 1310140. Part 6 - have DecodingState handle suspend-video-decoding. MozReview-Commit-ID: 3GxHdxZCiwE
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -530,16 +530,23 @@ public:
   bool HandleAudioCaptured() override
   {
     MaybeStopPrerolling();
     // MediaSink is changed. Schedule Step() to check if we can start playback.
     mMaster->ScheduleStateMachine();
     return true;
   }
 
+  void HandleVideoSuspendTimeout() override
+  {
+    mMaster->mVideoDecodeSuspended = true;
+    mMaster->mOnPlaybackEvent.Notify(MediaEventType::EnterVideoSuspend);
+    Reader()->SetVideoBlankDecode(true);
+  }
+
   void DumpDebugInfo() override
   {
     SDUMP("mIsPrerolling=%d", mIsPrerolling);
   }
 
 private:
   void MaybeStartBuffering();
 
@@ -1127,16 +1134,24 @@ void
 MediaDecoderStateMachine::
 DecodingState::Enter()
 {
   MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);
   // Pending seek should've been handled by DECODING_FIRSTFRAME before
   // transitioning to DECODING.
   MOZ_ASSERT(!mMaster->mQueuedSeek.Exists());
 
+  if (!mMaster->mIsVisible &&
+      !mMaster->mVideoDecodeSuspendTimer.IsScheduled() &&
+      !mMaster->mVideoDecodeSuspended) {
+    // If we are not visible and the timer is not schedule, it means the timer
+    // has timed out and we should suspend video decoding now if necessary.
+    HandleVideoSuspendTimeout();
+  }
+
   if (mMaster->CheckIfDecodeComplete()) {
     SetState<CompletedState>();
     return;
   }
 
   mDecodeStartTime = TimeStamp::Now();
 
   MaybeStopPrerolling();