X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-indeo%2Fsrc%2Fcodecs%2Findeo3.rs;h=6e03cb3b308da41ed49dc8b065d9c521fc696df0;hb=f9be4e750dccff762b9a3d894faec50ffdb59233;hp=a99db74667b8ac2085569746cf9864b3747b97ab;hpb=1a967e6bad5f17943b4de0607078eb940ad5adfe;p=nihav.git diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index a99db74..6e03cb3 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats; use nihav_core::codecs::*; use nihav_core::io::byteio::*; @@ -225,7 +223,7 @@ fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topli } else if bufs.fbuf { for i in 0..8 { buf[i] = bufs.buf1[doff - stride + i]; } } else { - for i in 0..8 { buf[i] = bufs.buf1[doff - stride + i]; } + for i in 0..8 { buf[i] = bufs.buf2[doff - stride + i]; } } if topline && !firstline { for i in 0..4 { buf[i * 2 + 1] = buf[i * 2]; } @@ -254,7 +252,7 @@ fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topli } struct Indeo3Decoder { - info: Rc, + info: NACodecInfoRef, bpos: u8, bbuf: u8, width: u16, @@ -278,7 +276,7 @@ struct IV3Cell { impl IV3Cell { fn new(w: u16, h: u16) -> Self { - IV3Cell { x: 0, y: 0, w: w, h: h, d: 20, vqt: false, mv: None } + IV3Cell { x: 0, y: 0, w, h, d: 20, vqt: false, mv: None } } fn split_h(&self) -> (Self, Self) { let h1 = if self.h > 2 { ((self.h + 2) >> 2) << 1 } else { 1 }; @@ -308,7 +306,7 @@ impl IV3Cell { cell2.d -= 1; (cell1, cell2) } - fn no_mv(&self) -> bool { match self.mv { None => true, Some(_) => false } } + fn no_mv(&self) -> bool { self.mv.is_none() } } struct CellDecParams { @@ -330,7 +328,7 @@ const SKIP_OR_TREE: u8 = 2; impl Indeo3Decoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); + let dummy_info = NACodecInfo::new_dummy(); Indeo3Decoder { info: dummy_info, bpos: 0, bbuf: 0, width: 0, height: 0, mvs: Vec::new(), altquant: [0; 16], vq_offset: 0, bufs: Buffers::new() } @@ -367,8 +365,8 @@ impl Indeo3Decoder { sidx = 0; } else { let mv = cell.mv.unwrap(); - let mx = mv.x as i16; - let my = mv.y as i16; + let mx = i16::from(mv.x); + let my = i16::from(mv.y); let l = (cell.x as i16) * 4 + mx; let t = (cell.y as i16) * 4 + my; let r = ((cell.x + cell.w) as i16) * 4 + mx; @@ -475,7 +473,7 @@ impl Indeo3Decoder { tocopy = 4 - line; } if c >= 0xFD { - let nl = 257 - (c as i16) - (line as i16); + let nl = 257 - i16::from(c) - (line as i16); validate!(nl > 0); tocopy = nl as usize; } @@ -515,8 +513,8 @@ impl Indeo3Decoder { fn copy_cell(&mut self, cell: IV3Cell, off: usize, stride: usize) -> DecoderResult<()> { if cell.no_mv() { return Err(DecoderError::InvalidData); } let mv = cell.mv.unwrap(); - let mx = mv.x as i16; - let my = mv.y as i16; + let mx = i16::from(mv.x); + let my = i16::from(mv.y); let l = (cell.x as i16) * 4 + mx; let t = (cell.y as i16) * 4 + my; let r = ((cell.x + cell.w) as i16) * 4 + mx; @@ -648,7 +646,7 @@ impl Indeo3Decoder { for _ in 0..nvec { let x = br.read_byte()? as i8; let y = br.read_byte()? as i8; - self.mvs.push(MV{ x: x, y: y }); + self.mvs.push(MV{ x, y }); } let shift = if planeno == 0 { 2 } else { 4 }; @@ -673,7 +671,7 @@ impl Indeo3Decoder { for _ in 0..nvec { let y = br.read_byte()? as i8; let x = br.read_byte()? as i8; - self.mvs.push(MV{ x: x, y: y }); + self.mvs.push(MV{ x, y }); } let shift = if planeno == 0 { 2 } else { 4 }; @@ -690,20 +688,20 @@ const FLAG_KEYFRAME: u16 = 1 << 2; const FLAG_NONREF: u16 = 1 << 8; impl NADecoder for Indeo3Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + 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(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.bufs.reset(); Ok(()) } else { Err(DecoderError::InvalidData) } } - fn decode(&mut self, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); let mut mr = MemoryReader::new_read(&src); let mut br = ByteReader::new(&mut mr); @@ -717,7 +715,7 @@ impl NADecoder for Indeo3Decoder { if (frameno ^ hdr_2 ^ size ^ FRMH_TAG) != check { return Err(DecoderError::InvalidData); } - if (size as i64) > br.left() { return Err(DecoderError::InvalidData); } + if i64::from(size) > br.left() { return Err(DecoderError::InvalidData); } let ver = br.read_u16le()?; if ver != 32 { return Err(DecoderError::NotImplemented); } let flags = br.read_u16le()?; @@ -761,16 +759,14 @@ impl NADecoder for Indeo3Decoder { let vinfo = self.info.get_properties().get_video_info().unwrap(); validate!((vinfo.get_width() & !3) == (self.width & !3).into()); validate!((vinfo.get_height() & !3) == (self.height & !3).into()); - let bufret = alloc_video_buffer(vinfo, 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(vinfo, 4)?; let mut buf = bufinfo.get_vbuf().unwrap(); - let ystart = data_start + (yoff as u64); - let ustart = data_start + (uoff as u64); - let vstart = data_start + (voff as u64); - let yendpos = data_start + (yend as u64); - let uendpos = data_start + (uend as u64); - let vendpos = data_start + (vend as u64); + let ystart = data_start + u64::from(yoff); + let ustart = data_start + u64::from(uoff); + let vstart = data_start + u64::from(voff); + let yendpos = data_start + u64::from(yend); + let uendpos = data_start + u64::from(uend); + let vendpos = data_start + u64::from(vend); if intraframe { self.decode_plane_intra(&mut br, 0, ystart, yendpos)?; self.decode_plane_intra(&mut br, 1, ustart, uendpos)?; @@ -785,11 +781,14 @@ impl NADecoder for Indeo3Decoder { let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); frm.set_keyframe(intraframe); frm.set_frame_type(if intraframe { FrameType::I } else { FrameType::P }); - Ok(Rc::new(RefCell::new(frm))) + Ok(frm.into_ref()) + } + fn flush(&mut self) { + self.bufs.reset(); } } -pub fn get_decoder() -> Box { +pub fn get_decoder() -> Box { Box::new(Indeo3Decoder::new()) }