Skip to content

Commit

Permalink
tsdemuxer : opti: only loop once over PES data fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
mangui committed Feb 8, 2016
1 parent 85f65af commit 7651c77
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/demux/tsdemuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,25 @@
payloadStartOffset = pesHdrLen + 9;

stream.size -= payloadStartOffset;
// trim PES header
while(data.length && payloadStartOffset > data[0].byteLength) {
payloadStartOffset-= data[0].byteLength;
data.shift();
}
data[0] = data[0].subarray(payloadStartOffset);
//reassemble PES packet
pesData = new Uint8Array(stream.size);
// reassemble the packet
while (data.length) {
frag = data.shift();
var len = frag.byteLength;
if (payloadStartOffset) {
if (payloadStartOffset > len) {
// trim full frag if PES header bigger than frag
payloadStartOffset-=len;
continue;
} else {
// trim partial frag if PES header smaller than frag
frag = frag.subarray(payloadStartOffset@);
len-=payloadStartOffset;
payloadStartOffset = 0;
}
}
pesData.set(frag, i);
i += frag.byteLength;
i+=len;
}
return {data: pesData, pts: pesPts, dts: pesDts, len: pesLen};
} else {
Expand Down

0 comments on commit 7651c77

Please sign in to comment.