Bug 1307725. Part 4 - move MaybeStopPrerolling() into DecodingState.
MozReview-Commit-ID: JiedugPhOMU
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -563,17 +563,17 @@ public:
if (mMaster->CheckIfDecodeComplete()) {
SetState(DECODER_STATE_COMPLETED);
return;
}
mDecodeStartTime = TimeStamp::Now();
mMaster->mIsPrerolling = true;
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
// Ensure that we've got tasks enqueued to decode data if we need to.
mMaster->DispatchDecodeTasksIfNeeded();
mMaster->ScheduleStateMachine();
}
void Exit() override
@@ -609,24 +609,24 @@ public:
State GetState() const override
{
return DECODER_STATE_DECODING;
}
bool HandleAudioDecoded(MediaData* aAudio) override
{
mMaster->Push(aAudio, MediaData::AUDIO_DATA);
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
return true;
}
bool HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
{
mMaster->Push(aVideo, MediaData::VIDEO_DATA);
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
CheckSlowDecoding(aDecodeStart);
return true;
}
RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
{
mMaster->mQueuedSeek.RejectIfExists(__func__);
SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
@@ -637,30 +637,30 @@ public:
return p.forget();
}
bool HandleEndOfStream() override
{
if (mMaster->CheckIfDecodeComplete()) {
SetState(DECODER_STATE_COMPLETED);
} else {
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
}
return true;
}
bool HandleWaitingForData() override
{
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
return true;
}
bool HandleAudioCaptured() override
{
- mMaster->MaybeStopPrerolling();
+ MaybeStopPrerolling();
// MediaSink is changed. Schedule Step() to check if we can start playback.
mMaster->ScheduleStateMachine();
return true;
}
private:
void CheckSlowDecoding(TimeStamp aDecodeStart)
{
@@ -688,16 +688,27 @@ private:
SLOG("Slow video decode, set "
"mLowAudioThresholdUsecs=%lld "
"mAmpleAudioThresholdUsecs=%lld",
mMaster->mLowAudioThresholdUsecs,
mMaster->mAmpleAudioThresholdUsecs);
}
}
+ void MaybeStopPrerolling()
+ {
+ if (mMaster->mIsPrerolling &&
+ (mMaster->DonePrerollingAudio() || Reader()->IsWaitingAudioData()) &&
+ (mMaster->DonePrerollingVideo() || Reader()->IsWaitingVideoData())) {
+ mMaster->mIsPrerolling = false;
+ // Check if we can start playback.
+ mMaster->ScheduleStateMachine();
+ }
+ }
+
// Time at which we started decoding.
TimeStamp mDecodeStartTime;
};
class MediaDecoderStateMachine::SeekingState
: public MediaDecoderStateMachine::StateObject
{
public:
@@ -1747,29 +1758,16 @@ void MediaDecoderStateMachine::StopPlayb
if (IsPlaying()) {
mMediaSink->SetPlaying(false);
MOZ_ASSERT(!IsPlaying());
}
DispatchDecodeTasksIfNeeded();
}
-void
-MediaDecoderStateMachine::MaybeStopPrerolling()
-{
- MOZ_ASSERT(OnTaskQueue());
- if (mIsPrerolling &&
- (DonePrerollingAudio() || mReader->IsWaitingAudioData()) &&
- (DonePrerollingVideo() || mReader->IsWaitingVideoData())) {
- mIsPrerolling = false;
- // Check if we can start playback.
- ScheduleStateMachine();
- }
-}
-
void MediaDecoderStateMachine::MaybeStartPlayback()
{
MOZ_ASSERT(OnTaskQueue());
// Should try to start playback only after decoding first frames.
MOZ_ASSERT(mSentFirstFrameLoadedEvent);
MOZ_ASSERT(mState == DECODER_STATE_DECODING ||
mState == DECODER_STATE_COMPLETED);
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -687,18 +687,16 @@ private:
bool DonePrerollingVideo()
{
MOZ_ASSERT(OnTaskQueue());
return !IsVideoDecoding() ||
static_cast<uint32_t>(VideoQueue().GetSize()) >=
VideoPrerollFrames() * mPlaybackRate + 1;
}
- void MaybeStopPrerolling();
-
// When we start decoding (either for the first time, or after a pause)
// we may be low on decoded data. We don't want our "low data" logic to
// kick in and decide that we're low on decoded data because the download
// can't keep up with the decode, and cause us to pause playback. So we
// have a "preroll" stage, where we ignore the results of our "low data"
// logic during the first few frames of our decode. This occurs during
// playback.
bool mIsPrerolling = false;