Whitespace cleanup
[sxemacs] / src / media / media-sox.c
index 6d3482f..9904777 100644 (file)
@@ -29,11 +29,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 #include <errno.h>
 #include <string.h>
 
-/* 
+/*
 lisp.h defined UNUSED which also gets defined in some versions of SoX
 in an incompatible fashion.  We don't need that macro here...
 */
-#undef UNUSED 
+#undef UNUSED
 #include "media-sox.h"
 
 #define MYSELF MDRIVER_SOX
@@ -63,7 +63,7 @@ DEFINE_MEDIA_DRIVER_CUSTOM(media_sox,
 
 \f
 /* called from util.c::st_fail() */
-void cleanup(void) 
+void cleanup(void)
 {
 }
 
@@ -83,7 +83,7 @@ media_sox_open(Lisp_Media_Stream *ms)
        case MKIND_FILE: {
                mkind_file_properties *mkfp = NULL;
                const char *file = NULL;
-               int file_len = 0;
+               int file_len __attribute__((unused)) = 0;
 
                /* open the file */
                mkfp = media_stream_kind_properties(ms).fprops;
@@ -115,12 +115,8 @@ media_sox_open(Lisp_Media_Stream *ms)
        }
 
        /* retrieve the signal information */
-#if defined HAVE_STRUCT_SOX_FORMAT
+#if defined HAVE_STRUCT_SOX_FORMAT_T
        stinfo = &ft->signal;
-#elif defined MEMBER_STRUCT_ST_SOUNDSTREAM_SIGNAL
-       stinfo = &ft->signal;
-#elif defined MEMBER_STRUCT_ST_SOUNDSTREAM_INFO
-       stinfo = &ft->info;
 #else
 #  error "What's the matter with you?! How did you reach this?"
 #endif
@@ -159,7 +155,7 @@ media_sox_open(Lisp_Media_Stream *ms)
                mtap->samplewidth = 64;
                mtap->framesize = mtap->channels * 8;
                break;
-        default:
+       default:
                mtap->samplewidth = 32;
                mtap->framesize = mtap->channels * 4;
                break;
@@ -195,8 +191,8 @@ media_sox_close(ms_driver_data_t arg)
        sxe_sox_t ft = arg;
        sxe_sox_close(ft);
 
-       SOX_DEBUG("closing SoX handle: 0x%x\n",
-                 (unsigned int)ft);
+       SOX_DEBUG("closing SoX handle: 0x%lx\n",
+                 (unsigned long int)ft);
 
        return;
 }
@@ -209,11 +205,11 @@ media_sox_read(media_substream *mss, void *outbuf, size_t length)
        /* stream stuff */
        Lisp_Media_Stream *ms = mss->up;
        mtype_audio_properties *mtap;
-       /* libst stuff */
+       /* libsox stuff */
        sxe_sox_t ft;
        sxe_sox_ssize_t samples;
        sxe_sox_sample_t *bptr;
-       uint16_t framesize;
+       uint16_t framesize __attribute__((unused));
        media_sample_format_t *fmt;
 
        /* check the integrity of the media stream */
@@ -234,7 +230,8 @@ media_sox_read(media_substream *mss, void *outbuf, size_t length)
        bptr = (sxe_sox_sample_t*)outbuf;
        samples = sxe_sox_read(ft, bptr, mtap->channels*length);
 
-       SOX_DEBUG_S("read %d samples\n", samples);
+       SOX_DEBUG_S("SoX handle: 0x%lx read %zd samples\n",
+                    (unsigned long int)ft, samples);
 
        if (samples < 0)
                return 0;
@@ -249,9 +246,9 @@ media_sox_read(media_substream *mss, void *outbuf, size_t length)
 static void
 media_sox_rewind(media_substream *mss)
 {
-/* rewind the stream to the first frame */
+        /* rewind the stream to the first frame */
        Lisp_Media_Stream *ms = mss->up;
-       /* libst stuff */
+       /* libsox stuff */
        sxe_sox_t ft;
 
        /* check the integrity of the media stream */
@@ -264,8 +261,47 @@ media_sox_rewind(media_substream *mss)
        if (!(ft = media_stream_data(ms)))
                return;
 
-       SOX_DEBUG_S("rewind stream 0x%x\n", (unsigned int)ft);
-       sxe_sox_seek(ft, 0, SEEK_SET);
+       SOX_DEBUG_S("rewind stream 0x%lx\n", (unsigned long int)ft);
+
+        /* Unfortunately it seems sex_sox_seek is broken, so we are
+           closing and reopening the stream,
+       */
+#ifdef SXE_SOX_CAN_SEEK
+        if( sxe_sox_seek(ft, 0, SOX_SEEK_SET) == 0 ) {
+               return;
+       }
+       SOX_DEBUG_S("rewind stream 0x%lx failed, trying reopen\n",
+                   (unsigned long int)ft);
+#endif
+       sxe_sox_close(ft);
+       ft = NULL;
+       {
+               mkind_file_properties *mkfp = NULL;
+               const char *file = NULL;
+               int file_len __attribute__((unused)) = 0;
+
+               /* open the file */
+               mkfp = media_stream_kind_properties(ms).fprops;
+               TO_EXTERNAL_FORMAT(LISP_STRING, mkfp->filename,
+                                  ALLOCA, (file, file_len), Qnil);
+               if( file != NULL ) {
+#if defined HAVE_SOX_OPEN_READ_3ARGS
+                       ft = sxe_sox_open_read(file, NULL, NULL);
+#elif defined HAVE_SOX_OPEN_READ_4ARGS
+                       ft = sxe_sox_open_read(file, NULL, NULL, NULL);
+#else
+# error You shouldnt be here.  Wake up before you try to compile me.
+#endif
+               }
+       }
+       if (!ft) {
+               media_stream_set_meths(ms, NULL);
+               media_stream_driver(ms) = MDRIVER_UNKNOWN;
+               SOX_DEBUG_S("could not reopen stream");
+               return;
+       }
+       media_stream_data(ms) = ft;
+       media_substream_data(mss) = ft;
 }
 
 #undef MYSELF