diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 538a62e6aa..5474db2ccb 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -729,11 +729,13 @@ shaka.media.MediaSourceEngine = class { * @param {boolean=} seeked True if we just seeked * @param {boolean=} adaptation True if we just automatically switched active * variant(s). + * @param {boolean=} isChunkedData True if we add to the buffer from the + * partial read of the segment. * @return {!Promise} */ async appendBuffer( contentType, data, reference, stream, hasClosedCaptions, seeked = false, - adaptation = false) { + adaptation = false, isChunkedData = false) { const ContentType = shaka.util.ManifestParserUtils.ContentType; if (contentType == ContentType.TEXT) { @@ -837,13 +839,13 @@ shaka.media.MediaSourceEngine = class { let bufferedBefore = null; await this.enqueueOperation_(contentType, () => { - if (goog.DEBUG && reference) { + if (goog.DEBUG && reference && !reference.isPreload() && !isChunkedData) { bufferedBefore = this.getBuffered_(contentType); } this.append_(contentType, data); }); - if (goog.DEBUG && reference && !reference.isPreload()) { + if (goog.DEBUG && reference && !reference.isPreload() && !isChunkedData) { const bufferedAfter = this.getBuffered_(contentType); const newBuffered = shaka.media.TimeRangesUtils.computeAddedRange( bufferedBefore, bufferedAfter); diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index db7f2ed2b1..807c215d87 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1371,7 +1371,8 @@ shaka.media.StreamingEngine = class { const dataToAppend = remaining.subarray(0, offset); remaining = remaining.subarray(offset); await this.append_( - mediaState, presentationTime, stream, reference, dataToAppend); + mediaState, presentationTime, stream, reference, dataToAppend, + /* isChunkedData= */ true); } }; @@ -1856,10 +1857,12 @@ shaka.media.StreamingEngine = class { * @param {shaka.extern.Stream} stream * @param {!shaka.media.SegmentReference} reference * @param {BufferSource} segment + * @param {boolean=} isChunkedData * @return {!Promise} * @private */ - async append_(mediaState, presentationTime, stream, reference, segment) { + async append_(mediaState, presentationTime, stream, reference, segment, + isChunkedData = false) { const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState); const hasClosedCaptions = stream.closedCaptions && @@ -1914,7 +1917,8 @@ shaka.media.StreamingEngine = class { stream, hasClosedCaptions, seeked, - adaptation); + adaptation, + isChunkedData); this.destroyer_.ensureNotDestroyed(); shaka.log.v2(logPrefix, 'appended media segment'); }