X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fframe.rs;h=e739559a2e3f69adc0736d67ee2ecdf085398047;hb=f6fa6f3404393e399a05c5d5cda7a35c4e41fb4a;hp=19c1733c9c716b7101f199d9301e62931f68c5e5;hpb=e189501ed92ffd55123f9fceb7e4c78ddf1be936;p=nihav.git diff --git a/src/frame.rs b/src/frame.rs index 19c1733..e739559 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -88,15 +88,14 @@ impl fmt::Display for NACodecTypeInfo { } } -pub type BufferRef = Rc>>; - pub type NABufferRefT = Rc>>; #[derive(Clone)] pub struct NAVideoBuffer { - info: NAVideoInfo, - data: NABufferRefT, - offs: Vec, + info: NAVideoInfo, + data: NABufferRefT, + offs: Vec, + strides: Vec, } impl NAVideoBuffer { @@ -112,11 +111,13 @@ impl NAVideoBuffer { data.clone_from(self.data.borrow().as_ref()); let mut offs: Vec = Vec::with_capacity(self.offs.len()); offs.clone_from(&self.offs); - NAVideoBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs } + let mut strides: Vec = Vec::with_capacity(self.strides.len()); + strides.clone_from(&self.strides); + NAVideoBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs, strides: strides } } pub fn get_stride(&self, idx: usize) -> usize { - if idx >= self.info.get_format().get_num_comp() { return 0; } - self.info.get_format().get_chromaton(idx).unwrap().get_linesize(self.info.get_width()) + if idx >= self.strides.len() { return 0; } + self.strides[idx] } pub fn get_dimensions(&self, idx: usize) -> (usize, usize) { get_plane_size(&self.info, idx) @@ -149,6 +150,12 @@ impl NAAudioBuffer { } } +impl NAAudioBuffer { + pub fn new_from_buf(info: NAAudioInfo, data: NABufferRefT, chmap: NAChannelMap) -> Self { + NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new() } + } +} + #[derive(Clone)] pub enum NABufferType { Video (NAVideoBuffer), @@ -156,6 +163,7 @@ pub enum NABufferType { VideoPacked(NAVideoBuffer), AudioU8 (NAAudioBuffer), AudioI16 (NAAudioBuffer), + AudioI32 (NAAudioBuffer), AudioF32 (NAAudioBuffer), AudioPacked(NAAudioBuffer), Data (NABufferRefT), @@ -178,6 +186,38 @@ impl NABufferType { pub fn get_vbuf(&mut self) -> Option> { match *self { NABufferType::Video(ref vb) => Some(vb.clone()), + NABufferType::VideoPacked(ref vb) => Some(vb.clone()), + _ => None, + } + } + pub fn get_vbuf16(&mut self) -> Option> { + match *self { + NABufferType::Video16(ref vb) => Some(vb.clone()), + _ => None, + } + } + pub fn get_abuf_u8(&mut self) -> Option> { + match *self { + NABufferType::AudioU8(ref ab) => Some(ab.clone()), + NABufferType::AudioPacked(ref ab) => Some(ab.clone()), + _ => None, + } + } + pub fn get_abuf_i16(&mut self) -> Option> { + match *self { + NABufferType::AudioI16(ref ab) => Some(ab.clone()), + _ => None, + } + } + pub fn get_abuf_i32(&mut self) -> Option> { + match *self { + NABufferType::AudioI32(ref ab) => Some(ab.clone()), + _ => None, + } + } + pub fn get_abuf_f32(&mut self) -> Option> { + match *self { + NABufferType::AudioF32(ref ab) => Some(ab.clone()), _ => None, } } @@ -192,7 +232,8 @@ pub enum AllocatorError { pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result { let fmt = &vinfo.format; let mut new_size: usize = 0; - let mut offs: Vec = Vec::new(); + let mut offs: Vec = Vec::new(); + let mut strides: Vec = Vec::new(); for i in 0..fmt.get_num_comp() { if fmt.get_chromaton(i) == None { return Err(AllocatorError::FormatError); } @@ -204,7 +245,9 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result Result = Vec::with_capacity(new_size.unwrap()); + data.resize(new_size.unwrap(), 0); + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; + Ok(NABufferType::Video(buf)) + } else if !all_packed { for i in 0..fmt.get_num_comp() { - let chr = fmt.get_chromaton(i).unwrap(); + let ochr = fmt.get_chromaton(i); + if let None = ochr { continue; } + let chr = ochr.unwrap(); if !vinfo.is_flipped() { offs.push(new_size as usize); } - let cur_w = chr.get_width(width); + let stride = chr.get_linesize(width); let cur_h = chr.get_height(height); - let cur_sz = cur_w.checked_mul(cur_h); + let cur_sz = stride.checked_mul(cur_h); if cur_sz == None { return Err(AllocatorError::TooLargeDimensions); } let new_sz = new_size.checked_add(cur_sz.unwrap()); if new_sz == None { return Err(AllocatorError::TooLargeDimensions); } @@ -229,16 +289,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: Rc::new(RefCell::new(data)), info: vinfo, offs: offs }; + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; Ok(NABufferType::Video(buf)) } else { let mut data: Vec = Vec::with_capacity(new_size); data.resize(new_size, 0); - let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs }; + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; Ok(NABufferType::Video16(buf)) } } else { @@ -250,7 +311,8 @@ 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: Rc::new(RefCell::new(data)), info: vinfo, offs: offs }; + strides.push(line_sz.unwrap()); + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; Ok(NABufferType::VideoPacked(buf)) } } @@ -375,6 +437,7 @@ pub enum FrameType { I, P, B, + Skip, Other, } @@ -384,6 +447,7 @@ impl fmt::Display for FrameType { FrameType::I => write!(f, "I"), FrameType::P => write!(f, "P"), FrameType::B => write!(f, "B"), + FrameType::Skip => write!(f, "skip"), FrameType::Other => write!(f, "x"), } }