diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 2580bb550bfe..fbd31297906b 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -225,6 +225,8 @@ public: virtual nsCString GetDebugInfo() { return nsCString(); } + virtual void HandleLoopingChanged() {} + private: template auto ReturnTypeHelper(R(S::*)(As...)) -> R; @@ -305,6 +307,8 @@ protected: RefPtr SetSeekingState(SeekJob&& aSeekJob, EventVisibility aVisibility); + void SetDecodingState(); + // Take a raw pointer in order not to change the life cycle of MDSM. // It is guaranteed to be valid by MDSM. Master* mMaster; @@ -706,6 +710,11 @@ public: return nsPrintfCString("mIsPrerolling=%d", mIsPrerolling); } + void HandleLoopingChanged() override + { + SetDecodingState(); + } + protected: virtual void EnsureAudioDecodeTaskQueued(); @@ -828,7 +837,9 @@ class MediaDecoderStateMachine::LoopingDecodingState public: explicit LoopingDecodingState(Master* aPtr) : DecodingState(aPtr) - {} + { + MOZ_ASSERT(mMaster->mLooping); + } void Exit() override { @@ -1018,7 +1029,7 @@ protected: virtual void DoSeek() = 0; // Transition to the next state (defined by the subclass) when seek is completed. - virtual void GoToNextState() { SetState(); } + virtual void GoToNextState() { SetDecodingState(); } void SeekCompleted(); virtual TimeUnit CalculateNewCurrentTime() const = 0; }; @@ -2297,6 +2308,16 @@ StateObject::SetSeekingState(SeekJob&& aSeekJob, EventVisibility aVisibility) return nullptr; } +void +MediaDecoderStateMachine::StateObject::SetDecodingState() +{ + if (mMaster->mLooping) { + SetState(); + return; + } + SetState(); +} + void MediaDecoderStateMachine:: DecodeMetadataState::OnMetadataRead(MetadataHolder&& aMetadata) @@ -2367,7 +2388,7 @@ DecodingFirstFrameState::Enter() { // Transition to DECODING if we've decoded first frames. if (mMaster->mSentFirstFrameLoadedEvent) { - SetState(); + SetDecodingState(); return; } @@ -2397,7 +2418,7 @@ DecodingFirstFrameState::MaybeFinishDecodeFirstFrame() if (mPendingSeek.Exists()) { SetSeekingState(std::move(mPendingSeek), EventVisibility::Observable); } else { - SetState(); + SetDecodingState(); } } @@ -2713,7 +2734,7 @@ BufferingState::Step() } SLOG("Buffered for %.3lfs", (now - mBufferingStart).ToSeconds()); - SetState(); + SetDecodingState(); } void @@ -3786,9 +3807,7 @@ void MediaDecoderStateMachine::LoopingChanged() { MOZ_ASSERT(OnTaskQueue()); - if (mSeamlessLoopingAllowed) { - mReader->SetSeamlessLoopingEnabled(mLooping); - } + mStateObj->HandleLoopingChanged(); } RefPtr