diff options
author | Thomas Weißschuh <thomas@t-8ch.de> | 2022-03-28 08:18:54 +0200 |
---|---|---|
committer | Philip Langdale <github.philipl@overt.org> | 2022-03-30 13:06:33 -0700 |
commit | 84dc9b1a02db896b972928d39ef6d621483afb3b (patch) | |
tree | b9ac6c8bf5138a1bd6d979b0182759b35c4357ce /audio | |
parent | 1c2dde91d369987199782f4914f56019e5a2272c (diff) | |
download | mpv-84dc9b1a02db896b972928d39ef6d621483afb3b.tar.bz2 mpv-84dc9b1a02db896b972928d39ef6d621483afb3b.tar.xz |
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
Diffstat (limited to 'audio')
-rw-r--r-- | audio/out/ao_pipewire.c | 28 |
1 files changed, 21 insertions, 7 deletions
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; } |