Cameras with a metadata node (e.g. Razer Kiyo X video2) resolved to that node, so no modes and open failed
Browse files at this commita471c6afd97b2c17f63af555466cd918af69e4cfParent: dabd731- fix
- cameras with a metadata node (e.g. Razer Kiyo X video2) resolved to that node, so no modes and open failed
- pick the same-named node with VIDEO_CAPTURE. camera modes sorted and deduped
1 changed file +24 -3
crates/client/src/share/camera.rsmodified+24 -3
| @@ -142,7 +142,7 @@ fn index(device: Option<&str>) -> Option<CameraIndex> { | |||
| 142 | nokhwa::query(nokhwa::utils::ApiBackend::Auto) | 142 | nokhwa::query(nokhwa::utils::ApiBackend::Auto) |
| 143 | .ok()? | 143 | .ok()? |
| 144 | .into_iter() | 144 | .into_iter() |
| 145 | - .find(|info| info.human_name() == name) | 145 | + .find(|info| info.human_name() == name && captures(info.index())) |
| 146 | .map(|info| info.index().clone()) | 146 | .map(|info| info.index().clone()) |
| 147 | }) | 147 | }) |
| 148 | .unwrap_or(CameraIndex::Index(0)); | 148 | .unwrap_or(CameraIndex::Index(0)); |
| @@ -211,6 +211,24 @@ fn format_count(index: &CameraIndex) -> u64 { | |||
| 211 | count | 211 | count |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | +#[cfg(target_os = "linux")] | ||
| 215 | +fn captures(index: &CameraIndex) -> bool { | ||
| 216 | + index | ||
| 217 | + .as_index() | ||
| 218 | + .ok() | ||
| 219 | + .and_then(|number| v4l::Device::new(number as usize).ok()) | ||
| 220 | + .and_then(|device| device.query_caps().ok()) | ||
| 221 | + .is_some_and(|caps| { | ||
| 222 | + caps.capabilities | ||
| 223 | + .contains(v4l::capability::Flags::VIDEO_CAPTURE) | ||
| 224 | + }) | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +#[cfg(not(target_os = "linux"))] | ||
| 228 | +fn captures(_: &CameraIndex) -> bool { | ||
| 229 | + true | ||
| 230 | +} | ||
| 231 | + | ||
| 214 | #[cfg(not(target_os = "linux"))] | 232 | #[cfg(not(target_os = "linux"))] |
| 215 | fn format_count(_: &CameraIndex) -> u64 { | 233 | fn format_count(_: &CameraIndex) -> u64 { |
| 216 | 0 | 234 | 0 |
| @@ -322,10 +340,13 @@ fn decodable(formats: Vec<CameraFormat>) -> Vec<CameraFormat> { | |||
| 322 | } | 340 | } |
| 323 | 341 | ||
| 324 | fn modes(formats: &[CameraFormat]) -> Vec<Mode> { | 342 | fn modes(formats: &[CameraFormat]) -> Vec<Mode> { |
| 325 | - formats | 343 | + let mut modes: Vec<Mode> = formats |
| 326 | .iter() | 344 | .iter() |
| 327 | .map(|format| (format.height(), format.frame_rate())) | 345 | .map(|format| (format.height(), format.frame_rate())) |
| 328 | - .collect() | 346 | + .collect(); |
| 347 | + modes.sort_unstable(); | ||
| 348 | + modes.dedup(); | ||
| 349 | + modes | ||
| 329 | } | 350 | } |
| 330 | 351 | ||
| 331 | fn size(formats: &[CameraFormat]) -> Option<(u32, u32)> { | 352 | fn size(formats: &[CameraFormat]) -> Option<(u32, u32)> { |