Skip to content

Commit

Permalink
perf(HLS): do not loop twice when processing nalus (#6954)
Browse files Browse the repository at this point in the history
PES arrays can get pretty big so it would be prudent to avoid looping
over them more than needed

Co-authored-by: Ivan Kohut <[email protected]>
  • Loading branch information
2 people authored and avelad committed Jul 2, 2024
1 parent b9ce194 commit b03b9c8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/util/ts_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ shaka.util.TsParser = class {
}

/**
* Return the audio data
* Return the video data
*
* @param {boolean=} naluProcessing
* @return {!Array.<shaka.extern.MPEG_PES>}
Expand Down Expand Up @@ -760,15 +760,15 @@ shaka.util.TsParser = class {
if (naluProcessing) {
let lastNalu;
let lastState;
const pesWithLength = [];
for (const pes of this.videoPes_) {
pes.nalus = this.parseNalus(pes, lastNalu, lastState);
if (pes.nalus.length) {
pesWithLength.push(pes);
lastNalu = pes.nalus[pes.nalus.length - 1];
}
}
this.videoPes_ = this.videoPes_.filter((pes) => {
return pes.nalus.length;
});
this.videoPes_ = pesWithLength;
}
if (sort) {
this.videoPes_ = this.videoPes_.sort((a, b) => {
Expand Down

0 comments on commit b03b9c8

Please sign in to comment.