Skip to content

Commit

Permalink
fix: Do not reuse the same tsParser for different contentType (#7563)
Browse files Browse the repository at this point in the history
Fixes #7399

This PR resolves issue
#7399 which has the
same pid for audio and video, but they are different segments.

Backported to v4.9.x
  • Loading branch information
avelad authored and joeyparrish committed Nov 12, 2024
1 parent 3d845c8 commit 0534a75
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ shaka.media.MediaSourceEngine = class {
/** @private {?number} */
this.lastDuration_ = null;

/** @private {?shaka.util.TsParser} */
this.tsParser_ = null;
/** @private {!Object.<shaka.util.ManifestParserUtils.ContentType,
!shaka.util.TsParser>} */
this.tsParsers_ = {};

/** @private {?number} */
this.firstVideoTimestamp_ = null;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0534a75

Please sign in to comment.