fix: Wayland capture lifecycle and potential deadlock
Signed-off-by: Steve3184 <77789906+Steve3184@users.noreply.github.com>
This commit is contained in:
parent
91eba100f5
commit
021d5a1b83
2 changed files with 13 additions and 13 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue