From f7e9057a3965248b8dbb4cc1a1c9a8c1eae24529 Mon Sep 17 00:00:00 2001 From: dignow <136106582+dignow@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:59:25 +0800 Subject: [PATCH] fix: video service, do not skip refresh message (#8815) Signed-off-by: dignow --- src/flutter.rs | 6 ++++++ src/server/video_service.rs | 24 +++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/flutter.rs b/src/flutter.rs index e9065636a..cd6e51ea1 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -1914,6 +1914,12 @@ pub mod sessions { // Try capture all displays. s.capture_displays(vec![], vec![], value); } + // When switching display, we also need to send "Refresh display" message. + // On the controlled side: + // 1. If this display is not currently captured -> Refresh -> Message "Refresh display" is not required. + // One more key frame (first frame) will be sent because the refresh message. + // 2. If this display is currently captured -> Not refresh -> Message "Refresh display" is required. + // Without the message, the control side cannot see the latest display image. #[cfg(not(any(target_os = "android", target_os = "ios")))] { let is_support_multi_ui_session = crate::common::is_support_multi_ui_session( diff --git a/src/server/video_service.rs b/src/server/video_service.rs index e4c16fd82..7fd5dee1f 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -68,8 +68,6 @@ use std::{ pub const NAME: &'static str = "video"; pub const OPTION_REFRESH: &'static str = "refresh"; -const REFRESH_MIN_INTERVAL_MILLIS: u128 = 300; - lazy_static::lazy_static! { static ref FRAME_FETCHED_NOTIFIER: (UnboundedSender<(i32, Option)>, Arc)>>>) = { let (tx, rx) = unbounded_channel(); @@ -78,8 +76,6 @@ lazy_static::lazy_static! { pub static ref VIDEO_QOS: Arc> = Default::default(); pub static ref IS_UAC_RUNNING: Arc> = Default::default(); pub static ref IS_FOREGROUND_WINDOW_ELEVATED: Arc> = Default::default(); - // Avoid refreshing too frequently - static ref LAST_REFRESH_TIME: Arc>> = Default::default(); } #[inline] @@ -517,23 +513,9 @@ fn run(vs: VideoService) -> ResultType<()> { drop(video_qos); if sp.is_option_true(OPTION_REFRESH) { - if LAST_REFRESH_TIME - .lock() - .unwrap() - .get(&vs.idx) - .map(|x| x.elapsed().as_millis() > REFRESH_MIN_INTERVAL_MILLIS) - .unwrap_or(true) - { - let _ = try_broadcast_display_changed(&sp, display_idx, &c, true); - LAST_REFRESH_TIME - .lock() - .unwrap() - .insert(vs.idx, Instant::now()); - log::info!("switch to refresh"); - bail!("SWITCH"); - } else { - sp.set_option_bool(OPTION_REFRESH, false); - } + let _ = try_broadcast_display_changed(&sp, display_idx, &c, true); + log::info!("switch to refresh"); + bail!("SWITCH"); } if codec_format != Encoder::negotiated_codec() { log::info!(