From 603abb8685c773e233a1d406fb732cb28452df09 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 4 Dec 2024 18:37:11 +0100 Subject: [PATCH] indeo: extend Indeo 2 decoder to support IMA RTV2 as well --- nihav-indeo/src/codecs/indeo2.rs | 40 +++++++++++++++++++++++++++----- nihav-indeo/src/codecs/mod.rs | 2 ++ nihav-registry/src/register.rs | 1 + 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index 50af67a..ff17b54 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -188,15 +188,16 @@ struct Indeo2Decoder { info: NACodecInfoRef, cb: Codebook, frmmgr: HAMShuffler, + rtv2: bool, } #[allow(clippy::identity_op)] impl Indeo2Decoder { - fn new() -> Self { + fn new(rtv2: bool) -> Self { let dummy_info = NACodecInfo::new_dummy(); let mut coderead = IR2CodeReader{}; let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap(); - Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new() } + Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new(), rtv2 } } fn decode_plane_intra(&self, br: &mut BitReader, @@ -311,8 +312,12 @@ const IR2_START: usize = 48; impl NADecoder for Indeo2Decoder { fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { - let w = vinfo.get_width(); - let h = vinfo.get_height(); + // The only known RTV2 sample uses conventional Indeo 2 format but codes twice as small picture + let (w, h) = if !self.rtv2 { + (vinfo.width, vinfo.height) + } else { + (vinfo.width / 2, vinfo.height / 2) + }; let f = vinfo.is_flipped(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); @@ -373,7 +378,11 @@ impl NAOptionHandler for Indeo2Decoder { } pub fn get_decoder() -> Box { - Box::new(Indeo2Decoder::new()) + Box::new(Indeo2Decoder::new(false)) +} + +pub fn get_decoder_rtv2() -> Box { + Box::new(Indeo2Decoder::new(true)) } #[cfg(test)] @@ -381,9 +390,28 @@ mod test { use nihav_core::codecs::RegisteredDecoders; use nihav_core::demuxers::RegisteredDemuxers; use nihav_codec_support::test::dec_video::*; - use crate::indeo_register_all_decoders; + use crate::*; use nihav_commonfmt::generic_register_all_demuxers; #[test] + fn test_rtv2() { + let mut dmx_reg = RegisteredDemuxers::new(); + indeo_register_all_demuxers(&mut dmx_reg); + let mut dec_reg = RegisteredDecoders::new(); + indeo_register_all_decoders(&mut dec_reg); + + // sample comes from a demo by Digital Video Arts + test_decoding("dvi", "ima-rtv2", "assets/Indeo/YULELOG.AVS", Some(7), + &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![ + [0xcf6c556c, 0x4517cf10, 0x6831ced5, 0xc0d5df2e], + [0x19182a32, 0x0929c079, 0x5ee02d73, 0x8eb2292f], + [0x89fa94fc, 0xf8098a83, 0x9c82e77e, 0x402b4048], + [0xb1aef0a3, 0x27683f69, 0xe6328f7f, 0x810d922f], + [0xaa386982, 0xd205dcd1, 0x74d9ec2b, 0x38c0db83], + [0xc4a43fd2, 0x4b74e5cc, 0x77cb5f03, 0x8b2995e4], + [0xa35a2a2f, 0xf4d811be, 0x6beaa06c, 0x823fdaa3], + [0x4a841217, 0x1f42c091, 0xeeab933f, 0xfab83333]])); + } + #[test] fn test_indeo2() { let mut dmx_reg = RegisteredDemuxers::new(); generic_register_all_demuxers(&mut dmx_reg); diff --git a/nihav-indeo/src/codecs/mod.rs b/nihav-indeo/src/codecs/mod.rs index 78b8eae..317a636 100644 --- a/nihav-indeo/src/codecs/mod.rs +++ b/nihav-indeo/src/codecs/mod.rs @@ -39,6 +39,8 @@ mod ividsp; mod imc; const INDEO_CODECS: &[DecoderInfo] = &[ +#[cfg(feature="decoder_indeo2")] + DecoderInfo { name: "ima-rtv2", get_decoder: indeo2::get_decoder_rtv2 }, #[cfg(feature="decoder_indeo2")] DecoderInfo { name: "indeo2", get_decoder: indeo2::get_decoder }, #[cfg(feature="decoder_indeo3")] diff --git a/nihav-registry/src/register.rs b/nihav-registry/src/register.rs index b9888b9..ca51898 100644 --- a/nihav-registry/src/register.rs +++ b/nihav-registry/src/register.rs @@ -157,6 +157,7 @@ static CODEC_REGISTER: &[CodecDescription] = &[ desc!(video-im; "indeo1", "Intel Raw IF09"), desc!(video; "indeo2", "Intel Indeo 2"), + desc!(video; "ima-rtv2", "Intel RTV 2 (Indeo 2)"), desc!(video; "indeo3", "Intel Indeo 3"), desc!(video; "indeo4", "Intel Indeo 4", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE), desc!(video; "indeo5", "Intel Indeo 5", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE), -- 2.39.5