diff --git a/crates/client/src/share/capture.rs b/crates/client/src/share/capture.rs index 67c2144..4e2f60d 100644 --- a/crates/client/src/share/capture.rs +++ b/crates/client/src/share/capture.rs @@ -190,10 +190,13 @@ fn text(error: impl std::fmt::Display) -> String { error.to_string() } +type Applied = (bool, u64, u32, u32, u32); + struct State { format: VideoInfoRaw, size: (u32, u32), modifiers: Vec, + applied: Option, stop: Arc, started: Instant, negotiated: SyncSender, @@ -237,6 +240,7 @@ fn run( format: VideoInfoRaw::new(), size: (0, 0), modifiers: modifiers.clone(), + applied: None, stop: stop.clone(), started: Instant::now(), negotiated, @@ -446,14 +450,26 @@ fn on_param(stream: &pw::stream::Stream, state: &mut State, id: u32, param: Opti return; } let gpu = offered.is_some(); - tracing::info!(gpu, modifier = state.format.modifier(), format = ?state.format.format(), "share capture format"); + let size = state.format.size(); + let modifier = if gpu { state.format.modifier() } else { 0 }; + let applied = ( + gpu, + modifier, + state.format.format().as_raw(), + size.width, + size.height, + ); + if state.applied == Some(applied) { + return; + } + state.applied = Some(applied); + tracing::info!(gpu, modifier, format = ?state.format.format(), "share capture format"); if let Some(buffers) = buffers_values(gpu) && let Some(buffers) = Pod::from_bytes(&buffers) { let _ = stream.update_params(&mut [buffers]); } - let size = state.format.size(); let fps = state.format.max_framerate(); let refresh = fps .num diff --git a/crates/client/src/share/encode.rs b/crates/client/src/share/encode.rs index 71f3923..3675e12 100644 --- a/crates/client/src/share/encode.rs +++ b/crates/client/src/share/encode.rs @@ -23,12 +23,13 @@ pub struct Capabilities { struct Probe { capabilities: Capabilities, hardware: Vec, + vulkan: Vec, } fn probe() -> &'static Probe { static PROBE: OnceLock = OnceLock::new(); PROBE.get_or_init(|| { - let hardware = hardware::probe(); + let (hardware, vulkan) = hardware::probe(); let codecs: Vec = hardware.iter().map(|(codec, _)| *codec).collect(); let max_height = hardware .iter() @@ -46,6 +47,7 @@ fn probe() -> &'static Probe { max_height, }, hardware: codecs, + vulkan, } }) } @@ -300,8 +302,9 @@ mod hardware { } } - pub fn probe() -> Vec<(Codec, u32)> { + pub fn probe() -> (Vec<(Codec, u32)>, Vec) { let mut found: Vec<(Codec, u32)> = Vec::new(); + let mut vulkan = Vec::new(); for capability in ec_hw::capabilities() { if capability.direction != ec_hw::Direction::Encode { continue; @@ -309,32 +312,19 @@ mod hardware { let Some(codec) = codec(capability.codec) else { continue; }; + if capability.backend == ec_hw::Backend::Vk && !vulkan.contains(&codec) { + vulkan.push(codec); + } match found.iter_mut().find(|(known, _)| *known == codec) { Some((_, height)) => *height = (*height).max(capability.max_height), None => found.push((codec, capability.max_height)), } } - found - } - - fn vulkan_encodes(wanted: Codec) -> bool { - static VULKAN: std::sync::OnceLock> = std::sync::OnceLock::new(); - VULKAN - .get_or_init(|| { - ec_hw::capabilities() - .into_iter() - .filter(|capability| { - capability.direction == ec_hw::Direction::Encode - && capability.backend == ec_hw::Backend::Vk - }) - .filter_map(|capability| codec(capability.codec)) - .collect() - }) - .contains(&wanted) + (found, vulkan) } fn open_vulkan(config: ec_hw::EncoderConfig, wanted: Codec) -> Option { - if !vulkan_encodes(wanted) { + if !super::probe().vulkan.contains(&wanted) { return None; } for attempt in 1..=VULKAN_ATTEMPTS {