Bug 1296531 - Allow MediaSegment::AppendSlice to combine with last chunk. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 08 May 2017 11:39:08 +0200
changeset 670641 bb7f0a1416e33aa8c6565479ad240d2886a54fe7
parent 670640 6272e456e63edb52cf2417b9f3d4b128b926e29c
child 670642 c6f57ba4e67d9eab0b7b138ff7e5a4d3a76b20aa
push id81678
push userkgupta@mozilla.com
push dateTue, 26 Sep 2017 17:28:53 +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);