mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-20 14:53:17 +03:00
fix: linux, nokhwa, camera index (#12045)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -4326,7 +4326,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nokhwa"
|
name = "nokhwa"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#744dea9d277dfb18954cef389973c622dd15a85e"
|
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#f32e7d68be61db9b1e99016b24edb14543d0383b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flume",
|
"flume",
|
||||||
"image 0.25.1",
|
"image 0.25.1",
|
||||||
@@ -4341,7 +4341,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nokhwa-bindings-linux"
|
name = "nokhwa-bindings-linux"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#744dea9d277dfb18954cef389973c622dd15a85e"
|
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#f32e7d68be61db9b1e99016b24edb14543d0383b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nokhwa-core",
|
"nokhwa-core",
|
||||||
"v4l",
|
"v4l",
|
||||||
@@ -4350,7 +4350,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nokhwa-bindings-macos"
|
name = "nokhwa-bindings-macos"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#744dea9d277dfb18954cef389973c622dd15a85e"
|
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#f32e7d68be61db9b1e99016b24edb14543d0383b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block",
|
"block",
|
||||||
"cocoa-foundation",
|
"cocoa-foundation",
|
||||||
@@ -4366,7 +4366,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nokhwa-bindings-windows"
|
name = "nokhwa-bindings-windows"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#744dea9d277dfb18954cef389973c622dd15a85e"
|
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#f32e7d68be61db9b1e99016b24edb14543d0383b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dlopen",
|
"dlopen",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -4378,7 +4378,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nokhwa-core"
|
name = "nokhwa-core"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#744dea9d277dfb18954cef389973c622dd15a85e"
|
source = "git+https://github.com/rustdesk-org/nokhwa.git?branch=fix_from_raw_parts#f32e7d68be61db9b1e99016b24edb14543d0383b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"image 0.25.1",
|
"image 0.25.1",
|
||||||
|
|||||||
@@ -49,7 +49,18 @@ impl Cameras {
|
|||||||
let Some(info) = cameras.first() else {
|
let Some(info) = cameras.first() else {
|
||||||
bail!("No camera found")
|
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 resolution = camera.resolution();
|
||||||
let (width, height) = (resolution.width() as i32, resolution.height() as i32);
|
let (width, height) = (resolution.width() as i32, resolution.height() as i32);
|
||||||
camera_displays.push(DisplayInfo {
|
camera_displays.push(DisplayInfo {
|
||||||
@@ -110,9 +121,14 @@ impl Cameras {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_camera(index: &CameraIndex) -> ResultType<Camera> {
|
fn create_camera(index: &CameraIndex) -> ResultType<Camera> {
|
||||||
|
let format_type = if cfg!(target_os = "linux") {
|
||||||
|
RequestedFormatType::None
|
||||||
|
} else {
|
||||||
|
RequestedFormatType::AbsoluteHighestResolution
|
||||||
|
};
|
||||||
let result = Camera::new(
|
let result = Camera::new(
|
||||||
index.clone(),
|
index.clone(),
|
||||||
RequestedFormat::new::<RgbAFormat>(RequestedFormatType::None),
|
RequestedFormat::new::<RgbAFormat>(format_type),
|
||||||
);
|
);
|
||||||
match result {
|
match result {
|
||||||
Ok(camera) => Ok(camera),
|
Ok(camera) => Ok(camera),
|
||||||
|
|||||||
Reference in New Issue
Block a user