Bug 1302006. Part 4 - Let StateObject handle dormant request.
MozReview-Commit-ID: FK3UwbYDexV
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -218,17 +218,33 @@ 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;
// Event handlers for various events.
// Return true if the event is handled by this state object.
- virtual bool HandleDormant(bool aDormant) { return false; }
+ virtual bool HandleDormant(bool aDormant)
+ {
+ if (!aDormant) {
+ return true;
+ }
+ mMaster->mQueuedSeek.mTarget =
+ SeekTarget(mMaster->mCurrentPosition,
+ SeekTarget::Accurate,
+ MediaDecoderEventVisibility::Suppressed);
+ // SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
+ // need to create the promise even it is not used at all.
+ RefPtr<MediaDecoder::SeekPromise> unused =
+ mMaster->mQueuedSeek.mPromise.Ensure(__func__);
+ SetState(DECODER_STATE_DORMANT);
+ return true;
+ }
+
virtual bool HandleCDMProxyReady() { return false; }
protected:
using Master = MediaDecoderStateMachine;
explicit StateObject(Master* aPtr) : mMaster(aPtr) {}
TaskQueue* OwnerThread() const { return mMaster->mTaskQueue; }
MediaResource* Resource() const { return mMaster->mResource; }
MediaDecoderReaderWrapper* Reader() const { return mMaster->mReader; }
@@ -1517,40 +1533,17 @@ MediaDecoderStateMachine::DispatchSetDor
this, &MediaDecoderStateMachine::SetDormant, aDormant);
OwnerThread()->Dispatch(r.forget());
}
void
MediaDecoderStateMachine::SetDormant(bool aDormant)
{
MOZ_ASSERT(OnTaskQueue());
-
- if (mStateObj->HandleDormant(aDormant)) {
- return;
- }
-
- // These states are already handled by |mStateObj->HandleDormant| above.
- MOZ_ASSERT(mState != DECODER_STATE_DORMANT &&
- mState != DECODER_STATE_SEEKING);
-
- // Nothing to do for we are not in dormant state.
- if (!aDormant) {
- return;
- }
-
- DECODER_LOG("Enter dormant state");
-
- mQueuedSeek.mTarget = SeekTarget(mCurrentPosition,
- SeekTarget::Accurate,
- MediaDecoderEventVisibility::Suppressed);
- // SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
- // need to create the promise even it is not used at all.
- RefPtr<MediaDecoder::SeekPromise> unused = mQueuedSeek.mPromise.Ensure(__func__);
-
- SetState(DECODER_STATE_DORMANT);
+ mStateObj->HandleDormant(aDormant);
}
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::Shutdown()
{
MOZ_ASSERT(OnTaskQueue());
SetState(DECODER_STATE_SHUTDOWN);