-use std::rc::Rc;
-use std::cell::RefCell;
use nihav_core::io::bitreader::*;
use nihav_core::io::codebook::*;
use nihav_core::formats;
}
struct Intel263Decoder {
- info: Rc<NACodecInfo>,
+ info: NACodecInfoRef,
dec: H263BaseDecoder,
tables: Tables,
bdsp: H263BlockDSP,
fn new(src: &'a [u8], tables: &'a Tables) -> Self {
Intel263BR {
br: BitReader::new(src, src.len(), BitReaderMode::BE),
- tables: tables,
+ tables,
gob_no: 0,
mb_w: 0,
is_pb: false,
if !coded { return Ok(()); }
let rl_cb = &self.tables.rl_cb; // could be aic too
- let q_add = if quant == 0 { 0i16 } else { ((quant - 1) | 1) as i16 };
- let q = (quant * 2) as i16;
+ let q_add = if quant == 0 { 0i16 } else { i16::from((quant - 1) | 1) };
+ let q = i16::from(quant * 2);
while idx < 64 {
let code = br.read_cb(rl_cb)?;
let run;
}
idx += run;
validate!(idx < 64);
- let oidx = H263_ZIGZAG[idx as usize];
+ let oidx = ZIGZAG[idx as usize];
blk[oidx] = level;
idx += 1;
if last { break; }
}
fn decode_mv_component(br: &mut BitReader, mv_cb: &Codebook<u8>) -> DecoderResult<i16> {
- let code = br.read_cb(mv_cb)? as i16;
+ let code = i16::from(br.read_cb(mv_cb)?);
if code == 0 { return Ok(0) }
if !br.read_bool()? {
Ok(code)
let dquant = (cbpc & 4) != 0;
if dquant {
let idx = br.read(2)? as usize;
- q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
+ q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8;
}
Ok(BlockInfo::new(Type::I, cbp, q))
},
let cbp = (cbpy << 2) | (cbpc & 3);
if dquant {
let idx = br.read(2)? as usize;
- q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
+ q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8;
}
let mut binfo = BlockInfo::new(Type::I, cbp, q);
binfo.set_bpart(bbinfo);
let cbp = (cbpy << 2) | (cbpc & 3);
if dquant {
let idx = br.read(2)? as usize;
- q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
+ q = (i16::from(q) + i16::from(H263_DQUANT_TAB[idx])) as u8;
}
let mut binfo = BlockInfo::new(Type::P, cbp, q);
binfo.set_bpart(bbinfo);
let mut coderead = H263ShortCodeReader::new(H263_MV);
let mv_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
let tables = Tables {
- intra_mcbpc_cb: intra_mcbpc_cb,
- inter_mcbpc_cb: inter_mcbpc_cb,
- cbpy_cb: cbpy_cb,
- rl_cb: rl_cb,
- aic_rl_cb: aic_rl_cb,
- mv_cb: mv_cb,
+ intra_mcbpc_cb,
+ inter_mcbpc_cb,
+ cbpy_cb,
+ rl_cb,
+ aic_rl_cb,
+ mv_cb,
};
Intel263Decoder{
- info: Rc::new(DUMMY_CODEC_INFO),
+ info: NACodecInfo::new_dummy(),
dec: H263BaseDecoder::new(true),
- tables: tables,
+ tables,
bdsp: H263BlockDSP::new(),
}
}
}
impl NADecoder for Intel263Decoder {
- fn init(&mut self, info: Rc<NACodecInfo>) -> 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::YUV420_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();
Ok(())
} else {
Err(DecoderError::InvalidData)
}
}
- fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
+ fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
if src.len() == 8 {
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), buftype);
frm.set_keyframe(false);
frm.set_frame_type(if is_skip { FrameType::Skip } else { FrameType::B });
- return Ok(Rc::new(RefCell::new(frm)));
+ return Ok(frm.into_ref());
}
let mut ibr = Intel263BR::new(&src, &self.tables);
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
frm.set_keyframe(self.dec.is_intra());
frm.set_frame_type(if self.dec.is_intra() { FrameType::I } else { FrameType::P });
- Ok(Rc::new(RefCell::new(frm)))
+ Ok(frm.into_ref())
+ }
+ fn flush(&mut self) {
+ self.dec.flush();
}
}
-pub fn get_decoder() -> Box<NADecoder> {
+pub fn get_decoder() -> Box<dyn NADecoder> {
Box::new(Intel263Decoder::new())
}