diff src/audio/alsa/SDL_alsa_audio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents ee5dfa7f7993
children
line wrap: on
line diff
--- a/src/audio/alsa/SDL_alsa_audio.c	Tue Oct 17 08:04:51 2006 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Tue Oct 17 09:09:21 2006 +0000
@@ -151,12 +151,10 @@
 
 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 
-static int library_load_count = 0;
-
 static void
 UnloadALSALibrary(void)
 {
-    if ((alsa_handle != NULL) && (--library_load_count == 0)) {
+    if (alsa_handle != NULL) {
         dlclose(alsa_handle);
         alsa_handle = NULL;
     }
@@ -166,10 +164,9 @@
 LoadALSALibrary(void)
 {
     int retval = 0;
-    if (library_load_count++ == 0) {
+    if (alsa_handle == NULL) {
         alsa_handle = dlopen(alsa_library, RTLD_NOW);
         if (alsa_handle == NULL) {
-            library_load_count--;
             retval = -1;
             SDL_SetError("ALSA: dlopen('%s') failed: %s\n",
                           alsa_library, strerror(errno));
@@ -217,20 +214,6 @@
 }
 
 
-static int
-ALSA_Available(void)
-{
-    int available = 0;
-
-    if (LoadALSALibrary() >= 0) {
-        available = 1;
-        UnloadALSALibrary();
-    }
-    return (available);
-}
-
-
-
 /* This function waits until it is possible to write a full sound buffer */
 static void
 ALSA_WaitDevice(_THIS)
@@ -377,7 +360,6 @@
         }
         SDL_free(this->hidden);
         this->hidden = NULL;
-        UnloadALSALibrary();
     }
 }
 
@@ -401,11 +383,6 @@
     }
     SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
-    if (LoadALSALibrary() < 0) {
-        ALSA_CloseDevice(this);
-        return 0;
-    }
-
     /* Open the audio device */
     /* Name of device should depend on # channels in spec */
     status = ALSA_snd_pcm_open(&pcm_handle,
@@ -599,15 +576,26 @@
     return 1;
 }
 
+static void
+ALSA_Deinitialize(void)
+{
+    UnloadALSALibrary();
+}
+
 static int
 ALSA_Init(SDL_AudioDriverImpl *impl)
 {
+    if (LoadALSALibrary() < 0) {
+        return 0;
+    }
+
     /* Set the function pointers */
     impl->OpenDevice = ALSA_OpenDevice;
     impl->WaitDevice = ALSA_WaitDevice;
     impl->GetDeviceBuf = ALSA_GetDeviceBuf;
     impl->PlayDevice = ALSA_PlayDevice;
     impl->CloseDevice = ALSA_CloseDevice;
+    impl->Deinitialize = ALSA_Deinitialize;
     impl->OnlyHasDefaultOutputDevice = 1;  /* !!! FIXME: Add device enum! */
 
     return 1;
@@ -615,8 +603,7 @@
 
 
 AudioBootStrap ALSA_bootstrap = {
-    DRIVER_NAME, "ALSA 0.9 PCM audio",
-    ALSA_Available, ALSA_Init, 0
+    DRIVER_NAME, "ALSA 0.9 PCM audio", ALSA_Init, 0
 };
 
 /* vi: set ts=4 sw=4 expandtab: */