Bug 1352319. P3 - use TimeUnit in HasLowBufferedData().
MozReview-Commit-ID: HP7M78yKpww
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2451,17 +2451,17 @@ BufferingState::Step()
// we've not decoded enough data to begin playback, or if we've not
// downloaded a reasonable amount of data inside our buffering time.
if (Reader()->UseBufferingHeuristics()) {
TimeDuration elapsed = now - mBufferingStart;
bool isLiveStream = Resource()->IsLiveStream();
if ((isLiveStream || !mMaster->CanPlayThrough())
&& elapsed
< TimeDuration::FromSeconds(mBufferingWait * mMaster->mPlaybackRate)
- && mMaster->HasLowBufferedData(mBufferingWait * USECS_PER_S)
+ && mMaster->HasLowBufferedData(TimeUnit::FromSeconds(mBufferingWait))
&& IsExpectingMoreData()) {
SLOG("Buffering: wait %ds, timeout in %.3lfs",
mBufferingWait, mBufferingWait - elapsed.ToSeconds());
mMaster->ScheduleStateMachineIn(USECS_PER_S);
DispatchDecodeTasksIfNeeded();
return;
}
} else if (mMaster->OutOfDecodedAudio() || mMaster->OutOfDecodedVideo()) {
@@ -3310,68 +3310,67 @@ MediaDecoderStateMachine::HasLowDecodedD
bool MediaDecoderStateMachine::OutOfDecodedAudio()
{
MOZ_ASSERT(OnTaskQueue());
return IsAudioDecoding() && !AudioQueue().IsFinished()
&& AudioQueue().GetSize() == 0
&& !mMediaSink->HasUnplayedFrames(TrackInfo::kAudioTrack);
}
-bool MediaDecoderStateMachine::HasLowBufferedData()
+bool
+MediaDecoderStateMachine::HasLowBufferedData()
{
MOZ_ASSERT(OnTaskQueue());
- return HasLowBufferedData(detail::LOW_BUFFER_THRESHOLD.ToMicroseconds());
+ return HasLowBufferedData(detail::LOW_BUFFER_THRESHOLD);
}
-bool MediaDecoderStateMachine::HasLowBufferedData(int64_t aUsecs)
+bool
+MediaDecoderStateMachine::HasLowBufferedData(const TimeUnit& aThreshold)
{
MOZ_ASSERT(OnTaskQueue());
// If we don't have a duration, mBuffered is probably not going to have
// a useful buffered range. Return false here so that we don't get stuck in
// buffering mode for live streams.
if (Duration().IsInfinite()) {
return false;
}
if (mBuffered.Ref().IsInvalid()) {
return false;
}
// 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) {
+ TimeUnit endOfDecodedVideo = (HasVideo() && !VideoQueue().IsFinished())
+ ? TimeUnit::FromMicroseconds(mDecodedVideoEndTime)
+ : TimeUnit::FromInfinity();
+ TimeUnit endOfDecodedAudio = (HasAudio() && !AudioQueue().IsFinished())
+ ? TimeUnit::FromMicroseconds(mDecodedAudioEndTime)
+ : TimeUnit::FromInfinity();
+
+ auto endOfDecodedData = std::min(endOfDecodedVideo, endOfDecodedAudio);
+ if (Duration() < endOfDecodedData) {
// Our duration is not up to date. No point buffering.
return false;
}
- if (endOfDecodedData == INT64_MAX) {
+ if (endOfDecodedData.IsInfinite()) {
// Have decoded all samples. No point buffering.
return false;
}
- int64_t start = endOfDecodedData;
- int64_t end = std::min(GetMediaTime() + aUsecs, Duration().ToMicroseconds());
+ auto start = endOfDecodedData;
+ auto end = std::min(
+ TimeUnit::FromMicroseconds(GetMediaTime()) + aThreshold, Duration());
if (start >= end) {
// Duration of decoded samples is greater than our threshold.
return false;
}
- media::TimeInterval interval(media::TimeUnit::FromMicroseconds(start),
- media::TimeUnit::FromMicroseconds(end));
+ media::TimeInterval interval(start, end);
return !mBuffered.Ref().Contains(interval);
}
void
MediaDecoderStateMachine::DecodeError(const MediaResult& aError)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(!IsShutdown());
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -357,18 +357,18 @@ protected:
MOZ_ASSERT(OnTaskQueue());
return IsVideoDecoding() && VideoQueue().GetSize() <= 1;
}
// Returns true if we're running low on buffered data.
bool HasLowBufferedData();
- // Returns true if we have less than aUsecs of buffered data available.
- bool HasLowBufferedData(int64_t aUsecs);
+ // Returns true if we have less than aThreshold of buffered data available.
+ bool HasLowBufferedData(const media::TimeUnit& aThreshold);
void UpdateNextFrameStatus(NextFrameStatus aStatus);
// Return the current time, either the audio clock if available (if the media
// has audio, and the playback is possible), or a clock for the video.
// Called on the state machine thread.
// If aTimeStamp is non-null, set *aTimeStamp to the TimeStamp corresponding
// to the returned stream time.