Bug 1305876 - P2. Do not modify internal data when calculating buffered ranges. r=gerald, a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 12 Oct 2016 20:54:25 +1100
changeset 350720 11ba9af07367fa76691961289d5e46d880a868e8
parent 350719 2ae1db552424c583c8631429e06cab64a372d508
child 350721 0c46713f5b17e943e39866326bd040f639364b8e
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, ritu
bugs1305876
milestone50.0
Bug 1305876 - P2. Do not modify internal data when calculating buffered ranges. r=gerald, a=ritu MozReview-Commit-ID: 29WJozhIrEP
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -300,39 +300,42 @@ TimeIntervals
 TrackBuffersManager::Buffered()
 {
   MSE_DEBUG("");
   MonitorAutoLock mon(mMonitor);
   // http://w3c.github.io/media-source/index.html#widl-SourceBuffer-buffered
   // 2. Let highest end time be the largest track buffer ranges end time across all the track buffers managed by this SourceBuffer object.
   TimeUnit highestEndTime;
 
-  nsTArray<TimeIntervals*> tracks;
+  nsTArray<const TimeIntervals*> tracks;
   if (HasVideo()) {
     tracks.AppendElement(&mVideoBufferedRanges);
   }
   if (HasAudio()) {
     tracks.AppendElement(&mAudioBufferedRanges);
   }
   for (auto trackRanges : tracks) {
     highestEndTime = std::max(trackRanges->GetEnd(), highestEndTime);
   }
 
   // 3. Let intersection ranges equal a TimeRange object containing a single range from 0 to highest end time.
   TimeIntervals intersection{TimeInterval(TimeUnit::FromSeconds(0), highestEndTime)};
 
   // 4. For each track buffer managed by this SourceBuffer, run the following steps:
   //   1. Let track ranges equal the track buffer ranges for the current track buffer.
-  for (auto trackRanges : tracks) {
+  for (const TimeIntervals* trackRanges : tracks) {
     // 2. If readyState is "ended", then set the end time on the last range in track ranges to highest end time.
+    // 3. Let new intersection ranges equal the intersection between the intersection ranges and the track ranges.
     if (mEnded) {
-      trackRanges->Add(TimeInterval(trackRanges->GetEnd(), highestEndTime));
+      TimeIntervals tR = *trackRanges;
+      tR.Add(TimeInterval(tR.GetEnd(), highestEndTime));
+      intersection.Intersection(tR);
+    } else {
+      intersection.Intersection(*trackRanges);
     }
-    // 3. Let new intersection ranges equal the intersection between the intersection ranges and the track ranges.
-    intersection.Intersection(*trackRanges);
   }
   return intersection;
 }
 
 int64_t
 TrackBuffersManager::GetSize() const
 {
   return mSizeSourceBuffer;