Bug 1346498 part 2 - implement the VideoDecodeMode mechanism in MDSM; r=jwwang

The MDSM::mVideoDecodeMode and MDSM::SetVideoDecodeMode() are merely a renaming of MDSM::mIsVisible and MDSM::VisibilityChanged().
However, the renaming explicitly reflects that MDSM provides mechanism only without participating in the policy decision.
Will reremove the MDSM::mIsVisible and MDSM::VisibilityChanged() in following patches.

MozReview-Commit-ID: JdMKQTgVCf3

--HG--
extra : rebase_source : 95977b205f235b6a456d12dfde93fe84f3b12aa7
extra : source : 4382a3c10f30653d5a70abb3bd4b8146a4272784
This commit is contained in:
Kaku Kuo 2017-03-10 16:17:46 +08:00
Родитель 64305205ed
Коммит e9c23fc1ad
2 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@ -2611,6 +2611,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mVideoDecodeSuspendTimer(mTaskQueue),
mOutputStreamManager(new OutputStreamManager()),
mResource(aDecoder->GetResource()),
mVideoDecodeMode(VideoDecodeMode::Normal),
mIsMSE(aDecoder->IsMSE()),
INIT_MIRROR(mBuffered, TimeIntervals()),
INIT_MIRROR(mEstimatedDuration, NullableTimeUnit()),
@ -3068,6 +3069,56 @@ void MediaDecoderStateMachine::SuspendTaintChanged()
}
}
void MediaDecoderStateMachine::SetVideoDecodeMode(VideoDecodeMode aMode)
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod<VideoDecodeMode>(this,
&MediaDecoderStateMachine::SetVideoDecodeModeInternal,
aMode);
OwnerThread()->DispatchStateChange(r.forget());
}
void MediaDecoderStateMachine::SetVideoDecodeModeInternal(VideoDecodeMode aMode)
{
MOZ_ASSERT(OnTaskQueue());
DECODER_LOG("VideoDecodeModeChanged: VideoDecodeMode=(%s->%s), mVideoDecodeSuspended=%c",
mVideoDecodeMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
aMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
mVideoDecodeSuspended ? 'T' : 'F');
if (!MediaPrefs::MDSMSuspendBackgroundVideoEnabled()) {
return;
}
if (aMode == mVideoDecodeMode) {
return;
}
// Set new video decode mode.
mVideoDecodeMode = aMode;
// Start timer to trigger suspended video decoding.
if (mVideoDecodeMode == VideoDecodeMode::Suspend) {
TimeStamp target = TimeStamp::Now() + SuspendBackgroundVideoDelay();
RefPtr<MediaDecoderStateMachine> self = this;
mVideoDecodeSuspendTimer.Ensure(target,
[=]() { self->OnSuspendTimerResolved(); },
[] () { MOZ_DIAGNOSTIC_ASSERT(false); });
mOnPlaybackEvent.Notify(MediaEventType::StartVideoSuspendTimer);
return;
}
// Resuming from suspended decoding
// If suspend timer exists, destroy it.
CancelSuspendTimer();
if (mVideoDecodeSuspended) {
mStateObj->HandleResumeVideoDecoding();
}
}
void MediaDecoderStateMachine::BufferedRangeUpdated()
{
MOZ_ASSERT(OnTaskQueue());

Просмотреть файл

@ -127,6 +127,12 @@ enum class MediaEventType : int8_t
CancelVideoSuspendTimer
};
enum class VideoDecodeMode : uint8_t
{
Normal,
Suspend
};
/*
The state machine class. This manages the decoding and seeking in the
MediaDecoderReader on the decode task queue, and A/V sync on the shared
@ -226,6 +232,9 @@ public:
size_t SizeOfAudioQueue() const;
// Sets the video decode mode. Used by the suspend-video-decoder feature.
void SetVideoDecodeMode(VideoDecodeMode aMode);
private:
class StateObject;
class DecodeMetadataState;
@ -307,6 +316,8 @@ private:
void ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
TrackInfo::kVideoTrack));
void SetVideoDecodeModeInternal(VideoDecodeMode aMode);
protected:
virtual ~MediaDecoderStateMachine();
@ -676,6 +687,9 @@ private:
// Media data resource from the decoder.
RefPtr<MediaResource> mResource;
// Track the current video decode mode.
VideoDecodeMode mVideoDecodeMode;
// Track the complete & error for audio/video separately
MozPromiseRequestHolder<GenericPromise> mMediaSinkAudioPromise;
MozPromiseRequestHolder<GenericPromise> mMediaSinkVideoPromise;