dynamic library - win virtual display

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-11-18 13:33:54 +08:00
parent 4a8578ee85
commit 26e8355528
10 changed files with 91 additions and 6 deletions

View File

@@ -53,6 +53,8 @@ mod connection;
pub mod portable_service;
mod service;
mod video_qos;
#[cfg(windows)]
mod virtual_display;
pub mod video_service;
use hbb_common::tcp::new_listener;

View File

@@ -42,7 +42,7 @@ use std::{
time::{self, Duration, Instant},
};
#[cfg(windows)]
use virtual_display;
use super::virtual_display;
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str =

View File

@@ -0,0 +1,64 @@
#![allow(dead_code)]
use hbb_common::{bail, ResultType};
use std::sync::{Arc, Mutex};
const LIB_NAME_VIRTUAL_DISPLAY: &str = "virtual_display";
lazy_static::lazy_static! {
static ref LIB_VIRTUAL_DISPLAY: Arc<Mutex<Result<libloading::Library, libloading::Error>>> = {
#[cfg(target_os = "windows")]
let libname = format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY);
#[cfg(target_os = "linux")]
let libname = format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY);
#[cfg(target_os = "macos")]
let libname = format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY);
Arc::new(Mutex::new(unsafe { libloading::Library::new(libname) }))
};
}
pub(super) fn is_device_created() -> bool {
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
Ok(lib) => unsafe {
match lib.get::<libloading::Symbol<fn() -> bool>>(b"is_device_created") {
Ok(func) => func(),
Err(..) => false,
}
},
Err(..) => false,
}
}
macro_rules! def_func_result {
($func:ident, $name: tt) => {
pub(super) fn $func() -> ResultType<()> {
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
Ok(lib) => unsafe {
match lib.get::<libloading::Symbol<fn() -> ResultType<()>>>($name.as_bytes()) {
Ok(func) => func(),
Err(..) => bail!("Failed to load func {}", $name),
}
},
Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e),
}
}
};
}
def_func_result!(create_device, "create_device");
pub(super) fn close_device() {
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
Ok(lib) => unsafe {
match lib.get::<libloading::Symbol<fn()>>(b"close_device") {
Ok(func) => func(),
Err(..) => {},
}
},
Err(..) => {},
}
}
def_func_result!(plug_in_monitor, "plug_in_monitor");
def_func_result!(plug_out_monitor, "plug_out_monitor");
def_func_result!(update_monitor_modes, "update_monitor_modes");