use clap::{Parser, ValueEnum}; #[derive(Parser, Debug)] #[command(name = "vaapi_import_bench", about = "VAAPI DMA-BUF import benchmark")] pub(crate) struct BenchArgs { #[arg(short, long)] pub(crate) output: String, #[arg(long, default_value_t = 60)] pub(crate) frames: u32, #[arg(long, default_value_t = 2560)] pub(crate) enc_width: u32, #[arg(long, default_value_t = 1440)] pub(crate) enc_height: u32, #[arg(long, default_value = "/dev/dri/renderD128")] pub(crate) drm_device: String, #[arg(long, value_enum, default_value_t = PipelineMode::Both)] pub(crate) mode: PipelineMode, } #[derive(Copy, Clone, Debug, Eq, PartialEq, ValueEnum)] pub(crate) enum PipelineMode { Cpu, Gpu, Both, } #[derive(Default)] pub(crate) struct FrameStats { pub(crate) import_us: Vec, pub(crate) filter_us: Vec, pub(crate) transfer_us: Vec, pub(crate) scale_us: Vec, pub(crate) format_us: Vec, pub(crate) encode_us: Vec, pub(crate) total_us: Vec, pub(crate) import_failures: u32, pub(crate) frames_encoded: u32, pub(crate) elapsed_secs: f64, pub(crate) codec_name: String, pub(crate) output_path: String, } impl FrameStats { pub(crate) fn avg_ms(data: &[u64]) -> f64 { if data.is_empty() { return 0.0; } data.iter().sum::() as f64 / data.len() as f64 / 1000.0 } pub(crate) fn avg_total_ms(&self) -> f64 { Self::avg_ms(&self.total_us) } pub(crate) fn achieved_fps(&self) -> f64 { if self.frames_encoded > 0 && self.elapsed_secs > 0.0 { self.frames_encoded as f64 / self.elapsed_secs } else { 0.0 } } pub(crate) fn theoretical_fps(&self) -> f64 { let avg = self.avg_total_ms(); if avg > 0.0 { 1000.0 / avg } else { 0.0 } } }