From 6ea1b0f69fd946ee3011e3f5c60afb7a4bc787f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 29 Jun 2023 18:00:50 +0200 Subject: [PATCH] fix(DASH): Avoid "Possible encoding problem detected!" when appending chunked data (#5376) Backported to v4.3.x --- lib/media/media_source_engine.js | 8 +++++--- lib/media/streaming_engine.js | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 82558e2ac2..9c98d3ebd4 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -582,11 +582,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, hasClosedCaptions, seeked = false, - adaptation = false) { + adaptation = false, isChunkedData = false) { const ContentType = shaka.util.ManifestParserUtils.ContentType; if (contentType == ContentType.TEXT) { @@ -787,13 +789,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 7cce73b63f..78aebdd1ce 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1319,7 +1319,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); } }; @@ -1731,10 +1732,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 && @@ -1788,7 +1791,8 @@ shaka.media.StreamingEngine = class { reference, hasClosedCaptions, seeked, - adaptation); + adaptation, + isChunkedData); this.destroyer_.ensureNotDestroyed(); shaka.log.v2(logPrefix, 'appended media segment'); }