$NetBSD: patch-ba,v 1.3 2005/01/05 12:05:19 adam Exp $ --- src/audio/SDL_audio.c.orig 2004-12-13 07:54:31.000000000 +0000 +++ src/audio/SDL_audio.c @@ -38,8 +38,15 @@ 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, esd, nas */ + NULL, /* Optional 2: either arts, esd, nas */ + NULL, /* Optional 3: either arts, esd, nas */ +#define PLUGIN_COUNT 3 #ifdef OPENBSD_AUDIO_SUPPORT &OPENBSD_AUDIO_bootstrap, #endif @@ -59,15 +66,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 #ifdef ENABLE_DIRECTX &DSOUND_bootstrap, #endif @@ -268,16 +266,48 @@ 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"); + DO_LOAD("nas", "libaudio_nas.so", "NAS_bootstrap", "audio/SDL-nas"); +#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; @@ -287,7 +317,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; @@ -316,7 +346,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() ) { @@ -326,7 +356,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 ) {