Bug 1188238: [MSE] P2. Don't assert when unable to find position in frames array. r=gerald a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 12 Sep 2015 20:49:56 +1000
changeset 289256 a9cc4e966637a4422e2a4f28340d91c5299daed1
parent 289255 e0c5c53a99a9ad69b539b62297393e17743b5403
child 289257 e1f65e6a5ea0f4511126b4a624ac99764e15bdd9
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, sledru
bugs1188238
milestone42.0a2
Bug 1188238: [MSE] P2. Don't assert when unable to find position in frames array. r=gerald a=sledru Instead return an error which will terminate the video element.
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1563,53 +1563,56 @@ TrackBuffersManager::ProcessFrames(Track
   }
 
   if (samples.Length()) {
     InsertFrames(samples, samplesRange, trackBuffer);
     trackBuffer.mSizeBuffer += sizeNewSamples;
   }
 }
 
-void
+bool
 TrackBuffersManager::CheckNextInsertionIndex(TrackData& aTrackData,
                                              const TimeUnit& aSampleTime)
 {
   if (aTrackData.mNextInsertionIndex.isSome()) {
-    return;
+    return true;
   }
 
   TrackBuffer& data = aTrackData.mBuffers.LastElement();
 
   if (data.IsEmpty() || aSampleTime < aTrackData.mBufferedRanges.GetStart()) {
     aTrackData.mNextInsertionIndex = Some(size_t(0));
-    return;
+    return true;
   }
 
   // Find which discontinuity we should insert the frame before.
   TimeInterval target;
   for (const auto& interval : aTrackData.mBufferedRanges) {
     if (aSampleTime < interval.mStart) {
       target = interval;
       break;
     }
   }
   if (target.IsEmpty()) {
     // No target found, it will be added at the end of the track buffer.
     aTrackData.mNextInsertionIndex = Some(data.Length());
-    return;
+    return true;
   }
+  // We now need to find the first frame of the searched interval.
+  // We will insert our new frames right before.
   for (uint32_t i = 0; i < data.Length(); i++) {
     const nsRefPtr<MediaRawData>& sample = data[i];
     if (sample->mTime >= target.mStart.ToMicroseconds() ||
         sample->GetEndTime() > target.mStart.ToMicroseconds()) {
       aTrackData.mNextInsertionIndex = Some(size_t(i));
-      return;
+      return true;
     }
   }
-  MOZ_CRASH("Insertion Index Not Found");
+  NS_ASSERTION(false, "Insertion Index Not Found");
+  return false;
 }
 
 void
 TrackBuffersManager::InsertFrames(TrackBuffer& aSamples,
                                   const TimeIntervals& aIntervals,
                                   TrackData& aTrackData)
 {
   // 5. Let track buffer equal the track buffer that the coded frame will be added to.
@@ -1645,18 +1648,21 @@ TrackBuffersManager::InsertFrames(TrackB
   TimeIntervals intersection = trackBuffer.mBufferedRanges;
   intersection.Intersection(aIntervals);
 
   if (intersection.Length()) {
     RemoveFrames(aIntervals, trackBuffer, trackBuffer.mNextInsertionIndex.refOr(0));
   }
 
   // 16. Add the coded frame with the presentation timestamp, decode timestamp, and frame duration to the track buffer.
-  CheckNextInsertionIndex(aTrackData,
-                          TimeUnit::FromMicroseconds(aSamples[0]->mTime));
+  if (!CheckNextInsertionIndex(aTrackData,
+                               TimeUnit::FromMicroseconds(aSamples[0]->mTime))) {
+    RejectProcessing(NS_ERROR_FAILURE, __func__);
+    return;
+  }
 
   // Adjust our demuxing index if necessary.
   if (trackBuffer.mNextGetSampleIndex.isSome() &&
       (trackBuffer.mNextInsertionIndex.ref() < trackBuffer.mNextGetSampleIndex.ref() ||
        (trackBuffer.mNextInsertionIndex.ref() == trackBuffer.mNextGetSampleIndex.ref() &&
         aIntervals.GetEnd() < trackBuffer.mNextSampleTime))) {
     trackBuffer.mNextGetSampleIndex.ref() += aSamples.Length();
   }
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -277,17 +277,17 @@ private:
 
       mLongestFrameDuration.reset();
       mNextInsertionIndex.reset();
     }
   };
 
   void CheckSequenceDiscontinuity();
   void ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData);
-  void CheckNextInsertionIndex(TrackData& aTrackData,
+  bool CheckNextInsertionIndex(TrackData& aTrackData,
                                const media::TimeUnit& aSampleTime);
   void InsertFrames(TrackBuffer& aSamples,
                     const media::TimeIntervals& aIntervals,
                     TrackData& aTrackData);
   void RemoveFrames(const media::TimeIntervals& aIntervals,
                     TrackData& aTrackData,
                     uint32_t aStartIndex);
   void UpdateBufferedRanges();