From aeb223fc23c057af5d6bce12719b0f872b8ae8bf Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 28 May 2024 22:06:43 -0400 Subject: [PATCH] pipewire: if no devices seen in "preferred" init, try a different backend. We're seeing people with legit PipeWire installs that don't export any devices, that are also running a (not emulated) PulseAudio install that works. This solution might still get tweaked some more, but it seems to be working so far. --- src/audio/pipewire/SDL_pipewire.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index aab43f1617..f832eb79b3 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -1326,7 +1326,28 @@ static SDL_bool PipewireInitialize(SDL_AudioDriverImpl *impl, SDL_bool check_pre static SDL_bool PIPEWIRE_PREFERRED_Init(SDL_AudioDriverImpl *impl) { - return PipewireInitialize(impl, SDL_TRUE); + if (!PipewireInitialize(impl, SDL_TRUE)) { + return SDL_FALSE; + } + + // run device detection but don't add any devices to SDL; we're just waiting to see if PipeWire sees any devices. If not, fall back to the next backend. + PIPEWIRE_pw_thread_loop_lock(hotplug_loop); + + // Wait until the initial registry enumeration is complete + if (!hotplug_init_complete) { + PIPEWIRE_pw_thread_loop_wait(hotplug_loop); + } + + const int no_devices = spa_list_is_empty(&hotplug_io_list); + + PIPEWIRE_pw_thread_loop_unlock(hotplug_loop); + + if (no_devices) { + PIPEWIRE_Deinitialize(); + return SDL_FALSE; + } + + return SDL_TRUE; // this will move on to PIPEWIRE_DetectDevices and reuse hotplug_io_list. } static SDL_bool PIPEWIRE_Init(SDL_AudioDriverImpl *impl)