Bug 1420608 - don't switch off blank decoder when seeking begins. r=gerald

When looping videos in a background tab, SeekingState::Enter() will switch off
blank decoder and then DecodingState::Enter() will switch it on again. It is a
waste of CPU cycles when the tab never goes to the foreground. The overhread is
even more significant when looping short files.

We should resume video decoding only when necessary that is we check in
DecodingState::Enter() to see if mVideoDecodeSuspended matches mVideoDecodeMode.

MozReview-Commit-ID: 54vq7mEjWQf

--HG--
extra : rebase_source : 1f8ea7aad5b555dc2787404d457aaf742e5dd6c7
This commit is contained in:
JW Wang 2017-12-07 11:38:23 +08:00
parent 9c9c6b777b
commit 4139411ec5

View File

@ -833,15 +833,6 @@ public:
mSeekJob = Move(aSeekJob);
mVisibility = aVisibility;
// Always switch off the blank decoder otherwise we might become visible
// in the middle of seeking and won't have a valid video frame to show
// when seek is done.
if (mMaster->mVideoDecodeSuspended) {
mMaster->mVideoDecodeSuspended = false;
mMaster->mOnPlaybackEvent.Notify(MediaPlaybackEvent::ExitVideoSuspend);
Reader()->SetVideoBlankDecode(false);
}
// Suppressed visibility comes from two cases: (1) leaving dormant state,
// and (2) resuming suspended video decoder. We want both cases to be
// transparent to the user. So we only notify the change when the seek
@ -884,8 +875,7 @@ public:
void HandleResumeVideoDecoding(const TimeUnit&) override
{
// We set mVideoDecodeSuspended to false in Enter().
MOZ_ASSERT(false, "Shouldn't have suspended video decoding.");
// Do nothing. We will resume video decoding in the decoding state.
}
protected:
@ -2116,6 +2106,10 @@ StateObject::HandleResumeVideoDecoding(const TimeUnit& aTarget)
{
MOZ_ASSERT(mMaster->mVideoDecodeSuspended);
mMaster->mVideoDecodeSuspended = false;
mMaster->mOnPlaybackEvent.Notify(MediaPlaybackEvent::ExitVideoSuspend);
Reader()->SetVideoBlankDecode(false);
// Start counting recovery time from right now.
TimeStamp start = TimeStamp::Now();
@ -2278,6 +2272,12 @@ DecodingState::Enter()
{
MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);
if (mMaster->mVideoDecodeSuspended &&
mMaster->mVideoDecodeMode == VideoDecodeMode::Normal) {
StateObject::HandleResumeVideoDecoding(mMaster->GetMediaTime());
return;
}
if (mMaster->mVideoDecodeMode == VideoDecodeMode::Suspend &&
!mMaster->mVideoDecodeSuspendTimer.IsScheduled() &&
!mMaster->mVideoDecodeSuspended) {