Skip to content

Commit

Permalink
pipewire_common: Stop the loop in get_devices()
Browse files Browse the repository at this point in the history
Fixes occasional crash
  • Loading branch information
mpiatka committed Oct 24, 2023
1 parent 2f8bf28 commit 0eb6c48
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/pipewire_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,33 @@ std::vector<Pipewire_device> get_pw_device_list(){
pipewire_state_common s;
initialize_pw_common(s);

pipewire_thread_loop_lock_guard lock(s.pipewire_loop.get());
std::vector<Pipewire_device> 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<Pipewire_device> result;
spa_hook_uniq registry_listener;
pw_registry_add_listener(registry.get(), &registry_listener.get(), &registry_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(), &registry_listener.get(), &registry_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;
}
Expand Down

0 comments on commit 0eb6c48

Please sign in to comment.