#![forbid(unsafe_code)]
use crate::video::{VideoEncoderConfig, VideoInputPreference};
use mediaway_common::{CodecKind, GpuDeviceHandle, PixelFormat, Rational};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum EncodePathClass {
ZeroCopy,
GpuCopy,
CpuUpload,
Readback,
Software,
}
impl EncodePathClass {
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::ZeroCopy => "zc",
Self::GpuCopy => "copy",
Self::CpuUpload => "upload",
Self::Readback => "readback",
Self::Software => "sw",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Backend {
Os,
Nvenc,
QuickSync,
Amf,
Software,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum BackendSelection {
#[default]
Auto,
AutoHardwareOnly,
Explicit(Backend),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AutoVideoEncodeConfig {
pub codec: CodecKind,
pub width: u32,
pub height: u32,
pub time_base: Rational,
pub bitrate_bps: u32,
pub pixel_format: PixelFormat,
pub max_path_class: EncodePathClass,
pub gpu_device: Option<GpuDeviceHandle>,
pub backend: BackendSelection,
}
impl AutoVideoEncodeConfig {
#[must_use]
pub const fn new(codec: CodecKind, width: u32, height: u32, time_base: Rational) -> Self {
Self {
codec,
width,
height,
time_base,
bitrate_bps: 0,
pixel_format: PixelFormat::Nv12,
max_path_class: EncodePathClass::CpuUpload,
gpu_device: None,
backend: BackendSelection::Auto,
}
}
#[must_use]
pub const fn to_low_level(
&self,
input: VideoInputPreference,
gpu_device: Option<GpuDeviceHandle>,
) -> VideoEncoderConfig {
VideoEncoderConfig {
codec: self.codec,
width: self.width,
height: self.height,
time_base: self.time_base,
bitrate_bps: self.bitrate_bps,
pixel_format: self.pixel_format,
input,
gpu_device,
}
}
}
#[cfg(test)]
#[cfg(feature = "video")]
#[path = "auto_tests.rs"]
mod tests;