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.