Bug 1438956 - Add inline Start/End TimeRanges methods for C++ users. r?bz draft
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Fri, 16 Feb 2018 19:36:40 +0100
changeset 756266 9daad14d4dcde5233997e6582fd3829af6ebd681
parent 756265 09b2a94883e8a70813d318017311a5efb1120856
child 756734 8f94c0910e7ee2301727ad8afe7f3d6a1a842ed7
child 756735 2ad0a2b4a7c92efeec2f62995e9aec4ba543f20e
child 757098 ace5d983fdb19b0f57b880ce1064dc258dc3768a
push id99450
push userbmo:adrian.wielgosik@gmail.com
push dateFri, 16 Feb 2018 18:37:10 +0000
reviewersbz
bugs1438956
milestone60.0a1
Bug 1438956 - Add inline Start/End TimeRanges methods for C++ users. r?bz MozReview-Commit-ID: DcLsYyKV7WX
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
dom/html/TimeRanges.cpp
dom/html/TimeRanges.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2702,22 +2702,22 @@ HTMLMediaElement::SetCurrentTime(double 
 static bool
 IsInRanges(TimeRanges& aRanges,
            double aValue,
            int32_t& aIntervalIndex)
 {
   uint32_t length = aRanges.Length();
 
   for (uint32_t i = 0; i < length; i++) {
-    double start = aRanges.Start(i, IgnoreErrors());
+    double start = aRanges.Start(i);
     if (start > aValue) {
       aIntervalIndex = i - 1;
       return false;
     }
-    double end = aRanges.End(i, IgnoreErrors());
+    double end = aRanges.End(i);
     if (aValue <= end) {
       aIntervalIndex = i;
       return true;
     }
   }
   aIntervalIndex = length - 1;
   return false;
 }
@@ -2796,35 +2796,35 @@ HTMLMediaElement::Seek(double aTime,
   // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#seeking
   int32_t range = 0;
   bool isInRange = IsInRanges(*seekable, aTime, range);
   if (!isInRange) {
     if (range != -1) {
       // |range + 1| can't be negative, because the only possible negative value
       // for |range| is -1.
       if (uint32_t(range + 1) < length) {
-        double leftBound = seekable->End(range, IgnoreErrors());
-        double rightBound = seekable->Start(range + 1, IgnoreErrors());
+        double leftBound = seekable->End(range);
+        double rightBound = seekable->Start(range + 1);
         double distanceLeft = Abs(leftBound - aTime);
         double distanceRight = Abs(rightBound - aTime);
         if (distanceLeft == distanceRight) {
           double currentTime = CurrentTime();
           distanceLeft = Abs(leftBound - currentTime);
           distanceRight = Abs(rightBound - currentTime);
         }
         aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
       } else {
         // Seek target is after the end last range in seekable data.
         // Clamp the seek target to the end of the last seekable range.
-        aTime = seekable->GetEndTime();
+        aTime = seekable->End(length - 1);
       }
     } else {
       // aTime is before the first range in |seekable|, the closest point we can
       // seek to is the start of the first range.
-      aTime = seekable->GetStartTime();
+      aTime = seekable->Start(0);
     }
   }
 
   // TODO: The spec requires us to update the current time to reflect the
   //       actual seek target before beginning the synchronous section, but
   //       that requires changing all MediaDecoderReaders to support telling
   //       us the fastSeek target, and it's currently not possible to get
   //       this information as we don't yet control the demuxer for all
@@ -2878,18 +2878,18 @@ HTMLMediaElement::Played()
 {
   RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
 
   uint32_t timeRangeCount = 0;
   if (mPlayed) {
     timeRangeCount = mPlayed->Length();
   }
   for (uint32_t i = 0; i < timeRangeCount; i++) {
-    double begin = mPlayed->Start(i, IgnoreErrors());
-    double end = mPlayed->End(i, IgnoreErrors());
+    double begin = mPlayed->Start(i);
+    double end = mPlayed->End(i);
     ranges->Add(begin, end);
   }
 
   if (mCurrentPlayRangeStart != -1.0) {
     double now = CurrentTime();
     if (mCurrentPlayRangeStart != now) {
       ranges->Add(mCurrentPlayRangeStart, now);
     }
@@ -4483,19 +4483,18 @@ HTMLMediaElement::ReportTelemetry()
     // buffering if the last frame status was buffering and the ready state is
     // HAVE_CURRENT_DATA to account for times where we are in a buffering state
     // regardless of what actual data we have buffered.
     bool stalled = false;
     RefPtr<TimeRanges> ranges = Buffered();
     const double errorMargin = 0.05;
     double t = CurrentTime();
     TimeRanges::index_type index = ranges->Find(t, errorMargin);
-    ErrorResult ignore;
     stalled = index != TimeRanges::NoIndex &&
-              (ranges->End(index, ignore) - t) < errorMargin;
+              (ranges->End(index) - t) < errorMargin;
     stalled |= mDecoder && NextFrameStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING &&
                mReadyState == HAVE_CURRENT_DATA;
     if (stalled) {
       state = STALLED;
     }
   }
 
   Telemetry::Accumulate(Telemetry::VIDEO_UNLOAD_STATE, state);
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -350,18 +350,18 @@ double
 HTMLVideoElement::TotalPlayTime() const
 {
   double total = 0.0;
 
   if (mPlayed) {
     uint32_t timeRangeCount = mPlayed->Length();
 
     for (uint32_t i = 0; i < timeRangeCount; i++) {
-      double begin = mPlayed->Start(i, IgnoreErrors());
-      double end = mPlayed->End(i, IgnoreErrors());
+      double begin = mPlayed->Start(i);
+      double end = mPlayed->End(i);
       total += end - begin;
     }
 
     if (mCurrentPlayRangeStart != -1.0) {
       double now = CurrentTime();
       if (mCurrentPlayRangeStart != now) {
         total += now - mCurrentPlayRangeStart;
       }
--- a/dom/html/TimeRanges.cpp
+++ b/dom/html/TimeRanges.cpp
@@ -48,47 +48,46 @@ TimeRanges::TimeRanges(const media::Time
 {
 }
 
 media::TimeIntervals
 TimeRanges::ToTimeIntervals() const
 {
   media::TimeIntervals t;
   for (uint32_t i = 0; i < Length(); i++) {
-    ErrorResult rv;
-    t += media::TimeInterval(media::TimeUnit::FromSeconds(Start(i, rv)),
-                             media::TimeUnit::FromSeconds(End(i, rv)));
+    t += media::TimeInterval(media::TimeUnit::FromSeconds(Start(i)),
+                             media::TimeUnit::FromSeconds(End(i)));
   }
   return t;
 }
 
 TimeRanges::~TimeRanges()
 {
 }
 
 double
 TimeRanges::Start(uint32_t aIndex, ErrorResult& aRv) const
 {
   if (aIndex >= mRanges.Length()) {
     aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
     return 0;
   }
 
-  return mRanges[aIndex].mStart;
+  return Start(aIndex);
 }
 
 double
 TimeRanges::End(uint32_t aIndex, ErrorResult& aRv) const
 {
   if (aIndex >= mRanges.Length()) {
     aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
     return 0;
   }
 
-  return mRanges[aIndex].mEnd;
+  return End(aIndex);
 }
 
 void
 TimeRanges::Add(double aStart, double aEnd)
 {
   if (aStart > aEnd) {
     NS_WARNING("Can't add a range if the end is older that the start.");
     return;
--- a/dom/html/TimeRanges.h
+++ b/dom/html/TimeRanges.h
@@ -64,16 +64,26 @@ public:
   {
     return mRanges.Length();
   }
 
   double Start(uint32_t aIndex, ErrorResult& aRv) const;
 
   double End(uint32_t aIndex, ErrorResult& aRv) const;
 
+  double Start(uint32_t aIndex) const
+  {
+    return mRanges[aIndex].mStart;
+  }
+
+  double End(uint32_t aIndex) const
+  {
+    return mRanges[aIndex].mEnd;
+  }
+
   // Shift all values by aOffset seconds.
   void Shift(double aOffset);
 
 private:
   ~TimeRanges();
 
   // Comparator which orders TimeRanges by start time. Used by Normalize().
   struct TimeRange