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)]
TryAgain,
/// Invalid input data was provided.
InvalidData,
+ /// Checksum verification failed.
+ ChecksumError,
/// Provided input turned out to be incomplete.
ShortData,
/// Decoder could not decode provided frame because it references some missing previous frame.
}
/// Decoder trait.
-pub trait NADecoder {
+pub trait NADecoder: NAOptionHandler {
/// Initialises the decoder.
///
/// It takes [`NADecoderSupport`] allocated by the caller and `NACodecInfoRef` provided by demuxer.
/// 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<DecoderInfo>,
}
}
+/// 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)]
fn from(_: ByteIOError) -> Self { EncoderError::Bug }
}
+impl From<AllocatorError> 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.
/// while let Some(frame) = queue.get_frame() {
/// // convert to the format encoder expects if required
/// encoder.encode(frame)?;
-/// while let Some(enc_pkt) = encoder.get_packet()? {
+/// while let Ok(enc_pkt) = encoder.get_packet()? {
/// // send encoded packet to a muxer for example
/// }
/// }
/// 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<EncoderInfo>,