From 0534a7543cb604037c2736bfb40398bae3476298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 11 Nov 2024 15:55:45 +0100 Subject: [PATCH] fix: Do not reuse the same tsParser for different contentType (#7563) Fixes https://github.com/shaka-project/shaka-player/issues/7399 This PR resolves issue https://github.com/shaka-project/shaka-player/issues/7399 which has the same pid for audio and video, but they are different segments. Backported to v4.9.x --- lib/media/media_source_engine.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index ab0ca83347..4ad542582c 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -149,8 +149,9 @@ shaka.media.MediaSourceEngine = class { /** @private {?number} */ this.lastDuration_ = null; - /** @private {?shaka.util.TsParser} */ - this.tsParser_ = null; + /** @private {!Object.} */ + this.tsParsers_ = {}; /** @private {?number} */ this.firstVideoTimestamp_ = null; @@ -441,7 +442,7 @@ shaka.media.MediaSourceEngine = class { // This object is owned by Player this.lcevcDec_ = null; - this.tsParser_ = null; + this.tsParsers_ = {}; this.playerInterface_ = null; } @@ -493,7 +494,12 @@ shaka.media.MediaSourceEngine = class { this.manifestType_ == shaka.media.ManifestParser.HLS && !this.ignoreManifestTimestampsInSegmentsMode_; - this.tsParser_ = null; + this.tsParsers_ = {}; + this.firstVideoTimestamp_ = null; + this.firstVideoReferenceStartTime_ = null; + this.firstAudioTimestamp_ = null; + this.firstAudioReferenceStartTime_ = null; + this.audioCompensation_ = new shaka.util.PublicPromise(); for (const contentType of streamsByType.keys()) { const stream = streamsByType.get(contentType); @@ -844,12 +850,12 @@ shaka.media.MediaSourceEngine = class { } } else if (!mimeType.includes('/mp4') && !mimeType.includes('/webm') && shaka.util.TsParser.probe(uint8ArrayData)) { - if (!this.tsParser_) { - this.tsParser_ = new shaka.util.TsParser(); + if (!this.tsParsers_[contentType]) { + this.tsParsers_[contentType] = new shaka.util.TsParser(); } else { - this.tsParser_.clearData(); + this.tsParsers_[contentType].clearData(); } - const tsParser = this.tsParser_.parse(uint8ArrayData); + const tsParser = this.tsParsers_[contentType].parse(uint8ArrayData); const startTime = tsParser.getStartTime(contentType); if (startTime != null) { timestamp = startTime;