aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2020-06-11 10:11:02 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2020-06-11 10:11:02 +0200
commit0975e7e77fc0b337dad578071a6deca6aa2b4697 (patch)
treec18201d62006864ec97cd6ac28638c3cd0fdd44e
parent423005dc1d521e9089c9ddcf020979b825e30443 (diff)
downloadnihav-0975e7e77fc0b337dad578071a6deca6aa2b4697.tar.gz
add frame skip option for decoders
-rw-r--r--nihav-core/src/codecs/mod.rs41
-rw-r--r--nihav-core/src/options.rs11
2 files changed, 52 insertions, 0 deletions
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<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)]
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 {