diff --git a/crates/ec-h264/src/decoder.rs b/crates/ec-h264/src/decoder.rs index a1763f93..05163272 100644 --- a/crates/ec-h264/src/decoder.rs +++ b/crates/ec-h264/src/decoder.rs @@ -826,14 +826,11 @@ impl Core { copy(&pic.cr, cx_c, cy_c, cw_c, ch_c), ]; let mut frame = VideoFrame::try_new( - match (pic.cat, S::IS_8) { - (3, true) => PixelFormat::I444, - (3, false) => PixelFormat::I410, - (2, true) => PixelFormat::I422, - (2, false) => PixelFormat::I210, - (_, true) => PixelFormat::I420, - (_, false) => PixelFormat::I010, - }, + S::FORMATS[match pic.cat { + 3 => 0, + 2 => 1, + _ => 2, + }], w as u32, h as u32, planes, diff --git a/crates/ec-h264/src/sample.rs b/crates/ec-h264/src/sample.rs index 75850e96..f9ad7a99 100644 --- a/crates/ec-h264/src/sample.rs +++ b/crates/ec-h264/src/sample.rs @@ -10,6 +10,7 @@ use crate::decoder::SliceCtx; use crate::mc::{compensate8, compensate16}; use crate::dpb::Picture; use ec_core::error::Result; +use ec_core::frame::PixelFormat; /// A picture sample. pub(crate) trait Sample: @@ -17,6 +18,7 @@ pub(crate) trait Sample: { /// True for the 8-bit instantiation. const IS_8: bool; + const FORMATS: [PixelFormat; 3]; /// Bytes per sample in an output frame. const BYTES: usize; /// Append `src` to an output plane, little-endian, shifted left by `shift`. @@ -74,6 +76,7 @@ pub(crate) trait Sample: impl Sample for u8 { const IS_8: bool = true; + const FORMATS: [PixelFormat; 3] = [PixelFormat::I444, PixelFormat::I422, PixelFormat::I420]; const BYTES: usize = 1; #[inline] fn extend_bytes(out: &mut Vec, src: &[u8], _shift: u32) { @@ -131,6 +134,7 @@ impl Sample for u8 { impl Sample for u16 { const IS_8: bool = false; + const FORMATS: [PixelFormat; 3] = [PixelFormat::I410, PixelFormat::I210, PixelFormat::I010]; const BYTES: usize = 2; #[inline] fn extend_bytes(out: &mut Vec, src: &[u16], shift: u32) {