From b9a9e0a6f1c9995b2100d3b68d58f91bb0fc0b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 10 Oct 2022 23:52:55 +0200 Subject: [PATCH] ao_pipewire: test for session to contain audio sinks The pure presence of PipeWire does not mean that it is actually driving the audio session. For example it could only be meant for video. Currently there is no proper API to detect this (see [0]), so we check for the presence of audio sinks. As soon as a proper API exists, we should use that. [0] https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1835 --- audio/out/ao_pipewire.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/audio/out/ao_pipewire.c b/audio/out/ao_pipewire.c index d4e71c9c2b..6628cd4b48 100644 --- a/audio/out/ao_pipewire.c +++ b/audio/out/ao_pipewire.c @@ -384,6 +384,22 @@ unlock_loop: return ret; } +static void have_sink(struct ao *ao, uint32_t id, const struct spa_dict *props, void *ctx) +{ + bool *b = ctx; + *b = true; +} + +static bool session_has_sinks(struct ao *ao) +{ + bool b = false; + + if (for_each_sink(ao, have_sink, &b) < 0) + MP_WARN(ao, "Could not list devices, sink detection may be wrong\n"); + + return b; +} + static int pipewire_init_boilerplate(struct ao *ao) { struct priv *p = ao->priv; @@ -416,6 +432,12 @@ static int pipewire_init_boilerplate(struct ao *ao) } pw_thread_loop_unlock(p->loop); + + if (!session_has_sinks(ao)) { + MP_VERBOSE(ao, "PipeWire does not have any audio sinks, skipping\n"); + return -1; + } + return 0; error: