mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
remove many unwrap and enum_value_or_default
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -99,9 +99,11 @@ pub extern "system" fn Java_com_carriez_flutter_1hbb_MainService_onVideoFrameUpd
|
||||
buffer: JObject,
|
||||
) {
|
||||
let jb = JByteBuffer::from(buffer);
|
||||
let data = env.get_direct_buffer_address(&jb).unwrap();
|
||||
let len = env.get_direct_buffer_capacity(&jb).unwrap();
|
||||
VIDEO_RAW.lock().unwrap().update(data, len);
|
||||
if let Ok(data) = env.get_direct_buffer_address(&jb) {
|
||||
if let Ok(len) = env.get_direct_buffer_capacity(&jb) {
|
||||
VIDEO_RAW.lock().unwrap().update(data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -111,9 +113,11 @@ pub extern "system" fn Java_com_carriez_flutter_1hbb_MainService_onAudioFrameUpd
|
||||
buffer: JObject,
|
||||
) {
|
||||
let jb = JByteBuffer::from(buffer);
|
||||
let data = env.get_direct_buffer_address(&jb).unwrap();
|
||||
let len = env.get_direct_buffer_capacity(&jb).unwrap();
|
||||
AUDIO_RAW.lock().unwrap().update(data, len);
|
||||
if let Ok(data) = env.get_direct_buffer_address(&jb) {
|
||||
if let Ok(len) = env.get_direct_buffer_capacity(&jb) {
|
||||
AUDIO_RAW.lock().unwrap().update(data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -142,12 +146,12 @@ pub extern "system" fn Java_com_carriez_flutter_1hbb_MainService_init(
|
||||
ctx: JObject,
|
||||
) {
|
||||
log::debug!("MainService init from java");
|
||||
let jvm = env.get_java_vm().unwrap();
|
||||
|
||||
*JVM.write().unwrap() = Some(jvm);
|
||||
|
||||
let context = env.new_global_ref(ctx).unwrap();
|
||||
*MAIN_SERVICE_CTX.write().unwrap() = Some(context);
|
||||
if let Ok(jvm) = env.get_java_vm() {
|
||||
*JVM.write().unwrap() = Some(jvm);
|
||||
if let Ok(context) = env.new_global_ref(ctx) {
|
||||
*MAIN_SERVICE_CTX.write().unwrap() = Some(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn call_main_service_mouse_input(mask: i32, x: i32, y: i32) -> JniResult<()> {
|
||||
|
||||
@@ -19,20 +19,19 @@ use crate::{
|
||||
|
||||
use hbb_common::{
|
||||
anyhow::anyhow,
|
||||
bail,
|
||||
config::PeerConfig,
|
||||
log,
|
||||
message_proto::{
|
||||
supported_decoding::PreferCodec, video_frame, EncodedVideoFrames, Message,
|
||||
SupportedDecoding, SupportedEncoding,
|
||||
},
|
||||
sysinfo::{System, SystemExt},
|
||||
tokio::time::Instant,
|
||||
ResultType,
|
||||
};
|
||||
#[cfg(any(feature = "hwcodec", feature = "mediacodec"))]
|
||||
use hbb_common::{config::Config2, lazy_static};
|
||||
use hbb_common::{
|
||||
sysinfo::{System, SystemExt},
|
||||
tokio::time::Instant,
|
||||
};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref PEER_DECODINGS: Arc<Mutex<HashMap<i32, SupportedDecoding>>> = Default::default();
|
||||
@@ -88,9 +87,9 @@ impl DerefMut for Encoder {
|
||||
}
|
||||
|
||||
pub struct Decoder {
|
||||
vp8: VpxDecoder,
|
||||
vp9: VpxDecoder,
|
||||
av1: AomDecoder,
|
||||
vp8: Option<VpxDecoder>,
|
||||
vp9: Option<VpxDecoder>,
|
||||
av1: Option<AomDecoder>,
|
||||
#[cfg(feature = "hwcodec")]
|
||||
hw: HwDecoders,
|
||||
#[cfg(feature = "hwcodec")]
|
||||
@@ -279,12 +278,12 @@ impl Decoder {
|
||||
let vp8 = VpxDecoder::new(VpxDecoderConfig {
|
||||
codec: VpxVideoCodecId::VP8,
|
||||
})
|
||||
.unwrap();
|
||||
.ok();
|
||||
let vp9 = VpxDecoder::new(VpxDecoderConfig {
|
||||
codec: VpxVideoCodecId::VP9,
|
||||
})
|
||||
.unwrap();
|
||||
let av1 = AomDecoder::new().unwrap();
|
||||
.ok();
|
||||
let av1 = AomDecoder::new().ok();
|
||||
Decoder {
|
||||
vp8,
|
||||
vp9,
|
||||
@@ -314,13 +313,25 @@ impl Decoder {
|
||||
) -> ResultType<bool> {
|
||||
match frame {
|
||||
video_frame::Union::Vp8s(vp8s) => {
|
||||
Decoder::handle_vpxs_video_frame(&mut self.vp8, vp8s, rgb)
|
||||
if let Some(vp8) = &mut self.vp8 {
|
||||
Decoder::handle_vpxs_video_frame(vp8, vp8s, rgb)
|
||||
} else {
|
||||
bail!("vp8 decoder not available");
|
||||
}
|
||||
}
|
||||
video_frame::Union::Vp9s(vp9s) => {
|
||||
Decoder::handle_vpxs_video_frame(&mut self.vp9, vp9s, rgb)
|
||||
if let Some(vp9) = &mut self.vp9 {
|
||||
Decoder::handle_vpxs_video_frame(vp9, vp9s, rgb)
|
||||
} else {
|
||||
bail!("vp9 decoder not available");
|
||||
}
|
||||
}
|
||||
video_frame::Union::Av1s(av1s) => {
|
||||
Decoder::handle_av1s_video_frame(&mut self.av1, av1s, rgb)
|
||||
if let Some(av1) = &mut self.av1 {
|
||||
Decoder::handle_av1s_video_frame(av1, av1s, rgb)
|
||||
} else {
|
||||
bail!("av1 decoder not available");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "hwcodec")]
|
||||
video_frame::Union::H264s(h264s) => {
|
||||
|
||||
@@ -129,7 +129,7 @@ impl MagInterface {
|
||||
unsafe {
|
||||
// load lib
|
||||
let lib_file_name = "Magnification.dll";
|
||||
let lib_file_name_c = CString::new(lib_file_name).unwrap();
|
||||
let lib_file_name_c = CString::new(lib_file_name)?;
|
||||
s.lib_handle = LoadLibraryExA(
|
||||
lib_file_name_c.as_ptr() as _,
|
||||
NULL,
|
||||
@@ -189,7 +189,7 @@ impl MagInterface {
|
||||
}
|
||||
|
||||
unsafe fn load_func(lib_module: HMODULE, func_name: &str) -> Result<FARPROC> {
|
||||
let func_name_c = CString::new(func_name).unwrap();
|
||||
let func_name_c = CString::new(func_name)?;
|
||||
let func = GetProcAddress(lib_module, func_name_c.as_ptr() as _);
|
||||
if func.is_null() {
|
||||
return Err(Error::new(
|
||||
@@ -442,7 +442,7 @@ impl CapturerMag {
|
||||
}
|
||||
|
||||
pub(crate) fn exclude(&mut self, cls: &str, name: &str) -> Result<bool> {
|
||||
let name_c = CString::new(name).unwrap();
|
||||
let name_c = CString::new(name)?;
|
||||
unsafe {
|
||||
let mut hwnd = if cls.len() == 0 {
|
||||
FindWindowExA(NULL as _, NULL as _, NULL as _, name_c.as_ptr())
|
||||
|
||||
@@ -594,13 +594,14 @@ fn request_screen_cast(
|
||||
}
|
||||
let fd_res = fd_res.lock().unwrap();
|
||||
let streams_res = streams_res.lock().unwrap();
|
||||
if fd_res.is_some() && !streams_res.is_empty() {
|
||||
Ok((conn, fd_res.clone().unwrap(), streams_res.clone()))
|
||||
} else {
|
||||
Err(Box::new(DBusError(
|
||||
"Failed to obtain screen capture.".into(),
|
||||
)))
|
||||
if let Some(fd_res) = fd_res.clone() {
|
||||
if !streams_res.is_empty() {
|
||||
return Ok((conn, fd_res, streams_res.clone()));
|
||||
}
|
||||
}
|
||||
Err(Box::new(DBusError(
|
||||
"Failed to obtain screen capture.".into(),
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn get_capturables(capture_cursor: bool) -> Result<Vec<PipeWireCapturable>, Box<dyn Error>> {
|
||||
|
||||
Reference in New Issue
Block a user