From 22a66264fe0b8f2fe31de953503e1368f41e54eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 09:38:22 +0300 Subject: [PATCH] B5: one PCM table (pcm_codec/pcm_bits) shared by ec-matroska demux and mux pcm_bits(CodecId) gives (big, float, bits); mux picks the A_PCM element name from it. Mux emits no BitDepth, so bytes are unchanged for all codecs it accepted before. BE 24/32 stay refused by mux. Doc comment removed (no comments rule). --- crates/ec-matroska/src/demux.rs | 16 ++++++++++++++-- crates/ec-matroska/src/mux.rs | 16 +++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/ec-matroska/src/demux.rs b/crates/ec-matroska/src/demux.rs index 07b244dd..2f82b8af 100644 --- a/crates/ec-matroska/src/demux.rs +++ b/crates/ec-matroska/src/demux.rs @@ -1204,8 +1204,6 @@ pub(crate) fn codec_of(id: &str, bit_depth: u32) -> Result> { })) } -/// The PCM codec an `A_PCM/*` id and its `BitDepth` name. Matroska defines only -/// 32-bit float, and it is little-endian; any other float depth is refused. pub(crate) fn pcm_codec(big: bool, float: bool, bits: u32) -> Result { Ok(match (float, big, bits) { (true, _, 0 | 32) => CodecId::PcmF32Le, @@ -1225,6 +1223,20 @@ pub(crate) fn pcm_codec(big: bool, float: bool, bits: u32) -> Result { }) } +pub(crate) fn pcm_bits(codec: CodecId) -> Option<(bool, bool, u32)> { + Some(match codec { + CodecId::PcmU8 => (false, false, 8), + CodecId::PcmS16Le => (false, false, 16), + CodecId::PcmS24Le => (false, false, 24), + CodecId::PcmS32Le => (false, false, 32), + CodecId::PcmS16Be => (true, false, 16), + CodecId::PcmS24Be => (true, false, 24), + CodecId::PcmS32Be => (true, false, 32), + CodecId::PcmF32Le => (false, true, 32), + _ => return None, + }) +} + /// Codecs Matroska carries under a generic id and names only in `CodecPrivate`: /// Avid DNxHD/DNxHR in a `V_QUICKTIME` track (the QuickTime sample description, /// four-character code after its size) or a `V_MS/VFW/FOURCC` track (the diff --git a/crates/ec-matroska/src/mux.rs b/crates/ec-matroska/src/mux.rs index 18a877d1..202a1d40 100644 --- a/crates/ec-matroska/src/mux.rs +++ b/crates/ec-matroska/src/mux.rs @@ -12,6 +12,7 @@ use ec_core::{ TimeBase, }; +use crate::demux::pcm_bits; use crate::ebml::{self, elem, elem_head_len, float, put_id, put_size, uint}; /// One millisecond, the tick every Matroska muxer writes and this one's block @@ -767,11 +768,16 @@ pub(crate) fn matroska_codec_id(codec: CodecId) -> Result<&'static str> { CodecId::Mp3 => "A_MPEG/L3", CodecId::Opus => "A_OPUS", CodecId::Vorbis => "A_VORBIS", - CodecId::PcmU8 | CodecId::PcmS16Le | CodecId::PcmS24Le | CodecId::PcmS32Le => { - "A_PCM/INT/LIT" - } - CodecId::PcmS16Be => "A_PCM/INT/BIG", - CodecId::PcmF32Le => "A_PCM/FLOAT/IEEE", + CodecId::PcmU8 + | CodecId::PcmS16Le + | CodecId::PcmS24Le + | CodecId::PcmS32Le + | CodecId::PcmS16Be + | CodecId::PcmF32Le => match pcm_bits(codec) { + Some((_, true, _)) => "A_PCM/FLOAT/IEEE", + Some((true, _, _)) => "A_PCM/INT/BIG", + _ => "A_PCM/INT/LIT", + }, CodecId::Srt => "S_TEXT/UTF8", CodecId::WebVtt => "S_TEXT/WEBVTT", CodecId::Ass => "S_TEXT/ASS",