From a471c6afd97b2c17f63af555466cd918af69e4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 29 Nov 2026 06:42:14 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20cameras=20with=20a=20meta?= =?UTF-8?q?data=20node=20(e.g.=20Razer=20Kiyo=20X=20video2)=20resolved=20t?= =?UTF-8?q?o=20that=20node,=20so=20no=20modes=20and=20open=20failed;=20pic?= =?UTF-8?q?k=20the=20same-named=20node=20with=20VIDEO=5FCAPTURE.=20camera?= =?UTF-8?q?=20modes=20sorted=20and=20deduped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/share/camera.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/client/src/share/camera.rs b/crates/client/src/share/camera.rs index c627050..e570a07 100644 --- a/crates/client/src/share/camera.rs +++ b/crates/client/src/share/camera.rs @@ -142,7 +142,7 @@ fn index(device: Option<&str>) -> Option { nokhwa::query(nokhwa::utils::ApiBackend::Auto) .ok()? .into_iter() - .find(|info| info.human_name() == name) + .find(|info| info.human_name() == name && captures(info.index())) .map(|info| info.index().clone()) }) .unwrap_or(CameraIndex::Index(0)); @@ -211,6 +211,24 @@ fn format_count(index: &CameraIndex) -> u64 { count } +#[cfg(target_os = "linux")] +fn captures(index: &CameraIndex) -> bool { + index + .as_index() + .ok() + .and_then(|number| v4l::Device::new(number as usize).ok()) + .and_then(|device| device.query_caps().ok()) + .is_some_and(|caps| { + caps.capabilities + .contains(v4l::capability::Flags::VIDEO_CAPTURE) + }) +} + +#[cfg(not(target_os = "linux"))] +fn captures(_: &CameraIndex) -> bool { + true +} + #[cfg(not(target_os = "linux"))] fn format_count(_: &CameraIndex) -> u64 { 0 @@ -322,10 +340,13 @@ fn decodable(formats: Vec) -> Vec { } fn modes(formats: &[CameraFormat]) -> Vec { - formats + let mut modes: Vec = formats .iter() .map(|format| (format.height(), format.frame_rate())) - .collect() + .collect(); + modes.sort_unstable(); + modes.dedup(); + modes } fn size(formats: &[CameraFormat]) -> Option<(u32, u32)> {