From 6edcb8f1054b2422b823e6c57df62afe03899082 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 27 Mar 2014 07:27:01 +0800 Subject: [PATCH] Bug 945475 - clear |mVideoFrameContainer| to stop staled callbacks which give incorrect videoWidth/videoHeight. r=roc --- content/html/content/src/HTMLMediaElement.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/content/html/content/src/HTMLMediaElement.cpp b/content/html/content/src/HTMLMediaElement.cpp index 5ab86407489c..557628601c45 100644 --- a/content/html/content/src/HTMLMediaElement.cpp +++ b/content/html/content/src/HTMLMediaElement.cpp @@ -760,9 +760,13 @@ NS_IMETHODIMP HTMLMediaElement::Load() void HTMLMediaElement::ResetState() { mMediaSize = nsIntSize(-1, -1); - VideoFrameContainer* container = GetVideoFrameContainer(); - if (container) { - container->Reset(); + // There might be a pending MediaDecoder::PlaybackPositionChanged() which + // will overwrite |mMediaSize| in UpdateMediaSize() to give staled videoWidth + // and videoHeight. We have to call ForgetElement() here such that the staled + // callbacks won't reach us. + if (mVideoFrameContainer) { + mVideoFrameContainer->ForgetElement(); + mVideoFrameContainer = nullptr; } } @@ -3012,7 +3016,10 @@ void HTMLMediaElement::MetadataLoaded(int aChannels, // If this element had a video track, but consists only of an audio track now, // delete the VideoFrameContainer. This happens when the src is changed to an // audio only file. - if (!aHasVideo) { + if (!aHasVideo && mVideoFrameContainer) { + // call ForgetElement() such that callbacks from |mVideoFrameContainer| + // won't reach us anymore. + mVideoFrameContainer->ForgetElement(); mVideoFrameContainer = nullptr; } }