SDL: dsp: Refuse to initialize if there aren't any Open Sound System devices.

From e7e519a466167b7a3ef9aa9b28535e436139936a Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 17 Mar 2021 13:04:05 -0400
Subject: [PATCH] dsp: Refuse to initialize if there aren't any Open Sound
 System devices.

This prevents the dsp target from stealing the audio subsystem but not
being able to produce sound, so other audio targets further down the list
can make an attempt instead.

Thanks to Frank Praznik who did a lot of the research on this problem!
---
 src/audio/dsp/SDL_dspaudio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c
index 1622c6f87..2124dcc1f 100644
--- a/src/audio/dsp/SDL_dspaudio.c
+++ b/src/audio/dsp/SDL_dspaudio.c
@@ -292,9 +292,24 @@ DSP_FlushCapture(_THIS)
     }
 }
 
+static SDL_bool InitTimeDevicesExist = SDL_FALSE;
+static int
+look_for_devices_test(int fd)
+{
+    InitTimeDevicesExist = SDL_TRUE;  /* note that _something_ exists. */
+    /* Don't add to the device list, we're just seeing if any devices exist. */
+    return 0;
+}
+
 static int
 DSP_Init(SDL_AudioDriverImpl * impl)
 {
+    InitTimeDevicesExist = SDL_FALSE;
+    SDL_EnumUnixAudioDevices(0, look_for_devices_test);
+    if (!InitTimeDevicesExist) {
+        return 0;  /* maybe try a different backend. */
+    }
+
     /* Set the function pointers */
     impl->DetectDevices = DSP_DetectDevices;
     impl->OpenDevice = DSP_OpenDevice;