introduce NADecoderSupport and buffer pools
[nihav.git] / nihav-game / src / codecs / bmv3.rs
index 66afc4ffd60b57cc85ba29130502028512a7e7ad..f6067cf308a663c8d34b2bd8b3ab42e503482cc3 100644 (file)
@@ -69,7 +69,7 @@ impl NibbleReader {
 }
 
 struct BMV3VideoDecoder {
-    info:       Rc<NACodecInfo>,
+    info:       NACodecInfoRef,
     stride:     usize,
     height:     usize,
     frame:      Vec<u16>,
@@ -85,7 +85,6 @@ struct BMV3VideoDecoder {
 
 impl BMV3VideoDecoder {
     fn new() -> Self {
-        let dummy_info = Rc::new(DUMMY_CODEC_INFO);
         let mut frame1 = Vec::with_capacity(BMV_MAX_SIZE);
         frame1.resize(BMV_MAX_SIZE, 0);
         let mut frame2 = Vec::with_capacity(BMV_MAX_SIZE);
@@ -103,7 +102,7 @@ impl BMV3VideoDecoder {
         }
 
         Self {
-            info:       dummy_info,
+            info:       NACodecInfoRef::default(),
             stride:     0,
             height:     0,
             frame:      frame1,
@@ -442,10 +441,10 @@ impl BMV3VideoDecoder {
 }
 
 impl NADecoder for BMV3VideoDecoder {
-    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 myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, RGB565_FORMAT));
-            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.stride = vinfo.get_width();
             self.height = vinfo.get_height();
@@ -458,7 +457,7 @@ impl NADecoder for BMV3VideoDecoder {
             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();
         validate!(src.len() > 1);
 
@@ -491,7 +490,7 @@ impl NADecoder for BMV3VideoDecoder {
         {
             let mut buf = bufinfo.get_vbuf16().unwrap();
             let stride = buf.get_stride(0);
-            let mut data = buf.get_data_mut();
+            let data = buf.get_data_mut().unwrap();
             let dst = data.as_mut_slice();
 
             let refbuf = &self.frame[self.stride..];
@@ -505,7 +504,7 @@ impl NADecoder for BMV3VideoDecoder {
         let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
         frm.set_keyframe(self.is_intra);
         frm.set_frame_type(if self.is_intra { FrameType::I } else { FrameType::P });
-        Ok(Rc::new(RefCell::new(frm)))
+        Ok(frm.into_ref())
     }
 }
 
@@ -553,7 +552,7 @@ fn decode_block(mode: u8, src: &[u8], dst: &mut [i16], mut pred: i16) -> i16 {
 }
 
 impl NADecoder for BMV3AudioDecoder {
-    fn init(&mut self, info: Rc<NACodecInfo>) -> DecoderResult<()> {
+    fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
         if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
             self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), formats::SND_S16P_FORMAT, 32);
             self.chmap = NAChannelMap::from_str("L,R").unwrap();
@@ -562,7 +561,7 @@ impl NADecoder for BMV3AudioDecoder {
             Err(DecoderError::InvalidData)
         }
     }
-    fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
+    fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let info = pkt.get_stream().get_info();
         if let NACodecTypeInfo::Audio(_) = info.get_properties() {
             let pktbuf = pkt.get_buffer();
@@ -571,7 +570,7 @@ impl NADecoder for BMV3AudioDecoder {
             let abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
             let mut adata = abuf.get_abuf_i16().unwrap();
             let off1 = adata.get_offset(1);
-            let mut dst = adata.get_data_mut();
+            let dst = adata.get_data_mut().unwrap();
             let mut first = pktbuf[0] == 0;
             let psrc = &pktbuf[1..];
             for (n, src) in psrc.chunks_exact(41).enumerate() {
@@ -592,7 +591,7 @@ impl NADecoder for BMV3AudioDecoder {
             let mut frm = NAFrame::new_from_pkt(pkt, info, abuf);
             frm.set_duration(Some(samples as u64));
             frm.set_keyframe(false);
-            Ok(Rc::new(RefCell::new(frm)))
+            Ok(frm.into_ref())
         } else {
             Err(DecoderError::InvalidData)
         }