[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v1.0-dev-300-geea248e

Colin Guthrie gitmailer-noreply at 0pointer.de
Sat Apr 30 07:45:51 PDT 2011


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  2f7eb35f370bb79c12f229d109fc4dd2b74c9f47 (commit)

- Log -----------------------------------------------------------------
eea248e build-system: Small fixes
155f2d5 build-system: Rearrange database selection
96d0ecb build-system: Replace some more conditionals with AS_IF
6da83d3 build-system: Move dependency error messages to outer scope
459b5ef build-system: Move AC_DEFINE to separate line with AS_IF
78d174c build-system: Use AS_IF macro for configure output
18e5d0d build-system: Simplify AC_ARG_ENABLE usage
512baa1 combine: Rename module-combine to module-combine-sink.
94e12b9 bluetooth: Only close SCO if status has changed
6f99198 bluetooth: Fix using pointer-pointer when appending an array as variant
9542211 bluetooth: Fix not updating sample spec when using Media API
adb16f9 x11: More XCB fixes.
-----------------------------------------------------------------------

Summary of changes:
 configure.ac                                       | 1090 +++++-----------
 src/Makefile.am                                    |    6 +
 src/modules/bluetooth/bluetooth-util.c             |    6 +-
 src/modules/bluetooth/module-bluetooth-device.c    |   23 +-
 .../{module-combine.c => module-combine-sink.c}    |    2 +-
 src/modules/module-combine.c                       | 1366 +-------------------
 src/pulsecore/x11prop.c                            |   38 +-
 7 files changed, 384 insertions(+), 2147 deletions(-)
 copy src/modules/{module-combine.c => module-combine-sink.c} (99%)

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

commit adb16f9ff42008c5b8f76133d8879fc15a82533f
Author: Arnaud Fontaine <arnau at debian.org>
Date:   Tue Mar 29 22:56:28 2011 +0159

    x11: More XCB fixes.
    
    Commit 65ef80b fixed building with xcb-util >= 0.3.8, but the reply is never
    checked (possible SIGSEGV if the reply is NULL) nor freed (memory leak at each
    call of the functions).
    
    Also, remove include and dependencies on xcb-atom, as it was only meaningful
    for xcb_atom_get() and STRING, and depend instead on xcb >= 1.6 for
    XCB_ATOM_STRING.

diff --git a/configure.ac b/configure.ac
index 980d148..76cf7e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -591,7 +591,7 @@ AC_ARG_ENABLE([x11],
         [x11=auto])
 
 if test "x${x11}" != xno ; then
-    PKG_CHECK_MODULES(X11, [ x11-xcb ice sm xtst xcb-atom ],
+    PKG_CHECK_MODULES(X11, [ x11-xcb xcb >= 1.6 ice sm xtst ],
         HAVE_X11=1,
         [
             HAVE_X11=0
diff --git a/src/pulsecore/x11prop.c b/src/pulsecore/x11prop.c
index 99ea55d..baf5b01 100644
--- a/src/pulsecore/x11prop.c
+++ b/src/pulsecore/x11prop.c
@@ -30,7 +30,6 @@
 #include <pulsecore/macro.h>
 
 #include <xcb/xproto.h>
-#include <xcb/xcb_atom.h>
 
 #define PA_XCB_FORMAT 8
 
@@ -49,7 +48,6 @@ static xcb_screen_t *screen_of_display(xcb_connection_t *xcb, int screen) {
 
 void pa_x11_set_prop(xcb_connection_t *xcb, int screen, const char *name, const char *data) {
     xcb_screen_t *xs;
-    xcb_intern_atom_cookie_t cookie;
     xcb_intern_atom_reply_t *reply;
 
     pa_assert(xcb);
@@ -57,26 +55,36 @@ void pa_x11_set_prop(xcb_connection_t *xcb, int screen, const char *name, const
     pa_assert(data);
 
     if ((xs = screen_of_display(xcb, screen))) {
-        cookie = xcb_intern_atom(xcb, 0, strlen(name), name);
-        reply = xcb_intern_atom_reply(xcb, cookie, NULL);
+        reply = xcb_intern_atom_reply(xcb,
+                                      xcb_intern_atom(xcb, 0, strlen(name), name),
+                                      NULL);
 
-        xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, xs->root, reply->atom, XCB_ATOM_STRING, PA_XCB_FORMAT, (int) strlen(data), (const void*) data);
+        if (reply) {
+            xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, xs->root, reply->atom,
+                                XCB_ATOM_STRING, PA_XCB_FORMAT,
+                                (int) strlen(data), (const void*) data);
+
+            free(reply);
+        }
     }
 }
 
 void pa_x11_del_prop(xcb_connection_t *xcb, int screen, const char *name) {
     xcb_screen_t *xs;
-    xcb_intern_atom_cookie_t cookie;
     xcb_intern_atom_reply_t *reply;
 
     pa_assert(xcb);
     pa_assert(name);
 
     if ((xs = screen_of_display(xcb, screen))) {
-        cookie = xcb_intern_atom(xcb, 0, strlen(name), name);
-        reply = xcb_intern_atom_reply(xcb, cookie, NULL);
-
-        xcb_delete_property(xcb, xs->root, reply->atom);
+        reply = xcb_intern_atom_reply(xcb,
+                                      xcb_intern_atom(xcb, 0, strlen(name), name),
+                                      NULL);
+
+        if (reply) {
+            xcb_delete_property(xcb, xs->root, reply->atom);
+            free(reply);
+        }
     }
 }
 
@@ -86,7 +94,6 @@ char* pa_x11_get_prop(xcb_connection_t *xcb, int screen, const char *name, char
     xcb_get_property_cookie_t req;
     xcb_get_property_reply_t* prop = NULL;
     xcb_screen_t *xs;
-    xcb_intern_atom_cookie_t cookie;
     xcb_intern_atom_reply_t *reply;
 
     pa_assert(xcb);
@@ -105,10 +112,15 @@ char* pa_x11_get_prop(xcb_connection_t *xcb, int screen, const char *name, char
         xs = screen_of_display(xcb, 0);
 
     if (xs) {
-        cookie = xcb_intern_atom(xcb, 0, strlen(name), name);
-        reply = xcb_intern_atom_reply(xcb, cookie, NULL);
+        reply = xcb_intern_atom_reply(xcb,
+                                      xcb_intern_atom(xcb, 0, strlen(name), name),
+                                      NULL);
+
+        if (!reply)
+            goto finish;
 
         req = xcb_get_property(xcb, 0, xs->root, reply->atom, XCB_ATOM_STRING, 0, (uint32_t)(l-1));
+        free(reply);
         prop = xcb_get_property_reply(xcb, req, NULL);
 
         if (!prop)

commit 95422110ba2492d1e8b466b3bc0592eaa8b895ec
Author: Luiz Augusto von Dentz <luiz.dentz-von at nokia.com>
Date:   Fri Apr 29 17:48:05 2011 +0300

    bluetooth: Fix not updating sample spec when using Media API
    
    When using transport configured via Media API sample spec needs to be
    updated since codec configuration may affect it when e.g. headset
    configure a different frequency or number of channels from default.

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index bbd57ed..6d2679d 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2156,6 +2156,8 @@ static int bt_transport_config_a2dp(struct userdata *u) {
 
     config = (a2dp_sbc_t *) t->config;
 
+    u->sample_spec.format = PA_SAMPLE_S16LE;
+
     if (a2dp->sbc_initialized)
         sbc_reinit(&a2dp->sbc, 0);
     else
@@ -2165,15 +2167,19 @@ static int bt_transport_config_a2dp(struct userdata *u) {
     switch (config->frequency) {
         case BT_SBC_SAMPLING_FREQ_16000:
             a2dp->sbc.frequency = SBC_FREQ_16000;
+            u->sample_spec.rate = 16000U;
             break;
         case BT_SBC_SAMPLING_FREQ_32000:
             a2dp->sbc.frequency = SBC_FREQ_32000;
+            u->sample_spec.rate = 32000U;
             break;
         case BT_SBC_SAMPLING_FREQ_44100:
             a2dp->sbc.frequency = SBC_FREQ_44100;
+            u->sample_spec.rate = 44100U;
             break;
         case BT_SBC_SAMPLING_FREQ_48000:
             a2dp->sbc.frequency = SBC_FREQ_48000;
+            u->sample_spec.rate = 48000U;
             break;
         default:
             pa_assert_not_reached();
@@ -2182,15 +2188,19 @@ static int bt_transport_config_a2dp(struct userdata *u) {
     switch (config->channel_mode) {
         case BT_A2DP_CHANNEL_MODE_MONO:
             a2dp->sbc.mode = SBC_MODE_MONO;
+            u->sample_spec.channels = 1;
             break;
         case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
             a2dp->sbc.mode = SBC_MODE_DUAL_CHANNEL;
+            u->sample_spec.channels = 2;
             break;
         case BT_A2DP_CHANNEL_MODE_STEREO:
             a2dp->sbc.mode = SBC_MODE_STEREO;
+            u->sample_spec.channels = 2;
             break;
         case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
             a2dp->sbc.mode = SBC_MODE_JOINT_STEREO;
+            u->sample_spec.channels = 2;
             break;
         default:
             pa_assert_not_reached();
@@ -2257,6 +2267,9 @@ static int bt_transport_config_a2dp(struct userdata *u) {
 static int bt_transport_config(struct userdata *u) {
     if (u->profile == PROFILE_HSP || u->profile == PROFILE_HFGW) {
         u->block_size = u->link_mtu;
+        u->sample_spec.format = PA_SAMPLE_S16LE;
+        u->sample_spec.channels = 1;
+        u->sample_spec.rate = 8000;
         return 0;
     }
 

commit 6f99198c41f7f5be466d942beca2e4e2c129e70d
Author: Luiz Augusto von Dentz <luiz.dentz-von at nokia.com>
Date:   Fri Apr 29 17:48:06 2011 +0300

    bluetooth: Fix using pointer-pointer when appending an array as variant
    
    pa_dbus_append_basic_array_variant_dict_entry should take the direct
    pointer to the array.

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 740b317..597a39d 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -631,11 +631,9 @@ static void register_endpoint(pa_bluetooth_discovery *y, const char *path, const
 
     if (pa_streq(uuid, HFP_AG_UUID)) {
         uint8_t capability = 0;
-        uint8_t *caps = &capability;
-        pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &caps, 1);
+        pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &capability, 1);
     } else {
         a2dp_sbc_t capabilities;
-        uint8_t *caps = (uint8_t *) &capabilities;
 
         capabilities.channel_mode = BT_A2DP_CHANNEL_MODE_MONO | BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL |
                                     BT_A2DP_CHANNEL_MODE_STEREO | BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
@@ -648,7 +646,7 @@ static void register_endpoint(pa_bluetooth_discovery *y, const char *path, const
         capabilities.min_bitpool = MIN_BITPOOL;
         capabilities.max_bitpool = MAX_BITPOOL;
 
-        pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &caps, sizeof(capabilities));
+        pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &capabilities, sizeof(capabilities));
     }
 
     dbus_message_iter_close_container(&i, &d);

commit 94e12b9aec4682d3b990bf454a80a0ca447c3f19
Author: Luiz Augusto von Dentz <luiz.dentz-von at nokia.com>
Date:   Fri Apr 29 17:48:07 2011 +0300

    bluetooth: Only close SCO if status has changed
    
    In case the io thread is starting there is no point on closing SCO just
    to resume it latter when the source/sink changes to opened state.

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 6d2679d..086fce9 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1916,7 +1916,7 @@ static char *get_name(const char *type, pa_modargs *ma, const char *device_id, p
     return pa_sprintf_malloc("bluez_%s.%s", type, n);
 }
 
-static int sco_over_pcm_state_update(struct userdata *u) {
+static int sco_over_pcm_state_update(struct userdata *u, pa_bool_t changed) {
     pa_assert(u);
     pa_assert(USE_SCO_OVER_PCM(u));
 
@@ -1939,7 +1939,7 @@ static int sco_over_pcm_state_update(struct userdata *u) {
         else
             return start_stream_fd(u);
 
-    } else {
+    } else if (changed) {
         if (u->service_fd < 0 && u->stream_fd < 0)
             return 0;
 
@@ -1967,7 +1967,7 @@ static pa_hook_result_t sink_state_changed_cb(pa_core *c, pa_sink *s, struct use
     if (s != u->hsp.sco_sink)
         return PA_HOOK_OK;
 
-    sco_over_pcm_state_update(u);
+    sco_over_pcm_state_update(u, TRUE);
 
     return PA_HOOK_OK;
 }
@@ -1980,7 +1980,7 @@ static pa_hook_result_t source_state_changed_cb(pa_core *c, pa_source *s, struct
     if (s != u->hsp.sco_source)
         return PA_HOOK_OK;
 
-    sco_over_pcm_state_update(u);
+    sco_over_pcm_state_update(u, TRUE);
 
     return PA_HOOK_OK;
 }
@@ -2447,7 +2447,7 @@ static int start_thread(struct userdata *u) {
     pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
 
     if (USE_SCO_OVER_PCM(u)) {
-        if (sco_over_pcm_state_update(u) < 0) {
+        if (sco_over_pcm_state_update(u, FALSE) < 0) {
             char *k;
 
             if (u->sink) {

commit 512baa1a1fdb58f2d39882ac9d1660da7b8b21be
Author: Colin Guthrie <colin at mageia.org>
Date:   Fri Apr 29 16:40:50 2011 +0100

    combine: Rename module-combine to module-combine-sink.
    
    This also includes a compatibility module that will ultimately be removed in
    a future release.

diff --git a/src/Makefile.am b/src/Makefile.am
index a6a16ea..23d809d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1042,6 +1042,7 @@ modlibexec_LTLIBRARIES += \
 		module-native-protocol-fd.la \
 		module-esound-protocol-tcp.la \
 		module-combine.la \
+		module-combine-sink.la \
 		module-remap-sink.la \
 		module-ladspa-sink.la \
 		module-esound-sink.la \
@@ -1279,6 +1280,7 @@ SYMDEF_FILES = \
 		module-native-protocol-fd-symdef.h \
 		module-sine-symdef.h \
 		module-combine-symdef.h \
+		module-combine-sink-symdef.h \
 		module-remap-sink-symdef.h \
 		module-ladspa-sink-symdef.h \
 		module-equalizer-sink-symdef.h \
@@ -1492,6 +1494,10 @@ module_combine_la_SOURCES = modules/module-combine.c
 module_combine_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_combine_la_LIBADD = $(MODULE_LIBADD)
 
+module_combine_sink_la_SOURCES = modules/module-combine-sink.c
+module_combine_sink_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_combine_sink_la_LIBADD = $(MODULE_LIBADD)
+
 module_switch_on_connect_la_SOURCES = modules/module-switch-on-connect.c
 module_switch_on_connect_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_switch_on_connect_la_LIBADD = $(MODULE_LIBADD)
diff --git a/src/modules/module-combine-sink.c b/src/modules/module-combine-sink.c
new file mode 100644
index 0000000..09af942
--- /dev/null
+++ b/src/modules/module-combine-sink.c
@@ -0,0 +1,1409 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-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
+  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 <stdio.h>
+#include <errno.h>
+
+#include <pulse/rtclock.h>
+#include <pulse/timeval.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/module.h>
+#include <pulsecore/llist.h>
+#include <pulsecore/sink.h>
+#include <pulsecore/sink-input.h>
+#include <pulsecore/memblockq.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-rtclock.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/modargs.h>
+#include <pulsecore/namereg.h>
+#include <pulsecore/mutex.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/thread-mq.h>
+#include <pulsecore/rtpoll.h>
+#include <pulsecore/core-error.h>
+#include <pulsecore/time-smoother.h>
+#include <pulsecore/strlist.h>
+
+#include "module-combine-sink-symdef.h"
+
+PA_MODULE_AUTHOR("Lennart Poettering");
+PA_MODULE_DESCRIPTION("Combine multiple sinks to one");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(FALSE);
+PA_MODULE_USAGE(
+        "sink_name=<name for the sink> "
+        "sink_properties=<properties for the sink> "
+        "slaves=<slave sinks> "
+        "adjust_time=<how often to readjust rates in s> "
+        "resample_method=<method> "
+        "format=<sample format> "
+        "rate=<sample rate> "
+        "channels=<number of channels> "
+        "channel_map=<channel map>");
+
+#define DEFAULT_SINK_NAME "combined"
+
+#define MEMBLOCKQ_MAXLENGTH (1024*1024*16)
+
+#define DEFAULT_ADJUST_TIME_USEC (10*PA_USEC_PER_SEC)
+
+#define BLOCK_USEC (PA_USEC_PER_MSEC * 200)
+
+static const char* const valid_modargs[] = {
+    "sink_name",
+    "sink_properties",
+    "slaves",
+    "adjust_time",
+    "resample_method",
+    "format",
+    "rate",
+    "channels",
+    "channel_map",
+    NULL
+};
+
+struct output {
+    struct userdata *userdata;
+
+    pa_sink *sink;
+    pa_sink_input *sink_input;
+    pa_bool_t ignore_state_change;
+
+    pa_asyncmsgq *inq,    /* Message queue from the sink thread to this sink input */
+                 *outq;   /* Message queue from this sink input to the sink thread */
+    pa_rtpoll_item *inq_rtpoll_item_read, *inq_rtpoll_item_write;
+    pa_rtpoll_item *outq_rtpoll_item_read, *outq_rtpoll_item_write;
+
+    pa_memblockq *memblockq;
+
+    /* For communication of the stream latencies to the main thread */
+    pa_usec_t total_latency;
+
+    /* For coomunication of the stream parameters to the sink thread */
+    pa_atomic_t max_request;
+    pa_atomic_t requested_latency;
+
+    PA_LLIST_FIELDS(struct output);
+};
+
+struct userdata {
+    pa_core *core;
+    pa_module *module;
+    pa_sink *sink;
+
+    pa_thread *thread;
+    pa_thread_mq thread_mq;
+    pa_rtpoll *rtpoll;
+
+    pa_time_event *time_event;
+    pa_usec_t adjust_time;
+
+    pa_bool_t automatic;
+    pa_bool_t auto_desc;
+
+    pa_strlist *unlinked_slaves;
+
+    pa_hook_slot *sink_put_slot, *sink_unlink_slot, *sink_state_changed_slot;
+
+    pa_resample_method_t resample_method;
+
+    pa_usec_t block_usec;
+
+    pa_idxset* outputs; /* managed in main context */
+
+    struct {
+        PA_LLIST_HEAD(struct output, active_outputs); /* managed in IO thread context */
+        pa_atomic_t running;  /* we cache that value here, so that every thread can query it cheaply */
+        pa_usec_t timestamp;
+        pa_bool_t in_null_mode;
+        pa_smoother *smoother;
+        uint64_t counter;
+    } thread_info;
+};
+
+enum {
+    SINK_MESSAGE_ADD_OUTPUT = PA_SINK_MESSAGE_MAX,
+    SINK_MESSAGE_REMOVE_OUTPUT,
+    SINK_MESSAGE_NEED,
+    SINK_MESSAGE_UPDATE_LATENCY,
+    SINK_MESSAGE_UPDATE_MAX_REQUEST,
+    SINK_MESSAGE_UPDATE_REQUESTED_LATENCY
+};
+
+enum {
+    SINK_INPUT_MESSAGE_POST = PA_SINK_INPUT_MESSAGE_MAX,
+};
+
+static void output_disable(struct output *o);
+static void output_enable(struct output *o);
+static void output_free(struct output *o);
+static int output_create_sink_input(struct output *o);
+
+static void adjust_rates(struct userdata *u) {
+    struct output *o;
+    pa_usec_t max_sink_latency = 0, min_total_latency = (pa_usec_t) -1, target_latency, avg_total_latency = 0;
+    uint32_t base_rate;
+    uint32_t idx;
+    unsigned n = 0;
+
+    pa_assert(u);
+    pa_sink_assert_ref(u->sink);
+
+    if (pa_idxset_size(u->outputs) <= 0)
+        return;
+
+    if (!PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)))
+        return;
+
+    PA_IDXSET_FOREACH(o, u->outputs, idx) {
+        pa_usec_t sink_latency;
+
+        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
+            continue;
+
+        o->total_latency = pa_sink_input_get_latency(o->sink_input, &sink_latency);
+        o->total_latency += sink_latency;
+
+        if (sink_latency > max_sink_latency)
+            max_sink_latency = sink_latency;
+
+        if (min_total_latency == (pa_usec_t) -1 || o->total_latency < min_total_latency)
+            min_total_latency = o->total_latency;
+
+        avg_total_latency += o->total_latency;
+        n++;
+
+        pa_log_debug("[%s] total=%0.2fms sink=%0.2fms ", o->sink->name, (double) o->total_latency / PA_USEC_PER_MSEC, (double) sink_latency / PA_USEC_PER_MSEC);
+
+        if (o->total_latency > 10*PA_USEC_PER_SEC)
+            pa_log_warn("[%s] Total latency of output is very high (%0.2fms), most likely the audio timing in one of your drivers is broken.", o->sink->name, (double) o->total_latency / PA_USEC_PER_MSEC);
+    }
+
+    if (min_total_latency == (pa_usec_t) -1)
+        return;
+
+    avg_total_latency /= n;
+
+    target_latency = max_sink_latency > min_total_latency ? max_sink_latency : min_total_latency;
+
+    pa_log_info("[%s] avg total latency is %0.2f msec.", u->sink->name, (double) avg_total_latency / PA_USEC_PER_MSEC);
+    pa_log_info("[%s] target latency is %0.2f msec.", u->sink->name, (double) target_latency / PA_USEC_PER_MSEC);
+
+    base_rate = u->sink->sample_spec.rate;
+
+    PA_IDXSET_FOREACH(o, u->outputs, idx) {
+        uint32_t new_rate = base_rate;
+        uint32_t current_rate = o->sink_input->sample_spec.rate;
+
+        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
+            continue;
+
+        if (o->total_latency != target_latency)
+            new_rate += (uint32_t) (((double) o->total_latency - (double) target_latency) / (double) u->adjust_time * (double) new_rate);
+
+        if (new_rate < (uint32_t) (base_rate*0.8) || new_rate > (uint32_t) (base_rate*1.25)) {
+            pa_log_warn("[%s] sample rates too different, not adjusting (%u vs. %u).", o->sink_input->sink->name, base_rate, new_rate);
+            new_rate = base_rate;
+        } else {
+            if (base_rate < new_rate + 20 && new_rate < base_rate + 20)
+              new_rate = base_rate;
+            /* Do the adjustment in small steps; 2‰ can be considered inaudible */
+            if (new_rate < (uint32_t) (current_rate*0.998) || new_rate > (uint32_t) (current_rate*1.002)) {
+                pa_log_info("[%s] new rate of %u Hz not within 2‰ of %u Hz, forcing smaller adjustment", o->sink_input->sink->name, new_rate, current_rate);
+                new_rate = PA_CLAMP(new_rate, (uint32_t) (current_rate*0.998), (uint32_t) (current_rate*1.002));
+            }
+            pa_log_info("[%s] new rate is %u Hz; ratio is %0.3f; latency is %0.2f msec.", o->sink_input->sink->name, new_rate, (double) new_rate / base_rate, (double) o->total_latency / PA_USEC_PER_MSEC);
+        }
+        pa_sink_input_set_rate(o->sink_input, new_rate);
+    }
+
+    pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, NULL, (int64_t) avg_total_latency, NULL);
+}
+
+static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct timeval *t, void *userdata) {
+    struct userdata *u = userdata;
+
+    pa_assert(u);
+    pa_assert(a);
+    pa_assert(u->time_event == e);
+
+    adjust_rates(u);
+
+    pa_core_rttime_restart(u->core, e, pa_rtclock_now() + u->adjust_time);
+}
+
+static void process_render_null(struct userdata *u, pa_usec_t now) {
+    size_t ate = 0;
+    pa_assert(u);
+
+    if (u->thread_info.in_null_mode)
+        u->thread_info.timestamp = now;
+
+    while (u->thread_info.timestamp < now + u->block_usec) {
+        pa_memchunk chunk;
+
+        pa_sink_render(u->sink, u->sink->thread_info.max_request, &chunk);
+        pa_memblock_unref(chunk.memblock);
+
+        u->thread_info.counter += chunk.length;
+
+/*         pa_log_debug("Ate %lu bytes.", (unsigned long) chunk.length); */
+        u->thread_info.timestamp += pa_bytes_to_usec(chunk.length, &u->sink->sample_spec);
+
+        ate += chunk.length;
+
+        if (ate >= u->sink->thread_info.max_request)
+            break;
+    }
+
+/*     pa_log_debug("Ate in sum %lu bytes (of %lu)", (unsigned long) ate, (unsigned long) nbytes); */
+
+    pa_smoother_put(u->thread_info.smoother, now,
+                    pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec) - (u->thread_info.timestamp - now));
+}
+
+static void thread_func(void *userdata) {
+    struct userdata *u = userdata;
+
+    pa_assert(u);
+
+    pa_log_debug("Thread starting up");
+
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority+1);
+
+    pa_thread_mq_install(&u->thread_mq);
+
+    u->thread_info.timestamp = pa_rtclock_now();
+    u->thread_info.in_null_mode = FALSE;
+
+    for (;;) {
+        int ret;
+
+        if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
+            if (u->sink->thread_info.rewind_requested)
+                pa_sink_process_rewind(u->sink, 0);
+
+        /* If no outputs are connected, render some data and drop it immediately. */
+        if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && !u->thread_info.active_outputs) {
+            pa_usec_t now;
+
+            now = pa_rtclock_now();
+
+            if (!u->thread_info.in_null_mode || u->thread_info.timestamp <= now)
+                process_render_null(u, now);
+
+            pa_rtpoll_set_timer_absolute(u->rtpoll, u->thread_info.timestamp);
+            u->thread_info.in_null_mode = TRUE;
+        } else {
+            pa_rtpoll_set_timer_disabled(u->rtpoll);
+            u->thread_info.in_null_mode = FALSE;
+        }
+
+        /* Hmm, nothing to do. Let's sleep */
+        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) {
+            pa_log_info("pa_rtpoll_run() = %i", ret);
+            goto fail;
+        }
+
+        if (ret == 0)
+            goto finish;
+    }
+
+fail:
+    /* If this was no regular exit from the loop we have to continue
+     * processing messages until we received PA_MESSAGE_SHUTDOWN */
+    pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
+    pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
+
+finish:
+    pa_log_debug("Thread shutting down");
+}
+
+/* Called from I/O thread context */
+static void render_memblock(struct userdata *u, struct output *o, size_t length) {
+    pa_assert(u);
+    pa_assert(o);
+
+    /* We are run by the sink thread, on behalf of an output (o). The
+     * output is waiting for us, hence it is safe to access its
+     * mainblockq and asyncmsgq directly. */
+
+    /* If we are not running, we cannot produce any data */
+    if (!pa_atomic_load(&u->thread_info.running))
+        return;
+
+    /* Maybe there's some data in the requesting output's queue
+     * now? */
+    while (pa_asyncmsgq_process_one(o->inq) > 0)
+        ;
+
+    /* Ok, now let's prepare some data if we really have to */
+    while (!pa_memblockq_is_readable(o->memblockq)) {
+        struct output *j;
+        pa_memchunk chunk;
+
+        /* Render data! */
+        pa_sink_render(u->sink, length, &chunk);
+
+        u->thread_info.counter += chunk.length;
+
+        /* OK, let's send this data to the other threads */
+        PA_LLIST_FOREACH(j, u->thread_info.active_outputs) {
+            if (j == o)
+                continue;
+
+            pa_asyncmsgq_post(j->inq, PA_MSGOBJECT(j->sink_input), SINK_INPUT_MESSAGE_POST, NULL, 0, &chunk, NULL);
+        }
+
+        /* And place it directly into the requesting output's queue */
+        pa_memblockq_push_align(o->memblockq, &chunk);
+        pa_memblock_unref(chunk.memblock);
+    }
+}
+
+/* Called from I/O thread context */
+static void request_memblock(struct output *o, size_t length) {
+    pa_assert(o);
+    pa_sink_input_assert_ref(o->sink_input);
+    pa_sink_assert_ref(o->userdata->sink);
+
+    /* If another thread already prepared some data we received
+     * the data over the asyncmsgq, hence let's first process
+     * it. */
+    while (pa_asyncmsgq_process_one(o->inq) > 0)
+        ;
+
+    /* Check whether we're now readable */
+    if (pa_memblockq_is_readable(o->memblockq))
+        return;
+
+    /* OK, we need to prepare new data, but only if the sink is actually running */
+    if (pa_atomic_load(&o->userdata->thread_info.running))
+        pa_asyncmsgq_send(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_NEED, o, (int64_t) length, NULL);
+}
+
+/* Called from I/O thread context */
+static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    /* If necessary, get some new data */
+    request_memblock(o, nbytes);
+
+    /* pa_log("%s q size is %u + %u (%u/%u)", */
+    /*        i->sink->name, */
+    /*        pa_memblockq_get_nblocks(o->memblockq), */
+    /*        pa_memblockq_get_nblocks(i->thread_info.render_memblockq), */
+    /*        pa_memblockq_get_maxrewind(o->memblockq), */
+    /*        pa_memblockq_get_maxrewind(i->thread_info.render_memblockq)); */
+
+    if (pa_memblockq_peek(o->memblockq, chunk) < 0)
+        return -1;
+
+    pa_memblockq_drop(o->memblockq, chunk->length);
+
+    return 0;
+}
+
+/* Called from I/O thread context */
+static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    pa_memblockq_rewind(o->memblockq, nbytes);
+}
+
+/* Called from I/O thread context */
+static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    pa_memblockq_set_maxrewind(o->memblockq, nbytes);
+}
+
+/* Called from I/O thread context */
+static void sink_input_update_max_request_cb(pa_sink_input *i, size_t nbytes) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    if (pa_atomic_load(&o->max_request) == (int) nbytes)
+        return;
+
+    pa_atomic_store(&o->max_request, (int) nbytes);
+    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_MAX_REQUEST, NULL, 0, NULL, NULL);
+}
+
+/* Called from thread context */
+static void sink_input_update_sink_requested_latency_cb(pa_sink_input *i) {
+    struct output *o;
+    pa_usec_t c;
+
+    pa_assert(i);
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    c = pa_sink_get_requested_latency_within_thread(i->sink);
+
+    if (c == (pa_usec_t) -1)
+        c = i->sink->thread_info.max_latency;
+
+    if (pa_atomic_load(&o->requested_latency) == (int) c)
+        return;
+
+    pa_atomic_store(&o->requested_latency, (int) c);
+    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_REQUESTED_LATENCY, NULL, 0, NULL, NULL);
+}
+
+/* Called from I/O thread context */
+static void sink_input_attach_cb(pa_sink_input *i) {
+    struct output *o;
+    pa_usec_t c;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    /* Set up the queue from the sink thread to us */
+    pa_assert(!o->inq_rtpoll_item_read && !o->outq_rtpoll_item_write);
+
+    o->inq_rtpoll_item_read = pa_rtpoll_item_new_asyncmsgq_read(
+            i->sink->thread_info.rtpoll,
+            PA_RTPOLL_LATE,  /* This one is not that important, since we check for data in _peek() anyway. */
+            o->inq);
+
+    o->outq_rtpoll_item_write = pa_rtpoll_item_new_asyncmsgq_write(
+            i->sink->thread_info.rtpoll,
+            PA_RTPOLL_EARLY,
+            o->outq);
+
+    pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
+
+    pa_atomic_store(&o->max_request, (int) pa_sink_input_get_max_request(i));
+
+    c = pa_sink_get_requested_latency_within_thread(i->sink);
+    pa_atomic_store(&o->requested_latency, (int) (c == (pa_usec_t) -1 ? 0 : c));
+
+    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_MAX_REQUEST, NULL, 0, NULL, NULL);
+    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_REQUESTED_LATENCY, NULL, 0, NULL, NULL);
+}
+
+/* Called from I/O thread context */
+static void sink_input_detach_cb(pa_sink_input *i) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    if (o->inq_rtpoll_item_read) {
+        pa_rtpoll_item_free(o->inq_rtpoll_item_read);
+        o->inq_rtpoll_item_read = NULL;
+    }
+
+    if (o->outq_rtpoll_item_write) {
+        pa_rtpoll_item_free(o->outq_rtpoll_item_write);
+        o->outq_rtpoll_item_write = NULL;
+    }
+}
+
+/* Called from main context */
+static void sink_input_kill_cb(pa_sink_input *i) {
+    struct output *o;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_se(o = i->userdata);
+
+    pa_module_unload_request(o->userdata->module, TRUE);
+    output_free(o);
+}
+
+/* Called from thread context */
+static int sink_input_process_msg(pa_msgobject *obj, int code, void *data, int64_t offset, pa_memchunk *chunk) {
+    struct output *o = PA_SINK_INPUT(obj)->userdata;
+
+    switch (code) {
+
+        case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
+            pa_usec_t *r = data;
+
+            *r = pa_bytes_to_usec(pa_memblockq_get_length(o->memblockq), &o->sink_input->sample_spec);
+
+            /* Fall through, the default handler will add in the extra
+             * latency added by the resampler */
+            break;
+        }
+
+        case SINK_INPUT_MESSAGE_POST:
+
+            if (PA_SINK_IS_OPENED(o->sink_input->sink->thread_info.state))
+                pa_memblockq_push_align(o->memblockq, chunk);
+            else
+                pa_memblockq_flush_write(o->memblockq, TRUE);
+
+            return 0;
+    }
+
+    return pa_sink_input_process_msg(obj, code, data, offset, chunk);
+}
+
+/* Called from main context */
+static void suspend(struct userdata *u) {
+    struct output *o;
+    uint32_t idx;
+
+    pa_assert(u);
+
+    /* Let's suspend by unlinking all streams */
+    PA_IDXSET_FOREACH(o, u->outputs, idx)
+        output_disable(o);
+
+    pa_log_info("Device suspended...");
+}
+
+/* Called from main context */
+static void unsuspend(struct userdata *u) {
+    struct output *o;
+    uint32_t idx;
+
+    pa_assert(u);
+
+    /* Let's resume */
+    PA_IDXSET_FOREACH(o, u->outputs, idx)
+        output_enable(o);
+
+    pa_log_info("Resumed successfully...");
+}
+
+/* Called from main context */
+static int sink_set_state(pa_sink *sink, pa_sink_state_t state) {
+    struct userdata *u;
+
+    pa_sink_assert_ref(sink);
+    pa_assert_se(u = sink->userdata);
+
+    /* Please note that in contrast to the ALSA modules we call
+     * suspend/unsuspend from main context here! */
+
+    switch (state) {
+        case PA_SINK_SUSPENDED:
+            pa_assert(PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)));
+
+            suspend(u);
+            break;
+
+        case PA_SINK_IDLE:
+        case PA_SINK_RUNNING:
+
+            if (pa_sink_get_state(u->sink) == PA_SINK_SUSPENDED)
+                unsuspend(u);
+
+            break;
+
+        case PA_SINK_UNLINKED:
+        case PA_SINK_INIT:
+        case PA_SINK_INVALID_STATE:
+            ;
+    }
+
+    return 0;
+}
+
+/* Called from IO context */
+static void update_max_request(struct userdata *u) {
+    size_t max_request = 0;
+    struct output *o;
+
+    pa_assert(u);
+    pa_sink_assert_io_context(u->sink);
+
+    /* Collects the max_request values of all streams and sets the
+     * largest one locally */
+
+    PA_LLIST_FOREACH(o, u->thread_info.active_outputs) {
+        size_t mr = (size_t) pa_atomic_load(&o->max_request);
+
+        if (mr > max_request)
+            max_request = mr;
+    }
+
+    if (max_request <= 0)
+        max_request = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec);
+
+    pa_sink_set_max_request_within_thread(u->sink, max_request);
+}
+
+/* Called from IO context */
+static void update_fixed_latency(struct userdata *u) {
+    pa_usec_t fixed_latency = 0;
+    struct output *o;
+
+    pa_assert(u);
+    pa_sink_assert_io_context(u->sink);
+
+    /* Collects the requested_latency values of all streams and sets
+     * the largest one as fixed_latency locally */
+
+    PA_LLIST_FOREACH(o, u->thread_info.active_outputs) {
+        pa_usec_t rl = (size_t) pa_atomic_load(&o->requested_latency);
+
+        if (rl > fixed_latency)
+            fixed_latency = rl;
+    }
+
+    if (fixed_latency <= 0)
+        fixed_latency = u->block_usec;
+
+    pa_sink_set_fixed_latency_within_thread(u->sink, fixed_latency);
+}
+
+/* Called from thread context of the io thread */
+static void output_add_within_thread(struct output *o) {
+    pa_assert(o);
+    pa_sink_assert_io_context(o->sink);
+
+    PA_LLIST_PREPEND(struct output, o->userdata->thread_info.active_outputs, o);
+
+    pa_assert(!o->outq_rtpoll_item_read && !o->inq_rtpoll_item_write);
+
+    o->outq_rtpoll_item_read = pa_rtpoll_item_new_asyncmsgq_read(
+            o->userdata->rtpoll,
+            PA_RTPOLL_EARLY-1,  /* This item is very important */
+            o->outq);
+    o->inq_rtpoll_item_write = pa_rtpoll_item_new_asyncmsgq_write(
+            o->userdata->rtpoll,
+            PA_RTPOLL_EARLY,
+            o->inq);
+}
+
+/* Called from thread context of the io thread */
+static void output_remove_within_thread(struct output *o) {
+    pa_assert(o);
+    pa_sink_assert_io_context(o->sink);
+
+    PA_LLIST_REMOVE(struct output, o->userdata->thread_info.active_outputs, o);
+
+    if (o->outq_rtpoll_item_read) {
+        pa_rtpoll_item_free(o->outq_rtpoll_item_read);
+        o->outq_rtpoll_item_read = NULL;
+    }
+
+    if (o->inq_rtpoll_item_write) {
+        pa_rtpoll_item_free(o->inq_rtpoll_item_write);
+        o->inq_rtpoll_item_write = NULL;
+    }
+}
+
+/* Called from thread context of the io thread */
+static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
+    struct userdata *u = PA_SINK(o)->userdata;
+
+    switch (code) {
+
+        case PA_SINK_MESSAGE_SET_STATE:
+            pa_atomic_store(&u->thread_info.running, PA_PTR_TO_UINT(data) == PA_SINK_RUNNING);
+
+            if (PA_PTR_TO_UINT(data) == PA_SINK_SUSPENDED)
+                pa_smoother_pause(u->thread_info.smoother, pa_rtclock_now());
+            else
+                pa_smoother_resume(u->thread_info.smoother, pa_rtclock_now(), TRUE);
+
+            break;
+
+        case PA_SINK_MESSAGE_GET_LATENCY: {
+            pa_usec_t x, y, c, *delay = data;
+
+            x = pa_rtclock_now();
+            y = pa_smoother_get(u->thread_info.smoother, x);
+
+            c = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
+
+            if (y < c)
+                *delay = c - y;
+            else
+                *delay = 0;
+
+            return 0;
+        }
+
+        case SINK_MESSAGE_ADD_OUTPUT:
+            output_add_within_thread(data);
+            update_max_request(u);
+            update_fixed_latency(u);
+            return 0;
+
+        case SINK_MESSAGE_REMOVE_OUTPUT:
+            output_remove_within_thread(data);
+            update_max_request(u);
+            update_fixed_latency(u);
+            return 0;
+
+        case SINK_MESSAGE_NEED:
+            render_memblock(u, (struct output*) data, (size_t) offset);
+            return 0;
+
+        case SINK_MESSAGE_UPDATE_LATENCY: {
+            pa_usec_t x, y, latency = (pa_usec_t) offset;
+
+            x = pa_rtclock_now();
+            y = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
+
+            if (y > latency)
+                y -= latency;
+            else
+                y = 0;
+
+            pa_smoother_put(u->thread_info.smoother, x, y);
+            return 0;
+        }
+
+        case SINK_MESSAGE_UPDATE_MAX_REQUEST:
+            update_max_request(u);
+            break;
+
+        case SINK_MESSAGE_UPDATE_REQUESTED_LATENCY:
+            update_fixed_latency(u);
+            break;
+}
+
+    return pa_sink_process_msg(o, code, data, offset, chunk);
+}
+
+static void update_description(struct userdata *u) {
+    pa_bool_t first = TRUE;
+    char *t;
+    struct output *o;
+    uint32_t idx;
+
+    pa_assert(u);
+
+    if (!u->auto_desc)
+        return;
+
+    if (pa_idxset_isempty(u->outputs)) {
+        pa_sink_set_description(u->sink, "Simultaneous output");
+        return;
+    }
+
+    t = pa_xstrdup("Simultaneous output to");
+
+    PA_IDXSET_FOREACH(o, u->outputs, idx) {
+        char *e;
+
+        if (first) {
+            e = pa_sprintf_malloc("%s %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
+            first = FALSE;
+        } else
+            e = pa_sprintf_malloc("%s, %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
+
+        pa_xfree(t);
+        t = e;
+    }
+
+    pa_sink_set_description(u->sink, t);
+    pa_xfree(t);
+}
+
+static int output_create_sink_input(struct output *o) {
+    pa_sink_input_new_data data;
+
+    pa_assert(o);
+
+    if (o->sink_input)
+        return 0;
+
+    pa_sink_input_new_data_init(&data);
+    data.sink = o->sink;
+    data.driver = __FILE__;
+    pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "Simultaneous output on %s", pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
+    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "filter");
+    pa_sink_input_new_data_set_sample_spec(&data, &o->userdata->sink->sample_spec);
+    pa_sink_input_new_data_set_channel_map(&data, &o->userdata->sink->channel_map);
+    data.module = o->userdata->module;
+    data.resample_method = o->userdata->resample_method;
+    data.flags = PA_SINK_INPUT_VARIABLE_RATE|PA_SINK_INPUT_DONT_MOVE|PA_SINK_INPUT_NO_CREATE_ON_SUSPEND;
+
+    pa_sink_input_new(&o->sink_input, o->userdata->core, &data);
+
+    pa_sink_input_new_data_done(&data);
+
+    if (!o->sink_input)
+        return -1;
+
+    o->sink_input->parent.process_msg = sink_input_process_msg;
+    o->sink_input->pop = sink_input_pop_cb;
+    o->sink_input->process_rewind = sink_input_process_rewind_cb;
+    o->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
+    o->sink_input->update_max_request = sink_input_update_max_request_cb;
+    o->sink_input->update_sink_requested_latency = sink_input_update_sink_requested_latency_cb;
+    o->sink_input->attach = sink_input_attach_cb;
+    o->sink_input->detach = sink_input_detach_cb;
+    o->sink_input->kill = sink_input_kill_cb;
+    o->sink_input->userdata = o;
+
+    pa_sink_input_set_requested_latency(o->sink_input, BLOCK_USEC);
+
+    return 0;
+}
+
+/* Called from main context */
+static struct output *output_new(struct userdata *u, pa_sink *sink) {
+    struct output *o;
+
+    pa_assert(u);
+    pa_assert(sink);
+    pa_assert(u->sink);
+
+    o = pa_xnew0(struct output, 1);
+    o->userdata = u;
+    o->inq = pa_asyncmsgq_new(0);
+    o->outq = pa_asyncmsgq_new(0);
+    o->sink = sink;
+    o->memblockq = pa_memblockq_new(
+            0,
+            MEMBLOCKQ_MAXLENGTH,
+            MEMBLOCKQ_MAXLENGTH,
+            pa_frame_size(&u->sink->sample_spec),
+            1,
+            0,
+            0,
+            &u->sink->silence);
+
+    pa_assert_se(pa_idxset_put(u->outputs, o, NULL) == 0);
+    update_description(u);
+
+    return o;
+}
+
+/* Called from main context */
+static void output_free(struct output *o) {
+    pa_assert(o);
+
+    output_disable(o);
+
+    pa_assert_se(pa_idxset_remove_by_data(o->userdata->outputs, o, NULL));
+    update_description(o->userdata);
+
+    if (o->inq_rtpoll_item_read)
+        pa_rtpoll_item_free(o->inq_rtpoll_item_read);
+    if (o->inq_rtpoll_item_write)
+        pa_rtpoll_item_free(o->inq_rtpoll_item_write);
+
+    if (o->outq_rtpoll_item_read)
+        pa_rtpoll_item_free(o->outq_rtpoll_item_read);
+    if (o->outq_rtpoll_item_write)
+        pa_rtpoll_item_free(o->outq_rtpoll_item_write);
+
+    if (o->inq)
+        pa_asyncmsgq_unref(o->inq);
+
+    if (o->outq)
+        pa_asyncmsgq_unref(o->outq);
+
+    if (o->memblockq)
+        pa_memblockq_free(o->memblockq);
+
+    pa_xfree(o);
+}
+
+/* Called from main context */
+static void output_enable(struct output *o) {
+    pa_assert(o);
+
+    if (o->sink_input)
+        return;
+
+    /* This might cause the sink to be resumed. The state change hook
+     * of the sink might hence be called from here, which might then
+     * cause us to be called in a loop. Make sure that state changes
+     * for this output don't cause this loop by setting a flag here */
+    o->ignore_state_change = TRUE;
+
+    if (output_create_sink_input(o) >= 0) {
+
+        if (pa_sink_get_state(o->sink) != PA_SINK_INIT) {
+
+            /* First we register the output. That means that the sink
+             * will start to pass data to this output. */
+            pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_ADD_OUTPUT, o, 0, NULL);
+
+            /* Then we enable the sink input. That means that the sink
+             * is now asked for new data. */
+            pa_sink_input_put(o->sink_input);
+
+        } else
+            /* Hmm the sink is not yet started, do things right here */
+            output_add_within_thread(o);
+    }
+
+    o->ignore_state_change = FALSE;
+}
+
+/* Called from main context */
+static void output_disable(struct output *o) {
+    pa_assert(o);
+
+    if (!o->sink_input)
+        return;
+
+    /* First we disable the sink input. That means that the sink is
+     * not asked for new data anymore  */
+    pa_sink_input_unlink(o->sink_input);
+
+    /* Then we unregister the output. That means that the sink doesn't
+     * pass any further data to this output */
+    pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
+
+    /* Now dellocate the stream */
+    pa_sink_input_unref(o->sink_input);
+    o->sink_input = NULL;
+
+    /* Finally, drop all queued data */
+    pa_memblockq_flush_write(o->memblockq, TRUE);
+    pa_asyncmsgq_flush(o->inq, FALSE);
+    pa_asyncmsgq_flush(o->outq, FALSE);
+}
+
+/* Called from main context */
+static void output_verify(struct output *o) {
+    pa_assert(o);
+
+    if (PA_SINK_IS_OPENED(pa_sink_get_state(o->userdata->sink)))
+        output_enable(o);
+    else
+        output_disable(o);
+}
+
+/* Called from main context */
+static pa_bool_t is_suitable_sink(struct userdata *u, pa_sink *s) {
+    const char *t;
+
+    pa_sink_assert_ref(s);
+
+    if (s == u->sink)
+        return FALSE;
+
+    if (!(s->flags & PA_SINK_HARDWARE))
+        return FALSE;
+
+    if (!(s->flags & PA_SINK_LATENCY))
+        return FALSE;
+
+    if ((t = pa_proplist_gets(s->proplist, PA_PROP_DEVICE_CLASS)))
+        if (!pa_streq(t, "sound"))
+            return FALSE;
+
+    return TRUE;
+}
+
+/* Called from main context */
+static pa_hook_result_t sink_put_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
+    struct output *o;
+
+    pa_core_assert_ref(c);
+    pa_sink_assert_ref(s);
+    pa_assert(u);
+
+    if (u->automatic) {
+        if (!is_suitable_sink(u, s))
+            return PA_HOOK_OK;
+    } else {
+        /* Check if the sink is a previously unlinked slave (non-automatic mode) */
+        pa_strlist *l = u->unlinked_slaves;
+
+        while (l && !pa_streq(pa_strlist_data(l), s->name))
+            l = pa_strlist_next(l);
+
+        if (!l)
+            return PA_HOOK_OK;
+
+        u->unlinked_slaves = pa_strlist_remove(u->unlinked_slaves, s->name);
+    }
+
+    pa_log_info("Configuring new sink: %s", s->name);
+    if (!(o = output_new(u, s))) {
+        pa_log("Failed to create sink input on sink '%s'.", s->name);
+        return PA_HOOK_OK;
+    }
+
+    output_verify(o);
+
+    return PA_HOOK_OK;
+}
+
+/* Called from main context */
+static struct output* find_output(struct userdata *u, pa_sink *s) {
+    struct output *o;
+    uint32_t idx;
+
+    pa_assert(u);
+    pa_assert(s);
+
+    if (u->sink == s)
+        return NULL;
+
+    PA_IDXSET_FOREACH(o, u->outputs, idx)
+        if (o->sink == s)
+            return o;
+
+    return NULL;
+}
+
+/* Called from main context */
+static pa_hook_result_t sink_unlink_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
+    struct output *o;
+
+    pa_assert(c);
+    pa_sink_assert_ref(s);
+    pa_assert(u);
+
+    if (!(o = find_output(u, s)))
+        return PA_HOOK_OK;
+
+    pa_log_info("Unconfiguring sink: %s", s->name);
+
+    if (!u->automatic)
+        u->unlinked_slaves = pa_strlist_prepend(u->unlinked_slaves, s->name);
+
+    output_free(o);
+
+    return PA_HOOK_OK;
+}
+
+/* Called from main context */
+static pa_hook_result_t sink_state_changed_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
+    struct output *o;
+
+    if (!(o = find_output(u, s)))
+        return PA_HOOK_OK;
+
+    /* This state change might be triggered because we are creating a
+     * stream here, in that case we don't want to create it a second
+     * time here and enter a loop */
+    if (o->ignore_state_change)
+        return PA_HOOK_OK;
+
+    output_verify(o);
+
+    return PA_HOOK_OK;
+}
+
+int pa__init(pa_module*m) {
+    struct userdata *u;
+    pa_modargs *ma = NULL;
+    const char *slaves, *rm;
+    int resample_method = PA_RESAMPLER_TRIVIAL;
+    pa_sample_spec ss;
+    pa_channel_map map;
+    struct output *o;
+    uint32_t idx;
+    pa_sink_new_data data;
+    uint32_t adjust_time_sec;
+
+    pa_assert(m);
+
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log("failed to parse module arguments");
+        goto fail;
+    }
+
+    if ((rm = pa_modargs_get_value(ma, "resample_method", NULL))) {
+        if ((resample_method = pa_parse_resample_method(rm)) < 0) {
+            pa_log("invalid resample method '%s'", rm);
+            goto fail;
+        }
+    }
+
+    m->userdata = u = pa_xnew0(struct userdata, 1);
+    u->core = m->core;
+    u->module = m;
+    u->rtpoll = pa_rtpoll_new();
+    pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
+    u->resample_method = resample_method;
+    u->outputs = pa_idxset_new(NULL, NULL);
+    u->thread_info.smoother = pa_smoother_new(
+            PA_USEC_PER_SEC,
+            PA_USEC_PER_SEC*2,
+            TRUE,
+            TRUE,
+            10,
+            0,
+            FALSE);
+
+    adjust_time_sec = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC;
+    if (pa_modargs_get_value_u32(ma, "adjust_time", &adjust_time_sec) < 0) {
+        pa_log("Failed to parse adjust_time value");
+        goto fail;
+    }
+
+    if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
+        u->adjust_time = adjust_time_sec * PA_USEC_PER_SEC;
+    else
+        u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
+
+    slaves = pa_modargs_get_value(ma, "slaves", NULL);
+    u->automatic = !slaves;
+
+    ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
+
+    /* Check the specified slave sinks for sample_spec and channel_map to use for the combined sink */
+    if (!u->automatic) {
+        const char*split_state = NULL;
+        char *n = NULL;
+        pa_sample_spec slaves_spec;
+        pa_channel_map slaves_map;
+        pa_bool_t is_first_slave = TRUE;
+
+        pa_sample_spec_init(&slaves_spec);
+
+        while ((n = pa_split(slaves, ",", &split_state))) {
+            pa_sink *slave_sink;
+
+            if (!(slave_sink = pa_namereg_get(m->core, n, PA_NAMEREG_SINK))) {
+                pa_log("Invalid slave sink '%s'", n);
+                pa_xfree(n);
+                goto fail;
+            }
+
+            pa_xfree(n);
+
+            if (is_first_slave) {
+                slaves_spec = slave_sink->sample_spec;
+                slaves_map = slave_sink->channel_map;
+                is_first_slave = FALSE;
+            } else {
+                if (slaves_spec.format != slave_sink->sample_spec.format)
+                    slaves_spec.format = PA_SAMPLE_INVALID;
+
+                if (slaves_spec.rate < slave_sink->sample_spec.rate)
+                    slaves_spec.rate = slave_sink->sample_spec.rate;
+
+                if (!pa_channel_map_equal(&slaves_map, &slave_sink->channel_map))
+                    slaves_spec.channels = 0;
+            }
+        }
+
+        if (!is_first_slave) {
+            if (slaves_spec.format != PA_SAMPLE_INVALID)
+                ss.format = slaves_spec.format;
+
+            ss.rate = slaves_spec.rate;
+
+            if (slaves_spec.channels > 0) {
+                map = slaves_map;
+                ss.channels = slaves_map.channels;
+            }
+        }
+    }
+
+    if ((pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0)) {
+        pa_log("Invalid sample specification.");
+        goto fail;
+    }
+
+    pa_sink_new_data_init(&data);
+    data.namereg_fail = FALSE;
+    data.driver = __FILE__;
+    data.module = m;
+    pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME));
+    pa_sink_new_data_set_sample_spec(&data, &ss);
+    pa_sink_new_data_set_channel_map(&data, &map);
+    pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "filter");
+
+    if (slaves)
+        pa_proplist_sets(data.proplist, "combine.slaves", slaves);
+
+    if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
+        pa_log("Invalid properties");
+        pa_sink_new_data_done(&data);
+        goto fail;
+    }
+
+    /* Check proplist for a description & fill in a default value if not */
+    u->auto_desc = FALSE;
+    if (NULL == pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)) {
+        u->auto_desc = TRUE;
+        pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Simultaneous Output");
+    }
+
+    u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY);
+    pa_sink_new_data_done(&data);
+
+    if (!u->sink) {
+        pa_log("Failed to create sink");
+        goto fail;
+    }
+
+    u->sink->parent.process_msg = sink_process_msg;
+    u->sink->set_state = sink_set_state;
+    u->sink->userdata = u;
+
+    pa_sink_set_rtpoll(u->sink, u->rtpoll);
+    pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+
+    u->block_usec = BLOCK_USEC;
+    pa_sink_set_max_request(u->sink, pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec));
+
+    if (!u->automatic) {
+        const char*split_state;
+        char *n = NULL;
+        pa_assert(slaves);
+
+        /* The slaves have been specified manually */
+
+        split_state = NULL;
+        while ((n = pa_split(slaves, ",", &split_state))) {
+            pa_sink *slave_sink;
+
+            if (!(slave_sink = pa_namereg_get(m->core, n, PA_NAMEREG_SINK)) || slave_sink == u->sink) {
+                pa_log("Invalid slave sink '%s'", n);
+                pa_xfree(n);
+                goto fail;
+            }
+
+            pa_xfree(n);
+
+            if (!output_new(u, slave_sink)) {
+                pa_log("Failed to create slave sink input on sink '%s'.", slave_sink->name);
+                goto fail;
+            }
+        }
+
+        if (pa_idxset_size(u->outputs) <= 1)
+            pa_log_warn("No slave sinks specified.");
+
+        u->sink_put_slot = NULL;
+
+    } else {
+        pa_sink *s;
+
+        /* We're in automatic mode, we add every sink that matches our needs  */
+
+        PA_IDXSET_FOREACH(s, m->core->sinks, idx) {
+
+            if (!is_suitable_sink(u, s))
+                continue;
+
+            if (!output_new(u, s)) {
+                pa_log("Failed to create sink input on sink '%s'.", s->name);
+                goto fail;
+            }
+        }
+    }
+
+    u->sink_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_put_hook_cb, u);
+    u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) sink_unlink_hook_cb, u);
+    u->sink_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_state_changed_hook_cb, u);
+
+    if (!(u->thread = pa_thread_new("combine", thread_func, u))) {
+        pa_log("Failed to create thread.");
+        goto fail;
+    }
+
+    /* Activate the sink and the sink inputs */
+    pa_sink_put(u->sink);
+
+    PA_IDXSET_FOREACH(o, u->outputs, idx)
+        output_verify(o);
+
+    if (u->adjust_time > 0)
+        u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
+
+    pa_modargs_free(ma);
+
+    return 0;
+
+fail:
+
+    if (ma)
+        pa_modargs_free(ma);
+
+    pa__done(m);
+
+    return -1;
+}
+
+void pa__done(pa_module*m) {
+    struct userdata *u;
+    struct output *o;
+
+    pa_assert(m);
+
+    if (!(u = m->userdata))
+        return;
+
+    pa_strlist_free(u->unlinked_slaves);
+
+    if (u->sink_put_slot)
+        pa_hook_slot_free(u->sink_put_slot);
+
+    if (u->sink_unlink_slot)
+        pa_hook_slot_free(u->sink_unlink_slot);
+
+    if (u->sink_state_changed_slot)
+        pa_hook_slot_free(u->sink_state_changed_slot);
+
+    if (u->outputs) {
+        while ((o = pa_idxset_first(u->outputs, NULL)))
+            output_free(o);
+
+        pa_idxset_free(u->outputs, NULL, NULL);
+    }
+
+    if (u->sink)
+        pa_sink_unlink(u->sink);
+
+    if (u->thread) {
+        pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
+        pa_thread_free(u->thread);
+    }
+
+    pa_thread_mq_done(&u->thread_mq);
+
+    if (u->sink)
+        pa_sink_unref(u->sink);
+
+    if (u->rtpoll)
+        pa_rtpoll_free(u->rtpoll);
+
+    if (u->time_event)
+        u->core->mainloop->time_free(u->time_event);
+
+    if (u->thread_info.smoother)
+        pa_smoother_free(u->thread_info.smoother);
+
+    pa_xfree(u);
+}
diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c
index ab93c05..bef2a98 100644
--- a/src/modules/module-combine.c
+++ b/src/modules/module-combine.c
@@ -1,7 +1,8 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2004-2008 Lennart Poettering
+  Copyright 2009 Lennart Poettering
+  Copyright 2011 Colin Guthrie
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
@@ -23,1387 +24,48 @@
 #include <config.h>
 #endif
 
-#include <stdio.h>
-#include <errno.h>
-
-#include <pulse/rtclock.h>
-#include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 
-#include <pulsecore/macro.h>
 #include <pulsecore/module.h>
-#include <pulsecore/llist.h>
-#include <pulsecore/sink.h>
-#include <pulsecore/sink-input.h>
-#include <pulsecore/memblockq.h>
 #include <pulsecore/log.h>
-#include <pulsecore/core-rtclock.h>
 #include <pulsecore/core-util.h>
-#include <pulsecore/modargs.h>
-#include <pulsecore/namereg.h>
-#include <pulsecore/mutex.h>
-#include <pulsecore/thread.h>
-#include <pulsecore/thread-mq.h>
-#include <pulsecore/rtpoll.h>
-#include <pulsecore/core-error.h>
-#include <pulsecore/time-smoother.h>
-#include <pulsecore/strlist.h>
 
 #include "module-combine-symdef.h"
 
-PA_MODULE_AUTHOR("Lennart Poettering");
-PA_MODULE_DESCRIPTION("Combine multiple sinks to one");
+PA_MODULE_AUTHOR("Colin Guthrie");
+PA_MODULE_DESCRIPTION("Compatibility module (module-combine rename)");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(FALSE);
-PA_MODULE_USAGE(
-        "sink_name=<name for the sink> "
-        "sink_properties=<properties for the sink> "
-        "slaves=<slave sinks> "
-        "adjust_time=<how often to readjust rates in s> "
-        "resample_method=<method> "
-        "format=<sample format> "
-        "rate=<sample rate> "
-        "channels=<number of channels> "
-        "channel_map=<channel map>");
-
-#define DEFAULT_SINK_NAME "combined"
-
-#define MEMBLOCKQ_MAXLENGTH (1024*1024*16)
-
-#define DEFAULT_ADJUST_TIME_USEC (10*PA_USEC_PER_SEC)
-
-#define BLOCK_USEC (PA_USEC_PER_MSEC * 200)
-
-static const char* const valid_modargs[] = {
-    "sink_name",
-    "sink_properties",
-    "slaves",
-    "adjust_time",
-    "resample_method",
-    "format",
-    "rate",
-    "channels",
-    "channel_map",
-    NULL
-};
-
-struct output {
-    struct userdata *userdata;
-
-    pa_sink *sink;
-    pa_sink_input *sink_input;
-    pa_bool_t ignore_state_change;
-
-    pa_asyncmsgq *inq,    /* Message queue from the sink thread to this sink input */
-                 *outq;   /* Message queue from this sink input to the sink thread */
-    pa_rtpoll_item *inq_rtpoll_item_read, *inq_rtpoll_item_write;
-    pa_rtpoll_item *outq_rtpoll_item_read, *outq_rtpoll_item_write;
-
-    pa_memblockq *memblockq;
-
-    /* For communication of the stream latencies to the main thread */
-    pa_usec_t total_latency;
-
-    /* For coomunication of the stream parameters to the sink thread */
-    pa_atomic_t max_request;
-    pa_atomic_t requested_latency;
-
-    PA_LLIST_FIELDS(struct output);
-};
+PA_MODULE_DEPRECATED("Please use module-combine-sink instead of module-combine!");
 
 struct userdata {
-    pa_core *core;
     pa_module *module;
-    pa_sink *sink;
-
-    pa_thread *thread;
-    pa_thread_mq thread_mq;
-    pa_rtpoll *rtpoll;
-
-    pa_time_event *time_event;
-    pa_usec_t adjust_time;
-
-    pa_bool_t automatic;
-    pa_bool_t auto_desc;
-
-    pa_strlist *unlinked_slaves;
-
-    pa_hook_slot *sink_put_slot, *sink_unlink_slot, *sink_state_changed_slot;
-
-    pa_resample_method_t resample_method;
-
-    pa_usec_t block_usec;
-
-    pa_idxset* outputs; /* managed in main context */
-
-    struct {
-        PA_LLIST_HEAD(struct output, active_outputs); /* managed in IO thread context */
-        pa_atomic_t running;  /* we cache that value here, so that every thread can query it cheaply */
-        pa_usec_t timestamp;
-        pa_bool_t in_null_mode;
-        pa_smoother *smoother;
-        uint64_t counter;
-    } thread_info;
 };
 
-enum {
-    SINK_MESSAGE_ADD_OUTPUT = PA_SINK_MESSAGE_MAX,
-    SINK_MESSAGE_REMOVE_OUTPUT,
-    SINK_MESSAGE_NEED,
-    SINK_MESSAGE_UPDATE_LATENCY,
-    SINK_MESSAGE_UPDATE_MAX_REQUEST,
-    SINK_MESSAGE_UPDATE_REQUESTED_LATENCY
-};
-
-enum {
-    SINK_INPUT_MESSAGE_POST = PA_SINK_INPUT_MESSAGE_MAX,
-};
-
-static void output_disable(struct output *o);
-static void output_enable(struct output *o);
-static void output_free(struct output *o);
-static int output_create_sink_input(struct output *o);
-
-static void adjust_rates(struct userdata *u) {
-    struct output *o;
-    pa_usec_t max_sink_latency = 0, min_total_latency = (pa_usec_t) -1, target_latency, avg_total_latency = 0;
-    uint32_t base_rate;
-    uint32_t idx;
-    unsigned n = 0;
-
-    pa_assert(u);
-    pa_sink_assert_ref(u->sink);
-
-    if (pa_idxset_size(u->outputs) <= 0)
-        return;
-
-    if (!PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)))
-        return;
-
-    PA_IDXSET_FOREACH(o, u->outputs, idx) {
-        pa_usec_t sink_latency;
-
-        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
-            continue;
-
-        o->total_latency = pa_sink_input_get_latency(o->sink_input, &sink_latency);
-        o->total_latency += sink_latency;
-
-        if (sink_latency > max_sink_latency)
-            max_sink_latency = sink_latency;
-
-        if (min_total_latency == (pa_usec_t) -1 || o->total_latency < min_total_latency)
-            min_total_latency = o->total_latency;
-
-        avg_total_latency += o->total_latency;
-        n++;
-
-        pa_log_debug("[%s] total=%0.2fms sink=%0.2fms ", o->sink->name, (double) o->total_latency / PA_USEC_PER_MSEC, (double) sink_latency / PA_USEC_PER_MSEC);
-
-        if (o->total_latency > 10*PA_USEC_PER_SEC)
-            pa_log_warn("[%s] Total latency of output is very high (%0.2fms), most likely the audio timing in one of your drivers is broken.", o->sink->name, (double) o->total_latency / PA_USEC_PER_MSEC);
-    }
-
-    if (min_total_latency == (pa_usec_t) -1)
-        return;
-
-    avg_total_latency /= n;
-
-    target_latency = max_sink_latency > min_total_latency ? max_sink_latency : min_total_latency;
-
-    pa_log_info("[%s] avg total latency is %0.2f msec.", u->sink->name, (double) avg_total_latency / PA_USEC_PER_MSEC);
-    pa_log_info("[%s] target latency is %0.2f msec.", u->sink->name, (double) target_latency / PA_USEC_PER_MSEC);
-
-    base_rate = u->sink->sample_spec.rate;
-
-    PA_IDXSET_FOREACH(o, u->outputs, idx) {
-        uint32_t new_rate = base_rate;
-        uint32_t current_rate = o->sink_input->sample_spec.rate;
-
-        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
-            continue;
-
-        if (o->total_latency != target_latency)
-            new_rate += (uint32_t) (((double) o->total_latency - (double) target_latency) / (double) u->adjust_time * (double) new_rate);
-
-        if (new_rate < (uint32_t) (base_rate*0.8) || new_rate > (uint32_t) (base_rate*1.25)) {
-            pa_log_warn("[%s] sample rates too different, not adjusting (%u vs. %u).", o->sink_input->sink->name, base_rate, new_rate);
-            new_rate = base_rate;
-        } else {
-            if (base_rate < new_rate + 20 && new_rate < base_rate + 20)
-              new_rate = base_rate;
-            /* Do the adjustment in small steps; 2‰ can be considered inaudible */
-            if (new_rate < (uint32_t) (current_rate*0.998) || new_rate > (uint32_t) (current_rate*1.002)) {
-                pa_log_info("[%s] new rate of %u Hz not within 2‰ of %u Hz, forcing smaller adjustment", o->sink_input->sink->name, new_rate, current_rate);
-                new_rate = PA_CLAMP(new_rate, (uint32_t) (current_rate*0.998), (uint32_t) (current_rate*1.002));
-            }
-            pa_log_info("[%s] new rate is %u Hz; ratio is %0.3f; latency is %0.2f msec.", o->sink_input->sink->name, new_rate, (double) new_rate / base_rate, (double) o->total_latency / PA_USEC_PER_MSEC);
-        }
-        pa_sink_input_set_rate(o->sink_input, new_rate);
-    }
-
-    pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, NULL, (int64_t) avg_total_latency, NULL);
-}
-
-static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct timeval *t, void *userdata) {
-    struct userdata *u = userdata;
-
-    pa_assert(u);
-    pa_assert(a);
-    pa_assert(u->time_event == e);
-
-    adjust_rates(u);
-
-    pa_core_rttime_restart(u->core, e, pa_rtclock_now() + u->adjust_time);
-}
-
-static void process_render_null(struct userdata *u, pa_usec_t now) {
-    size_t ate = 0;
-    pa_assert(u);
-
-    if (u->thread_info.in_null_mode)
-        u->thread_info.timestamp = now;
-
-    while (u->thread_info.timestamp < now + u->block_usec) {
-        pa_memchunk chunk;
-
-        pa_sink_render(u->sink, u->sink->thread_info.max_request, &chunk);
-        pa_memblock_unref(chunk.memblock);
-
-        u->thread_info.counter += chunk.length;
-
-/*         pa_log_debug("Ate %lu bytes.", (unsigned long) chunk.length); */
-        u->thread_info.timestamp += pa_bytes_to_usec(chunk.length, &u->sink->sample_spec);
-
-        ate += chunk.length;
-
-        if (ate >= u->sink->thread_info.max_request)
-            break;
-    }
-
-/*     pa_log_debug("Ate in sum %lu bytes (of %lu)", (unsigned long) ate, (unsigned long) nbytes); */
-
-    pa_smoother_put(u->thread_info.smoother, now,
-                    pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec) - (u->thread_info.timestamp - now));
-}
-
-static void thread_func(void *userdata) {
-    struct userdata *u = userdata;
-
-    pa_assert(u);
-
-    pa_log_debug("Thread starting up");
-
-    if (u->core->realtime_scheduling)
-        pa_make_realtime(u->core->realtime_priority+1);
-
-    pa_thread_mq_install(&u->thread_mq);
-
-    u->thread_info.timestamp = pa_rtclock_now();
-    u->thread_info.in_null_mode = FALSE;
-
-    for (;;) {
-        int ret;
-
-        if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
-            if (u->sink->thread_info.rewind_requested)
-                pa_sink_process_rewind(u->sink, 0);
-
-        /* If no outputs are connected, render some data and drop it immediately. */
-        if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && !u->thread_info.active_outputs) {
-            pa_usec_t now;
-
-            now = pa_rtclock_now();
-
-            if (!u->thread_info.in_null_mode || u->thread_info.timestamp <= now)
-                process_render_null(u, now);
-
-            pa_rtpoll_set_timer_absolute(u->rtpoll, u->thread_info.timestamp);
-            u->thread_info.in_null_mode = TRUE;
-        } else {
-            pa_rtpoll_set_timer_disabled(u->rtpoll);
-            u->thread_info.in_null_mode = FALSE;
-        }
-
-        /* Hmm, nothing to do. Let's sleep */
-        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) {
-            pa_log_info("pa_rtpoll_run() = %i", ret);
-            goto fail;
-        }
-
-        if (ret == 0)
-            goto finish;
-    }
-
-fail:
-    /* If this was no regular exit from the loop we have to continue
-     * processing messages until we received PA_MESSAGE_SHUTDOWN */
-    pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
-    pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
-
-finish:
-    pa_log_debug("Thread shutting down");
-}
-
-/* Called from I/O thread context */
-static void render_memblock(struct userdata *u, struct output *o, size_t length) {
-    pa_assert(u);
-    pa_assert(o);
-
-    /* We are run by the sink thread, on behalf of an output (o). The
-     * output is waiting for us, hence it is safe to access its
-     * mainblockq and asyncmsgq directly. */
-
-    /* If we are not running, we cannot produce any data */
-    if (!pa_atomic_load(&u->thread_info.running))
-        return;
-
-    /* Maybe there's some data in the requesting output's queue
-     * now? */
-    while (pa_asyncmsgq_process_one(o->inq) > 0)
-        ;
-
-    /* Ok, now let's prepare some data if we really have to */
-    while (!pa_memblockq_is_readable(o->memblockq)) {
-        struct output *j;
-        pa_memchunk chunk;
-
-        /* Render data! */
-        pa_sink_render(u->sink, length, &chunk);
-
-        u->thread_info.counter += chunk.length;
-
-        /* OK, let's send this data to the other threads */
-        PA_LLIST_FOREACH(j, u->thread_info.active_outputs) {
-            if (j == o)
-                continue;
-
-            pa_asyncmsgq_post(j->inq, PA_MSGOBJECT(j->sink_input), SINK_INPUT_MESSAGE_POST, NULL, 0, &chunk, NULL);
-        }
-
-        /* And place it directly into the requesting output's queue */
-        pa_memblockq_push_align(o->memblockq, &chunk);
-        pa_memblock_unref(chunk.memblock);
-    }
-}
-
-/* Called from I/O thread context */
-static void request_memblock(struct output *o, size_t length) {
-    pa_assert(o);
-    pa_sink_input_assert_ref(o->sink_input);
-    pa_sink_assert_ref(o->userdata->sink);
-
-    /* If another thread already prepared some data we received
-     * the data over the asyncmsgq, hence let's first process
-     * it. */
-    while (pa_asyncmsgq_process_one(o->inq) > 0)
-        ;
-
-    /* Check whether we're now readable */
-    if (pa_memblockq_is_readable(o->memblockq))
-        return;
-
-    /* OK, we need to prepare new data, but only if the sink is actually running */
-    if (pa_atomic_load(&o->userdata->thread_info.running))
-        pa_asyncmsgq_send(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_NEED, o, (int64_t) length, NULL);
-}
-
-/* Called from I/O thread context */
-static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    /* If necessary, get some new data */
-    request_memblock(o, nbytes);
-
-    /* pa_log("%s q size is %u + %u (%u/%u)", */
-    /*        i->sink->name, */
-    /*        pa_memblockq_get_nblocks(o->memblockq), */
-    /*        pa_memblockq_get_nblocks(i->thread_info.render_memblockq), */
-    /*        pa_memblockq_get_maxrewind(o->memblockq), */
-    /*        pa_memblockq_get_maxrewind(i->thread_info.render_memblockq)); */
-
-    if (pa_memblockq_peek(o->memblockq, chunk) < 0)
-        return -1;
-
-    pa_memblockq_drop(o->memblockq, chunk->length);
-
-    return 0;
-}
-
-/* Called from I/O thread context */
-static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    pa_memblockq_rewind(o->memblockq, nbytes);
-}
-
-/* Called from I/O thread context */
-static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    pa_memblockq_set_maxrewind(o->memblockq, nbytes);
-}
-
-/* Called from I/O thread context */
-static void sink_input_update_max_request_cb(pa_sink_input *i, size_t nbytes) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    if (pa_atomic_load(&o->max_request) == (int) nbytes)
-        return;
-
-    pa_atomic_store(&o->max_request, (int) nbytes);
-    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_MAX_REQUEST, NULL, 0, NULL, NULL);
-}
-
-/* Called from thread context */
-static void sink_input_update_sink_requested_latency_cb(pa_sink_input *i) {
-    struct output *o;
-    pa_usec_t c;
-
-    pa_assert(i);
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    c = pa_sink_get_requested_latency_within_thread(i->sink);
-
-    if (c == (pa_usec_t) -1)
-        c = i->sink->thread_info.max_latency;
-
-    if (pa_atomic_load(&o->requested_latency) == (int) c)
-        return;
-
-    pa_atomic_store(&o->requested_latency, (int) c);
-    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_REQUESTED_LATENCY, NULL, 0, NULL, NULL);
-}
-
-/* Called from I/O thread context */
-static void sink_input_attach_cb(pa_sink_input *i) {
-    struct output *o;
-    pa_usec_t c;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    /* Set up the queue from the sink thread to us */
-    pa_assert(!o->inq_rtpoll_item_read && !o->outq_rtpoll_item_write);
-
-    o->inq_rtpoll_item_read = pa_rtpoll_item_new_asyncmsgq_read(
-            i->sink->thread_info.rtpoll,
-            PA_RTPOLL_LATE,  /* This one is not that important, since we check for data in _peek() anyway. */
-            o->inq);
-
-    o->outq_rtpoll_item_write = pa_rtpoll_item_new_asyncmsgq_write(
-            i->sink->thread_info.rtpoll,
-            PA_RTPOLL_EARLY,
-            o->outq);
-
-    pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
-
-    pa_atomic_store(&o->max_request, (int) pa_sink_input_get_max_request(i));
-
-    c = pa_sink_get_requested_latency_within_thread(i->sink);
-    pa_atomic_store(&o->requested_latency, (int) (c == (pa_usec_t) -1 ? 0 : c));
-
-    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_MAX_REQUEST, NULL, 0, NULL, NULL);
-    pa_asyncmsgq_post(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_UPDATE_REQUESTED_LATENCY, NULL, 0, NULL, NULL);
-}
-
-/* Called from I/O thread context */
-static void sink_input_detach_cb(pa_sink_input *i) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    if (o->inq_rtpoll_item_read) {
-        pa_rtpoll_item_free(o->inq_rtpoll_item_read);
-        o->inq_rtpoll_item_read = NULL;
-    }
-
-    if (o->outq_rtpoll_item_write) {
-        pa_rtpoll_item_free(o->outq_rtpoll_item_write);
-        o->outq_rtpoll_item_write = NULL;
-    }
-}
-
-/* Called from main context */
-static void sink_input_kill_cb(pa_sink_input *i) {
-    struct output *o;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_se(o = i->userdata);
-
-    pa_module_unload_request(o->userdata->module, TRUE);
-    output_free(o);
-}
-
-/* Called from thread context */
-static int sink_input_process_msg(pa_msgobject *obj, int code, void *data, int64_t offset, pa_memchunk *chunk) {
-    struct output *o = PA_SINK_INPUT(obj)->userdata;
-
-    switch (code) {
-
-        case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
-            pa_usec_t *r = data;
-
-            *r = pa_bytes_to_usec(pa_memblockq_get_length(o->memblockq), &o->sink_input->sample_spec);
-
-            /* Fall through, the default handler will add in the extra
-             * latency added by the resampler */
-            break;
-        }
-
-        case SINK_INPUT_MESSAGE_POST:
-
-            if (PA_SINK_IS_OPENED(o->sink_input->sink->thread_info.state))
-                pa_memblockq_push_align(o->memblockq, chunk);
-            else
-                pa_memblockq_flush_write(o->memblockq, TRUE);
-
-            return 0;
-    }
-
-    return pa_sink_input_process_msg(obj, code, data, offset, chunk);
-}
-
-/* Called from main context */
-static void suspend(struct userdata *u) {
-    struct output *o;
-    uint32_t idx;
-
-    pa_assert(u);
-
-    /* Let's suspend by unlinking all streams */
-    PA_IDXSET_FOREACH(o, u->outputs, idx)
-        output_disable(o);
-
-    pa_log_info("Device suspended...");
-}
-
-/* Called from main context */
-static void unsuspend(struct userdata *u) {
-    struct output *o;
-    uint32_t idx;
-
-    pa_assert(u);
-
-    /* Let's resume */
-    PA_IDXSET_FOREACH(o, u->outputs, idx)
-        output_enable(o);
-
-    pa_log_info("Resumed successfully...");
-}
-
-/* Called from main context */
-static int sink_set_state(pa_sink *sink, pa_sink_state_t state) {
-    struct userdata *u;
-
-    pa_sink_assert_ref(sink);
-    pa_assert_se(u = sink->userdata);
-
-    /* Please note that in contrast to the ALSA modules we call
-     * suspend/unsuspend from main context here! */
-
-    switch (state) {
-        case PA_SINK_SUSPENDED:
-            pa_assert(PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)));
-
-            suspend(u);
-            break;
-
-        case PA_SINK_IDLE:
-        case PA_SINK_RUNNING:
-
-            if (pa_sink_get_state(u->sink) == PA_SINK_SUSPENDED)
-                unsuspend(u);
-
-            break;
-
-        case PA_SINK_UNLINKED:
-        case PA_SINK_INIT:
-        case PA_SINK_INVALID_STATE:
-            ;
-    }
-
-    return 0;
-}
-
-/* Called from IO context */
-static void update_max_request(struct userdata *u) {
-    size_t max_request = 0;
-    struct output *o;
-
-    pa_assert(u);
-    pa_sink_assert_io_context(u->sink);
-
-    /* Collects the max_request values of all streams and sets the
-     * largest one locally */
-
-    PA_LLIST_FOREACH(o, u->thread_info.active_outputs) {
-        size_t mr = (size_t) pa_atomic_load(&o->max_request);
-
-        if (mr > max_request)
-            max_request = mr;
-    }
-
-    if (max_request <= 0)
-        max_request = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec);
-
-    pa_sink_set_max_request_within_thread(u->sink, max_request);
-}
-
-/* Called from IO context */
-static void update_fixed_latency(struct userdata *u) {
-    pa_usec_t fixed_latency = 0;
-    struct output *o;
-
-    pa_assert(u);
-    pa_sink_assert_io_context(u->sink);
-
-    /* Collects the requested_latency values of all streams and sets
-     * the largest one as fixed_latency locally */
-
-    PA_LLIST_FOREACH(o, u->thread_info.active_outputs) {
-        pa_usec_t rl = (size_t) pa_atomic_load(&o->requested_latency);
-
-        if (rl > fixed_latency)
-            fixed_latency = rl;
-    }
-
-    if (fixed_latency <= 0)
-        fixed_latency = u->block_usec;
-
-    pa_sink_set_fixed_latency_within_thread(u->sink, fixed_latency);
-}
-
-/* Called from thread context of the io thread */
-static void output_add_within_thread(struct output *o) {
-    pa_assert(o);
-    pa_sink_assert_io_context(o->sink);
-
-    PA_LLIST_PREPEND(struct output, o->userdata->thread_info.active_outputs, o);
-
-    pa_assert(!o->outq_rtpoll_item_read && !o->inq_rtpoll_item_write);
-
-    o->outq_rtpoll_item_read = pa_rtpoll_item_new_asyncmsgq_read(
-            o->userdata->rtpoll,
-            PA_RTPOLL_EARLY-1,  /* This item is very important */
-            o->outq);
-    o->inq_rtpoll_item_write = pa_rtpoll_item_new_asyncmsgq_write(
-            o->userdata->rtpoll,
-            PA_RTPOLL_EARLY,
-            o->inq);
-}
-
-/* Called from thread context of the io thread */
-static void output_remove_within_thread(struct output *o) {
-    pa_assert(o);
-    pa_sink_assert_io_context(o->sink);
-
-    PA_LLIST_REMOVE(struct output, o->userdata->thread_info.active_outputs, o);
-
-    if (o->outq_rtpoll_item_read) {
-        pa_rtpoll_item_free(o->outq_rtpoll_item_read);
-        o->outq_rtpoll_item_read = NULL;
-    }
-
-    if (o->inq_rtpoll_item_write) {
-        pa_rtpoll_item_free(o->inq_rtpoll_item_write);
-        o->inq_rtpoll_item_write = NULL;
-    }
-}
-
-/* Called from thread context of the io thread */
-static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
-    struct userdata *u = PA_SINK(o)->userdata;
-
-    switch (code) {
-
-        case PA_SINK_MESSAGE_SET_STATE:
-            pa_atomic_store(&u->thread_info.running, PA_PTR_TO_UINT(data) == PA_SINK_RUNNING);
-
-            if (PA_PTR_TO_UINT(data) == PA_SINK_SUSPENDED)
-                pa_smoother_pause(u->thread_info.smoother, pa_rtclock_now());
-            else
-                pa_smoother_resume(u->thread_info.smoother, pa_rtclock_now(), TRUE);
-
-            break;
-
-        case PA_SINK_MESSAGE_GET_LATENCY: {
-            pa_usec_t x, y, c, *delay = data;
-
-            x = pa_rtclock_now();
-            y = pa_smoother_get(u->thread_info.smoother, x);
-
-            c = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
-
-            if (y < c)
-                *delay = c - y;
-            else
-                *delay = 0;
-
-            return 0;
-        }
-
-        case SINK_MESSAGE_ADD_OUTPUT:
-            output_add_within_thread(data);
-            update_max_request(u);
-            update_fixed_latency(u);
-            return 0;
-
-        case SINK_MESSAGE_REMOVE_OUTPUT:
-            output_remove_within_thread(data);
-            update_max_request(u);
-            update_fixed_latency(u);
-            return 0;
-
-        case SINK_MESSAGE_NEED:
-            render_memblock(u, (struct output*) data, (size_t) offset);
-            return 0;
-
-        case SINK_MESSAGE_UPDATE_LATENCY: {
-            pa_usec_t x, y, latency = (pa_usec_t) offset;
-
-            x = pa_rtclock_now();
-            y = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
-
-            if (y > latency)
-                y -= latency;
-            else
-                y = 0;
-
-            pa_smoother_put(u->thread_info.smoother, x, y);
-            return 0;
-        }
-
-        case SINK_MESSAGE_UPDATE_MAX_REQUEST:
-            update_max_request(u);
-            break;
-
-        case SINK_MESSAGE_UPDATE_REQUESTED_LATENCY:
-            update_fixed_latency(u);
-            break;
-}
-
-    return pa_sink_process_msg(o, code, data, offset, chunk);
-}
-
-static void update_description(struct userdata *u) {
-    pa_bool_t first = TRUE;
-    char *t;
-    struct output *o;
-    uint32_t idx;
-
-    pa_assert(u);
-
-    if (!u->auto_desc)
-        return;
-
-    if (pa_idxset_isempty(u->outputs)) {
-        pa_sink_set_description(u->sink, "Simultaneous output");
-        return;
-    }
-
-    t = pa_xstrdup("Simultaneous output to");
-
-    PA_IDXSET_FOREACH(o, u->outputs, idx) {
-        char *e;
-
-        if (first) {
-            e = pa_sprintf_malloc("%s %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
-            first = FALSE;
-        } else
-            e = pa_sprintf_malloc("%s, %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
-
-        pa_xfree(t);
-        t = e;
-    }
-
-    pa_sink_set_description(u->sink, t);
-    pa_xfree(t);
-}
-
-static int output_create_sink_input(struct output *o) {
-    pa_sink_input_new_data data;
-
-    pa_assert(o);
-
-    if (o->sink_input)
-        return 0;
-
-    pa_sink_input_new_data_init(&data);
-    data.sink = o->sink;
-    data.driver = __FILE__;
-    pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "Simultaneous output on %s", pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
-    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "filter");
-    pa_sink_input_new_data_set_sample_spec(&data, &o->userdata->sink->sample_spec);
-    pa_sink_input_new_data_set_channel_map(&data, &o->userdata->sink->channel_map);
-    data.module = o->userdata->module;
-    data.resample_method = o->userdata->resample_method;
-    data.flags = PA_SINK_INPUT_VARIABLE_RATE|PA_SINK_INPUT_DONT_MOVE|PA_SINK_INPUT_NO_CREATE_ON_SUSPEND;
-
-    pa_sink_input_new(&o->sink_input, o->userdata->core, &data);
-
-    pa_sink_input_new_data_done(&data);
-
-    if (!o->sink_input)
-        return -1;
-
-    o->sink_input->parent.process_msg = sink_input_process_msg;
-    o->sink_input->pop = sink_input_pop_cb;
-    o->sink_input->process_rewind = sink_input_process_rewind_cb;
-    o->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
-    o->sink_input->update_max_request = sink_input_update_max_request_cb;
-    o->sink_input->update_sink_requested_latency = sink_input_update_sink_requested_latency_cb;
-    o->sink_input->attach = sink_input_attach_cb;
-    o->sink_input->detach = sink_input_detach_cb;
-    o->sink_input->kill = sink_input_kill_cb;
-    o->sink_input->userdata = o;
-
-    pa_sink_input_set_requested_latency(o->sink_input, BLOCK_USEC);
-
-    return 0;
-}
-
-/* Called from main context */
-static struct output *output_new(struct userdata *u, pa_sink *sink) {
-    struct output *o;
-
-    pa_assert(u);
-    pa_assert(sink);
-    pa_assert(u->sink);
-
-    o = pa_xnew0(struct output, 1);
-    o->userdata = u;
-    o->inq = pa_asyncmsgq_new(0);
-    o->outq = pa_asyncmsgq_new(0);
-    o->sink = sink;
-    o->memblockq = pa_memblockq_new(
-            0,
-            MEMBLOCKQ_MAXLENGTH,
-            MEMBLOCKQ_MAXLENGTH,
-            pa_frame_size(&u->sink->sample_spec),
-            1,
-            0,
-            0,
-            &u->sink->silence);
-
-    pa_assert_se(pa_idxset_put(u->outputs, o, NULL) == 0);
-    update_description(u);
-
-    return o;
-}
-
-/* Called from main context */
-static void output_free(struct output *o) {
-    pa_assert(o);
-
-    output_disable(o);
-
-    pa_assert_se(pa_idxset_remove_by_data(o->userdata->outputs, o, NULL));
-    update_description(o->userdata);
-
-    if (o->inq_rtpoll_item_read)
-        pa_rtpoll_item_free(o->inq_rtpoll_item_read);
-    if (o->inq_rtpoll_item_write)
-        pa_rtpoll_item_free(o->inq_rtpoll_item_write);
-
-    if (o->outq_rtpoll_item_read)
-        pa_rtpoll_item_free(o->outq_rtpoll_item_read);
-    if (o->outq_rtpoll_item_write)
-        pa_rtpoll_item_free(o->outq_rtpoll_item_write);
-
-    if (o->inq)
-        pa_asyncmsgq_unref(o->inq);
-
-    if (o->outq)
-        pa_asyncmsgq_unref(o->outq);
-
-    if (o->memblockq)
-        pa_memblockq_free(o->memblockq);
-
-    pa_xfree(o);
-}
-
-/* Called from main context */
-static void output_enable(struct output *o) {
-    pa_assert(o);
-
-    if (o->sink_input)
-        return;
-
-    /* This might cause the sink to be resumed. The state change hook
-     * of the sink might hence be called from here, which might then
-     * cause us to be called in a loop. Make sure that state changes
-     * for this output don't cause this loop by setting a flag here */
-    o->ignore_state_change = TRUE;
-
-    if (output_create_sink_input(o) >= 0) {
-
-        if (pa_sink_get_state(o->sink) != PA_SINK_INIT) {
-
-            /* First we register the output. That means that the sink
-             * will start to pass data to this output. */
-            pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_ADD_OUTPUT, o, 0, NULL);
-
-            /* Then we enable the sink input. That means that the sink
-             * is now asked for new data. */
-            pa_sink_input_put(o->sink_input);
-
-        } else
-            /* Hmm the sink is not yet started, do things right here */
-            output_add_within_thread(o);
-    }
-
-    o->ignore_state_change = FALSE;
-}
-
-/* Called from main context */
-static void output_disable(struct output *o) {
-    pa_assert(o);
-
-    if (!o->sink_input)
-        return;
-
-    /* First we disable the sink input. That means that the sink is
-     * not asked for new data anymore  */
-    pa_sink_input_unlink(o->sink_input);
-
-    /* Then we unregister the output. That means that the sink doesn't
-     * pass any further data to this output */
-    pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
-
-    /* Now dellocate the stream */
-    pa_sink_input_unref(o->sink_input);
-    o->sink_input = NULL;
-
-    /* Finally, drop all queued data */
-    pa_memblockq_flush_write(o->memblockq, TRUE);
-    pa_asyncmsgq_flush(o->inq, FALSE);
-    pa_asyncmsgq_flush(o->outq, FALSE);
-}
-
-/* Called from main context */
-static void output_verify(struct output *o) {
-    pa_assert(o);
-
-    if (PA_SINK_IS_OPENED(pa_sink_get_state(o->userdata->sink)))
-        output_enable(o);
-    else
-        output_disable(o);
-}
-
-/* Called from main context */
-static pa_bool_t is_suitable_sink(struct userdata *u, pa_sink *s) {
-    const char *t;
-
-    pa_sink_assert_ref(s);
-
-    if (s == u->sink)
-        return FALSE;
-
-    if (!(s->flags & PA_SINK_HARDWARE))
-        return FALSE;
-
-    if (!(s->flags & PA_SINK_LATENCY))
-        return FALSE;
-
-    if ((t = pa_proplist_gets(s->proplist, PA_PROP_DEVICE_CLASS)))
-        if (!pa_streq(t, "sound"))
-            return FALSE;
-
-    return TRUE;
-}
-
-/* Called from main context */
-static pa_hook_result_t sink_put_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
-    struct output *o;
-
-    pa_core_assert_ref(c);
-    pa_sink_assert_ref(s);
-    pa_assert(u);
-
-    if (u->automatic) {
-        if (!is_suitable_sink(u, s))
-            return PA_HOOK_OK;
-    } else {
-        /* Check if the sink is a previously unlinked slave (non-automatic mode) */
-        pa_strlist *l = u->unlinked_slaves;
-
-        while (l && !pa_streq(pa_strlist_data(l), s->name))
-            l = pa_strlist_next(l);
-
-        if (!l)
-            return PA_HOOK_OK;
-
-        u->unlinked_slaves = pa_strlist_remove(u->unlinked_slaves, s->name);
-    }
-
-    pa_log_info("Configuring new sink: %s", s->name);
-    if (!(o = output_new(u, s))) {
-        pa_log("Failed to create sink input on sink '%s'.", s->name);
-        return PA_HOOK_OK;
-    }
-
-    output_verify(o);
-
-    return PA_HOOK_OK;
-}
-
-/* Called from main context */
-static struct output* find_output(struct userdata *u, pa_sink *s) {
-    struct output *o;
-    uint32_t idx;
-
-    pa_assert(u);
-    pa_assert(s);
-
-    if (u->sink == s)
-        return NULL;
-
-    PA_IDXSET_FOREACH(o, u->outputs, idx)
-        if (o->sink == s)
-            return o;
-
-    return NULL;
-}
-
-/* Called from main context */
-static pa_hook_result_t sink_unlink_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
-    struct output *o;
-
-    pa_assert(c);
-    pa_sink_assert_ref(s);
-    pa_assert(u);
-
-    if (!(o = find_output(u, s)))
-        return PA_HOOK_OK;
-
-    pa_log_info("Unconfiguring sink: %s", s->name);
-
-    if (!u->automatic)
-        u->unlinked_slaves = pa_strlist_prepend(u->unlinked_slaves, s->name);
-
-    output_free(o);
-
-    return PA_HOOK_OK;
-}
-
-/* Called from main context */
-static pa_hook_result_t sink_state_changed_hook_cb(pa_core *c, pa_sink *s, struct userdata* u) {
-    struct output *o;
-
-    if (!(o = find_output(u, s)))
-        return PA_HOOK_OK;
-
-    /* This state change might be triggered because we are creating a
-     * stream here, in that case we don't want to create it a second
-     * time here and enter a loop */
-    if (o->ignore_state_change)
-        return PA_HOOK_OK;
-
-    output_verify(o);
-
-    return PA_HOOK_OK;
-}
-
 int pa__init(pa_module*m) {
     struct userdata *u;
-    pa_modargs *ma = NULL;
-    const char *slaves, *rm;
-    int resample_method = PA_RESAMPLER_TRIVIAL;
-    pa_sample_spec ss;
-    pa_channel_map map;
-    struct output *o;
-    uint32_t idx;
-    pa_sink_new_data data;
-    uint32_t adjust_time_sec;
 
     pa_assert(m);
+    pa_assert_se(m->userdata = u = pa_xnew0(struct userdata, 1));
 
-    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
-        pa_log("failed to parse module arguments");
-        goto fail;
-    }
-
-    if ((rm = pa_modargs_get_value(ma, "resample_method", NULL))) {
-        if ((resample_method = pa_parse_resample_method(rm)) < 0) {
-            pa_log("invalid resample method '%s'", rm);
-            goto fail;
-        }
-    }
-
-    m->userdata = u = pa_xnew0(struct userdata, 1);
-    u->core = m->core;
-    u->module = m;
-    u->rtpoll = pa_rtpoll_new();
-    pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
-    u->resample_method = resample_method;
-    u->outputs = pa_idxset_new(NULL, NULL);
-    u->thread_info.smoother = pa_smoother_new(
-            PA_USEC_PER_SEC,
-            PA_USEC_PER_SEC*2,
-            TRUE,
-            TRUE,
-            10,
-            0,
-            FALSE);
-
-    adjust_time_sec = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC;
-    if (pa_modargs_get_value_u32(ma, "adjust_time", &adjust_time_sec) < 0) {
-        pa_log("Failed to parse adjust_time value");
-        goto fail;
-    }
-
-    if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
-        u->adjust_time = adjust_time_sec * PA_USEC_PER_SEC;
-    else
-        u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
-
-    slaves = pa_modargs_get_value(ma, "slaves", NULL);
-    u->automatic = !slaves;
-
-    ss = m->core->default_sample_spec;
-    map = m->core->default_channel_map;
-
-    /* Check the specified slave sinks for sample_spec and channel_map to use for the combined sink */
-    if (!u->automatic) {
-        const char*split_state = NULL;
-        char *n = NULL;
-        pa_sample_spec slaves_spec;
-        pa_channel_map slaves_map;
-        pa_bool_t is_first_slave = TRUE;
-
-        pa_sample_spec_init(&slaves_spec);
-
-        while ((n = pa_split(slaves, ",", &split_state))) {
-            pa_sink *slave_sink;
-
-            if (!(slave_sink = pa_namereg_get(m->core, n, PA_NAMEREG_SINK))) {
-                pa_log("Invalid slave sink '%s'", n);
-                pa_xfree(n);
-                goto fail;
-            }
-
-            pa_xfree(n);
-
-            if (is_first_slave) {
-                slaves_spec = slave_sink->sample_spec;
-                slaves_map = slave_sink->channel_map;
-                is_first_slave = FALSE;
-            } else {
-                if (slaves_spec.format != slave_sink->sample_spec.format)
-                    slaves_spec.format = PA_SAMPLE_INVALID;
-
-                if (slaves_spec.rate < slave_sink->sample_spec.rate)
-                    slaves_spec.rate = slave_sink->sample_spec.rate;
-
-                if (!pa_channel_map_equal(&slaves_map, &slave_sink->channel_map))
-                    slaves_spec.channels = 0;
-            }
-        }
+    pa_log_warn("We will now load module-combine-sink. Please make sure to remove module-combine from your configuration.");
 
-        if (!is_first_slave) {
-            if (slaves_spec.format != PA_SAMPLE_INVALID)
-                ss.format = slaves_spec.format;
+    u->module = pa_module_load(m->core, "module-combine-sink", m->argument);
 
-            ss.rate = slaves_spec.rate;
-
-            if (slaves_spec.channels > 0) {
-                map = slaves_map;
-                ss.channels = slaves_map.channels;
-            }
-        }
-    }
-
-    if ((pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0)) {
-        pa_log("Invalid sample specification.");
-        goto fail;
-    }
-
-    pa_sink_new_data_init(&data);
-    data.namereg_fail = FALSE;
-    data.driver = __FILE__;
-    data.module = m;
-    pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME));
-    pa_sink_new_data_set_sample_spec(&data, &ss);
-    pa_sink_new_data_set_channel_map(&data, &map);
-    pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "filter");
-
-    if (slaves)
-        pa_proplist_sets(data.proplist, "combine.slaves", slaves);
-
-    if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
-        pa_log("Invalid properties");
-        pa_sink_new_data_done(&data);
-        goto fail;
-    }
-
-    /* Check proplist for a description & fill in a default value if not */
-    u->auto_desc = FALSE;
-    if (NULL == pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)) {
-        u->auto_desc = TRUE;
-        pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Simultaneous Output");
-    }
-
-    u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY);
-    pa_sink_new_data_done(&data);
-
-    if (!u->sink) {
-        pa_log("Failed to create sink");
-        goto fail;
-    }
-
-    u->sink->parent.process_msg = sink_process_msg;
-    u->sink->set_state = sink_set_state;
-    u->sink->userdata = u;
-
-    pa_sink_set_rtpoll(u->sink, u->rtpoll);
-    pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
-
-    u->block_usec = BLOCK_USEC;
-    pa_sink_set_max_request(u->sink, pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec));
-
-    if (!u->automatic) {
-        const char*split_state;
-        char *n = NULL;
-        pa_assert(slaves);
-
-        /* The slaves have been specified manually */
-
-        split_state = NULL;
-        while ((n = pa_split(slaves, ",", &split_state))) {
-            pa_sink *slave_sink;
-
-            if (!(slave_sink = pa_namereg_get(m->core, n, PA_NAMEREG_SINK)) || slave_sink == u->sink) {
-                pa_log("Invalid slave sink '%s'", n);
-                pa_xfree(n);
-                goto fail;
-            }
-
-            pa_xfree(n);
-
-            if (!output_new(u, slave_sink)) {
-                pa_log("Failed to create slave sink input on sink '%s'.", slave_sink->name);
-                goto fail;
-            }
-        }
-
-        if (pa_idxset_size(u->outputs) <= 1)
-            pa_log_warn("No slave sinks specified.");
-
-        u->sink_put_slot = NULL;
-
-    } else {
-        pa_sink *s;
-
-        /* We're in automatic mode, we add every sink that matches our needs  */
-
-        PA_IDXSET_FOREACH(s, m->core->sinks, idx) {
-
-            if (!is_suitable_sink(u, s))
-                continue;
-
-            if (!output_new(u, s)) {
-                pa_log("Failed to create sink input on sink '%s'.", s->name);
-                goto fail;
-            }
-        }
-    }
-
-    u->sink_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_put_hook_cb, u);
-    u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_EARLY, (pa_hook_cb_t) sink_unlink_hook_cb, u);
-    u->sink_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_state_changed_hook_cb, u);
-
-    if (!(u->thread = pa_thread_new("combine", thread_func, u))) {
-        pa_log("Failed to create thread.");
-        goto fail;
-    }
-
-    /* Activate the sink and the sink inputs */
-    pa_sink_put(u->sink);
-
-    PA_IDXSET_FOREACH(o, u->outputs, idx)
-        output_verify(o);
-
-    if (u->adjust_time > 0)
-        u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
-
-    pa_modargs_free(ma);
-
-    return 0;
-
-fail:
-
-    if (ma)
-        pa_modargs_free(ma);
-
-    pa__done(m);
-
-    return -1;
+    return u->module ? 0 : -1;
 }
 
+
 void pa__done(pa_module*m) {
     struct userdata *u;
-    struct output *o;
 
     pa_assert(m);
+    pa_assert(m->userdata);
 
-    if (!(u = m->userdata))
-        return;
-
-    pa_strlist_free(u->unlinked_slaves);
-
-    if (u->sink_put_slot)
-        pa_hook_slot_free(u->sink_put_slot);
-
-    if (u->sink_unlink_slot)
-        pa_hook_slot_free(u->sink_unlink_slot);
-
-    if (u->sink_state_changed_slot)
-        pa_hook_slot_free(u->sink_state_changed_slot);
-
-    if (u->outputs) {
-        while ((o = pa_idxset_first(u->outputs, NULL)))
-            output_free(o);
-
-        pa_idxset_free(u->outputs, NULL, NULL);
-    }
-
-    if (u->sink)
-        pa_sink_unlink(u->sink);
-
-    if (u->thread) {
-        pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
-        pa_thread_free(u->thread);
-    }
-
-    pa_thread_mq_done(&u->thread_mq);
-
-    if (u->sink)
-        pa_sink_unref(u->sink);
-
-    if (u->rtpoll)
-        pa_rtpoll_free(u->rtpoll);
-
-    if (u->time_event)
-        u->core->mainloop->time_free(u->time_event);
+    u = m->userdata;
 
-    if (u->thread_info.smoother)
-        pa_smoother_free(u->thread_info.smoother);
+    if (u)
+        pa_module_unload_request(u->module, TRUE);
 
     pa_xfree(u);
 }

commit 18e5d0d0899df20312b95c8cb74bf3f9b196eeeb
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:49 2011 +0200

    build-system: Simplify AC_ARG_ENABLE usage
    
    Make use of the enable_[feature] variable automatically defined
    by AC_ARG_ENABLE instead of defining our own variable.

diff --git a/configure.ac b/configure.ac
index 76cf7e9..f09ac00 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,25 +148,14 @@ AM_CONDITIONAL([BUILD_TESTS_DEFAULT], [test "x$enable_default_build_tests" != "x
 
 # Native atomic operation support
 AC_ARG_ENABLE([atomic-arm-linux-helpers],
-    AS_HELP_STRING([--disable-atomic-arm-linux-helpers],[use inline asm or libatomic_ops instead]),
-        [
-            case "${enableval}" in
-                yes) atomic_arm_linux_helpers=yes ;;
-                no) atomic_arm_linux_helpers=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-atomic-arm-linux-helpers) ;;
-            esac
-        ],
-        [atomic_arm_linux_helpers=auto])
+    AS_HELP_STRING([--disable-atomic-arm-linux-helpers],[use inline asm or libatomic_ops instead]))
 
 AC_ARG_ENABLE([atomic-arm-memory-barrier],
-    AS_HELP_STRING([--enable-atomic-arm-memory-barrier],[only really needed in SMP arm systems]),
-        [
-            case "${enableval}" in
-                yes) AC_DEFINE_UNQUOTED(ATOMIC_ARM_MEMORY_BARRIER_ENABLED, 1, [Enable memory barriers]) ;;
-                no) ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-atomic-arm-linux-helpers) ;;
-            esac
-        ],)
+    AS_HELP_STRING([--enable-atomic-arm-memory-barrier],[only really needed in SMP arm systems]))
+
+if test "x$enable_atomic_arm_memory_barrier" = "xyes"; then
+    AC_DEFINE_UNQUOTED(ATOMIC_ARM_MEMORY_BARRIER_ENABLED, 1, [Enable memory barriers])
+fi
 
 AC_ARG_ENABLE(mac-universal,
     AS_HELP_STRING([--enable-mac-universal], [Build Mac universal binaries]),
@@ -229,7 +218,7 @@ else
             # The Linux kernel helper functions have been there since 2.6.16. However
             # compile time checking for kernel version in cross compile environment
             # (which is usually the case for arm cpu) is tricky (or impossible).
-            if test "x$pulse_target_os" = "xlinux" && test "x$atomic_arm_linux_helpers" != "xno"; then
+            if test "x$pulse_target_os" = "xlinux" && test "x$enable_atomic_arm_linux_helpers" != "xno"; then
                 AC_MSG_RESULT([yes])
                 AC_DEFINE_UNQUOTED(ATOMIC_ARM_LINUX_HELPERS, 1, [special arm linux implementation])
                 need_libatomic_ops=no
@@ -580,22 +569,14 @@ PKG_PROG_PKG_CONFIG
 #### X11 (optional) ####
 
 AC_ARG_ENABLE([x11],
-    AS_HELP_STRING([--disable-x11],[Disable optional X11 support]),
-        [
-            case "${enableval}" in
-                yes) x11=yes ;;
-                no) x11=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-x11) ;;
-            esac
-        ],
-        [x11=auto])
+    AS_HELP_STRING([--disable-x11],[Disable optional X11 support]))
 
-if test "x${x11}" != xno ; then
+if test "x$enable_x11" != "xno"; then
     PKG_CHECK_MODULES(X11, [ x11-xcb xcb >= 1.6 ice sm xtst ],
         HAVE_X11=1,
         [
             HAVE_X11=0
-            if test "x$x11" = xyes ; then
+            if test "x$enable_x11" = "xyes"; then
                 AC_MSG_ERROR([*** X11 not found])
             fi
         ])
@@ -665,22 +646,14 @@ fi
 #### Libsamplerate support (optional) ####
 
 AC_ARG_ENABLE([samplerate],
-    AS_HELP_STRING([--disable-samplerate],[Disable optional libsamplerate support]),
-        [
-            case "${enableval}" in
-                yes) samplerate=yes ;;
-                no) samplerate=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-samplerate) ;;
-            esac
-        ],
-        [samplerate=auto])
+    AS_HELP_STRING([--disable-samplerate],[Disable optional libsamplerate support]))
 
-if test "x${samplerate}" != xno ; then
+if test "x$enable_samplerate" != "xno"; then
     PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ],
         HAVE_LIBSAMPLERATE=1,
         [
             HAVE_LIBSAMPLERATE=0
-            if test "x$samplerate" = xyes ; then
+            if test "x$enable_samplerate" = "xyes"; then
                 AC_MSG_ERROR([*** Libsamplerate not found])
             fi
         ])
@@ -772,41 +745,25 @@ AM_CONDITIONAL([HAVE_SIMPLEDB], [test "x$HAVE_SIMPLEDB" = x1])
 #### OSS support (optional) ####
 
 AC_ARG_ENABLE([oss-output],
-    AS_HELP_STRING([--disable-oss-output],[Disable optional OSS output support]),
-        [
-            case "${enableval}" in
-                yes) oss_output=yes ;;
-                no) oss_output=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-oss-output) ;;
-            esac
-        ],
-        [oss_output=auto])
+    AS_HELP_STRING([--disable-oss-output],[Disable optional OSS output support]))
 
 AC_ARG_ENABLE([oss-wrapper],
-    AS_HELP_STRING([--disable-oss-wrapper],[Disable optional OSS wrapper support]),
-        [
-            case "${enableval}" in
-                yes) oss_wrapper=yes ;;
-                no) oss_wrapper=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-oss-wrapper) ;;
-            esac
-        ],
-        [oss_wrapper=auto])
+    AS_HELP_STRING([--disable-oss-wrapper],[Disable optional OSS wrapper support]))
 
-if test "x${oss_output}" != xno || test "x${oss_wrapper}" != "xno"; then
+if test "x$enable_oss_output" != "xno" || test "x$enable_oss_wrapper" != "xno"; then
     AC_CHECK_HEADERS([sys/soundcard.h],
         [
-            if test "x${oss_output}" != "xno"; then
+            if test "x$enable_oss_output" != "xno"; then
                 AC_DEFINE([HAVE_OSS_OUTPUT], 1, [Have OSS output?])
             fi
-            if test "x${oss_wrapper}" != "xno"; then
+            if test "x$enable_oss_wrapper" != "xno"; then
                 AC_DEFINE([HAVE_OSS_WRAPPER], 1, [Have OSS wrapper (padsp)?])
             fi
             HAVE_OSS=1
         ],
         [
             HAVE_OSS=0
-            if test "x$oss_output" = xyes || test "x$oss_wrapper" = "xyes"; then
+            if test "x$enable_oss_output" = "xyes" || test "x$enable_oss_wrapper" = "xyes"; then
                 AC_MSG_ERROR([*** OSS support not found])
             fi
         ])
@@ -815,45 +772,29 @@ else
 fi
 
 AC_SUBST(HAVE_OSS)
-AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS" = x1 && test "x${oss_output}" != "xno"])
-AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS" = x1 && test "x${oss_wrapper}" != "xno"])
+AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS" = "x1" && test "x$enable_oss_output" != "xno"])
+AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS" = "x1" && test "x$enable_oss_wrapper" != "xno"])
 
 #### CoreAudio support (optional) ####
 
 AC_ARG_ENABLE([coreaudio-output],
-    AS_HELP_STRING([--disable-coreaudio-output],[Disable optional CoreAudio output support]),
-        [
-            case "${enableval}" in
-                yes) coreaudio_enabled=yes ;;
-                no) coreaudio_enabled=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-coreaudio-output) ;;
-            esac
-        ],
-        [coreaudio_enabled=auto])
+    AS_HELP_STRING([--disable-coreaudio-output],[Disable optional CoreAudio output support]))
 
-if test "x${coreaudio_enabled}" != xno ; then
+if test "x$enable_coreaudio_output" != "xno"; then
     AC_CHECK_HEADERS([CoreAudio/CoreAudio.h], HAVE_COREAUDIO=1)
 else
     HAVE_COREAUDIO=0
 fi
 
 AC_SUBST(HAVE_COREAUDIO)
-AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = x1 && test "x${coreaudio_enabled}" != "xno"])
+AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = "x1" && test "x$enable_coreaudio_output" != "xno"])
 
 #### ALSA support (optional) ####
 
 AC_ARG_ENABLE([alsa],
-    AS_HELP_STRING([--disable-alsa],[Disable optional ALSA support]),
-        [
-            case "${enableval}" in
-                yes) alsa=yes ;;
-                no) alsa=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-alsa) ;;
-            esac
-        ],
-        [alsa=auto])
+    AS_HELP_STRING([--disable-alsa],[Disable optional ALSA support]))
 
-if test "x${alsa}" != xno ; then
+if test "x$enable_alsa" != "xno"; then
     PKG_CHECK_MODULES(ASOUNDLIB, [ alsa >= 1.0.19 ],
         [
             HAVE_ALSA=1
@@ -861,7 +802,7 @@ if test "x${alsa}" != xno ; then
         ],
         [
             HAVE_ALSA=0
-            if test "x$alsa" = xyes ; then
+            if test "x$enable_alsa" = "xyes"; then
                 AC_MSG_ERROR([*** Needed alsa >= 1.0.19 support not found])
             fi
         ])
@@ -877,17 +818,9 @@ AM_CONDITIONAL([HAVE_ALSA], [test "x$HAVE_ALSA" = x1])
 #### Solaris audio support (optional) ####
 
 AC_ARG_ENABLE([solaris],
-    AS_HELP_STRING([--disable-solaris],[Disable optional Solaris audio support]),
-        [
-            case "${enableval}" in
-                yes) solaris=yes ;;
-                no) solaris=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-solaris) ;;
-            esac
-        ],
-        [solaris=auto])
+    AS_HELP_STRING([--disable-solaris],[Disable optional Solaris audio support]))
 
-if test "x${solaris}" != xno ; then
+if test "x$enable_solaris" != "xno"; then
     AC_CHECK_HEADERS([sys/audio.h],
         [
             HAVE_SOLARIS=1
@@ -895,7 +828,7 @@ if test "x${solaris}" != xno ; then
         ],
         [
             HAVE_SOLARIS=0
-            if test "x$solaris" = xyes ; then
+            if test "x$enable_solaris" = "xyes"; then
                 AC_MSG_ERROR([*** Solaris audio support not found])
             fi
         ])
@@ -909,17 +842,9 @@ AM_CONDITIONAL([HAVE_SOLARIS], [test "x$HAVE_SOLARIS" = x1])
 #### WaveOut audio support (optional) ####
 
 AC_ARG_ENABLE([waveout],
-    AS_HELP_STRING([--disable-waveout],[Disable optional WaveOut audio support]),
-        [
-            case "${enableval}" in
-                yes) waveout=yes ;;
-                no) waveout=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-waveout) ;;
-            esac
-        ],
-        [waveout=auto])
+    AS_HELP_STRING([--disable-waveout],[Disable optional WaveOut audio support]))
 
-if test "x${waveout}" != xno ; then
+if test "x$enable_waveout" != "xno"; then
     AC_CHECK_HEADERS([mmsystem.h],
         [
             HAVE_WAVEOUT=1
@@ -927,7 +852,7 @@ if test "x${waveout}" != xno ; then
         ],
         [
             HAVE_WAVEOUT=0
-            if test "x$waveout" = xyes ; then
+            if test "x$enable_waveout" = "xyes"; then
                 AC_MSG_ERROR([*** WaveOut audio support not found])
             fi
         ],
@@ -942,22 +867,14 @@ AM_CONDITIONAL([HAVE_WAVEOUT], [test "x$HAVE_WAVEOUT" = x1])
 #### GLib 2 support (optional) ####
 
 AC_ARG_ENABLE([glib2],
-    AS_HELP_STRING([--disable-glib2],[Disable optional GLib 2 support]),
-        [
-            case "${enableval}" in
-                yes) glib2=yes ;;
-                no) glib2=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-glib2) ;;
-            esac
-        ],
-        [glib2=auto])
+    AS_HELP_STRING([--disable-glib2],[Disable optional GLib 2 support]))
 
-if test "x${glib2}" != xno ; then
+if test "x$enable_glib2" != "xno"; then
     PKG_CHECK_MODULES(GLIB20, [ glib-2.0 >= 2.4.0 ],
         HAVE_GLIB20=1,
         [
             HAVE_GLIB20=0
-            if test "x$glib2" = xyes ; then
+            if test "x$enable_glib2" = "xyes"; then
                 AC_MSG_ERROR([*** GLib 2 support not found])
             fi
         ])
@@ -977,22 +894,14 @@ fi
 #### GTK2 support (optional) ####
 
 AC_ARG_ENABLE([gtk2],
-    AS_HELP_STRING([--disable-gtk2],[Disable optional Gtk+ 2 support]),
-        [
-            case "${enableval}" in
-                yes) gtk2=yes ;;
-                no) gtk2=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-gtk2) ;;
-            esac
-        ],
-        [gtk2=auto])
+    AS_HELP_STRING([--disable-gtk2],[Disable optional Gtk+ 2 support]))
 
-if test "x${gtk2}" != xno ; then
+if test "x$enable_gtk2" != "xno"; then
     PKG_CHECK_MODULES(GTK20, [ gtk+-2.0 >= 2.4.0 ],
         HAVE_GTK20=1,
         [
             HAVE_GTK20=0
-            if test "x$gtk2" = xyes ; then
+            if test "x$enable_gtk2" = "xyes"; then
                 AC_MSG_ERROR([*** Gtk+ 2 support not found])
             fi
         ])
@@ -1012,22 +921,14 @@ fi
 #### GConf support (optional) ####
 
 AC_ARG_ENABLE([gconf],
-    AS_HELP_STRING([--disable-gconf],[Disable optional GConf support]),
-        [
-            case "${enableval}" in
-                yes) gconf=yes ;;
-                no) gconf=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-gconf) ;;
-            esac
-        ],
-        [gconf=auto])
+    AS_HELP_STRING([--disable-gconf],[Disable optional GConf support]))
 
-if test "x${gconf}" != xno ; then
+if test "x$enable_gconf" != "xno"; then
     PKG_CHECK_MODULES(GCONF, [ gconf-2.0 >= 2.4.0 gobject-2.0 ],
         HAVE_GCONF=1,
         [
             HAVE_GCONF=0
-            if test "x$gconf" = xyes ; then
+            if test "x$enable_gconf" = "xyes"; then
                 AC_MSG_ERROR([*** GConf support not found])
             fi
         ])
@@ -1043,22 +944,14 @@ AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = x1])
 #### Avahi support (optional) ####
 
 AC_ARG_ENABLE([avahi],
-    AS_HELP_STRING([--disable-avahi],[Disable optional Avahi support]),
-        [
-            case "${enableval}" in
-                yes) avahi=yes ;;
-                no) avahi=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-avahi) ;;
-            esac
-        ],
-        [avahi=auto])
+    AS_HELP_STRING([--disable-avahi],[Disable optional Avahi support]))
 
-if test "x${avahi}" != xno ; then
+if test "x$enable_avahi" != "xno"; then
     PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6.0 ],
         HAVE_AVAHI=1,
         [
                 HAVE_AVAHI=0
-                if test "x$avahi" = xyes ; then
+                if test "x$enable_avahi" = "xyes"; then
                         AC_MSG_ERROR([*** Avahi support not found])
                 fi
         ])
@@ -1074,22 +967,14 @@ AM_CONDITIONAL([HAVE_AVAHI], [test "x$HAVE_AVAHI" = x1])
 ### JACK (optional) ####
 
 AC_ARG_ENABLE([jack],
-    AS_HELP_STRING([--disable-jack],[Disable optional JACK support]),
-        [
-            case "${enableval}" in
-                yes) jack=yes ;;
-                no) jack=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-jack) ;;
-            esac
-        ],
-        [jack=auto])
+    AS_HELP_STRING([--disable-jack],[Disable optional JACK support]))
 
-if test "x${jack}" != xno ; then
+if test "x$enable_jack" != "xno"; then
     PKG_CHECK_MODULES(JACK, [ jack >= 0.100 ],
         HAVE_JACK=1,
         [
             HAVE_JACK=0
-            if test "x$jack" = xyes ; then
+            if test "x$enable_jack" = "xyes"; then
                 AC_MSG_ERROR([*** JACK support not found])
             fi
         ])
@@ -1105,22 +990,14 @@ AM_CONDITIONAL([HAVE_JACK], [test "x$HAVE_JACK" = x1])
 #### Async DNS support (optional) ####
 
 AC_ARG_ENABLE([asyncns],
-    AS_HELP_STRING([--disable-asyncns],[Disable optional Async DNS support]),
-        [
-            case "${enableval}" in
-                yes) asyncns=yes ;;
-                no) asyncns=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-asyncns) ;;
-            esac
-        ],
-        [asyncns=auto])
+    AS_HELP_STRING([--disable-asyncns],[Disable optional Async DNS support]))
 
-if test "x${asyncns}" != xno ; then
+if test "x$enable_asyncns" != "xno"; then
     PKG_CHECK_MODULES(LIBASYNCNS, [ libasyncns >= 0.1 ],
         HAVE_LIBASYNCNS=1,
         [
             HAVE_LIBASYNCNS=0
-            if test "x$asyncns" = xyes ; then
+            if test "x$enable_asyncns" = "xyes"; then
                 AC_MSG_ERROR([*** Async DNS support not found])
             fi
         ])
@@ -1140,19 +1017,11 @@ fi
 #### TCP wrappers (optional) ####
 
 AC_ARG_ENABLE([tcpwrap],
-    AS_HELP_STRING([--disable-tcpwrap],[Disable optional TCP wrappers support]),
-        [
-            case "${enableval}" in
-                yes) tcpwrap=yes ;;
-                no) tcpwrap=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-tcpwrap) ;;
-            esac
-        ],
-        [tcpwrap=auto])
+    AS_HELP_STRING([--disable-tcpwrap],[Disable optional TCP wrappers support]))
 
-if test "x${tcpwrap}" != xno ; then
+if test "x$enable_tcpwrap" != "xno"; then
     ACX_LIBWRAP
-    if test "x${LIBWRAP_LIBS}" = x && test "x$tcpwrap" = xyes ; then
+    if test "x${LIBWRAP_LIBS}" = "x" && test "x$enable_tcpwrap" = "xyes"; then
         AC_MSG_ERROR([*** TCP wrappers support not found])
     fi
 else
@@ -1164,19 +1033,11 @@ AC_SUBST(LIBWRAP_LIBS)
 #### LIRC support (optional) ####
 
 AC_ARG_ENABLE([lirc],
-    AS_HELP_STRING([--disable-lirc],[Disable optional LIRC support]),
-        [
-            case "${enableval}" in
-                yes) lirc=yes ;;
-                no) lirc=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-lirc) ;;
-            esac
-        ],
-        [lirc=auto])
+    AS_HELP_STRING([--disable-lirc],[Disable optional LIRC support]))
 
-if test "x${lirc}" != xno ; then
+if test "x$enable_lirc" != "xno"; then
     ACX_LIRC
-    if test "x${HAVE_LIRC}" = x0 && test "x$lirc" = xyes ; then
+    if test "x${HAVE_LIRC}" = "x0" && test "x$enable_lirc" = "xyes"; then
         AC_MSG_ERROR([*** LIRC support not found])
     fi
 else
@@ -1190,16 +1051,9 @@ AM_CONDITIONAL([HAVE_LIRC], [test "x$HAVE_LIRC" = x1])
 #### HAL support (optional) ####
 
 AC_ARG_ENABLE([hal],
-    AS_HELP_STRING([--disable-hal],[Disable optional HAL support]),
-        [
-            case "${enableval}" in
-                yes) hal=yes ;;
-                no) hal=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-hal) ;;
-            esac
-        ],
-        [hal=auto])
-if test "x${hal}" != xno -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \) ; then
+    AS_HELP_STRING([--disable-hal],[Disable optional HAL support]))
+
+if test "x$enable_hal" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \); then
     PKG_CHECK_MODULES(HAL, [ hal >= 0.5.11 ],
         [
             HAVE_HAL=1
@@ -1207,7 +1061,7 @@ if test "x${hal}" != xno -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \) ;
         ],
         [
             HAVE_HAL=0
-            if test "x$hal" = xyes ; then
+            if test "x$enable_hal" = "xyes"; then
                 AC_MSG_ERROR([*** HAL support not found])
             fi
         ])
@@ -1223,16 +1077,9 @@ AM_CONDITIONAL([HAVE_HAL], [test "x$HAVE_HAL" = x1])
 #### UDEV support (optional) ####
 
 AC_ARG_ENABLE([udev],
-    AS_HELP_STRING([--disable-udev],[Disable optional UDEV support]),
-        [
-            case "${enableval}" in
-                yes) udev=yes ;;
-                no) udev=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-udev) ;;
-            esac
-        ],
-        [udev=auto])
-if test "x${udev}" != xno -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \) ; then
+    AS_HELP_STRING([--disable-udev],[Disable optional UDEV support]))
+
+if test "x$enable_udev" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \); then
     PKG_CHECK_MODULES(UDEV, [ libudev >= 143 ],
         [
             HAVE_UDEV=1
@@ -1240,7 +1087,7 @@ if test "x${udev}" != xno -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \) ;
         ],
         [
             HAVE_UDEV=0
-            if test "x$udev" = xyes ; then
+            if test "x$enable_udev" = "xyes"; then
                 AC_MSG_ERROR([*** UDEV support not found])
             fi
         ])
@@ -1256,21 +1103,14 @@ AM_CONDITIONAL([HAVE_UDEV], [test "x$HAVE_UDEV" = x1])
 #### BlueZ support (optional) ####
 
 AC_ARG_ENABLE([bluez],
-    AS_HELP_STRING([--disable-bluez],[Disable optional BlueZ support]),
-        [
-            case "${enableval}" in
-                yes) bluez=yes ;;
-                no) bluez=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-bluez) ;;
-            esac
-        ],
-        [bluez=auto])
-if test "x${bluez}" != xno ; then
+    AS_HELP_STRING([--disable-bluez],[Disable optional BlueZ support]))
+
+if test "x$enable_bluez" != "xno"; then
     PKG_CHECK_MODULES(BLUEZ, [ bluez >= 3.0 ],
         HAVE_BLUEZ=1,
         [
             HAVE_BLUEZ=0
-            if test "x$bluez" = xyes ; then
+            if test "x$enable_bluez" = "xyes"; then
                 AC_MSG_ERROR([*** BLUEZ support not found])
             fi
         ])
@@ -1286,18 +1126,9 @@ AM_CONDITIONAL([HAVE_BLUEZ], [test "x$HAVE_BLUEZ" = x1])
 #### D-Bus support (optional) ####
 
 AC_ARG_ENABLE([dbus],
-    AS_HELP_STRING([--disable-dbus],[Disable optional D-Bus support]),
-        [
-            case "${enableval}" in
-                yes) dbus=yes ;;
-                no) dbus=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-dbus) ;;
-            esac
-        ],
-        [dbus=auto])
-
-if test "x${dbus}" != xno ; then
+    AS_HELP_STRING([--disable-dbus],[Disable optional D-Bus support]))
 
+if test "x$enable_dbus" != "xno"; then
     PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 1.0.0 ],
         [
             HAVE_DBUS=1
@@ -1310,7 +1141,7 @@ if test "x${dbus}" != xno ; then
         ],
         [
             HAVE_DBUS=0
-            if test "x$dbus" = xyes ; then
+            if test "x$enable_dbus" = "xyes"; then
                 AC_MSG_ERROR([*** D-Bus support not found])
             fi
         ])
@@ -1327,12 +1158,12 @@ AM_CONDITIONAL([HAVE_DBUS], [test "x$HAVE_DBUS" = x1])
 # udev and HAL depend on D-Bus: So double check if they were explicitly enabled.
 if test "x$HAVE_DBUS" != "x1" ; then
     HAVE_HAL=0
-    if test "x${hal}" = xyes ; then
+    if test "x$enable_hal" = "xyes"; then
         AC_MSG_ERROR([*** D-Bus support is required by HAL])
     fi
 
     HAVE_BLUEZ=0
-    if test "x${bluez}" = xyes ; then
+    if test "x$enable_bluez" = "xyes"; then
         AC_MSG_ERROR([*** D-Bus support is required by BLUEZ])
     fi
 fi
@@ -1341,16 +1172,9 @@ fi
 #### HAL compat support (optional) ####
 
 AC_ARG_ENABLE([hal-compat],
-    AS_HELP_STRING([--disable-hal-compat],[Disable optional HAL->udev transition compatibility support]),
-        [
-            case "${enableval}" in
-                yes) halcompat=yes ;;
-                no) halcompat=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-hal-compat) ;;
-            esac
-        ],
-        [halcompat=auto])
-if test "x${halcompat}" != xno -a "x$HAVE_HAL" = "x0" -a "x$HAVE_UDEV" = "x1" ; then
+    AS_HELP_STRING([--disable-hal-compat],[Disable optional HAL->udev transition compatibility support]))
+
+if test "x$enable_hal_compat" != "xno" -a "x$HAVE_HAL" = "x0" -a "x$HAVE_UDEV" = "x1"; then
     HAVE_HAL_COMPAT=1
     AC_DEFINE([HAVE_HAL_COMPAT], 1, [Have HAL compatibility.])
 else
@@ -1363,17 +1187,9 @@ AM_CONDITIONAL([HAVE_HAL_COMPAT], [test "x$HAVE_HAL_COMPAT" = x1])
 ### IPv6 connection support (optional) ###
 
 AC_ARG_ENABLE([ipv6],
-    AS_HELP_STRING([--disable-ipv6],[Disable optional IPv6 support]),
-        [
-            case "${enableval}" in
-                yes) ipv6=yes ;;
-                no) ipv6=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-ipv6) ;;
-            esac
-        ],
-        [ipv6=auto])
+    AS_HELP_STRING([--disable-ipv6],[Disable optional IPv6 support]))
 
-if test "x${ipv6}" != xno ; then
+if test "x$enable_ipv6" != "xno"; then
     AC_DEFINE([HAVE_IPV6], [1], [Define this to enable IPv6 connection support])
     HAVE_IPV6=1
 else
@@ -1383,17 +1199,9 @@ fi
 #### OpenSSL support (optional) ####
 
 AC_ARG_ENABLE([openssl],
-    AS_HELP_STRING([--disable-openssl],[Disable OpenSSL support (used for Airtunes/RAOP)]),
-        [
-            case "${enableval}" in
-                yes) openssl=yes ;;
-                no) openssl=no ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-openssl) ;;
-            esac
-        ],
-        [openssl=auto])
+    AS_HELP_STRING([--disable-openssl],[Disable OpenSSL support (used for Airtunes/RAOP)]))
 
-if test "x${openssl}" != xno ; then
+if test "x$enable_openssl" != "xno"; then
 
     PKG_CHECK_MODULES(OPENSSL, [ openssl > 0.9 ],
         [
@@ -1402,7 +1210,7 @@ if test "x${openssl}" != xno ; then
         ],
         [
             HAVE_OPENSSL=0
-            if test "x$openssl" = xyes ; then
+            if test "x$enable_openssl" = "xyes"; then
                 AC_MSG_ERROR([*** OpenSSL support not found])
             fi
         ])
@@ -1416,9 +1224,8 @@ AC_SUBST(HAVE_OPENSSL)
 AM_CONDITIONAL([HAVE_OPENSSL], [test "x$HAVE_OPENSSL" = x1])
 
 #### FFTW (optional) ####
-AC_ARG_WITH(
-	[fftw],
-	AS_HELP_STRING([--without-fftw], [Omit FFTW-using modules (equalizer)]))
+AC_ARG_WITH([fftw],
+    AS_HELP_STRING([--without-fftw],[Omit FFTW-using modules (equalizer)]))
 
 if test "x${with_fftw}" != "xno"; then
     PKG_CHECK_MODULES([FFTW], [fftw3f], [HAVE_FFTW=1], [HAVE_FFTW=0])
@@ -1429,15 +1236,10 @@ AM_CONDITIONAL([HAVE_FFTW], [test "x$HAVE_FFTW" = "x1"])
 ORC_CHECK([0.4.11])
 
 ### Build and Install man pages ###
-AC_ARG_ENABLE(manpages,
-        AS_HELP_STRING([--disable-manpages],[Disable building and installation of man pages]),
-[case "${enableval}" in
-  yes) manpages=yes ;;
-  no)  manpages=no ;;
-  *) AC_MSG_ERROR([bad value ${enableval} for --disable-manpages]) ;;
-esac],[manpages=yes])
+AC_ARG_ENABLE([manpages],
+    AS_HELP_STRING([--disable-manpages],[Disable building and installation of man pages]))
 
-AM_CONDITIONAL([BUILD_MANPAGES], [test "x$manpages" = xyes])
+AM_CONDITIONAL([BUILD_MANPAGES], [test "x$enable_manpages" != "xno"])
 
 #### PulseAudio system group & user  #####
 
@@ -1468,19 +1270,10 @@ fi
 AC_SUBST(PA_ACCESS_GROUP)
 AC_DEFINE_UNQUOTED(PA_ACCESS_GROUP,"$PA_ACCESS_GROUP", [Access group])
 
-AC_ARG_ENABLE(
-        per_user_esound_socket,
-        AS_HELP_STRING([--disable-per-user-esound-socket], [Use global esound socket directory /tmp/.esd/socket.]),
-        [
-            case "${enableval}" in
-                yes) per_user_esound_socket=1 ;;
-                no) per_user_esound_socket=0 ;;
-                *) AC_MSG_ERROR(bad value ${enableval} for --disable-per-user-esound-socket) ;;
-            esac
-        ],
-        [per_user_esound_socket=1])
+AC_ARG_ENABLE([per-user-esound-socket],
+    AS_HELP_STRING([--disable-per-user-esound-socket],[Use global esound socket directory /tmp/.esd/socket.]))
 
-if test "x$per_user_esound_socket" = "x1"; then
+if test "x$enable_per_user_esound_socket" != "xno"; then
    AC_DEFINE([USE_PER_USER_ESOUND_SOCKET], [1], [Define this if you want per-user esound socket directories])
 fi
 
@@ -1502,10 +1295,15 @@ if test "x$enable_legacy_runtime_dir" != "xno" ; then
         AC_DEFINE(ENABLE_LEGACY_RUNTIME_DIR, [1], [Legacy runtime dir])
 fi
 
-AC_ARG_ENABLE(
-        [static-bins],
-        AS_HELP_STRING([--enable-static-bins],[Statically link executables.]),
-        [STATIC_BINS=1], [STATIC_BINS=0])
+AC_ARG_ENABLE([static-bins],
+    AS_HELP_STRING([--enable-static-bins],[Statically link executables.]))
+
+if test "x$enable_static_bins" = "xyes"; then
+    STATIC_BINS=1
+else
+    STATIC_BINS=0
+fi
+
 AM_CONDITIONAL([STATIC_BINS], [test "x$STATIC_BINS" = "x1"])
 
 AC_ARG_WITH(
@@ -1536,10 +1334,15 @@ AC_ARG_WITH(
 
 AC_SUBST(udevrulesdir)
 
-AC_ARG_ENABLE(
-        [force-preopen],
-        AS_HELP_STRING([--enable-force-preopen],[Preopen modules, even when dlopen() is supported.]),
-        [FORCE_PREOPEN=$enableval], [FORCE_PREOPEN=no])
+AC_ARG_ENABLE([force-preopen],
+    AS_HELP_STRING([--enable-force-preopen],[Preopen modules, even when dlopen() is supported.]))
+
+if test "x$enable_force_preopen" = "xyes"; then
+    FORCE_PREOPEN=yes
+else
+    FORCE_PREOPEN=no
+fi
+
 AM_CONDITIONAL([FORCE_PREOPEN], [test "x$FORCE_PREOPEN" = "xyes"])
 
 AC_CONFIG_FILES([
@@ -1701,7 +1504,7 @@ if test "x${HAVE_IPV6}" = "x1" ; then
 fi
 
 ENABLE_PER_USER_ESOUND_SOCKET=no
-if test "x$per_user_esound_socket" = "x1" ; then
+if test "x$enable_per_user_esound_socket" != "xno"; then
    ENABLE_PER_USER_ESOUND_SOCKET=yes
 fi
 

commit 78d174c29dbb76460980b5df329134c613523987
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:50 2011 +0200

    build-system: Use AS_IF macro for configure output
    
    And add some HAVE_[feature] variables for clarity.

diff --git a/configure.ac b/configure.ac
index f09ac00..f7418f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -754,26 +754,32 @@ if test "x$enable_oss_output" != "xno" || test "x$enable_oss_wrapper" != "xno";
     AC_CHECK_HEADERS([sys/soundcard.h],
         [
             if test "x$enable_oss_output" != "xno"; then
+                HAVE_OSS_OUTPUT=1
                 AC_DEFINE([HAVE_OSS_OUTPUT], 1, [Have OSS output?])
             fi
             if test "x$enable_oss_wrapper" != "xno"; then
+                HAVE_OSS_WRAPPER=1
                 AC_DEFINE([HAVE_OSS_WRAPPER], 1, [Have OSS wrapper (padsp)?])
             fi
             HAVE_OSS=1
         ],
         [
             HAVE_OSS=0
+            HAVE_OSS_OUTPUT=0
+            HAVE_OSS_WRAPPER=0
             if test "x$enable_oss_output" = "xyes" || test "x$enable_oss_wrapper" = "xyes"; then
                 AC_MSG_ERROR([*** OSS support not found])
             fi
         ])
 else
     HAVE_OSS=0
+    HAVE_OSS_OUTPUT=0
+    HAVE_OSS_WRAPPER=0
 fi
 
 AC_SUBST(HAVE_OSS)
-AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS" = "x1" && test "x$enable_oss_output" != "xno"])
-AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS" = "x1" && test "x$enable_oss_wrapper" != "xno"])
+AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS_OUTPUT" = "x1"])
+AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS_WRAPPER" = "x1"])
 
 #### CoreAudio support (optional) ####
 
@@ -1021,11 +1027,15 @@ AC_ARG_ENABLE([tcpwrap],
 
 if test "x$enable_tcpwrap" != "xno"; then
     ACX_LIBWRAP
-    if test "x${LIBWRAP_LIBS}" = "x" && test "x$enable_tcpwrap" = "xyes"; then
-        AC_MSG_ERROR([*** TCP wrappers support not found])
+    HAVE_TCPWRAP=1
+    if test "x${LIBWRAP_LIBS}" = "x"; then
+        HAVE_TCPWRAP=0
+        if test "x$enable_tcpwrap" = "xyes"; then
+            AC_MSG_ERROR([*** TCP wrappers support not found])
+        fi
     fi
 else
-    LIBWRAP_LIBS=
+    HAVE_TCPWRAP=0
 fi
 
 AC_SUBST(LIBWRAP_LIBS)
@@ -1274,7 +1284,10 @@ AC_ARG_ENABLE([per-user-esound-socket],
     AS_HELP_STRING([--disable-per-user-esound-socket],[Use global esound socket directory /tmp/.esd/socket.]))
 
 if test "x$enable_per_user_esound_socket" != "xno"; then
-   AC_DEFINE([USE_PER_USER_ESOUND_SOCKET], [1], [Define this if you want per-user esound socket directories])
+    USE_PER_USER_ESOUND_SOCKET=1
+    AC_DEFINE([USE_PER_USER_ESOUND_SOCKET], [1], [Define this if you want per-user esound socket directories])
+else
+    USE_PER_USER_ESOUND_SOCKET=0
 fi
 
 #### PulseAudio system runtime dir ####
@@ -1362,151 +1375,36 @@ po/Makefile.in
 AC_OUTPUT
 
 # ==========================================================================
-ENABLE_X11=no
-if test "x$HAVE_X11" = "x1" ; then
-   ENABLE_X11=yes
-fi
-
-ENABLE_OSS_OUTPUT=no
-ENABLE_OSS_WRAPPER=no
-if test "x$HAVE_OSS" = "x1" ; then
-   if test "x$enable_oss_output" != "xno"; then
-      ENABLE_OSS_OUTPUT=yes
-   fi
-   if test "x$enable_oss_wrapper" != "xno"; then
-      ENABLE_OSS_WRAPPER=yes
-   fi
-fi
-
-ENABLE_COREAUDIO=no
-if test "x$HAVE_COREAUDIO" = "x1" ; then
-   ENABLE_COREAUDIO=yes
-fi
-
-ENABLE_ALSA=no
-if test "x$HAVE_ALSA" = "x1" ; then
-   ENABLE_ALSA=yes
-fi
-
-ENABLE_SOLARIS=no
-if test "x$HAVE_SOLARIS" = "x1" ; then
-   ENABLE_SOLARIS=yes
-fi
-
-ENABLE_WAVEOUT=no
-if test "x$HAVE_WAVEOUT" = "x1" ; then
-   ENABLE_WAVEOUT=yes
-fi
-
-ENABLE_GTK20=no
-if test "x$HAVE_GTK20" = "x1" ; then
-   ENABLE_GTK20=yes
-fi
-
-ENABLE_GLIB20=no
-if test "x$HAVE_GLIB20" = "x1" ; then
-   ENABLE_GLIB20=yes
-fi
-
-ENABLE_GCONF=no
-if test "x$HAVE_GCONF" = "x1" ; then
-   ENABLE_GCONF=yes
-fi
-
-ENABLE_AVAHI=no
-if test "x$HAVE_AVAHI" = "x1" ; then
-   ENABLE_AVAHI=yes
-fi
-
-ENABLE_JACK=no
-if test "x$HAVE_JACK" = "x1" ; then
-   ENABLE_JACK=yes
-fi
-
-ENABLE_LIBASYNCNS=no
-if test "x$HAVE_LIBASYNCNS" = "x1" ; then
-   ENABLE_LIBASYNCNS=yes
-fi
-
-ENABLE_LIRC=no
-if test "x$HAVE_LIRC" = "x1" ; then
-   ENABLE_LIRC=yes
-fi
-
-ENABLE_DBUS=no
-if test "x$HAVE_DBUS" = "x1" ; then
-   ENABLE_DBUS=yes
-fi
-
-ENABLE_HAL=no
-if test "x$HAVE_HAL" = "x1" ; then
-   ENABLE_HAL=yes
-fi
-
-ENABLE_UDEV=no
-if test "x$HAVE_UDEV" = "x1" ; then
-   ENABLE_UDEV=yes
-fi
-
-ENABLE_HAL_COMPAT=no
-if test "x$HAVE_HAL_COMPAT" = "x1" ; then
-   ENABLE_HAL_COMPAT=yes
-fi
-
-ENABLE_TCPWRAP=no
-if test "x${LIBWRAP_LIBS}" != x ; then
-   ENABLE_TCPWRAP=yes
-fi
-
-ENABLE_LIBSAMPLERATE=no
-if test "x${HAVE_LIBSAMPLERATE}" = "x1" ; then
-   ENABLE_LIBSAMPLERATE=yes
-fi
-
-ENABLE_BLUEZ=no
-if test "x${HAVE_BLUEZ}" = "x1" ; then
-   ENABLE_BLUEZ=yes
-fi
-
-ENABLE_GDBM=no
-if test "x${HAVE_GDBM}" = "x1" ; then
-   ENABLE_GDBM=yes
-fi
 
-ENABLE_TDB=no
-if test "x${HAVE_TDB}" = "x1" ; then
-   ENABLE_TDB=yes
-fi
-
-ENABLE_SIMPLEDB=no
-if test "x${HAVE_SIMPLEDB}" = "x1" ; then
-    ENABLE_SIMPLEDB=yes
-fi
-
-ENABLE_FFTW=no
-if test "x${HAVE_FFTW}" = "x1" ; then
-   ENABLE_FFTW=yes
-fi
-
-ENABLE_ORC=no
-if test "x${HAVE_ORC}" = "xyes" ; then
-   ENABLE_ORC=yes
-fi
-
-ENABLE_OPENSSL=no
-if test "x${HAVE_OPENSSL}" = "x1" ; then
-   ENABLE_OPENSSL=yes
-fi
-
-ENABLE_IPV6=no
-if test "x${HAVE_IPV6}" = "x1" ; then
-   ENABLE_IPV6=yes
-fi
-
-ENABLE_PER_USER_ESOUND_SOCKET=no
-if test "x$enable_per_user_esound_socket" != "xno"; then
-   ENABLE_PER_USER_ESOUND_SOCKET=yes
-fi
+AS_IF([test "x$HAVE_X11" = "x1"], ENABLE_X11=yes, ENABLE_X11=no)
+AS_IF([test "x$HAVE_OSS_OUTPUT" = "x1"], ENABLE_OSS_OUTPUT=yes, ENABLE_OSS_OUTPUT=no)
+AS_IF([test "x$HAVE_OSS_WRAPPER" = "x1"], ENABLE_OSS_WRAPPER=yes, ENABLE_OSS_WRAPPER=no)
+AS_IF([test "x$HAVE_ALSA" = "x1"], ENABLE_ALSA=yes, ENABLE_ALSA=no)
+AS_IF([test "x$HAVE_COREAUDIO" = "x1"], ENABLE_COREAUDIO=yes, ENABLE_COREAUDIO=no)
+AS_IF([test "x$HAVE_SOLARIS" = "x1"], ENABLE_SOLARIS=yes, ENABLE_SOLARIS=no)
+AS_IF([test "x$HAVE_WAVEOUT" = "x1"], ENABLE_WAVEOUT=yes, ENABLE_WAVEOUT=no)
+AS_IF([test "x$HAVE_GLIB20" = "x1"], ENABLE_GLIB20=yes, ENABLE_GLIB20=no)
+AS_IF([test "x$HAVE_GTK20" = "x1"], ENABLE_GTK20=yes, ENABLE_GTK20=no)
+AS_IF([test "x$HAVE_GCONF" = "x1"], ENABLE_GCONF=yes, ENABLE_GCONF=no)
+AS_IF([test "x$HAVE_AVAHI" = "x1"], ENABLE_AVAHI=yes, ENABLE_AVAHI=no)
+AS_IF([test "x$HAVE_JACK" = "x1"], ENABLE_JACK=yes, ENABLE_JACK=no)
+AS_IF([test "x$HAVE_LIBASYNCNS" = "x1"], ENABLE_LIBASYNCNS=yes, ENABLE_LIBASYNCNS=no)
+AS_IF([test "x$HAVE_LIRC" = "x1"], ENABLE_LIRC=yes, ENABLE_LIRC=no)
+AS_IF([test "x$HAVE_DBUS" = "x1"], ENABLE_DBUS=yes, ENABLE_DBUS=no)
+AS_IF([test "x$HAVE_HAL" = "x1"], ENABLE_HAL=yes, ENABLE_HAL=no)
+AS_IF([test "x$HAVE_UDEV" = "x1"], ENABLE_UDEV=yes, ENABLE_UDEV=no)
+AS_IF([test "x$HAVE_BLUEZ" = "x1"], ENABLE_BLUEZ=yes, ENABLE_BLUEZ=no)
+AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, ENABLE_HAL_COMPAT=no)
+AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, ENABLE_TCPWRAP=no)
+AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], ENABLE_LIBSAMPLERATE=yes, ENABLE_LIBSAMPLERATE=no)
+AS_IF([test "x$HAVE_IPV6" = "x1"], ENABLE_IPV6=yes, ENABLE_IPV6=no)
+AS_IF([test "x$HAVE_OPENSSL" = "x1"], ENABLE_OPENSSL=yes, ENABLE_OPENSSL=no)
+AS_IF([test "x$HAVE_FFTW" = "x1"], ENABLE_FFTW=yes, ENABLE_FFTW=no)
+AS_IF([test "x$HAVE_ORC" = "xyes"], ENABLE_ORC=yes, ENABLE_ORC=no)
+AS_IF([test "x$HAVE_TDB" = "x1"], ENABLE_TDB=yes, ENABLE_TDB=no)
+AS_IF([test "x$HAVE_GDBM" = "x1"], ENABLE_GDBM=yes, ENABLE_GDBM=no)
+AS_IF([test "x$HAVE_SIMPLEDB" = "x1"], ENABLE_SIMPLEDB=yes, ENABLE_SIMPLEDB=no)
+AS_IF([test "x$USE_PER_USER_ESOUND_SOCKET" = "x1"], ENABLE_PER_USER_ESOUND_SOCKET=yes, ENABLE_PER_USER_ESOUND_SOCKET=no)
 
 echo "
  ---{ $PACKAGE_NAME $VERSION }---

commit 459b5ef94d86b81eb72019759d95c3f4e1551ab1
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:51 2011 +0200

    build-system: Move AC_DEFINE to separate line with AS_IF

diff --git a/configure.ac b/configure.ac
index f7418f0..7edb22f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -584,14 +584,11 @@ else
     HAVE_X11=0
 fi
 
-if test "x${HAVE_X11}" = x1 ; then
-   AC_DEFINE([HAVE_X11], 1, [Have X11?])
-fi
-
 AC_SUBST(X11_CFLAGS)
 AC_SUBST(X11_LIBS)
 AC_SUBST(HAVE_X11)
 AM_CONDITIONAL([HAVE_X11], [test "x$HAVE_X11" = x1])
+AS_IF([test "x$HAVE_X11" = "x1"], AC_DEFINE([HAVE_X11], 1, [Have X11?]))
 
 #### Capabilities (optional) ####
 
@@ -661,14 +658,11 @@ else
     HAVE_LIBSAMPLERATE=0
 fi
 
-if test "x${HAVE_LIBSAMPLERATE}" = x1 ; then
-   AC_DEFINE([HAVE_LIBSAMPLERATE], 1, [Have libsamplerate?])
-fi
-
 AC_SUBST(LIBSAMPLERATE_CFLAGS)
 AC_SUBST(LIBSAMPLERATE_LIBS)
 AC_SUBST(HAVE_LIBSAMPLERATE)
 AM_CONDITIONAL([HAVE_LIBSAMPLERATE], [test "x$HAVE_LIBSAMPLERATE" = x1])
+AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], AC_DEFINE([HAVE_LIBSAMPLERATE], 1, [Have libsamplerate?]))
 
 #### Database support ####
 
@@ -717,30 +711,21 @@ if test "x${HAVE_TDB}" != x1 -a "x${HAVE_GDBM}" != x1 -a "x${HAVE_SIMPLEDB}" !=
    AC_MSG_ERROR([*** missing database backend])
 fi
 
-if test "x${HAVE_TDB}" = x1 ; then
-   AC_DEFINE([HAVE_TDB], 1, [Have tdb?])
-fi
-
-if test "x${HAVE_GDBM}" = x1 ; then
-   AC_DEFINE([HAVE_GDBM], 1, [Have gdbm?])
-fi
-
-if test "x${HAVE_SIMPLEDB}" = x1 ; then
-    AC_DEFINE([HAVE_SIMPLEDB], 1, [Have simple?])
-fi
-
 AC_SUBST(TDB_CFLAGS)
 AC_SUBST(TDB_LIBS)
 AC_SUBST(HAVE_TDB)
 AM_CONDITIONAL([HAVE_TDB], [test "x$HAVE_TDB" = x1])
+AS_IF([test "x$HAVE_TDB" = "x1"], AC_DEFINE([HAVE_TDB], 1, [Have tdb?]))
 
 AC_SUBST(GDBM_CFLAGS)
 AC_SUBST(GDBM_LIBS)
 AC_SUBST(HAVE_GDBM)
 AM_CONDITIONAL([HAVE_GDBM], [test "x$HAVE_GDBM" = x1])
+AS_IF([test "x$HAVE_GDBM" = "x1"], AC_DEFINE([HAVE_GDBM], 1, [Have gdbm?]))
 
 AC_SUBST(HAVE_SIMPLEDB)
 AM_CONDITIONAL([HAVE_SIMPLEDB], [test "x$HAVE_SIMPLEDB" = x1])
+AS_IF([test "x$HAVE_SIMPLEDB" = "x1"], AC_DEFINE([HAVE_SIMPLEDB], 1, [Have simple?]))
 
 #### OSS support (optional) ####
 
@@ -755,11 +740,9 @@ if test "x$enable_oss_output" != "xno" || test "x$enable_oss_wrapper" != "xno";
         [
             if test "x$enable_oss_output" != "xno"; then
                 HAVE_OSS_OUTPUT=1
-                AC_DEFINE([HAVE_OSS_OUTPUT], 1, [Have OSS output?])
             fi
             if test "x$enable_oss_wrapper" != "xno"; then
                 HAVE_OSS_WRAPPER=1
-                AC_DEFINE([HAVE_OSS_WRAPPER], 1, [Have OSS wrapper (padsp)?])
             fi
             HAVE_OSS=1
         ],
@@ -780,6 +763,8 @@ fi
 AC_SUBST(HAVE_OSS)
 AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS_OUTPUT" = "x1"])
 AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS_WRAPPER" = "x1"])
+AS_IF([test "x$HAVE_OSS_OUTPUT" = "x1"], AC_DEFINE([HAVE_OSS_OUTPUT], 1, [Have OSS output?]))
+AS_IF([test "x$HAVE_OSS_WRAPPER" = "x1"], AC_DEFINE([HAVE_OSS_WRAPPER], 1, [Have OSS wrapper (padsp)?]))
 
 #### CoreAudio support (optional) ####
 
@@ -804,7 +789,6 @@ if test "x$enable_alsa" != "xno"; then
     PKG_CHECK_MODULES(ASOUNDLIB, [ alsa >= 1.0.19 ],
         [
             HAVE_ALSA=1
-            AC_DEFINE([HAVE_ALSA], 1, [Have ALSA?])
         ],
         [
             HAVE_ALSA=0
@@ -820,6 +804,7 @@ AC_SUBST(ASOUNDLIB_CFLAGS)
 AC_SUBST(ASOUNDLIB_LIBS)
 AC_SUBST(HAVE_ALSA)
 AM_CONDITIONAL([HAVE_ALSA], [test "x$HAVE_ALSA" = x1])
+AS_IF([test "x$HAVE_ALSA" = "x1"], AC_DEFINE([HAVE_ALSA], 1, [Have ALSA?]))
 
 #### Solaris audio support (optional) ####
 
@@ -830,7 +815,6 @@ if test "x$enable_solaris" != "xno"; then
     AC_CHECK_HEADERS([sys/audio.h],
         [
             HAVE_SOLARIS=1
-            AC_DEFINE([HAVE_SOLARIS], 1, [Have Solaris audio?])
         ],
         [
             HAVE_SOLARIS=0
@@ -844,6 +828,7 @@ fi
 
 AC_SUBST(HAVE_SOLARIS)
 AM_CONDITIONAL([HAVE_SOLARIS], [test "x$HAVE_SOLARIS" = x1])
+AS_IF([test "x$HAVE_SOLARIS" = "x1"], AC_DEFINE([HAVE_SOLARIS], 1, [Have Solaris audio?]))
 
 #### WaveOut audio support (optional) ####
 
@@ -854,7 +839,6 @@ if test "x$enable_waveout" != "xno"; then
     AC_CHECK_HEADERS([mmsystem.h],
         [
             HAVE_WAVEOUT=1
-            AC_DEFINE([HAVE_WAVEOUT], 1, [Have WaveOut audio?])
         ],
         [
             HAVE_WAVEOUT=0
@@ -869,6 +853,7 @@ fi
 
 AC_SUBST(HAVE_WAVEOUT)
 AM_CONDITIONAL([HAVE_WAVEOUT], [test "x$HAVE_WAVEOUT" = x1])
+AS_IF([test "x$HAVE_WAVEOUT" = "x1"], AC_DEFINE([HAVE_WAVEOUT], 1, [Have WaveOut audio?]))
 
 #### GLib 2 support (optional) ####
 
@@ -892,10 +877,7 @@ AC_SUBST(GLIB20_CFLAGS)
 AC_SUBST(GLIB20_LIBS)
 AC_SUBST(HAVE_GLIB20)
 AM_CONDITIONAL([HAVE_GLIB20], [test "x$HAVE_GLIB20" = x1])
-
-if test "x$HAVE_GLIB20" = x1 ; then
-   AC_DEFINE([HAVE_GLIB], 1, [Have GLIB?])
-fi
+AS_IF([test "x$HAVE_GLIB20" = "x1"], AC_DEFINE([HAVE_GLIB], 1, [Have GLIB?]))
 
 #### GTK2 support (optional) ####
 
@@ -919,10 +901,7 @@ AC_SUBST(GTK20_CFLAGS)
 AC_SUBST(GTK20_LIBS)
 AC_SUBST(HAVE_GTK20)
 AM_CONDITIONAL([HAVE_GTK20], [test "x$HAVE_GTK20" = x1])
-
-if test "x$HAVE_GTK20" = x1 ; then
-   AC_DEFINE([HAVE_GTK], 1, [Have GTK?])
-fi
+AS_IF([test "x$HAVE_GTK20" = "x1"], AC_DEFINE([HAVE_GTK], 1, [Have GTK?]))
 
 #### GConf support (optional) ####
 
@@ -1015,10 +994,7 @@ AC_SUBST(LIBASYNCNS_CFLAGS)
 AC_SUBST(LIBASYNCNS_LIBS)
 AC_SUBST(HAVE_LIBASYNCNS)
 AM_CONDITIONAL([HAVE_LIBASYNCNS], [test "x$HAVE_LIBASYNCNS" = x1])
-
-if test "x$HAVE_LIBASYNCNS" != "x0" ; then
-   AC_DEFINE([HAVE_LIBASYNCNS], 1, [Have libasyncns?])
-fi
+AS_IF([test "x$HAVE_LIBASYNCNS" = "x1"], AC_DEFINE([HAVE_LIBASYNCNS], 1, [Have libasyncns?]))
 
 #### TCP wrappers (optional) ####
 
@@ -1067,7 +1043,6 @@ if test "x$enable_hal" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1
     PKG_CHECK_MODULES(HAL, [ hal >= 0.5.11 ],
         [
             HAVE_HAL=1
-            AC_DEFINE([HAVE_HAL], 1, [Have HAL.])
         ],
         [
             HAVE_HAL=0
@@ -1083,6 +1058,7 @@ AC_SUBST(HAL_CFLAGS)
 AC_SUBST(HAL_LIBS)
 AC_SUBST(HAVE_HAL)
 AM_CONDITIONAL([HAVE_HAL], [test "x$HAVE_HAL" = x1])
+AS_IF([test "x$HAVE_HAL" = "x1"], AC_DEFINE([HAVE_HAL], 1, [Have HAL.]))
 
 #### UDEV support (optional) ####
 
@@ -1093,7 +1069,6 @@ if test "x$enable_udev" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x
     PKG_CHECK_MODULES(UDEV, [ libudev >= 143 ],
         [
             HAVE_UDEV=1
-            AC_DEFINE([HAVE_UDEV], 1, [Have UDEV.])
         ],
         [
             HAVE_UDEV=0
@@ -1109,6 +1084,7 @@ AC_SUBST(UDEV_CFLAGS)
 AC_SUBST(UDEV_LIBS)
 AC_SUBST(HAVE_UDEV)
 AM_CONDITIONAL([HAVE_UDEV], [test "x$HAVE_UDEV" = x1])
+AS_IF([test "x$HAVE_UDEV" = "x1"], AC_DEFINE([HAVE_UDEV], 1, [Have UDEV.]))
 
 #### BlueZ support (optional) ####
 
@@ -1147,7 +1123,6 @@ if test "x$enable_dbus" != "xno"; then
             CFLAGS="$CFLAGS $DBUS_CFLAGS"
             AC_CHECK_FUNCS(dbus_watch_get_unix_fd)
             LIBS="$saved_LIBS"
-            AC_DEFINE([HAVE_DBUS], 1, [Have D-Bus.])
         ],
         [
             HAVE_DBUS=0
@@ -1163,7 +1138,7 @@ AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 AC_SUBST(HAVE_DBUS)
 AM_CONDITIONAL([HAVE_DBUS], [test "x$HAVE_DBUS" = x1])
-
+AS_IF([test "x$HAVE_DBUS" = "x1"], AC_DEFINE([HAVE_DBUS], 1, [Have D-Bus.]))
 
 # udev and HAL depend on D-Bus: So double check if they were explicitly enabled.
 if test "x$HAVE_DBUS" != "x1" ; then
@@ -1216,7 +1191,6 @@ if test "x$enable_openssl" != "xno"; then
     PKG_CHECK_MODULES(OPENSSL, [ openssl > 0.9 ],
         [
             HAVE_OPENSSL=1
-            AC_DEFINE([HAVE_OPENSSL], 1, [Have OpenSSL])
         ],
         [
             HAVE_OPENSSL=0
@@ -1232,6 +1206,7 @@ AC_SUBST(OPENSSL_CFLAGS)
 AC_SUBST(OPENSSL_LIBS)
 AC_SUBST(HAVE_OPENSSL)
 AM_CONDITIONAL([HAVE_OPENSSL], [test "x$HAVE_OPENSSL" = x1])
+AS_IF([test "x$HAVE_OPENSSL" = "x1"], AC_DEFINE([HAVE_OPENSSL], 1, [Have OpenSSL]))
 
 #### FFTW (optional) ####
 AC_ARG_WITH([fftw],

commit 6da83d3cb640235c08c707966e4d43d42a901194
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:52 2011 +0200

    build-system: Move dependency error messages to outer scope

diff --git a/configure.ac b/configure.ac
index 7edb22f..01f621f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -576,13 +576,12 @@ if test "x$enable_x11" != "xno"; then
         HAVE_X11=1,
         [
             HAVE_X11=0
-            if test "x$enable_x11" = "xyes"; then
-                AC_MSG_ERROR([*** X11 not found])
-            fi
         ])
 else
     HAVE_X11=0
 fi
+AS_IF([test "x$enable_x11" = "xyes" && test "x$HAVE_X11" = "x0"],
+    [AC_MSG_ERROR([*** X11 not found])])
 
 AC_SUBST(X11_CFLAGS)
 AC_SUBST(X11_LIBS)
@@ -650,13 +649,12 @@ if test "x$enable_samplerate" != "xno"; then
         HAVE_LIBSAMPLERATE=1,
         [
             HAVE_LIBSAMPLERATE=0
-            if test "x$enable_samplerate" = "xyes"; then
-                AC_MSG_ERROR([*** Libsamplerate not found])
-            fi
         ])
 else
     HAVE_LIBSAMPLERATE=0
 fi
+AS_IF([test "x$enable_samplerate" = "xyes" && test "x$HAVE_LIBSAMPLERATE" = "x0"],
+    [AC_MSG_ERROR([*** Libsamplerate not found])])
 
 AC_SUBST(LIBSAMPLERATE_CFLAGS)
 AC_SUBST(LIBSAMPLERATE_LIBS)
@@ -679,12 +677,10 @@ if test "x${with_database}" = "xauto" -o "x${with_database}" = "xtdb" ; then
         [
             HAVE_TDB=1
             with_database=tdb
-        ], [
-            if test "x${with_database}" = "xtdb" ; then
-                AC_MSG_ERROR([*** tdb not found])
-            fi
-        ])
+        ], [])
 fi
+AS_IF([test "x$with_database" = "xtdb" && test "x$HAVE_TDB" = "x0"],
+    [AC_MSG_ERROR([*** tdb not found])])
 
 if test "x${with_database}" = "xauto" -o "x${with_database}" = "xgdbm" ; then
    have_gdbm=yes
@@ -697,10 +693,10 @@ if test "x${with_database}" = "xauto" -o "x${with_database}" = "xgdbm" ; then
        GDBM_CFLAGS=
        GDBM_LIBS=-lgdbm
        with_database=gdbm
-   elif test "x${with_database}" = "xgdbm"; then
-       AC_MSG_ERROR([*** gdbm not found])
    fi
 fi
+AS_IF([test "x$with_database" = "xgdbm" && test "x$HAVE_GDBM" = "x0"],
+    [AC_MSG_ERROR([*** gdbm not found])])
 
 if test "x${with_database}" = "xauto" -o "x${with_database}" = "xsimple" ; then
     HAVE_SIMPLEDB=1
@@ -750,15 +746,14 @@ if test "x$enable_oss_output" != "xno" || test "x$enable_oss_wrapper" != "xno";
             HAVE_OSS=0
             HAVE_OSS_OUTPUT=0
             HAVE_OSS_WRAPPER=0
-            if test "x$enable_oss_output" = "xyes" || test "x$enable_oss_wrapper" = "xyes"; then
-                AC_MSG_ERROR([*** OSS support not found])
-            fi
         ])
 else
     HAVE_OSS=0
     HAVE_OSS_OUTPUT=0
     HAVE_OSS_WRAPPER=0
 fi
+AS_IF([test "x$enable_oss_output" = "xyes" -o "x$enable_oss_wrapper" = "xyes" && test "x$HAVE_ALSA" = "x0"],
+    [AC_MSG_ERROR([*** OSS support not found])])
 
 AC_SUBST(HAVE_OSS)
 AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS_OUTPUT" = "x1"])
@@ -792,13 +787,12 @@ if test "x$enable_alsa" != "xno"; then
         ],
         [
             HAVE_ALSA=0
-            if test "x$enable_alsa" = "xyes"; then
-                AC_MSG_ERROR([*** Needed alsa >= 1.0.19 support not found])
-            fi
         ])
 else
     HAVE_ALSA=0
 fi
+AS_IF([test "x$enable_alsa" = "xyes" && test "x$HAVE_ALSA" = "x0"],
+    [AC_MSG_ERROR([*** Needed alsa >= 1.0.19 support not found])])
 
 AC_SUBST(ASOUNDLIB_CFLAGS)
 AC_SUBST(ASOUNDLIB_LIBS)
@@ -818,13 +812,12 @@ if test "x$enable_solaris" != "xno"; then
         ],
         [
             HAVE_SOLARIS=0
-            if test "x$enable_solaris" = "xyes"; then
-                AC_MSG_ERROR([*** Solaris audio support not found])
-            fi
         ])
 else
     HAVE_SOLARIS=0
 fi
+AS_IF([test "x$enable_solaris" = "xyes" && test "x$HAVE_SOLARIS" = "x0"],
+    [AC_MSG_ERROR([*** Solaris audio support not found])])
 
 AC_SUBST(HAVE_SOLARIS)
 AM_CONDITIONAL([HAVE_SOLARIS], [test "x$HAVE_SOLARIS" = x1])
@@ -842,14 +835,13 @@ if test "x$enable_waveout" != "xno"; then
         ],
         [
             HAVE_WAVEOUT=0
-            if test "x$enable_waveout" = "xyes"; then
-                AC_MSG_ERROR([*** WaveOut audio support not found])
-            fi
         ],
         [#include <windows.h>])
 else
     HAVE_WAVEOUT=0
 fi
+AS_IF([test "x$enable_waveout" = "xyes" && test "x$HAVE_WAVEOUT" = "x0"],
+    [AC_MSG_ERROR([*** WaveOut audio support not found])])
 
 AC_SUBST(HAVE_WAVEOUT)
 AM_CONDITIONAL([HAVE_WAVEOUT], [test "x$HAVE_WAVEOUT" = x1])
@@ -865,13 +857,12 @@ if test "x$enable_glib2" != "xno"; then
         HAVE_GLIB20=1,
         [
             HAVE_GLIB20=0
-            if test "x$enable_glib2" = "xyes"; then
-                AC_MSG_ERROR([*** GLib 2 support not found])
-            fi
         ])
 else
     HAVE_GLIB20=0
 fi
+AS_IF([test "x$enable_glib2" = "xyes" && test "x$HAVE_GLIB20" = "x0"],
+    [AC_MSG_ERROR([*** GLib 2 support not found])])
 
 AC_SUBST(GLIB20_CFLAGS)
 AC_SUBST(GLIB20_LIBS)
@@ -889,13 +880,12 @@ if test "x$enable_gtk2" != "xno"; then
         HAVE_GTK20=1,
         [
             HAVE_GTK20=0
-            if test "x$enable_gtk2" = "xyes"; then
-                AC_MSG_ERROR([*** Gtk+ 2 support not found])
-            fi
         ])
 else
     HAVE_GTK20=0
 fi
+AS_IF([test "x$enable_gtk2" = "xyes" && test "x$HAVE_GTK20" = "x0"],
+    [AC_MSG_ERROR([*** Gtk+ 2 support not found])])
 
 AC_SUBST(GTK20_CFLAGS)
 AC_SUBST(GTK20_LIBS)
@@ -913,13 +903,12 @@ if test "x$enable_gconf" != "xno"; then
         HAVE_GCONF=1,
         [
             HAVE_GCONF=0
-            if test "x$enable_gconf" = "xyes"; then
-                AC_MSG_ERROR([*** GConf support not found])
-            fi
         ])
 else
     HAVE_GCONF=0
 fi
+AS_IF([test "x$enable_gconf" = "xyes" && test "x$HAVE_GCONF" = "x0"],
+    [AC_MSG_ERROR([*** GConf support not found])])
 
 AC_SUBST(GCONF_CFLAGS)
 AC_SUBST(GCONF_LIBS)
@@ -936,13 +925,12 @@ if test "x$enable_avahi" != "xno"; then
         HAVE_AVAHI=1,
         [
                 HAVE_AVAHI=0
-                if test "x$enable_avahi" = "xyes"; then
-                        AC_MSG_ERROR([*** Avahi support not found])
-                fi
         ])
 else
     HAVE_AVAHI=0
 fi
+AS_IF([test "x$enable_avahi" = "xyes" && test "x$HAVE_AVAHI" = "x0"],
+    [AC_MSG_ERROR([*** Avahi support not found])])
 
 AC_SUBST(AVAHI_CFLAGS)
 AC_SUBST(AVAHI_LIBS)
@@ -959,13 +947,12 @@ if test "x$enable_jack" != "xno"; then
         HAVE_JACK=1,
         [
             HAVE_JACK=0
-            if test "x$enable_jack" = "xyes"; then
-                AC_MSG_ERROR([*** JACK support not found])
-            fi
         ])
 else
     HAVE_JACK=0
 fi
+AS_IF([test "x$enable_jack" = "xyes" && test "x$HAVE_JACK" = "x0"],
+    [AC_MSG_ERROR([*** JACK support not found])])
 
 AC_SUBST(JACK_CFLAGS)
 AC_SUBST(JACK_LIBS)
@@ -982,13 +969,12 @@ if test "x$enable_asyncns" != "xno"; then
         HAVE_LIBASYNCNS=1,
         [
             HAVE_LIBASYNCNS=0
-            if test "x$enable_asyncns" = "xyes"; then
-                AC_MSG_ERROR([*** Async DNS support not found])
-            fi
         ])
 else
     HAVE_LIBASYNCNS=0
 fi
+AS_IF([test "x$enable_asyncns" = "xyes" && test "x$HAVE_LIBASYNCNS" = "x0"],
+    [AC_MSG_ERROR([*** Async DNS support not found])])
 
 AC_SUBST(LIBASYNCNS_CFLAGS)
 AC_SUBST(LIBASYNCNS_LIBS)
@@ -1006,13 +992,12 @@ if test "x$enable_tcpwrap" != "xno"; then
     HAVE_TCPWRAP=1
     if test "x${LIBWRAP_LIBS}" = "x"; then
         HAVE_TCPWRAP=0
-        if test "x$enable_tcpwrap" = "xyes"; then
-            AC_MSG_ERROR([*** TCP wrappers support not found])
-        fi
     fi
 else
     HAVE_TCPWRAP=0
 fi
+AS_IF([test "x$enable_tcpwrap" = "xyes" && test "x$HAVE_TCPWRAP" = "x0"],
+    [AC_MSG_ERROR([*** TCP wrappers support not found])])
 
 AC_SUBST(LIBWRAP_LIBS)
 
@@ -1023,12 +1008,11 @@ AC_ARG_ENABLE([lirc],
 
 if test "x$enable_lirc" != "xno"; then
     ACX_LIRC
-    if test "x${HAVE_LIRC}" = "x0" && test "x$enable_lirc" = "xyes"; then
-        AC_MSG_ERROR([*** LIRC support not found])
-    fi
 else
     HAVE_LIRC=0
 fi
+AS_IF([test "x$enable_lirc" = "xyes" && test "x$HAVE_LIRC" = "x0"],
+    [AC_MSG_ERROR([*** LIRC support not found])])
 
 AC_SUBST(LIRC_CFLAGS)
 AC_SUBST(LIRC_LIBS)
@@ -1046,13 +1030,12 @@ if test "x$enable_hal" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1
         ],
         [
             HAVE_HAL=0
-            if test "x$enable_hal" = "xyes"; then
-                AC_MSG_ERROR([*** HAL support not found])
-            fi
         ])
 else
     HAVE_HAL=0
 fi
+AS_IF([test "x$enable_hal" = "xyes" && test "x$HAVE_HAL" = "x0"],
+    [AC_MSG_ERROR([*** HAL support not found])])
 
 AC_SUBST(HAL_CFLAGS)
 AC_SUBST(HAL_LIBS)
@@ -1072,13 +1055,12 @@ if test "x$enable_udev" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x
         ],
         [
             HAVE_UDEV=0
-            if test "x$enable_udev" = "xyes"; then
-                AC_MSG_ERROR([*** UDEV support not found])
-            fi
         ])
 else
     HAVE_UDEV=0
 fi
+AS_IF([test "x$enable_udev" = "xyes" && test "x$HAVE_UDEV" = "x0"],
+    [AC_MSG_ERROR([*** UDEV support not found])])
 
 AC_SUBST(UDEV_CFLAGS)
 AC_SUBST(UDEV_LIBS)
@@ -1096,13 +1078,12 @@ if test "x$enable_bluez" != "xno"; then
         HAVE_BLUEZ=1,
         [
             HAVE_BLUEZ=0
-            if test "x$enable_bluez" = "xyes"; then
-                AC_MSG_ERROR([*** BLUEZ support not found])
-            fi
         ])
 else
     HAVE_BLUEZ=0
 fi
+AS_IF([test "x$enable_bluez" = "xyes" && test "x$HAVE_BLUEZ" = "x0"],
+    [AC_MSG_ERROR([*** BLUEZ support not found])])
 
 AC_SUBST(BLUEZ_CFLAGS)
 AC_SUBST(BLUEZ_LIBS)
@@ -1126,13 +1107,12 @@ if test "x$enable_dbus" != "xno"; then
         ],
         [
             HAVE_DBUS=0
-            if test "x$enable_dbus" = "xyes"; then
-                AC_MSG_ERROR([*** D-Bus support not found])
-            fi
         ])
 else
     HAVE_DBUS=0
 fi
+AS_IF([test "x$enable_dbus" = "xyes" && test "x$HAVE_DBUS" = "x0"],
+    [AC_MSG_ERROR([*** D-Bus support not found])])
 
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
@@ -1194,13 +1174,12 @@ if test "x$enable_openssl" != "xno"; then
         ],
         [
             HAVE_OPENSSL=0
-            if test "x$enable_openssl" = "xyes"; then
-                AC_MSG_ERROR([*** OpenSSL support not found])
-            fi
         ])
 else
     HAVE_OPENSSL=0
 fi
+AS_IF([test "x$enable_openssl" = "xyes" && test "x$HAVE_OPENSSL" = "x0"],
+    [AC_MSG_ERROR([*** OpenSSL support not found])])
 
 AC_SUBST(OPENSSL_CFLAGS)
 AC_SUBST(OPENSSL_LIBS)

commit 96d0ecb01bef5f7832825499bddbc9059b4840f6
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:53 2011 +0200

    build-system: Replace some more conditionals with AS_IF

diff --git a/configure.ac b/configure.ac
index 01f621f..46fa28d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -571,15 +571,10 @@ PKG_PROG_PKG_CONFIG
 AC_ARG_ENABLE([x11],
     AS_HELP_STRING([--disable-x11],[Disable optional X11 support]))
 
-if test "x$enable_x11" != "xno"; then
-    PKG_CHECK_MODULES(X11, [ x11-xcb xcb >= 1.6 ice sm xtst ],
-        HAVE_X11=1,
-        [
-            HAVE_X11=0
-        ])
-else
-    HAVE_X11=0
-fi
+AS_IF([test "x$enable_x11" != "xno"],
+    [PKG_CHECK_MODULES(X11, [ x11-xcb xcb >= 1.6 ice sm xtst ], HAVE_X11=1, HAVE_X11=0)],
+    HAVE_X11=0)
+
 AS_IF([test "x$enable_x11" = "xyes" && test "x$HAVE_X11" = "x0"],
     [AC_MSG_ERROR([*** X11 not found])])
 
@@ -644,15 +639,10 @@ fi
 AC_ARG_ENABLE([samplerate],
     AS_HELP_STRING([--disable-samplerate],[Disable optional libsamplerate support]))
 
-if test "x$enable_samplerate" != "xno"; then
-    PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ],
-        HAVE_LIBSAMPLERATE=1,
-        [
-            HAVE_LIBSAMPLERATE=0
-        ])
-else
-    HAVE_LIBSAMPLERATE=0
-fi
+AS_IF([test "x$enable_samplerate" != "xno"],
+    [PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ], HAVE_LIBSAMPLERATE=1, HAVE_LIBSAMPLERATE=0)],
+    HAVE_LIBSAMPLERATE=0)
+
 AS_IF([test "x$enable_samplerate" = "xyes" && test "x$HAVE_LIBSAMPLERATE" = "x0"],
     [AC_MSG_ERROR([*** Libsamplerate not found])])
 
@@ -731,30 +721,21 @@ AC_ARG_ENABLE([oss-output],
 AC_ARG_ENABLE([oss-wrapper],
     AS_HELP_STRING([--disable-oss-wrapper],[Disable optional OSS wrapper support]))
 
-if test "x$enable_oss_output" != "xno" || test "x$enable_oss_wrapper" != "xno"; then
-    AC_CHECK_HEADERS([sys/soundcard.h],
-        [
-            if test "x$enable_oss_output" != "xno"; then
-                HAVE_OSS_OUTPUT=1
-            fi
-            if test "x$enable_oss_wrapper" != "xno"; then
-                HAVE_OSS_WRAPPER=1
-            fi
-            HAVE_OSS=1
-        ],
-        [
-            HAVE_OSS=0
-            HAVE_OSS_OUTPUT=0
-            HAVE_OSS_WRAPPER=0
-        ])
-else
-    HAVE_OSS=0
-    HAVE_OSS_OUTPUT=0
-    HAVE_OSS_WRAPPER=0
-fi
-AS_IF([test "x$enable_oss_output" = "xyes" -o "x$enable_oss_wrapper" = "xyes" && test "x$HAVE_ALSA" = "x0"],
+AS_IF([test "x$enable_oss_output" != "xno" -o "x$enable_oss_wrapper" != "xno"],
+    [AC_CHECK_HEADERS([sys/soundcard.h], HAVE_OSS=1, HAVE_OSS=0)],
+    HAVE_OSS=0)
+
+AS_IF([test "x$enable_oss_output" = "xyes" -o "x$enable_oss_wrapper" = "xyes" && test "x$HAVE_OSS" = "x0"],
     [AC_MSG_ERROR([*** OSS support not found])])
 
+AS_IF([test "x$enable_oss_output" != "xno"],
+    [AS_IF([test "x$HAVE_OSS" = "x1"], HAVE_OSS_OUTPUT=1, HAVE_OSS_OUTPUT=0)],
+    HAVE_OSS_OUTPUT=0)
+
+AS_IF([test "x$enable_oss_wrapper" != "xno"],
+    [AS_IF([test "x$HAVE_OSS" = "x1"], HAVE_OSS_WRAPPER=1, HAVE_OSS_WRAPPER=0)],
+    HAVE_OSS_WRAPPER=0)
+
 AC_SUBST(HAVE_OSS)
 AM_CONDITIONAL([HAVE_OSS_OUTPUT], [test "x$HAVE_OSS_OUTPUT" = "x1"])
 AM_CONDITIONAL([HAVE_OSS_WRAPPER], [test "x$HAVE_OSS_WRAPPER" = "x1"])
@@ -766,11 +747,9 @@ AS_IF([test "x$HAVE_OSS_WRAPPER" = "x1"], AC_DEFINE([HAVE_OSS_WRAPPER], 1, [Have
 AC_ARG_ENABLE([coreaudio-output],
     AS_HELP_STRING([--disable-coreaudio-output],[Disable optional CoreAudio output support]))
 
-if test "x$enable_coreaudio_output" != "xno"; then
-    AC_CHECK_HEADERS([CoreAudio/CoreAudio.h], HAVE_COREAUDIO=1)
-else
-    HAVE_COREAUDIO=0
-fi
+AS_IF([test "x$enable_coreaudio_output" != "xno"],
+    [AC_CHECK_HEADERS([CoreAudio/CoreAudio.h], HAVE_COREAUDIO=1, HAVE_COREAUDIO=0)],
+    HAVE_COREAUDIO=0)
 
 AC_SUBST(HAVE_COREAUDIO)
 AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = "x1" && test "x$enable_coreaudio_output" != "xno"])
@@ -780,17 +759,10 @@ AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = "x1" && test "x$enab
 AC_ARG_ENABLE([alsa],
     AS_HELP_STRING([--disable-alsa],[Disable optional ALSA support]))
 
-if test "x$enable_alsa" != "xno"; then
-    PKG_CHECK_MODULES(ASOUNDLIB, [ alsa >= 1.0.19 ],
-        [
-            HAVE_ALSA=1
-        ],
-        [
-            HAVE_ALSA=0
-        ])
-else
-    HAVE_ALSA=0
-fi
+AS_IF([test "x$enable_alsa" != "xno"],
+    [PKG_CHECK_MODULES(ASOUNDLIB, [ alsa >= 1.0.19 ], HAVE_ALSA=1, HAVE_ALSA=0)],
+    HAVE_ALSA=0)
+
 AS_IF([test "x$enable_alsa" = "xyes" && test "x$HAVE_ALSA" = "x0"],
     [AC_MSG_ERROR([*** Needed alsa >= 1.0.19 support not found])])
 
@@ -805,17 +777,10 @@ AS_IF([test "x$HAVE_ALSA" = "x1"], AC_DEFINE([HAVE_ALSA], 1, [Have ALSA?]))
 AC_ARG_ENABLE([solaris],
     AS_HELP_STRING([--disable-solaris],[Disable optional Solaris audio support]))
 
-if test "x$enable_solaris" != "xno"; then
-    AC_CHECK_HEADERS([sys/audio.h],
-        [
-            HAVE_SOLARIS=1
-        ],
-        [
-            HAVE_SOLARIS=0
-        ])
-else
-    HAVE_SOLARIS=0
-fi
+AS_IF([test "x$enable_solaris" != "xno"],
+    [AC_CHECK_HEADERS([sys/audio.h], HAVE_SOLARIS=1, HAVE_SOLARIS=0)],
+    HAVE_SOLARIS=0)
+
 AS_IF([test "x$enable_solaris" = "xyes" && test "x$HAVE_SOLARIS" = "x0"],
     [AC_MSG_ERROR([*** Solaris audio support not found])])
 
@@ -828,18 +793,10 @@ AS_IF([test "x$HAVE_SOLARIS" = "x1"], AC_DEFINE([HAVE_SOLARIS], 1, [Have Solaris
 AC_ARG_ENABLE([waveout],
     AS_HELP_STRING([--disable-waveout],[Disable optional WaveOut audio support]))
 
-if test "x$enable_waveout" != "xno"; then
-    AC_CHECK_HEADERS([mmsystem.h],
-        [
-            HAVE_WAVEOUT=1
-        ],
-        [
-            HAVE_WAVEOUT=0
-        ],
-        [#include <windows.h>])
-else
-    HAVE_WAVEOUT=0
-fi
+AS_IF([test "x$enable_waveout" != "xno"],
+    [AC_CHECK_HEADERS([mmsystem.h], HAVE_WAVEOUT=1, HAVE_WAVEOUT=0, [#include <windows.h>])],
+    HAVE_WAVEOUT=0)
+
 AS_IF([test "x$enable_waveout" = "xyes" && test "x$HAVE_WAVEOUT" = "x0"],
     [AC_MSG_ERROR([*** WaveOut audio support not found])])
 
@@ -852,15 +809,10 @@ AS_IF([test "x$HAVE_WAVEOUT" = "x1"], AC_DEFINE([HAVE_WAVEOUT], 1, [Have WaveOut
 AC_ARG_ENABLE([glib2],
     AS_HELP_STRING([--disable-glib2],[Disable optional GLib 2 support]))
 
-if test "x$enable_glib2" != "xno"; then
-    PKG_CHECK_MODULES(GLIB20, [ glib-2.0 >= 2.4.0 ],
-        HAVE_GLIB20=1,
-        [
-            HAVE_GLIB20=0
-        ])
-else
-    HAVE_GLIB20=0
-fi
+AS_IF([test "x$enable_glib2" != "xno"],
+    [PKG_CHECK_MODULES(GLIB20, [ glib-2.0 >= 2.4.0 ], HAVE_GLIB20=1, HAVE_GLIB20=0)],
+    HAVE_GLIB20=0)
+
 AS_IF([test "x$enable_glib2" = "xyes" && test "x$HAVE_GLIB20" = "x0"],
     [AC_MSG_ERROR([*** GLib 2 support not found])])
 
@@ -875,15 +827,10 @@ AS_IF([test "x$HAVE_GLIB20" = "x1"], AC_DEFINE([HAVE_GLIB], 1, [Have GLIB?]))
 AC_ARG_ENABLE([gtk2],
     AS_HELP_STRING([--disable-gtk2],[Disable optional Gtk+ 2 support]))
 
-if test "x$enable_gtk2" != "xno"; then
-    PKG_CHECK_MODULES(GTK20, [ gtk+-2.0 >= 2.4.0 ],
-        HAVE_GTK20=1,
-        [
-            HAVE_GTK20=0
-        ])
-else
-    HAVE_GTK20=0
-fi
+AS_IF([test "x$enable_gtk2" != "xno"],
+    [PKG_CHECK_MODULES(GTK20, [ gtk+-2.0 >= 2.4.0 ], HAVE_GTK20=1, HAVE_GTK20=0)],
+    HAVE_GTK20=0)
+
 AS_IF([test "x$enable_gtk2" = "xyes" && test "x$HAVE_GTK20" = "x0"],
     [AC_MSG_ERROR([*** Gtk+ 2 support not found])])
 
@@ -898,15 +845,10 @@ AS_IF([test "x$HAVE_GTK20" = "x1"], AC_DEFINE([HAVE_GTK], 1, [Have GTK?]))
 AC_ARG_ENABLE([gconf],
     AS_HELP_STRING([--disable-gconf],[Disable optional GConf support]))
 
-if test "x$enable_gconf" != "xno"; then
-    PKG_CHECK_MODULES(GCONF, [ gconf-2.0 >= 2.4.0 gobject-2.0 ],
-        HAVE_GCONF=1,
-        [
-            HAVE_GCONF=0
-        ])
-else
-    HAVE_GCONF=0
-fi
+AS_IF([test "x$enable_gconf" != "xno"],
+    [PKG_CHECK_MODULES(GCONF, [ gconf-2.0 >= 2.4.0 gobject-2.0 ], HAVE_GCONF=1, HAVE_GCONF=0)],
+    HAVE_GCONF=0)
+
 AS_IF([test "x$enable_gconf" = "xyes" && test "x$HAVE_GCONF" = "x0"],
     [AC_MSG_ERROR([*** GConf support not found])])
 
@@ -920,15 +862,10 @@ AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = x1])
 AC_ARG_ENABLE([avahi],
     AS_HELP_STRING([--disable-avahi],[Disable optional Avahi support]))
 
-if test "x$enable_avahi" != "xno"; then
-    PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6.0 ],
-        HAVE_AVAHI=1,
-        [
-                HAVE_AVAHI=0
-        ])
-else
-    HAVE_AVAHI=0
-fi
+AS_IF([test "x$enable_avahi" != "xno"],
+    [PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6.0 ], HAVE_AVAHI=1, HAVE_AVAHI=0)],
+    HAVE_AVAHI=0)
+
 AS_IF([test "x$enable_avahi" = "xyes" && test "x$HAVE_AVAHI" = "x0"],
     [AC_MSG_ERROR([*** Avahi support not found])])
 
@@ -942,15 +879,10 @@ AM_CONDITIONAL([HAVE_AVAHI], [test "x$HAVE_AVAHI" = x1])
 AC_ARG_ENABLE([jack],
     AS_HELP_STRING([--disable-jack],[Disable optional JACK support]))
 
-if test "x$enable_jack" != "xno"; then
-    PKG_CHECK_MODULES(JACK, [ jack >= 0.100 ],
-        HAVE_JACK=1,
-        [
-            HAVE_JACK=0
-        ])
-else
-    HAVE_JACK=0
-fi
+AS_IF([test "x$enable_jack" != "xno"],
+    [PKG_CHECK_MODULES(JACK, [ jack >= 0.100 ], HAVE_JACK=1, HAVE_JACK=0)],
+    HAVE_JACK=0)
+
 AS_IF([test "x$enable_jack" = "xyes" && test "x$HAVE_JACK" = "x0"],
     [AC_MSG_ERROR([*** JACK support not found])])
 
@@ -964,15 +896,10 @@ AM_CONDITIONAL([HAVE_JACK], [test "x$HAVE_JACK" = x1])
 AC_ARG_ENABLE([asyncns],
     AS_HELP_STRING([--disable-asyncns],[Disable optional Async DNS support]))
 
-if test "x$enable_asyncns" != "xno"; then
-    PKG_CHECK_MODULES(LIBASYNCNS, [ libasyncns >= 0.1 ],
-        HAVE_LIBASYNCNS=1,
-        [
-            HAVE_LIBASYNCNS=0
-        ])
-else
-    HAVE_LIBASYNCNS=0
-fi
+AS_IF([test "x$enable_asyncns" != "xno"],
+    [PKG_CHECK_MODULES(LIBASYNCNS, [ libasyncns >= 0.1 ], HAVE_LIBASYNCNS=1, HAVE_LIBASYNCNS=0)],
+    HAVE_LIBASYNCNS=0)
+
 AS_IF([test "x$enable_asyncns" = "xyes" && test "x$HAVE_LIBASYNCNS" = "x0"],
     [AC_MSG_ERROR([*** Async DNS support not found])])
 
@@ -987,15 +914,13 @@ AS_IF([test "x$HAVE_LIBASYNCNS" = "x1"], AC_DEFINE([HAVE_LIBASYNCNS], 1, [Have l
 AC_ARG_ENABLE([tcpwrap],
     AS_HELP_STRING([--disable-tcpwrap],[Disable optional TCP wrappers support]))
 
-if test "x$enable_tcpwrap" != "xno"; then
-    ACX_LIBWRAP
-    HAVE_TCPWRAP=1
-    if test "x${LIBWRAP_LIBS}" = "x"; then
-        HAVE_TCPWRAP=0
-    fi
-else
-    HAVE_TCPWRAP=0
-fi
+AS_IF([test "x$enable_tcpwrap" != "xno"],
+    [
+        ACX_LIBWRAP
+        AS_IF([test "x$LIBWRAP_LIBS" != "x"], HAVE_TCPWRAP=1, HAVE_TCPWRAP=0)
+    ],
+    HAVE_TCPWRAP=0)
+
 AS_IF([test "x$enable_tcpwrap" = "xyes" && test "x$HAVE_TCPWRAP" = "x0"],
     [AC_MSG_ERROR([*** TCP wrappers support not found])])
 
@@ -1006,11 +931,10 @@ AC_SUBST(LIBWRAP_LIBS)
 AC_ARG_ENABLE([lirc],
     AS_HELP_STRING([--disable-lirc],[Disable optional LIRC support]))
 
-if test "x$enable_lirc" != "xno"; then
-    ACX_LIRC
-else
-    HAVE_LIRC=0
-fi
+AS_IF([test "x$enable_lirc" != "xno"],
+    [ACX_LIRC],
+    HAVE_LIRC=0)
+
 AS_IF([test "x$enable_lirc" = "xyes" && test "x$HAVE_LIRC" = "x0"],
     [AC_MSG_ERROR([*** LIRC support not found])])
 
@@ -1023,17 +947,10 @@ AM_CONDITIONAL([HAVE_LIRC], [test "x$HAVE_LIRC" = x1])
 AC_ARG_ENABLE([hal],
     AS_HELP_STRING([--disable-hal],[Disable optional HAL support]))
 
-if test "x$enable_hal" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \); then
-    PKG_CHECK_MODULES(HAL, [ hal >= 0.5.11 ],
-        [
-            HAVE_HAL=1
-        ],
-        [
-            HAVE_HAL=0
-        ])
-else
-    HAVE_HAL=0
-fi
+AS_IF([test "x$enable_hal" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \)],
+    [PKG_CHECK_MODULES(HAL, [ hal >= 0.5.11 ], HAVE_HAL=1, HAVE_HAL=0)],
+    HAVE_HAL=0)
+
 AS_IF([test "x$enable_hal" = "xyes" && test "x$HAVE_HAL" = "x0"],
     [AC_MSG_ERROR([*** HAL support not found])])
 
@@ -1048,17 +965,10 @@ AS_IF([test "x$HAVE_HAL" = "x1"], AC_DEFINE([HAVE_HAL], 1, [Have HAL.]))
 AC_ARG_ENABLE([udev],
     AS_HELP_STRING([--disable-udev],[Disable optional UDEV support]))
 
-if test "x$enable_udev" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \); then
-    PKG_CHECK_MODULES(UDEV, [ libudev >= 143 ],
-        [
-            HAVE_UDEV=1
-        ],
-        [
-            HAVE_UDEV=0
-        ])
-else
-    HAVE_UDEV=0
-fi
+AS_IF([test "x$enable_udev" != "xno" -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \)],
+    [PKG_CHECK_MODULES(UDEV, [ libudev >= 143 ], HAVE_UDEV=1, HAVE_UDEV=0)],
+    HAVE_UDEV=0)
+
 AS_IF([test "x$enable_udev" = "xyes" && test "x$HAVE_UDEV" = "x0"],
     [AC_MSG_ERROR([*** UDEV support not found])])
 
@@ -1073,15 +983,10 @@ AS_IF([test "x$HAVE_UDEV" = "x1"], AC_DEFINE([HAVE_UDEV], 1, [Have UDEV.]))
 AC_ARG_ENABLE([bluez],
     AS_HELP_STRING([--disable-bluez],[Disable optional BlueZ support]))
 
-if test "x$enable_bluez" != "xno"; then
-    PKG_CHECK_MODULES(BLUEZ, [ bluez >= 3.0 ],
-        HAVE_BLUEZ=1,
-        [
-            HAVE_BLUEZ=0
-        ])
-else
-    HAVE_BLUEZ=0
-fi
+AS_IF([test "x$enable_bluez" != "xno"],
+    [PKG_CHECK_MODULES(BLUEZ, [ bluez >= 3.0 ], HAVE_BLUEZ=1, HAVE_BLUEZ=0)],
+    HAVE_BLUEZ=0)
+
 AS_IF([test "x$enable_bluez" = "xyes" && test "x$HAVE_BLUEZ" = "x0"],
     [AC_MSG_ERROR([*** BLUEZ support not found])])
 
@@ -1095,25 +1000,22 @@ AM_CONDITIONAL([HAVE_BLUEZ], [test "x$HAVE_BLUEZ" = x1])
 AC_ARG_ENABLE([dbus],
     AS_HELP_STRING([--disable-dbus],[Disable optional D-Bus support]))
 
-if test "x$enable_dbus" != "xno"; then
-    PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 1.0.0 ],
-        [
-            HAVE_DBUS=1
-            saved_LIBS="$LIBS"
-            LIBS="$LIBS $DBUS_LIBS"
-            CFLAGS="$CFLAGS $DBUS_CFLAGS"
-            AC_CHECK_FUNCS(dbus_watch_get_unix_fd)
-            LIBS="$saved_LIBS"
-        ],
-        [
-            HAVE_DBUS=0
-        ])
-else
-    HAVE_DBUS=0
-fi
+AS_IF([test "x$enable_dbus" != "xno"],
+    [PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 1.0.0 ], HAVE_DBUS=1, HAVE_DBUS=0)],
+    HAVE_DBUS=0)
+
 AS_IF([test "x$enable_dbus" = "xyes" && test "x$HAVE_DBUS" = "x0"],
     [AC_MSG_ERROR([*** D-Bus support not found])])
 
+AS_IF([test "x$HAVE_DBUS" = "x1"],
+    [
+        saved_LIBS="$LIBS"
+        LIBS="$LIBS $DBUS_LIBS"
+        CFLAGS="$CFLAGS $DBUS_CFLAGS"
+        AC_CHECK_FUNCS(dbus_watch_get_unix_fd)
+        LIBS="$saved_LIBS"
+    ])
+
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 AC_SUBST(HAVE_DBUS)
@@ -1166,18 +1068,10 @@ fi
 AC_ARG_ENABLE([openssl],
     AS_HELP_STRING([--disable-openssl],[Disable OpenSSL support (used for Airtunes/RAOP)]))
 
-if test "x$enable_openssl" != "xno"; then
+AS_IF([test "x$enable_openssl" != "xno"],
+    [PKG_CHECK_MODULES(OPENSSL, [ openssl > 0.9 ], HAVE_OPENSSL=1, HAVE_OPENSSL=0)],
+    HAVE_OPENSSL=0)
 
-    PKG_CHECK_MODULES(OPENSSL, [ openssl > 0.9 ],
-        [
-            HAVE_OPENSSL=1
-        ],
-        [
-            HAVE_OPENSSL=0
-        ])
-else
-    HAVE_OPENSSL=0
-fi
 AS_IF([test "x$enable_openssl" = "xyes" && test "x$HAVE_OPENSSL" = "x0"],
     [AC_MSG_ERROR([*** OpenSSL support not found])])
 
@@ -1191,9 +1085,10 @@ AS_IF([test "x$HAVE_OPENSSL" = "x1"], AC_DEFINE([HAVE_OPENSSL], 1, [Have OpenSSL
 AC_ARG_WITH([fftw],
     AS_HELP_STRING([--without-fftw],[Omit FFTW-using modules (equalizer)]))
 
-if test "x${with_fftw}" != "xno"; then
-    PKG_CHECK_MODULES([FFTW], [fftw3f], [HAVE_FFTW=1], [HAVE_FFTW=0])
-fi
+AS_IF([test "x$with_fftw" != "xno"],
+    [PKG_CHECK_MODULES(FFTW, [ fftw3f ], HAVE_FFTW=1, HAVE_FFTW=0)],
+    HAVE_FFTW=0)
+
 AM_CONDITIONAL([HAVE_FFTW], [test "x$HAVE_FFTW" = "x1"])
 
 ### ORC (optional) ###

commit 155f2d5b9d0f2414ce503cfab32de4870449cb99
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:54 2011 +0200

    build-system: Rearrange database selection

diff --git a/configure.ac b/configure.ac
index 46fa28d..08cfbeb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -654,48 +654,45 @@ AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], AC_DEFINE([HAVE_LIBSAMPLERATE], 1, [
 
 #### Database support ####
 
-HAVE_TDB=0
-HAVE_GDBM=0
-HAVE_SIMPLEDB=0
+AC_ARG_WITH([database],
+    AS_HELP_STRING([--with-database=auto|tdb|gdbm|simple],[Choose database backend.]),[],[with_database=auto])
+
+
+AS_IF([test "x$with_database" = "xauto" -o "x$with_database" = "xtdb"],
+    [PKG_CHECK_MODULES(TDB, [ tdb ], HAVE_TDB=1, HAVE_TDB=0)],
+    HAVE_TDB=0)
+AS_IF([test "x$HAVE_TDB" = "x1"], with_database=tdb)
 
-AC_ARG_WITH(
-        [database],
-        AS_HELP_STRING([--with-database=auto|tdb|gdbm|simple],[Choose database backend.]),[],[with_database=auto])
-
-if test "x${with_database}" = "xauto" -o "x${with_database}" = "xtdb" ; then
-    PKG_CHECK_MODULES(TDB, [ tdb ],
-        [
-            HAVE_TDB=1
-            with_database=tdb
-        ], [])
-fi
 AS_IF([test "x$with_database" = "xtdb" && test "x$HAVE_TDB" = "x0"],
     [AC_MSG_ERROR([*** tdb not found])])
 
-if test "x${with_database}" = "xauto" -o "x${with_database}" = "xgdbm" ; then
-   have_gdbm=yes
 
-   AC_CHECK_LIB(gdbm, gdbm_open, [], [have_gdbm=no])
-   AC_CHECK_HEADERS(gdbm.h, [], [have_gdbm=no])
+AS_IF([test "x$with_database" = "xauto" -o "x$with_database" = "xgdbm"],
+    [
+        HAVE_GDBM=1
+        AC_CHECK_LIB(gdbm, gdbm_open, [], HAVE_GDBM=0)
+        AC_CHECK_HEADERS(gdbm.h, [], HAVE_GDBM=0)
+    ],
+    HAVE_GDBM=0)
+AS_IF([test "x$HAVE_GDBM" = "x1"],
+    [
+        with_database=gdbm
+        GDBM_CFLAGS=
+        GDBM_LIBS=-lgdbm
+    ])
 
-   if test "x${have_gdbm}" = "xyes" ; then
-       HAVE_GDBM=1
-       GDBM_CFLAGS=
-       GDBM_LIBS=-lgdbm
-       with_database=gdbm
-   fi
-fi
 AS_IF([test "x$with_database" = "xgdbm" && test "x$HAVE_GDBM" = "x0"],
     [AC_MSG_ERROR([*** gdbm not found])])
 
-if test "x${with_database}" = "xauto" -o "x${with_database}" = "xsimple" ; then
-    HAVE_SIMPLEDB=1
-    with_database=simple
-fi
 
-if test "x${HAVE_TDB}" != x1 -a "x${HAVE_GDBM}" != x1 -a "x${HAVE_SIMPLEDB}" != x1; then
-   AC_MSG_ERROR([*** missing database backend])
-fi
+AS_IF([test "x$with_database" = "xauto" -o "x$with_database" = "xsimple"],
+    HAVE_SIMPLEDB=1,
+    HAVE_SIMPLEDB=0)
+AS_IF([test "x$HAVE_SIMPLEDB" = "x1"], with_database=simple)
+
+AS_IF([test "x$HAVE_TDB" != x1 -a "x$HAVE_GDBM" != x1 -a "x$HAVE_SIMPLEDB" != x1],
+    AC_MSG_ERROR([*** missing database backend]))
+
 
 AC_SUBST(TDB_CFLAGS)
 AC_SUBST(TDB_LIBS)
@@ -751,6 +748,9 @@ AS_IF([test "x$enable_coreaudio_output" != "xno"],
     [AC_CHECK_HEADERS([CoreAudio/CoreAudio.h], HAVE_COREAUDIO=1, HAVE_COREAUDIO=0)],
     HAVE_COREAUDIO=0)
 
+AS_IF([test "x$enable_coreaudio_output" = "xyes" && test "x$HAVE_COREAUDIO" = "x0"],
+    [AC_MSG_ERROR([*** CoreAudio output support not found])])
+
 AC_SUBST(HAVE_COREAUDIO)
 AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = "x1" && test "x$enable_coreaudio_output" != "xno"])
 

commit eea248e233301cc7b243114b975d588c80056625
Author: Maarten Bosmans <mkbosmans at gmail.com>
Date:   Sat Apr 30 15:25:55 2011 +0200

    build-system: Small fixes

diff --git a/configure.ac b/configure.ac
index 08cfbeb..ec1099b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -382,7 +382,6 @@ AM_CONDITIONAL(HAVE_AF_UNIX, test "x$HAVE_AF_UNIX" = "x1")
 
 # Linux
 AC_CHECK_HEADERS([linux/input.h], [HAVE_EVDEV=1], [HAVE_EVDEV=0])
-
 AM_CONDITIONAL([HAVE_EVDEV], [test "x$HAVE_EVDEV" = "x1"])
 
 AC_CHECK_HEADERS_ONCE([sys/prctl.h])
@@ -452,12 +451,6 @@ AC_SEARCH_LIBS([pthread_setname_np], [pthread])
 AC_SEARCH_LIBS([connect], [socket])
 AC_SEARCH_LIBS([backtrace], [execinfo])
 
-# Non-standard
-
-# This magic is needed so we do not needlessly add static libs to the win32
-# build, disabling its ability to make dlls.
-AC_CHECK_FUNCS([getopt_long], [], [AC_CHECK_LIB([iberty], [getopt_long])])
-
 # Darwin/OS X
 if test "x$os_is_darwin" = "x1" ; then
     AC_MSG_CHECKING([looking for Apple CoreService Framework])
@@ -474,7 +467,10 @@ fi
 AC_SUBST(HAVE_BONJOUR)
 AM_CONDITIONAL([HAVE_BONJOUR], [test "x$HAVE_BONJOUR" = x1])
 
+# Windows
 AC_SEARCH_LIBS([regexec], [pcreposix])
+# This magic is needed so we do not needlessly add static libs to the win32  build, disabling its ability to make dlls.
+AC_CHECK_FUNCS([getopt_long], [], [AC_CHECK_LIB([iberty], [getopt_long])])
 
 #### Check for functions ####
 
@@ -1022,7 +1018,7 @@ AC_SUBST(HAVE_DBUS)
 AM_CONDITIONAL([HAVE_DBUS], [test "x$HAVE_DBUS" = x1])
 AS_IF([test "x$HAVE_DBUS" = "x1"], AC_DEFINE([HAVE_DBUS], 1, [Have D-Bus.]))
 
-# udev and HAL depend on D-Bus: So double check if they were explicitly enabled.
+# HAL and BlueZ depend on D-Bus: So double check if they were explicitly enabled.
 if test "x$HAVE_DBUS" != "x1" ; then
     HAVE_HAL=0
     if test "x$enable_hal" = "xyes"; then
@@ -1035,7 +1031,6 @@ if test "x$HAVE_DBUS" != "x1" ; then
     fi
 fi
 
-
 #### HAL compat support (optional) ####
 
 AC_ARG_ENABLE([hal-compat],
@@ -1268,11 +1263,11 @@ echo "
     CFLAGS:                        ${CFLAGS}
     LIBS:                          ${LIBS}
 
-    Have X11:                      ${ENABLE_X11}
+    Enable X11:                    ${ENABLE_X11}
     Enable OSS Output:             ${ENABLE_OSS_OUTPUT}
     Enable OSS Wrapper:            ${ENABLE_OSS_WRAPPER}
-    Enable CoreAudio:              ${ENABLE_COREAUDIO}
     Enable Alsa:                   ${ENABLE_ALSA}
+    Enable CoreAudio:              ${ENABLE_COREAUDIO}
     Enable Solaris:                ${ENABLE_SOLARIS}
     Enable WaveOut:                ${ENABLE_WAVEOUT}
     Enable GLib 2.0:               ${ENABLE_GLIB20}
@@ -1291,11 +1286,12 @@ echo "
     Enable libsamplerate:          ${ENABLE_LIBSAMPLERATE}
     Enable IPv6:                   ${ENABLE_IPV6}
     Enable OpenSSL (for Airtunes): ${ENABLE_OPENSSL}
-    Enable tdb:                    ${ENABLE_TDB}
-    Enable gdbm:                   ${ENABLE_GDBM}
-    Enable simple database:        ${ENABLE_SIMPLEDB}
     Enable fftw:                   ${ENABLE_FFTW}
     Enable orc:                    ${ENABLE_ORC}
+    Database
+      tdb:                         ${ENABLE_TDB}
+      gdbm:                        ${ENABLE_GDBM}
+      simple database:             ${ENABLE_SIMPLEDB}
 
     System User:                   ${PA_SYSTEM_USER}
     System Group:                  ${PA_SYSTEM_GROUP}

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list