Option allow-d3d-render and fix ios ci (#11107)

* option `allow-d3d-render`, default false

Add this option because it fails on some machines

Signed-off-by: 21pages <sunboeasy@gmail.com>

* only add nokhwa to windows and linux dependencies

Signed-off-by: 21pages <sunboeasy@gmail.com>

---------

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2025-03-13 09:34:13 +08:00 committed by GitHub
parent 1403c939db
commit d1c8b331c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 204 additions and 43 deletions

@ -1 +1 @@
Subproject commit 7cf11f7b771e27ecbd14fd1dd0ced55a64f40eb5
Subproject commit 1819875476d487612a654099881b8a16f4337599

View file

@ -23,7 +23,6 @@ lazy_static = "1.4"
hbb_common = { path = "../hbb_common" }
webm = { git = "https://github.com/rustdesk-org/rust-webm" }
serde = {version="1.0", features=["derive"]}
nokhwa = { git = "https://github.com/rustdesk-org/nokhwa.git", branch = "fix_from_raw_parts", features = ["input-native"] }
[dependencies.winapi]
version = "0.3"
@ -63,3 +62,6 @@ gstreamer-video = { version = "0.16", optional = true }
git = "https://github.com/rustdesk-org/hwcodec"
optional = true
[target.'cfg(any(target_os = "windows", target_os = "linux"))'.dependencies]
nokhwa = { git = "https://github.com/rustdesk-org/nokhwa.git", branch = "fix_from_raw_parts", features = ["input-native"] }

View file

@ -3,6 +3,7 @@ use std::{
sync::{Arc, Mutex},
};
#[cfg(any(target_os = "windows", target_os = "linux"))]
use nokhwa::{
pixel_format::RgbAFormat,
query,
@ -23,6 +24,9 @@ lazy_static::lazy_static! {
static ref SYNC_CAMERA_DISPLAYS: Arc<Mutex<Vec<DisplayInfo>>> = Arc::new(Mutex::new(Vec::new()));
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
const CAMERA_NOT_SUPPORTED: &str = "This platform doesn't support camera yet";
pub struct Cameras;
// pre-condition
@ -30,12 +34,9 @@ pub fn primary_camera_exists() -> bool {
Cameras::exists(PRIMARY_CAMERA_IDX)
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
impl Cameras {
pub fn all_info() -> ResultType<Vec<DisplayInfo>> {
// TODO: support more platforms.
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
return Ok(Vec::new());
match query(ApiBackend::Auto) {
Ok(cameras) => {
let mut camera_displays = SYNC_CAMERA_DISPLAYS.lock().unwrap();
@ -102,10 +103,6 @@ impl Cameras {
}
pub fn exists(index: usize) -> bool {
// TODO: support more platforms.
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
return false;
match query(ApiBackend::Auto) {
Ok(cameras) => index < cameras.len(),
_ => return false,
@ -113,10 +110,6 @@ impl Cameras {
}
fn create_camera(index: &CameraIndex) -> ResultType<Camera> {
// TODO: support more platforms.
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
bail!("This platform doesn't support camera yet");
let result = Camera::new(
index.clone(),
RequestedFormat::new::<RgbAFormat>(RequestedFormatType::AbsoluteHighestResolution),
@ -147,13 +140,41 @@ impl Cameras {
}
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
impl Cameras {
pub fn all_info() -> ResultType<Vec<DisplayInfo>> {
return Ok(Vec::new());
}
pub fn exists(index: usize) -> bool {
false
}
pub fn get_camera_resolution(index: usize) -> ResultType<Resolution> {
bail!(CAMERA_NOT_SUPPORTED);
}
pub fn get_sync_cameras() -> Vec<DisplayInfo> {
vec![]
}
pub fn get_capturer(current: usize) -> ResultType<Box<dyn TraitCapturer>> {
bail!(CAMERA_NOT_SUPPORTED);
}
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
pub struct CameraCapturer {
camera: Camera,
data: Vec<u8>,
last_data: Vec<u8>, // for faster compare and copy
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
pub struct CameraCapturer;
impl CameraCapturer {
#[cfg(any(target_os = "windows", target_os = "linux"))]
fn new(current: usize) -> ResultType<Self> {
let index = CameraIndex::Index(current as u32);
let camera = Cameras::create_camera(&index)?;
@ -163,9 +184,15 @@ impl CameraCapturer {
last_data: Vec::new(),
})
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
fn new(_current: usize) -> ResultType<Self> {
bail!(CAMERA_NOT_SUPPORTED);
}
}
impl TraitCapturer for CameraCapturer {
#[cfg(any(target_os = "windows", target_os = "linux"))]
fn frame<'a>(&'a mut self, _timeout: std::time::Duration) -> std::io::Result<Frame<'a>> {
// TODO: move this check outside `frame`.
if !self.camera.is_stream_open() {
@ -212,6 +239,14 @@ impl TraitCapturer for CameraCapturer {
}
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
fn frame<'a>(&'a mut self, _timeout: std::time::Duration) -> std::io::Result<Frame<'a>> {
Err(io::Error::new(
io::ErrorKind::Other,
CAMERA_NOT_SUPPORTED.to_string(),
))
}
#[cfg(windows)]
fn is_gdi(&self) -> bool {
false

View file

@ -864,7 +864,7 @@ pub fn enable_vram_option(encode: bool) -> bool {
if encode {
enable && enable_directx_capture()
} else {
enable
enable && allow_d3d_render()
}
} else {
false
@ -874,10 +874,13 @@ pub fn enable_vram_option(encode: bool) -> bool {
#[cfg(windows)]
pub fn enable_directx_capture() -> bool {
use hbb_common::config::keys::OPTION_ENABLE_DIRECTX_CAPTURE as OPTION;
option2bool(
OPTION,
&Config::get_option(hbb_common::config::keys::OPTION_ENABLE_DIRECTX_CAPTURE),
)
option2bool(OPTION, &Config::get_option(OPTION))
}
#[cfg(windows)]
pub fn allow_d3d_render() -> bool {
use hbb_common::config::keys::OPTION_ALLOW_D3D_RENDER as OPTION;
option2bool(OPTION, &hbb_common::config::LocalConfig::get_option(OPTION))
}
pub const BR_BEST: f32 = 1.5;

View file

@ -48,8 +48,9 @@ pub use self::convert::*;
pub const STRIDE_ALIGN: usize = 64; // commonly used in libvpx vpx_img_alloc caller
pub const HW_STRIDE_ALIGN: usize = 0; // recommended by av_frame_get_buffer
pub mod camera;
pub mod aom;
#[cfg(not(any(target_os = "ios")))]
pub mod camera;
pub mod record;
mod vpx;

View file

@ -25,7 +25,8 @@ pub struct RecorderContext {
pub server: bool,
pub id: String,
pub dir: String,
pub video_service_name: String,
pub display_idx: usize,
pub camera: bool,
pub tx: Option<Sender<RecordState>>,
}
@ -46,7 +47,11 @@ impl RecorderContext2 {
+ "_"
+ &ctx.id.clone()
+ &chrono::Local::now().format("_%Y%m%d%H%M%S%3f_").to_string()
+ &format!("{}_", ctx.video_service_name)
+ &format!(
"{}{}_",
if ctx.camera { "camera" } else { "display" },
ctx.display_idx
)
+ &self.format.to_string().to_lowercase()
+ if self.format == CodecFormat::VP9
|| self.format == CodecFormat::VP8