Skip to content

Commit

Permalink
perf: Improve transmuxer performance (shaka-project#5789)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored and Rodolphe Breton committed Nov 30, 2023
1 parent d8a5717 commit 15b5c5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
9 changes: 5 additions & 4 deletions lib/transmuxer/h264.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ shaka.transmuxer.H264 = class {
static parseFrame(nalus) {
const H264 = shaka.transmuxer.H264;
let isKeyframe = false;
let data = new Uint8Array([]);
const nalusData = [];
const spsNalu = nalus.find((nalu) => {
return nalu.type == H264.NALU_TYPE_SPS_;
});
Expand Down Expand Up @@ -240,13 +240,14 @@ shaka.transmuxer.H264 = class {
naluLength[1] = (size >> 16) & 0xff;
naluLength[2] = (size >> 8) & 0xff;
naluLength[3] = size & 0xff;
data = shaka.util.Uint8ArrayUtils.concat(
data, naluLength, nalu.fullData);
nalusData.push(shaka.util.Uint8ArrayUtils.concat(
naluLength, nalu.fullData));
}
}
if (!data.byteLength) {
if (!nalusData.length) {
return null;
}
const data = shaka.util.Uint8ArrayUtils.concat(...nalusData);
return {
data,
isKeyframe,
Expand Down
9 changes: 5 additions & 4 deletions lib/transmuxer/h265.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ shaka.transmuxer.H265 = class {
static parseFrame(nalus) {
const H265 = shaka.transmuxer.H265;
let isKeyframe = false;
let data = new Uint8Array([]);
const nalusData = [];
let hvcSample = false;
for (const nalu of nalus) {
let push = false;
Expand Down Expand Up @@ -636,13 +636,14 @@ shaka.transmuxer.H265 = class {
naluLength[1] = (size >> 16) & 0xff;
naluLength[2] = (size >> 8) & 0xff;
naluLength[3] = size & 0xff;
data = shaka.util.Uint8ArrayUtils.concat(
data, naluLength, nalu.fullData);
nalusData.push(shaka.util.Uint8ArrayUtils.concat(
naluLength, nalu.fullData));
}
}
if (!data.byteLength) {
if (!nalusData.length) {
return null;
}
const data = shaka.util.Uint8ArrayUtils.concat(...nalusData);
return {
data,
isKeyframe,
Expand Down
6 changes: 2 additions & 4 deletions lib/util/mp4_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,8 @@ shaka.util.Mp4Generator = class {
mdat_(streamInfo) {
const Mp4Generator = shaka.util.Mp4Generator;
const samples = streamInfo.data ? streamInfo.data.samples : [];
let bytes = new Uint8Array([]);
for (const sample of samples) {
bytes = shaka.util.Uint8ArrayUtils.concat(bytes, sample.data);
}
const allData = samples.map((sample) => sample.data);
const bytes = shaka.util.Uint8ArrayUtils.concat(...allData);
return Mp4Generator.box('mdat', bytes);
}

Expand Down

0 comments on commit 15b5c5f

Please sign in to comment.