From 8417a33af959b193f0259bd88fb3b401f172ca35 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 8 Jul 2001 09:00:06 +0000 Subject: [PATCH] Cleaned up the OpenBSD port, thanks to Peter Valchev --- configure.in | 73 ++++++++++---- include/SDL_syswm.h | 2 +- src/audio/SDL_audio.c | 6 +- src/audio/SDL_audiodev.c | 6 +- src/audio/SDL_sysaudio.h | 6 +- src/audio/dma/SDL_dmaaudio.c | 6 ++ src/audio/dsp/SDL_dspaudio.c | 6 ++ src/audio/openbsd/SDL_openbsdaudio.c | 144 +++++++++++++++------------ src/thread/linux/SDL_syssem.c | 2 +- 9 files changed, 157 insertions(+), 94 deletions(-) diff --git a/configure.in b/configure.in index b2d92d49f..0676fc195 100644 --- a/configure.in +++ b/configure.in @@ -245,13 +245,25 @@ CheckOSS() if test x$enable_audio = xyes -a x$enable_oss = xyes; then AC_MSG_CHECKING(for OSS audio support) have_oss=no - AC_TRY_COMPILE([ - #include - ],[ - int arg = SNDCTL_DSP_SETFRAGMENT; - ],[ - have_oss=yes - ]) + if test x$have_oss != xyes; then + AC_TRY_COMPILE([ + #include + ],[ + int arg = SNDCTL_DSP_SETFRAGMENT; + ],[ + have_oss=yes + ]) + fi + if test x$have_oss != xyes; then + AC_TRY_COMPILE([ + #include + ],[ + int arg = SNDCTL_DSP_SETFRAGMENT; + ],[ + have_oss=yes + CFLAGS="$CFLAGS -DOSS_USE_SOUNDCARD_H" + ]) + fi AC_MSG_RESULT($have_oss) if test x$have_oss = xyes; then CFLAGS="$CFLAGS -DOSS_SUPPORT" @@ -286,10 +298,10 @@ dnl Check whether we want to use OpenBSD native audio or not CheckOPENBSDAUDIO() { AC_ARG_ENABLE(openbsdaudio, -[ --enable-openbsdaudio OpenBSD native audio support [default=no]], - , enable_openbsdaudio=no) +[ --enable-openbsdaudio OpenBSD native audio support [default=yes]], + , enable_openbsdaudio=yes) if test x$enable_audio = xyes -a x$enable_openbsdaudio = xyes; then - SYSTEM_LIBS="$SYSTEM_LIBS $ESD_LIBS" + CFLAGS="$CFLAGS -DOBSD_SUPPORT" AUDIO_SUBDIRS="$AUDIO_SUBDIRS openbsd" AUDIO_DRIVERS="$AUDIO_DRIVERS openbsd/libaudio_openbsd.la" fi @@ -994,6 +1006,20 @@ CheckPTHREAD() CFLAGS="$CFLAGS -DPTHREAD_NO_RECURSIVE_MUTEX" fi + # Check to see if pthread semaphore support is missing + if test x$enable_pthread_sem = xyes; then + AC_MSG_CHECKING(for pthread semaphores) + have_pthread_sem=no + AC_TRY_COMPILE([ + #include + #include + ],[ + ],[ + have_pthread_sem=yes + ]) + AC_MSG_RESULT($have_pthread_sem) + fi + # Check to see if this is broken glibc 2.0 pthreads case "$target" in *-*-linux*) @@ -1196,7 +1222,7 @@ case "$target" in fi COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c) COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) - if test x$use_pthreads = xyes -a x$enable_pthread_sem != xyes; then + if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1303,7 +1329,7 @@ case "$target" in COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h) - if test x$use_pthreads = xyes -a x$enable_pthread_sem != xyes; then + if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1353,7 +1379,7 @@ case "$target" in COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h) - if test x$use_pthreads = xyes -a x$enable_pthread_sem != xyes; then + if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1373,6 +1399,7 @@ case "$target" in ARCH=openbsd CheckDummyVideo CheckDiskAudio + CheckOPENBSDAUDIO CheckNASM CheckOSS CheckARTSC @@ -1385,7 +1412,15 @@ case "$target" in # Set up files for the main() stub COPY_ARCH_SRC(src/main, linux, SDL_main.c) # Set up files for the audio library - CheckOPENBSDAUDIO + # We use the OSS and native API's, not the Sun audio API + #if test x$enable_audio = xyes; then + # AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun" + # AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la" + #fi + # OpenBSD needs linking with ossaudio emulation library + if test x$have_oss = xyes; then + SYSTEM_LIBS="$SYSTEM_LIBS -lossaudio" + fi # Set up files for the joystick library # (No joystick support yet) if test x$enable_joystick = xyes; then @@ -1402,7 +1437,7 @@ case "$target" in COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h) - if test x$use_pthreads = xyes -a x$enable_pthread_sem != xyes; then + if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1528,7 +1563,7 @@ case "$target" in if test x$enable_audio = xyes; then AUDIO_SUBDIRS="$AUDIO_SUBDIRS dmedia" AUDIO_DRIVERS="$AUDIO_DRIVERS dmedia/libaudio_dmedia.la" - LIBS="$LIBS -laudio" + SYSTEM_LIBS="$SYSTEM_LIBS -laudio" fi # Set up files for the joystick library # (No joystick support yet) @@ -1548,7 +1583,7 @@ case "$target" in COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h) - if test x$enable_pthread_sem != xyes; then + if test x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1937,7 +1972,7 @@ case "$target" in COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c) COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h) - if test x$use_pthreads = xyes -a x$enable_pthread_sem != xyes; then + if test x$use_pthreads = xyes -a x$have_pthread_sem != xyes; then COPY_ARCH_SRC(src/thread, generic, SDL_syssem.c) else COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c) @@ -1989,7 +2024,7 @@ if test $ARCH = solaris; then fi if test $ARCH = openbsd; then - SDL_RLD_FLAGS="-L${X11BASE}/lib -Wl,-rpath,\${exec_prefix}/lib -Wl,-rpath,${X11BASE}/lib" + SDL_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib $SYSTEM_LIBS" fi dnl Output the video drivers we use diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index 34bb0c05b..082ba0efa 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -49,7 +49,7 @@ typedef struct SDL_SysWMinfo SDL_SysWMinfo; #else /* This is the structure for custom window manager events */ -#if (defined(unix) || defined(__unix__) || defined(_AIX)) && \ +#if (defined(unix) || defined(__unix__) || defined(_AIX) || defined(__OpenBSD__)) && \ (!defined(DISABLE_X11) && !defined(__CYGWIN32__)) /* AIX is unix, of course, but the native compiler CSet doesn't define unix */ #include diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index dd2ad84db..d7311c5bc 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -40,6 +40,9 @@ static char rcsid = /* Available audio drivers */ static AudioBootStrap *bootstrap[] = { +#ifdef OBSD_SUPPORT + &OBSD_bootstrap, +#endif #ifdef OSS_SUPPORT &DSP_bootstrap, &DMA_bootstrap, @@ -47,9 +50,6 @@ static AudioBootStrap *bootstrap[] = { #ifdef ALSA_SUPPORT &ALSA_bootstrap, #endif -#ifdef __OpenBSD__ - &OBSD_bootstrap, -#endif #if (defined(unix) && !defined(__CYGWIN32__)) && \ !defined(OSS_SUPPORT) && !defined(ALSA_SUPPORT) &AUDIO_bootstrap, diff --git a/src/audio/SDL_audiodev.c b/src/audio/SDL_audiodev.c index f035bad8d..47e2582cf 100644 --- a/src/audio/SDL_audiodev.c +++ b/src/audio/SDL_audiodev.c @@ -39,7 +39,11 @@ static char rcsid = #include "SDL_audiodev_c.h" #ifndef _PATH_DEV_DSP -#define _PATH_DEV_DSP "/dev/dsp" +#ifdef __OpenBSD__ +#define _PATH_DEV_DSP "/dev/audio" +#else +#define _PATH_DEV_DSP "/dev/dsp" +#endif #endif #ifndef _PATH_DEV_DSP24 #define _PATH_DEV_DSP24 "/dev/sound/dsp" diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 0bfc1ad2f..28a50de62 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -99,6 +99,9 @@ typedef struct AudioBootStrap { SDL_AudioDevice *(*create)(int devindex); } AudioBootStrap; +#ifdef OBSD_SUPPORT +extern AudioBootStrap OBSD_bootstrap; +#endif #ifdef OSS_SUPPORT extern AudioBootStrap DSP_bootstrap; extern AudioBootStrap DMA_bootstrap; @@ -106,9 +109,6 @@ extern AudioBootStrap DMA_bootstrap; #ifdef ALSA_SUPPORT extern AudioBootStrap ALSA_bootstrap; #endif -#ifdef __OpenBSD__ -extern AudioBootStrap OBSD_bootstrap; -#endif #if (defined(unix) && !defined(__CYGWIN32__)) && \ !defined(OSS_SUPPORT) && !defined(ALSA_SUPPORT) extern AudioBootStrap AUDIO_bootstrap; diff --git a/src/audio/dma/SDL_dmaaudio.c b/src/audio/dma/SDL_dmaaudio.c index 344abdeb4..dcee60512 100644 --- a/src/audio/dma/SDL_dmaaudio.c +++ b/src/audio/dma/SDL_dmaaudio.c @@ -39,7 +39,13 @@ static char rcsid = #include #include #include +#ifdef OSS_USE_SOUNDCARD_H +/* This is installed on some systems */ +#include +#else +/* This is recommended by OSS */ #include +#endif #ifndef MAP_FAILED #define MAP_FAILED ((Uint8 *)-1) diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index 46a7f103c..8c560d9fb 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -37,7 +37,13 @@ static char rcsid = #include #include #include +#ifdef OSS_USE_SOUNDCARD_H +/* This is installed on some systems */ +#include +#else +/* This is recommended by OSS */ #include +#endif #include "SDL_audio.h" #include "SDL_error.h" diff --git a/src/audio/openbsd/SDL_openbsdaudio.c b/src/audio/openbsd/SDL_openbsdaudio.c index eef205134..33fbd6df0 100644 --- a/src/audio/openbsd/SDL_openbsdaudio.c +++ b/src/audio/openbsd/SDL_openbsdaudio.c @@ -140,83 +140,95 @@ AudioBootStrap OBSD_bootstrap = { static void OBSD_WaitAudio(_THIS) { -#ifndef USE_BLOCKING_WRITES - fd_set fdset; - - /* Check to see if the thread-parent process is still alive */ - { - static int cnt = 0; - /* Note that this only works with thread implementations - that use a different process id for each thread. */ - if(parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ - if(kill(parent, 0) < 0) - this->enabled = 0; + /* Check to see if the thread-parent process is still alive */ + { static int cnt = 0; + /* Note that this only works with thread implementations + that use a different process id for each thread. + */ + if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ + if ( kill(parent, 0) < 0 ) { + this->enabled = 0; + } + } } - } - -#ifdef USE_TIMER_SYNC - /* See if we need to use timed audio synchronization */ - if(frame_ticks) - { - /* Use timer for general audio synchronization */ - Sint32 ticks; - ticks = ((Sint32)(next_frame - SDL_GetTicks())) - FUDGE_TICKS; - if(ticks > 0) - SDL_Delay(ticks); - } - else -#endif /* USE_TIMER_SYNC */ - { - /* Use select() for audio synchronization */ - struct timeval timeout; - FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - timeout.tv_sec = 10; - timeout.tv_usec = 0; - -#if defined(DEBUG_AUDIO_STREAM) && defined(DEBUG_AUDIO_STREAM) - OBSD_Status(this); +#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */ + /* See if we need to use timed audio synchronization */ + if ( frame_ticks ) { + /* Use timer for general audio synchronization */ + Sint32 ticks; + + ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS; + if ( ticks > 0 ) { + SDL_Delay(ticks); + } + } else { + /* Use select() for audio synchronization */ + fd_set fdset; + struct timeval timeout; + + FD_ZERO(&fdset); + FD_SET(audio_fd, &fdset); + timeout.tv_sec = 10; + timeout.tv_usec = 0; +#ifdef DEBUG_AUDIO + fprintf(stderr, "Waiting for audio to get ready\n"); +#endif + if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) { + const char *message = + "Audio timeout - buggy audio driver? (disabled)"; + /* In general we should never print to the screen, + but in this case we have no other way of letting + the user know what happened. + */ + fprintf(stderr, "SDL: %s\n", message); + this->enabled = 0; + /* Don't try to close - may hang */ + audio_fd = -1; +#ifdef DEBUG_AUDIO + fprintf(stderr, "Done disabling audio\n"); +#endif + } +#ifdef DEBUG_AUDIO + fprintf(stderr, "Ready!\n"); #endif - if(select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0) - { - const char *message = - "Audio timeout - buggy audio driver? (disabled)"; - fprintf(stderr, "SDL: %s\n", message); - this->enabled = 0; - audio_fd = -1; } - } #endif /* !USE_BLOCKING_WRITES */ - } static void OBSD_PlayAudio(_THIS) { - int written; - - /* Write the audio data, checking for EAGAIN on broken audio drivers */ - do - { - written = write(audio_fd, mixbuf, mixlen); - if((written < 0) && ((errno == 0) || (errno == EAGAIN))) - SDL_Delay(1); - } - while((written < 0) && - ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); - -#ifdef USE_TIMER_SYNC - if(frame_ticks) - next_frame += frame_ticks; -#endif - - /* If we couldn't write, assume fatal error for now */ - if(written < 0) - this->enabled = 0; + int written, p=0; + + /* Write the audio data, checking for EAGAIN on broken audio drivers */ + do { + written = write(audio_fd, &mixbuf[p], mixlen-p); + if (written>0) + p += written; + if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) + { + /* Non recoverable error has occurred. It should be reported!!! */ + perror("audio"); + break; + } + + if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) { + SDL_Delay(1); /* Let a little CPU time go by */ + } + } while ( p < written ); + + /* If timer synchronization is enabled, set the next write frame */ + if ( frame_ticks ) { + next_frame += frame_ticks; + } -#ifdef DEBUG_AUDIO_STREAM - fprintf(stderr, "Wrote %d bytes of audio data\n", written); + /* If we couldn't write, assume fatal error for now */ + if ( written < 0 ) { + this->enabled = 0; + } +#ifdef DEBUG_AUDIO + fprintf(stderr, "Wrote %d bytes of audio data\n", written); #endif } diff --git a/src/thread/linux/SDL_syssem.c b/src/thread/linux/SDL_syssem.c index b272abf00..aa29033da 100644 --- a/src/thread/linux/SDL_syssem.c +++ b/src/thread/linux/SDL_syssem.c @@ -48,7 +48,7 @@ static char rcsid = #ifdef SDL_USE_PTHREADS #ifdef SDL_NO_PTHREAD_SEMAPHORES -#include "generic/SDL_sem.c" +#include "generic/SDL_syssem.c" #else #include