X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=253842aff677dfcb2010627d72df1acc6e114318;hb=009a04a99f0f0c8a2084f7ea8168a07c660b760e;hp=9756dfbaded9a3f3402cd3b029f46af926d11600;hpb=4e8b4f31bc2ef2b22b4c725aa07dfc776664a97b;p=nihav.git diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 9756dfb..253842a 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -177,6 +177,7 @@ impl NAAudioBuffer { pub enum NABufferType { Video (NAVideoBuffer), Video16 (NAVideoBuffer), + Video32 (NAVideoBuffer), VideoPacked(NAVideoBuffer), AudioU8 (NAAudioBuffer), AudioI16 (NAAudioBuffer), @@ -192,6 +193,7 @@ impl NABufferType { match *self { NABufferType::Video(ref vb) => vb.get_offset(idx), NABufferType::Video16(ref vb) => vb.get_offset(idx), + NABufferType::Video32(ref vb) => vb.get_offset(idx), NABufferType::VideoPacked(ref vb) => vb.get_offset(idx), NABufferType::AudioU8(ref ab) => ab.get_offset(idx), NABufferType::AudioI16(ref ab) => ab.get_offset(idx), @@ -200,39 +202,54 @@ impl NABufferType { _ => 0, } } - pub fn get_vbuf(&mut self) -> Option> { + pub fn get_video_info(&self) -> Option { + match *self { + NABufferType::Video(ref vb) => Some(vb.get_info()), + NABufferType::Video16(ref vb) => Some(vb.get_info()), + NABufferType::Video32(ref vb) => Some(vb.get_info()), + NABufferType::VideoPacked(ref vb) => Some(vb.get_info()), + _ => None, + } + } + 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(&mut self) -> Option> { + pub fn get_vbuf16(&self) -> Option> { match *self { NABufferType::Video16(ref vb) => Some(vb.clone()), _ => None, } } - pub fn get_abuf_u8(&mut self) -> Option> { + pub fn get_vbuf32(&self) -> Option> { + match *self { + NABufferType::Video32(ref vb) => Some(vb.clone()), + _ => None, + } + } + pub fn get_abuf_u8(&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> { + pub fn get_abuf_i16(&self) -> Option> { match *self { NABufferType::AudioI16(ref ab) => Some(ab.clone()), _ => None, } } - pub fn get_abuf_i32(&mut self) -> Option> { + pub fn get_abuf_i32(&self) -> Option> { match *self { NABufferType::AudioI32(ref ab) => Some(ab.clone()), _ => None, } } - pub fn get_abuf_f32(&mut self) -> Option> { + pub fn get_abuf_f32(&self) -> Option> { match *self { NABufferType::AudioF32(ref ab) => Some(ab.clone()), _ => None, @@ -261,16 +278,22 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result false, + _ => true, + }; //todo semi-packed like NV12 if fmt.is_paletted() { @@ -313,13 +336,18 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; Ok(NABufferType::Video(buf)) - } else { + } else if max_depth <= 16 { 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, strides: strides }; Ok(NABufferType::Video16(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, strides: strides }; + Ok(NABufferType::Video32(buf)) } - } else { + } else if all_bytealigned || unfit_elem_size { let elem_sz = fmt.get_elem_size(); let line_sz = width.checked_mul(elem_sz as usize); if line_sz == None { return Err(AllocatorError::TooLargeDimensions); } @@ -331,6 +359,28 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; Ok(NABufferType::VideoPacked(buf)) + } else { + let elem_sz = fmt.get_elem_size(); + let new_sz = width.checked_mul(height); + if new_sz == None { return Err(AllocatorError::TooLargeDimensions); } + new_size = new_sz.unwrap(); + match elem_sz { + 2 => { + let mut data: Vec = Vec::with_capacity(new_size); + data.resize(new_size, 0); + strides.push(width); + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; + Ok(NABufferType::Video16(buf)) + }, + 4 => { + let mut data: Vec = Vec::with_capacity(new_size); + data.resize(new_size, 0); + strides.push(width); + let buf: NAVideoBuffer = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides }; + Ok(NABufferType::Video32(buf)) + }, + _ => unreachable!(), + } } } @@ -430,6 +480,10 @@ impl NACodecInfo { } } +impl Default for NACodecInfo { + fn default() -> Self { DUMMY_CODEC_INFO } +} + impl fmt::Display for NACodecInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let edata = match self.extradata.clone() {