21 #include "../../SDL_internal.h" 23 #if SDL_AUDIO_DRIVER_ESD 27 #include <sys/types.h> 35 #include "../SDL_audiomem.h" 36 #include "../SDL_audio_c.h" 39 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC 46 #ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC 48 static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
49 static void *esd_handle =
NULL;
51 static int (*
SDL_NAME(esd_open_sound)) (
const char *host);
52 static int (*
SDL_NAME(esd_close)) (
int esd);
53 static int (*
SDL_NAME(esd_play_stream)) (esd_format_t
format,
int rate,
54 const char *host,
const char *
name);
56 #define SDL_ESD_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } 61 }
const esd_functions[] = {
62 SDL_ESD_SYM(esd_open_sound),
63 SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),
71 if (esd_handle !=
NULL) {
82 if (esd_handle ==
NULL) {
87 *esd_functions[
i].func =
89 if (!*esd_functions[i].
func) {
119 ESD_WaitDevice(
_THIS)
130 if (this->hidden->parent && (((++cnt) % 10) == 0)) {
131 if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
145 ESD_PlayDevice(
_THIS)
151 written = write(this->hidden->audio_fd,
152 this->hidden->mixbuf, this->hidden->mixlen);
153 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
156 }
while ((written < 0) &&
157 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
160 this->hidden->next_frame += this->hidden->frame_ticks;
169 ESD_GetDeviceBuf(
_THIS)
171 return (this->hidden->mixbuf);
175 ESD_CloseDevice(
_THIS)
177 if (this->hidden !=
NULL) {
179 this->hidden->mixbuf =
NULL;
180 if (this->hidden->audio_fd >= 0) {
181 SDL_NAME(esd_close) (this->hidden->audio_fd);
182 this->hidden->audio_fd = -1;
194 char *progname =
NULL;
197 static char temp[BUFSIZ];
200 fp = fopen(temp,
"r");
202 if (fgets(temp,
sizeof(temp) - 1, fp)) {
204 if (progname ==
NULL) {
207 progname = progname + 1;
218 ESD_OpenDevice(
_THIS,
void *handle,
const char *devname,
int iscapture)
220 esd_format_t format = (ESD_STREAM | ESD_PLAY);
227 if (this->hidden ==
NULL) {
230 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
231 this->hidden->audio_fd = -1;
238 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
241 switch (test_format) {
246 format |= ESD_BITS16;
255 ESD_CloseDevice(
this);
256 return SDL_SetError(
"Couldn't find any hardware audio formats");
262 format |= ESD_STEREO;
269 this->hidden->audio_fd =
273 if (this->hidden->audio_fd < 0) {
274 ESD_CloseDevice(
this);
280 this->hidden->frame_ticks =
282 this->hidden->next_frame =
SDL_GetTicks() + this->hidden->frame_ticks;
285 this->hidden->mixlen = this->
spec.
size;
287 if (this->hidden->mixbuf ==
NULL) {
288 ESD_CloseDevice(
this);
291 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
294 this->hidden->parent = getpid();
301 ESD_Deinitialize(
void)
309 if (LoadESDLibrary() < 0) {
318 if (connection < 0) {
320 SDL_SetError(
"ESD: esd_open_sound failed (no audio server?)");
340 "esd",
"Enlightened Sound Daemon", ESD_Init, 0
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
void(* PlayDevice)(_THIS)
void(* WaitDevice)(_THIS)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
GLuint const GLchar * name
SDL_AudioFormat SDL_NextAudioFormat(void)
int OnlyHasDefaultOutputDevice
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
uint8_t Uint8
An unsigned 8-bit integer type.
void(* Deinitialize)(void)
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
#define SDL_AllocAudioMem
int32_t Sint32
A signed 32-bit integer type.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
void(* CloseDevice)(_THIS)
Uint8 *(* GetDeviceBuf)(_THIS)
#define SDL_arraysize(array)
AudioBootStrap ESD_bootstrap
void * SDL_LoadFunction(void *handle, const char *name)