]> code.delx.au - pulseaudio/blobdiff - src/utils/padsp.c
Merge remote branch 'origin/master-tx'
[pulseaudio] / src / utils / padsp.c
index c82fde64fa251985af2c68e312a71a7c8e94e3e0..41bfd741e618e8ff20e55d26ae946cc92d32abb6 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -53,6 +53,7 @@
 #include <pulse/pulseaudio.h>
 #include <pulse/gccmacro.h>
 #include <pulsecore/llist.h>
+#include <pulsecore/core-util.h>
 
 /* On some systems SIOCINQ isn't defined, but FIONREAD is just an alias */
 #if !defined(SIOCINQ) && defined(FIONREAD)
@@ -422,7 +423,7 @@ static void fd_info_unref(fd_info *i) {
     pthread_mutex_lock(&i->mutex);
     assert(i->ref >= 1);
     r = --i->ref;
-        debug(DEBUG_LEVEL_VERBOSE, __FILE__": ref--, now %i\n", i->ref);
+    debug(DEBUG_LEVEL_VERBOSE, __FILE__": ref--, now %i\n", i->ref);
     pthread_mutex_unlock(&i->mutex);
 
     if (r <= 0)
@@ -459,15 +460,16 @@ static void reset_params(fd_info *i) {
 }
 
 static const char *client_name(char *buf, size_t n) {
-    char p[PATH_MAX];
+    char *p;
     const char *e;
 
     if ((e = getenv("PADSP_CLIENT_NAME")))
         return e;
 
-    if (pa_get_binary_name(p, sizeof(p)))
+    if ((p = pa_get_binary_name_malloc())) {
         snprintf(buf, n, "OSS Emulation[%s]", p);
-    else
+        pa_xfree(p);
+    } else
         snprintf(buf, n, "OSS");
 
     return buf;
@@ -498,7 +500,6 @@ static void atfork_prepare(void) {
 
     pthread_mutex_lock(&func_mutex);
 
-
     debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_prepare() exit\n");
 }
 
@@ -550,12 +551,14 @@ static void atfork_child(void) {
         }
 
         if (i->app_fd >= 0) {
-            close(i->app_fd);
+            LOAD_CLOSE_FUNC();
+            _close(i->app_fd);
             i->app_fd = -1;
         }
 
         if (i->thread_fd >= 0) {
-            close(i->thread_fd);
+            LOAD_CLOSE_FUNC();
+            _close(i->thread_fd);
             i->thread_fd = -1;
         }
 
@@ -748,7 +751,7 @@ static void fix_metrics(fd_info *i) {
     /* Number of fragments set? */
     if (i->n_fragments < 2) {
         if (i->fragment_size > 0) {
-            i->n_fragments = pa_bytes_per_second(&i->sample_spec) / 2 / i->fragment_size;
+            i->n_fragments = (unsigned) (pa_bytes_per_second(&i->sample_spec) / 2 / i->fragment_size);
             if (i->n_fragments < 2)
                 i->n_fragments = 2;
         } else
@@ -864,7 +867,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
                 return -1;
             }
 
-            if (pa_stream_write(i->play_stream, i->buf, r, free, 0, PA_SEEK_RELATIVE) < 0) {
+            if (pa_stream_write(i->play_stream, i->buf, (size_t) r, free, 0LL, PA_SEEK_RELATIVE) < 0) {
                 debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_write(): %s\n", pa_strerror(pa_context_errno(i->context)));
                 return -1;
             }
@@ -872,7 +875,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
             i->buf = NULL;
 
             assert(n >= (size_t) r);
-            n -= r;
+            n -= (size_t) r;
         }
 
         if (n >= i->fragment_size)
@@ -916,7 +919,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
             }
 
             assert((size_t)r <= len - i->rec_offset);
-            i->rec_offset += r;
+            i->rec_offset += (size_t) r;
 
             if (i->rec_offset == len) {
                 if (pa_stream_drop(i->rec_stream) < 0) {
@@ -927,7 +930,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
             }
 
             assert(n >= (size_t) r);
-            n -= r;
+            n -= (size_t) r;
         }
 
         if (n >= i->fragment_size)
@@ -943,6 +946,10 @@ static int fd_info_copy_data(fd_info *i, int force) {
         api->io_enable(i->io_event, i->io_flags);
     }
 
+    /* So, we emptied the socket now, let's tell dsp_empty_socket()
+     * about this */
+    pa_threaded_mainloop_signal(i->mainloop, 0);
+
     return 0;
 }
 
@@ -998,12 +1005,12 @@ static int create_playback_stream(fd_info *i) {
     pa_stream_set_latency_update_callback(i->play_stream, stream_latency_update_cb, i);
 
     memset(&attr, 0, sizeof(attr));
-    attr.maxlength = i->fragment_size * (i->n_fragments+1);
-    attr.tlength = i->fragment_size * i->n_fragments;
-    attr.prebuf = i->fragment_size;
-    attr.minreq = i->fragment_size;
+    attr.maxlength = (uint32_t) (i->fragment_size * (i->n_fragments+1));
+    attr.tlength = (uint32_t) (i->fragment_size * i->n_fragments);
+    attr.prebuf = (uint32_t) i->fragment_size;
+    attr.minreq = (uint32_t) i->fragment_size;
 
-    flags = PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE;
+    flags = PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_EARLY_REQUESTS;
     if (i->play_precork) {
         flags |= PA_STREAM_START_CORKED;
         debug(DEBUG_LEVEL_NORMAL, __FILE__": creating stream corked\n");
@@ -1013,9 +1020,9 @@ static int create_playback_stream(fd_info *i) {
         goto fail;
     }
 
-    n = i->fragment_size;
+    n = (int) i->fragment_size;
     setsockopt(i->app_fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n));
-    n = i->fragment_size;
+    n = (int) i->fragment_size;
     setsockopt(i->thread_fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
 
     return 0;
@@ -1042,8 +1049,8 @@ static int create_record_stream(fd_info *i) {
     pa_stream_set_latency_update_callback(i->rec_stream, stream_latency_update_cb, i);
 
     memset(&attr, 0, sizeof(attr));
-    attr.maxlength = i->fragment_size * (i->n_fragments+1);
-    attr.fragsize = i->fragment_size;
+    attr.maxlength = (uint32_t) (i->fragment_size * (i->n_fragments+1));
+    attr.fragsize = (uint32_t) i->fragment_size;
 
     flags = PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE;
     if (i->rec_precork) {
@@ -1055,9 +1062,9 @@ static int create_record_stream(fd_info *i) {
         goto fail;
     }
 
-    n = i->fragment_size;
+    n = (int) i->fragment_size;
     setsockopt(i->app_fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
-    n = i->fragment_size;
+    n = (int) i->fragment_size;
     setsockopt(i->thread_fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n));
 
     return 0;
@@ -1197,7 +1204,7 @@ fail:
 static void sink_info_cb(pa_context *context, const pa_sink_info *si, int eol, void *userdata) {
     fd_info *i = userdata;
 
-    if (!si && eol < 0) {
+    if (!si || eol < 0) {
         i->operation_success = 0;
         pa_threaded_mainloop_signal(i->mainloop, 0);
         return;
@@ -1219,7 +1226,7 @@ static void sink_info_cb(pa_context *context, const pa_sink_info *si, int eol, v
 static void source_info_cb(pa_context *context, const pa_source_info *si, int eol, void *userdata) {
     fd_info *i = userdata;
 
-    if (!si && eol < 0) {
+    if (!si || eol < 0) {
         i->operation_success = 0;
         pa_threaded_mainloop_signal(i->mainloop, 0);
         return;
@@ -1474,7 +1481,7 @@ int open(const char *filename, int flags, ...) {
     if (flags & O_CREAT) {
         va_start(args, flags);
         if (sizeof(mode_t) < sizeof(int))
-            mode = va_arg(args, int);
+            mode = (mode_t) va_arg(args, int);
         else
             mode = va_arg(args, mode_t);
         va_end(args);
@@ -1814,7 +1821,7 @@ fail:
 
     pa_threaded_mainloop_unlock(i->mainloop);
 
-    return 0;
+    return r;
 }
 
 static int dsp_trigger(fd_info *i) {
@@ -1857,7 +1864,7 @@ fail:
 
     pa_threaded_mainloop_unlock(i->mainloop);
 
-    return 0;
+    return r;
 }
 
 static int dsp_cork(fd_info *i, pa_stream *s, int b) {
@@ -1895,7 +1902,7 @@ fail:
 
     pa_threaded_mainloop_unlock(i->mainloop);
 
-    return 0;
+    return r;
 }
 
 static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) {
@@ -2377,15 +2384,15 @@ int access(const char *pathname, int mode) {
     debug(DEBUG_LEVEL_VERBOSE, __FILE__": access(%s)\n", pathname?pathname:"NULL");
 
     if (!pathname ||
-        ( strcmp(pathname, "/dev/dsp") != 0 &&
-          strcmp(pathname, "/dev/adsp") != 0 &&
-          strcmp(pathname, "/dev/sndstat") != 0 &&
-          strcmp(pathname, "/dev/mixer") != 0 )) {
+        (strcmp(pathname, "/dev/dsp") != 0 &&
+         strcmp(pathname, "/dev/adsp") != 0 &&
+         strcmp(pathname, "/dev/sndstat") != 0 &&
+         strcmp(pathname, "/dev/mixer") != 0 )) {
         LOAD_ACCESS_FUNC();
         return _access(pathname, mode);
     }
 
-    if (mode & (W_OK | X_OK)) {
+    if (mode & X_OK) {
         debug(DEBUG_LEVEL_NORMAL, __FILE__": access(%s, %x) = EACCESS\n", pathname, mode);
         errno = EACCES;
         return -1;