changeset 94:ae6e6b73333f

Cleaned up the OpenBSD port, thanks to Peter Valchev
author Sam Lantinga <slouken@lokigames.com>
date Sun, 08 Jul 2001 09:00:06 +0000
parents fc774f445e10
children d84a06e0c358
files configure.in include/SDL_syswm.h src/audio/SDL_audio.c src/audio/SDL_audiodev.c src/audio/SDL_sysaudio.h src/audio/dma/SDL_dmaaudio.c src/audio/dsp/SDL_dspaudio.c src/audio/openbsd/SDL_openbsdaudio.c src/thread/linux/SDL_syssem.c
diffstat 9 files changed, 153 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sat Jul 07 23:27:29 2001 +0000
+++ b/configure.in	Sun Jul 08 09:00:06 2001 +0000
@@ -245,13 +245,25 @@
     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 <sys/soundcard.h>
-        ],[
-          int arg = SNDCTL_DSP_SETFRAGMENT;
-        ],[
-        have_oss=yes
-        ])
+        if test x$have_oss != xyes; then
+            AC_TRY_COMPILE([
+              #include <sys/soundcard.h>
+            ],[
+              int arg = SNDCTL_DSP_SETFRAGMENT;
+            ],[
+            have_oss=yes
+            ])
+        fi
+        if test x$have_oss != xyes; then
+            AC_TRY_COMPILE([
+              #include <soundcard.h>
+            ],[
+              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 @@
 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 @@
                 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 <pthread.h>
+                  #include <semaphore.h>
+                ],[
+                ],[
+                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 @@
             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 @@
             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 @@
             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 @@
         ARCH=openbsd
         CheckDummyVideo
         CheckDiskAudio
+        CheckOPENBSDAUDIO
         CheckNASM
         CheckOSS
         CheckARTSC
@@ -1385,7 +1412,15 @@
         # 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 @@
             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 @@
         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 @@
                 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 @@
             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 @@
 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
--- a/include/SDL_syswm.h	Sat Jul 07 23:27:29 2001 +0000
+++ b/include/SDL_syswm.h	Sun Jul 08 09:00:06 2001 +0000
@@ -49,7 +49,7 @@
 #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 <X11/Xlib.h>
--- a/src/audio/SDL_audio.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/SDL_audio.c	Sun Jul 08 09:00:06 2001 +0000
@@ -40,6 +40,9 @@
 
 /* Available audio drivers */
 static AudioBootStrap *bootstrap[] = {
+#ifdef OBSD_SUPPORT
+	&OBSD_bootstrap,
+#endif
 #ifdef OSS_SUPPORT
 	&DSP_bootstrap,
 	&DMA_bootstrap,
@@ -47,9 +50,6 @@
 #ifdef ALSA_SUPPORT
 	&ALSA_bootstrap,
 #endif
-#ifdef __OpenBSD__
-	&OBSD_bootstrap,
-#endif
 #if (defined(unix) && !defined(__CYGWIN32__)) && \
     !defined(OSS_SUPPORT) && !defined(ALSA_SUPPORT)
 	&AUDIO_bootstrap,
--- a/src/audio/SDL_audiodev.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/SDL_audiodev.c	Sun Jul 08 09:00:06 2001 +0000
@@ -39,7 +39,11 @@
 #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"
--- a/src/audio/SDL_sysaudio.h	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/SDL_sysaudio.h	Sun Jul 08 09:00:06 2001 +0000
@@ -99,6 +99,9 @@
 	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 @@
 #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;
--- a/src/audio/dma/SDL_dmaaudio.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/dma/SDL_dmaaudio.c	Sun Jul 08 09:00:06 2001 +0000
@@ -39,7 +39,13 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+#ifdef OSS_USE_SOUNDCARD_H
+/* This is installed on some systems */
+#include <soundcard.h>
+#else
+/* This is recommended by OSS */
 #include <sys/soundcard.h>
+#endif
 
 #ifndef MAP_FAILED
 #define MAP_FAILED	((Uint8 *)-1)
--- a/src/audio/dsp/SDL_dspaudio.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Sun Jul 08 09:00:06 2001 +0000
@@ -37,7 +37,13 @@
 #include <sys/time.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
+#ifdef OSS_USE_SOUNDCARD_H
+/* This is installed on some systems */
+#include <soundcard.h>
+#else
+/* This is recommended by OSS */
 #include <sys/soundcard.h>
+#endif
 
 #include "SDL_audio.h"
 #include "SDL_error.h"
--- a/src/audio/openbsd/SDL_openbsdaudio.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/audio/openbsd/SDL_openbsdaudio.c	Sun Jul 08 09:00:06 2001 +0000
@@ -140,83 +140,95 @@
 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;
-	}
-    }
+#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;
 
-#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 {
+		/* Use select() for audio synchronization */
+		fd_set fdset;
+		struct timeval timeout;
 
-	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);
+		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)";
-	    fprintf(stderr, "SDL: %s\n", message);
-	    this->enabled = 0;
-	    audio_fd = -1;
+		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
 	}
-    }
 #endif /* !USE_BLOCKING_WRITES */
-
 }
 
 static void
 OBSD_PlayAudio(_THIS)
 {
-    int written;
+	int written, p=0;
 
-    /* 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)));
+	/* 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;
+		}
 
-#ifdef USE_TIMER_SYNC
-    if(frame_ticks)
-	next_frame += frame_ticks;
-#endif
+		if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
+			SDL_Delay(1);	/* Let a little CPU time go by */
+		}
+	} while ( p < written );
 
-    /* If we couldn't write, assume fatal error for now */
-    if(written < 0)
-	this->enabled = 0;
+	/* 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
 }
 
--- a/src/thread/linux/SDL_syssem.c	Sat Jul 07 23:27:29 2001 +0000
+++ b/src/thread/linux/SDL_syssem.c	Sun Jul 08 09:00:06 2001 +0000
@@ -48,7 +48,7 @@
 #ifdef SDL_USE_PTHREADS
 
 #ifdef SDL_NO_PTHREAD_SEMAPHORES
-#include "generic/SDL_sem.c"
+#include "generic/SDL_syssem.c"
 #else
 
 #include <stdio.h>