shithub: opus-tools

Download patch

ref: 064bb2176518117531e0032747128761a19e5439
parent: 0e1665104b189774fef617caa7355059a7306c67
author: Christian Weisgerber <[email protected]>
date: Thu Jul 12 12:12:42 EDT 2012

This uses the native sndio interface instead of the OSS compatibility
library.

--- a/Makefile.am
+++ b/Makefile.am
@@ -32,7 +32,7 @@
 opusenc_MANS = man/opusenc.1
 
 opusdec_SOURCES = src/opus_header.c src/wav_io.c src/wave_out.c src/opusdec.c src/resample.c src/diag_range.c
-opusdec_LDADD = $(OGG_LIBS) $(Opus_LIBS) $(OSS_LIBS) -lm
+opusdec_LDADD = $(OGG_LIBS) $(Opus_LIBS) -lm
 opusdec_MANS = man/opusdec.1
 
 opusinfo_SOURCES = src/opus_header.c src/opusinfo.c src/info_opus.c
--- a/configure.ac
+++ b/configure.ac
@@ -159,18 +159,17 @@
   HAVE_OSS=yes
   break
 ])
-if test x$HAVE_OSS != xyes; then
-  AC_MSG_WARN([OSS audio support not found -- no direct audio output in opusdec])
+
+dnl check for sndio
+HAVE_SNDIO=no
+AC_CHECK_LIB([sndio], [sio_open])
+if x$ac_cv_lib_sndio_sio_open = xyes; then
+  HAVE_SNDIO=yes
 fi
 
-dnl OpenBSD needs -lossaudio to use the oss interface
-OSS_LIBS=
-case "$host_os" in
-  openbsd*)
-    OSS_LIBS='-lossaudio'
-    ;;
-esac
-AC_SUBST(OSS_LIBS)
+if test x$HAVE_OSS != xyes && test x$HAVE_SNDIO != xyes; then
+  AC_MSG_WARN([Audio support not found -- no direct audio output in opusdec])
+fi
 
 
 dnl Enable stack-protector-all only on x86 where it's well supported.
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -69,7 +69,10 @@
 #define I64FORMAT "lld"
 #endif
 
-#if defined HAVE_SYS_SOUNDCARD_H || defined HAVE_MACHINE_SOUNDCARD_H || HAVE_SOUNDCARD_H
+#if defined HAVE_LIBSNDIO
+#include <sndio.h>
+
+#elif defined HAVE_SYS_SOUNDCARD_H || defined HAVE_MACHINE_SOUNDCARD_H || HAVE_SOUNDCARD_H
 #ifdef HAVE_SYS_SOUNDCARD_H
 # include <sys/soundcard.h>
 #elif HAVE_MACHINE_SOUNDCARD_H
@@ -112,6 +115,10 @@
                            ((buf[base+1]<<8)&0xff00)| \
                            (buf[base]&0xff))
 
+#ifdef HAVE_LIBSNDIO
+struct sio_hdl *hdl;
+#endif
+
 typedef struct shapestate shapestate;
 struct shapestate {
   float * b_buf;
@@ -316,6 +323,32 @@
         perror("Cannot open output");
         exit(1);
       }
+#elif defined HAVE_LIBSNDIO
+      struct sio_par par;
+
+      hdl = sio_open(NULL, SIO_PLAY, 0);
+      if (!hdl)
+      {
+         fprintf(stderr, "Cannot open sndio device\n");
+         exit(1);
+      }
+
+      sio_initpar(&par);
+      par.sig = 1;
+      par.bits = 16;
+      par.rate = rate;
+      par.pchan = *channels;
+
+      if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
+        par.sig != 1 || par.bits != 16 || par.rate != rate) {
+          fprintf(stderr, "could not set sndio parameters\n");
+          exit(1);
+      }
+      *channels = par.pchan;
+      if (!sio_start(hdl)) {
+          fprintf(stderr, "could not start sndio\n");
+          exit(1);
+      }
 #elif defined HAVE_SYS_AUDIOIO_H
       audio_info_t info;
       int audio_fd;
@@ -547,6 +580,12 @@
 #if defined WIN32 || defined _WIN32
        if(!file){
          ret=WIN_Play_Samples (out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
+         if(ret>0)ret/=sizeof(short)*channels;
+         else fprintf(stderr, "Error playing audio.\n");
+       }else
+#elif defined HAVE_LIBSNDIO
+       if(!file){
+         ret=sio_write (hdl, out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
          if(ret>0)ret/=sizeof(short)*channels;
          else fprintf(stderr, "Error playing audio.\n");
        }else