]> git.nihav.org Git - nihav.git/blobdiff - src/codecs/mod.rs
preliminary work on Intel I.263
[nihav.git] / src / codecs / mod.rs
index 54dc0f2096ca7d25d571e61351ed2684b62299a3..ec67a4d7a9a38d78b3b2f91d8460528c4f161ee9 100644 (file)
@@ -8,6 +8,8 @@ use io::codebook::CodebookError;
 #[derive(Debug,Clone,Copy,PartialEq)]
 #[allow(dead_code)]
 pub enum DecoderError {
+    NoFrame,
+    TryAgain,
     InvalidData,
     ShortData,
     MissingReference,
@@ -15,7 +17,7 @@ pub enum DecoderError {
     Bug,
 }
 
-type DecoderResult<T> = Result<T, DecoderError>;
+pub type DecoderResult<T> = Result<T, DecoderError>;
 
 impl From<ByteIOError> for DecoderError {
     fn from(_: ByteIOError) -> Self { DecoderError::ShortData }
@@ -34,6 +36,15 @@ impl From<CodebookError> for DecoderError {
     fn from(_: CodebookError) -> Self { DecoderError::InvalidData }
 }
 
+macro_rules! validate {
+    ($a:expr) => { if !$a { return Err(DecoderError::InvalidData); } };
+}
+
+mod blockdsp;
+mod blockdec;
+mod h263code;
+mod h263data;
+
 #[allow(dead_code)]
 struct HAMShuffler {
     lastframe: Option<NAVideoBuffer<u8>>,
@@ -102,22 +113,27 @@ pub struct DecoderInfo {
     get_decoder: fn () -> Box<NADecoder>,
 }
 
-macro_rules! validate {
-    ($a:expr) => { if !$a { return Err(DecoderError::InvalidData); } };
-}
-
+#[cfg(feature="decoder_gdvvid")]
+mod gremlinvideo;
 #[cfg(feature="decoder_indeo2")]
 mod indeo2;
 #[cfg(feature="decoder_indeo3")]
 mod indeo3;
+
+mod intel263;
 #[cfg(feature="decoder_pcm")]
 mod pcm;
 
 const DECODERS: &[DecoderInfo] = &[
+#[cfg(feature="decoder_gdvvid")]
+    DecoderInfo { name: "gdv-video", get_decoder: gremlinvideo::get_decoder },
 #[cfg(feature="decoder_indeo2")]
     DecoderInfo { name: "indeo2", get_decoder: indeo2::get_decoder },
 #[cfg(feature="decoder_indeo3")]
     DecoderInfo { name: "indeo3", get_decoder: indeo3::get_decoder },
+
+    DecoderInfo { name: "intel263", get_decoder: intel263::get_decoder },
+
 #[cfg(feature="decoder_pcm")]
     DecoderInfo { name: "pcm", get_decoder: pcm::get_decoder },
 ];
@@ -137,8 +153,10 @@ use std::fs::{File, OpenOptions};
 use std::io::prelude::*;
 
 #[cfg(test)]
+#[allow(dead_code)]
 fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frmref: NAFrameRef) {
     let frm = frmref.borrow();
+    if let NABufferType::None = frm.get_buffer() { return; }
     let name = format!("assets/{}out{:02}_{:04}.pgm", pfx, strno, num);
     let mut ofile = File::create(name).unwrap();
     let buf = frm.get_buffer().get_vbuf().unwrap();
@@ -150,7 +168,7 @@ fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frmref: NAFrameRef) {
     let dta = buf.get_data();
     let ls = buf.get_stride(0);
     let mut idx = 0;
-    let mut idx2 = ls;
+    let mut idx2 = w;
     let mut pad: Vec<u8> = Vec::with_capacity((w - w2 * 2) / 2);
     pad.resize((w - w2 * 2) / 2, 0xFF);
     for _ in 0..h {
@@ -180,6 +198,36 @@ fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frmref: NAFrameRef) {
 }
 
 #[cfg(test)]
+#[allow(dead_code)]
+fn write_palppm(pfx: &str, strno: usize, num: u64, frmref: NAFrameRef) {
+    let frm = frmref.borrow();
+    let name = format!("assets/{}out{:02}_{:04}.ppm", pfx, strno, num);
+    let mut ofile = File::create(name).unwrap();
+    let buf = frm.get_buffer().get_vbuf().unwrap();
+    let (w, h) = buf.get_dimensions(0);
+    let paloff = buf.get_offset(1);
+    let hdr = format!("P6\n{} {}\n255\n", w, h);
+    ofile.write_all(hdr.as_bytes()).unwrap();
+    let dta = buf.get_data();
+    let ls = buf.get_stride(0);
+    let mut idx  = 0;
+    let mut line: Vec<u8> = Vec::with_capacity(w * 3);
+    line.resize(w * 3, 0);
+    for _ in 0..h {
+        let src = &dta[idx..(idx+w)];
+        for x in 0..w {
+            let pix = src[x] as usize;
+            line[x * 3 + 0] = dta[paloff + pix * 3 + 2];
+            line[x * 3 + 1] = dta[paloff + pix * 3 + 1];
+            line[x * 3 + 2] = dta[paloff + pix * 3 + 0];
+        }
+        ofile.write_all(line.as_slice()).unwrap();
+        idx  += ls;
+    }
+}
+
+#[cfg(test)]
+#[allow(dead_code)]
 fn write_sound(pfx: &str, strno: usize, frmref: NAFrameRef, first: bool) {
     let frm = frmref.borrow();
     let name = format!("assets/{}out{:02}.raw", pfx, strno);