Bug 1300956. Part 3 - Implement DormantState.
MozReview-Commit-ID: 85IjZCdFjyJ
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -246,16 +246,38 @@ public:
explicit WaitForCDMState(Master* aPtr) : StateObject(aPtr) {}
State GetState() const override
{
return DECODER_STATE_WAIT_FOR_CDM;
}
};
+class MediaDecoderStateMachine::DormantState
+ : public MediaDecoderStateMachine::StateObject
+{
+public:
+ explicit DormantState(Master* aPtr) : StateObject(aPtr) {}
+
+ void Enter() override
+ {
+ mMaster->DiscardSeekTaskIfExist();
+ if (mMaster->IsPlaying()) {
+ mMaster->StopPlayback();
+ }
+ mMaster->Reset();
+ mMaster->mReader->ReleaseResources();
+ }
+
+ State GetState() const override
+ {
+ return DECODER_STATE_DORMANT;
+ }
+};
+
#define INIT_WATCHABLE(name, val) \
name(val, "MediaDecoderStateMachine::" #name)
#define INIT_MIRROR(name, val) \
name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Mirror)")
#define INIT_CANONICAL(name, val) \
name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Canonical)")
MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
@@ -1116,16 +1138,19 @@ MediaDecoderStateMachine::SetState(State
switch (mState) {
case DECODER_STATE_DECODING_METADATA:
mStateObj = MakeUnique<DecodeMetadataState>(this);
break;
case DECODER_STATE_WAIT_FOR_CDM:
mStateObj = MakeUnique<WaitForCDMState>(this);
break;
+ case DECODER_STATE_DORMANT:
+ mStateObj = MakeUnique<DormantState>(this);
+ break;
default:
mStateObj = nullptr;
break;
}
EnterState();
}
@@ -1159,24 +1184,16 @@ MediaDecoderStateMachine::EnterState()
if (mStateObj) {
MOZ_ASSERT(mState == mStateObj->GetState());
mStateObj->Enter();
return;
}
switch (mState) {
- case DECODER_STATE_DORMANT:
- DiscardSeekTaskIfExist();
- if (IsPlaying()) {
- StopPlayback();
- }
- Reset();
- mReader->ReleaseResources();
- break;
case DECODER_STATE_DECODING_FIRSTFRAME:
DecodeFirstFrame();
break;
case DECODER_STATE_DECODING:
StartDecoding();
break;
case DECODER_STATE_BUFFERING:
StartBuffering();