if br.read_bool()? {
let len = br.read(3)? as usize;
let mut present: [bool; 16] = [false; 16];
- for i in 0..len+1 {
+ for i in 0..=len {
self.syms[i] = br.read(4)? as u8;
present[self.syms[i] as usize] = true;
}
let len = br.read(2)? as usize;
let mut syms: [u8; 16] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let mut tmp: [u8; 16] = [0; 16];
- for bits in 0..len+1 {
+ for bits in 0..=len {
let size = 1 << bits;
for arr in syms.chunks_mut(size * 2) {
let mut ptr0 = 0;
#[derive(Default)]
struct BinkDecoder {
- info: Rc<NACodecInfo>,
+ info: NACodecInfoRef,
ips: IPShuffler,
hams: HAMShuffler,
let q_index = if let Some(qidx) = q { qidx } else { br.read(4)? as usize };
let qmat = &quant_matrices[q_index];
block[0] = block[0].wrapping_mul(qmat[0]) >> 11;
- for idx in coef_idx.into_iter().take(coef_count) {
+ for idx in coef_idx.iter().take(coef_count) {
block[scan[*idx]] = block[scan[*idx]].wrapping_mul(qmat[*idx]) >> 11;
}
const BINK_FLAG_GRAY: u32 = 0x00020000;
impl NADecoder for BinkDecoder {
- 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();
None, None, None, None, 0, 1);
}
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.init_bundle_lengths(w.max(8), (w + 7) >> 3);
self.init_bundle_bufs((w + 7) >> 3, (h + 7) >> 3);
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();
let mut br = BitReader::new(&src, src.len(), BitReaderMode::LE);
if let Some(bbuf) = bufret {
buf = bbuf;
} else {
- let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4)?;
buf = bufinfo.get_vbuf().unwrap();
self.key_frame = true;
self.hams.add_frame(buf);
buf = self.hams.get_output_frame().unwrap();
}
} else {
- let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4)?;
buf = bufinfo.get_vbuf().unwrap();
}
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
frm.set_frame_type(FrameType::P);
- Ok(Rc::new(RefCell::new(frm)))
+ Ok(frm.into_ref())
+ }
+ fn flush(&mut self) {
+ self.ips.clear();
}
}
-pub fn get_decoder() -> Box<NADecoder> {
+pub fn get_decoder() -> Box<dyn NADecoder + Send> {
Box::new(BinkDecoder::new())
}