chiark / gitweb /
empeg integration
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 7 Oct 2007 12:12:45 +0000 (13:12 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 7 Oct 2007 12:12:45 +0000 (13:12 +0100)
clients/playrtp-oss.c
clients/playrtp.c
configure.ac

index 8a8f4c63569b76aa96d89ea2f6e06c447031d3aa..3c6312d41e38f03d1e4d716679b0dd92f25a2fd2 100644 (file)
  * USA
  */
 /** @file clients/playrtp-oss.c
  * USA
  */
 /** @file clients/playrtp-oss.c
- * @brief RTP player - OSS support
+ * @brief RTP player - OSS and empeg support
  */
 
 #include <config.h>
 
  */
 
 #include <config.h>
 
-#if HAVE_SYS_SOUNDCARD_H
+#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
 #include "types.h"
 
 #include <poll.h>
 #include <sys/ioctl.h>
 #include "types.h"
 
 #include <poll.h>
 #include <sys/ioctl.h>
+#if !EMPEG_HOST
 #include <sys/soundcard.h>
 #include <sys/soundcard.h>
+#endif
 #include <assert.h>
 #include <pthread.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
 #include <pthread.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
-#if HAVE_LINUX_EMPEG_H
-# include <linux/empeg.h>
-#endif
 
 #include "mem.h"
 #include "log.h"
 
 #include "mem.h"
 #include "log.h"
@@ -61,6 +60,16 @@ static int playrtp_oss_bufused;
 /** @brief Open and configure the OSS audio device */
 static void playrtp_oss_enable(void) {
   if(playrtp_oss_fd == -1) {
 /** @brief Open and configure the OSS audio device */
 static void playrtp_oss_enable(void) {
   if(playrtp_oss_fd == -1) {
+#if EMPEG_HOST
+    /* empeg audio driver only knows /dev/audio, only supports the equivalent
+     * of AFMT_S16_NE, has a fixed buffer size, and does not support the
+     * SNDCTL_ ioctls. */
+    if(!device)
+      device = "/dev/audio";
+    if((playrtp_oss_fd = open(device, O_WRONLY)) < 0)
+      fatal(errno, "error opening %s", device);
+    playrtp_oss_bufsize = 4608;
+#else
     int rate = 44100, stereo = 1, format = AFMT_S16_BE;
     if(!device) {
       if(access("/dev/dsp", W_OK) == 0)
     int rate = 44100, stereo = 1, format = AFMT_S16_BE;
     if(!device) {
       if(access("/dev/dsp", W_OK) == 0)
@@ -82,9 +91,10 @@ static void playrtp_oss_enable(void) {
       error(0, "asking for 44100Hz, got %dHz", rate);
     if(ioctl(playrtp_oss_fd, SNDCTL_DSP_GETBLKSIZE, &playrtp_oss_bufsize) < 0)
       fatal(errno, "ioctl SNDCTL_DSP_GETBLKSIZE");
       error(0, "asking for 44100Hz, got %dHz", rate);
     if(ioctl(playrtp_oss_fd, SNDCTL_DSP_GETBLKSIZE, &playrtp_oss_bufsize) < 0)
       fatal(errno, "ioctl SNDCTL_DSP_GETBLKSIZE");
+    info("OSS buffer size %d", playrtp_oss_bufsize);
+#endif
     playrtp_oss_buffer = xmalloc(playrtp_oss_bufsize);
     playrtp_oss_bufused = 0;
     playrtp_oss_buffer = xmalloc(playrtp_oss_bufsize);
     playrtp_oss_bufused = 0;
-    info("OSS buffer size %d", playrtp_oss_bufsize);
     nonblock(playrtp_oss_fd);
   }
 }
     nonblock(playrtp_oss_fd);
   }
 }
@@ -100,6 +110,16 @@ static int playrtp_oss_flush(void) {
   /* 0 out the unused portion of the buffer */
   memset(playrtp_oss_buffer + playrtp_oss_bufused, 0,
          playrtp_oss_bufsize - playrtp_oss_bufused);
   /* 0 out the unused portion of the buffer */
   memset(playrtp_oss_buffer + playrtp_oss_bufused, 0,
          playrtp_oss_bufsize - playrtp_oss_bufused);
+#if EMPEG_HOST 
+  /* empeg audio driver insists on native-endian samples */
+  {
+    uint16_t *ptr,
+      *const limit = (uint16_t *)(playrtp_oss_buffer + playrtp_oss_bufused);
+
+    for(ptr = (uint16_t *)playrtp_oss_buffer; ptr < limit; ++ptr)
+      *ptr = ntohs(*ptr);
+  }
+#endif
   for(;;) {
     nbyteswritten = write(playrtp_oss_fd,
                           playrtp_oss_buffer, playrtp_oss_bufsize);
   for(;;) {
     nbyteswritten = write(playrtp_oss_fd,
                           playrtp_oss_buffer, playrtp_oss_bufsize);
@@ -143,8 +163,11 @@ static void playrtp_oss_wait(void) {
  */
 static void playrtp_oss_disable(int hard) {
   if(hard) {
  */
 static void playrtp_oss_disable(int hard) {
   if(hard) {
+#if !EMPEG_HOST
+    /* No SNDCTL_DSP_ ioctls on empeg */
     if(ioctl(playrtp_oss_fd, SNDCTL_DSP_RESET, 0) < 0)
       error(errno, "ioctl SNDCTL_DSP_RESET");
     if(ioctl(playrtp_oss_fd, SNDCTL_DSP_RESET, 0) < 0)
       error(errno, "ioctl SNDCTL_DSP_RESET");
+#endif
   } else
     playrtp_oss_flush();
   xclose(playrtp_oss_fd);
   } else
     playrtp_oss_flush();
   xclose(playrtp_oss_fd);
index 2a4dc86c335fd16472e913791d106932e907aeda..cac7dcc3c53ddbc5c34c8afccbc6c88bf884ffa6 100644 (file)
@@ -163,7 +163,7 @@ pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
 
 #if HAVE_ALSA_ASOUNDLIB_H
 # define DEFAULT_BACKEND playrtp_alsa
 
 #if HAVE_ALSA_ASOUNDLIB_H
 # define DEFAULT_BACKEND playrtp_alsa
-#elif HAVE_SYS_SOUNDCARD_H
+#elif HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
 # define DEFAULT_BACKEND playrtp_oss
 #elif HAVE_COREAUDIO_AUDIOHARDWARE_H
 # define DEFAULT_BACKEND playrtp_coreaudio
 # define DEFAULT_BACKEND playrtp_oss
 #elif HAVE_COREAUDIO_AUDIOHARDWARE_H
 # define DEFAULT_BACKEND playrtp_coreaudio
@@ -186,7 +186,7 @@ static const struct option options[] = {
   { "buffer", required_argument, 0, 'b' },
   { "rcvbuf", required_argument, 0, 'R' },
   { "multicast", required_argument, 0, 'M' },
   { "buffer", required_argument, 0, 'b' },
   { "rcvbuf", required_argument, 0, 'R' },
   { "multicast", required_argument, 0, 'M' },
-#if HAVE_SYS_SOUNDCARD_H
+#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
   { "oss", no_argument, 0, 'o' },
 #endif
 #if HAVE_ALSA_ASOUNDLIB_H
   { "oss", no_argument, 0, 'o' },
 #endif
 #if HAVE_ALSA_ASOUNDLIB_H
@@ -410,7 +410,7 @@ static void help(void) {
 #if HAVE_ALSA_ASOUNDLIB_H
           "  --alsa, -a              Use ALSA to play audio\n"
 #endif
 #if HAVE_ALSA_ASOUNDLIB_H
           "  --alsa, -a              Use ALSA to play audio\n"
 #endif
-#if HAVE_SYS_SOUNDCARD_H
+#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
           "  --oss, -o               Use OSS to play audio\n"
 #endif
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
           "  --oss, -o               Use OSS to play audio\n"
 #endif
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
@@ -469,7 +469,7 @@ int main(int argc, char **argv) {
 #if HAVE_ALSA_ASOUNDLIB_H
     case 'a': backend = playrtp_alsa; break;
 #endif
 #if HAVE_ALSA_ASOUNDLIB_H
     case 'a': backend = playrtp_alsa; break;
 #endif
-#if HAVE_SYS_SOUNDCARD_H      
+#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
     case 'o': backend = playrtp_oss; break;
 #endif
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H      
     case 'o': backend = playrtp_oss; break;
 #endif
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H      
index 32eaeaffa987122d00a46a26b658d2ce9bffe6e7..0f9258ccd6a02c94885bea4699ce839989128322 100644 (file)
@@ -32,29 +32,40 @@ AC_CANONICAL_HOST
 want_gtk=yes
 want_python=yes
 
 want_gtk=yes
 want_python=yes
 
+# Checks for programs.
+AC_PROG_CC
+AC_SET_MAKE
+if test "x$GCC" = xyes; then
+  gcc_werror=-Werror
+else
+  gcc_werror=""
+fi
+
+AC_MSG_CHECKING([for a known target platform])
 case "$host" in
 case "$host" in
+*empeg* )
+  AC_DEFINE([EMPEG_HOST],[1],[define if host is an empeg car stereo])
+  # work around broken toolchain
+  AC_CHECK_LIB([gpg-error], [gpg_strerror])
+  want_server=no
+  AC_MSG_RESULT([empeg car stereo])
+ ;;
 *linux* | *Linux* )
   want_server=yes
 *linux* | *Linux* )
   want_server=yes
+  AC_MSG_RESULT([Linux])
   ;;
 *-apple-darwin* )
   want_server=no
   COREAUDIO="-framework CoreAudio"
   ;;
 *-apple-darwin* )
   want_server=no
   COREAUDIO="-framework CoreAudio"
+  AC_MSG_RESULT([Mac OS X])
   ;;
 * )
   want_server=no
   ;;
 * )
   want_server=no
+  AC_MSG_RESULT([unknown, winging it])
   ;;
 esac
 AC_SUBST([COREAUDIO])
 
   ;;
 esac
 AC_SUBST([COREAUDIO])
 
-# Checks for programs.
-AC_PROG_CC
-AC_SET_MAKE
-if test "x$GCC" = xyes; then
-  gcc_werror=-Werror
-else
-  gcc_werror=""
-fi
-
 AC_ARG_WITH([server],
            [AS_HELP_STRING([--without-server],
                            [do not build server])],
 AC_ARG_WITH([server],
            [AS_HELP_STRING([--without-server],
                            [do not build server])],
@@ -182,7 +193,7 @@ RJK_REQUIRE_PCRE_UTF8([-lpcre])
 
 # Checks for header files.
 RJK_FIND_GC_H
 
 # Checks for header files.
 RJK_FIND_GC_H
-AC_CHECK_HEADERS([inttypes.h CoreAudio/AudioHardware.h sys/soundcard.h alsa/asoundlib.h linux/empeg.h])
+AC_CHECK_HEADERS([inttypes.h CoreAudio/AudioHardware.h sys/soundcard.h alsa/asoundlib.h])
 # We don't bother checking very standard stuff
 # Compilation will fail if any of these headers are missing, so we
 # check for them here and fail early.
 # We don't bother checking very standard stuff
 # Compilation will fail if any of these headers are missing, so we
 # check for them here and fail early.