Bug 1298217. Part 11 - Move some code to the entry action of DECODER_STATE_BUFFERING.
MozReview-Commit-ID: BCtmXQi2zNg
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -987,21 +987,17 @@ MediaDecoderStateMachine::MaybeStartBuff
shouldBuffer = HasLowDecodedData(EXHAUSTED_DATA_MARGIN_USECS) &&
(JustExitedQuickBuffering() || HasLowUndecodedData());
} else {
MOZ_ASSERT(mReader->IsWaitForDataSupported());
shouldBuffer = (OutOfDecodedAudio() && mReader->IsWaitingAudioData()) ||
(OutOfDecodedVideo() && mReader->IsWaitingVideoData());
}
if (shouldBuffer) {
- StartBuffering();
- // Don't go straight back to the state machine loop since that might
- // cause us to start decoding again and we could flip-flop between
- // decoding and quick-buffering.
- ScheduleStateMachineIn(USECS_PER_S);
+ SetState(DECODER_STATE_BUFFERING);
}
}
}
void MediaDecoderStateMachine::UpdatePlaybackPositionInternal(int64_t aTime)
{
MOZ_ASSERT(OnTaskQueue());
SAMPLE_LOG("UpdatePlaybackPositionInternal(%lld)", aTime);
@@ -1093,16 +1089,19 @@ MediaDecoderStateMachine::EnterState(Sta
StopPlayback();
}
Reset();
mReader->ReleaseResources();
break;
case DECODER_STATE_DECODING:
StartDecoding();
break;
+ case DECODER_STATE_BUFFERING:
+ StartBuffering();
+ break;
case DECODER_STATE_COMPLETED:
ScheduleStateMachine();
break;
case DECODER_STATE_ERROR:
case DECODER_STATE_SHUTDOWN:
mIsShutdown = true;
break;
default:
@@ -2557,41 +2556,46 @@ MediaDecoderStateMachine::GetStatistics(
result.mTotalBytes = mResource->GetLength();
result.mPlaybackRate = mPlaybackBytesPerSecond;
result.mPlaybackRateReliable = mPlaybackRateReliable;
result.mDecoderPosition = mDecoderPosition;
result.mPlaybackPosition = mPlaybackOffset;
return result;
}
-void MediaDecoderStateMachine::StartBuffering()
+void
+MediaDecoderStateMachine::StartBuffering()
{
MOZ_ASSERT(OnTaskQueue());
- MOZ_ASSERT(mState == DECODER_STATE_DECODING);
+ MOZ_ASSERT(mState == DECODER_STATE_BUFFERING);
if (IsPlaying()) {
StopPlayback();
}
TimeDuration decodeDuration = TimeStamp::Now() - mDecodeStartTime;
// Go into quick buffering mode provided we've not just left buffering using
// a "quick exit". This stops us flip-flopping between playing and buffering
// when the download speed is similar to the decode speed.
mQuickBuffering =
!JustExitedQuickBuffering() &&
decodeDuration < UsecsToDuration(QUICK_BUFFER_THRESHOLD_USECS);
mBufferingStart = TimeStamp::Now();
- SetState(DECODER_STATE_BUFFERING);
DECODER_LOG("Changed state from DECODING to BUFFERING, decoded for %.3lfs",
decodeDuration.ToSeconds());
MediaStatistics stats = GetStatistics();
DECODER_LOG("Playback rate: %.1lfKB/s%s download rate: %.1lfKB/s%s",
stats.mPlaybackRate/1024, stats.mPlaybackRateReliable ? "" : " (unreliable)",
stats.mDownloadRate/1024, stats.mDownloadRateReliable ? "" : " (unreliable)");
+
+ // Don't go straight back to the state machine loop since that might
+ // cause us to start decoding again and we could flip-flop between
+ // decoding and quick-buffering.
+ ScheduleStateMachineIn(USECS_PER_S);
}
void
MediaDecoderStateMachine::ScheduleStateMachine()
{
MOZ_ASSERT(OnTaskQueue());
if (mDispatchedStateMachine) {
return;