[pulseaudio-commits] 4 commits - configure.ac src/modules src/pulse src/pulsecore

Colin Guthrie colin at kemper.freedesktop.org
Sun Nov 27 08:31:35 PST 2011


 configure.ac                     |    1 
 src/modules/module-esound-sink.c |    2 
 src/pulse/mainloop.c             |    4 -
 src/pulsecore/poll.c             |   16 +------
 src/pulsecore/resampler.c        |   88 ++++++++++++++++++++-------------------
 src/pulsecore/shm.c              |    2 
 src/pulsecore/socket-server.c    |    6 +-
 src/pulsecore/socket-util.c      |   20 ++++----
 8 files changed, 68 insertions(+), 71 deletions(-)

New commits:
commit 40e35efbce6ea02d59ac2556343817f8257271e0
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Wed Nov 2 21:54:17 2011 +0100

    resamplers: Improve performance of peaks resampler
    
    This is mainly achieved by special-casing the common 1ch float case,
    which is used by applications such as pavucontrol.

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 26aa4f8..dda6a2f 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -1451,6 +1451,8 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
     pa_assert(input);
     pa_assert(output);
     pa_assert(out_n_frames);
+    pa_assert(r->i_ss.rate >= r->o_ss.rate);
+    pa_assert(r->work_format == PA_SAMPLE_S16NE || r->work_format == PA_SAMPLE_FLOAT32NE);
 
     fz = r->w_sz * r->o_ss.channels;
 
@@ -1464,19 +1466,34 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
         i_end = (((r->peaks.o_counter+1) * r->i_ss.rate) / r->o_ss.rate);
         i_end = i_end > r->peaks.i_counter ? i_end - r->peaks.i_counter : 0;
 
-        pa_assert(o_index * fz < pa_memblock_get_length(output->memblock));
+        pa_assert_fp(o_index * fz < pa_memblock_get_length(output->memblock));
+
+        /* 1ch float is treated separately, because that is the common case */
+        if (r->o_ss.channels == 1 && r->work_format == PA_SAMPLE_FLOAT32NE) {
+            float *s = (float*) src + i;
+            float *d = (float*) dst + o_index;
+
+            for (; i < i_end && i < in_n_frames; i++) {
+                float n = fabsf(*s++);
+
+                if (n > r->peaks.max_f[0])
+                    r->peaks.max_f[0] = n;
+            }
 
-        if (r->work_format == PA_SAMPLE_S16NE) {
+            if (i == i_end) {
+                *d = r->peaks.max_f[0];
+                r->peaks.max_f[0] = 0;
+                o_index++, r->peaks.o_counter++;
+            }
+        } else if (r->work_format == PA_SAMPLE_S16NE) {
             int16_t *s = (int16_t*) ((uint8_t*) src + fz * i);
             int16_t *d = (int16_t*) ((uint8_t*) dst + fz * o_index);
 
             for (; i < i_end && i < in_n_frames; i++)
-                for (c = 0; c < r->o_ss.channels; c++, s++) {
-                    int16_t n;
+                for (c = 0; c < r->o_ss.channels; c++) {
+                    int16_t n = abs(*s++);
 
-                    n = (int16_t) (*s < 0 ? -*s : *s);
-
-                    if (PA_UNLIKELY(n > r->peaks.max_i[c]))
+                    if (n > r->peaks.max_i[c])
                         r->peaks.max_i[c] = n;
                 }
 
@@ -1491,11 +1508,9 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
             float *s = (float*) ((uint8_t*) src + fz * i);
             float *d = (float*) ((uint8_t*) dst + fz * o_index);
 
-            pa_assert(r->work_format == PA_SAMPLE_FLOAT32NE);
-
             for (; i < i_end && i < in_n_frames; i++)
-                for (c = 0; c < r->o_ss.channels; c++, s++) {
-                    float n = fabsf(*s);
+                for (c = 0; c < r->o_ss.channels; c++) {
+                    float n = fabsf(*s++);
 
                     if (n > r->peaks.max_f[c])
                         r->peaks.max_f[c] = n;

commit 115d903ab7bdd4b88cceacae1f546ef59b570286
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Wed Nov 2 21:54:16 2011 +0100

    resamplers: Rework the peaks resampler
    
    The algorithm had been implemented the same way as the trivial resampler.  But
    an important difference between the two is that the trivial resampler can write
    an output as soon as the first corresponding input sample is seen, whereas the
    peaks resampler must have read all input samples before writing an output
    sample.
    
    With this rework, the peaks resampler now outputs samples correctly when the
    input data is spanning multiple memblocks.

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index c432a6f..26aa4f8 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -1443,9 +1443,9 @@ static int trivial_init(pa_resampler*r) {
 
 static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     size_t fz;
-    unsigned o_index;
+    unsigned c, o_index = 0;
+    unsigned i, i_end = 0;
     void *src, *dst;
-    unsigned start = 0;
 
     pa_assert(r);
     pa_assert(input);
@@ -1457,25 +1457,20 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
     src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
     dst = (uint8_t*) pa_memblock_acquire(output->memblock) + output->index;
 
-    for (o_index = 0;; o_index++, r->peaks.o_counter++) {
-        unsigned j;
+    i = ((r->peaks.o_counter * r->i_ss.rate) / r->o_ss.rate);
+    i = i > r->peaks.i_counter ? i - r->peaks.i_counter : 0;
 
-        j = ((r->peaks.o_counter * r->i_ss.rate) / r->o_ss.rate);
-
-        if (j > r->peaks.i_counter)
-            j -= r->peaks.i_counter;
-        else
-            j = 0;
+    while (i_end < in_n_frames) {
+        i_end = (((r->peaks.o_counter+1) * r->i_ss.rate) / r->o_ss.rate);
+        i_end = i_end > r->peaks.i_counter ? i_end - r->peaks.i_counter : 0;
 
         pa_assert(o_index * fz < pa_memblock_get_length(output->memblock));
 
         if (r->work_format == PA_SAMPLE_S16NE) {
-            unsigned i, c;
-            int16_t *s = (int16_t*) ((uint8_t*) src + fz * start);
+            int16_t *s = (int16_t*) ((uint8_t*) src + fz * i);
             int16_t *d = (int16_t*) ((uint8_t*) dst + fz * o_index);
 
-            for (i = start; i <= j && i < in_n_frames; i++)
-
+            for (; i < i_end && i < in_n_frames; i++)
                 for (c = 0; c < r->o_ss.channels; c++, s++) {
                     int16_t n;
 
@@ -1485,22 +1480,20 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
                         r->peaks.max_i[c] = n;
                 }
 
-            if (i >= in_n_frames)
-                break;
-
-            for (c = 0; c < r->o_ss.channels; c++, d++) {
-                *d = r->peaks.max_i[c];
-                r->peaks.max_i[c] = 0;
+            if (i == i_end) {
+                for (c = 0; c < r->o_ss.channels; c++, d++) {
+                    *d = r->peaks.max_i[c];
+                    r->peaks.max_i[c] = 0;
+                }
+                o_index++, r->peaks.o_counter++;
             }
-
         } else {
-            unsigned i, c;
-            float *s = (float*) ((uint8_t*) src + fz * start);
+            float *s = (float*) ((uint8_t*) src + fz * i);
             float *d = (float*) ((uint8_t*) dst + fz * o_index);
 
             pa_assert(r->work_format == PA_SAMPLE_FLOAT32NE);
 
-            for (i = start; i <= j && i < in_n_frames; i++)
+            for (; i < i_end && i < in_n_frames; i++)
                 for (c = 0; c < r->o_ss.channels; c++, s++) {
                     float n = fabsf(*s);
 
@@ -1508,16 +1501,14 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
                         r->peaks.max_f[c] = n;
                 }
 
-            if (i >= in_n_frames)
-                break;
-
-            for (c = 0; c < r->o_ss.channels; c++, d++) {
-                *d = r->peaks.max_f[c];
-                r->peaks.max_f[c] = 0;
+            if (i == i_end) {
+                for (c = 0; c < r->o_ss.channels; c++, d++) {
+                    *d = r->peaks.max_f[c];
+                    r->peaks.max_f[c] = 0;
+                }
+                o_index++, r->peaks.o_counter++;
             }
         }
-
-        start = j;
     }
 
     pa_memblock_release(input->memblock);

commit ae179d7321761d24960972c94ec412ad1713cfd3
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sun Nov 27 16:12:10 2011 +0000

    shm: Use a goto rather than early return for consistency.
    
    This is functionally the same but is easier to understand.

diff --git a/src/pulsecore/shm.c b/src/pulsecore/shm.c
index 06e32c4..fe34a51 100644
--- a/src/pulsecore/shm.c
+++ b/src/pulsecore/shm.c
@@ -176,7 +176,7 @@ int pa_shm_create_rw(pa_shm *m, size_t size, pa_bool_t shared, mode_t mode) {
         pa_assert_se(pa_close(fd) == 0);
         m->do_unlink = TRUE;
 #else
-        return -1;
+        goto fail;
 #endif
     }
 

commit e8028304b30c359ee4c0e97fb57a0f6e985227e8
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Wed Nov 2 21:54:13 2011 +0100

    win32: Avoid some compiler warnings when cross-compiling for mingw32
    
    Autoconf documentation says that AC_FUNC_SELECT_ARGTYPES shouldn't be used anyway.

diff --git a/configure.ac b/configure.ac
index b15b1e4..e3ce987 100644
--- a/configure.ac
+++ b/configure.ac
@@ -490,7 +490,6 @@ AC_CHECK_FUNCS_ONCE([lrintf strtof])
 # POSIX
 AC_FUNC_FORK
 AC_FUNC_GETGROUPS
-AC_FUNC_SELECT_ARGTYPES
 AC_CHECK_FUNCS_ONCE([chmod chown fstat fchown fchmod clock_gettime getaddrinfo getgrgid_r getgrnam_r \
     getpwnam_r getpwuid_r gettimeofday getuid mlock nanosleep \
     pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \
diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index d79054f..1e26e5e 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -377,7 +377,7 @@ static int do_write(struct userdata *u) {
 
         pa_make_tcp_socket_low_delay(u->fd);
 
-        if (getsockopt(u->fd, SOL_SOCKET, SO_SNDBUF, &so_sndbuf, &sl) < 0)
+        if (getsockopt(u->fd, SOL_SOCKET, SO_SNDBUF, (void *) &so_sndbuf, &sl) < 0)
             pa_log_warn("getsockopt(SO_SNDBUF) failed: %s", pa_cstrerror(errno));
         else {
             pa_log_debug("SO_SNDBUF is %zu.", (size_t) so_sndbuf);
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 8e956c9..5c0345e 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -186,9 +186,7 @@ static pa_io_event* mainloop_io_new(
         FD_ZERO (&xset);
         FD_SET (fd, &xset);
 
-        if ((select((SELECT_TYPE_ARG1) fd, NULL, NULL, SELECT_TYPE_ARG234 &xset,
-                    SELECT_TYPE_ARG5 &tv) == -1) &&
-             (WSAGetLastError() == WSAENOTSOCK)) {
+        if ((select(fd, NULL, NULL, &xset, &tv) == -1) && (WSAGetLastError() == WSAENOTSOCK)) {
             pa_log_warn("Cannot monitor non-socket file descriptors.");
             e->dead = TRUE;
         }
diff --git a/src/pulsecore/poll.c b/src/pulsecore/poll.c
index d5abb04..cd888b5 100644
--- a/src/pulsecore/poll.c
+++ b/src/pulsecore/poll.c
@@ -106,9 +106,7 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
     tv.tv_sec = timeout / 1000;
     tv.tv_usec = (timeout % 1000) * 1000;
 
-    ready = select((SELECT_TYPE_ARG1) maxfd + 1, SELECT_TYPE_ARG234 &rset,
-                    SELECT_TYPE_ARG234 &wset, SELECT_TYPE_ARG234 &xset,
-                    SELECT_TYPE_ARG5 (timeout == -1 ? NULL : &tv));
+    ready = select(maxfd + 1, &rset, &wset, &xset, (timeout == -1 ? NULL : &tv));
 
     if ((ready == -1) && (errno == EBADF)) {
         ready = 0;
@@ -144,9 +142,7 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
                     singl_tv.tv_sec = 0;
                     singl_tv.tv_usec = 0;
 
-                    if (select((SELECT_TYPE_ARG1) f->fd, SELECT_TYPE_ARG234 &rset,
-                               SELECT_TYPE_ARG234 &wset, SELECT_TYPE_ARG234 &xset,
-                               SELECT_TYPE_ARG5 &singl_tv) != -1) {
+                    if (select(f->fd, &rset, &wset, &xset, &singl_tv) != -1) {
                         if (f->events & POLLIN)
                             FD_SET (f->fd, &rset);
                         if (f->events & POLLOUT)
@@ -185,9 +181,7 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
         /* Linux alters the tv struct... but it shouldn't matter here ...
          * as we're going to be a little bit out anyway as we've just eaten
          * more than a couple of cpu cycles above */
-            ready = select((SELECT_TYPE_ARG1) maxfd + 1, SELECT_TYPE_ARG234 &rset,
-                            SELECT_TYPE_ARG234 &wset, SELECT_TYPE_ARG234 &xset,
-                            SELECT_TYPE_ARG5 (timeout == -1 ? NULL : &tv));
+            ready = select(maxfd + 1, &rset, &wset, &xset, (timeout == -1 ? NULL : &tv));
         }
     }
 
@@ -196,8 +190,6 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
 #endif
 
     if (ready > 0) {
-        int r;
-
         ready = 0;
         for (f = fds; f < &fds[nfds]; ++f) {
             f->revents = 0;
@@ -210,7 +202,7 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
                      * for some kinds of descriptors.  Detect if this descriptor is a
                      * connected socket, a server socket, or something else using a
                      * 0-byte recv, and use ioctl(2) to detect POLLHUP.  */
-                    r = recv(f->fd, NULL, 0, MSG_PEEK);
+                    int r = recv(f->fd, NULL, 0, MSG_PEEK);
                     if (r == 0 || (r < 0 && errno == ENOTSOCK))
                         ioctl(f->fd, FIONREAD, &r);
 
diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
index fd81c2a..0b0b2a5 100644
--- a/src/pulsecore/socket-server.c
+++ b/src/pulsecore/socket-server.c
@@ -244,7 +244,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
     }
 
 #ifdef SO_REUSEADDR
-    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(on)) < 0)
         pa_log("setsockopt(): %s", pa_cstrerror(errno));
 #endif
 
@@ -307,13 +307,13 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
 
 #ifdef IPV6_V6ONLY
     on = 1;
-    if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
+    if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(on)) < 0)
         pa_log("setsockopt(IPPROTO_IPV6, IPV6_V6ONLY): %s", pa_cstrerror(errno));
 #endif
 
 #ifdef SO_REUSEADDR
     on = 1;
-    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(on)) < 0)
         pa_log("setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", pa_cstrerror(errno));
 #endif
 
diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 00fcbc4..2b8d463 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -63,7 +63,9 @@
 #include "socket-util.h"
 
 void pa_socket_peer_to_string(int fd, char *c, size_t l) {
+#ifndef OS_IS_WIN32
     struct stat st;
+#endif
 
     pa_assert(fd >= 0);
     pa_assert(c);
@@ -139,7 +141,7 @@ void pa_make_socket_low_delay(int fd) {
     pa_assert(fd >= 0);
 
     priority = 6;
-    if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (const void *) &priority, sizeof(priority)) < 0)
         pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno));
 #endif
 }
@@ -153,9 +155,9 @@ void pa_make_tcp_socket_low_delay(int fd) {
     {
         int on = 1;
 #if defined(SOL_TCP)
-        if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
+        if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *) &on, sizeof(on)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
+        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *) &on, sizeof(on)) < 0)
 #endif
             pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
     }
@@ -165,9 +167,9 @@ void pa_make_tcp_socket_low_delay(int fd) {
     {
         int tos = IPTOS_LOWDELAY;
 #ifdef SOL_IP
-        if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, SOL_IP, IP_TOS, (const void *) &tos, sizeof(tos)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, IPPROTO_IP, IP_TOS, (const void *) &tos, sizeof(tos)) < 0)
 #endif
             pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
     }
@@ -183,9 +185,9 @@ void pa_make_udp_socket_low_delay(int fd) {
     {
         int tos = IPTOS_LOWDELAY;
 #ifdef SOL_IP
-        if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, SOL_IP, IP_TOS, (const void *) &tos, sizeof(tos)) < 0)
 #else
-        if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
+        if (setsockopt(fd, IPPROTO_IP, IP_TOS, (const void *) &tos, sizeof(tos)) < 0)
 #endif
             pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
     }
@@ -197,7 +199,7 @@ int pa_socket_set_rcvbuf(int fd, size_t l) {
 
     pa_assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsz, sizeof(bufsz)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void *) &bufsz, sizeof(bufsz)) < 0) {
         pa_log_warn("SO_RCVBUF: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -210,7 +212,7 @@ int pa_socket_set_sndbuf(int fd, size_t l) {
 
     pa_assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &bufsz, sizeof(bufsz)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &bufsz, sizeof(bufsz)) < 0) {
         pa_log_warn("SO_SNDBUF: %s", pa_cstrerror(errno));
         return -1;
     }



More information about the pulseaudio-commits mailing list