mirror of
https://github.com/mpv-player/mpv
synced 2025-03-22 19:34:14 +00:00
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
This commit is contained in:
parent
1c2dde91d3
commit
84dc9b1a02
@ -230,13 +230,17 @@ static const struct pw_stream_events stream_events = {
|
|||||||
static void uninit(struct ao *ao)
|
static void uninit(struct ao *ao)
|
||||||
{
|
{
|
||||||
struct priv *p = ao->priv;
|
struct priv *p = ao->priv;
|
||||||
if (p->loop)
|
if (p->loop) {
|
||||||
|
pw_thread_loop_lock(p->loop);
|
||||||
pw_thread_loop_stop(p->loop);
|
pw_thread_loop_stop(p->loop);
|
||||||
|
}
|
||||||
if (p->stream)
|
if (p->stream)
|
||||||
pw_stream_destroy(p->stream);
|
pw_stream_destroy(p->stream);
|
||||||
p->stream = NULL;
|
p->stream = NULL;
|
||||||
if (p->core)
|
if (p->core) {
|
||||||
pw_core_disconnect(p->core);
|
pw_core_disconnect(p->core);
|
||||||
|
pw_context_destroy(pw_core_get_context(p->core));
|
||||||
|
}
|
||||||
p->core = NULL;
|
p->core = NULL;
|
||||||
if (p->loop)
|
if (p->loop)
|
||||||
pw_thread_loop_destroy(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 priv *p = ao->priv;
|
||||||
struct pw_context *context;
|
struct pw_context *context;
|
||||||
|
int ret;
|
||||||
|
|
||||||
pw_init(NULL, NULL);
|
pw_init(NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
p->loop = pw_thread_loop_new("ao-pipewire", NULL);
|
p->loop = pw_thread_loop_new("ao-pipewire", NULL);
|
||||||
|
pw_thread_loop_lock(p->loop);
|
||||||
if (p->loop == NULL)
|
if (p->loop == NULL)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
if (pw_thread_loop_start(p->loop) < 0)
|
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);
|
context = pw_context_new(pw_thread_loop_get_loop(p->loop), NULL, 0);
|
||||||
if (!context)
|
if (!context)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
p->core = pw_context_connect(context, NULL, 0);
|
p->core = pw_context_connect(context, NULL, 0);
|
||||||
if (!p->core)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user