Skip to content

Commit

Permalink
fix(DASH): Avoid "Possible encoding problem detected!" when appending…
Browse files Browse the repository at this point in the history
… chunked data (#5376)

Backported to v4.3.x
  • Loading branch information
avelad authored and joeyparrish committed Jul 20, 2023
1 parent 29b81ea commit ad9de15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,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) {
Expand Down Expand Up @@ -706,13 +708,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);
Expand Down
10 changes: 7 additions & 3 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,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);
}
};

Expand Down Expand Up @@ -1696,10 +1697,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 &&
Expand Down Expand Up @@ -1732,7 +1735,8 @@ shaka.media.StreamingEngine = class {
reference,
hasClosedCaptions,
seeked,
adaptation);
adaptation,
isChunkedData);
this.destroyer_.ensureNotDestroyed();
shaka.log.v2(logPrefix, 'appended media segment');
}
Expand Down

0 comments on commit ad9de15

Please sign in to comment.