From 4d537b2a9ad8d57b670cdb7f9af6df4052a7a346 Mon Sep 17 00:00:00 2001 From: dignow Date: Wed, 18 Oct 2023 11:35:28 +0800 Subject: [PATCH] fix/change_display_resolution, send change resolution message Signed-off-by: dignow --- src/server/display_service.rs | 4 +++- src/server/video_service.rs | 42 ++++++++++++++++------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/server/display_service.rs b/src/server/display_service.rs index d1d14f0f9..780833f78 100644 --- a/src/server/display_service.rs +++ b/src/server/display_service.rs @@ -60,7 +60,9 @@ impl SyncDisplaysInfo { } // This function is really useful, though a duplicate check if display changed. -// Because the video server will send the supported resolutions of the {idx} display to the subscribers. +// The video server will then send the following messages to the client: +// 1. the supported resolutions of the {idx} display +// 2. the switch resolution message, so that the client can record the custom resolution. pub(super) fn check_display_changed( ndisplay: usize, idx: usize, diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 0e1c3cb23..5b7496015 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -298,7 +298,6 @@ fn check_uac_switch(privacy_mode_id: i32, capturer_privacy_mode_id: i32) -> Resu } pub(super) struct CapturerInfo { - pub name: String, pub origin: (i32, i32), pub width: usize, pub height: usize, @@ -390,7 +389,6 @@ fn get_capturer( portable_service_running, )?; Ok(CapturerInfo { - name, origin, width, height, @@ -489,6 +487,7 @@ fn run(vs: VideoService) -> ResultType<()> { drop(video_qos); if sp.is_option_true(OPTION_REFRESH) { + let _ = try_broadcast_display_changed(&sp, display_idx, &c); bail!("SWITCH"); } if codec_name != Encoder::negotiated_codec() { @@ -510,15 +509,7 @@ fn run(vs: VideoService) -> ResultType<()> { let now = time::Instant::now(); if last_check_displays.elapsed().as_millis() > 1000 { last_check_displays = now; - if let Some(display) = check_display_changed( - c.ndisplay, - c.current, - (c.origin.0, c.origin.1, c.width, c.height), - ) { - log::info!("Display {} changed", display); - broadcast_display_changed(display_idx, &sp, display); - bail!("SWITCH"); - } + try_broadcast_display_changed(&sp, display_idx, &c)?; } frame_controller.reset(); @@ -595,15 +586,7 @@ fn run(vs: VideoService) -> ResultType<()> { } } Err(err) => { - if let Some(display) = check_display_changed( - c.ndisplay, - c.current, - (c.origin.0, c.origin.1, c.width, c.height), - ) { - log::info!("Display {} changed", display); - broadcast_display_changed(display_idx, &sp, display); - bail!("SWITCH"); - } + try_broadcast_display_changed(&sp, display_idx, &c)?; #[cfg(windows)] if !c.is_gdi() { @@ -858,10 +841,23 @@ fn get_wake_lock() -> crate::platform::WakeLock { } #[inline] -fn broadcast_display_changed(display_idx: usize, sp: &GenericService, display: DisplayInfo) { - if let Some(msg_out) = make_display_changed_msg(display_idx, Some(display)) { - sp.send(msg_out); +fn try_broadcast_display_changed( + sp: &GenericService, + display_idx: usize, + cap: &CapturerInfo, +) -> ResultType<()> { + if let Some(display) = check_display_changed( + cap.ndisplay, + cap.current, + (cap.origin.0, cap.origin.1, cap.width, cap.height), + ) { + log::info!("Display {} changed", display); + if let Some(msg_out) = make_display_changed_msg(display_idx, Some(display)) { + sp.send(msg_out); + bail!("SWITCH"); + } } + Ok(()) } pub fn make_display_changed_msg(