From 0eb6c486b2e7832ab69b322db1381bad01c184cc Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Mon, 23 Oct 2023 14:24:23 +0200 Subject: [PATCH] pipewire_common: Stop the loop in get_devices() Fixes occasional crash --- src/pipewire_common.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/pipewire_common.cpp b/src/pipewire_common.cpp index d22c5b04d..a66586d60 100644 --- a/src/pipewire_common.cpp +++ b/src/pipewire_common.cpp @@ -83,27 +83,33 @@ std::vector get_pw_device_list(){ pipewire_state_common s; initialize_pw_common(s); - pipewire_thread_loop_lock_guard lock(s.pipewire_loop.get()); + std::vector result; - pw_registry_uniq registry(pw_core_get_registry(s.pipewire_core.get(), PW_VERSION_REGISTRY, 0)); + { - const static pw_registry_events registry_events = { - PW_VERSION_REGISTRY_EVENTS, - .global = on_registry_event_global, - .global_remove = nullptr - }; + pipewire_thread_loop_lock_guard lock(s.pipewire_loop.get()); - std::vector result; - spa_hook_uniq registry_listener; - pw_registry_add_listener(registry.get(), ®istry_listener.get(), ®istry_events, &result); + pw_registry_uniq registry(pw_core_get_registry(s.pipewire_core.get(), PW_VERSION_REGISTRY, 0)); + + const static pw_registry_events registry_events = { + PW_VERSION_REGISTRY_EVENTS, + .global = on_registry_event_global, + .global_remove = nullptr + }; - s.pw_pending_seq = pw_core_sync(s.pipewire_core.get(), PW_ID_CORE, s.pw_pending_seq); - int wait_seq = s.pw_pending_seq; + spa_hook_uniq registry_listener; + pw_registry_add_listener(registry.get(), ®istry_listener.get(), ®istry_events, &result); - do{ - pw_thread_loop_wait(s.pipewire_loop.get()); - } while(s.pw_last_seq < wait_seq); + s.pw_pending_seq = pw_core_sync(s.pipewire_core.get(), PW_ID_CORE, s.pw_pending_seq); + int wait_seq = s.pw_pending_seq; + + do{ + pw_thread_loop_wait(s.pipewire_loop.get()); + } while(s.pw_last_seq < wait_seq); + + } + pw_thread_loop_stop(s.pipewire_loop.get()); return result; }