[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.11-209-g821dc17

Lennart Poettering gitmailer-noreply at 0pointer.de
Mon Sep 8 07:23:06 PDT 2008


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  fb837f0cac00d0207f84c9e68e1f7c2d6cd33a51 (commit)

- Log -----------------------------------------------------------------
821dc17... move autospawn lock to pulsecore/ since we don't need it in the client anymore
f216402... Add new option to disable remixing from/to LFE and set it to on by default
33d349d... include build and runtime host information in debug output
-----------------------------------------------------------------------

Summary of changes:
 man/pulse-daemon.conf.5.xml.in            |   10 ++++++++
 src/Makefile.am                           |    7 ++---
 src/daemon/daemon-conf.c                  |   36 ++++++++++++++++-------------
 src/daemon/daemon-conf.h                  |    1 +
 src/daemon/daemon.conf.in                 |    1 +
 src/daemon/main.c                         |   12 +++++++--
 src/pulsecore/core-util.c                 |    8 ++++++
 src/pulsecore/core-util.h                 |    1 +
 src/pulsecore/core.c                      |    1 +
 src/pulsecore/core.h                      |    1 +
 src/{pulse => pulsecore}/lock-autospawn.c |    0 
 src/{pulse => pulsecore}/lock-autospawn.h |    0 
 src/pulsecore/resampler.c                 |    8 +++++-
 src/pulsecore/resampler.h                 |    7 +++--
 src/pulsecore/sink-input.c                |    3 +-
 src/pulsecore/source-output.c             |    3 +-
 src/tests/lock-autospawn-test.c           |    2 +-
 17 files changed, 70 insertions(+), 31 deletions(-)
 rename src/{pulse => pulsecore}/lock-autospawn.c (100%)
 rename src/{pulse => pulsecore}/lock-autospawn.h (100%)

-----------------------------------------------------------------------

commit 33d349dcbbef0952e9e59ca105e08fdff5454803
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 5 15:42:39 2008 +0300

    include build and runtime host information in debug output

diff --git a/src/daemon/main.c b/src/daemon/main.c
index c8eda39..bb8af44 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -778,8 +778,15 @@ int main(int argc, char *argv[]) {
     pa_set_env("PULSE_SYSTEM", conf->system_instance ? "1" : "0");
 
     pa_log_info(_("This is PulseAudio %s"), PACKAGE_VERSION);
+    pa_log_debug(_("Compilation host: %s"), CANONICAL_HOST);
     pa_log_debug(_("Compilation CFLAGS: %s"), PA_CFLAGS);
 
+    s = pa_uname_string();
+    pa_log_debug(_("Running on host: %s"), s);
+    pa_xfree(s);
+
+    pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);
+
 #ifdef HAVE_VALGRIND_MEMCHECK_H
     pa_log_debug(_("Compiled with Valgrind support: yes"));
 #else
@@ -792,8 +799,6 @@ int main(int argc, char *argv[]) {
     pa_log_debug(_("Optimized build: no"));
 #endif
 
-    pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);
-
     if (!(s = pa_machine_id())) {
         pa_log(_("Failed to get machine ID"));
         goto finish;
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index ad00f4f..3e5ea49 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -42,6 +42,7 @@
 #include <dirent.h>
 #include <regex.h>
 #include <langinfo.h>
+#include <sys/utsname.h>
 
 #ifdef HAVE_STRTOF_L
 #include <locale.h>
@@ -2445,5 +2446,12 @@ char *pa_machine_id(void) {
     /* If no hostname was set we use the POSIX hostid. It's usually
      * the IPv4 address.  Mit not be that stable. */
     return pa_sprintf_malloc("%08lx", (unsigned long) gethostid);
+}
+
+char *pa_uname_string(void) {
+    struct utsname u;
+
+    pa_assert_se(uname(&u) == 0);
 
+    return pa_sprintf_malloc("%s %s %s %s", u.sysname, u.machine, u.release, u.version);
 }
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index c9e307f..df8ce3f 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -191,5 +191,6 @@ pa_bool_t pa_in_system_mode(void);
 #define pa_streq(a,b) (!strcmp((a),(b)))
 
 char *pa_machine_id(void);
+char *pa_uname_string(void);
 
 #endif

commit f2164023fd0fda8c1a456c5c2f144f8943c24db9
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 5 16:04:42 2008 +0300

    Add new option to disable remixing from/to LFE and set it to on by default

diff --git a/man/pulse-daemon.conf.5.xml.in b/man/pulse-daemon.conf.5.xml.in
index c2eefaa..ed158df 100644
--- a/man/pulse-daemon.conf.5.xml.in
+++ b/man/pulse-daemon.conf.5.xml.in
@@ -106,6 +106,16 @@ USA.
     </option>
 
     <option>
+      <p><opt>disable-lfe-remixing=</opt> When upmixing or downmixing
+      ignore LFE channels. When this option is on the output LFE
+      channel will only get a signal when an input LFE channel is
+      available as well. If no input LFE channel is available the
+      output LFE channel will always be 0. If no output LFE channel is
+      available the signal on the input LFE channel will be
+      ignored.</p>
+    </option>
+
+    <option>
       <p><opt>use-pid-file=</opt> Create a PID file in
       <file>/tmp/pulse-$USER/pid</file>. Of this is enabled you may
       use commands like <opt>--kill</opt> or <opt>--check</opt>. If
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 40e0a17..77da3f7 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -76,6 +76,7 @@ static const pa_daemon_conf default_conf = {
     .log_level = PA_LOG_NOTICE,
     .resample_method = PA_RESAMPLER_AUTO,
     .disable_remixing = FALSE,
+    .disable_lfe_remixing = TRUE,
     .config_file = NULL,
     .use_pid_file = TRUE,
     .system_instance = FALSE,
@@ -426,6 +427,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
         { "default-fragment-size-msec", parse_fragment_size_msec, NULL },
         { "nice-level",                 parse_nice_level,         NULL },
         { "disable-remixing",           pa_config_parse_bool,     NULL },
+        { "disable-lfe-remixing",       pa_config_parse_bool,     NULL },
         { "load-default-script-file",   pa_config_parse_bool,     NULL },
 #ifdef HAVE_SYS_RESOURCE_H
         { "rlimit-fsize",               parse_rlimit,             NULL },
@@ -490,66 +492,67 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
     table[24].data = c;
     table[25].data = c;
     table[26].data = &c->disable_remixing;
-    table[27].data = &c->load_default_script_file;
+    table[27].data = &c->disable_lfe_remixing;
+    table[28].data = &c->load_default_script_file;
 #ifdef HAVE_SYS_RESOURCE_H
-    table[28].data = &c->rlimit_fsize;
-    table[29].data = &c->rlimit_data;
-    table[30].data = &c->rlimit_stack;
-    table[31].data = &c->rlimit_as;
-    table[32].data = &c->rlimit_core;
-    table[33].data = &c->rlimit_nofile;
-    table[34].data = &c->rlimit_as;
+    table[29].data = &c->rlimit_fsize;
+    table[30].data = &c->rlimit_data;
+    table[31].data = &c->rlimit_stack;
+    table[32].data = &c->rlimit_as;
+    table[33].data = &c->rlimit_core;
+    table[34].data = &c->rlimit_nofile;
+    table[35].data = &c->rlimit_as;
 #ifdef RLIMIT_NPROC
-    table[35].data = &c->rlimit_nproc;
+    table[36].data = &c->rlimit_nproc;
 #endif
 
 #ifdef RLIMIT_MEMLOCK
 #ifndef RLIMIT_NPROC
 #error "Houston, we have a numbering problem!"
 #endif
-    table[36].data = &c->rlimit_memlock;
+    table[37].data = &c->rlimit_memlock;
 #endif
 
 #ifdef RLIMIT_LOCKS
 #ifndef RLIMIT_MEMLOCK
 #error "Houston, we have a numbering problem!"
 #endif
-    table[37].data = &c->rlimit_locks;
+    table[38].data = &c->rlimit_locks;
 #endif
 
 #ifdef RLIMIT_SIGPENDING
 #ifndef RLIMIT_LOCKS
 #error "Houston, we have a numbering problem!"
 #endif
-    table[38].data = &c->rlimit_sigpending;
+    table[39].data = &c->rlimit_sigpending;
 #endif
 
 #ifdef RLIMIT_MSGQUEUE
 #ifndef RLIMIT_SIGPENDING
 #error "Houston, we have a numbering problem!"
 #endif
-    table[39].data = &c->rlimit_msgqueue;
+    table[40].data = &c->rlimit_msgqueue;
 #endif
 
 #ifdef RLIMIT_NICE
 #ifndef RLIMIT_MSGQUEUE
 #error "Houston, we have a numbering problem!"
 #endif
-    table[40].data = &c->rlimit_nice;
+    table[41].data = &c->rlimit_nice;
 #endif
 
 #ifdef RLIMIT_RTPRIO
 #ifndef RLIMIT_NICE
 #error "Houston, we have a numbering problem!"
 #endif
-    table[41].data = &c->rlimit_rtprio;
+    table[42].data = &c->rlimit_rtprio;
 #endif
 
 #ifdef RLIMIT_RTTIME
 #ifndef RLIMIT_RTTIME
 #error "Houston, we have a numbering problem!"
 #endif
-    table[42].data = &c->rlimit_rttime;
+    table[43].data = &c->rlimit_rttime;
 #endif
 #endif
 
@@ -661,6 +664,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) {
     pa_strbuf_printf(s, "log-level = %s\n", log_level_to_string[c->log_level]);
     pa_strbuf_printf(s, "resample-method = %s\n", pa_resample_method_to_string(c->resample_method));
     pa_strbuf_printf(s, "disable-remixing = %s\n", pa_yes_no(c->disable_remixing));
+    pa_strbuf_printf(s, "disable-lfe-remixing = %s\n", pa_yes_no(c->disable_lfe_remixing));
     pa_strbuf_printf(s, "default-sample-format = %s\n", pa_sample_format_to_string(c->default_sample_spec.format));
     pa_strbuf_printf(s, "default-sample-rate = %u\n", c->default_sample_spec.rate);
     pa_strbuf_printf(s, "default-sample-channels = %u\n", c->default_sample_spec.channels);
diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h
index c42984f..309a142 100644
--- a/src/daemon/daemon-conf.h
+++ b/src/daemon/daemon-conf.h
@@ -66,6 +66,7 @@ typedef struct pa_daemon_conf {
         no_cpu_limit,
         disable_shm,
         disable_remixing,
+        disable_lfe_remixing,
         load_default_script_file,
         disallow_exit;
     int exit_idle_time,
diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in
index 33b1d61..ea09fe0 100644
--- a/src/daemon/daemon.conf.in
+++ b/src/daemon/daemon.conf.in
@@ -47,6 +47,7 @@
 
 ; resample-method = speex-float-3
 ; disable-remixing = no
+; disable-lfe-remixing = yes
 
 ; no-cpu-limit = no
 
diff --git a/src/daemon/main.c b/src/daemon/main.c
index bb8af44..f91573b 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -869,6 +869,7 @@ int main(int argc, char *argv[]) {
     c->realtime_priority = conf->realtime_priority;
     c->realtime_scheduling = !!conf->realtime_scheduling;
     c->disable_remixing = !!conf->disable_remixing;
+    c->disable_lfe_remixing = !!conf->disable_lfe_remixing;
     c->running_as_daemon = !!conf->daemonize;
     c->disallow_exit = conf->disallow_exit;
 
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 6f8a292..bd956ae 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -138,6 +138,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
     c->realtime_scheduling = FALSE;
     c->realtime_priority = 5;
     c->disable_remixing = FALSE;
+    c->disable_lfe_remixing = FALSE;
 
     for (j = 0; j < PA_CORE_HOOK_MAX; j++)
         pa_hook_init(&c->hooks[j], c);
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index eb76841..fb4490f 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -124,6 +124,7 @@ struct pa_core {
     pa_bool_t running_as_daemon:1;
     pa_bool_t realtime_scheduling:1;
     pa_bool_t disable_remixing:1;
+    pa_bool_t disable_lfe_remixing:1;
 
     pa_resample_method_t resample_method;
     int realtime_priority;
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 45cd68c..0ae029b 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -716,7 +716,11 @@ static void calc_map_table(pa_resampler *r) {
                  * channels for LFE. */
 
                 for (ic = 0; ic < r->i_ss.channels; ic++) {
-                    r->map_table[oc][ic] = 1.0f / (float) r->i_ss.channels;
+
+                    if (!(r->flags & PA_RESAMPLER_NO_LFE))
+                        r->map_table[oc][ic] = 1.0f / (float) r->i_ss.channels;
+                    else
+                        r->map_table[oc][ic] = 0;
 
                     /* Please note that a channel connected to LFE
                      * doesn't really count as connected. */
@@ -851,7 +855,7 @@ static void calc_map_table(pa_resampler *r) {
             }
         }
 
-        if (ic_unconnected_lfe > 0) {
+        if (ic_unconnected_lfe > 0 && !(r->flags & PA_RESAMPLER_NO_LFE)) {
 
             /* OK, so there is an unconnected LFE channel. Let's mix
              * it into all channels, with factor 0.375 */
diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h
index 5e302a9..87110cc 100644
--- a/src/pulsecore/resampler.h
+++ b/src/pulsecore/resampler.h
@@ -49,9 +49,10 @@ typedef enum pa_resample_method {
 } pa_resample_method_t;
 
 typedef enum pa_resample_flags {
-    PA_RESAMPLER_VARIABLE_RATE = 1,
-    PA_RESAMPLER_NO_REMAP = 2,  /* implies NO_REMIX */
-    PA_RESAMPLER_NO_REMIX = 4
+    PA_RESAMPLER_VARIABLE_RATE = 0x0001U,
+    PA_RESAMPLER_NO_REMAP      = 0x0002U,  /* implies NO_REMIX */
+    PA_RESAMPLER_NO_REMIX      = 0x0004U,
+    PA_RESAMPLER_NO_LFE        = 0x0008U
 } pa_resample_flags_t;
 
 pa_resampler* pa_resampler_new(
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 7d80242..326a7e2 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -201,7 +201,8 @@ pa_sink_input* pa_sink_input_new(
                       data->resample_method,
                       ((flags & PA_SINK_INPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
                       ((flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
-                      (core->disable_remixing || (flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)))) {
+                      (core->disable_remixing || (flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) |
+                      (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) {
             pa_log_warn("Unsupported resampling operation.");
             return NULL;
         }
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 5df950a..d76f6e4 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -171,7 +171,8 @@ pa_source_output* pa_source_output_new(
                       data->resample_method,
                       ((flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) |
                       ((flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) |
-                      (core->disable_remixing || (flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)))) {
+                      (core->disable_remixing || (flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) |
+                      (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) {
             pa_log_warn("Unsupported resampling operation.");
             return NULL;
         }

commit 821dc1797faa903618c7585d3c053fd7ae6e93db
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Sep 8 17:22:27 2008 +0300

    move autospawn lock to pulsecore/ since we don't need it in the client anymore

diff --git a/src/Makefile.am b/src/Makefile.am
index 3ee5372..1663d66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -541,8 +541,7 @@ libpulse_la_SOURCES = \
 		pulse/xmalloc.c pulse/xmalloc.h \
 		pulse/proplist.c pulse/proplist.h \
 		pulse/ext-stream-restore.c pulse/ext-stream-restore.h \
-		pulse/i18n.c pulse/i18n.h \
-		pulse/lock-autospawn.c pulse/lock-autospawn.h
+		pulse/i18n.c pulse/i18n.h
 
 # Internal stuff that is shared with libpulsecore
 libpulse_la_SOURCES += \
@@ -740,8 +739,7 @@ libpulsecore_la_SOURCES = \
 		pulse/volume.c pulse/volume.h \
 		pulse/xmalloc.c pulse/xmalloc.h \
 		pulse/proplist.c pulse/proplist.h \
-		pulse/i18n.c pulse/i18n.h \
-		pulse/lock-autospawn.c pulse/lock-autospawn.h
+		pulse/i18n.c pulse/i18n.h
 
 # Pure core stuff (some are shared in libpulse though).
 libpulsecore_la_SOURCES += \
@@ -811,6 +809,7 @@ libpulsecore_la_SOURCES += \
 		pulsecore/start-child.c pulsecore/start-child.h \
 		pulsecore/envelope.c pulsecore/envelope.h \
 		pulsecore/proplist-util.c pulsecore/proplist-util.h \
+		pulsecore/lock-autospawn.c pulsecore/lock-autospawn.h \
 		$(PA_THREAD_OBJS)
 
 if OS_IS_WIN32
diff --git a/src/daemon/main.c b/src/daemon/main.c
index f91573b..a9e8ed4 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -65,8 +65,8 @@
 #include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 #include <pulse/i18n.h>
-#include <pulse/lock-autospawn.h>
 
+#include <pulsecore/lock-autospawn.h>
 #include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/core.h>
diff --git a/src/pulse/lock-autospawn.c b/src/pulse/lock-autospawn.c
deleted file mode 100644
index d36b669..0000000
--- a/src/pulse/lock-autospawn.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/***
-  This file is part of PulseAudio.
-
-  Copyright 2008 Lennart Poettering
-
-  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,
-  or (at your option) any later version.
-
-  PulseAudio is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with PulseAudio; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-  USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/poll.h>
-#include <signal.h>
-#include <pthread.h>
-
-#include <pulse/i18n.h>
-#include <pulse/xmalloc.h>
-
-#include <pulsecore/mutex.h>
-#include <pulsecore/thread.h>
-#include <pulsecore/core-util.h>
-
-#include "lock-autospawn.h"
-
-/* So, why do we have this complex code here with threads and pipes
- * and stuff? For two reasons: POSIX file locks are per-process, not
- * per-file descriptor. That means that two contexts within the same
- * process that try to create the autospawn lock might end up assuming
- * they both managed to lock the file. And then, POSIX locking
- * operations are synchronous. If two contexts run from the same event
- * loop it must be made sure that they do not block each other, but
- * that the locking operation can happen asynchronously. */
-
-#define AUTOSPAWN_LOCK "autospawn.lock"
-
-static pa_mutex *mutex;
-
-static unsigned n_ref = 0;
-static int lock_fd = -1;
-static pa_mutex *lock_fd_mutex = NULL;
-static pa_bool_t taken = FALSE;
-static pa_thread *thread;
-static int pipe_fd[2] = { -1, -1 };
-
-static void destroy_mutex(void) PA_GCC_DESTRUCTOR;
-
-static int ref(void) {
-
-    if (n_ref > 0) {
-
-        pa_assert(pipe_fd[0] >= 0);
-        pa_assert(pipe_fd[1] >= 0);
-
-        n_ref++;
-
-        return 0;
-    }
-
-    pa_assert(lock_fd < 0);
-    pa_assert(!lock_fd_mutex);
-    pa_assert(!taken);
-    pa_assert(!thread);
-    pa_assert(pipe_fd[0] < 0);
-    pa_assert(pipe_fd[1] < 0);
-
-    if (pipe(pipe_fd) < 0)
-        return -1;
-
-    lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
-
-    pa_make_fd_cloexec(pipe_fd[0]);
-    pa_make_fd_cloexec(pipe_fd[1]);
-
-    pa_make_fd_nonblock(pipe_fd[1]);
-    pa_make_fd_nonblock(pipe_fd[0]);
-
-    n_ref = 1;
-    return 0;
-}
-
-static void unref(pa_bool_t after_fork) {
-
-    pa_assert(n_ref > 0);
-    pa_assert(pipe_fd[0] >= 0);
-    pa_assert(pipe_fd[1] >= 0);
-    pa_assert(lock_fd_mutex);
-
-    n_ref--;
-
-    if (n_ref > 0)
-        return;
-
-    pa_assert(!taken);
-
-    if (thread) {
-        pa_thread_free(thread);
-        thread = NULL;
-    }
-
-    pa_mutex_lock(lock_fd_mutex);
-    if (lock_fd >= 0) {
-
-        if (after_fork)
-            pa_close(lock_fd);
-        else {
-            char *lf;
-
-            if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
-                pa_log_warn(_("Cannot access autospawn lock."));
-
-            pa_unlock_lockfile(lf, lock_fd);
-            pa_xfree(lf);
-
-            lock_fd = -1;
-        }
-    }
-    pa_mutex_unlock(lock_fd_mutex);
-
-    pa_mutex_free(lock_fd_mutex);
-    lock_fd_mutex = NULL;
-
-    pa_close(pipe_fd[0]);
-    pa_close(pipe_fd[1]);
-    pipe_fd[0] = pipe_fd[1] = -1;
-}
-
-static void ping(void) {
-    ssize_t s;
-
-    pa_assert(pipe_fd[1] >= 0);
-
-    for (;;) {
-        char x = 'x';
-
-        if ((s = write(pipe_fd[1], &x, 1)) == 1)
-            break;
-
-        pa_assert(s < 0);
-
-        if (errno == EAGAIN)
-            break;
-
-        pa_assert(errno == EINTR);
-    }
-}
-
-static void wait_for_ping(void) {
-    ssize_t s;
-    char x;
-    struct pollfd pfd;
-    int k;
-
-    pa_assert(pipe_fd[0] >= 0);
-
-    memset(&pfd, 0, sizeof(pfd));
-    pfd.fd = pipe_fd[0];
-    pfd.events = POLLIN;
-
-    if ((k = poll(&pfd, 1, -1)) != 1) {
-        pa_assert(k < 0);
-        pa_assert(errno == EINTR);
-    } else if ((s = read(pipe_fd[0], &x, 1)) != 1) {
-        pa_assert(s < 0);
-        pa_assert(errno == EAGAIN);
-    }
-}
-
-static void empty_pipe(void) {
-    char x[16];
-    ssize_t s;
-
-    pa_assert(pipe_fd[0] >= 0);
-
-    if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) {
-        pa_assert(s < 0);
-        pa_assert(errno == EAGAIN);
-    }
-}
-
-static void thread_func(void *u) {
-    int fd;
-    char *lf;
-    sigset_t fullset;
-
-    /* No signals in this thread please */
-    sigfillset(&fullset);
-    pthread_sigmask(SIG_BLOCK, &fullset, NULL);
-
-    if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
-        pa_log_warn(_("Cannot access autospawn lock."));
-        goto finish;
-    }
-
-    if ((fd = pa_lock_lockfile(lf)) < 0)
-        goto finish;
-
-    pa_mutex_lock(lock_fd_mutex);
-    pa_assert(lock_fd < 0);
-    lock_fd = fd;
-    pa_mutex_unlock(lock_fd_mutex);
-
-finish:
-    pa_xfree(lf);
-
-    ping();
-}
-
-static int start_thread(void) {
-
-    if (!thread)
-        if (!(thread = pa_thread_new(thread_func, NULL)))
-            return -1;
-
-    return 0;
-}
-
-static void create_mutex(void) {
-    PA_ONCE_BEGIN {
-        mutex = pa_mutex_new(FALSE, FALSE);
-    } PA_ONCE_END;
-}
-
-static void destroy_mutex(void) {
-
-    if (mutex)
-        pa_mutex_free(mutex);
-}
-
-
-int pa_autospawn_lock_init(void) {
-    int ret = -1;
-
-    create_mutex();
-    pa_mutex_lock(mutex);
-
-    if (ref() < 0)
-        ret = -1;
-    else
-        ret = pipe_fd[0];
-
-    pa_mutex_unlock(mutex);
-
-    return ret;
-}
-
-int pa_autospawn_lock_acquire(pa_bool_t block) {
-    int ret = -1;
-
-    create_mutex();
-    pa_mutex_lock(mutex);
-    pa_assert(n_ref >= 1);
-
-    pa_mutex_lock(lock_fd_mutex);
-
-    for (;;) {
-
-        empty_pipe();
-
-        if (lock_fd >= 0 && !taken) {
-            taken = TRUE;
-            ret = 1;
-            break;
-        }
-
-        if (lock_fd < 0)
-            if (start_thread() < 0)
-                break;
-
-        if (!block) {
-            ret = 0;
-            break;
-        }
-
-        pa_mutex_unlock(lock_fd_mutex);
-        pa_mutex_unlock(mutex);
-
-        wait_for_ping();
-
-        pa_mutex_lock(mutex);
-        pa_mutex_lock(lock_fd_mutex);
-    }
-
-    pa_mutex_unlock(lock_fd_mutex);
-
-    pa_mutex_unlock(mutex);
-
-    return ret;
-}
-
-void pa_autospawn_lock_release(void) {
-
-    create_mutex();
-    pa_mutex_lock(mutex);
-    pa_assert(n_ref >= 1);
-
-    pa_assert(taken);
-    taken = FALSE;
-
-    ping();
-
-    pa_mutex_unlock(mutex);
-}
-
-void pa_autospawn_lock_done(pa_bool_t after_fork) {
-
-    create_mutex();
-    pa_mutex_lock(mutex);
-    pa_assert(n_ref >= 1);
-
-    unref(after_fork);
-
-    pa_mutex_unlock(mutex);
-}
diff --git a/src/pulse/lock-autospawn.h b/src/pulse/lock-autospawn.h
deleted file mode 100644
index c04c4bd..0000000
--- a/src/pulse/lock-autospawn.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef foopulselockautospawnhfoo
-#define foopulselockautospawnhfoo
-
-/***
-  This file is part of PulseAudio.
-
-  Copyright 2008 Lennart Poettering
-
-  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.1 of the
-  License, or (at your option) any later version.
-
-  PulseAudio is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with PulseAudio; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-  USA.
-***/
-
-#include <pulsecore/macro.h>
-
-int pa_autospawn_lock_init(void);
-int pa_autospawn_lock_acquire(pa_bool_t block);
-void pa_autospawn_lock_release(void);
-void pa_autospawn_lock_done(pa_bool_t after_fork);
-
-#endif
diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c
new file mode 100644
index 0000000..d36b669
--- /dev/null
+++ b/src/pulsecore/lock-autospawn.c
@@ -0,0 +1,330 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2008 Lennart Poettering
+
+  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,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/poll.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include <pulse/i18n.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/mutex.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/core-util.h>
+
+#include "lock-autospawn.h"
+
+/* So, why do we have this complex code here with threads and pipes
+ * and stuff? For two reasons: POSIX file locks are per-process, not
+ * per-file descriptor. That means that two contexts within the same
+ * process that try to create the autospawn lock might end up assuming
+ * they both managed to lock the file. And then, POSIX locking
+ * operations are synchronous. If two contexts run from the same event
+ * loop it must be made sure that they do not block each other, but
+ * that the locking operation can happen asynchronously. */
+
+#define AUTOSPAWN_LOCK "autospawn.lock"
+
+static pa_mutex *mutex;
+
+static unsigned n_ref = 0;
+static int lock_fd = -1;
+static pa_mutex *lock_fd_mutex = NULL;
+static pa_bool_t taken = FALSE;
+static pa_thread *thread;
+static int pipe_fd[2] = { -1, -1 };
+
+static void destroy_mutex(void) PA_GCC_DESTRUCTOR;
+
+static int ref(void) {
+
+    if (n_ref > 0) {
+
+        pa_assert(pipe_fd[0] >= 0);
+        pa_assert(pipe_fd[1] >= 0);
+
+        n_ref++;
+
+        return 0;
+    }
+
+    pa_assert(lock_fd < 0);
+    pa_assert(!lock_fd_mutex);
+    pa_assert(!taken);
+    pa_assert(!thread);
+    pa_assert(pipe_fd[0] < 0);
+    pa_assert(pipe_fd[1] < 0);
+
+    if (pipe(pipe_fd) < 0)
+        return -1;
+
+    lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
+
+    pa_make_fd_cloexec(pipe_fd[0]);
+    pa_make_fd_cloexec(pipe_fd[1]);
+
+    pa_make_fd_nonblock(pipe_fd[1]);
+    pa_make_fd_nonblock(pipe_fd[0]);
+
+    n_ref = 1;
+    return 0;
+}
+
+static void unref(pa_bool_t after_fork) {
+
+    pa_assert(n_ref > 0);
+    pa_assert(pipe_fd[0] >= 0);
+    pa_assert(pipe_fd[1] >= 0);
+    pa_assert(lock_fd_mutex);
+
+    n_ref--;
+
+    if (n_ref > 0)
+        return;
+
+    pa_assert(!taken);
+
+    if (thread) {
+        pa_thread_free(thread);
+        thread = NULL;
+    }
+
+    pa_mutex_lock(lock_fd_mutex);
+    if (lock_fd >= 0) {
+
+        if (after_fork)
+            pa_close(lock_fd);
+        else {
+            char *lf;
+
+            if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
+                pa_log_warn(_("Cannot access autospawn lock."));
+
+            pa_unlock_lockfile(lf, lock_fd);
+            pa_xfree(lf);
+
+            lock_fd = -1;
+        }
+    }
+    pa_mutex_unlock(lock_fd_mutex);
+
+    pa_mutex_free(lock_fd_mutex);
+    lock_fd_mutex = NULL;
+
+    pa_close(pipe_fd[0]);
+    pa_close(pipe_fd[1]);
+    pipe_fd[0] = pipe_fd[1] = -1;
+}
+
+static void ping(void) {
+    ssize_t s;
+
+    pa_assert(pipe_fd[1] >= 0);
+
+    for (;;) {
+        char x = 'x';
+
+        if ((s = write(pipe_fd[1], &x, 1)) == 1)
+            break;
+
+        pa_assert(s < 0);
+
+        if (errno == EAGAIN)
+            break;
+
+        pa_assert(errno == EINTR);
+    }
+}
+
+static void wait_for_ping(void) {
+    ssize_t s;
+    char x;
+    struct pollfd pfd;
+    int k;
+
+    pa_assert(pipe_fd[0] >= 0);
+
+    memset(&pfd, 0, sizeof(pfd));
+    pfd.fd = pipe_fd[0];
+    pfd.events = POLLIN;
+
+    if ((k = poll(&pfd, 1, -1)) != 1) {
+        pa_assert(k < 0);
+        pa_assert(errno == EINTR);
+    } else if ((s = read(pipe_fd[0], &x, 1)) != 1) {
+        pa_assert(s < 0);
+        pa_assert(errno == EAGAIN);
+    }
+}
+
+static void empty_pipe(void) {
+    char x[16];
+    ssize_t s;
+
+    pa_assert(pipe_fd[0] >= 0);
+
+    if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) {
+        pa_assert(s < 0);
+        pa_assert(errno == EAGAIN);
+    }
+}
+
+static void thread_func(void *u) {
+    int fd;
+    char *lf;
+    sigset_t fullset;
+
+    /* No signals in this thread please */
+    sigfillset(&fullset);
+    pthread_sigmask(SIG_BLOCK, &fullset, NULL);
+
+    if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
+        pa_log_warn(_("Cannot access autospawn lock."));
+        goto finish;
+    }
+
+    if ((fd = pa_lock_lockfile(lf)) < 0)
+        goto finish;
+
+    pa_mutex_lock(lock_fd_mutex);
+    pa_assert(lock_fd < 0);
+    lock_fd = fd;
+    pa_mutex_unlock(lock_fd_mutex);
+
+finish:
+    pa_xfree(lf);
+
+    ping();
+}
+
+static int start_thread(void) {
+
+    if (!thread)
+        if (!(thread = pa_thread_new(thread_func, NULL)))
+            return -1;
+
+    return 0;
+}
+
+static void create_mutex(void) {
+    PA_ONCE_BEGIN {
+        mutex = pa_mutex_new(FALSE, FALSE);
+    } PA_ONCE_END;
+}
+
+static void destroy_mutex(void) {
+
+    if (mutex)
+        pa_mutex_free(mutex);
+}
+
+
+int pa_autospawn_lock_init(void) {
+    int ret = -1;
+
+    create_mutex();
+    pa_mutex_lock(mutex);
+
+    if (ref() < 0)
+        ret = -1;
+    else
+        ret = pipe_fd[0];
+
+    pa_mutex_unlock(mutex);
+
+    return ret;
+}
+
+int pa_autospawn_lock_acquire(pa_bool_t block) {
+    int ret = -1;
+
+    create_mutex();
+    pa_mutex_lock(mutex);
+    pa_assert(n_ref >= 1);
+
+    pa_mutex_lock(lock_fd_mutex);
+
+    for (;;) {
+
+        empty_pipe();
+
+        if (lock_fd >= 0 && !taken) {
+            taken = TRUE;
+            ret = 1;
+            break;
+        }
+
+        if (lock_fd < 0)
+            if (start_thread() < 0)
+                break;
+
+        if (!block) {
+            ret = 0;
+            break;
+        }
+
+        pa_mutex_unlock(lock_fd_mutex);
+        pa_mutex_unlock(mutex);
+
+        wait_for_ping();
+
+        pa_mutex_lock(mutex);
+        pa_mutex_lock(lock_fd_mutex);
+    }
+
+    pa_mutex_unlock(lock_fd_mutex);
+
+    pa_mutex_unlock(mutex);
+
+    return ret;
+}
+
+void pa_autospawn_lock_release(void) {
+
+    create_mutex();
+    pa_mutex_lock(mutex);
+    pa_assert(n_ref >= 1);
+
+    pa_assert(taken);
+    taken = FALSE;
+
+    ping();
+
+    pa_mutex_unlock(mutex);
+}
+
+void pa_autospawn_lock_done(pa_bool_t after_fork) {
+
+    create_mutex();
+    pa_mutex_lock(mutex);
+    pa_assert(n_ref >= 1);
+
+    unref(after_fork);
+
+    pa_mutex_unlock(mutex);
+}
diff --git a/src/pulsecore/lock-autospawn.h b/src/pulsecore/lock-autospawn.h
new file mode 100644
index 0000000..c04c4bd
--- /dev/null
+++ b/src/pulsecore/lock-autospawn.h
@@ -0,0 +1,32 @@
+#ifndef foopulselockautospawnhfoo
+#define foopulselockautospawnhfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2008 Lennart Poettering
+
+  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.1 of the
+  License, or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <pulsecore/macro.h>
+
+int pa_autospawn_lock_init(void);
+int pa_autospawn_lock_acquire(pa_bool_t block);
+void pa_autospawn_lock_release(void);
+void pa_autospawn_lock_done(pa_bool_t after_fork);
+
+#endif
diff --git a/src/tests/lock-autospawn-test.c b/src/tests/lock-autospawn-test.c
index cb3dc87..80cfda6 100644
--- a/src/tests/lock-autospawn-test.c
+++ b/src/tests/lock-autospawn-test.c
@@ -28,7 +28,7 @@
 
 #include <pulsecore/macro.h>
 #include <pulsecore/thread.h>
-#include <pulse/lock-autospawn.h>
+#include <pulsecore/lock-autospawn.h>
 #include <pulse/util.h>
 
 static void thread_func(void*k) {

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list