Bug 1175395: P2. Properly add sample at end of array if previous sample was overlapping. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 17 Jun 2015 15:26:35 +1000
changeset 249730 a519d1f3064e2562435f631cb891325477ecf94d
parent 249729 a64d14d0bf260a2e29bd23ad2f29b657c2dcfa11
child 249731 d24f1437b19e909580b68d46be5d3df4362eb14c
push id28936
push userryanvm@gmail.com
push dateFri, 19 Jun 2015 20:34:42 +0000
treeherdermozilla-central@c319f262ce3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1175395
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1175395: P2. Properly add sample at end of array if previous sample was overlapping. r=gerald By spec, slightly overlapping frames are to be kept, so we can't rely on the buffered range end time as it could be of the overlapped frame and ending later than the new frame.
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -391,17 +391,17 @@ TrackBuffersManager::DoEvictData(const T
       }
       partialEvict = 0;
     }
     if (frame->mTime <= upperLimit.ToMicroseconds()) {
       break;
     }
     partialEvict += sizeof(*frame) + frame->mSize;
   }
-  if (lastKeyFrameIndex < buffer.Length()) {
+  if (lastKeyFrameIndex + 1 < buffer.Length()) {
     CodedFrameRemoval(
       TimeInterval(TimeUnit::FromMicroseconds(buffer[lastKeyFrameIndex+1]->mTime),
                    TimeUnit::FromInfinity()));
   }
 }
 
 nsRefPtr<TrackBuffersManager::RangeRemovalPromise>
 TrackBuffersManager::CodedFrameRemovalWithPromise(TimeInterval aInterval)
@@ -1445,31 +1445,34 @@ TrackBuffersManager::ProcessFrame(MediaR
     MOZ_ASSERT(trackBuffer.mNextInsertionIndex.ref() == 0 ||
                data[trackBuffer.mNextInsertionIndex.ref()]->mTrackInfo->GetID() == data[trackBuffer.mNextInsertionIndex.ref()-1]->mTrackInfo->GetID() ||
                data[trackBuffer.mNextInsertionIndex.ref()]->mKeyframe);
     trackBuffer.mNextInsertionIndex.ref()++;
   } else if (presentationTimestamp < trackBuffer.mBufferedRanges.GetStart()) {
     data.InsertElementAt(0, aSample);
     MOZ_ASSERT(aSample->mKeyframe);
     trackBuffer.mNextInsertionIndex = Some(size_t(1));
-  } else if (presentationTimestamp >= trackBuffer.mBufferedRanges.GetEnd()) {
-    data.AppendElement(aSample);
-    MOZ_ASSERT(data.Length() <= 2 ||
-               data[data.Length()-1]->mTrackInfo->GetID() == data[data.Length()-2]->mTrackInfo->GetID() ||
-               data[data.Length()-1]->mKeyframe);
-    trackBuffer.mNextInsertionIndex = Some(data.Length());
   } else {
     // Find which discontinuity we should insert the frame before.
     TimeInterval target;
     for (const auto& interval : trackBuffer.mBufferedRanges) {
       if (presentationTimestamp < interval.mStart) {
         target = interval;
         break;
       }
     }
+    if (target.IsEmpty()) {
+      // No existing ranges found after our frame presentation time.
+      // Insert frame at the end of array.
+      data.AppendElement(aSample);
+      MOZ_ASSERT(data.Length() <= 2 ||
+                 data[data.Length()-1]->mTrackInfo->GetID() == data[data.Length()-2]->mTrackInfo->GetID() ||
+                 data[data.Length()-1]->mKeyframe);
+      trackBuffer.mNextInsertionIndex = Some(data.Length());
+    }
     for (uint32_t i = 0; i < data.Length(); i++) {
       const nsRefPtr<MediaRawData>& sample = data[i];
       TimeInterval sampleInterval{
         TimeUnit::FromMicroseconds(sample->mTime),
         TimeUnit::FromMicroseconds(sample->GetEndTime())};
       if (target.Intersects(sampleInterval)) {
         data.InsertElementAt(i, aSample);
         MOZ_ASSERT(i != 0 &&