Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing multiple user data unregistered SEI #4242

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/demux/tsdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ class TSDemuxer implements Demuxer {
}
}
break;
// IDR
}
// IDR
case 5:
push = true;
// handle PES not starting with AUD
Expand Down Expand Up @@ -624,7 +624,7 @@ class TSDemuxer implements Demuxer {
let endOfCaptions = false;
let b = 0;

while (!endOfCaptions && expGolombDecoder.bytesAvailable > 1) {
while (expGolombDecoder.bytesAvailable > 1) {
payloadType = 0;
do {
b = expGolombDecoder.readUByte();
Expand All @@ -638,9 +638,13 @@ class TSDemuxer implements Demuxer {
payloadSize += b;
} while (b === 0xff);

// TODO: there can be more than one payload in an SEI packet...
// TODO: need to read type and size in a while loop to get them all
if (payloadType === 4 && expGolombDecoder.bytesAvailable !== 0) {
if (
!endOfCaptions &&
payloadType === 4 &&
expGolombDecoder.bytesAvailable !== 0
) {
// User data registered by Rec. ITU-T T.35 SEI message
// Only the first encountered SEI is taken into account
endOfCaptions = true;

const countryCode = expGolombDecoder.readUByte();
Expand Down Expand Up @@ -671,6 +675,7 @@ class TSDemuxer implements Demuxer {

insertSampleInOrder(this._txtTrack.samples, {
type: 3,
payloadType: payloadType,
pts: pes.pts,
bytes: byteArray,
});
Expand All @@ -682,12 +687,12 @@ class TSDemuxer implements Demuxer {
payloadType === 5 &&
expGolombDecoder.bytesAvailable !== 0
) {
endOfCaptions = true;

// User data unregistered SEI message
if (payloadSize > 16) {
const uuidStrArray: Array<string> = [];
for (let i = 0; i < 16; i++) {
uuidStrArray.push(expGolombDecoder.readUByte().toString(16));
const b = expGolombDecoder.readUByte().toString(16);
uuidStrArray.push(b.length == 1 ? '0' + b : b);

if (i === 3 || i === 5 || i === 7 || i === 9) {
uuidStrArray.push('-');
Expand All @@ -714,8 +719,8 @@ class TSDemuxer implements Demuxer {
}
}
break;
// SPS
}
// SPS
case 7:
push = true;
spsfound = true;
Expand Down