Bug 1295921 - P6: Move resume from suspend into new function. r?jwwang draft
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 28 Sep 2016 10:04:57 +1000
changeset 450826 7f516a0e3426d3214d71ae4697d4b456016a8504
parent 450825 5a2984a53741f19df84b4215c46dd54101b4be3b
child 450827 7751fe83806471fb98f124018daab78055fdc551
push id38957
push userbmo:dglastonbury@mozilla.com
push dateMon, 19 Dec 2016 02:15:56 +0000
reviewersjwwang
bugs1295921
milestone53.0a1
Bug 1295921 - P6: Move resume from suspend into new function. r?jwwang Extract resume from suspend code from visibility changed handler and put into a new function to allow this code be called when the suspend taint changes. MozReview-Commit-ID: 5qXCQrnNy0l
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2306,16 +2306,17 @@ MediaDecoderStateMachine::Initialization
   mWatchManager.Watch(mExplicitDuration, &MediaDecoderStateMachine::RecomputeDuration);
   mWatchManager.Watch(mObservedDuration, &MediaDecoderStateMachine::RecomputeDuration);
   mWatchManager.Watch(mPlayState, &MediaDecoderStateMachine::PlayStateChanged);
 
   if (MediaPrefs::MDSMSuspendBackgroundVideoEnabled()) {
     mIsVisible.Connect(aDecoder->CanonicalIsVisible());
     mHasSuspendTaint.Connect(aDecoder->CanonicalHasSuspendTaint());
     mWatchManager.Watch(mIsVisible, &MediaDecoderStateMachine::VisibilityChanged);
+    mWatchManager.Watch(mHasSuspendTaint, &MediaDecoderStateMachine::SuspendTaintChanged);
   }
 
   // Configure MediaDecoderReaderWrapper.
   SetMediaDecoderReaderWrapperCallback();
 }
 
 void
 MediaDecoderStateMachine::AudioAudibleChanged(bool aAudible)
@@ -2859,19 +2860,17 @@ MediaDecoderStateMachine::Shutdown()
   MOZ_ASSERT(OnTaskQueue());
   return mStateObj->HandleShutdown();
 }
 
 void MediaDecoderStateMachine::PlayStateChanged()
 {
   MOZ_ASSERT(OnTaskQueue());
 
-  if (mPlayState != MediaDecoder::PLAY_STATE_PLAYING) {
-    CancelSuspendTimer();
-  } else if (mMinimizePreroll) {
+  if (mMinimizePreroll) {
     // Once we start playing, we don't want to minimize our prerolling, as we
     // assume the user is likely to want to keep playing in future. This needs to
     // happen before we invoke StartDecoding().
     mMinimizePreroll = false;
     DispatchDecodeTasksIfNeeded();
   }
 
   mStateObj->HandlePlayStateChanged(mPlayState);
@@ -2891,21 +2890,32 @@ void MediaDecoderStateMachine::Visibilit
     mVideoDecodeSuspendTimer.Ensure(target,
                                     [=]() { self->OnSuspendTimerResolved(); },
                                     [] () { MOZ_DIAGNOSTIC_ASSERT(false); });
     mOnPlaybackEvent.Notify(MediaEventType::BeginVideoSuspend);
 
     return;
   }
 
-  // Resuming from suspended decoding
-
-  // If suspend timer exists, destroy it.
   CancelSuspendTimer();
 
+  // Resume from suspended decoding.
+  if (mVideoDecodeSuspended) {
+    mStateObj->HandleResumeVideoDecoding();
+  }
+}
+
+void MediaDecoderStateMachine::SuspendTaintChanged()
+{
+  MOZ_ASSERT(OnTaskQueue());
+  MOZ_ASSERT(mHasSuspendTaint); // Suspend taint is only ever set.
+
+  CancelSuspendTimer();
+
+  // Resume from suspended decoding.
   if (mVideoDecodeSuspended) {
     mStateObj->HandleResumeVideoDecoding();
   }
 }
 
 void MediaDecoderStateMachine::BufferedRangeUpdated()
 {
   MOZ_ASSERT(OnTaskQueue());
@@ -3776,17 +3786,19 @@ MediaDecoderStateMachine::OnSuspendTimer
   DECODER_LOG("OnSuspendTimerResolved");
   mVideoDecodeSuspendTimer.CompleteRequest();
   mStateObj->HandleVideoSuspendTimeout();
 }
 
 void
 MediaDecoderStateMachine::CancelSuspendTimer()
 {
-  DECODER_LOG("CancelSuspendTimer");
+  DECODER_LOG("CancelSuspendTimer: State: %s, Timer.IsScheduled: %c",
+              ToStateStr(mStateObj->GetState()),
+              mVideoDecodeSuspendTimer.IsScheduled() ? 'T' : 'F');
   MOZ_ASSERT(OnTaskQueue());
   if (mVideoDecodeSuspendTimer.IsScheduled()) {
     mOnPlaybackEvent.Notify(MediaEventType::CancelVideoSuspend);
   }
   mVideoDecodeSuspendTimer.Reset();
 }
 
 } // namespace mozilla
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -433,16 +433,19 @@ protected:
   void StartMediaSink();
 
   // Notification method invoked when mPlayState changes.
   void PlayStateChanged();
 
   // Notification method invoked when mIsVisible changes.
   void VisibilityChanged();
 
+  // Notification method invoked when mHasSuspendTaint changes.
+  void SuspendTaintChanged();
+
   // Sets internal state which causes playback of media to pause.
   // The decoder monitor must be held.
   void StopPlayback();
 
   // If the conditions are right, sets internal state which causes playback
   // of media to begin or resume.
   // Must be called with the decode monitor held.
   void MaybeStartPlayback();