B5: one PCM table (pcm_codec/pcm_bits) shared by ec-matroska demux and mux
Browse files at this commit22a66264fe0b8f2fe31de953503e1368f41e54ebParent: c7763752 changed files +25 -7
crates/ec-matroska/src/demux.rsmodified+14 -2
| @@ -1204,8 +1204,6 @@ pub(crate) fn codec_of(id: &str, bit_depth: u32) -> Result<Option<CodecId>> { | |||
| 1204 | })) | 1204 | })) |
| 1205 | } | 1205 | } |
| 1206 | 1206 | ||
| 1207 | -/// The PCM codec an `A_PCM/*` id and its `BitDepth` name. Matroska defines only | ||
| 1208 | -/// 32-bit float, and it is little-endian; any other float depth is refused. | ||
| 1209 | pub(crate) fn pcm_codec(big: bool, float: bool, bits: u32) -> Result<CodecId> { | 1207 | pub(crate) fn pcm_codec(big: bool, float: bool, bits: u32) -> Result<CodecId> { |
| 1210 | Ok(match (float, big, bits) { | 1208 | Ok(match (float, big, bits) { |
| 1211 | (true, _, 0 | 32) => CodecId::PcmF32Le, | 1209 | (true, _, 0 | 32) => CodecId::PcmF32Le, |
| @@ -1225,6 +1223,20 @@ pub(crate) fn pcm_codec(big: bool, float: bool, bits: u32) -> Result<CodecId> { | |||
| 1225 | }) | 1223 | }) |
| 1226 | } | 1224 | } |
| 1227 | 1225 | ||
| 1226 | +pub(crate) fn pcm_bits(codec: CodecId) -> Option<(bool, bool, u32)> { | ||
| 1227 | + Some(match codec { | ||
| 1228 | + CodecId::PcmU8 => (false, false, 8), | ||
| 1229 | + CodecId::PcmS16Le => (false, false, 16), | ||
| 1230 | + CodecId::PcmS24Le => (false, false, 24), | ||
| 1231 | + CodecId::PcmS32Le => (false, false, 32), | ||
| 1232 | + CodecId::PcmS16Be => (true, false, 16), | ||
| 1233 | + CodecId::PcmS24Be => (true, false, 24), | ||
| 1234 | + CodecId::PcmS32Be => (true, false, 32), | ||
| 1235 | + CodecId::PcmF32Le => (false, true, 32), | ||
| 1236 | + _ => return None, | ||
| 1237 | + }) | ||
| 1238 | +} | ||
| 1239 | + | ||
| 1228 | /// Codecs Matroska carries under a generic id and names only in `CodecPrivate`: | 1240 | /// Codecs Matroska carries under a generic id and names only in `CodecPrivate`: |
| 1229 | /// Avid DNxHD/DNxHR in a `V_QUICKTIME` track (the QuickTime sample description, | 1241 | /// Avid DNxHD/DNxHR in a `V_QUICKTIME` track (the QuickTime sample description, |
| 1230 | /// four-character code after its size) or a `V_MS/VFW/FOURCC` track (the | 1242 | /// four-character code after its size) or a `V_MS/VFW/FOURCC` track (the |
crates/ec-matroska/src/mux.rsmodified+11 -5
| @@ -12,6 +12,7 @@ use ec_core::{ | |||
| 12 | TimeBase, | 12 | TimeBase, |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | +use crate::demux::pcm_bits; | ||
| 15 | use crate::ebml::{self, elem, elem_head_len, float, put_id, put_size, uint}; | 16 | use crate::ebml::{self, elem, elem_head_len, float, put_id, put_size, uint}; |
| 16 | 17 | ||
| 17 | /// One millisecond, the tick every Matroska muxer writes and this one's block | 18 | /// 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> { | |||
| 767 | CodecId::Mp3 => "A_MPEG/L3", | 768 | CodecId::Mp3 => "A_MPEG/L3", |
| 768 | CodecId::Opus => "A_OPUS", | 769 | CodecId::Opus => "A_OPUS", |
| 769 | CodecId::Vorbis => "A_VORBIS", | 770 | CodecId::Vorbis => "A_VORBIS", |
| 770 | - CodecId::PcmU8 | CodecId::PcmS16Le | CodecId::PcmS24Le | CodecId::PcmS32Le => { | 771 | + CodecId::PcmU8 |
| 771 | - "A_PCM/INT/LIT" | 772 | + | CodecId::PcmS16Le |
| 772 | - } | 773 | + | CodecId::PcmS24Le |
| 773 | - CodecId::PcmS16Be => "A_PCM/INT/BIG", | 774 | + | CodecId::PcmS32Le |
| 774 | - CodecId::PcmF32Le => "A_PCM/FLOAT/IEEE", | 775 | + | CodecId::PcmS16Be |
| 776 | + | CodecId::PcmF32Le => match pcm_bits(codec) { | ||
| 777 | + Some((_, true, _)) => "A_PCM/FLOAT/IEEE", | ||
| 778 | + Some((true, _, _)) => "A_PCM/INT/BIG", | ||
| 779 | + _ => "A_PCM/INT/LIT", | ||
| 780 | + }, | ||
| 775 | CodecId::Srt => "S_TEXT/UTF8", | 781 | CodecId::Srt => "S_TEXT/UTF8", |
| 776 | CodecId::WebVtt => "S_TEXT/WEBVTT", | 782 | CodecId::WebVtt => "S_TEXT/WEBVTT", |
| 777 | CodecId::Ass => "S_TEXT/ASS", | 783 | CodecId::Ass => "S_TEXT/ASS", |