Bug 1114840 - Dynamically compute preroll thresholds. r=cpearce

Currently, the preroll threshold ends up higher than the ample threshold in the
audio-only case where we slash the audio thresholds by a factor of 8. The best
way to avoid these sorts of bugs is to compute the values dynamically.
This commit is contained in:
Bobby Holley 2014-12-29 23:16:48 -08:00
parent 01990f4d69
commit c3291e8b61
3 changed files with 15 additions and 7 deletions

View File

@ -232,9 +232,6 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mBufferingWait = mScheduler->IsRealTime() ? 0 : 30;
mLowDataThresholdUsecs = mScheduler->IsRealTime() ? 0 : LOW_DATA_THRESHOLD_USECS;
mVideoPrerollFrames = mScheduler->IsRealTime() ? 0 : mAmpleVideoFrames / 2;
mAudioPrerollUsecs = mScheduler->IsRealTime() ? 0 : LOW_AUDIO_USECS * 2;
#ifdef XP_WIN
// Ensure high precision timers are enabled on Windows, otherwise the state
// machine thread isn't woken up at reliable intervals to set the next frame,
@ -638,7 +635,7 @@ MediaDecoderStateMachine::DecodeVideo()
// some frames before enabling the keyframe skip logic on video.
if (mIsVideoPrerolling &&
(static_cast<uint32_t>(VideoQueue().GetSize())
>= mVideoPrerollFrames * mPlaybackRate))
>= VideoPrerollFrames() * mPlaybackRate))
{
mIsVideoPrerolling = false;
}
@ -698,7 +695,7 @@ MediaDecoderStateMachine::DecodeAudio()
// only just started up the decode loop, so wait until we've decoded
// some audio data before enabling the keyframe skip logic on audio.
if (mIsAudioPrerolling &&
GetDecodedAudioDuration() >= mAudioPrerollUsecs * mPlaybackRate) {
GetDecodedAudioDuration() >= AudioPrerollUsecs() * mPlaybackRate) {
mIsAudioPrerolling = false;
}
}

View File

@ -89,6 +89,7 @@ hardware (via AudioStream).
#include "MediaDecoderReader.h"
#include "MediaDecoderOwner.h"
#include "MediaMetadataManager.h"
#include "MediaDecoderStateMachineScheduler.h"
class nsITimer;
@ -943,8 +944,17 @@ protected:
// unneccessarily if we start playing as soon as the first sample is
// decoded. These two fields store how many video frames and audio
// samples we must consume before are considered to be finished prerolling.
uint32_t mAudioPrerollUsecs;
uint32_t mVideoPrerollFrames;
uint32_t AudioPrerollUsecs() const
{
if (mScheduler->IsRealTime()) {
return 0;
}
uint32_t result = mLowAudioThresholdUsecs * 2;
MOZ_ASSERT(result <= mAmpleAudioThresholdUsecs, "Prerolling will never finish");
return result;
}
uint32_t VideoPrerollFrames() const { return mScheduler->IsRealTime() ? 0 : mAmpleVideoFrames / 2; }
// This temporarily stores the first frame we decode after we seek.
// This is so that if we hit end of stream while we're decoding to reach

View File

@ -102,6 +102,7 @@ EXPORTS += [
'MediaDecoderOwner.h',
'MediaDecoderReader.h',
'MediaDecoderStateMachine.h',
'MediaDecoderStateMachineScheduler.h',
'MediaInfo.h',
'MediaMetadataManager.h',
'MediaPromise.h',