From 84dc9b1a02db896b972928d39ef6d621483afb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 28 Mar 2022 08:18:54 +0200 Subject: ao_pipewire: fix resource lifetimes We have to destroy the core before destroying the loop. Also we have to lock the mainloop for operations on its objects. Fixes #10003 --- audio/out/ao_pipewire.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_pipewire.c b/audio/out/ao_pipewire.c index 0b2e178bbe..8cd778b0c9 100644 --- a/audio/out/ao_pipewire.c +++ b/audio/out/ao_pipewire.c @@ -230,13 +230,17 @@ static const struct pw_stream_events stream_events = { static void uninit(struct ao *ao) { struct priv *p = ao->priv; - if (p->loop) + if (p->loop) { + pw_thread_loop_lock(p->loop); pw_thread_loop_stop(p->loop); + } if (p->stream) pw_stream_destroy(p->stream); p->stream = NULL; - if (p->core) + if (p->core) { pw_core_disconnect(p->core); + pw_context_destroy(pw_core_get_context(p->core)); + } p->core = NULL; if (p->loop) pw_thread_loop_destroy(p->loop); @@ -347,26 +351,36 @@ static int pipewire_init_boilerplate(struct ao *ao) { struct priv *p = ao->priv; struct pw_context *context; + int ret; pw_init(NULL, NULL); p->loop = pw_thread_loop_new("ao-pipewire", NULL); + pw_thread_loop_lock(p->loop); if (p->loop == NULL) - return -1; + goto error; if (pw_thread_loop_start(p->loop) < 0) - return -1; + goto error; context = pw_context_new(pw_thread_loop_get_loop(p->loop), NULL, 0); if (!context) - return -1; + goto error; p->core = pw_context_connect(context, NULL, 0); if (!p->core) - return -1; + goto error; - return 0; + ret = 0; + +out: + pw_thread_loop_unlock(p->loop); + return ret; + +error: + ret = -1; + goto out; } -- cgit v1.2.3