Bug 1296531 - Allow MediaSegment::AppendSlice to combine with last chunk. r?jesup
This makes it consistent with MediaSegment::AppendFrom.
MozReview-Commit-ID: JNvLlURAqE7
--- 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);