forge
Explore
Log in

Don't you dare go Hollow

TrueHD and DTS codec ids, and a Matroska track's own number

Browse files at this commit

254c09a15bdd9862b045a3859322eabb30f32dadAhmet Kaan GümüşParent: d60d66b
  • feat
    • TrueHD and DTS codec ids, and a Matroska track's own number
Show full message
feat(core): TrueHD and DTS codec ids, and a Matroska track's own number

A track nothing here decodes is named rather than dropped: a player that
lists a TrueHD track as unsupported tells the user something, and one
that shows no audio at all does not. The Matroska reader maps A_TRUEHD,
A_MLP and the A_DTS family onto them.

MatroskaDemuxer::track_number answers what TrackNumber a stream index
came from, which is how a caller names one language of a dual-audio
remux (edith matches its audio streams by that number).
crates/ec-core/src/registry.rsmodified+11 -3
@@ -38,6 +38,10 @@ pub enum CodecId {
3838 Ac3,
3939 /// Dolby Digital Plus (E-AC-3).
4040 EAc3,
41+ /// Dolby TrueHD (MLP), including the Atmos substream.
42+ TrueHd,
43+ /// DTS and its extensions (DTS-HD, DTS:X).
44+ Dts,
4145 /// Apple Lossless.
4246 Alac,
4347 /// Xiph FLAC.
@@ -78,8 +82,8 @@ impl CodecId {
7882 use CodecId::*;
7983 match self {
8084 H264 | H265 | Vp8 | Vp9 | Av1 => MediaType::Video,
81- Aac | Ac3 | EAc3 | Alac | Flac | Mp3 | Opus | Vorbis | PcmU8 | PcmS16Le | PcmS16Be
82- | PcmS24Le | PcmS32Le | PcmF32Le => MediaType::Audio,
85+ Aac | Ac3 | EAc3 | TrueHd | Dts | Alac | Flac | Mp3 | Opus | Vorbis | PcmU8
86+ | PcmS16Le | PcmS16Be | PcmS24Le | PcmS32Le | PcmF32Le => MediaType::Audio,
8387 Srt | WebVtt | Ass | Pgs | Tx3g => MediaType::Subtitle,
8488 }
8589 }
@@ -96,6 +100,8 @@ impl CodecId {
96100 Aac => "aac",
97101 Ac3 => "ac3",
98102 EAc3 => "eac3",
103+ TrueHd => "truehd",
104+ Dts => "dts",
99105 Alac => "alac",
100106 Flac => "flac",
101107 Mp3 => "mp3",
@@ -363,6 +369,8 @@ mod tests {
363369 CodecId::Aac,
364370 CodecId::Ac3,
365371 CodecId::EAc3,
372+ CodecId::TrueHd,
373+ CodecId::Dts,
366374 CodecId::Alac,
367375 CodecId::Flac,
368376 CodecId::Mp3,
@@ -380,7 +388,7 @@ mod tests {
380388 CodecId::Pgs,
381389 CodecId::Tx3g,
382390 ];
383- assert_eq!(all.len(), 24);
391+ assert_eq!(all.len(), 26);
384392 let mut names: Vec<&str> = all.iter().map(|c| c.name()).collect();
385393 names.sort_unstable();
386394 names.dedup();
crates/ec-matroska/src/demux.rsmodified+16 -0
@@ -355,6 +355,18 @@ impl<R: Read + Seek> MatroskaDemuxer<R> {
355355 self.time_base
356356 }
357357
358+ /// The `TrackNumber` a stream index came from.
359+ ///
360+ /// Stream indices are this crate's own numbering; the `TrackNumber` is the
361+ /// file's, and it is what a caller naming one language of a dual-audio
362+ /// remux is holding.
363+ pub fn track_number(&self, stream: u32) -> Option<u64> {
364+ self.tracks
365+ .iter()
366+ .find(|t| t.stream == Some(stream))
367+ .map(|t| t.number)
368+ }
369+
358370 /// The next cluster into [`MatroskaDemuxer::queue`]; `false` at the end of
359371 /// the segment. `at` comes back holding the offset of the cluster read.
360372 fn load_cluster(&mut self, at: &mut u64) -> Result<bool> {
@@ -945,6 +957,10 @@ pub(crate) fn codec_of(id: &str, bit_depth: u32) -> Option<CodecId> {
945957 "A_VORBIS" => CodecId::Vorbis,
946958 "A_AC3" => CodecId::Ac3,
947959 "A_EAC3" => CodecId::EAc3,
960+ // Named rather than dropped: nothing here decodes them, and a track a
961+ // player lists as unsupported is a better answer than a silent one.
962+ "A_TRUEHD" | "A_MLP" => CodecId::TrueHd,
963+ id if id.starts_with("A_DTS") => CodecId::Dts,
948964 "A_FLAC" => CodecId::Flac,
949965 "A_ALAC" => CodecId::Alac,
950966 "S_TEXT/UTF8" => CodecId::Srt,