From 449c5fc2ebb90b404f9df9211c2af96ed3cf48ee Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Thu, 11 Dec 2014 15:19:50 -0800 Subject: [PATCH] Backed out changeset 22484b7bbff3 (bug 1108728) for mochitest-11 bustage on a CLOSED TREE --- dom/media/MediaDecoder.cpp | 42 ++++++++++++++++++++++++++++---------- dom/media/MediaDecoder.h | 8 ++++++++ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index f989749aacf..26131597961 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -125,7 +125,8 @@ void MediaDecoder::SetDormantIfNecessary(bool aDormant) if (!mDecoderStateMachine || !mDecoderStateMachine->IsDormantNeeded() || - mPlayState == PLAY_STATE_SHUTDOWN) { + mPlayState == PLAY_STATE_SHUTDOWN || + mIsDormant == aDormant) { return; } @@ -139,11 +140,14 @@ void MediaDecoder::SetDormantIfNecessary(bool aDormant) mRequestedSeekTarget = SeekTarget(timeUsecs, SeekTarget::Accurate); mNextState = mPlayState; + mIsDormant = true; + mIsExitingDormant = false; ChangeState(PLAY_STATE_LOADING); - } else { + } else if (!aDormant && mPlayState == PLAY_STATE_LOADING) { // exit dormant state // trigger to state machine. mDecoderStateMachine->SetDormant(false); + mIsExitingDormant = true; } } @@ -151,7 +155,7 @@ void MediaDecoder::Pause() { MOZ_ASSERT(NS_IsMainThread()); ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); - if (mPlayState == PLAY_STATE_LOADING || + if ((mPlayState == PLAY_STATE_LOADING && mIsDormant) || mPlayState == PLAY_STATE_SEEKING || mPlayState == PLAY_STATE_ENDED) { mNextState = PLAY_STATE_PAUSED; @@ -428,6 +432,8 @@ MediaDecoder::MediaDecoder() : mMediaSeekable(true), mSameOriginMedia(false), mReentrantMonitor("media.decoder"), + mIsDormant(false), + mIsExitingDormant(false), mPlayState(PLAY_STATE_LOADING), mNextState(PLAY_STATE_PAUSED), mIgnoreProgressData(false), @@ -594,13 +600,12 @@ nsresult MediaDecoder::Play() } nsresult res = ScheduleStateMachineThread(); NS_ENSURE_SUCCESS(res,res); - if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING) { + if ((mPlayState == PLAY_STATE_LOADING && mIsDormant) || mPlayState == PLAY_STATE_SEEKING) { mNextState = PLAY_STATE_PLAYING; return NS_OK; } - if (mPlayState == PLAY_STATE_ENDED) { + if (mPlayState == PLAY_STATE_ENDED) return Seek(0, SeekTarget::PrevSyncPoint); - } ChangeState(PLAY_STATE_PLAYING); return NS_OK; @@ -623,7 +628,7 @@ nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType) // If we are already in the seeking state, then setting mRequestedSeekTarget // above will result in the new seek occurring when the current seek // completes. - if (mPlayState != PLAY_STATE_LOADING && mPlayState != PLAY_STATE_SEEKING) { + if ((mPlayState != PLAY_STATE_LOADING || !mIsDormant) && mPlayState != PLAY_STATE_SEEKING) { bool paused = false; if (mOwner) { paused = mOwner->GetPaused(); @@ -698,6 +703,12 @@ void MediaDecoder::MetadataLoaded(nsAutoPtr aInfo, { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); + if (mPlayState == PLAY_STATE_LOADING && mIsDormant && !mIsExitingDormant) { + return; + } else if (mPlayState == PLAY_STATE_LOADING && mIsDormant && mIsExitingDormant) { + mIsDormant = false; + mIsExitingDormant = false; + } mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1; // Duration has changed so we should recompute playback rate UpdatePlaybackRate(); @@ -730,6 +741,10 @@ void MediaDecoder::FirstFrameLoaded(nsAutoPtr aInfo) aInfo->mAudio.mChannels, aInfo->mAudio.mRate, aInfo->HasAudio(), aInfo->HasVideo()); + if (mPlayState == PLAY_STATE_LOADING && mIsDormant && !mIsExitingDormant) { + return; + } + mInfo = aInfo.forget(); if (mOwner) { @@ -814,8 +829,7 @@ bool MediaDecoder::IsSameOriginMedia() bool MediaDecoder::IsSeeking() const { MOZ_ASSERT(NS_IsMainThread()); - return mPlayState == PLAY_STATE_SEEKING || - (mPlayState == PLAY_STATE_LOADING && mRequestedSeekTarget.IsValid()); + return mPlayState == PLAY_STATE_SEEKING; } bool MediaDecoder::IsEnded() const @@ -830,7 +844,7 @@ void MediaDecoder::PlaybackEnded() if (mShuttingDown || mPlayState == PLAY_STATE_SEEKING || - (mPlayState == PLAY_STATE_LOADING)) { + (mPlayState == PLAY_STATE_LOADING && mIsDormant)) { return; } @@ -1127,7 +1141,8 @@ void MediaDecoder::ChangeState(PlayState aState) mNextState = PLAY_STATE_PAUSED; } - if (mPlayState == PLAY_STATE_SHUTDOWN) { + if ((mPlayState == PLAY_STATE_LOADING && mIsDormant && aState != PLAY_STATE_SHUTDOWN) || + mPlayState == PLAY_STATE_SHUTDOWN) { GetReentrantMonitor().NotifyAll(); return; } @@ -1152,6 +1167,11 @@ void MediaDecoder::ChangeState(PlayState aState) ApplyStateToStateMachine(mPlayState); + if (aState!= PLAY_STATE_LOADING) { + mIsDormant = false; + mIsExitingDormant = false; + } + GetReentrantMonitor().NotifyAll(); } diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index ebfb4a617d0..9b4e3f20c4c 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -1124,6 +1124,14 @@ protected: // without holding the monitor. nsAutoPtr mDecodedStream; + // True if this decoder is in dormant state. + // Should be true only when PlayState is PLAY_STATE_LOADING. + bool mIsDormant; + + // True if this decoder is exiting from dormant state. + // Should be true only when PlayState is PLAY_STATE_LOADING. + bool mIsExitingDormant; + // Set to one of the valid play states. // This can only be changed on the main thread while holding the decoder // monitor. Thus, it can be safely read while holding the decoder monitor