Give every audio and video codec its own registered Matroska CodecID

MkvTrack::audio's catch-all was `_ => CODEC_AC3`, and ebml.rs defined no
A_AAC, A_MPEG/L2, A_MPEG/L3, A_FLAC or A_OPUS constant at all. A CodecID
names the payload, so any of those codecs was written into the MKV declaring
AC-3 while carrying something else — a player either refuses the track or
decodes noise.

Reachable through two ordinary paths, both verified: ifo.rs:577 maps DVD
audio_coding_mode 3 to Codec::Mp2, so a DVD with MPEG audio muxed to mkv://
produced a track declaring A_AC3 over MP2 bytes; and mp4/read.rs:479 maps the
`mp4a` sample entry to Codec::Aac for an mp4:// source. codec/mod.rs already
has working parsers for MP2, MP3, AAC, FLAC and Opus, so the pipeline carried
these codecs end to end and only the container label was wrong.

MkvTrack::video had the same shape: `_ => CODEC_MPEG2` announced Codec::Mpeg1
and Codec::Av1 as MPEG-2 video. V_MPEG1 and V_AV1 added.

Both catch-alls stay, because MkvTrack::audio/video return Self and have no
error channel, but they are now reachable only by a non-audio/non-video or
Unknown codec routed there in error. Two tests enumerate every real codec of
each kind and cross-check each against Codec::kind(), so a codec added to the
enum later cannot silently inherit another codec's ID.

Both proven red first: Aac declared A_AC3 before the fix.
This commit is contained in:
Matthew Jackson
2026-07-29 18:34:53 -07:00
parent b2c7490b5b
commit ea72e6df5f
2 changed files with 126 additions and 0 deletions
+17
View File
@@ -582,11 +582,28 @@ pub const CODEC_HEVC: &str = "V_MPEGH/ISO/HEVC";
pub const CODEC_H264: &str = "V_MPEG4/ISO/AVC";
pub const CODEC_VC1: &str = "V_MS/VFW/FOURCC";
pub const CODEC_MPEG2: &str = "V_MPEG2";
/// MPEG-1 Video. Distinct from V_MPEG2: a decoder selects its bitstream
/// parser from this ID.
pub const CODEC_MPEG1: &str = "V_MPEG1";
/// AV1. CodecPrivate carries the AV1CodecConfigurationRecord.
pub const CODEC_AV1: &str = "V_AV1";
pub const CODEC_AC3: &str = "A_AC3";
pub const CODEC_EAC3: &str = "A_EAC3";
pub const CODEC_TRUEHD: &str = "A_TRUEHD";
pub const CODEC_DTS: &str = "A_DTS";
pub const CODEC_PCM_BE: &str = "A_PCM/INT/BIG";
/// AAC. The generic registered ID; the AudioSpecificConfig travels in
/// CodecPrivate, so no profile suffix is needed (and the `A_AAC/MPEG4/*`
/// suffixed forms are legacy).
pub const CODEC_AAC: &str = "A_AAC";
/// MPEG-1/2 Audio Layer II — DVD audio_coding_mode 3.
pub const CODEC_MP2: &str = "A_MPEG/L2";
/// MPEG-1/2 Audio Layer III.
pub const CODEC_MP3: &str = "A_MPEG/L3";
/// FLAC. CodecPrivate carries the STREAMINFO metadata block.
pub const CODEC_FLAC: &str = "A_FLAC";
/// Opus. CodecPrivate carries the OpusHead identification header.
pub const CODEC_OPUS: &str = "A_OPUS";
pub const CODEC_PGS: &str = "S_HDMV/PGS";
pub const CODEC_VOBSUB: &str = "S_VOBSUB";