diff --git a/src/server/video_service.rs b/src/server/video_service.rs index ffe60551f..13a781c28 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -538,17 +538,11 @@ fn run(vs: VideoService) -> ResultType<()> { // But for now, we do not support multi-screen capture on wayland. #[cfg(target_os = "linux")] super::wayland::ensure_inited()?; - - #[cfg(windows)] - let last_portable_service_running = crate::portable_service::client::running(); - #[cfg(not(windows))] - let last_portable_service_running = false; - - let display_idx = vs.idx; - let sp = vs.sp; - let mut c = get_capturer(vs.source, display_idx, last_portable_service_running)?; #[cfg(target_os = "linux")] let _wayland_call_on_ret = { + // Increment active display count when starting + let _display_count = super::wayland::increment_active_display_count(); + SimpleCallOnReturn { b: true, f: Box::new(|| { @@ -560,6 +554,15 @@ fn run(vs: VideoService) -> ResultType<()> { }), } }; + + #[cfg(windows)] + let last_portable_service_running = crate::portable_service::client::running(); + #[cfg(not(windows))] + let last_portable_service_running = false; + + let display_idx = vs.idx; + let sp = vs.sp; + let mut c = get_capturer(vs.source, display_idx, last_portable_service_running)?; #[cfg(windows)] if !scrap::codec::enable_directx_capture() && !c.is_gdi() { log::info!("disable dxgi with option, fall back to gdi"); diff --git a/src/server/wayland.rs b/src/server/wayland.rs index d6e25c089..e56dbbb04 100644 --- a/src/server/wayland.rs +++ b/src/server/wayland.rs @@ -27,7 +27,6 @@ pub fn init() { } pub(super) fn increment_active_display_count() -> usize { - let _cap_map_guard = CAP_DISPLAY_INFO.read().unwrap(); let mut count = ACTIVE_DISPLAY_COUNT.write().unwrap(); *count += 1; *count @@ -349,7 +348,6 @@ pub(super) fn get_capturer_for_display( { let cap_map = CAP_DISPLAY_INFO.read().unwrap(); if let Some(&addr) = cap_map.get(&display_idx) { - increment_active_display_count(); return build_capturer_info(addr); } } @@ -361,7 +359,7 @@ pub(super) fn get_capturer_for_display( // Wait until all active capturers have exited before reinitializing. let active_count = *ACTIVE_DISPLAY_COUNT.read().unwrap(); - if active_count > 0 { + if active_count > 1 { bail!( "Display {} not found in CAP_DISPLAY_INFO, but {} active capturer(s) are still running. Skipping reinitialization now.", display_idx, active_count @@ -384,7 +382,6 @@ pub(super) fn get_capturer_for_display( "get_capturer_for_display: re-initialization succeeded for display {}.", display_idx ); - increment_active_display_count(); build_capturer_info(addr) } else { bail!(