Bug 1300711 - Remove MediaDecoderStateMachine::mQuickBuffering. r=cpearce

MozReview-Commit-ID: GW7bhY6ruKG

--HG--
extra : rebase_source : 272c297ffa1e5b1034992b6a2b35e5949fb26b84
This commit is contained in:
JW Wang 2016-09-06 16:28:20 +08:00
parent 8599325724
commit 5564be70f2
2 changed files with 4 additions and 71 deletions

View File

@ -142,36 +142,6 @@ static_assert(LOW_DATA_THRESHOLD_USECS > AMPLE_AUDIO_USECS,
// Amount of excess usecs of data to add in to the "should we buffer" calculation.
static const uint32_t EXHAUSTED_DATA_MARGIN_USECS = 100000;
// If we enter buffering within QUICK_BUFFER_THRESHOLD_USECS seconds of starting
// decoding, we'll enter "quick buffering" mode, which exits a lot sooner than
// normal buffering mode. This exists so that if the decode-ahead exhausts the
// downloaded data while decode/playback is just starting up (for example
// after a seek while the media is still playing, or when playing a media
// as soon as it's load started), we won't necessarily stop for 30s and wait
// for buffering. We may actually be able to playback in this case, so exit
// buffering early and try to play. If it turns out we can't play, we'll fall
// back to buffering normally.
static const uint32_t QUICK_BUFFER_THRESHOLD_USECS = 2000000;
namespace detail {
// If we're quick buffering, we'll remain in buffering mode while we have less than
// QUICK_BUFFERING_LOW_DATA_USECS of decoded data available.
static const uint32_t QUICK_BUFFERING_LOW_DATA_USECS = 1000000;
// If QUICK_BUFFERING_LOW_DATA_USECS is > AMPLE_AUDIO_USECS, we won't exit
// quick buffering in a timely fashion, as the decode pauses when it
// reaches AMPLE_AUDIO_USECS decoded data, and thus we'll never reach
// QUICK_BUFFERING_LOW_DATA_USECS.
static_assert(QUICK_BUFFERING_LOW_DATA_USECS <= AMPLE_AUDIO_USECS,
"QUICK_BUFFERING_LOW_DATA_USECS is too large");
} // namespace detail
static TimeDuration UsecsToDuration(int64_t aUsecs) {
return TimeDuration::FromMicroseconds(aUsecs);
}
static int64_t DurationToUsecs(TimeDuration aDuration) {
return static_cast<int64_t>(aDuration.ToSeconds() * USECS_PER_S);
}
@ -611,14 +581,12 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mPlaybackRate(1.0),
mLowAudioThresholdUsecs(detail::LOW_AUDIO_USECS),
mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_USECS),
mQuickBufferingLowDataThresholdUsecs(detail::QUICK_BUFFERING_LOW_DATA_USECS),
mIsAudioPrerolling(false),
mIsVideoPrerolling(false),
mAudioCaptured(false),
INIT_WATCHABLE(mAudioCompleted, false),
INIT_WATCHABLE(mVideoCompleted, false),
mNotifyMetadataBeforeFirstFrame(false),
mQuickBuffering(false),
mMinimizePreroll(false),
mDecodeThreadWaiting(false),
mSentLoadedMetadataEvent(false),
@ -1386,7 +1354,7 @@ MediaDecoderStateMachine::MaybeStartBuffering()
bool shouldBuffer;
if (mReader->UseBufferingHeuristics()) {
shouldBuffer = HasLowDecodedData(EXHAUSTED_DATA_MARGIN_USECS) &&
(JustExitedQuickBuffering() || HasLowBufferedData());
HasLowBufferedData();
} else {
MOZ_ASSERT(mReader->IsWaitForDataSupported());
shouldBuffer = (OutOfDecodedAudio() && mReader->IsWaitingAudioData()) ||
@ -2470,11 +2438,6 @@ MediaDecoderStateMachine::SeekCompleted()
// Try to decode another frame to detect if we're at the end...
DECODER_LOG("Seek completed, mCurrentPosition=%lld", mCurrentPosition.Ref());
// Reset quick buffering status. This ensures that if we began the
// seek while quick-buffering, we won't bypass quick buffering mode
// if we need to buffer after the seek.
mQuickBuffering = false;
if (video) {
mMediaSink->Redraw(mInfo.mVideo);
mOnPlaybackEvent.Notify(MediaEventType::Invalidate);
@ -2550,12 +2513,10 @@ MediaDecoderStateMachine::StepBuffering()
bool isLiveStream = mResource->IsLiveStream();
if ((isLiveStream || !CanPlayThrough()) &&
elapsed < TimeDuration::FromSeconds(mBufferingWait * mPlaybackRate) &&
(mQuickBuffering ? HasLowDecodedData(mQuickBufferingLowDataThresholdUsecs)
: HasLowBufferedData(mBufferingWait * USECS_PER_S)) &&
HasLowBufferedData(mBufferingWait * USECS_PER_S) &&
mResource->IsExpectingMoreData()) {
DECODER_LOG("Buffering: wait %ds, timeout in %.3lfs %s",
mBufferingWait, mBufferingWait - elapsed.ToSeconds(),
(mQuickBuffering ? "(quick exit)" : ""));
DECODER_LOG("Buffering: wait %ds, timeout in %.3lfs",
mBufferingWait, mBufferingWait - elapsed.ToSeconds());
ScheduleStateMachineIn(USECS_PER_S);
return;
}
@ -2755,14 +2716,6 @@ void MediaDecoderStateMachine::UpdateNextFrameStatus()
mNextFrameStatus = status;
}
bool MediaDecoderStateMachine::JustExitedQuickBuffering()
{
MOZ_ASSERT(OnTaskQueue());
return !mDecodeStartTime.IsNull() &&
mQuickBuffering &&
(TimeStamp::Now() - mDecodeStartTime) < TimeDuration::FromMicroseconds(QUICK_BUFFER_THRESHOLD_USECS);
}
bool
MediaDecoderStateMachine::CanPlayThrough()
{
@ -2796,12 +2749,6 @@ MediaDecoderStateMachine::StartBuffering()
}
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();
DECODER_LOG("Changed state from DECODING to BUFFERING, decoded for %.3lfs",

View File

@ -411,9 +411,6 @@ protected:
// The decoder monitor must be held.
bool HasFutureAudio();
// Returns true if we recently exited "quick buffering" mode.
bool JustExitedQuickBuffering();
// Recomputes mNextFrameStatus, possibly dispatching notifications to interested
// parties.
void UpdateNextFrameStatus();
@ -712,10 +709,6 @@ private:
// we detect that the decode can't keep up with rendering.
int64_t mAmpleAudioThresholdUsecs;
// If we're quick buffering, we'll remain in buffering mode while we have less than
// QUICK_BUFFERING_LOW_DATA_USECS of decoded data available.
int64_t mQuickBufferingLowDataThresholdUsecs;
// At the start of decoding we want to "preroll" the decode until we've
// got a few frames decoded before we consider whether decode is falling
// behind. Otherwise our "we're falling behind" logic will trigger
@ -818,13 +811,6 @@ private:
// simplified.
bool mNotifyMetadataBeforeFirstFrame;
// If this is true while we're in buffering mode, we can exit early,
// as it's likely we may be able to playback. This happens when we enter
// buffering mode soon after the decode starts, because the decode-ahead
// ran fast enough to exhaust all data while the download is starting up.
// Synchronised via decoder monitor.
bool mQuickBuffering;
// True if we should not decode/preroll unnecessary samples, unless we're
// played. "Prerolling" in this context refers to when we decode and
// buffer decoded samples in advance of when they're needed for playback.