mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-28 23:51:07 +03:00
fix: linux, nokhwa, camera index (#12045)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -49,7 +49,18 @@ impl Cameras {
|
||||
let Some(info) = cameras.first() else {
|
||||
bail!("No camera found")
|
||||
};
|
||||
let camera = Self::create_camera(&CameraIndex::Index(0))?;
|
||||
// Use index (0) camera as main camera, fallback to the first camera if index (0) is not available.
|
||||
// But maybe we also need to check index (1) or the lowest index camera.
|
||||
//
|
||||
// https://askubuntu.com/questions/234362/how-to-fix-this-problem-where-sometimes-dev-video0-becomes-automatically-dev
|
||||
// https://github.com/rustdesk/rustdesk/pull/12010#issue-3125329069
|
||||
let mut camera_index = info.index().clone();
|
||||
if !matches!(camera_index, CameraIndex::Index(0)) {
|
||||
if cameras.iter().any(|cam| matches!(cam.index(), CameraIndex::Index(0))) {
|
||||
camera_index = CameraIndex::Index(0);
|
||||
}
|
||||
}
|
||||
let camera = Self::create_camera(&camera_index)?;
|
||||
let resolution = camera.resolution();
|
||||
let (width, height) = (resolution.width() as i32, resolution.height() as i32);
|
||||
camera_displays.push(DisplayInfo {
|
||||
@@ -110,9 +121,14 @@ impl Cameras {
|
||||
}
|
||||
|
||||
fn create_camera(index: &CameraIndex) -> ResultType<Camera> {
|
||||
let format_type = if cfg!(target_os = "linux") {
|
||||
RequestedFormatType::None
|
||||
} else {
|
||||
RequestedFormatType::AbsoluteHighestResolution
|
||||
};
|
||||
let result = Camera::new(
|
||||
index.clone(),
|
||||
RequestedFormat::new::<RgbAFormat>(RequestedFormatType::None),
|
||||
RequestedFormat::new::<RgbAFormat>(format_type),
|
||||
);
|
||||
match result {
|
||||
Ok(camera) => Ok(camera),
|
||||
|
||||
Reference in New Issue
Block a user