]> git.nihav.org Git - nihav.git/blobdiff - src/frame.rs
add skip frames and paletted alloc
[nihav.git] / src / frame.rs
index 19c1733c9c716b7101f199d9301e62931f68c5e5..02bdf3348d84cd09a3e212e9844dd1d23bf4cc09 100644 (file)
@@ -88,8 +88,6 @@ impl fmt::Display for NACodecTypeInfo {
     }
 }
 
-pub type BufferRef = Rc<RefCell<Vec<u8>>>;
-
 pub type NABufferRefT<T> = Rc<RefCell<Vec<T>>>;
 
 #[derive(Clone)]
@@ -149,6 +147,12 @@ impl<T: Clone> NAAudioBuffer<T> {
     }
 }
 
+impl NAAudioBuffer<u8> {
+    pub fn new_from_buf(info: NAAudioInfo, data: NABufferRefT<u8>, chmap: NAChannelMap) -> Self {
+        NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new() }
+    }
+}
+
 #[derive(Clone)]
 pub enum NABufferType {
     Video      (NAVideoBuffer<u8>),
@@ -156,6 +160,7 @@ pub enum NABufferType {
     VideoPacked(NAVideoBuffer<u8>),
     AudioU8    (NAAudioBuffer<u8>),
     AudioI16   (NAAudioBuffer<i16>),
+    AudioI32   (NAAudioBuffer<i32>),
     AudioF32   (NAAudioBuffer<f32>),
     AudioPacked(NAAudioBuffer<u8>),
     Data       (NABufferRefT<u8>),
@@ -178,6 +183,38 @@ impl NABufferType {
     pub fn get_vbuf(&mut self) -> Option<NAVideoBuffer<u8>> {
         match *self {
             NABufferType::Video(ref vb)       => Some(vb.clone()),
+            NABufferType::VideoPacked(ref vb) => Some(vb.clone()),
+            _ => None,
+        }
+    }
+    pub fn get_vbuf16(&mut self) -> Option<NAVideoBuffer<u16>> {
+        match *self {
+            NABufferType::Video16(ref vb)     => Some(vb.clone()),
+            _ => None,
+        }
+    }
+    pub fn get_abuf_u8(&mut self) -> Option<NAAudioBuffer<u8>> {
+        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<NAAudioBuffer<i16>> {
+        match *self {
+            NABufferType::AudioI16(ref ab) => Some(ab.clone()),
+            _ => None,
+        }
+    }
+    pub fn get_abuf_i32(&mut self) -> Option<NAAudioBuffer<i32>> {
+        match *self {
+            NABufferType::AudioI32(ref ab) => Some(ab.clone()),
+            _ => None,
+        }
+    }
+    pub fn get_abuf_f32(&mut self) -> Option<NAAudioBuffer<f32>> {
+        match *self {
+            NABufferType::AudioF32(ref ab) => Some(ab.clone()),
             _ => None,
         }
     }
@@ -213,7 +250,20 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result<NABufferType,
     }
 
 //todo semi-packed like NV12
-    if !all_packed {
+    if fmt.is_paletted() {
+//todo various-sized palettes?
+        let pic_sz = width.checked_mul(height);
+        if pic_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+        let pal_size = 256 * (fmt.get_elem_size() as usize);
+        let new_size = pic_sz.unwrap().checked_add(pal_size);
+        if new_size == None { return Err(AllocatorError::TooLargeDimensions); }
+        offs.push(0);
+        offs.push(width * height);
+        let mut data: Vec<u8> = Vec::with_capacity(new_size.unwrap());
+        data.resize(new_size.unwrap(), 0);
+        let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs };
+        Ok(NABufferType::Video(buf))
+    } else if !all_packed {
         for i in 0..fmt.get_num_comp() {
             let chr = fmt.get_chromaton(i).unwrap();
             if !vinfo.is_flipped() {
@@ -375,6 +425,7 @@ pub enum FrameType {
     I,
     P,
     B,
+    Skip,
     Other,
 }
 
@@ -384,6 +435,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"),
         }
     }