Bug 1511235 - Part 1: Suspend video decoding for video whose visibility state is UNTRACK. r=jya, a=RyanVM
authoralwu <alwu@mozilla.com>
Thu, 20 Dec 2018 20:02:24 +0000
changeset 506424 2616da988292
parent 506423 226db4f6cb06
child 506425 9d3238bbfcc6
push id10410
push userryanvm@gmail.com
push dateSun, 30 Dec 2018 23:47:52 +0000
treeherdermozilla-beta@1d747c8ca942 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, RyanVM
bugs1511235
milestone65.0
Bug 1511235 - Part 1: Suspend video decoding for video whose visibility state is UNTRACK. r=jya, a=RyanVM If video has not been within the potential visible range (which is larger than viewport) yet, its visibility state won't be updated and would stay in 'UNTRACK'. As those kinds of video are still invisible to users, we don't need to decode any video frames, we can suspend their video decoding until they're going to be visible. Differential Revision: https://phabricator.services.mozilla.com/D13804
dom/media/MediaDecoder.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -962,24 +962,16 @@ void MediaDecoder::UpdateVideoDecodeMode
   AbstractThread::AutoEnter context(mAbstractMainThread);
 
   // The MDSM may yet be set.
   if (!mDecoderStateMachine) {
     LOG("UpdateVideoDecodeMode(), early return because we don't have MDSM.");
     return;
   }
 
-  // If an element is in-tree with UNTRACKED visibility, the visibility is
-  // incomplete and don't update the video decode mode.
-  if (mIsElementInTree && mElementVisibility == Visibility::UNTRACKED) {
-    LOG("UpdateVideoDecodeMode(), early return because we have incomplete "
-        "visibility states.");
-    return;
-  }
-
   // If mHasSuspendTaint is set, never suspend the video decoder.
   if (mHasSuspendTaint) {
     LOG("UpdateVideoDecodeMode(), set Normal because the element has been "
         "tainted.");
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
     return;
   }
 
@@ -1002,16 +994,26 @@ void MediaDecoder::UpdateVideoDecodeMode
   // Resume decoding in the advance, even the element is in the background.
   if (mIsBackgroundVideoDecodingAllowed) {
     LOG("UpdateVideoDecodeMode(), set Normal because the tab is in background "
         "and hovered.");
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
     return;
   }
 
+  // If the element is in-tree with UNTRACKED visibility, that means the element
+  // is not close enough to the viewport so we have not start to update its
+  // visibility. In this case, it's equals to invisible.
+  if (mIsElementInTree && mElementVisibility == Visibility::UNTRACKED) {
+    LOG("UpdateVideoDecodeMode(), set Suspend because element hasn't be "
+        "updated visibility state.");
+    mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Suspend);
+    return;
+  }
+
   // Otherwise, depends on the owner's visibility state.
   // A element is visible only if its document is visible and the element
   // itself is visible.
   if (mIsDocumentVisible &&
       mElementVisibility == Visibility::APPROXIMATELY_VISIBLE) {
     LOG("UpdateVideoDecodeMode(), set Normal because the element visible.");
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
   } else {