Bug 1296531 - Allow MediaSegment::AppendSlice to combine with last chunk. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 08 May 2017 11:39:08 +0200
changeset 670285 eb1ba0f0ffc3fa440743b7c8dce3fb54ed128f5e
parent 670284 297d5256d0259be80eea325a60a9c334bfe2af5a
child 670286 6b974c29726cad852f043ee08c5d6cfc5f9644d5
push id81598
push userbmo:apehrson@mozilla.com
push dateTue, 26 Sep 2017 09:13:19 +0000
reviewersjesup
bugs1296531
milestone58.0a1
Bug 1296531 - Allow MediaSegment::AppendSlice to combine with last chunk. r?jesup This makes it consistent with MediaSegment::AppendFrom. MozReview-Commit-ID: JNvLlURAqE7
dom/media/MediaSegment.h
--- a/dom/media/MediaSegment.h
+++ b/dom/media/MediaSegment.h
@@ -456,17 +456,24 @@ protected:
     mDuration += aEnd - aStart;
     StreamTime offset = 0;
     for (uint32_t i = 0; i < aSource.mChunks.Length() && offset < aEnd; ++i) {
       const Chunk& c = aSource.mChunks[i];
       StreamTime start = std::max(aStart, offset);
       StreamTime nextOffset = offset + c.GetDuration();
       StreamTime end = std::min(aEnd, nextOffset);
       if (start < end) {
-        mChunks.AppendElement(c)->SliceTo(start - offset, end - offset);
+        if (!mChunks.IsEmpty() &&
+            mChunks[mChunks.Length() - 1].CanCombineWithFollowing(c)) {
+          MOZ_ASSERT(start - offset >= 0 && end - offset <= aSource.mDuration,
+                     "Slice out of bounds");
+          mChunks[mChunks.Length() - 1].mDuration += end - start;
+        } else {
+          mChunks.AppendElement(c)->SliceTo(start - offset, end - offset);
+        }
       }
       offset = nextOffset;
     }
   }
 
   Chunk* AppendChunk(StreamTime aDuration)
   {
     MOZ_ASSERT(aDuration >= 0);