You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use crate::av::decoder::Decoder;
|
|
use crate::av::xcoder::XCoder;
|
|
use crate::av::{decoders_for_codec, FfmpegCodec};
|
|
use ffmpeg_sys_next::AVCodecID;
|
|
|
|
pub struct DecoderSelector {
|
|
decoders: Vec<FfmpegCodec>,
|
|
}
|
|
|
|
impl DecoderSelector {
|
|
pub fn for_codec_id(codec_id: AVCodecID) -> DecoderSelector {
|
|
DecoderSelector {
|
|
decoders: decoders_for_codec(codec_id),
|
|
}
|
|
}
|
|
|
|
pub fn select(
|
|
&self,
|
|
hwaccel: Option<bool>,
|
|
config_fn: impl Fn(&Decoder) -> Result<(), String>,
|
|
) -> Result<Decoder, String> {
|
|
for decoder in &self.decoders {
|
|
if !hwaccel.is_none() && hwaccel != Some(decoder.hwaccel) {
|
|
continue;
|
|
}
|
|
|
|
if let Some(Ok(decoder)) =
|
|
Decoder::from_name(&decoder.name).map(|d| -> Result<Decoder, String> {
|
|
config_fn(&d)?;
|
|
Ok(d)
|
|
})
|
|
{
|
|
return Ok(decoder);
|
|
}
|
|
}
|
|
|
|
Err("No working decoders found".to_string())
|
|
}
|
|
}
|