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

Add support for AC-3 audio in DVB streams #5636

Merged
merged 2 commits into from
Jul 17, 2023
Merged
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
39 changes: 38 additions & 1 deletion src/demux/tsdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ function parsePMT(
offset += 12 + programInfoLength;
while (offset < tableEnd) {
const pid = parsePID(data, offset);
const esInfoLength = ((data[offset + 3] & 0x0f) << 8) | data[offset + 4];
switch (data[offset]) {
case 0xcf: // SAMPLE-AES AAC
if (!isSampleAes) {
Expand Down Expand Up @@ -830,6 +831,42 @@ function parsePMT(
}
break;

case 0x06:
// stream_type 6 can mean a lot of different things in case of DVB.
// We need to look at the descriptors. Right now, we're only interested
// in AC-3 audio, so we do the descriptor parsing only when we don't have
// an audio PID yet.
if (result.audioPid === -1 && esInfoLength > 0) {
let parsePos = offset + 5;
let remaining = esInfoLength;

while (remaining > 2) {
const descriptorId = data[parsePos];

switch (descriptorId) {
case 0x6a: // DVB Descriptor for AC-3
if (__USE_M2TS_ADVANCED_CODECS__) {
robwalch marked this conversation as resolved.
Show resolved Hide resolved
if (typeSupported.ac3 !== true) {
logger.log(
'AC-3 audio found, not supported in this browser for now'
);
} else {
result.audioPid = pid;
result.segmentAudioCodec = 'ac3';
}
} else {
logger.warn('AC-3 in M2TS support not included in build');
}
break;
}

const descriptorLen = data[parsePos + 1] + 2;
parsePos += descriptorLen;
remaining -= descriptorLen;
}
}
break;

case 0xc2: // SAMPLE-AES EC3
/* falls through */
case 0x87:
Expand All @@ -845,7 +882,7 @@ function parsePMT(
}
// move to the next table entry
// skip past the elementary stream descriptors, if present
offset += (((data[offset + 3] & 0x0f) << 8) | data[offset + 4]) + 5;
offset += esInfoLength + 5;
}
return result;
}
Expand Down
Loading