mark traits as dyn
[nihav.git] / nihav-game / src / codecs / vmd.rs
index a70ef6044e2518a3e47af225e3ae8b05ec556502..ea6c31dad92d84105ebe01fc1546c06a0a660d57 100644 (file)
@@ -147,7 +147,7 @@ fn decode_frame_data(br: &mut ByteReader, dst: &mut [u8], mut dpos: usize, strid
 }
 
 struct VMDVideoDecoder {
-    info:       Rc<NACodecInfo>,
+    info:       NACodecInfoRef,
     pal:        [u8; 768],
     buf:        Vec<u8>,
     width:      usize,
@@ -158,7 +158,7 @@ struct VMDVideoDecoder {
 impl VMDVideoDecoder {
     fn new() -> Self {
         Self {
-            info:       Rc::new(NACodecInfo::default()),
+            info:       NACodecInfoRef::default(),
             pal:        [0; 768],
             buf:        Vec::new(),
             width:      0,
@@ -169,7 +169,7 @@ impl VMDVideoDecoder {
     fn decode_frame(&mut self, br: &mut ByteReader, buf: &mut NAVideoBuffer<u8>) -> DecoderResult<bool> {
         let paloff = buf.get_offset(1);
         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 frame_x                             = br.read_u16le()? as usize;
@@ -215,12 +215,12 @@ impl VMDVideoDecoder {
 }
 
 impl NADecoder for VMDVideoDecoder {
-    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() {
             self.width  = vinfo.get_width();
             self.height = vinfo.get_height();
             let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(self.width, self.height, false, PAL8_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();
             validate!(info.get_extradata().is_some());
 
             if let Some(ref edata) = info.get_extradata() {
@@ -239,7 +239,7 @@ impl NADecoder for VMDVideoDecoder {
             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() >= 10);
 
@@ -264,12 +264,12 @@ impl NADecoder for VMDVideoDecoder {
         let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf));
         frm.set_keyframe(is_intra);
         frm.set_frame_type(if is_intra { FrameType::I } else { FrameType::P });
-        Ok(Rc::new(RefCell::new(frm)))
+        Ok(frm.into_ref())
     }
 }
 
 
-pub fn get_decoder_video() -> Box<NADecoder> {
+pub fn get_decoder_video() -> Box<dyn NADecoder> {
     Box::new(VMDVideoDecoder::new())
 }
 
@@ -351,7 +351,7 @@ impl VMDAudioDecoder {
 }
 
 impl NADecoder for VMDAudioDecoder {
-    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() {
             let fmt;
             if ainfo.get_format().get_bits() == 8 {
@@ -372,7 +372,7 @@ impl NADecoder for VMDAudioDecoder {
             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();
@@ -398,11 +398,11 @@ impl NADecoder for VMDAudioDecoder {
             if self.is16bit {
                 let mut adata = abuf.get_abuf_i16().unwrap();
                 let off1 = adata.get_offset(1);
-                let mut dst = adata.get_data_mut();
+                let mut dst = adata.get_data_mut().unwrap();
                 self.decode_16bit(&mut dst, off1, &mut br, nblocks, mask)?;
             } else {
                 let mut adata = abuf.get_abuf_u8().unwrap();
-                let mut dst = adata.get_data_mut();
+                let dst = adata.get_data_mut().unwrap();
                 let mut doff = 0;
                 let mut mask = mask;
                 let channels = self.chmap.num_channels();
@@ -433,14 +433,14 @@ impl NADecoder for VMDAudioDecoder {
             let mut frm = NAFrame::new_from_pkt(pkt, info, abuf);
             frm.set_duration(Some(samples as u64));
             frm.set_keyframe(true);
-            Ok(Rc::new(RefCell::new(frm)))
+            Ok(frm.into_ref())
         } else {
             Err(DecoderError::InvalidData)
         }
     }
 }
 
-pub fn get_decoder_audio() -> Box<NADecoder> {
+pub fn get_decoder_audio() -> Box<dyn NADecoder> {
     Box::new(VMDAudioDecoder::new())
 }