From: Kostya Shishkov Date: Tue, 30 Apr 2019 13:54:06 +0000 (+0200) Subject: switch NABufferType to use refs for video buffers X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=3fc28ece6664a34af9b7f6a52dbf8a8809fa9204;p=nihav.git switch NABufferType to use refs for video buffers --- diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 692269e..4f81d9e 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -45,7 +45,7 @@ impl From for DecoderError { #[allow(dead_code)] pub struct HAMShuffler { - lastframe: Option>, + lastframe: Option>, } impl HAMShuffler { @@ -54,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,7 +82,7 @@ impl Default for HAMShuffler { #[allow(dead_code)] pub struct IPShuffler { - lastframe: Option>, + lastframe: Option>, } impl IPShuffler { @@ -91,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 { @@ -110,8 +110,8 @@ impl Default for IPShuffler { #[allow(dead_code)] pub struct IPBShuffler { - lastframe: Option>, - nextframe: Option>, + lastframe: Option>, + nextframe: Option>, } impl IPBShuffler { @@ -120,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 { @@ -133,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 { @@ -141,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 { @@ -149,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 { diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index d219ee4..789088a 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -134,8 +134,13 @@ impl NAVideoBuffer { pub fn get_dimensions(&self, idx: usize) -> (usize, usize) { get_plane_size(&self.info, idx) } + pub fn into_ref(self) -> NABufferRef { + NABufferRef::new(self) + } } +pub type NAVideoBufferRef = NABufferRef>; + #[derive(Clone)] pub struct NAAudioBuffer { info: NAAudioInfo, @@ -173,10 +178,10 @@ impl NAAudioBuffer { #[derive(Clone)] pub enum NABufferType { - Video (NAVideoBuffer), - Video16 (NAVideoBuffer), - Video32 (NAVideoBuffer), - VideoPacked(NAVideoBuffer), + Video (NAVideoBufferRef), + Video16 (NAVideoBufferRef), + Video32 (NAVideoBufferRef), + VideoPacked(NAVideoBufferRef), AudioU8 (NAAudioBuffer), AudioI16 (NAAudioBuffer), AudioI32 (NAAudioBuffer), @@ -209,20 +214,20 @@ impl NABufferType { _ => None, } } - pub fn get_vbuf(&self) -> Option> { + pub fn get_vbuf(&self) -> Option> { match *self { NABufferType::Video(ref vb) => Some(vb.clone()), NABufferType::VideoPacked(ref vb) => Some(vb.clone()), _ => None, } } - pub fn get_vbuf16(&self) -> Option> { + pub fn get_vbuf16(&self) -> Option> { match *self { NABufferType::Video16(ref vb) => Some(vb.clone()), _ => None, } } - pub fn get_vbuf32(&self) -> Option> { + pub fn get_vbuf32(&self) -> Option> { match *self { NABufferType::Video32(ref vb) => Some(vb.clone()), _ => None, @@ -350,7 +355,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = Vec::with_capacity(new_size.unwrap()); data.resize(new_size.unwrap(), 0); let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video(buf)) + Ok(NABufferType::Video(buf.into_ref())) } else if !all_packed { for i in 0..fmt.get_num_comp() { let ochr = fmt.get_chromaton(i); @@ -375,17 +380,17 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = Vec::with_capacity(new_size); data.resize(new_size, 0); let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video(buf)) + Ok(NABufferType::Video(buf.into_ref())) } else if max_depth <= 16 { let mut data: Vec = Vec::with_capacity(new_size); data.resize(new_size, 0); let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video16(buf)) + Ok(NABufferType::Video16(buf.into_ref())) } else { let mut data: Vec = Vec::with_capacity(new_size); data.resize(new_size, 0); let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video32(buf)) + Ok(NABufferType::Video32(buf.into_ref())) } } else if all_bytealigned || unfit_elem_size { let elem_sz = fmt.get_elem_size(); @@ -398,7 +403,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::VideoPacked(buf)) + Ok(NABufferType::VideoPacked(buf.into_ref())) } else { let elem_sz = fmt.get_elem_size(); let new_sz = width.checked_mul(height); @@ -410,14 +415,14 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video16(buf)) + Ok(NABufferType::Video16(buf.into_ref())) }, 4 => { let mut data: Vec = Vec::with_capacity(new_size); data.resize(new_size, 0); strides.push(width); let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; - Ok(NABufferType::Video32(buf)) + Ok(NABufferType::Video32(buf.into_ref())) }, _ => unreachable!(), } diff --git a/nihav-duck/src/codecs/truemotion1.rs b/nihav-duck/src/codecs/truemotion1.rs index b8edd4e..c205b3c 100644 --- a/nihav-duck/src/codecs/truemotion1.rs +++ b/nihav-duck/src/codecs/truemotion1.rs @@ -129,27 +129,27 @@ impl Default for DeltaTables { } struct FrameBuf { - last16: Option>, - last24: Option>, + last16: Option>, + last24: Option>, } impl FrameBuf { - fn set16(&mut self, buf: NAVideoBuffer) { self.last16 = Some(buf); } - fn set24(&mut self, buf: NAVideoBuffer) { self.last24 = Some(buf); } - fn get16(&mut self) -> Option> { + fn set16(&mut self, buf: NAVideoBufferRef) { self.last16 = Some(buf); } + fn set24(&mut self, buf: NAVideoBufferRef) { self.last24 = Some(buf); } + fn get16(&mut self) -> Option> { if let Some(ref mut frm) = self.last16 { let newfrm = frm.copy_buffer(); - *frm = newfrm.clone(); - Some(newfrm) + *frm = newfrm.clone().into_ref(); + Some(newfrm.into_ref()) } else { None } } - fn get24(&mut self) -> Option> { + fn get24(&mut self) -> Option> { if let Some(ref mut frm) = self.last24 { let newfrm = frm.copy_buffer(); - *frm = newfrm.clone(); - Some(newfrm) + *frm = newfrm.clone().into_ref(); + Some(newfrm.into_ref()) } else { None } diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index d517cac..adde678 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -1,5 +1,5 @@ use nihav_core::formats::YUV420_FORMAT; -use nihav_core::frame::{NABufferType, NAVideoInfo, NAVideoBuffer, FrameType, alloc_video_buffer}; +use nihav_core::frame::{NABufferType, NAVideoInfo, NAVideoBuffer, NAVideoBufferRef, FrameType, alloc_video_buffer}; use nihav_core::codecs::{MV, ZERO_MV, DecoderError, DecoderResult, IPBShuffler}; use nihav_core::io::bitreader::{BitReader,BitReaderMode}; use nihav_core::io::intcode::*; @@ -767,7 +767,7 @@ pub struct RV34Decoder { ratio2: u32, is_b: bool, mbinfo: Vec, - avg_buf: NAVideoBuffer, + avg_buf: NAVideoBufferRef, base_ts: u64, } diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 82dce04..f064861 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -614,7 +614,7 @@ struct RealVideo60Decoder { dsp: RV60DSP, ipred: IntraPredContext, - avg_buf: NAVideoBuffer, + avg_buf: NAVideoBufferRef, y_coeffs: [i16; 16 * 16], u_coeffs: [i16; 8 * 8],