Bug 1314884. Part 5 - pass StateObject::EventVisibility to SeekingState::Enter() to indicate whether to publish events during seek.
Note EventVisibility::Suppressed is used by internal seeks only like video-only seek or exit-dormant seek.
MozReview-Commit-ID: 6jlCWRJsmdI
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -212,16 +212,22 @@ public:
virtual void DumpDebugInfo() {}
private:
template <class S, typename R, typename... As>
auto ReturnTypeHelper(R(S::*)(As...)) -> R;
protected:
+ enum class EventVisibility : int8_t
+ {
+ Observable,
+ Suppressed
+ };
+
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; }
const MediaInfo& Info() const { return mMaster->Info(); }
bool IsExpectingMoreData() const
{
@@ -744,17 +750,18 @@ private:
* DECODING otherwise.
*/
class MediaDecoderStateMachine::SeekingState
: public MediaDecoderStateMachine::StateObject
{
public:
explicit SeekingState(Master* aPtr) : StateObject(aPtr) {}
- RefPtr<MediaDecoder::SeekPromise> Enter(SeekJob aSeekJob)
+ RefPtr<MediaDecoder::SeekPromise> Enter(SeekJob aSeekJob,
+ EventVisibility aVisibility)
{
mSeekJob = Move(aSeekJob);
// Always switch off the blank decoder otherwise we might become visible
// in the middle of seeking and won't have a valid video frame to show
// when seek is done.
if (mMaster->mVideoDecodeSuspended) {
mMaster->mVideoDecodeSuspended = false;
@@ -787,18 +794,17 @@ public:
// mSeekJob.mTarget.mTime might be different from
// mSeekTask->GetSeekTarget().mTime because the seek task might clamp the
// seek target to [0, duration]. We want to update the playback position to
// the clamped value.
mMaster->UpdatePlaybackPositionInternal(
mSeekTask->GetSeekTarget().GetTime().ToMicroseconds());
- if (mSeekJob.mTarget.mEventVisibility ==
- MediaDecoderEventVisibility::Observable) {
+ if (aVisibility == EventVisibility::Observable) {
mMaster->mOnPlaybackEvent.Notify(MediaEventType::SeekStarted);
}
// Reset our state machine and decoding pipeline before seeking.
if (mSeekTask->NeedToResetMDSM()) {
if (mSeekJob.mTarget.IsVideoOnly()) {
mMaster->Reset(TrackInfo::kVideoTrack);
} else {
@@ -1126,17 +1132,17 @@ public:
RefPtr<MediaDecoder::SeekPromise>
MediaDecoderStateMachine::
StateObject::HandleSeek(SeekTarget aTarget)
{
SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
SeekJob seekJob;
seekJob.mTarget = aTarget;
- return SetState<SeekingState>(Move(seekJob));
+ return SetState<SeekingState>(Move(seekJob), EventVisibility::Observable);
}
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::
StateObject::HandleShutdown()
{
return SetState<ShutdownState>();
}
@@ -1202,17 +1208,17 @@ StateObject::HandleResumeVideoDecoding()
? SeekTarget::Type::Accurate
: SeekTarget::Type::PrevSyncPoint;
seekJob.mTarget = SeekTarget(mMaster->GetMediaTime(),
type,
MediaDecoderEventVisibility::Suppressed,
true /* aVideoOnly */);
- SetState<SeekingState>(Move(seekJob))->Then(
+ SetState<SeekingState>(Move(seekJob), EventVisibility::Suppressed)->Then(
AbstractThread::MainThread(), __func__,
[start, info, hw](){ ReportRecoveryTelemetry(start, info, hw); },
[](){});
}
void
MediaDecoderStateMachine::
DecodeMetadataState::OnMetadataRead(MetadataHolder* aMetadata)
@@ -1279,17 +1285,17 @@ DecodeMetadataState::OnMetadataRead(Meta
void
MediaDecoderStateMachine::
DormantState::HandlePlayStateChanged(MediaDecoder::PlayState aPlayState)
{
if (aPlayState == MediaDecoder::PLAY_STATE_PLAYING) {
// Exit dormant when the user wants to play.
MOZ_ASSERT(!Info().IsEncrypted() || mMaster->mCDMProxy);
MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);
- SetState<SeekingState>(Move(mPendingSeek));
+ SetState<SeekingState>(Move(mPendingSeek), EventVisibility::Suppressed);
}
}
void
MediaDecoderStateMachine::
WaitForCDMState::HandleCDMProxyReady()
{
SetState<DecodingFirstFrameState>(Move(mPendingSeek));
@@ -1298,17 +1304,17 @@ WaitForCDMState::HandleCDMProxyReady()
void
MediaDecoderStateMachine::
DecodingFirstFrameState::Enter(SeekJob aPendingSeek)
{
// Handle pending seek.
if (aPendingSeek.Exists() &&
(mMaster->mSentFirstFrameLoadedEvent ||
Reader()->ForceZeroStartTime())) {
- SetState<SeekingState>(Move(aPendingSeek));
+ SetState<SeekingState>(Move(aPendingSeek), EventVisibility::Observable);
return;
}
// Transition to DECODING if we've decoded first frames.
if (mMaster->mSentFirstFrameLoadedEvent) {
SetState<DecodingState>();
return;
}
@@ -1352,17 +1358,17 @@ DecodingFirstFrameState::MaybeFinishDeco
if ((mMaster->IsAudioDecoding() && mMaster->AudioQueue().GetSize() == 0) ||
(mMaster->IsVideoDecoding() && mMaster->VideoQueue().GetSize() == 0)) {
return;
}
mMaster->FinishDecodeFirstFrame();
if (mPendingSeek.Exists()) {
- SetState<SeekingState>(Move(mPendingSeek));
+ SetState<SeekingState>(Move(mPendingSeek), EventVisibility::Observable);
} else {
SetState<DecodingState>();
}
}
void
MediaDecoderStateMachine::
DecodingState::Enter()