Added a new header file: SDL_loadso.h
It contains the following functions: SDL_LoadObject(), SDL_LoadFunction(), SDL_UnloadObject() The UNIX esd and arts audio code use these to dynamically load their respective audio libraries. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40295
This commit is contained in:
parent
89f7ace3fc
commit
b7e54037ed
13 changed files with 516 additions and 24 deletions
|
@ -4,6 +4,8 @@
|
|||
noinst_LTLIBRARIES = libaudio_arts.la
|
||||
libaudio_arts_la_SOURCES = $(SRCS)
|
||||
|
||||
arts_lib = \"@arts_lib@\"
|
||||
|
||||
# The SDL audio driver sources
|
||||
SRCS = SDL_artsaudio.c \
|
||||
SDL_artsaudio.h
|
||||
|
|
|
@ -43,6 +43,13 @@ static char rcsid =
|
|||
#include "SDL_audiodev_c.h"
|
||||
#include "SDL_artsaudio.h"
|
||||
|
||||
#ifdef ARTSC_DYNAMIC
|
||||
#include "SDL_name.h"
|
||||
#include "SDL_loadso.h"
|
||||
#else
|
||||
#define SDL_NAME(X) X
|
||||
#endif
|
||||
|
||||
/* The tag name used by artsc audio */
|
||||
#define ARTSC_DRIVER_NAME "artsc"
|
||||
|
||||
|
@ -53,20 +60,96 @@ static void ARTSC_PlayAudio(_THIS);
|
|||
static Uint8 *ARTSC_GetAudioBuf(_THIS);
|
||||
static void ARTSC_CloseAudio(_THIS);
|
||||
|
||||
#ifdef ARTSC_DYNAMIC
|
||||
|
||||
static const char *arts_library = ARTSC_DYNAMIC;
|
||||
static void *arts_handle = NULL;
|
||||
static int arts_loaded = 0;
|
||||
|
||||
static int (*SDL_NAME(arts_init))();
|
||||
static int (*SDL_NAME(arts_free))();
|
||||
static int (*SDL_NAME(arts_play_stream))();
|
||||
static int (*SDL_NAME(arts_stream_set))();
|
||||
static int (*SDL_NAME(arts_stream_get))();
|
||||
static int (*SDL_NAME(arts_write))();
|
||||
static int (*SDL_NAME(arts_close_stream))();
|
||||
static struct {
|
||||
const char *name;
|
||||
void **func;
|
||||
} arts_functions[] = {
|
||||
{ "arts_init", (void **)&SDL_NAME(arts_init) },
|
||||
{ "arts_free", (void **)&SDL_NAME(arts_free) },
|
||||
{ "arts_play_stream", (void **)&SDL_NAME(arts_play_stream) },
|
||||
{ "arts_stream_set", (void **)&SDL_NAME(arts_stream_set) },
|
||||
{ "arts_stream_get", (void **)&SDL_NAME(arts_stream_get) },
|
||||
{ "arts_write", (void **)&SDL_NAME(arts_write) },
|
||||
{ "arts_close_stream", (void **)&SDL_NAME(arts_close_stream) },
|
||||
};
|
||||
|
||||
static void UnloadARTSLibrary()
|
||||
{
|
||||
if ( arts_loaded ) {
|
||||
SDL_UnloadObject(arts_handle);
|
||||
arts_handle = NULL;
|
||||
arts_loaded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int LoadARTSLibrary(void)
|
||||
{
|
||||
int i, retval = -1;
|
||||
|
||||
arts_handle = SDL_LoadObject(arts_library);
|
||||
if ( arts_handle ) {
|
||||
arts_loaded = 1;
|
||||
retval = 0;
|
||||
for ( i=0; i<SDL_TABLESIZE(arts_functions); ++i ) {
|
||||
*arts_functions[i].func = SDL_LoadFunction(arts_handle, arts_functions[i].name);
|
||||
if ( ! arts_functions[i].func ) {
|
||||
retval = -1;
|
||||
UnloadARTSLibrary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void UnloadARTSLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int LoadARTSLibrary(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ARTSC_DYNAMIC */
|
||||
|
||||
/* Audio driver bootstrap functions */
|
||||
|
||||
static int Audio_Available(void)
|
||||
{
|
||||
if(arts_init())
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
int available = 0;
|
||||
|
||||
if ( LoadARTSLibrary() < 0 ) {
|
||||
return available;
|
||||
}
|
||||
if ( SDL_NAME(arts_init)() == 0 ) {
|
||||
available = 1;
|
||||
SDL_NAME(arts_free)();
|
||||
}
|
||||
UnloadARTSLibrary();
|
||||
}
|
||||
|
||||
static void Audio_DeleteDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
free(device->hidden);
|
||||
free(device);
|
||||
UnloadARTSLibrary();
|
||||
}
|
||||
|
||||
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
|
||||
|
@ -74,6 +157,7 @@ static SDL_AudioDevice *Audio_CreateDevice(int devindex)
|
|||
SDL_AudioDevice *this;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
LoadARTSLibrary();
|
||||
this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
|
||||
if ( this ) {
|
||||
memset(this, 0, (sizeof *this));
|
||||
|
@ -136,7 +220,7 @@ static void ARTSC_PlayAudio(_THIS)
|
|||
int written;
|
||||
|
||||
/* Write the audio data */
|
||||
written = arts_write(stream, mixbuf, mixlen);
|
||||
written = SDL_NAME(arts_write)(stream, mixbuf, mixlen);
|
||||
|
||||
/* If timer synchronization is enabled, set the next write frame */
|
||||
if ( frame_ticks ) {
|
||||
|
@ -164,9 +248,10 @@ static void ARTSC_CloseAudio(_THIS)
|
|||
mixbuf = NULL;
|
||||
}
|
||||
if ( stream ) {
|
||||
arts_close_stream(stream);
|
||||
SDL_NAME(arts_close_stream)(stream);
|
||||
stream = 0;
|
||||
}
|
||||
SDL_NAME(arts_free)();
|
||||
}
|
||||
|
||||
static int ARTSC_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
||||
|
@ -210,7 +295,11 @@ static int ARTSC_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
|||
}
|
||||
spec->format = test_format;
|
||||
|
||||
stream = arts_play_stream(spec->freq, bits, spec->channels, "SDL");
|
||||
if ( SDL_NAME(arts_init)() != 0 ) {
|
||||
SDL_SetError("Unable to initialize ARTS");
|
||||
return(-1);
|
||||
}
|
||||
stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL");
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
SDL_CalculateAudioSpec(spec);
|
||||
|
@ -224,12 +313,12 @@ static int ARTSC_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
|||
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
||||
|
||||
#ifdef ARTS_P_PACKET_SETTINGS
|
||||
arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
|
||||
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
|
||||
#else
|
||||
arts_stream_set(stream, ARTS_P_PACKET_SIZE, frag_spec&0xffff);
|
||||
arts_stream_set(stream, ARTS_P_PACKET_COUNT, frag_spec>>16);
|
||||
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SIZE, frag_spec&0xffff);
|
||||
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_COUNT, frag_spec>>16);
|
||||
#endif
|
||||
spec->size = arts_stream_get(stream, ARTS_P_PACKET_SIZE);
|
||||
spec->size = SDL_NAME(arts_stream_get)(stream, ARTS_P_PACKET_SIZE);
|
||||
|
||||
/* Allocate mixing buffer */
|
||||
mixlen = spec->size;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
noinst_LTLIBRARIES = libaudio_esd.la
|
||||
libaudio_esd_la_SOURCES = $(SRCS)
|
||||
|
||||
esd_lib = \"@esd_lib@\"
|
||||
|
||||
# The SDL audio driver sources
|
||||
SRCS = SDL_esdaudio.c \
|
||||
SDL_esdaudio.h
|
||||
|
|
|
@ -46,6 +46,13 @@ static char rcsid =
|
|||
#include "SDL_audiodev_c.h"
|
||||
#include "SDL_esdaudio.h"
|
||||
|
||||
#ifdef ESD_DYNAMIC
|
||||
#include "SDL_name.h"
|
||||
#include "SDL_loadso.h"
|
||||
#else
|
||||
#define SDL_NAME(X) X
|
||||
#endif
|
||||
|
||||
/* The tag name used by ESD audio */
|
||||
#define ESD_DRIVER_NAME "esd"
|
||||
|
||||
|
@ -56,6 +63,68 @@ static void ESD_PlayAudio(_THIS);
|
|||
static Uint8 *ESD_GetAudioBuf(_THIS);
|
||||
static void ESD_CloseAudio(_THIS);
|
||||
|
||||
#ifdef ESD_DYNAMIC
|
||||
|
||||
static const char *esd_library = ESD_DYNAMIC;
|
||||
static void *esd_handle = NULL;
|
||||
static int esd_loaded = 0;
|
||||
|
||||
static int (*SDL_NAME(esd_open_sound))( const char *host );
|
||||
static int (*SDL_NAME(esd_close))( int esd );
|
||||
static int (*SDL_NAME(esd_play_stream))( esd_format_t format, int rate,
|
||||
const char *host, const char *name );
|
||||
static struct {
|
||||
const char *name;
|
||||
void **func;
|
||||
} esd_functions[] = {
|
||||
{ "esd_open_sound", (void **)&SDL_NAME(esd_open_sound) },
|
||||
{ "esd_close", (void **)&SDL_NAME(esd_close) },
|
||||
{ "esd_play_stream", (void **)&SDL_NAME(esd_play_stream) },
|
||||
};
|
||||
|
||||
static void UnloadESDLibrary()
|
||||
{
|
||||
if ( esd_loaded ) {
|
||||
SDL_UnloadObject(esd_handle);
|
||||
esd_handle = NULL;
|
||||
esd_loaded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int LoadESDLibrary(void)
|
||||
{
|
||||
int i, retval = -1;
|
||||
|
||||
esd_handle = SDL_LoadObject(esd_library);
|
||||
if ( esd_handle ) {
|
||||
esd_loaded = 1;
|
||||
retval = 0;
|
||||
for ( i=0; i<SDL_TABLESIZE(esd_functions); ++i ) {
|
||||
*esd_functions[i].func = SDL_LoadFunction(esd_handle, esd_functions[i].name);
|
||||
if ( ! esd_functions[i].func ) {
|
||||
retval = -1;
|
||||
UnloadESDLibrary();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void UnloadESDLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int LoadESDLibrary(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ESD_DYNAMIC */
|
||||
|
||||
/* Audio driver bootstrap functions */
|
||||
|
||||
static int Audio_Available(void)
|
||||
|
@ -64,11 +133,15 @@ static int Audio_Available(void)
|
|||
int available;
|
||||
|
||||
available = 0;
|
||||
connection = esd_open_sound(NULL);
|
||||
if ( LoadESDLibrary() < 0 ) {
|
||||
return available;
|
||||
}
|
||||
connection = SDL_NAME(esd_open_sound)(NULL);
|
||||
if ( connection >= 0 ) {
|
||||
available = 1;
|
||||
esd_close(connection);
|
||||
SDL_NAME(esd_close)(connection);
|
||||
}
|
||||
UnloadESDLibrary();
|
||||
return(available);
|
||||
}
|
||||
|
||||
|
@ -76,6 +149,7 @@ static void Audio_DeleteDevice(SDL_AudioDevice *device)
|
|||
{
|
||||
free(device->hidden);
|
||||
free(device);
|
||||
UnloadESDLibrary();
|
||||
}
|
||||
|
||||
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
|
||||
|
@ -83,6 +157,7 @@ static SDL_AudioDevice *Audio_CreateDevice(int devindex)
|
|||
SDL_AudioDevice *this;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
LoadESDLibrary();
|
||||
this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
|
||||
if ( this ) {
|
||||
memset(this, 0, (sizeof *this));
|
||||
|
@ -174,7 +249,7 @@ static void ESD_CloseAudio(_THIS)
|
|||
mixbuf = NULL;
|
||||
}
|
||||
if ( audio_fd >= 0 ) {
|
||||
close(audio_fd);
|
||||
SDL_NAME(esd_close)(audio_fd);
|
||||
audio_fd = -1;
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +306,7 @@ static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
|||
#endif
|
||||
|
||||
/* Open a connection to the ESD audio server */
|
||||
audio_fd = esd_play_stream(format, spec->freq, NULL, get_progname());
|
||||
audio_fd = SDL_NAME(esd_play_stream)(format, spec->freq, NULL, get_progname());
|
||||
if ( audio_fd < 0 ) {
|
||||
SDL_SetError("Couldn't open ESD connection");
|
||||
return(-1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue