Skip to content

Commit

Permalink
fix: Fix transmuxer when some PES has the same pts and dts value
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Dec 4, 2023
1 parent 7fd99b7 commit 95c542e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/util/ts_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ 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) {
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 < (this.audioPes_[this.audioPes_.length - 1].dts || 0)) {
sort = true;
Expand All @@ -625,7 +628,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 +657,12 @@ 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) {
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 < (this.videoPes_[this.videoPes_.length - 1].dts || 0)) {
pes.dts < (previousPes.dts || 0)) {
sort = true;
}
this.videoPes_.push(pes);
Expand All @@ -665,7 +671,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 95c542e

Please sign in to comment.