X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fcodecs%2Fmod.rs;h=4ea379d59bc64294e19036e006d19a2e1ea03b89;hb=6011e20199143f519881660144a4ca95ba77fd2d;hp=76c683d0a9adae6cb7d0fd97fe9a2e37b7e42961;hpb=38953fb529efad1b0b609eec77f7839e62ad2719;p=nihav.git diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 76c683d..4ea379d 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -1,9 +1,7 @@ use std::fmt; use std::ops::{Add, AddAssign, Sub, SubAssign}; -use crate::frame::*; -use std::rc::Rc; -use std::cell::RefCell; +pub use crate::frame::*; use std::mem; use crate::io::byteio::ByteIOError; use crate::io::bitreader::BitReaderError; @@ -45,13 +43,9 @@ impl From for DecoderError { fn from(_: AllocatorError) -> Self { DecoderError::AllocError } } -macro_rules! validate { - ($a:expr) => { if !$a { println!("check failed at {}:{}", file!(), line!()); return Err(DecoderError::InvalidData); } }; -} - #[allow(dead_code)] pub struct HAMShuffler { - lastframe: Option>, + lastframe: Option>, } impl HAMShuffler { @@ -60,21 +54,21 @@ impl HAMShuffler { #[allow(dead_code)] pub fn clear(&mut self) { self.lastframe = None; } #[allow(dead_code)] - pub fn add_frame(&mut self, buf: NAVideoBuffer) { + pub fn add_frame(&mut self, buf: NAVideoBufferRef) { self.lastframe = Some(buf); } #[allow(dead_code)] - pub fn clone_ref(&mut self) -> Option> { + pub fn clone_ref(&mut self) -> Option> { if let Some(ref mut frm) = self.lastframe { let newfrm = frm.copy_buffer(); - *frm = newfrm.clone(); - Some(newfrm) + *frm = newfrm.clone().into_ref(); + Some(newfrm.into_ref()) } else { None } } #[allow(dead_code)] - pub fn get_output_frame(&mut self) -> Option> { + pub fn get_output_frame(&mut self) -> Option> { match self.lastframe { Some(ref frm) => Some(frm.clone()), None => None, @@ -82,9 +76,13 @@ impl HAMShuffler { } } +impl Default for HAMShuffler { + fn default() -> Self { Self { lastframe: None } } +} + #[allow(dead_code)] pub struct IPShuffler { - lastframe: Option>, + lastframe: Option>, } impl IPShuffler { @@ -93,11 +91,11 @@ impl IPShuffler { #[allow(dead_code)] pub fn clear(&mut self) { self.lastframe = None; } #[allow(dead_code)] - pub fn add_frame(&mut self, buf: NAVideoBuffer) { + pub fn add_frame(&mut self, buf: NAVideoBufferRef) { self.lastframe = Some(buf); } #[allow(dead_code)] - pub fn get_ref(&mut self) -> Option> { + pub fn get_ref(&mut self) -> Option> { if let Some(ref frm) = self.lastframe { Some(frm.clone()) } else { @@ -106,10 +104,14 @@ impl IPShuffler { } } +impl Default for IPShuffler { + fn default() -> Self { Self { lastframe: None } } +} + #[allow(dead_code)] pub struct IPBShuffler { - lastframe: Option>, - nextframe: Option>, + lastframe: Option>, + nextframe: Option>, } impl IPBShuffler { @@ -118,12 +120,12 @@ impl IPBShuffler { #[allow(dead_code)] pub fn clear(&mut self) { self.lastframe = None; self.nextframe = None; } #[allow(dead_code)] - pub fn add_frame(&mut self, buf: NAVideoBuffer) { + pub fn add_frame(&mut self, buf: NAVideoBufferRef) { mem::swap(&mut self.lastframe, &mut self.nextframe); self.lastframe = Some(buf); } #[allow(dead_code)] - pub fn get_lastref(&mut self) -> Option> { + pub fn get_lastref(&mut self) -> Option> { if let Some(ref frm) = self.lastframe { Some(frm.clone()) } else { @@ -131,7 +133,7 @@ impl IPBShuffler { } } #[allow(dead_code)] - pub fn get_nextref(&mut self) -> Option> { + pub fn get_nextref(&mut self) -> Option> { if let Some(ref frm) = self.nextframe { Some(frm.clone()) } else { @@ -139,7 +141,7 @@ impl IPBShuffler { } } #[allow(dead_code)] - pub fn get_b_fwdref(&mut self) -> Option> { + pub fn get_b_fwdref(&mut self) -> Option> { if let Some(ref frm) = self.nextframe { Some(frm.clone()) } else { @@ -147,7 +149,7 @@ impl IPBShuffler { } } #[allow(dead_code)] - pub fn get_b_bwdref(&mut self) -> Option> { + pub fn get_b_bwdref(&mut self) -> Option> { if let Some(ref frm) = self.lastframe { Some(frm.clone()) } else { @@ -156,7 +158,11 @@ impl IPBShuffler { } } -#[derive(Debug,Clone,Copy,PartialEq)] +impl Default for IPBShuffler { + fn default() -> Self { Self { lastframe: None, nextframe: None } } +} + +#[derive(Debug,Clone,Copy,Default,PartialEq)] pub struct MV { pub x: i16, pub y: i16, @@ -223,16 +229,32 @@ impl fmt::Display for MV { } } +pub struct NADecoderSupport { + pub pool_u8: NAVideoBufferPool, + pub pool_u16: NAVideoBufferPool, + pub pool_u32: NAVideoBufferPool, +} + +impl NADecoderSupport { + pub fn new() -> Self { + Self { + pool_u8: NAVideoBufferPool::new(0), + pool_u16: NAVideoBufferPool::new(0), + pool_u32: NAVideoBufferPool::new(0), + } + } +} + pub trait NADecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()>; - fn decode(&mut self, pkt: &NAPacket) -> DecoderResult; + fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()>; + fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult; } #[derive(Clone,Copy)] pub struct DecoderInfo { pub name: &'static str, - pub get_decoder: fn () -> Box, + pub get_decoder: fn () -> Box, } #[cfg(any(feature="h263"))] @@ -252,7 +274,7 @@ impl RegisteredDecoders { pub fn add_decoder(&mut self, dec: DecoderInfo) { self.decs.push(dec); } - pub fn find_decoder(&self, name: &str) -> Option Box> { + pub fn find_decoder(&self, name: &str) -> Option Box> { for &dec in self.decs.iter() { if dec.name == name { return Some(dec.get_decoder); @@ -260,4 +282,7 @@ impl RegisteredDecoders { } None } + pub fn iter(&self) -> std::slice::Iter { + self.decs.iter() + } }