From 6c6393c4865fce2a4b03952128db6eb22c9579a4 Mon Sep 17 00:00:00 2001 From: Shawn Walker Date: Mon, 25 Feb 2013 22:46:21 +0000 Subject: [PATCH] Fix pulseaudio dynamic linking for Solaris builds. Fix Solaris Studio compilation errors. Fix sunaudio backend for SDL2. --- configure.in | 8 + src/audio/sun/SDL_sunaudio.c | 293 ++++++++++++++++------------------- src/audio/sun/SDL_sunaudio.h | 10 -- src/video/SDL_blit_0.c | 12 +- src/video/SDL_blit_1.c | 10 +- src/video/x11/edid.h | 4 - 6 files changed, 154 insertions(+), 183 deletions(-) diff --git a/configure.in b/configure.in index 6f0a900d5..9a0b7e1a9 100644 --- a/configure.in +++ b/configure.in @@ -794,6 +794,14 @@ AC_HELP_STRING([--enable-pulseaudio-shared], [dynamically load PulseAudio suppor test x$enable_pulseaudio_shared = xyes && test x$pulseaudio_lib != x; then echo "-- dynamic libpulse-simple -> $pulseaudio_lib" AC_DEFINE_UNQUOTED(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC, "$pulseaudio_lib", [ ]) + + case "$host" in + # On Solaris, pulseaudio must be linked deferred explicitly + # to prevent undefined symbol failures. + *-*-solaris*) + PULSEAUDIO_LIBS=`echo $PULSEAUDIO_LIBS | sed 's/\-l/-Wl,-l/g'` + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-zdeferred $PULSEAUDIO_LIBS -Wl,-znodeferred" + esac else EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PULSEAUDIO_LIBS" fi diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index d7ffbdb41..2d643b503 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -22,11 +22,6 @@ #if SDL_AUDIO_DRIVER_SUNAUDIO -/* I'm gambling no one uses this audio backend...we'll see who emails. :) */ -#error this code has not been updated for SDL 1.3. -#error if no one emails icculus at icculus.org and tells him that this -#error code is needed, this audio backend will eventually be removed from SDL. - /* Allow access to a raw mixing buffer */ #include @@ -51,84 +46,21 @@ #include "SDL_sunaudio.h" /* Open the audio device for playback, and don't block if busy */ -#define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) #if defined(AUDIO_GETINFO) && !defined(AUDIO_GETBUFINFO) #define AUDIO_GETBUFINFO AUDIO_GETINFO #endif /* Audio driver functions */ -static int DSP_OpenAudio(_THIS, SDL_AudioSpec * spec); -static void DSP_WaitAudio(_THIS); -static void DSP_PlayAudio(_THIS); -static Uint8 *DSP_GetAudioBuf(_THIS); -static void DSP_CloseAudio(_THIS); - static Uint8 snd2au(int sample); /* Audio driver bootstrap functions */ - -static int -Audio_Available(void) -{ - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 1); - if (fd >= 0) { - available = 1; - close(fd); - } - return (available); -} - static void -Audio_DeleteDevice(SDL_AudioDevice * device) +SUNAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn) { - SDL_free(device->hidden); - SDL_free(device); + SDL_EnumUnixAudioDevices(iscapture, 1, (int (*)(int fd)) NULL, addfn); } -static SDL_AudioDevice * -Audio_CreateDevice(int devindex) -{ - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); - if (this) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory(); - if (this) { - SDL_free(this); - } - return (0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DSP_OpenAudio; - this->WaitAudio = DSP_WaitAudio; - this->PlayAudio = DSP_PlayAudio; - this->GetAudioBuf = DSP_GetAudioBuf; - this->CloseAudio = DSP_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; -} - -AudioBootStrap SUNAUDIO_bootstrap = { - "audio", "UNIX /dev/audio interface", - Audio_Available, Audio_CreateDevice, 0 -}; - #ifdef DEBUG_AUDIO void CheckUnderflow(_THIS) @@ -137,29 +69,29 @@ CheckUnderflow(_THIS) audio_info_t info; int left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (written && (left == 0)) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (this->hidden->written && (left == 0)) { fprintf(stderr, "audio underflow!\n"); } #endif } #endif -void -DSP_WaitAudio(_THIS) +static void +SUNAUDIO_WaitDevice(_THIS) { #ifdef AUDIO_GETBUFINFO #define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */ audio_info_t info; Sint32 left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (left > fragsize) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (left > this->hidden->fragsize) { Sint32 sleepy; - sleepy = ((left - fragsize) / frequency); + sleepy = ((left - this->hidden->fragsize) / this->hidden->frequency); sleepy -= SLEEP_FUDGE; if (sleepy > 0) { SDL_Delay(sleepy); @@ -169,30 +101,30 @@ DSP_WaitAudio(_THIS) fd_set fdset; FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - select(audio_fd + 1, NULL, &fdset, NULL, NULL); + FD_SET(this->hidden->audio_fd, &fdset); + select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, NULL); #endif } -void -DSP_PlayAudio(_THIS) +static void +SUNAUDIO_PlayDevice(_THIS) { /* Write the audio data */ - if (ulaw_only) { + if (this->hidden->ulaw_only) { /* Assuming that this->spec.freq >= 8000 Hz */ int accum, incr, pos; Uint8 *aubuf; accum = 0; incr = this->spec.freq / 8; - aubuf = ulaw_buf; - switch (audio_fmt & 0xFF) { + aubuf = this->hidden->ulaw_buf; + switch (this->hidden->audio_fmt & 0xFF) { case 8: { Uint8 *sndbuf; - sndbuf = mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au((0x80 - *sndbuf) * 64); accum += incr; while (accum > 0) { @@ -207,8 +139,8 @@ DSP_PlayAudio(_THIS) { Sint16 *sndbuf; - sndbuf = (Sint16 *) mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = (Sint16 *) this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au(*sndbuf / 4); accum += incr; while (accum > 0) { @@ -223,63 +155,96 @@ DSP_PlayAudio(_THIS) #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, ulaw_buf, fragsize) < 0) { + if (write(this->hidden->audio_fd, this->hidden->ulaw_buf, + this->hidden->fragsize) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } else { #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, mixbuf, this->spec.size) < 0) { + if (write(this->hidden->audio_fd, this->hidden->mixbuf, + this->spec.size) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } } -Uint8 * -DSP_GetAudioBuf(_THIS) +static Uint8 * +SUNAUDIO_GetDeviceBuf(_THIS) { - return (mixbuf); + return (this->hidden->mixbuf); } -void -DSP_CloseAudio(_THIS) +static void +SUNAUDIO_CloseDevice(_THIS) { - if (mixbuf != NULL) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if (ulaw_buf != NULL) { - SDL_free(ulaw_buf); - ulaw_buf = NULL; + if (this->hidden != NULL) { + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem(this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } + if (this->hidden->ulaw_buf != NULL) { + SDL_free(this->hidden->ulaw_buf); + this->hidden->ulaw_buf = NULL; + } + if (this->hidden->audio_fd >= 0) { + close(this->hidden->audio_fd); + this->hidden->audio_fd = -1; + } + SDL_free(this->hidden); + this->hidden = NULL; } - close(audio_fd); } -int -DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) +static int +SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { - char audiodev[1024]; + const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT); + SDL_AudioFormat format = 0; + audio_info_t info; + + /* We don't care what the devname is...we'll try to open anything. */ + /* ...but default to first name in the list... */ + if (devname == NULL) { + devname = SDL_GetAudioDeviceName(0, iscapture); + if (devname == NULL) { + SDL_SetError("No such audio device"); + return 0; + } + } + + /* Initialize all variables that we clean on shutdown */ + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + if (this->hidden == NULL) { + SDL_OutOfMemory(); + return 0; + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Open the audio device */ + this->hidden->audio_fd = open(devname, flags, 0); + if (this->hidden->audio_fd < 0) { + SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); + return 0; + } + #ifdef AUDIO_SETINFO int enc; #endif - int desired_freq = spec->freq; - - /* Initialize our freeable variables, in case we fail */ - audio_fd = -1; - mixbuf = NULL; - ulaw_buf = NULL; + int desired_freq = this->spec.freq; /* Determine the audio parameters from the AudioSpec */ - switch (SDL_AUDIO_BITSIZE(spec->format)) { + switch (SDL_AUDIO_BITSIZE(this->spec.format)) { case 8: { /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; + this->spec.format = AUDIO_U8; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR8; #endif @@ -288,7 +253,7 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case 16: { /* Signed 16 bit audio data */ - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR; #endif @@ -302,40 +267,33 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) return (-1); } } - audio_fmt = spec->format; - - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 1); - if (audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return (-1); - } + this->hidden->audio_fmt = this->spec.format; - ulaw_only = 0; /* modern Suns do support linear audio */ + this->hidden->ulaw_only = 0; /* modern Suns do support linear audio */ #ifdef AUDIO_SETINFO for (;;) { audio_info_t info; AUDIO_INITINFO(&info); /* init all fields to "no change" */ /* Try to set the requested settings */ - info.play.sample_rate = spec->freq; - info.play.channels = spec->channels; + info.play.sample_rate = this->spec.freq; + info.play.channels = this->spec.channels; info.play.precision = (enc == AUDIO_ENCODING_ULAW) - ? 8 : spec->format & 0xff; + ? 8 : this->spec.format & 0xff; info.play.encoding = enc; - if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) { + if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) { /* Check to be sure we got what we wanted */ - if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { + if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) { SDL_SetError("Error getting audio parameters: %s", strerror(errno)); return -1; } if (info.play.encoding == enc - && info.play.precision == (spec->format & 0xff) - && info.play.channels == spec->channels) { + && info.play.precision == (this->spec.format & 0xff) + && info.play.channels == this->spec.channels) { /* Yow! All seems to be well! */ - spec->freq = info.play.sample_rate; + this->spec.freq = info.play.sample_rate; break; } } @@ -344,16 +302,16 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case AUDIO_ENCODING_LINEAR8: /* unsigned 8bit apparently not supported here */ enc = AUDIO_ENCODING_LINEAR; - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; break; /* try again */ case AUDIO_ENCODING_LINEAR: /* linear 16bit didn't work either, resort to µ-law */ enc = AUDIO_ENCODING_ULAW; - spec->channels = 1; - spec->freq = 8000; - spec->format = AUDIO_U8; - ulaw_only = 1; + this->spec.channels = 1; + this->spec.freq = 8000; + this->spec.format = AUDIO_U8; + this->hidden->ulaw_only = 1; break; default: @@ -364,43 +322,44 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) } } #endif /* AUDIO_SETINFO */ - written = 0; + this->hidden->written = 0; /* We can actually convert on-the-fly to U-Law */ - if (ulaw_only) { - spec->freq = desired_freq; - fragsize = (spec->samples * 1000) / (spec->freq / 8); - frequency = 8; - ulaw_buf = (Uint8 *) SDL_malloc(fragsize); - if (ulaw_buf == NULL) { + if (this->hidden->ulaw_only) { + this->spec.freq = desired_freq; + this->hidden->fragsize = (this->spec.samples * 1000) / + (this->spec.freq / 8); + this->hidden->frequency = 8; + this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize); + if (this->hidden->ulaw_buf == NULL) { SDL_OutOfMemory(); return (-1); } - spec->channels = 1; + this->spec.channels = 1; } else { - fragsize = spec->samples; - frequency = spec->freq / 1000; + this->hidden->fragsize = this->spec.samples; + this->hidden->frequency = this->spec.freq / 1000; } #ifdef DEBUG_AUDIO fprintf(stderr, "Audio device %s U-Law only\n", - ulaw_only ? "is" : "is not"); + this->hidden->ulaw_only ? "is" : "is not"); fprintf(stderr, "format=0x%x chan=%d freq=%d\n", - spec->format, spec->channels, spec->freq); + this->spec.format, this->spec.channels, this->spec.freq); #endif /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec(&this->spec); /* Allocate mixing buffer */ - mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); - if (mixbuf == NULL) { + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size); + if (this->hidden->mixbuf == NULL) { SDL_OutOfMemory(); return (-1); } - SDL_memset(mixbuf, spec->silence, spec->size); + SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return (0); + return (1); } /************************************************************************/ @@ -456,6 +415,24 @@ snd2au(int sample) return (mask & sample); } +static int +SUNAUDIO_Init(SDL_AudioDriverImpl * impl) +{ + /* Set the function pointers */ + impl->DetectDevices = SUNAUDIO_DetectDevices; + impl->OpenDevice = SUNAUDIO_OpenDevice; + impl->PlayDevice = SUNAUDIO_PlayDevice; + impl->WaitDevice = SUNAUDIO_WaitDevice; + impl->GetDeviceBuf = SUNAUDIO_GetDeviceBuf; + impl->CloseDevice = SUNAUDIO_CloseDevice; + + return 1; /* this audio target is available. */ +} + +AudioBootStrap SUNAUDIO_bootstrap = { + "audio", "UNIX /dev/audio interface", SUNAUDIO_Init, 0 +}; + #endif /* SDL_AUDIO_DRIVER_SUNAUDIO */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/sun/SDL_sunaudio.h b/src/audio/sun/SDL_sunaudio.h index 67b01dc1d..1f2c0b4f2 100644 --- a/src/audio/sun/SDL_sunaudio.h +++ b/src/audio/sun/SDL_sunaudio.h @@ -42,16 +42,6 @@ struct SDL_PrivateAudioData int frequency; /* The audio frequency in KHz */ }; -/* Old variable names */ -#define audio_fd (this->hidden->audio_fd) -#define audio_fmt (this->hidden->audio_fmt) -#define mixbuf (this->hidden->mixbuf) -#define ulaw_only (this->hidden->ulaw_only) -#define ulaw_buf (this->hidden->ulaw_buf) -#define written (this->hidden->written) -#define fragsize (this->hidden->fragsize) -#define frequency (this->hidden->frequency) - #endif /* _SDL_sunaudio_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index 54e6b8061..12cf8607b 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -443,11 +443,11 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc bitmap_blit[] = { - NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 + (SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; static const SDL_BlitFunc colorkey_blit[] = { - NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key + (SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; SDL_BlitFunc @@ -457,7 +457,7 @@ SDL_CalculateBlit0(SDL_Surface * surface) if (surface->format->BitsPerPixel != 1) { /* We don't support sub 8-bit packed pixel modes */ - return NULL; + return (SDL_BlitFunc) NULL; } if (surface->map->dst->format->BitsPerPixel < 8) { which = 0; @@ -472,12 +472,12 @@ SDL_CalculateBlit0(SDL_Surface * surface) return colorkey_blit[which]; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlpha : NULL; + return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlphaKey : NULL; + return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 095660489..514edab01 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -511,11 +511,11 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc one_blit[] = { - NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 + (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; static const SDL_BlitFunc one_blitkey[] = { - NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key + (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; SDL_BlitFunc @@ -541,12 +541,12 @@ SDL_CalculateBlit1(SDL_Surface * surface) /* Supporting 8bpp->8bpp alpha is doable but requires lots of tables which consume space and takes time to precompute, so is better left to the user */ - return which >= 2 ? Blit1toNAlpha : NULL; + return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? Blit1toNAlphaKey : NULL; + return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/x11/edid.h b/src/video/x11/edid.h index c0c14e8f0..8c217eba2 100644 --- a/src/video/x11/edid.h +++ b/src/video/x11/edid.h @@ -39,10 +39,6 @@ struct Timing int frequency; }; -struct DisplayDescriptor -{ -}; - struct DetailedTiming { int pixel_clock;