Commit e70e4587 authored by Paul Adenot's avatar Paul Adenot
Browse files

Bug 1835363 - Consistently return a positive range for...

Bug 1835363 - Consistently return a positive range for HTMLMediaElement.seekable. r=media-playback-reviewers,kinetik

Differential Revision: https://phabricator.services.mozilla.com/D179450
parent e7c5c25a
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -1295,31 +1295,40 @@ IntervalType MediaDecoder::GetSeekableImpl() {
    return IntervalType();
  }

  // Compute [0, duration] -- When dealing with doubles, use ::GetDuration to
  // avoid rounding the value differently. When dealing with TimeUnit, it's
  // returned directly.
  typename IntervalType::InnerType duration;
  if constexpr (std::is_same<typename IntervalType::InnerType, double>::value) {
    duration = GetDuration();
  } else {
    duration = mDuration.as<TimeUnit>();
  }
  typename IntervalType::ElemType zeroToDuration =
      typename IntervalType::ElemType(
          Zero<typename IntervalType::InnerType>(),
          IsInfinite() ? Infinity<typename IntervalType::InnerType>()
                       : duration);
  auto buffered = IntervalType(GetBuffered());
  // Remove any negative range in the interval -- seeking to a non-positive
  // position isn't possible.
  auto positiveBuffered = buffered.Intersection(zeroToDuration);

  // We can seek in buffered range if the media is seekable. Also, we can seek
  // in unbuffered ranges if the transport level is seekable (local file or the
  // server supports range requests, etc.) or in cue-less WebMs
  if (mMediaSeekableOnlyInBufferedRanges) {
    return IntervalType(GetBuffered());
    return IntervalType(positiveBuffered);
  }
  if (!IsMediaSeekable()) {
    return IntervalType();
  }
  if (!IsTransportSeekable()) {
    return IntervalType(GetBuffered());
  }
  // Return [0, duration] -- When dealing with doubles, use ::GetDuration to
  // avoid rounding the value differently. When dealing with TimeUnit, it's
  // returned directly.
  typename IntervalType::InnerType duration;
  if constexpr (std::is_same<typename IntervalType::InnerType, double>::value) {
    duration = GetDuration();
  } else {
    duration = mDuration.as<TimeUnit>();
    return IntervalType(positiveBuffered);
  }

  return IntervalType(typename IntervalType::ElemType(
      Zero<typename IntervalType::InnerType>(),
      IsInfinite() ? Infinity<typename IntervalType::InnerType>() : duration));
  // Common case: seeking is possible at any point of the stream.
  return IntervalType(zeroToDuration);
}

media::TimeIntervals MediaDecoder::GetSeekable() {