Bug 1346498 part 3 - implement the UpdateVideoDecodeMode() policy in MediaDecoder; r=jwwang
authorKaku Kuo <kaku@mozilla.com>
Fri, 10 Mar 2017 16:52:03 +0800
changeset 347419 af2fd441e1b2e96ffa38ff7b3a194be9cd67c1cd
parent 347418 caaa45f70bb7a7fd8077bdad3fe3b660aa4ca460
child 347420 a42487bf567a382db80ffe2116324dd76daa7735
push id31496
push usercbook@mozilla.com
push dateTue, 14 Mar 2017 13:21:57 +0000
treeherdermozilla-central@9a26ed658fdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1346498
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1346498 part 3 - implement the UpdateVideoDecodeMode() policy in MediaDecoder; r=jwwang So, the MediaDecoder is the one who rules out the policy of suspending video decoder. We also extract all the policy rules into one single method, MediaDecoder::UpdateVideoDecodeMode(). MozReview-Commit-ID: IOQq6kFfkIs
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1305,32 +1305,56 @@ MediaDecoder::NotifyCompositor()
   }
 }
 
 void
 MediaDecoder::SetElementVisibility(bool aIsVisible)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mElementVisible = aIsVisible;
-  mIsVisible = !mForcedHidden && mElementVisible;
+  UpdateVideoDecodeMode();
 }
 
 void
 MediaDecoder::SetForcedHidden(bool aForcedHidden)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mForcedHidden = aForcedHidden;
-  SetElementVisibility(mElementVisible);
+  UpdateVideoDecodeMode();
 }
 
 void
 MediaDecoder::SetSuspendTaint(bool aTainted)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mHasSuspendTaint = aTainted;
+  UpdateVideoDecodeMode();
+}
+
+void
+MediaDecoder::UpdateVideoDecodeMode()
+{
+  // The MDSM may yet be set.
+  if (!mDecoderStateMachine) {
+    return;
+  }
+
+  // If mHasSuspendTaint is set, never suspend the video decoder.
+  if (mHasSuspendTaint) {
+    mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
+    return;
+  }
+
+  // If mForcedHidden is set, suspend the video decoder anyway.
+  // Otherwise, depends on the owner's visibility state.
+  if (!mForcedHidden && mElementVisible) {
+    mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
+  } else {
+    mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Suspend);
+  }
 }
 
 bool
 MediaDecoder::HasSuspendTaint() const
 {
   MOZ_ASSERT(NS_IsMainThread());
   return mHasSuspendTaint;
 }
@@ -1499,16 +1523,17 @@ MediaDecoder::DisconnectMirrors()
 void
 MediaDecoder::SetStateMachine(MediaDecoderStateMachine* aStateMachine)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT_IF(aStateMachine, !mDecoderStateMachine);
   mDecoderStateMachine = aStateMachine;
   if (aStateMachine) {
     ConnectMirrors(aStateMachine);
+    UpdateVideoDecodeMode();
   } else {
     DisconnectMirrors();
   }
 }
 
 ImageContainer*
 MediaDecoder::GetImageContainer()
 {
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -378,16 +378,18 @@ private:
   void SetForcedHidden(bool aForcedHidden);
 
   // Mark the decoder as tainted, meaning suspend-video-decoder is disabled.
   void SetSuspendTaint(bool aTaint);
 
   // Returns true if the decoder can't participate in suspend-video-decoder.
   bool HasSuspendTaint() const;
 
+  void UpdateVideoDecodeMode();
+
   /******
    * The following methods must only be called on the main
    * thread.
    ******/
 
   // Change to a new play state. This updates the mState variable and
   // notifies any thread blocking on this object's monitor of the
   // change. Call on the main thread only.