]> git.nihav.org Git - nihav.git/blobdiff - nihav-core/src/register.rs
core: document register module
[nihav.git] / nihav-core / src / register.rs
index d9321530663910f8ac3e83b477f54b563f48d1f5..c54ce584d7b63367b55f1db235d57a30bc81db69 100644 (file)
@@ -1,12 +1,21 @@
+//! Global registry of codec information.
+//!
+//! This module contains codec information from technical level that allows user to retrieve information about codec type and features without creating and invoking a decoder for such codec.
 use std::fmt;
 
+/// Codec types.
 #[derive(Debug,Clone,Copy,PartialEq)]
 #[allow(dead_code)]
 pub enum CodecType {
+    /// Video codec.
     Video,
+    /// Audio codec.
     Audio,
+    /// Subtitle codec.
     Subtitles,
+    /// Some special codec (e.g. some event stream or separate timecodes stream).
     Data,
+    /// Dummy codec.
     None,
 }
 
@@ -22,34 +31,51 @@ impl fmt::Display for CodecType {
     }
 }
 
-const CODEC_CAP_INTRAONLY:u32   = 0x000001;
-const CODEC_CAP_LOSSLESS:u32    = 0x000002;
-const CODEC_CAP_REORDER:u32     = 0x000004;
-const CODEC_CAP_HYBRID:u32      = 0x000008;
-const CODEC_CAP_SCALABLE:u32    = 0x000010;
+const CODEC_CAP_INTRAONLY:u32   = 0x0001;
+const CODEC_CAP_LOSSLESS:u32    = 0x0002;
+const CODEC_CAP_REORDER:u32     = 0x0004;
+const CODEC_CAP_HYBRID:u32      = 0x0008;
+const CODEC_CAP_SCALABLE:u32    = 0x0010;
 
+/// Codec description structure.
 #[derive(Clone)]
 pub struct CodecDescription {
+    /// Short codec name.
+    ///
+    /// Short codec name is used inside NihAV as the unique identifier.
     pub name:  &'static str,
+    /// Full codec name.
     pub fname: &'static str,
+    /// Codec type.
     pub ctype: CodecType,
+    /// Codec capabilities.
     pub caps:  u32,
 }
 
 impl CodecDescription {
+    /// Returns short codec name.
     pub fn get_name(&self) -> &'static str { self.name }
+    /// Returns full codec name.
     pub fn get_full_name(&self) -> &'static str { self.fname }
+    /// Returns codec type.
     pub fn get_codec_type(&self) -> CodecType { self.ctype }
+    /// Reports whether the codec has only intra frames or not.
     pub fn is_intraonly(&self) -> bool { (self.caps & CODEC_CAP_INTRAONLY) != 0 }
+    /// Reports whether the codec is lossless.
     pub fn is_lossless(&self)  -> bool { (self.caps & CODEC_CAP_LOSSLESS)  != 0 }
+    /// Reports whether the codec requires frame reordering.
     pub fn has_reorder(&self)  -> bool { (self.caps & CODEC_CAP_REORDER)   != 0 }
+    /// Reports whether the codec can be either lossless or lossy.
     pub fn is_hybrid(&self)    -> bool { (self.caps & CODEC_CAP_HYBRID)    != 0 }
+    /// Reports whether codec supports scalability.
+    ///
+    /// Scalability means that codec can be decoded in reduced resolution by design.
     pub fn is_scalable(&self)  -> bool { (self.caps & CODEC_CAP_SCALABLE)  != 0 }
 }
 
 impl fmt::Display for CodecDescription {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let mut out = format!("{}", self.fname);
+        let mut out = self.fname.to_string();
         if self.caps != 0 {
             let mut capfmt = "".to_string();
             if (self.caps & CODEC_CAP_INTRAONLY) != 0 {
@@ -108,6 +134,7 @@ macro_rules! desc {
     });
 }
 
+/// Returns codec description for the provided codec short name if it is found.
 pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> {
     for reg in CODEC_REGISTER {
         if reg.name == name {
@@ -118,6 +145,8 @@ pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> {
 }
 
 static CODEC_REGISTER: &'static [CodecDescription] = &[
+    desc!(audio-ll; "pcm", "PCM"),
+
     desc!(video-im; "indeo1", "Intel Raw IF09"),
     desc!(video-im; "indeo2", "Intel Indeo 2"),
     desc!(video;    "indeo3", "Intel Indeo 3"),
@@ -142,6 +171,42 @@ static CODEC_REGISTER: &'static [CodecDescription] = &[
     desc!(audio;    "ac3",        "ETSI TS 102 366"),
     desc!(audio;    "atrac3",     "Sony Atrac3"),
     desc!(audio;    "sipro",      "Sipro Labs ADPCM"),
+
+    desc!(video;    "truemotion1",   "TrueMotion 1"),
+    desc!(video-im; "truemotionrt",  "TrueMotion RT"),
+    desc!(video;    "truemotion2",   "TrueMotion 2"),
+    desc!(video;    "truemotion2x",  "TrueMotion 2X"),
+    desc!(video;    "vp3",           "VP3"),
+    desc!(video;    "vp4",           "VP4"),
+    desc!(video;    "vp5",           "VP5"),
+    desc!(video;    "vp6",           "VP6"),
+    desc!(video;    "vp6a",          "VP6"),
+    desc!(video;    "vp7",           "VP7"),
+    desc!(video;    "vp8",           "VP8"),
+    desc!(video;    "vp9",           "VP9"),
+    desc!(audio;    "adpcm-dk3",     "Duck DK3 ADPCM"),
+    desc!(audio;    "adpcm-dk4",     "Duck DK4 ADPCM"),
+    desc!(audio;    "on2avc-500",    "On2 AVC"),
+    desc!(audio;    "on2avc-501",    "On2 AVC"),
+
+    desc!(video;    "gdv-video",     "Gremlin Digital Video - video"),
+    desc!(audio;    "gdv-audio",     "Gremlin Digital Video - audio"),
+    desc!(video;    "bmv-video",     "BMV video"),
+    desc!(audio;    "bmv-audio",     "BMV audio"),
+    desc!(video;    "bmv3-video",    "DW Noir BMV video"),
+    desc!(audio;    "bmv3-audio",    "DW Noir BMV audio"),
+    desc!(video;    "midivid",       "MidiVid"),
+    desc!(video;    "midivid3",      "MidiVid 3"),
+    desc!(video-ll; "midivid-ll",    "MidiVid Lossless"),
+    desc!(video;    "vmd-video",     "VMD video"),
+    desc!(audio;    "vmd-audio",     "VMD audio"),
+
+    desc!(video;    "smacker-video", "Smacker video"),
+    desc!(audio;    "smacker-audio", "Smacker audio"),
+    desc!(video;    "bink-video",    "Bink video"),
+    desc!(video;    "bink2-video",   "Bink2 video"),
+    desc!(audio;    "bink-audio-dct",   "Bink audio (DCT)"),
+    desc!(audio;    "bink-audio-rdft",  "Bink audio (RDFT)"),
 ];
 
 static AVI_VIDEO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
@@ -155,41 +220,50 @@ static AVI_VIDEO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
 
     (b"UCOD", "clearvideo"),
 
+    (b"MVDV", "midivid"),
+    (b"MV30", "midivid3"),
+    (b"MVLZ", "midivid-ll"),
+
     (b"DUCK", "truemotion1"),
     (b"TR20", "truemotionrt"),
     (b"TM20", "truemotion2"),
     (b"TM2A", "truemotion2x"),
     (b"TM2X", "truemotion2x"),
-    (b"VP30", "truemotion3"),
-    (b"VP31", "truemotion3"),
-    (b"VP40", "truemotion4"),
-    (b"VP50", "truemotion5"),
-    (b"VP60", "truemotion6"),
-    (b"VP61", "truemotion6"),
-    (b"VP62", "truemotion6"),
-    (b"VP70", "truemotion7"),
+    (b"VP30", "vp3"),
+    (b"VP31", "vp3"),
+    (b"VP40", "vp4"),
+    (b"VP50", "vp5"),
+    (b"VP60", "vp6"),
+    (b"VP61", "vp6"),
+    (b"VP62", "vp6"),
+    (b"VP6A", "vp6a"),
+    (b"VP70", "vp7"),
 ];
 
 static WAV_CODEC_REGISTER: &'static [(u16, &str)] = &[
     (0x0000, "pcm"),
     (0x0001, "pcm"),
     (0x0003, "pcm"),
+    (0x0061, "adpcm-dk4"),
+    (0x0062, "adpcm-dk3"),
     (0x0401, "imc"),
     (0x0402, "iac"),
+    (0x0500, "on2avc-500"),
+    (0x0501, "on2avc-501"),
 ];
 
+/// Returns video codec short name for provided FOURCC (used in AVI format).
 pub fn find_codec_from_avi_fourcc(fcc: &[u8;4]) -> Option<&'static str> {
-    for i in 0..AVI_VIDEO_CODEC_REGISTER.len() {
-        let (fourcc, name) = AVI_VIDEO_CODEC_REGISTER[i];
-        if fourcc == fcc { return Some(name); }
+    for (fourcc, name) in AVI_VIDEO_CODEC_REGISTER.iter() {
+        if *fourcc == fcc { return Some(name); }
     }
     None
 }
 
+/// Returns known audio codec short name for provided TWOCC (used in WAV and AVI format).
 pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> {
-    for i in 0..WAV_CODEC_REGISTER.len() {
-        let (twocc, name) = WAV_CODEC_REGISTER[i];
-        if twocc == tcc { return Some(name); }
+    for (twocc, name) in WAV_CODEC_REGISTER.iter() {
+        if *twocc == tcc { return Some(name); }
     }
     None
 }