Bug 1314884. Part 1 - move the calculation of seek target into DormantState::Enter() so we don't need to pass a SeekJob to the function.
MozReview-Commit-ID: FyFp509dxwl
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -398,22 +398,32 @@ private:
* SEEKING if any seek request.
*/
class MediaDecoderStateMachine::DormantState
: public MediaDecoderStateMachine::StateObject
{
public:
explicit DormantState(Master* aPtr) : StateObject(aPtr) {}
- void Enter(SeekJob aPendingSeek)
+ void Enter()
{
- mPendingSeek = Move(aPendingSeek);
if (mMaster->IsPlaying()) {
mMaster->StopPlayback();
}
+
+ // Calculate the position to seek to when exiting dormant.
+ auto t = mMaster->mMediaSink->IsStarted()
+ ? mMaster->GetClock()
+ : mMaster->GetMediaTime();
+ mPendingSeek.mTarget = SeekTarget(
+ t, 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> x = mPendingSeek.mPromise.Ensure(__func__);
+
mMaster->Reset();
mMaster->mReader->ReleaseResources();
}
void Exit() override
{
// mPendingSeek is either moved when exiting dormant or
// should be rejected here before transition to SHUTDOWN.
@@ -681,26 +691,17 @@ private:
mIsPrerolling = false;
// Check if we can start playback.
mMaster->ScheduleStateMachine();
}
}
void EnterDormant()
{
- auto t = mMaster->mMediaSink->IsStarted()
- ? mMaster->GetClock()
- : mMaster->GetMediaTime();
- SeekJob seekJob;
- seekJob.mTarget = SeekTarget(t, 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 = seekJob.mPromise.Ensure(__func__);
- SetState<DormantState>(Move(seekJob));
+ SetState<DormantState>();
}
void StartDormantTimer()
{
auto timeout = MediaPrefs::DormantOnPauseTimeout();
if (timeout < 0) {
// Disabled when timeout is negative.
return;