$NetBSD$ --- src/audio/SDL_audio.c.orig 2002-10-05 18:50:56.000000000 +0200 +++ src/audio/SDL_audio.c @@ -38,8 +38,14 @@ static char rcsid = #include "SDL_audiomem.h" #include "SDL_sysaudio.h" +#include "SDL_name.h" +#include "SDL_loadso.h" + /* Available audio drivers */ static AudioBootStrap *bootstrap[] = { + NULL, /* Optional 1: either arts or esd */ + NULL, /* Optional 2: either arts or esd */ +#define PLUGIN_COUNT 2 #ifdef OPENBSD_AUDIO_SUPPORT &OPENBSD_AUDIO_bootstrap, #endif @@ -56,12 +62,6 @@ static AudioBootStrap *bootstrap[] = { #ifdef DMEDIA_SUPPORT &DMEDIA_bootstrap, #endif -#ifdef ARTSC_SUPPORT - &ARTSC_bootstrap, -#endif -#ifdef ESD_SUPPORT - &ESD_bootstrap, -#endif #ifdef NAS_SUPPORT &NAS_bootstrap, #endif @@ -252,16 +252,47 @@ static void SDL_UnlockAudio_Default(SDL_ SDL_mutexV(audio->mixer_lock); } +static int SDL_LoadAudioPlugins(void) +{ + int first = PLUGIN_COUNT; + char *envvar; + void *plugin; + +#define DO_LOAD(IDNAME, SONAME, BSNAME, PKGNAME) \ + envvar = getenv("SDL_AUDIO_PLUGIN"); \ + if (envvar == NULL || strcmp(envvar, IDNAME) == 0) { \ + plugin = SDL_LoadObject(SONAME); \ + if (plugin != NULL) { \ + struct AudioBootStrap *bs; \ + bs = SDL_LoadFunction(plugin, BSNAME); \ + if (bs != NULL) { \ + bootstrap[--first] = bs; \ + } \ + } else if (envvar != NULL && strcmp(envvar, IDNAME) == 0) { \ + fprintf(stderr, "SDL (pkgsrc): SDL_AUDIO_PLUGIN is explicitly set to `" IDNAME "'.\n"); \ + fprintf(stderr, "SDL (pkgsrc): Please install the " PKGNAME " package and retry.\n"); \ + } \ + } + + DO_LOAD("arts", "libaudio_arts.so", "ARTSC_bootstrap", "audio/SDL-arts"); + DO_LOAD("esound", "libaudio_esd.so", "ESD_bootstrap", "audio/SDL-esound"); +#undef DO_LOAD + + return first; +} + int SDL_AudioInit(const char *driver_name) { SDL_AudioDevice *audio; - int i = 0, idx; + int i = 0, idx, first; /* Check to make sure we don't overwrite 'current_audio' */ if ( current_audio != NULL ) { SDL_AudioQuit(); } + first = SDL_LoadAudioPlugins(); + /* Select the proper audio driver */ audio = NULL; idx = 0; @@ -271,7 +302,7 @@ int SDL_AudioInit(const char *driver_nam to use ESD, but don't start it if it's not already running. This probably isn't the place to do this, but... Shh! :) */ - for ( i=0; bootstrap[i]; ++i ) { + for ( i=first; bootstrap[i]; ++i ) { if ( strcmp(bootstrap[i]->name, "esd") == 0 ) { const char *esd_no_spawn; @@ -300,7 +331,7 @@ int SDL_AudioInit(const char *driver_nam idx = atoi(strrchr(driver_name, ':')+1); } #endif - for ( i=0; bootstrap[i]; ++i ) { + for ( i=first; bootstrap[i]; ++i ) { if (strncmp(bootstrap[i]->name, driver_name, strlen(bootstrap[i]->name)) == 0) { if ( bootstrap[i]->available() ) { @@ -310,7 +341,7 @@ int SDL_AudioInit(const char *driver_nam } } } else { - for ( i=0; bootstrap[i]; ++i ) { + for ( i=first; bootstrap[i]; ++i ) { if ( bootstrap[i]->available() ) { audio = bootstrap[i]->create(idx); if ( audio != NULL ) {