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)> {