From: Kostya Shishkov Date: Thu, 11 Jun 2020 08:11:02 +0000 (+0200) Subject: add frame skip option for decoders X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=0975e7e77fc0b337dad578071a6deca6aa2b4697;p=nihav.git add frame skip option for decoders --- diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 43abbfd..c6ee95e 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -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 { + 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)] diff --git a/nihav-core/src/options.rs b/nihav-core/src/options.rs index 846a948..ea5b329 100644 --- a/nihav-core/src/options.rs +++ b/nihav-core/src/options.rs @@ -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 {