X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-core%2Fsrc%2Fcodecs%2Fmod.rs;h=58757efaf867ab449f7907e6cae51e343a6ace28;hp=5470325d08e72cf94ebf55c70e05e7a636230d2d;hb=78fb6560c73965d834b215fb0b49505ae5443288;hpb=0b257d9fde8ee0cc24e15a63544b100a0b6da52d diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 5470325..58757ef 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -3,6 +3,8 @@ pub use crate::frame::*; 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)] @@ -76,7 +78,7 @@ impl Default for NADecoderSupport { } /// Decoder trait. -pub trait NADecoder { +pub trait NADecoder: NAOptionHandler { /// Initialises the decoder. /// /// It takes [`NADecoderSupport`] allocated by the caller and `NACodecInfoRef` provided by demuxer. @@ -100,7 +102,7 @@ pub struct DecoderInfo { /// Structure for registering known decoders. /// -/// It is supposed to be filled using `register_all_codecs()` from some decoders crate and then it can be used to create decoders for the requested codecs. +/// It is supposed to be filled using `register_all_decoders()` from some decoders crate and then it can be used to create decoders for the requested codecs. #[derive(Default)] pub struct RegisteredDecoders { decs: Vec, @@ -130,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)] @@ -157,6 +199,10 @@ impl From for EncoderError { fn from(_: ByteIOError) -> Self { EncoderError::Bug } } +impl From for EncoderError { + fn from(_: AllocatorError) -> Self { EncoderError::AllocError } +} + /// Encoding parameter flag to force constant bitrate mode. pub const ENC_MODE_CBR: u64 = 1 << 0; /// Encoding parameter flag to force constant framerate mode. @@ -231,7 +277,7 @@ impl Default for EncodeParameters { /// [`negotiate_format`]: ./trait.NAEncoder.html#tymethod.negotiate_format /// [`encode`]: ./trait.NAEncoder.html#tymethod.encode /// [`get_packet`]: ./trait.NAEncoder.html#tymethod.get_packet -pub trait NAEncoder { +pub trait NAEncoder: NAOptionHandler { /// Tries to negotiate input format. /// /// This function takes input encoding parameters and returns adjusted encoding parameters if input ones make sense. @@ -273,7 +319,7 @@ pub struct EncoderInfo { /// Structure for registering known encoders. /// -/// It is supposed to be filled using `register_all_codecs()` from some encoders crate and then it can be used to create encoders for the requested codecs. +/// It is supposed to be filled using `register_all_decoders()` from some encoders crate and then it can be used to create encoders for the requested codecs. #[derive(Default)] pub struct RegisteredEncoders { encs: Vec,