add frame skip option for decoders
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 11 Jun 2020 08:11:02 +0000 (10:11 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 11 Jun 2020 08:11:02 +0000 (10:11 +0200)
nihav-core/src/codecs/mod.rs
nihav-core/src/options.rs

index 43abbfd12ebd92209d7553ed9e327f678f9935ae..c6ee95ec71a844043d449af5b3e6ade48e7dc5ba 100644 (file)
@@ -4,6 +4,7 @@ use crate::io::byteio::ByteIOError;
 use crate::io::bitreader::BitReaderError;
 use crate::io::codebook::CodebookError;
 pub use crate::options::*;
+pub use std::str::FromStr;
 
 /// A list specifying general decoding errors.
 #[derive(Debug,Clone,Copy,PartialEq)]
@@ -131,6 +132,46 @@ impl RegisteredDecoders {
     }
 }
 
+/// Frame skipping mode for decoders.
+#[derive(Clone,Copy,PartialEq,Debug)]
+pub enum FrameSkipMode {
+    /// Decode all frames.
+    None,
+    /// Decode all key frames.
+    KeyframesOnly,
+    /// Decode only intra frames.
+    IntraOnly,
+}
+
+impl Default for FrameSkipMode {
+    fn default() -> Self {
+        FrameSkipMode::None
+    }
+}
+
+impl FromStr for FrameSkipMode {
+    type Err = DecoderError;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        match s {
+            FRAME_SKIP_OPTION_VAL_NONE      => Ok(FrameSkipMode::None),
+            FRAME_SKIP_OPTION_VAL_KEYFRAME  => Ok(FrameSkipMode::KeyframesOnly),
+            FRAME_SKIP_OPTION_VAL_INTRA     => Ok(FrameSkipMode::IntraOnly),
+            _ => Err(DecoderError::InvalidData),
+        }
+    }
+}
+
+impl ToString for FrameSkipMode {
+    fn to_string(&self) -> String {
+        match *self {
+            FrameSkipMode::None             => FRAME_SKIP_OPTION_VAL_NONE.to_string(),
+            FrameSkipMode::KeyframesOnly    => FRAME_SKIP_OPTION_VAL_KEYFRAME.to_string(),
+            FrameSkipMode::IntraOnly        => FRAME_SKIP_OPTION_VAL_INTRA.to_string(),
+        }
+    }
+}
+
 /// A list specifying general encoding errors.
 #[derive(Debug,Clone,Copy,PartialEq)]
 #[allow(dead_code)]
index 846a948701f2a1d044541ed84a1713c14b900fc6..ea5b32933ad790b5e00e5d51797e20c1b4c0132a 100644 (file)
@@ -13,6 +13,17 @@ pub const KEYFRAME_OPTION: &'static str = "key_int";
 /// Common description for keyframe interval option.
 pub const KEYFRAME_OPTION_DESC: &'static str = "Keyframe interval (0 - automatic)";
 
+/// Common name for frame skipping mode.
+pub const FRAME_SKIP_OPTION: &'static str = "frame_skip";
+/// Common description for frame skipping mode.
+pub const FRAME_SKIP_OPTION_DESC: &'static str = "Frame skipping mode";
+/// Frame skipping option value for no skipped frames.
+pub const FRAME_SKIP_OPTION_VAL_NONE: &'static str = "none";
+/// Frame skipping option value for decoding only keyframes.
+pub const FRAME_SKIP_OPTION_VAL_KEYFRAME: &'static str = "keyframes";
+/// Frame skipping option value for decoding only intra frames.
+pub const FRAME_SKIP_OPTION_VAL_INTRA: &'static str = "intra";
+
 /// A list specifying option parsing and validating errors.
 #[derive(Clone,Copy,Debug,PartialEq)]
 pub enum OptionError {