add Arxel Tribe video support
[nihav.git] / nihav-registry / src / detect.rs
index 6f67fbd7253502f17f82a212d8bfce2a6eb531a0..bfe1d44a301656edf49b7d977996d581c2107517 100644 (file)
@@ -7,7 +7,7 @@
 //! # Examples
 //!
 //! ```no_run
-//! use nihav_core::detect::detect_format;
+//! use nihav_registry::detect::detect_format;
 //! use std::fs::File;
 //! use nihav_core::io::byteio::*;
 //!
@@ -118,29 +118,39 @@ impl Arg {
         }
     }
     fn eq(&self, src: &mut ByteReader) -> bool {
-        let val = self.read_val(src);
-        if val.is_none() { false }
-        else { val.unwrap() == self.val() }
+        if let Some(rval) = self.read_val(src) {
+            rval == self.val()
+        } else {
+            false
+        }
     }
     fn ge(&self, src: &mut ByteReader) -> bool {
-        let val = self.read_val(src);
-        if val.is_none() { false }
-        else { val.unwrap() >= self.val() }
+        if let Some(rval) = self.read_val(src) {
+            rval >= self.val()
+        } else {
+            false
+        }
     }
     fn gt(&self, src: &mut ByteReader) -> bool {
-        let val = self.read_val(src);
-        if val.is_none() { false }
-        else { val.unwrap() > self.val() }
+        if let Some(rval) = self.read_val(src) {
+            rval > self.val()
+        } else {
+            false
+        }
     }
     fn le(&self, src: &mut ByteReader) -> bool {
-        let val = self.read_val(src);
-        if val.is_none() { false }
-        else { val.unwrap() <= self.val() }
+        if let Some(rval) = self.read_val(src) {
+            rval <= self.val()
+        } else {
+            false
+        }
     }
     fn lt(&self, src: &mut ByteReader) -> bool {
-        let val = self.read_val(src);
-        if val.is_none() { false }
-        else { val.unwrap() < self.val() }
+        if let Some(rval) = self.read_val(src) {
+            rval < self.val()
+        } else {
+            false
+        }
     }
 }
 
@@ -159,7 +169,7 @@ enum CC<'a> {
 impl<'a> CC<'a> {
     fn eval(&self, src: &mut ByteReader) -> bool {
         match *self {
-            CC::Or (ref a, ref b) => { a.eval(src) || b.eval(src) },
+            CC::Or(a, b)         => { a.eval(src) || b.eval(src) },
             CC::Eq(ref arg)      => { arg.eq(src) },
             CC::In(ref a, ref b) => { a.ge(src) && b.le(src) },
             CC::Lt(ref arg)      => { arg.lt(src) },
@@ -220,11 +230,96 @@ const DETECTORS: &[DetectConditions] = &[
                                                                 &CC::Str(b"moov")),
                                                                 &CC::Str(b"ftyp")) }],
     },
+    DetectConditions {
+        demux_name: "yuv4mpeg",
+        extensions: ".y4m",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"YUV4MPEG2 ") }],
+    },
+    DetectConditions {
+        demux_name: "flv",
+        extensions: ".flv",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"FLV") },
+                      CheckItem{offs: 3, cond: &CC::Le(Arg::Byte(1)) }],
+    },
+    DetectConditions {
+        demux_name: "ivf",
+        extensions: ".ivf",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(&[0x50, 0xEF, 0x81, 0x19, 0xB3, 0xBD, 0xD0, 0x11, 0xA3, 0xE5, 0x00, 0xA0, 0xC9, 0x24, 0x44])},
+                      CheckItem{offs: 15, cond: &CC::Or(&CC::Eq(Arg::Byte(0x36)), &CC::Eq(Arg::Byte(0x37)))}],
+    },
+    DetectConditions {
+        demux_name: "dkivf",
+        extensions: ".ivf",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"DKIF\x00\x00")},
+                      CheckItem{offs: 6, cond: &CC::Ge(Arg::U16LE(32))}],
+    },
+    DetectConditions {
+        demux_name: "arxel-cnm",
+        extensions: ".cnm",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"CNM UNR\x00")}],
+    },
+    DetectConditions {
+        demux_name: "fcmp",
+        extensions: ".cmp",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"FCMP")}],
+    },
+    DetectConditions {
+        demux_name: "fst",
+        extensions: ".fst",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"2TSF")}],
+    },
     DetectConditions {
         demux_name: "gdv",
         extensions: ".gdv",
         conditions: &[CheckItem{offs: 0, cond: &CC::Eq(Arg::U32LE(0x29111994))}],
     },
+    DetectConditions {
+        demux_name: "fable-imax",
+        extensions: ".imx",
+        conditions: &[CheckItem{offs:  0, cond: &CC::Str(b"IMAX") },
+                      CheckItem{offs: 10, cond: &CC::Eq(Arg::U16LE(0x102)) }],
+    },
+    DetectConditions {
+        demux_name: "hl-fmv",
+        extensions: ".fmv",
+        conditions: &[CheckItem{offs:  0, cond: &CC::Str(b"FMV*") },
+                      CheckItem{offs:  4, cond: &CC::Eq(Arg::U32LE(0)) }],
+    },
+    DetectConditions {
+        demux_name: "legend-q",
+        extensions: ".q",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Eq(Arg::U16LE(0x6839))},
+                      CheckItem{offs: 2, cond: &CC::In(Arg::Byte(3), Arg::Byte(7))}],
+    },
+    DetectConditions {
+        demux_name: "siff",
+        extensions: ".vb,.vbc,.fcp,.son",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"SIFF")},
+                      CheckItem{offs: 4, cond: &CC::Or(
+                                    &CC::Or(
+                                        &CC::Str(b"VBV1VBHD"),
+                                        &CC::Str(b"SOUNSHDR")),
+                                    &CC::Str(b"FCPKFCHD"))}],
+    },
+    DetectConditions {
+        demux_name: "smush",
+        extensions: ".san",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"ANIM")},
+                      CheckItem{offs: 8, cond: &CC::Str(b"AHDR")}],
+    },
+    DetectConditions {
+        demux_name: "smush-mcmp",
+        extensions: ".imc",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"MCMP")},
+                      CheckItem{offs: 6, cond: &CC::Eq(Arg::Byte(0))},
+                      CheckItem{offs: 7, cond: &CC::Eq(Arg::Byte(0))}],
+    },
+    DetectConditions {
+        demux_name: "smush",
+        extensions: ".snm",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"SANM")},
+                      CheckItem{offs: 8, cond: &CC::Str(b"SHDR")}],
+    },
     DetectConditions {
         demux_name: "realaudio",
         extensions: ".ra,.ram",
@@ -254,6 +349,28 @@ const DETECTORS: &[DetectConditions] = &[
         extensions: ".smk",
         conditions: &[CheckItem{offs: 0, cond: &CC::Or(&CC::Str(b"SMK2"), &CC::Str(b"SMK4"))}],
     },
+    DetectConditions {
+        demux_name: "ape",
+        extensions: ".ape",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"MAC ") },
+                      CheckItem{offs: 4, cond: &CC::In(Arg::U16LE(3800), Arg::U16LE(3990))}],
+    },
+    DetectConditions {
+        demux_name: "flac",
+        extensions: ".flac",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"fLaC") }],
+    },
+    DetectConditions {
+        demux_name: "tta",
+        extensions: ".tta",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"TTA1") }],
+    },
+    DetectConditions {
+        demux_name: "wavpack",
+        extensions: ".wv",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"wvpk") },
+                      CheckItem{offs: 8, cond: &CC::In(Arg::U16LE(0x402), Arg::U16LE(0x410))}],
+    },
     DetectConditions {
         demux_name: "vivo",
         extensions: ".viv",
@@ -338,7 +455,7 @@ pub fn detect_format(name: &str, src: &mut ByteReader) -> Option<(&'static str,
 }
 
 /// Tries to detect container format for provided file name.
-pub fn detect_format_by_name(name: &str) -> Option<(&'static str)> {
+pub fn detect_format_by_name(name: &str) -> Option<&'static str> {
     if name.is_empty() {
         return None;
     }
@@ -357,7 +474,7 @@ pub fn detect_format_by_name(name: &str) -> Option<(&'static str)> {
 mod test {
     use super::*;
     use std::fs::File;
-    use crate::io::byteio::*;
+    use nihav_core::io::byteio::*;
 
     #[test]
     fn test_avi_detect() {