From 41df7a67159d85106d6d40a934ec7baeb8e050d4 Mon Sep 17 00:00:00 2001 From: alwu Date: Thu, 20 Dec 2018 20:02:24 +0000 Subject: [PATCH] Bug 1511235 - part1 : suspend video decoding for video whose visibility state is UNTRACK. r=jya 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 --HG-- extra : moz-landing-system : lando --- dom/media/MediaDecoder.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 9cc5310f550e..dfc2b5a4ab70 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -966,14 +966,6 @@ void MediaDecoder::UpdateVideoDecodeMode() { 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; - } - // Seeking is required when leaving suspend mode. if (!mMediaSeekable) { LOG("UpdateVideoDecodeMode(), set Normal because the media is not " @@ -1014,6 +1006,16 @@ void MediaDecoder::UpdateVideoDecodeMode() { 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.