Skip to content

Commit

Permalink
fix: Fix transmuxer when some PES has the same pts and dts value (#5985)
Browse files Browse the repository at this point in the history
Fixes #5913
  • Loading branch information
avelad authored Dec 5, 2023
1 parent 26e572f commit 165feac
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/util/ts_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,11 @@ shaka.util.TsParser = class {
let sort = false;
for (const audioData of this.audioData_) {
const pes = this.parsePES_(audioData);
if (pes && pes.pts != null && pes.dts != null) {
if (this.audioPes_.length &&
pes.dts < (this.audioPes_[this.audioPes_.length - 1].dts || 0)) {
let previousPes = this.audioPes_.length ?
this.audioPes_[this.audioPes_.length - 1] : null;
if (pes && pes.pts != null && pes.dts != null && (!previousPes ||
(previousPes.pts != pes.pts && previousPes.dts != pes.dts))) {
if (this.audioPes_.length && pes.dts < (previousPes.dts || 0)) {
sort = true;
}
this.audioPes_.push(pes);
Expand All @@ -625,7 +627,7 @@ shaka.util.TsParser = class {
if (!data) {
continue;
}
const previousPes = this.audioPes_.pop();
previousPes = this.audioPes_.pop();
previousPes.data =
shaka.util.Uint8ArrayUtils.concat(previousPes.data, data);
this.audioPes_.push(previousPes);
Expand Down Expand Up @@ -654,9 +656,11 @@ shaka.util.TsParser = class {
let sort = false;
for (const videoData of this.videoData_) {
const pes = this.parsePES_(videoData);
if (pes && pes.pts != null && pes.dts != null) {
if (this.videoPes_.length &&
pes.dts < (this.videoPes_[this.videoPes_.length - 1].dts || 0)) {
let previousPes = this.videoPes_.length ?
this.videoPes_[this.videoPes_.length - 1] : null;
if (pes && pes.pts != null && pes.dts != null && (!previousPes ||
(previousPes.pts != pes.pts && previousPes.dts != pes.dts))) {
if (this.videoPes_.length && pes.dts < (previousPes.dts || 0)) {
sort = true;
}
this.videoPes_.push(pes);
Expand All @@ -665,7 +669,7 @@ shaka.util.TsParser = class {
if (!data) {
continue;
}
const previousPes = this.videoPes_.pop();
previousPes = this.videoPes_.pop();
previousPes.data =
shaka.util.Uint8ArrayUtils.concat(previousPes.data, data);
this.videoPes_.push(previousPes);
Expand Down

0 comments on commit 165feac

Please sign in to comment.