Mercurial > sdl-ios-xcode
comparison src/audio/esd/SDL_esdaudio.c @ 294:d2d48e10f370
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.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 06 Mar 2002 05:20:11 +0000 |
parents | e8157fcb3114 |
children | f6ffac90895c |
comparison
equal
deleted
inserted
replaced
293:585a7e1285ae | 294:d2d48e10f370 |
---|---|
44 #include "SDL_audio_c.h" | 44 #include "SDL_audio_c.h" |
45 #include "SDL_timer.h" | 45 #include "SDL_timer.h" |
46 #include "SDL_audiodev_c.h" | 46 #include "SDL_audiodev_c.h" |
47 #include "SDL_esdaudio.h" | 47 #include "SDL_esdaudio.h" |
48 | 48 |
49 #ifdef ESD_DYNAMIC | |
50 #include "SDL_name.h" | |
51 #include "SDL_loadso.h" | |
52 #else | |
53 #define SDL_NAME(X) X | |
54 #endif | |
55 | |
49 /* The tag name used by ESD audio */ | 56 /* The tag name used by ESD audio */ |
50 #define ESD_DRIVER_NAME "esd" | 57 #define ESD_DRIVER_NAME "esd" |
51 | 58 |
52 /* Audio driver functions */ | 59 /* Audio driver functions */ |
53 static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec); | 60 static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec); |
54 static void ESD_WaitAudio(_THIS); | 61 static void ESD_WaitAudio(_THIS); |
55 static void ESD_PlayAudio(_THIS); | 62 static void ESD_PlayAudio(_THIS); |
56 static Uint8 *ESD_GetAudioBuf(_THIS); | 63 static Uint8 *ESD_GetAudioBuf(_THIS); |
57 static void ESD_CloseAudio(_THIS); | 64 static void ESD_CloseAudio(_THIS); |
58 | 65 |
66 #ifdef ESD_DYNAMIC | |
67 | |
68 static const char *esd_library = ESD_DYNAMIC; | |
69 static void *esd_handle = NULL; | |
70 static int esd_loaded = 0; | |
71 | |
72 static int (*SDL_NAME(esd_open_sound))( const char *host ); | |
73 static int (*SDL_NAME(esd_close))( int esd ); | |
74 static int (*SDL_NAME(esd_play_stream))( esd_format_t format, int rate, | |
75 const char *host, const char *name ); | |
76 static struct { | |
77 const char *name; | |
78 void **func; | |
79 } esd_functions[] = { | |
80 { "esd_open_sound", (void **)&SDL_NAME(esd_open_sound) }, | |
81 { "esd_close", (void **)&SDL_NAME(esd_close) }, | |
82 { "esd_play_stream", (void **)&SDL_NAME(esd_play_stream) }, | |
83 }; | |
84 | |
85 static void UnloadESDLibrary() | |
86 { | |
87 if ( esd_loaded ) { | |
88 SDL_UnloadObject(esd_handle); | |
89 esd_handle = NULL; | |
90 esd_loaded = 0; | |
91 } | |
92 } | |
93 | |
94 static int LoadESDLibrary(void) | |
95 { | |
96 int i, retval = -1; | |
97 | |
98 esd_handle = SDL_LoadObject(esd_library); | |
99 if ( esd_handle ) { | |
100 esd_loaded = 1; | |
101 retval = 0; | |
102 for ( i=0; i<SDL_TABLESIZE(esd_functions); ++i ) { | |
103 *esd_functions[i].func = SDL_LoadFunction(esd_handle, esd_functions[i].name); | |
104 if ( ! esd_functions[i].func ) { | |
105 retval = -1; | |
106 UnloadESDLibrary(); | |
107 break; | |
108 } | |
109 } | |
110 } | |
111 return retval; | |
112 } | |
113 | |
114 #else | |
115 | |
116 static void UnloadESDLibrary() | |
117 { | |
118 return; | |
119 } | |
120 | |
121 static int LoadESDLibrary(void) | |
122 { | |
123 return 0; | |
124 } | |
125 | |
126 #endif /* ESD_DYNAMIC */ | |
127 | |
59 /* Audio driver bootstrap functions */ | 128 /* Audio driver bootstrap functions */ |
60 | 129 |
61 static int Audio_Available(void) | 130 static int Audio_Available(void) |
62 { | 131 { |
63 int connection; | 132 int connection; |
64 int available; | 133 int available; |
65 | 134 |
66 available = 0; | 135 available = 0; |
67 connection = esd_open_sound(NULL); | 136 if ( LoadESDLibrary() < 0 ) { |
137 return available; | |
138 } | |
139 connection = SDL_NAME(esd_open_sound)(NULL); | |
68 if ( connection >= 0 ) { | 140 if ( connection >= 0 ) { |
69 available = 1; | 141 available = 1; |
70 esd_close(connection); | 142 SDL_NAME(esd_close)(connection); |
71 } | 143 } |
144 UnloadESDLibrary(); | |
72 return(available); | 145 return(available); |
73 } | 146 } |
74 | 147 |
75 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 148 static void Audio_DeleteDevice(SDL_AudioDevice *device) |
76 { | 149 { |
77 free(device->hidden); | 150 free(device->hidden); |
78 free(device); | 151 free(device); |
152 UnloadESDLibrary(); | |
79 } | 153 } |
80 | 154 |
81 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | 155 static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
82 { | 156 { |
83 SDL_AudioDevice *this; | 157 SDL_AudioDevice *this; |
84 | 158 |
85 /* Initialize all variables that we clean on shutdown */ | 159 /* Initialize all variables that we clean on shutdown */ |
160 LoadESDLibrary(); | |
86 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | 161 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); |
87 if ( this ) { | 162 if ( this ) { |
88 memset(this, 0, (sizeof *this)); | 163 memset(this, 0, (sizeof *this)); |
89 this->hidden = (struct SDL_PrivateAudioData *) | 164 this->hidden = (struct SDL_PrivateAudioData *) |
90 malloc((sizeof *this->hidden)); | 165 malloc((sizeof *this->hidden)); |
172 if ( mixbuf != NULL ) { | 247 if ( mixbuf != NULL ) { |
173 SDL_FreeAudioMem(mixbuf); | 248 SDL_FreeAudioMem(mixbuf); |
174 mixbuf = NULL; | 249 mixbuf = NULL; |
175 } | 250 } |
176 if ( audio_fd >= 0 ) { | 251 if ( audio_fd >= 0 ) { |
177 close(audio_fd); | 252 SDL_NAME(esd_close)(audio_fd); |
178 audio_fd = -1; | 253 audio_fd = -1; |
179 } | 254 } |
180 } | 255 } |
181 | 256 |
182 /* Try to get the name of the program */ | 257 /* Try to get the name of the program */ |
229 #if 0 | 304 #if 0 |
230 spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ | 305 spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */ |
231 #endif | 306 #endif |
232 | 307 |
233 /* Open a connection to the ESD audio server */ | 308 /* Open a connection to the ESD audio server */ |
234 audio_fd = esd_play_stream(format, spec->freq, NULL, get_progname()); | 309 audio_fd = SDL_NAME(esd_play_stream)(format, spec->freq, NULL, get_progname()); |
235 if ( audio_fd < 0 ) { | 310 if ( audio_fd < 0 ) { |
236 SDL_SetError("Couldn't open ESD connection"); | 311 SDL_SetError("Couldn't open ESD connection"); |
237 return(-1); | 312 return(-1); |
238 } | 313 } |
239 | 314 |