src/audio/bsd/SDL_bsdaudio.c
changeset 5593 ab22ca13c47f
parent 5586 7fe92c1dc1d9
child 5594 e741303e08a8
--- a/src/audio/bsd/SDL_bsdaudio.c	Thu Aug 04 01:07:09 2011 -0400
+++ b/src/audio/bsd/SDL_bsdaudio.c	Thu Aug 04 00:31:11 2011 -0400
@@ -50,91 +50,23 @@
 #define BSD_AUDIO_DRIVER_DESC         "Native OpenBSD audio"
 #endif
 
-/* Open the audio device for playback, and don't block if busy */
-/* #define USE_BLOCKING_WRITES */
-
 /* Use timer for synchronization */
 /* #define USE_TIMER_SYNC */
 
 /* #define DEBUG_AUDIO */
 /* #define DEBUG_AUDIO_STREAM */
 
-#ifdef USE_BLOCKING_WRITES
-#define OPEN_FLAGS_OUTPUT O_WRONLY
-#define OPEN_FLAGS_INPUT O_RDONLY
-#else
-#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
-#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
-#endif
 
-/* !!! FIXME: so much cut and paste with dsp target... */
-static char **outputDevices = NULL;
-static int outputDeviceCount = 0;
-static char **inputDevices = NULL;
-static int inputDeviceCount = 0;
-
-static inline void
-free_device_list(char ***devs, int *count)
+static void
+BSDAUDIO_Deinitialize(void)
 {
-    SDL_FreeUnixAudioDevices(devs, count);
-}
-
-static inline void
-build_device_list(int iscapture, char ***devs, int *count)
-{
-    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
-    free_device_list(devs, count);
-    SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
-}
-
-static inline void
-build_device_lists(void)
-{
-    build_device_list(0, &outputDevices, &outputDeviceCount);
-    build_device_list(1, &inputDevices, &inputDeviceCount);
-}
-
-
-static inline void
-free_device_lists(void)
-{
-    free_device_list(&outputDevices, &outputDeviceCount);
-    free_device_list(&inputDevices, &inputDeviceCount);
 }
 
 
 static void
-BSDAUDIO_Deinitialize(void)
-{
-    free_device_lists();
-}
-
-
-static int
-BSDAUDIO_DetectDevices(int iscapture)
+BSDAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
 {
-    if (iscapture) {
-        build_device_list(1, &inputDevices, &inputDeviceCount);
-        return inputDeviceCount;
-    } else {
-        build_device_list(0, &outputDevices, &outputDeviceCount);
-        return outputDeviceCount;
-    }
-
-    return 0;                   /* shouldn't ever hit this. */
-}
-
-static const char *
-BSDAUDIO_GetDeviceName(int index, int iscapture)
-{
-    if ((iscapture) && (index < inputDeviceCount)) {
-        return inputDevices[index];
-    } else if ((!iscapture) && (index < outputDeviceCount)) {
-        return outputDevices[index];
-    }
-
-    SDL_SetError("No such device");
-    return NULL;
+    SDL_EnumUnixAudioDevices(iscapture, 0, NULL, addfn);
 }
 
 
@@ -318,12 +250,11 @@
     /* We don't care what the devname is...we'll try to open anything. */
     /*  ...but default to first name in the list... */
     if (devname == NULL) {
-        if (((iscapture) && (inputDeviceCount == 0)) ||
-            ((!iscapture) && (outputDeviceCount == 0))) {
+        devname = SDL_GetAudioDeviceName(0, iscapture);
+        if (devname == NULL) {
             SDL_SetError("No such audio device");
             return 0;
         }
-        devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
     }
 
     /* Initialize all variables that we clean on shutdown */
@@ -434,7 +365,6 @@
 {
     /* Set the function pointers */
     impl->DetectDevices = BSDAUDIO_DetectDevices;
-    impl->GetDeviceName = BSDAUDIO_GetDeviceName;
     impl->OpenDevice = BSDAUDIO_OpenDevice;
     impl->PlayDevice = BSDAUDIO_PlayDevice;
     impl->WaitDevice = BSDAUDIO_WaitDevice;
@@ -442,8 +372,6 @@
     impl->CloseDevice = BSDAUDIO_CloseDevice;
     impl->Deinitialize = BSDAUDIO_Deinitialize;
 
-    build_device_lists();
-
     return 1;   /* this audio target is available. */
 }