Bug 1269249: [MSE] P1. Clamp range to media source duration when media source is ended. r?jwwang
MozReview-Commit-ID: KncGDdTISQ8
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -263,17 +263,17 @@ MediaSourceDecoder::NextFrameBufferedSta
}
// 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(interval)
+ return GetBuffered().Contains(ClampIntervalToEnd(interval))
? MediaDecoderOwner::NEXT_FRAME_AVAILABLE
: MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
bool
MediaSourceDecoder::CanPlayThrough()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -296,15 +296,25 @@ MediaSourceDecoder::CanPlayThrough()
}
// If we have data up to the mediasource's duration or 30s ahead, we can
// assume that we can play without interruption.
TimeUnit timeAhead =
std::min(duration, currentPosition + TimeUnit::FromSeconds(30));
TimeInterval interval(currentPosition,
timeAhead,
MediaSourceDemuxer::EOS_FUZZ);
- return GetBuffered().Contains(interval);
+ return GetBuffered().Contains(ClampIntervalToEnd(interval));
+}
+
+TimeInterval
+MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
+{
+ if (!mEnded) {
+ return aInterval;
+ }
+ TimeInterval interval(TimeUnit(), TimeUnit::FromSeconds(GetDuration()));
+ return aInterval.Intersection(interval);
}
#undef MSE_DEBUG
#undef MSE_DEBUGV
} // namespace mozilla
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -78,16 +78,17 @@ public:
void AddSizeOfResources(ResourceSizes* aSizes) override;
MediaDecoderOwner::NextFrameStatus NextFrameBufferedStatus() override;
bool CanPlayThrough() override;
private:
void DoSetMediaSourceDuration(double aDuration);
+ media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval);
// The owning MediaSource holds a strong reference to this decoder, and
// calls Attach/DetachMediaSource on this decoder to set and clear
// mMediaSource.
dom::MediaSource* mMediaSource;
RefPtr<MediaSourceDemuxer> mDemuxer;
RefPtr<MediaFormatReader> mReader;