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 {
38 Ac3,38 Ac3,
39 /// Dolby Digital Plus (E-AC-3).39 /// Dolby Digital Plus (E-AC-3).
40 EAc3,40 EAc3,
41+ /// Dolby TrueHD (MLP), including the Atmos substream.
42+ TrueHd,
43+ /// DTS and its extensions (DTS-HD, DTS:X).
44+ Dts,
41 /// Apple Lossless.45 /// Apple Lossless.
42 Alac,46 Alac,
43 /// Xiph FLAC.47 /// Xiph FLAC.
@@ -78,8 +82,8 @@ impl CodecId {
78 use CodecId::*;82 use CodecId::*;
79 match self {83 match self {
80 H264 | H265 | Vp8 | Vp9 | Av1 => MediaType::Video,84 H264 | H265 | Vp8 | Vp9 | Av1 => MediaType::Video,
81- Aac | Ac3 | EAc3 | Alac | Flac | Mp3 | Opus | Vorbis | PcmU8 | PcmS16Le | PcmS16Be85+ Aac | Ac3 | EAc3 | TrueHd | Dts | Alac | Flac | Mp3 | Opus | Vorbis | PcmU8
82- | PcmS24Le | PcmS32Le | PcmF32Le => MediaType::Audio,86+ | PcmS16Le | PcmS16Be | PcmS24Le | PcmS32Le | PcmF32Le => MediaType::Audio,
83 Srt | WebVtt | Ass | Pgs | Tx3g => MediaType::Subtitle,87 Srt | WebVtt | Ass | Pgs | Tx3g => MediaType::Subtitle,
84 }88 }
85 }89 }
@@ -96,6 +100,8 @@ impl CodecId {
96 Aac => "aac",100 Aac => "aac",
97 Ac3 => "ac3",101 Ac3 => "ac3",
98 EAc3 => "eac3",102 EAc3 => "eac3",
103+ TrueHd => "truehd",
104+ Dts => "dts",
99 Alac => "alac",105 Alac => "alac",
100 Flac => "flac",106 Flac => "flac",
101 Mp3 => "mp3",107 Mp3 => "mp3",
@@ -363,6 +369,8 @@ mod tests {
363 CodecId::Aac,369 CodecId::Aac,
364 CodecId::Ac3,370 CodecId::Ac3,
365 CodecId::EAc3,371 CodecId::EAc3,
372+ CodecId::TrueHd,
373+ CodecId::Dts,
366 CodecId::Alac,374 CodecId::Alac,
367 CodecId::Flac,375 CodecId::Flac,
368 CodecId::Mp3,376 CodecId::Mp3,
@@ -380,7 +388,7 @@ mod tests {
380 CodecId::Pgs,388 CodecId::Pgs,
381 CodecId::Tx3g,389 CodecId::Tx3g,
382 ];390 ];
383- assert_eq!(all.len(), 24);391+ assert_eq!(all.len(), 26);
384 let mut names: Vec<&str> = all.iter().map(|c| c.name()).collect();392 let mut names: Vec<&str> = all.iter().map(|c| c.name()).collect();
385 names.sort_unstable();393 names.sort_unstable();
386 names.dedup();394 names.dedup();
crates/ec-matroska/src/demux.rsmodified+16 -0
@@ -355,6 +355,18 @@ impl<R: Read + Seek> MatroskaDemuxer<R> {
355 self.time_base355 self.time_base
356 }356 }
357 357
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+
358 /// The next cluster into [`MatroskaDemuxer::queue`]; `false` at the end of370 /// The next cluster into [`MatroskaDemuxer::queue`]; `false` at the end of
359 /// the segment. `at` comes back holding the offset of the cluster read.371 /// the segment. `at` comes back holding the offset of the cluster read.
360 fn load_cluster(&mut self, at: &mut u64) -> Result<bool> {372 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> {
945 "A_VORBIS" => CodecId::Vorbis,957 "A_VORBIS" => CodecId::Vorbis,
946 "A_AC3" => CodecId::Ac3,958 "A_AC3" => CodecId::Ac3,
947 "A_EAC3" => CodecId::EAc3,959 "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,
948 "A_FLAC" => CodecId::Flac,964 "A_FLAC" => CodecId::Flac,
949 "A_ALAC" => CodecId::Alac,965 "A_ALAC" => CodecId::Alac,
950 "S_TEXT/UTF8" => CodecId::Srt,966 "S_TEXT/UTF8" => CodecId::Srt,