X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-indeo%2Fsrc%2Fcodecs%2Fimc.rs;h=ea4d0b02d700c12eeb2375ebd1658b92aee655e3;hb=e6aaad5c5273cd814b5748b7faf3751835a37217;hp=f8a4f28fcb5acb0a7ffcc39212314b38877b37a6;hpb=08a1fab72215ea7716f51adf7008f85372e80c71;p=nihav.git diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index f8a4f28..ea4d0b0 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -7,8 +7,8 @@ use nihav_core::frame::*; use nihav_core::codecs::*; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; -use nihav_core::dsp::fft::*; -use nihav_core::dsp::window::*; +use nihav_codec_support::dsp::fft::*; +use nihav_codec_support::dsp::window::*; const BANDS: usize = 32; const COEFFS: usize = 256; @@ -103,6 +103,7 @@ impl BitAlloc { self.skip_flag[i] = false; } } + #[allow(clippy::cognitive_complexity)] fn calculate_bit_allocation(&mut self, ch_data: &mut IMCChannel, bits: usize, fixed_head: bool, adj_idx: usize) -> DecoderResult<()> { let mut peak = 0.0; @@ -160,7 +161,7 @@ impl BitAlloc { if len < 0 { len = 0; } if len > 6 { len = 6; } self.band_bits[band] = len as u8; - cur_bits += (self.band_width[band] as i32) * (len as i32); + cur_bits += (self.band_width[band] as i32) * len; if len > 0 { acc += self.band_width[band] as i32; } @@ -347,7 +348,6 @@ fn calc_maxcoef(coef: f32) -> (f32, f32) { impl IMCDecoder { fn new(is_imc: bool) -> Self { - let mut codes: [[Codebook; 4]; 4]; let mut cycle1: [usize; BANDS] = [0; BANDS]; let mut cycle2: [usize; BANDS] = [0; BANDS]; let mut weights1: [f32; BANDS-1] = [0.0; BANDS-1]; @@ -358,15 +358,16 @@ impl IMCDecoder { weights1.copy_from_slice(&IMC_WEIGHTS1); weights2.copy_from_slice(&IMC_WEIGHTS2); } - unsafe { - codes = mem::uninitialized(); - for i in 0..4 { - for j in 0..4 { - let mut cr = IMCCodeReader::new(i, j); - ptr::write(&mut codes[i][j], Codebook::new(&mut cr, CodebookMode::MSB).unwrap()); + let codes = unsafe { + let mut ucodes: mem::MaybeUninit::<[[Codebook; 4]; 4]> = mem::MaybeUninit::uninit(); + for i in 0..4 { + for j in 0..4 { + let mut cr = IMCCodeReader::new(i, j); + ptr::write(&mut (*ucodes.as_mut_ptr())[i][j], Codebook::new(&mut cr, CodebookMode::MSB).unwrap()); + } } - } - } + ucodes.assume_init() + }; IMCDecoder { is_imc, chmap: NAChannelMap::new(), @@ -642,7 +643,7 @@ impl IMCDecoder { } if self.ba.band_present[band] { let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band]; - let bitsum = self.ba.band_bitsum[band] as usize; + let bitsum = self.ba.band_bitsum[band]; if (bitsum > 0) && (((band_w * 3) >> 1) > bitsum) { self.ba.band_skip[band] = true; } @@ -651,7 +652,7 @@ impl IMCDecoder { self.read_skip_flags(br)?; - let mut ch_data = &mut self.ch_data[ch]; + let ch_data = &mut self.ch_data[ch]; for band in 0..BANDS { ch_data.adj_floor[band] = ch_data.new_floor[band]; let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band]; @@ -674,7 +675,7 @@ impl IMCDecoder { } if bits_freed < 0 { return Err(DecoderError::Bug); } - self.ba.adjust_bit_allocation(&mut ch_data, bits_freed); + self.ba.adjust_bit_allocation(ch_data, bits_freed); Ok(()) } @@ -728,7 +729,7 @@ impl IMCDecoder { } fn decode_block(&mut self, data: &[u8], ch: usize, dst: &mut [f32]) -> DecoderResult<()> { - let mut br = BitReader::new(&data[BLOCK_SIZE*ch..], BLOCK_SIZE, BitReaderMode::LE16MSB); + let mut br = BitReader::new(&data[BLOCK_SIZE*ch..][..BLOCK_SIZE], BitReaderMode::LE16MSB); let hdr = br.read(9)?; validate!((hdr & 0x18) == 0); @@ -902,8 +903,8 @@ impl NADecoder for IMCDecoder { let channels = self.ainfo.get_channels() as usize; for chunk in pktbuf.chunks(BLOCK_SIZE * channels) { for ch in 0..channels { - let off = abuf.get_offset(ch as usize) + start; - self.decode_block(chunk, ch as usize, &mut dst[off..off+COEFFS])?; + let off = abuf.get_offset(ch) + start; + self.decode_block(chunk, ch, &mut dst[off..off+COEFFS])?; } if (channels == 2) && ((chunk[1] & 0x20) != 0) { let off1 = abuf.get_offset(0) + start; @@ -926,6 +927,12 @@ impl NADecoder for IMCDecoder { } } +impl NAOptionHandler for IMCDecoder { + fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] } + fn set_options(&mut self, _options: &[NAOption]) { } + fn query_option_value(&self, _name: &str) -> Option { None } +} + pub fn get_decoder_imc() -> Box { Box::new(IMCDecoder::new(true)) } @@ -1111,18 +1118,19 @@ const IMC_CB_SELECTOR: [[usize; BANDS]; 4] = [ mod test { use nihav_core::codecs::RegisteredDecoders; use nihav_core::demuxers::RegisteredDemuxers; - use nihav_core::test::dec_video::*; - use crate::codecs::indeo_register_all_codecs; - use nihav_commonfmt::demuxers::generic_register_all_demuxers; + use nihav_codec_support::test::dec_video::*; + use crate::indeo_register_all_decoders; + use nihav_commonfmt::generic_register_all_demuxers; #[test] fn test_imc() { let mut dmx_reg = RegisteredDemuxers::new(); generic_register_all_demuxers(&mut dmx_reg); let mut dec_reg = RegisteredDecoders::new(); - indeo_register_all_codecs(&mut dec_reg); + indeo_register_all_decoders(&mut dec_reg); // let file = "assets/Indeo/neal73_saber.avi"; // let file = "assets/Indeo/IMC/hvalen.avi"; + // sample from a private collection let file = "assets/Indeo/IMC/8khz.avi"; // let file = "assets/Indeo/STsKlassFist-1a.avi"; // let file = "assets/Indeo/IMC/Angel Bday.avi";