From 4aa02e19414bca91985ed913609d17597312f5f9 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Wed, 27 Jan 2016 15:12:49 +0800 Subject: [PATCH] Bug 1242845 - Make the computation of MediaDecoderStateMachine::HasLowUndecodedData() more accurate and consistent. r=jya. --- dom/media/MediaDecoderStateMachine.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 206cb598fdc..317039e5de5 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1877,14 +1877,17 @@ bool MediaDecoderStateMachine::HasLowUndecodedData(int64_t aUsecs) return false; } - int64_t endOfDecodedVideoData = INT64_MAX; - if (HasVideo() && !VideoQueue().AtEndOfStream()) { - endOfDecodedVideoData = VideoQueue().Peek() ? VideoQueue().Peek()->GetEndTime() : VideoEndTime(); - } - int64_t endOfDecodedAudioData = INT64_MAX; - if (HasAudio() && !AudioQueue().AtEndOfStream()) { - endOfDecodedAudioData = mDecodedAudioEndTime; - } + // We are never low in decoded data when we don't have audio/video or have + // decoded all audio/video samples. + int64_t endOfDecodedVideoData = + (HasVideo() && !VideoQueue().IsFinished()) ? + mDecodedVideoEndTime : + INT64_MAX; + int64_t endOfDecodedAudioData = + (HasAudio() && !AudioQueue().IsFinished()) ? + mDecodedAudioEndTime : + INT64_MAX; + int64_t endOfDecodedData = std::min(endOfDecodedVideoData, endOfDecodedAudioData); if (Duration().ToMicroseconds() < endOfDecodedData) { // Our duration is not up to date. No point buffering.