From 9bd559b94ad86234e927b2422bbde0655831bb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 18 Aug 2023 01:15:36 +0200 Subject: [PATCH] feat: Add support for AC-3 and EC-3 audio in DVB streams (#5484) --- lib/util/ts_parser.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/util/ts_parser.js b/lib/util/ts_parser.js index b8e66b0fc8..b64e69a7aa 100644 --- a/lib/util/ts_parser.js +++ b/lib/util/ts_parser.js @@ -225,7 +225,36 @@ shaka.util.TsParser = class { offset += 12 + programInfoLength; while (offset < tableEnd) { const pid = ((data[offset + 1] & 0x1f) << 8) | data[offset + 2]; + const esInfoLength = ((data[offset + 3] & 0x0f) << 8) | data[offset + 4]; switch (data[offset]) { + 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 and EC-3 audio, so we do the descriptor parsing + // only when we don't have an audio PID yet. + if (result.audio == -1 && esInfoLength > 0) { + let parsePos = offset + 5; + let remaining = esInfoLength; + while (remaining > 2) { + const descriptorId = data[parsePos]; + switch (descriptorId) { + // DVB Descriptor for AC-3 + case 0x6a: + result.audio = pid; + result.audioCodec = 'ac3'; + break; + // DVB Descriptor for EC-3 + case 0x7a: + result.audio = pid; + result.audioCodec = 'ec3'; + break; + } + const descriptorLen = data[parsePos + 1] + 2; + parsePos += descriptorLen; + remaining -= descriptorLen; + } + } + break; // SAMPLE-AES AAC case 0xcf: break; @@ -289,7 +318,7 @@ shaka.util.TsParser = class { } // 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; }