Bug 1300956. Part 1 - Add declarations of the state objects of MDSM. Also implement DecodeMetadataState. r=kaku

MozReview-Commit-ID: BRyi409rmn5

--HG--
extra : rebase_source : 369b2654a77c76aa5654680f8cce763e67205fc2
This commit is contained in:
JW Wang 2016-09-06 11:01:57 +08:00
Родитель 2487c1c0d0
Коммит 733e1bae5a
2 изменённых файлов: 78 добавлений и 3 удалений

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

@ -204,6 +204,41 @@ SuspendBackgroundVideoDelay()
MediaPrefs::MDSMSuspendBackgroundVideoDelay());
}
class MediaDecoderStateMachine::StateObject
{
public:
virtual ~StateObject() {}
virtual void Enter() {}; // Entry action.
virtual void Exit() {}; // Exit action.
virtual void Step() {} // Perform a 'cycle' of this state object.
virtual State GetState() const = 0;
protected:
using Master = MediaDecoderStateMachine;
explicit StateObject(Master* aPtr) : mMaster(aPtr) {}
// Take a raw pointer in order not to change the life cycle of MDSM.
// It is guaranteed to be valid by MDSM.
Master* mMaster;
};
class MediaDecoderStateMachine::DecodeMetadataState
: public MediaDecoderStateMachine::StateObject
{
public:
explicit DecodeMetadataState(Master* aPtr) : StateObject(aPtr) {}
void Enter() override
{
mMaster->ReadMetadata();
}
State GetState() const override
{
return DECODER_STATE_DECODING_METADATA;
}
};
#define INIT_WATCHABLE(name, val) \
name(val, "MediaDecoderStateMachine::" #name)
#define INIT_MIRROR(name, val) \
@ -223,6 +258,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mDispatchedStateMachine(false),
mDelayedScheduler(mTaskQueue),
INIT_WATCHABLE(mState, DECODER_STATE_DECODING_METADATA),
mStateObj(new DecodeMetadataState(this)),
mCurrentFrameID(0),
INIT_WATCHABLE(mObservedDuration, TimeUnit()),
mFragmentEndTime(-1),
@ -1065,6 +1101,16 @@ MediaDecoderStateMachine::SetState(State aState)
ExitState();
mState = aState;
switch (mState) {
case DECODER_STATE_DECODING_METADATA:
mStateObj = MakeUnique<DecodeMetadataState>(this);
break;
default:
mStateObj = nullptr;
break;
}
EnterState();
}
@ -1072,6 +1118,13 @@ void
MediaDecoderStateMachine::ExitState()
{
MOZ_ASSERT(OnTaskQueue());
if (mStateObj) {
MOZ_ASSERT(mState == mStateObj->GetState());
mStateObj->Exit();
return;
}
switch (mState) {
case DECODER_STATE_COMPLETED:
mSentPlaybackEndedEvent = false;
@ -1088,10 +1141,14 @@ void
MediaDecoderStateMachine::EnterState()
{
MOZ_ASSERT(OnTaskQueue());
if (mStateObj) {
MOZ_ASSERT(mState == mStateObj->GetState());
mStateObj->Enter();
return;
}
switch (mState) {
case DECODER_STATE_DECODING_METADATA:
ReadMetadata();
break;
case DECODER_STATE_DORMANT:
DiscardSeekTaskIfExist();
if (IsPlaying()) {
@ -2263,6 +2320,11 @@ MediaDecoderStateMachine::RunStateMachine()
mDelayedScheduler.Reset(); // Must happen on state machine task queue.
mDispatchedStateMachine = false;
if (mStateObj) {
mStateObj->Step();
return;
}
switch (mState) {
case DECODER_STATE_DECODING:
StepDecoding();

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

@ -251,6 +251,17 @@ public:
size_t SizeOfAudioQueue() const;
private:
class StateObject;
class DecodeMetadataState;
class WaitForCDMState;
class DormantState;
class DecodingFirstFrameState;
class DecodingState;
class SeekingState;
class BufferingState;
class CompletedState;
class ShutdownState;
static const char* ToStateStr(State aState);
const char* ToStateStr();
@ -603,6 +614,8 @@ private:
// Accessed on state machine, audio, main, and AV thread.
Watchable<State> mState;
UniquePtr<StateObject> mStateObj;
// Time that buffering started. Used for buffering timeout and only
// accessed on the state machine thread. This is null while we're not
// buffering.