Bug 1298606: [MSE] P2. Properly determine next frame status in ended state. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 27 Aug 2016 22:27:22 +1200
changeset 406612 190d2ee183ea9c2244eddf1d51deed76748f719f
parent 406611 16dc54f745ed99f23ea3ee175bc1f7e0b39b7088
child 406613 ae21b2455191afb64a67ade2eaa7df6b20c8a311
child 406629 2531f896fa0d6928ee9d222d3e2aea41fc4c4b0c
child 406631 072f680acd8b323f014fdcc7d5d39d395cb7dae6
push id27776
push userbmo:jyavenard@mozilla.com
push dateMon, 29 Aug 2016 07:12:53 +0000
reviewersgerald
bugs1298606
milestone51.0a1
Bug 1298606: [MSE] P2. Properly determine next frame status in ended state. r?gerald MozReview-Commit-ID: 2m05GzauHes
dom/media/mediasource/MediaSourceDecoder.cpp
--- 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