Bug 1298606: [MSE] P2. Properly determine next frame status in ended state. r?gerald
MozReview-Commit-ID: 2m05GzauHes
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -272,20 +272,23 @@ MediaSourceDecoder::NextFrameBufferedSta
if (!mMediaSource ||
mMediaSource->ReadyState() == dom::MediaSourceReadyState::Closed) {
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
// Next frame hasn't been decoded yet.
// Use the buffered range to consider if we have the next frame available.
TimeUnit currentPosition = TimeUnit::FromMicroseconds(CurrentPosition());
- TimeInterval interval(currentPosition,
- currentPosition + media::TimeUnit::FromMicroseconds(DEFAULT_NEXT_FRAME_AVAILABLE_BUFFERED),
- MediaSourceDemuxer::EOS_FUZZ);
- return GetBuffered().Contains(ClampIntervalToEnd(interval))
+ TimeIntervals buffered = GetBuffered();
+ buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
+ TimeInterval interval(
+ currentPosition,
+ currentPosition
+ + media::TimeUnit::FromMicroseconds(DEFAULT_NEXT_FRAME_AVAILABLE_BUFFERED));
+ return buffered.ContainsStrict(ClampIntervalToEnd(interval))
? MediaDecoderOwner::NEXT_FRAME_AVAILABLE
: MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
bool
MediaSourceDecoder::CanPlayThrough()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -303,22 +306,22 @@ MediaSourceDecoder::CanPlayThrough()
if (duration.IsInfinite()) {
// We can't make an informed decision and just assume that it's a live stream
return true;
} else if (duration <= currentPosition) {
return true;
}
// If we have data up to the mediasource's duration or 30s ahead, we can
// assume that we can play without interruption.
+ TimeIntervals buffered = GetBuffered();
+ buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
TimeUnit timeAhead =
std::min(duration, currentPosition + TimeUnit::FromSeconds(30));
- TimeInterval interval(currentPosition,
- timeAhead,
- MediaSourceDemuxer::EOS_FUZZ);
- return GetBuffered().Contains(ClampIntervalToEnd(interval));
+ TimeInterval interval(currentPosition, timeAhead);
+ return buffered.ContainsStrict(ClampIntervalToEnd(interval));
}
void
MediaSourceDecoder::NotifyWaitingForKey()
{
mWaitingForKeyEvent.Notify();
}
@@ -331,16 +334,21 @@ MediaSourceDecoder::WaitingForKeyEvent()
TimeInterval
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
{
MOZ_ASSERT(NS_IsMainThread());
if (!mEnded) {
return aInterval;
}
- TimeInterval interval(TimeUnit(), TimeUnit::FromSeconds(GetDuration()));
- return aInterval.Intersection(interval);
+ TimeUnit duration = TimeUnit::FromSeconds(GetDuration());
+ if (duration < aInterval.mStart) {
+ return aInterval;
+ }
+ return TimeInterval(aInterval.mStart,
+ std::min(aInterval.mEnd, duration),
+ aInterval.mFuzz);
}
#undef MSE_DEBUG
#undef MSE_DEBUGV
} // namespace mozilla