pub const TEMPORAL_LAYERS: u8 = 3;
pub const AV1_TEMPORAL_LAYERS: u8 = 3;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct Av1Options {
pub screen_content: bool,
}
impl Av1Options {
#[must_use]
pub fn new(screen_content: bool) -> Self {
Self { screen_content }
}
}
pub fn vp9_threads() -> u32 {
std::thread::available_parallelism()
.map_or(1, |n| n.get().min(4))
.try_into()
.unwrap_or(1)
}
#[cfg_attr(
feature = "svt-av1",
doc = "opening an encoder; [`Av1Encoder::new`](crate::Av1Encoder::new) refuses such CPUs as a safety net."
)]
#[cfg_attr(
not(feature = "svt-av1"),
doc = "opening an encoder; `Av1Encoder::new` (feature `svt-av1`) refuses such CPUs as a safety net."
)]
pub fn av1_cpu_supported() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::arch::is_x86_feature_detected!("avx2")
}
#[cfg(not(target_arch = "x86_64"))]
{
true
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_plain_values_need_no_codec() {
assert_eq!(TEMPORAL_LAYERS, 3);
assert_eq!(AV1_TEMPORAL_LAYERS, 3);
assert_eq!(Av1Options::default(), Av1Options::new(false));
assert!(Av1Options::new(true).screen_content);
assert!((1..=4).contains(&vp9_threads()));
if cfg!(not(target_arch = "x86_64")) {
assert!(av1_cpu_supported());
}
}
}