]> code.delx.au - pulseaudio/commitdiff
Merge commit 'origin/master-tx'
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Feb 2009 10:33:05 +0000 (11:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 24 Feb 2009 10:33:05 +0000 (11:33 +0100)
63 files changed:
libpulse.pc.in
man/pulse-daemon.conf.5.xml.in
po/.gitignore
po/POTFILES.in
src/.gitignore
src/Makefile.am
src/daemon/.gitignore [new file with mode: 0644]
src/daemon/cmdline.c
src/daemon/daemon-conf.c
src/daemon/daemon-conf.h
src/daemon/daemon.conf.in
src/daemon/main.c
src/daemon/org.pulseaudio.policy.in [moved from src/daemon/org.pulseaudio.policy with 79% similarity]
src/daemon/pulseaudio.desktop.in [moved from src/daemon/pulseaudio.desktop with 63% similarity]
src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c
src/modules/alsa/alsa-util.c
src/modules/alsa/alsa-util.h
src/modules/alsa/module-alsa-card.c
src/modules/bluetooth/module-bluetooth-device.c
src/modules/module-augment-properties.c
src/modules/module-combine.c
src/modules/module-jack-sink.c
src/modules/module-jack-source.c
src/modules/module-null-sink.c
src/modules/module-pipe-sink.c
src/modules/module-pipe-source.c
src/modules/module-raop-discover.c
src/modules/module-raop-sink.c
src/modules/module-tunnel.c
src/modules/module-zeroconf-discover.c
src/modules/oss/module-oss.c
src/modules/reserve-wrap.c [new file with mode: 0644]
src/modules/reserve-wrap.h [new file with mode: 0644]
src/modules/reserve.c [new file with mode: 0644]
src/modules/reserve.h [new file with mode: 0644]
src/pulse/context.c
src/pulse/introspect.c
src/pulse/introspect.h
src/pulse/proplist.h
src/pulsecore/cli-command.c
src/pulsecore/client.c
src/pulsecore/conf-parser.c
src/pulsecore/core.c
src/pulsecore/core.h
src/pulsecore/log.c
src/pulsecore/log.h
src/pulsecore/modargs.c
src/pulsecore/namereg.c
src/pulsecore/proplist-util.c
src/pulsecore/protocol-esound.c
src/pulsecore/protocol-native.c
src/pulsecore/rtpoll.c
src/pulsecore/sink-input.c
src/pulsecore/source-output.c
src/tests/alsa-time-test.c
src/tests/envelope-test.c
src/tests/gtk-test.c
src/tests/memblockq-test.c
src/tests/mix-test.c
src/tests/remix-test.c
src/tests/resampler-test.c
src/utils/pactl.c

index 161599e13cfdfb24a85cc23297e3ec1165086acb..c78b12314cbdc0b0c203b3bbb422eb288ef532eb 100644 (file)
@@ -2,6 +2,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
+modlibexecdir=@modlibexecdir@
 
 Name: libpulse
 Description: PulseAudio Client Interface
index 9ddcd6ae0d7739ccc3ee212b0699db64cdd77cfb..afa7ca00c8cd3e2bc29b8cfa7e8725000db370d5 100644 (file)
@@ -388,6 +388,10 @@ USA.
       <p><opt>default-sample-channels</opt> The default number of channels.</p>
     </option>
 
+    <option>
+      <p><opt>default-channel-map</opt> The default channel map.</p>
+    </option>
+
   </section>
 
   <section name="Default Fragment Settings">
index 2691982879fa360bdf3506acb45fba7a21f227f4..9a0243ade54ca883b830de6d5b43af3e759ae2e9 100644 (file)
@@ -1,3 +1,4 @@
+.intltool-merge-cache
 Makefile.in.in
 Makevars.template
 POTFILES
index 324b9460a6915aac15ebc035edd5d5f48083d269..0d5b42fb616fb08cd352d0063bd8cb4ec533dc55 100644 (file)
@@ -155,6 +155,8 @@ src/daemon/cmdline.c
 src/daemon/dumpmodules.c
 src/daemon/daemon-conf.c
 src/daemon/caps.c
+src/daemon/pulseaudio.desktop.in
+src/daemon/org.pulseaudio.policy.in
 src/pulse/channelmap.c
 src/pulse/error.c
 src/pulse/proplist.c
index 4da445ba2c78834ce2af0f888bbf359b0952f87e..80d33d364c7bc5321fee719645d23836bf7609dd 100644 (file)
@@ -1,3 +1,4 @@
+alsa-time-test
 gtk-test
 prioq-test
 lock-autospawn-test
index ceafdf796931e995bbed6df7bc3221cbc749c72a..1fc873537471f7d39e6edc4a34f76e6924716b03 100644 (file)
@@ -86,6 +86,7 @@ AM_LDFLAGS+=-Wl,--export-all-symbols
 WINSOCK_LIBS=-lwsock32 -lws2_32 -lwininet
 endif
 
+FOREIGN_CLFGAS = -w
 MODULE_LDFLAGS = -module -disable-static -avoid-version
 
 ###################################
@@ -104,9 +105,9 @@ EXTRA_DIST = \
                daemon/start-pulseaudio-x11.in \
                utils/padsp \
                modules/module-defs.h.m4 \
-               daemon/pulseaudio.desktop \
+               daemon/pulseaudio.desktop.in \
                map-file \
-               daemon/org.pulseaudio.policy
+               daemon/org.pulseaudio.policy.in
 
 pulseconf_DATA = \
                default.pa \
@@ -115,9 +116,12 @@ pulseconf_DATA = \
                client.conf
 
 if HAVE_X11
-xdgautostart_DATA = \
-               daemon/pulseaudio.desktop
+xdgautostart_in_files = \
+               daemon/pulseaudio.desktop.in
 endif
+xdgautostart_DATA = $(xdgautostart_in_files:.desktop.in=.desktop)
+@INTLTOOL_DESKTOP_RULE@
+
 
 BUILT_SOURCES = \
                pulse/version.h
@@ -155,7 +159,9 @@ pulseaudio_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) -dlopen force $(foreach f,$(PRE
 endif
 
 if HAVE_POLKIT
-policy_DATA = daemon/org.pulseaudio.policy
+policy_in_files = daemon/org.pulseaudio.policy.in
+policy_DATA = $(policy_in_files:.policy.in=.policy)
+@INTLTOOL_POLICY_RULE@
 
 pulseaudio_SOURCES += daemon/polkit.c daemon/polkit.h
 pulseaudio_CFLAGS += $(POLKIT_CFLAGS)
@@ -765,7 +771,6 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES = \
                pulsecore/core.c pulsecore/core.h \
                pulsecore/envelope.c pulsecore/envelope.h \
                pulsecore/fdsem.c pulsecore/fdsem.h \
-               pulsecore/ffmpeg/resample2.c pulsecore/ffmpeg/avcodec.h pulsecore/ffmpeg/dsputil.h \
                pulsecore/g711.c pulsecore/g711.h \
                pulsecore/hook-list.c pulsecore/hook-list.h \
                pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \
@@ -799,7 +804,7 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES = \
 
 libpulsecore_@PA_MAJORMINORMICRO@_la_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
 libpulsecore_@PA_MAJORMINORMICRO@_la_LDFLAGS = -avoid-version
-libpulsecore_@PA_MAJORMINORMICRO@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSNDFILE_LIBS) $(LIBSPEEX_LIBS) $(WINSOCK_LIBS) $(LIBOIL_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
+libpulsecore_@PA_MAJORMINORMICRO@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSNDFILE_LIBS) $(LIBSPEEX_LIBS) $(WINSOCK_LIBS) $(LIBOIL_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la libpulsecore-foreign.la
 
 if HAVE_X11
 libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/x11wrap.c pulsecore/x11wrap.h
@@ -807,6 +812,14 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_CFLAGS += $(X11_CFLAGS)
 libpulsecore_@PA_MAJORMINORMICRO@_la_LDFLAGS += $(X11_LIBS)
 endif
 
+# We split the foreign code off to not be annoyed by warnings we don't care about
+noinst_LTLIBRARIES = libpulsecore-foreign.la
+
+libpulsecore_foreign_la_SOURCES = \
+               pulsecore/ffmpeg/resample2.c pulsecore/ffmpeg/avcodec.h pulsecore/ffmpeg/dsputil.h
+
+libpulsecore_foreign_la_CFLAGS = $(AM_CFLAGS) -w
+
 ###################################
 #   Plug-in support libraries     #
 ###################################
@@ -1296,10 +1309,16 @@ libalsa_util_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS)
 
 if HAVE_HAL
 libalsa_util_la_SOURCES += modules/hal-util.h modules/hal-util.c
-libalsa_util_la_LIBADD += $(HAL_LIBS) libdbus-util.la
+libalsa_util_la_LIBADD += $(HAL_LIBS)
 libalsa_util_la_CFLAGS += $(HAL_CFLAGS)
 endif
 
+if HAVE_DBUS
+libalsa_util_la_SOURCES += modules/reserve.h modules/reserve.c modules/reserve-wrap.c modules/reserve-wrap.h
+libalsa_util_la_LIBADD += $(DBUS_LIBS)
+libalsa_util_la_CFLAGS += $(DBUS_CFLAGS)
+endif
+
 module_alsa_sink_la_SOURCES = modules/alsa/module-alsa-sink.c
 module_alsa_sink_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_alsa_sink_la_LIBADD = $(AM_LIBADD) $(ASOUNDLIB_LIBS) libalsa-util.la libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
@@ -1535,7 +1554,7 @@ suid: pulseaudio .libs/lt-pulseaudio
        chown root $^
        chmod u+s $^
 
-CLEANFILES = esdcompat client.conf default.pa system.pa daemon.conf start-pulseaudio-x11
+CLEANFILES = esdcompat client.conf default.pa system.pa daemon.conf start-pulseaudio-x11 daemon/pulseaudio.desktop daemon/org.pulseaudio.policy
 
 esdcompat: daemon/esdcompat.in Makefile
        sed -e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
@@ -1601,6 +1620,11 @@ update-sbc:
                wget -O modules/bluetooth/$$i http://git.kernel.org/\?p=bluetooth/bluez.git\;a=blob_plain\;f=audio/$$i ; \
        done
 
+update-reserve:
+       for i in reserve.c reserve.h ; do \
+               wget -O modules/$$i http://git.0pointer.de/\?p=reserve.git\;a=blob_plain\;f=$$i\;hb=master ; \
+       done
+
 # Automatically generate linker version script. We use the same one for all public .sos
 update-map-file:
        ( echo "PULSE_0 {" ; \
diff --git a/src/daemon/.gitignore b/src/daemon/.gitignore
new file mode 100644 (file)
index 0000000..0efa55b
--- /dev/null
@@ -0,0 +1,2 @@
+org.pulseaudio.policy
+pulseaudio.desktop
index 43a4a3260469987cd9ddf17c23e92bc061b75761..f4224ea80d8d2d03e17bc706432b20e2effb7e7b 100644 (file)
@@ -299,7 +299,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
 
             case ARG_DISALLOW_EXIT:
                 if ((conf->disallow_exit = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
-                    pa_log(_("--disallow-exit boolean argument"));
+                    pa_log(_("--disallow-exit expects boolean argument"));
                     goto fail;
                 }
                 break;
@@ -330,14 +330,14 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
 
             case ARG_LOG_TIME:
                 if ((conf->log_time = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
-                    pa_log(_("--log-time boolean argument"));
+                    pa_log(_("--log-time expects boolean argument"));
                     goto fail;
                 }
                 break;
 
             case ARG_LOG_META:
                 if ((conf->log_meta = optarg ? pa_parse_boolean(optarg) : TRUE) < 0) {
-                    pa_log(_("--log-meta boolean argument"));
+                    pa_log(_("--log-meta expects boolean argument"));
                     goto fail;
                 }
                 break;
index 7dfef27fc7f9e301fa7edb6b7e5ae758f87b3acc..10144ea45b302718ef84548a161f5204818017e0 100644 (file)
@@ -88,6 +88,7 @@ static const pa_daemon_conf default_conf = {
     .default_n_fragments = 4,
     .default_fragment_size_msec = 25,
     .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 },
+    .default_channel_map = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } },
     .shm_size = 0
 #ifdef HAVE_SYS_RESOURCE_H
    ,.rlimit_fsize = { .value = 0, .is_set = FALSE },
@@ -313,8 +314,14 @@ static int parse_sample_rate(const char *filename, unsigned line, const char *se
     return 0;
 }
 
+struct channel_conf_info {
+    pa_daemon_conf *conf;
+    pa_bool_t default_sample_spec_set;
+    pa_bool_t default_channel_map_set;
+};
+
 static int parse_sample_channels(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
-    pa_daemon_conf *c = data;
+    struct channel_conf_info *i = data;
     int32_t n;
 
     pa_assert(filename);
@@ -327,7 +334,25 @@ static int parse_sample_channels(const char *filename, unsigned line, const char
         return -1;
     }
 
-    c->default_sample_spec.channels = (uint8_t) n;
+    i->conf->default_sample_spec.channels = (uint8_t) n;
+    i->default_sample_spec_set = TRUE;
+    return 0;
+}
+
+static int parse_channel_map(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
+    struct channel_conf_info *i = data;
+
+    pa_assert(filename);
+    pa_assert(lvalue);
+    pa_assert(rvalue);
+    pa_assert(data);
+
+    if (!pa_channel_map_parse(&i->conf->default_channel_map, rvalue)) {
+        pa_log(_("[%s:%u] Invalid channel map '%s'."), filename, line, rvalue);
+        return -1;
+    }
+
+    i->default_channel_map_set = TRUE;
     return 0;
 }
 
@@ -406,155 +431,82 @@ static int parse_rtprio(const char *filename, unsigned line, const char *section
 int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
     int r = -1;
     FILE *f = NULL;
-    unsigned i = 0;
-
+    struct channel_conf_info ci;
     pa_config_item table[] = {
-        { "daemonize",                  pa_config_parse_bool,     NULL, NULL },
-        { "fail",                       pa_config_parse_bool,     NULL, NULL },
-        { "high-priority",              pa_config_parse_bool,     NULL, NULL },
-        { "realtime-scheduling",        pa_config_parse_bool,     NULL, NULL },
-        { "disallow-module-loading",    pa_config_parse_bool,     NULL, NULL },
-        { "disallow-exit",              pa_config_parse_bool,     NULL, NULL },
-        { "use-pid-file",               pa_config_parse_bool,     NULL, NULL },
-        { "system-instance",            pa_config_parse_bool,     NULL, NULL },
-        { "no-cpu-limit",               pa_config_parse_bool,     NULL, NULL },
-        { "disable-shm",                pa_config_parse_bool,     NULL, NULL },
-        { "flat-volumes",               pa_config_parse_bool,     NULL, NULL },
-        { "exit-idle-time",             pa_config_parse_int,      NULL, NULL },
-        { "scache-idle-time",           pa_config_parse_int,      NULL, NULL },
-        { "realtime-priority",          parse_rtprio,             NULL, NULL },
-        { "dl-search-path",             pa_config_parse_string,   NULL, NULL },
-        { "default-script-file",        pa_config_parse_string,   NULL, NULL },
-        { "log-target",                 parse_log_target,         NULL, NULL },
-        { "log-level",                  parse_log_level,          NULL, NULL },
-        { "verbose",                    parse_log_level,          NULL, NULL },
-        { "resample-method",            parse_resample_method,    NULL, NULL },
-        { "default-sample-format",      parse_sample_format,      NULL, NULL },
-        { "default-sample-rate",        parse_sample_rate,        NULL, NULL },
-        { "default-sample-channels",    parse_sample_channels,    NULL, NULL },
-        { "default-fragments",          parse_fragments,          NULL, NULL },
-        { "default-fragment-size-msec", parse_fragment_size_msec, NULL, NULL },
-        { "nice-level",                 parse_nice_level,         NULL, NULL },
-        { "disable-remixing",           pa_config_parse_bool,     NULL, NULL },
-        { "disable-lfe-remixing",       pa_config_parse_bool,     NULL, NULL },
-        { "load-default-script-file",   pa_config_parse_bool,     NULL, NULL },
-        { "shm-size-bytes",             pa_config_parse_size,     NULL, NULL },
-        { "log-meta",                   pa_config_parse_bool,     NULL, NULL },
-        { "log-time",                   pa_config_parse_bool,     NULL, NULL },
-        { "log-backtrace",              pa_config_parse_unsigned, NULL, NULL },
+        { "daemonize",                  pa_config_parse_bool,     &c->daemonize, NULL },
+        { "fail",                       pa_config_parse_bool,     &c->fail, NULL },
+        { "high-priority",              pa_config_parse_bool,     &c->high_priority, NULL },
+        { "realtime-scheduling",        pa_config_parse_bool,     &c->realtime_scheduling, NULL },
+        { "disallow-module-loading",    pa_config_parse_bool,     &c->disallow_module_loading, NULL },
+        { "disallow-exit",              pa_config_parse_bool,     &c->disallow_exit, NULL },
+        { "use-pid-file",               pa_config_parse_bool,     &c->use_pid_file, NULL },
+        { "system-instance",            pa_config_parse_bool,     &c->system_instance, NULL },
+        { "no-cpu-limit",               pa_config_parse_bool,     &c->no_cpu_limit, NULL },
+        { "disable-shm",                pa_config_parse_bool,     &c->disable_shm, NULL },
+        { "flat-volumes",               pa_config_parse_bool,     &c->flat_volumes, NULL },
+        { "exit-idle-time",             pa_config_parse_int,      &c->exit_idle_time, NULL },
+        { "scache-idle-time",           pa_config_parse_int,      &c->scache_idle_time, NULL },
+        { "realtime-priority",          parse_rtprio,             c, NULL },
+        { "dl-search-path",             pa_config_parse_string,   &c->dl_search_path, NULL },
+        { "default-script-file",        pa_config_parse_string,   &c->default_script_file, NULL },
+        { "log-target",                 parse_log_target,         c, NULL },
+        { "log-level",                  parse_log_level,          c, NULL },
+        { "verbose",                    parse_log_level,          c, NULL },
+        { "resample-method",            parse_resample_method,    c, NULL },
+        { "default-sample-format",      parse_sample_format,      c, NULL },
+        { "default-sample-rate",        parse_sample_rate,        c, NULL },
+        { "default-sample-channels",    parse_sample_channels,    &ci,  NULL },
+        { "default-channel-map",        parse_channel_map,        &ci,  NULL },
+        { "default-fragments",          parse_fragments,          c, NULL },
+        { "default-fragment-size-msec", parse_fragment_size_msec, c, NULL },
+        { "nice-level",                 parse_nice_level,         c, NULL },
+        { "disable-remixing",           pa_config_parse_bool,     &c->disable_remixing, NULL },
+        { "disable-lfe-remixing",       pa_config_parse_bool,     &c->disable_lfe_remixing, NULL },
+        { "load-default-script-file",   pa_config_parse_bool,     &c->load_default_script_file, NULL },
+        { "shm-size-bytes",             pa_config_parse_size,     &c->shm_size, NULL },
+        { "log-meta",                   pa_config_parse_bool,     &c->log_meta, NULL },
+        { "log-time",                   pa_config_parse_bool,     &c->log_time, NULL },
+        { "log-backtrace",              pa_config_parse_unsigned, &c->log_backtrace, NULL },
 #ifdef HAVE_SYS_RESOURCE_H
-        { "rlimit-fsize",               parse_rlimit,             NULL, NULL },
-        { "rlimit-data",                parse_rlimit,             NULL, NULL },
-        { "rlimit-stack",               parse_rlimit,             NULL, NULL },
-        { "rlimit-core",                parse_rlimit,             NULL, NULL },
-        { "rlimit-rss",                 parse_rlimit,             NULL, NULL },
+        { "rlimit-fsize",               parse_rlimit,             &c->rlimit_fsize, NULL },
+        { "rlimit-data",                parse_rlimit,             &c->rlimit_data, NULL },
+        { "rlimit-stack",               parse_rlimit,             &c->rlimit_stack, NULL },
+        { "rlimit-core",                parse_rlimit,             &c->rlimit_core, NULL },
+        { "rlimit-rss",                 parse_rlimit,             &c->rlimit_rss, NULL },
 #ifdef RLIMIT_NOFILE
-        { "rlimit-nofile",              parse_rlimit,             NULL, NULL },
+        { "rlimit-nofile",              parse_rlimit,             &c->rlimit_nofile, NULL },
 #endif
 #ifdef RLIMIT_AS
-        { "rlimit-as",                  parse_rlimit,             NULL, NULL },
+        { "rlimit-as",                  parse_rlimit,             &c->rlimit_as, NULL },
 #endif
 #ifdef RLIMIT_NPROC
-        { "rlimit-nproc",               parse_rlimit,             NULL, NULL },
+        { "rlimit-nproc",               parse_rlimit,             &c->rlimit_nproc, NULL },
 #endif
 #ifdef RLIMIT_MEMLOCK
-        { "rlimit-memlock",             parse_rlimit,             NULL, NULL },
+        { "rlimit-memlock",             parse_rlimit,             &c->rlimit_memlock, NULL },
 #endif
 #ifdef RLIMIT_LOCKS
-        { "rlimit-locks",               parse_rlimit,             NULL, NULL },
+        { "rlimit-locks",               parse_rlimit,             &c->rlimit_locks, NULL },
 #endif
 #ifdef RLIMIT_SIGPENDING
-        { "rlimit-sigpending",          parse_rlimit,             NULL, NULL },
+        { "rlimit-sigpending",          parse_rlimit,             &c->rlimit_sigpending, NULL },
 #endif
 #ifdef RLIMIT_MSGQUEUE
-        { "rlimit-msgqueue",            parse_rlimit,             NULL, NULL },
+        { "rlimit-msgqueue",            parse_rlimit,             &c->rlimit_msgqueue, NULL },
 #endif
 #ifdef RLIMIT_NICE
-        { "rlimit-nice",                parse_rlimit,             NULL, NULL },
+        { "rlimit-nice",                parse_rlimit,             &c->rlimit_nice, NULL },
 #endif
 #ifdef RLIMIT_RTPRIO
-        { "rlimit-rtprio",              parse_rlimit,             NULL, NULL },
+        { "rlimit-rtprio",              parse_rlimit,             &c->rlimit_rtprio, NULL },
 #endif
 #ifdef RLIMIT_RTTIME
-        { "rlimit-rttime",              parse_rlimit,             NULL, NULL },
+        { "rlimit-rttime",              parse_rlimit,             &c->rlimit_rttime, NULL },
 #endif
 #endif
         { NULL,                         NULL,                     NULL, NULL },
     };
 
-    table[i++].data = &c->daemonize;
-    table[i++].data = &c->fail;
-    table[i++].data = &c->high_priority;
-    table[i++].data = &c->realtime_scheduling;
-    table[i++].data = &c->disallow_module_loading;
-    table[i++].data = &c->disallow_exit;
-    table[i++].data = &c->use_pid_file;
-    table[i++].data = &c->system_instance;
-    table[i++].data = &c->no_cpu_limit;
-    table[i++].data = &c->disable_shm;
-    table[i++].data = &c->flat_volumes;
-    table[i++].data = &c->exit_idle_time;
-    table[i++].data = &c->scache_idle_time;
-    table[i++].data = c;
-    table[i++].data = &c->dl_search_path;
-    table[i++].data = &c->default_script_file;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = c;
-    table[i++].data = &c->disable_remixing;
-    table[i++].data = &c->disable_lfe_remixing;
-    table[i++].data = &c->load_default_script_file;
-    table[i++].data = &c->shm_size;
-    table[i++].data = &c->log_meta;
-    table[i++].data = &c->log_time;
-    table[i++].data = &c->log_backtrace;
-#ifdef HAVE_SYS_RESOURCE_H
-    table[i++].data = &c->rlimit_fsize;
-    table[i++].data = &c->rlimit_data;
-    table[i++].data = &c->rlimit_stack;
-    table[i++].data = &c->rlimit_core;
-    table[i++].data = &c->rlimit_rss;
-#ifdef RLIMIT_NOFILE
-    table[i++].data = &c->rlimit_nofile;
-#endif
-#ifdef RLIMIT_AS
-    table[i++].data = &c->rlimit_as;
-#endif
-#ifdef RLIMIT_NPROC
-    table[i++].data = &c->rlimit_nproc;
-#endif
-#ifdef RLIMIT_MEMLOCK
-    table[i++].data = &c->rlimit_memlock;
-#endif
-#ifdef RLIMIT_LOCKS
-    table[i++].data = &c->rlimit_locks;
-#endif
-#ifdef RLIMIT_SIGPENDING
-    table[i++].data = &c->rlimit_sigpending;
-#endif
-#ifdef RLIMIT_MSGQUEUE
-    table[i++].data = &c->rlimit_msgqueue;
-#endif
-#ifdef RLIMIT_NICE
-    table[i++].data = &c->rlimit_nice;
-#endif
-#ifdef RLIMIT_RTPRIO
-    table[i++].data = &c->rlimit_rtprio;
-#endif
-#ifdef RLIMIT_RTTIME
-    table[i++].data = &c->rlimit_rttime;
-#endif
-#endif
-
-    pa_assert(i == PA_ELEMENTSOF(table)-1);
-
     pa_xfree(c->config_file);
     c->config_file = NULL;
 
@@ -567,8 +519,27 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
         goto finish;
     }
 
+    ci.default_channel_map_set = ci.default_sample_spec_set = FALSE;
+    ci.conf = c;
+
     r = f ? pa_config_parse(c->config_file, f, table, NULL) : 0;
 
+    if (r >= 0) {
+
+        /* Make sure that channel map and sample spec fit together */
+
+        if (ci.default_sample_spec_set &&
+            ci.default_channel_map_set &&
+            c->default_channel_map.channels != c->default_sample_spec.channels) {
+            pa_log_error(_("The specified default channel map has a different number of channels than the specified default number of channels."));
+            r = -1;
+            goto finish;
+        } else if (ci.default_sample_spec_set)
+            pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+        else if (ci.default_channel_map_set)
+            c->default_sample_spec.channels = c->default_channel_map.channels;
+    }
+
 finish:
     if (f)
         fclose(f);
@@ -631,6 +602,7 @@ static const char* const log_level_to_string[] = {
 
 char *pa_daemon_conf_dump(pa_daemon_conf *c) {
     pa_strbuf *s;
+    char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
 
     pa_assert(c);
 
@@ -667,6 +639,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) {
     pa_strbuf_printf(s, "default-sample-format = %s\n", pa_sample_format_to_string(c->default_sample_spec.format));
     pa_strbuf_printf(s, "default-sample-rate = %u\n", c->default_sample_spec.rate);
     pa_strbuf_printf(s, "default-sample-channels = %u\n", c->default_sample_spec.channels);
+    pa_strbuf_printf(s, "default-channel-map = %s\n", pa_channel_map_snprint(cm, sizeof(cm), &c->default_channel_map));
     pa_strbuf_printf(s, "default-fragments = %u\n", c->default_n_fragments);
     pa_strbuf_printf(s, "default-fragment-size-msec = %u\n", c->default_fragment_size_msec);
     pa_strbuf_printf(s, "shm-size-bytes = %lu\n", (unsigned long) c->shm_size);
index aa9d2981d9a9d78742a19634009b1190445d0583..9331280b5121461b4de3c48f11be803234282db6 100644 (file)
   USA.
 ***/
 
+#include <pulse/sample.h>
+#include <pulse/channelmap.h>
+
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/core-util.h>
-#include <pulse/sample.h>
 
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
@@ -121,6 +123,7 @@ typedef struct pa_daemon_conf {
 
     unsigned default_n_fragments, default_fragment_size_msec;
     pa_sample_spec default_sample_spec;
+    pa_channel_map default_channel_map;
     size_t shm_size;
 } pa_daemon_conf;
 
index 69d17f26141de44848bcffe4804b4a4587689efc..fcd2513a6c8bfb96df1cf6d8ffc73279a2ad5885 100644 (file)
@@ -76,6 +76,7 @@
 ; default-sample-format = s16le
 ; default-sample-rate = 44100
 ; default-sample-channels = 2
+; default-channel-map = front-left,front-right
 
 ; default-fragments = 4
 ; default-fragment-size-msec = 25
index 5f94ec66501b3e80ace50e9f9eca000b718ab6b9..b630bd173375439d84bb9173bd32a88735392ad4 100644 (file)
@@ -351,8 +351,9 @@ int main(int argc, char *argv[]) {
     int autospawn_fd = -1;
     pa_bool_t autospawn_locked = FALSE;
 
-    pa_log_set_maximal_level(PA_LOG_INFO);
     pa_log_set_ident("pulseaudio");
+    pa_log_set_level(PA_LOG_INFO);
+    pa_log_set_flags(PA_LOG_COLORS|PA_LOG_PRINT_FILE|PA_LOG_PRINT_LEVEL, PA_LOG_RESET);
 
 #if defined(__linux__) && defined(__OPTIMIZE__)
     /*
@@ -432,11 +433,13 @@ int main(int argc, char *argv[]) {
         goto finish;
     }
 
-    pa_log_set_maximal_level(conf->log_level);
-    pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target, NULL);
-    pa_log_set_show_meta(conf->log_meta);
+    pa_log_set_level(conf->log_level);
+    pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target);
+    if (conf->log_meta)
+        pa_log_set_flags(PA_LOG_PRINT_META, PA_LOG_SET);
+    if (conf->log_time)
+        pa_log_set_flags(PA_LOG_PRINT_TIME, PA_LOG_SET);
     pa_log_set_show_backtrace(conf->log_backtrace);
-    pa_log_set_show_time(conf->log_time);
 
     pa_log_debug("Started as real root: %s, suid root: %s", pa_yes_no(real_root), pa_yes_no(suid_root));
 
@@ -506,8 +509,9 @@ int main(int argc, char *argv[]) {
         if ((conf->high_priority && !allow_high_priority) ||
             (conf->realtime_scheduling && !allow_realtime))
             pa_log_notice(_("Called SUID root and real-time and/or high-priority scheduling was requested in the configuration. However, we lack the necessary privileges:\n"
-                            "We are not in group '"PA_REALTIME_GROUP"', PolicyKit refuse to grant us the requested privileges and we have no increase RLIMIT_NICE/RLIMIT_RTPRIO resource limits.\n"
-                            "For enabling real-time/high-priority scheduling please acquire the appropriate PolicyKit privileges, or become a member of '"PA_REALTIME_GROUP"', or increase the RLIMIT_NICE/RLIMIT_RTPRIO resource limits for this user."));
+                            "We are not in group '%s', PolicyKit refuse to grant us the requested privileges and we have no increase RLIMIT_NICE/RLIMIT_RTPRIO resource limits.\n"
+                            "For enabling real-time/high-priority scheduling please acquire the appropriate PolicyKit privileges, or become a member of '%s', or increase the RLIMIT_NICE/RLIMIT_RTPRIO resource limits for this user."),
+                          PA_REALTIME_GROUP, PA_REALTIME_GROUP);
 
 
         if (!allow_realtime)
@@ -770,7 +774,7 @@ int main(int argc, char *argv[]) {
 #endif
 
         if (conf->auto_log_target)
-            pa_log_set_target(PA_LOG_SYSLOG, NULL);
+            pa_log_set_target(PA_LOG_SYSLOG);
 
 #ifdef HAVE_SETSID
         setsid();
@@ -908,6 +912,7 @@ int main(int argc, char *argv[]) {
     }
 
     c->default_sample_spec = conf->default_sample_spec;
+    c->default_channel_map = conf->default_channel_map;
     c->default_n_fragments = conf->default_n_fragments;
     c->default_fragment_size_msec = conf->default_fragment_size_msec;
     c->exit_idle_time = conf->exit_idle_time;
similarity index 79%
rename from src/daemon/org.pulseaudio.policy
rename to src/daemon/org.pulseaudio.policy.in
index 6cdeec687c5ad4648badc04c1b0790f09255553b..1d0b6a7d25f5aadc0db7cff0a8455ca9edd05cac 100644 (file)
@@ -28,8 +28,8 @@ USA.
   <icon_name>audio-card</icon_name>
 
   <action id="org.pulseaudio.acquire-real-time">
-    <description>Real-time scheduling for the PulseAudio daemon</description>
-    <message>System policy prevents PulseAudio from acquiring real-time scheduling.</message>
+    <_description>Real-time scheduling for the PulseAudio daemon</_description>
+    <_message>System policy prevents PulseAudio from acquiring real-time scheduling.</_message>
     <defaults>
       <allow_any>no</allow_any>
       <allow_inactive>no</allow_inactive>
@@ -38,8 +38,8 @@ USA.
   </action>
 
   <action id="org.pulseaudio.acquire-high-priority">
-    <description>High-priority scheduling (negative Unix nice level) for the PulseAudio daemon</description>
-    <message>System policy prevents PulseAudio from acquiring high-priority scheduling.</message>
+    <_description>High-priority scheduling (negative Unix nice level) for the PulseAudio daemon</_description>
+    <_message>System policy prevents PulseAudio from acquiring high-priority scheduling.</_message>
     <defaults>
       <allow_any>no</allow_any>
       <allow_inactive>no</allow_inactive>
similarity index 63%
rename from src/daemon/pulseaudio.desktop
rename to src/daemon/pulseaudio.desktop.in
index 57a7a6e4a181884d5c652af0e9d011614be37e3d..99bdbd005035354e5deda72da109672ee7450fe3 100644 (file)
@@ -1,8 +1,8 @@
 [Desktop Entry]
 Version=1.0
 Encoding=UTF-8
-Name=PulseAudio Sound System
-Comment=Start the PulseAudio Sound System
+_Name=PulseAudio Sound System
+_Comment=Start the PulseAudio Sound System
 Exec=start-pulseaudio-x11
 Terminal=false
 Type=Application
index 239a9d786422469e21e3237c44836dabd73e8508..dbd95b637e7345d90374bbb59491af2c05289e31 100644 (file)
@@ -53,6 +53,8 @@
 #include <pulsecore/rtclock.h>
 #include <pulsecore/time-smoother.h>
 
+#include <modules/reserve-wrap.h>
+
 #include "alsa-util.h"
 #include "alsa-sink.h"
 
@@ -101,10 +103,75 @@ struct userdata {
     pa_smoother *smoother;
     uint64_t write_count;
     uint64_t since_start;
+
+    pa_reserve_wrapper *reserve;
+    pa_hook_slot *reserve_slot;
 };
 
 static void userdata_free(struct userdata *u);
 
+static pa_hook_result_t reserve_cb(pa_reserve_wrapper *r, void *forced, struct userdata *u) {
+    pa_assert(r);
+    pa_assert(u);
+
+    if (pa_sink_suspend(u->sink, TRUE) < 0)
+        return PA_HOOK_CANCEL;
+
+    return PA_HOOK_OK;
+}
+
+static void reserve_done(struct userdata *u) {
+    pa_assert(u);
+
+    if (u->reserve_slot) {
+        pa_hook_slot_free(u->reserve_slot);
+        u->reserve_slot = NULL;
+    }
+
+    if (u->reserve) {
+        pa_reserve_wrapper_unref(u->reserve);
+        u->reserve = NULL;
+    }
+}
+
+static void reserve_update(struct userdata *u) {
+    const char *description;
+    pa_assert(u);
+
+    if (!u->sink)
+        return;
+
+    if ((description = pa_proplist_gets(u->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)))
+        pa_reserve_wrapper_set_application_device_name(u->reserve, description);
+}
+
+static int reserve_init(struct userdata *u, const char *dname) {
+    char *rname;
+
+    pa_assert(u);
+    pa_assert(dname);
+
+    if (u->reserve)
+        return 0;
+
+    /* We are resuming, try to lock the device */
+    if (!(rname = pa_alsa_get_reserve_name(dname)))
+        return 0;
+
+    u->reserve = pa_reserve_wrapper_get(u->core, rname);
+    pa_xfree(rname);
+
+    if (!(u->reserve))
+        return -1;
+
+    reserve_update(u);
+
+    pa_assert(!u->reserve_slot);
+    u->reserve_slot = pa_hook_connect(pa_reserve_wrapper_hook(u->reserve), PA_HOOK_NORMAL, (pa_hook_cb_t) reserve_cb, u);
+
+    return 0;
+}
+
 static void fix_min_sleep_wakeup(struct userdata *u) {
     size_t max_use, max_use_2;
 
@@ -255,6 +322,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
     pa_bool_t work_done = TRUE;
     pa_usec_t max_sleep_usec = 0, process_usec = 0;
     size_t left_to_play;
+    unsigned j = 0;
 
     pa_assert(u);
     pa_sink_assert_ref(u->sink);
@@ -304,10 +372,15 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
 
         if (PA_UNLIKELY(n_bytes <= u->hwbuf_unused)) {
 
-            if (polled && pa_log_ratelimit())
-                pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
-                         "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
-                         "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0."));
+            if (polled)
+                PA_ONCE_BEGIN {
+                    char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle);
+                    pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write!\n"
+                             "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n"
+                             "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."),
+                           pa_strnull(dn));
+                    pa_xfree(dn);
+                } PA_ONCE_END;
 
 #ifdef DEBUG_TIMING
             pa_log_debug("Not filling up, because not necessary.");
@@ -315,6 +388,15 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
             break;
         }
 
+
+        if (++j > 10) {
+#ifdef DEBUG_TIMING
+            pa_log_debug("Not filling up, because already too many iterations.");
+#endif
+
+            break;
+        }
+
         n_bytes -= u->hwbuf_unused;
         polled = FALSE;
 
@@ -394,6 +476,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
     pa_bool_t work_done = FALSE;
     pa_usec_t max_sleep_usec = 0, process_usec = 0;
     size_t left_to_play;
+    unsigned j = 0;
 
     pa_assert(u);
     pa_sink_assert_ref(u->sink);
@@ -431,10 +514,23 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
 
         if (PA_UNLIKELY(n_bytes <= u->hwbuf_unused)) {
 
-            if (polled && pa_log_ratelimit())
-                pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
-                         "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
-                         "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0."));
+            if (polled)
+                PA_ONCE_BEGIN {
+                    char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle);
+                    pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write!\n"
+                             "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n"
+                             "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."),
+                           pa_strnull(dn));
+                    pa_xfree(dn);
+                } PA_ONCE_END;
+
+            break;
+        }
+
+        if (++j > 10) {
+#ifdef DEBUG_TIMING
+            pa_log_debug("Not filling up, because already too many iterations.");
+#endif
 
             break;
         }
@@ -512,7 +608,7 @@ static void update_smoother(struct userdata *u) {
 
     /* Let's update the time smoother */
 
-    if (PA_UNLIKELY((err = snd_pcm_delay(u->pcm_handle, &delay)) < 0)) {
+    if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, &delay, u->hwbuf_size, &u->sink->sample_spec)) < 0)) {
         pa_log_warn("Failed to query DSP status data: %s", snd_strerror(err));
         return;
     }
@@ -572,6 +668,7 @@ static int build_pollfd(struct userdata *u) {
     return 0;
 }
 
+/* Called from IO context */
 static int suspend(struct userdata *u) {
     pa_assert(u);
     pa_assert(u->pcm_handle);
@@ -593,6 +690,7 @@ static int suspend(struct userdata *u) {
     return 0;
 }
 
+/* Called from IO context */
 static int update_sw_params(struct userdata *u) {
     snd_pcm_uframes_t avail_min;
     int err;
@@ -648,6 +746,7 @@ static int update_sw_params(struct userdata *u) {
     return 0;
 }
 
+/* Called from IO context */
 static int unsuspend(struct userdata *u) {
     pa_sample_spec ss;
     int err;
@@ -720,6 +819,7 @@ fail:
     return -1;
 }
 
+/* Called from IO context */
 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;
 
@@ -775,6 +875,25 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
     return pa_sink_process_msg(o, code, data, offset, chunk);
 }
 
+/* Called from main context */
+static int sink_set_state_cb(pa_sink *s, pa_sink_state_t new_state) {
+    pa_sink_state_t old_state;
+    struct userdata *u;
+
+    pa_sink_assert_ref(s);
+    pa_assert_se(u = s->userdata);
+
+    old_state = pa_sink_get_state(u->sink);
+
+    if (PA_SINK_IS_OPENED(old_state) && new_state == PA_SINK_SUSPENDED)
+        reserve_done(u);
+    else if (old_state == PA_SINK_SUSPENDED && PA_SINK_IS_OPENED(new_state))
+        if (reserve_init(u, u->device_name) < 0)
+            return -1;
+
+    return 0;
+}
+
 static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
     struct userdata *u = snd_mixer_elem_get_callback_private(elem);
 
@@ -1378,6 +1497,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     pa_assert(ma);
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification and channel map");
         goto fail;
@@ -1438,6 +1558,11 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     pa_smoother_set_time_offset(u->smoother, usec);
     pa_smoother_pause(u->smoother, usec);
 
+    if (reserve_init(u, pa_modargs_get_value(
+                             ma, "device_id",
+                             pa_modargs_get_value(ma, "device", DEFAULT_DEVICE))) < 0)
+        goto fail;
+
     b = use_mmap;
     d = use_tsched;
 
@@ -1539,6 +1664,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     u->sink->parent.process_msg = sink_process_msg;
     u->sink->update_requested_latency = sink_update_requested_latency_cb;
+    u->sink->set_state = sink_set_state_cb;
     u->sink->userdata = u;
 
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
@@ -1571,6 +1697,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         pa_log_info("Time scheduling watermark is %0.2fms",
                     (double) pa_bytes_to_usec(u->tsched_watermark, &ss) / PA_USEC_PER_MSEC);
 
+    reserve_update(u);
+
     if (update_sw_params(u) < 0)
         goto fail;
 
@@ -1651,6 +1779,8 @@ static void userdata_free(struct userdata *u) {
     if (u->smoother)
         pa_smoother_free(u->smoother);
 
+    reserve_done(u);
+
     pa_xfree(u->device_name);
     pa_xfree(u);
 }
index 50cdb31092140eb4213cc154f04208f6b8de3424..39df4a917ab0e7eeecf417890f3051d85434fb93 100644 (file)
@@ -54,6 +54,8 @@
 #include <pulsecore/time-smoother.h>
 #include <pulsecore/rtclock.h>
 
+#include <modules/reserve-wrap.h>
+
 #include "alsa-util.h"
 #include "alsa-source.h"
 
@@ -99,10 +101,75 @@ struct userdata {
 
     pa_smoother *smoother;
     uint64_t read_count;
+
+    pa_reserve_wrapper *reserve;
+    pa_hook_slot *reserve_slot;
 };
 
 static void userdata_free(struct userdata *u);
 
+static pa_hook_result_t reserve_cb(pa_reserve_wrapper *r, void *forced, struct userdata *u) {
+    pa_assert(r);
+    pa_assert(u);
+
+    if (pa_source_suspend(u->source, TRUE) < 0)
+        return PA_HOOK_CANCEL;
+
+    return PA_HOOK_OK;
+}
+
+static void reserve_done(struct userdata *u) {
+    pa_assert(u);
+
+    if (u->reserve_slot) {
+        pa_hook_slot_free(u->reserve_slot);
+        u->reserve_slot = NULL;
+    }
+
+    if (u->reserve) {
+        pa_reserve_wrapper_unref(u->reserve);
+        u->reserve = NULL;
+    }
+}
+
+static void reserve_update(struct userdata *u) {
+    const char *description;
+    pa_assert(u);
+
+    if (!u->source)
+        return;
+
+    if ((description = pa_proplist_gets(u->source->proplist, PA_PROP_DEVICE_DESCRIPTION)))
+        pa_reserve_wrapper_set_application_device_name(u->reserve, description);
+}
+
+static int reserve_init(struct userdata *u, const char *dname) {
+    char *rname;
+
+    pa_assert(u);
+    pa_assert(dname);
+
+    if (u->reserve)
+        return 0;
+
+    /* We are resuming, try to lock the device */
+    if (!(rname = pa_alsa_get_reserve_name(dname)))
+        return 0;
+
+    u->reserve = pa_reserve_wrapper_get(u->core, rname);
+    pa_xfree(rname);
+
+    if (!(u->reserve))
+        return -1;
+
+    reserve_update(u);
+
+    pa_assert(!u->reserve_slot);
+    u->reserve_slot = pa_hook_connect(pa_reserve_wrapper_hook(u->reserve), PA_HOOK_NORMAL, (pa_hook_cb_t) reserve_cb, u);
+
+    return 0;
+}
+
 static void fix_min_sleep_wakeup(struct userdata *u) {
     size_t max_use, max_use_2;
     pa_assert(u);
@@ -248,6 +315,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
     pa_bool_t work_done = FALSE;
     pa_usec_t max_sleep_usec = 0, process_usec = 0;
     size_t left_to_record;
+    unsigned j = 0;
 
     pa_assert(u);
     pa_source_assert_ref(u->source);
@@ -287,10 +355,15 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
 
         if (PA_UNLIKELY(n_bytes <= 0)) {
 
-            if (polled && pa_log_ratelimit())
-                pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read! "
-                         "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
-                         "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0."));
+            if (polled)
+                PA_ONCE_BEGIN {
+                    char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle);
+                    pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read!\n"
+                             "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n"
+                             "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."),
+                           pa_strnull(dn));
+                    pa_xfree(dn);
+                } PA_ONCE_END;
 
 #ifdef DEBUG_TIMING
             pa_log_debug("Not reading, because not necessary.");
@@ -298,6 +371,14 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
             break;
         }
 
+        if (++j > 10) {
+#ifdef DEBUG_TIMING
+            pa_log_debug("Not filling up, because already too many iterations.");
+#endif
+
+            break;
+        }
+
         polled = FALSE;
 
 #ifdef DEBUG_TIMING
@@ -376,6 +457,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
     int work_done = FALSE;
     pa_usec_t max_sleep_usec = 0, process_usec = 0;
     size_t left_to_record;
+    unsigned j = 0;
 
     pa_assert(u);
     pa_source_assert_ref(u->source);
@@ -406,10 +488,23 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
 
         if (PA_UNLIKELY(n_bytes <= 0)) {
 
-            if (polled && pa_log_ratelimit())
-                pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read! "
-                         "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
-                         "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0."));
+            if (polled)
+                PA_ONCE_BEGIN {
+                    char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle);
+                    pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read!\n"
+                             "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n"
+                             "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."),
+                           pa_strnull(dn));
+                    pa_xfree(dn);
+                } PA_ONCE_END;
+
+            break;
+        }
+
+        if (++j > 10) {
+#ifdef DEBUG_TIMING
+            pa_log_debug("Not filling up, because already too many iterations.");
+#endif
 
             break;
         }
@@ -482,7 +577,7 @@ static void update_smoother(struct userdata *u) {
 
     /* Let's update the time smoother */
 
-    if (PA_UNLIKELY((err = snd_pcm_delay(u->pcm_handle, &delay)) < 0)) {
+    if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, &delay, u->hwbuf_size, &u->source->sample_spec)) < 0)) {
         pa_log_warn("Failed to get delay: %s", snd_strerror(err));
         return;
     }
@@ -737,6 +832,25 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
     return pa_source_process_msg(o, code, data, offset, chunk);
 }
 
+/* Called from main context */
+static int source_set_state_cb(pa_source *s, pa_source_state_t new_state) {
+    pa_source_state_t old_state;
+    struct userdata *u;
+
+    pa_source_assert_ref(s);
+    pa_assert_se(u = s->userdata);
+
+    old_state = pa_source_get_state(u->source);
+
+    if (PA_SINK_IS_OPENED(old_state) && new_state == PA_SINK_SUSPENDED)
+        reserve_done(u);
+    else if (old_state == PA_SINK_SUSPENDED && PA_SINK_IS_OPENED(new_state))
+        if (reserve_init(u, u->device_name) < 0)
+            return -1;
+
+    return 0;
+}
+
 static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
     struct userdata *u = snd_mixer_elem_get_callback_private(elem);
 
@@ -1229,6 +1343,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     pa_assert(ma);
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification");
         goto fail;
@@ -1287,6 +1402,11 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     u->smoother = pa_smoother_new(DEFAULT_TSCHED_WATERMARK_USEC*2, DEFAULT_TSCHED_WATERMARK_USEC*2, TRUE, 5);
     pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());
 
+    if (reserve_init(u, pa_modargs_get_value(
+                             ma, "device_id",
+                             pa_modargs_get_value(ma, "device", DEFAULT_DEVICE))) < 0)
+        goto fail;
+
     b = use_mmap;
     d = use_tsched;
 
@@ -1385,6 +1505,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     u->source->parent.process_msg = source_process_msg;
     u->source->update_requested_latency = source_update_requested_latency_cb;
+    u->source->set_state = source_set_state_cb;
     u->source->userdata = u;
 
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
@@ -1414,6 +1535,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         pa_log_info("Time scheduling watermark is %0.2fms",
                     (double) pa_bytes_to_usec(u->tsched_watermark, &ss) / PA_USEC_PER_MSEC);
 
+    reserve_update(u);
+
     if (update_sw_params(u) < 0)
         goto fail;
 
@@ -1490,6 +1613,8 @@ static void userdata_free(struct userdata *u) {
     if (u->smoother)
         pa_smoother_free(u->smoother);
 
+    reserve_done(u);
+
     pa_xfree(u->device_name);
     pa_xfree(u);
 }
index d00a80f157412ab34a504c69da33e7e2e359b1b5..6740c06927f99ef34c85eb0c9de5fa3b882d24ec 100644 (file)
@@ -39,6 +39,7 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/atomic.h>
 #include <pulsecore/core-error.h>
+#include <pulsecore/once.h>
 
 #include "alsa-util.h"
 
@@ -1026,6 +1027,7 @@ snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, const
     pa_assert(name);
 
     snd_mixer_selem_id_set_name(sid, name);
+    snd_mixer_selem_id_set_index(sid, 0);
 
     if ((elem = snd_mixer_find_selem(mixer, sid))) {
 
@@ -1042,6 +1044,7 @@ snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, const
 
     if (fallback) {
         snd_mixer_selem_id_set_name(sid, fallback);
+        snd_mixer_selem_id_set_index(sid, 0);
 
         if ((fallback_elem = snd_mixer_find_selem(mixer, sid))) {
 
@@ -1084,7 +1087,6 @@ success:
     return elem;
 }
 
-
 int pa_alsa_find_mixer_and_elem(
         snd_pcm_t *pcm,
         snd_mixer_t **_m,
@@ -1446,9 +1448,9 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *
         cn = pa_proplist_gets(p, "alsa.card_name");
     }
 
-    if (cn && n)
-        pa_proplist_setf(p, PA_PROP_DEVICE_DESCRIPTION, "%s - %s", cn, n);
-    else if (cn)
+    if (cn && n && !strstr(cn, n) && !strstr(n, cn))
+        pa_proplist_setf(p, PA_PROP_DEVICE_DESCRIPTION, "%s, %s", cn, n);
+    else if (cn && (!n || strstr(cn, n)))
         pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, cn);
     else if (n)
         pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, n);
@@ -1572,15 +1574,70 @@ snd_pcm_sframes_t pa_alsa_safe_avail(snd_pcm_t *pcm, size_t hwbuf_size, const pa
 
     k = (size_t) n * pa_frame_size(ss);
 
-    if (k >= hwbuf_size * 3 ||
-        k >= pa_bytes_per_second(ss)*10)
-        pa_log(_("snd_pcm_avail_update() returned a value that is exceptionally large: %lu bytes (%lu ms). "
-                 "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers."),
-               (unsigned long) k, (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC));
+    if (k >= hwbuf_size * 5 ||
+        k >= pa_bytes_per_second(ss)*10) {
+
+        PA_ONCE_BEGIN {
+            char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
+            pa_log(_("snd_pcm_avail() returned a value that is exceptionally large: %lu bytes (%lu ms).\n"
+                     "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
+                   (unsigned long) k,
+                   (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC),
+                   pa_strnull(dn));
+            pa_xfree(dn);
+        } PA_ONCE_END;
+
+        /* Mhmm, let's try not to fail completely */
+        n = (snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+    }
 
     return n;
 }
 
+int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delay, size_t hwbuf_size, const pa_sample_spec *ss) {
+    ssize_t k;
+    size_t abs_k;
+    int r;
+
+    pa_assert(pcm);
+    pa_assert(delay);
+    pa_assert(hwbuf_size > 0);
+    pa_assert(ss);
+
+    /* Some ALSA driver expose weird bugs, let's inform the user about
+     * what is going on */
+
+    if ((r = snd_pcm_delay(pcm, delay)) < 0)
+        return r;
+
+    k = (ssize_t) *delay * (ssize_t) pa_frame_size(ss);
+
+    abs_k = k >= 0 ? (size_t) k : (size_t) -k;
+
+    if (abs_k >= hwbuf_size * 5 ||
+        abs_k >= pa_bytes_per_second(ss)*10) {
+
+        PA_ONCE_BEGIN {
+            char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
+            pa_log(_("snd_pcm_delay() returned a value that is exceptionally large: %li bytes (%s%lu ms).\n"
+                     "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
+                   (signed long) k,
+                   k < 0 ? "-" : "",
+                   (unsigned long) (pa_bytes_to_usec(abs_k, ss) / PA_USEC_PER_MSEC),
+                   pa_strnull(dn));
+            pa_xfree(dn);
+        } PA_ONCE_END;
+
+        /* Mhmm, let's try not to fail completely */
+        if (k < 0)
+            *delay = -(snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+        else
+            *delay = (snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+    }
+
+    return 0;
+}
+
 int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames, size_t hwbuf_size, const pa_sample_spec *ss) {
     int r;
     snd_pcm_uframes_t before;
@@ -1606,9 +1663,15 @@ int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas
         k >= hwbuf_size * 3 ||
         k >= pa_bytes_per_second(ss)*10)
 
-        pa_log(_("snd_pcm_mmap_begin() returned a value that is exceptionally large: %lu bytes (%lu ms). "
-                 "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers."),
-               (unsigned long) k, (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC));
+        PA_ONCE_BEGIN {
+            char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
+            pa_log(_("snd_pcm_mmap_begin() returned a value that is exceptionally large: %lu bytes (%lu ms).\n"
+                     "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
+                   (unsigned long) k,
+                   (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC),
+                   pa_strnull(dn));
+            pa_xfree(dn);
+        } PA_ONCE_END;
 
     return r;
 }
@@ -1630,3 +1693,39 @@ char *pa_alsa_get_driver_name(int card) {
 
     return n;
 }
+
+char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm) {
+    int card;
+
+    snd_pcm_info_t* info;
+    snd_pcm_info_alloca(&info);
+
+    if (snd_pcm_info(pcm, info) < 0)
+        return NULL;
+
+    if ((card = snd_pcm_info_get_card(info)) < 0)
+        return NULL;
+
+    return pa_alsa_get_driver_name(card);
+}
+
+char *pa_alsa_get_reserve_name(const char *device) {
+    const char *t;
+    int i;
+
+    pa_assert(device);
+
+    if ((t = strchr(device, ':')))
+        device = t+1;
+
+    if ((i = snd_card_get_index(device)) < 0) {
+        int32_t k;
+
+        if (pa_atoi(device, &k) < 0)
+            return NULL;
+
+        i = (int) k;
+    }
+
+    return pa_sprintf_malloc("Audio%i", i);
+}
index 2d0f407ee6cb8e104c1d8f08dd7b97be02480551..899532e2498d0878f7f23c2468cc4bbe2f22378f 100644 (file)
@@ -129,8 +129,13 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents);
 pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll);
 
 snd_pcm_sframes_t pa_alsa_safe_avail(snd_pcm_t *pcm, size_t hwbuf_size, const pa_sample_spec *ss);
+int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delay, size_t hwbuf_size, const pa_sample_spec *ss);
 int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames, size_t hwbuf_size, const pa_sample_spec *ss);
 
 char *pa_alsa_get_driver_name(int card);
 
+char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm);
+
+char *pa_alsa_get_reserve_name(const char *device);
+
 #endif
index e517ddcc181fc29fb7fa837821296d36a804b066..fc6b886b9d80143fbd224fc5b61b0ecd30e4aaf3 100644 (file)
@@ -30,6 +30,8 @@
 #include <pulsecore/modargs.h>
 #include <pulsecore/queue.h>
 
+#include <modules/reserve-wrap.h>
+
 #include "alsa-util.h"
 #include "alsa-sink.h"
 #include "alsa-source.h"
@@ -88,6 +90,8 @@ struct userdata {
     pa_source *source;
 
     pa_modargs *modargs;
+
+    pa_hashmap *profiles;
 };
 
 struct profile_data {
@@ -99,10 +103,11 @@ static void enumerate_cb(
         const pa_alsa_profile_info *source,
         void *userdata) {
 
-    pa_hashmap *profiles = (pa_hashmap *) userdata;
+    struct userdata *u = userdata;
     char *t, *n;
     pa_card_profile *p;
     struct profile_data *d;
+    unsigned bonus = 0;
 
     if (sink && source) {
         n = pa_sprintf_malloc("output-%s+input-%s", sink->name, source->name);
@@ -116,6 +121,20 @@ static void enumerate_cb(
         t = pa_sprintf_malloc(_("Input %s"), _(source->description));
     }
 
+    if (sink) {
+        if (pa_channel_map_equal(&sink->map, &u->core->default_channel_map))
+            bonus += 50000;
+        else if (sink->map.channels == u->core->default_channel_map.channels)
+            bonus += 40000;
+    }
+
+    if (source) {
+        if (pa_channel_map_equal(&source->map, &u->core->default_channel_map))
+            bonus += 30000;
+        else if (source->map.channels == u->core->default_channel_map.channels)
+            bonus += 20000;
+    }
+
     pa_log_info("Found output profile '%s'", t);
 
     p = pa_card_profile_new(n, t, sizeof(struct profile_data));
@@ -123,7 +142,11 @@ static void enumerate_cb(
     pa_xfree(t);
     pa_xfree(n);
 
-    p->priority = (sink ? sink->priority : 0)*100 + (source ? source->priority : 0);
+    p->priority =
+        (sink ? sink->priority : 0) * 100 +
+        (source ? source->priority : 0) +
+        bonus;
+
     p->n_sinks = !!sink;
     p->n_sources = !!source;
 
@@ -137,7 +160,7 @@ static void enumerate_cb(
     d->sink_profile = sink;
     d->source_profile = source;
 
-    pa_hashmap_put(profiles, p->name, p);
+    pa_hashmap_put(u->profiles, p->name, p);
 }
 
 static void add_disabled_profile(pa_hashmap *profiles) {
@@ -252,11 +275,14 @@ static void set_card_name(pa_card_new_data *data, pa_modargs *ma, const char *de
     pa_xfree(t);
 }
 
-int pa__init(pa_module*m) {
+int pa__init(pa_module *m) {
     pa_card_new_data data;
     pa_modargs *ma;
     int alsa_card_index;
     struct userdata *u;
+    char rname[32];
+    pa_reserve_wrapper *reserve = NULL;
+    const char *description;
 
     pa_alsa_redirect_errors_inc();
     snd_config_update_free_global();
@@ -282,6 +308,11 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
+    pa_snprintf(rname, sizeof(rname), "Audio%i", alsa_card_index);
+
+    if (!(reserve = pa_reserve_wrapper_get(m->core, rname)))
+        goto fail;
+
     pa_card_new_data_init(&data);
     data.driver = __FILE__;
     data.module = m;
@@ -289,8 +320,12 @@ int pa__init(pa_module*m) {
     pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_id);
     set_card_name(&data, ma, u->device_id);
 
-    data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    if (pa_alsa_probe_profiles(u->device_id, &m->core->default_sample_spec, enumerate_cb, data.profiles) < 0) {
+    if (reserve)
+        if ((description = pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)))
+            pa_reserve_wrapper_set_application_device_name(reserve, description);
+
+    u->profiles = data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    if (pa_alsa_probe_profiles(u->device_id, &m->core->default_sample_spec, enumerate_cb, u) < 0) {
         pa_card_new_data_done(&data);
         goto fail;
     }
@@ -314,11 +349,16 @@ int pa__init(pa_module*m) {
 
     init_profile(u);
 
+    pa_reserve_wrapper_unref(reserve);
+
     return 0;
 
 fail:
+    if (reserve)
+        pa_reserve_wrapper_unref(reserve);
 
     pa__done(m);
+
     return -1;
 }
 
index ac8344f0450d4bd37b957a2d517bb2a6aae11ebe..b2fb1db1e8d03badbac797c2ae41320810cac917 100644 (file)
@@ -653,7 +653,8 @@ static int set_conf(struct userdata *u) {
     return 0;
 }
 
-static int setup_stream_fd(struct userdata *u) {
+/* from IO thread */
+static int start_stream_fd(struct userdata *u) {
     union {
         bt_audio_msg_header_t rsp;
         struct bt_start_stream_req start_req;
@@ -662,8 +663,11 @@ static int setup_stream_fd(struct userdata *u) {
         bt_audio_error_t error;
         uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
     } msg;
+    struct pollfd *pollfd;
 
     pa_assert(u);
+    pa_assert(u->rtpoll);
+    pa_assert(!u->rtpoll_item);
     pa_assert(u->stream_fd < 0);
 
     memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
@@ -691,11 +695,53 @@ static int setup_stream_fd(struct userdata *u) {
     pa_make_fd_nonblock(u->stream_fd);
     pa_make_socket_low_delay(u->stream_fd);
 
+    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
+    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+    pollfd->fd = u->stream_fd;
+    pollfd->events = pollfd->revents = 0;
+
     return 0;
 }
 
+/* from IO thread */
+static int stop_stream_fd(struct userdata *u) {
+    union {
+        bt_audio_msg_header_t rsp;
+        struct bt_stop_stream_req start_req;
+        struct bt_stop_stream_rsp start_rsp;
+        bt_audio_error_t error;
+        uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
+    } msg;
+    int r = 0;
+
+    pa_assert(u);
+    pa_assert(u->rtpoll);
+    pa_assert(u->rtpoll_item);
+    pa_assert(u->stream_fd >= 0);
+
+    pa_rtpoll_item_free(u->rtpoll_item);
+    u->rtpoll_item = NULL;
+
+    memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
+    msg.start_req.h.type = BT_REQUEST;
+    msg.start_req.h.name = BT_STOP_STREAM;
+    msg.start_req.h.length = sizeof(msg.start_req);
+
+    if (service_send(u, &msg.start_req.h) < 0 ||
+        service_expect(u, &msg.rsp, sizeof(msg), BT_STOP_STREAM, sizeof(msg.start_rsp)) < 0)
+        r = -1;
+
+    pa_close(u->stream_fd);
+    u->stream_fd = -1;
+
+    return r;
+}
+
 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;
+    pa_bool_t failed = FALSE;
+    int r;
+
     pa_assert(u->sink == PA_SINK(o));
 
     pa_log_debug("got message: %d", code);
@@ -707,13 +753,27 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
 
                 case PA_SINK_SUSPENDED:
                     pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
+
+                    /* Stop the device if the source is suspended as well */
+                    if (!u->source || u->source->state == PA_SOURCE_SUSPENDED)
+                        /* We deliberately ignore whether stopping
+                         * actually worked. Since the stream_fd is
+                         * closed it doesn't really matter */
+                        stop_stream_fd(u);
+
                     break;
 
                 case PA_SINK_IDLE:
                 case PA_SINK_RUNNING:
-                    if (!PA_SINK_IS_OPENED(u->sink->thread_info.state))
-                        u->started_at = pa_rtclock_usec();
+                    if (u->sink->thread_info.state != PA_SINK_SUSPENDED)
+                        break;
+
+                    /* Resume the device if the source was suspended as well */
+                    if (!u->source || u->source->state == PA_SOURCE_SUSPENDED)
+                        if (start_stream_fd(u) < 0)
+                            failed = TRUE;
 
+                    u->started_at = pa_rtclock_usec();
                     break;
 
                 case PA_SINK_UNLINKED:
@@ -727,14 +787,17 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
             *((pa_usec_t*) data) = 0;
             return 0;
         }
-
     }
 
-    return pa_sink_process_msg(o, code, data, offset, chunk);
+    r = pa_sink_process_msg(o, code, data, offset, chunk);
+
+    return (r < 0 || !failed) ? r : -1;
 }
 
 static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SOURCE(o)->userdata;
+    pa_bool_t failed = FALSE;
+    int r;
 
     pa_assert(u->source == PA_SOURCE(o));
 
@@ -746,13 +809,26 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
             switch ((pa_source_state_t) PA_PTR_TO_UINT(data)) {
 
                 case PA_SOURCE_SUSPENDED:
+                    pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state));
+
+                    /* Stop the device if the sink is suspended as well */
+                    if (!u->sink || u->sink->state == PA_SINK_SUSPENDED)
+                        stop_stream_fd(u);
+
                     pa_smoother_pause(u->read_smoother, pa_rtclock_usec());
                     break;
 
                 case PA_SOURCE_IDLE:
                 case PA_SOURCE_RUNNING:
-                    if (u->source->thread_info.state == PA_SOURCE_SUSPENDED)
-                        pa_smoother_resume(u->read_smoother, pa_rtclock_usec());
+                    if (u->source->thread_info.state != PA_SOURCE_SUSPENDED)
+                        break;
+
+                    /* Resume the device if the sink was suspended as well */
+                    if (!u->sink || u->sink->thread_info.state == PA_SINK_SUSPENDED)
+                        if (start_stream_fd(u) < 0)
+                            failed = TRUE;
+
+                    pa_smoother_resume(u->read_smoother, pa_rtclock_usec());
                     break;
 
                 case PA_SOURCE_UNLINKED:
@@ -769,7 +845,9 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
 
     }
 
-    return pa_source_process_msg(o, code, data, offset, chunk);
+    r = pa_source_process_msg(o, code, data, offset, chunk);
+
+    return (r < 0 || !failed) ? r : -1;
 }
 
 static int hsp_process_render(struct userdata *u) {
@@ -994,6 +1072,9 @@ static void thread_func(void *userdata) {
     if (u->core->realtime_scheduling)
         pa_make_realtime(u->core->realtime_priority);
 
+    if (start_stream_fd(u) < 0)
+        goto fail;
+
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);
 
@@ -1002,12 +1083,13 @@ static void thread_func(void *userdata) {
     for (;;) {
         struct pollfd *pollfd;
         int ret;
+        pa_bool_t disable_timer = TRUE;
 
-        pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+        pollfd = u->rtpoll_item ? pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL) : NULL;
 
         if (u->source && PA_SOURCE_IS_LINKED(u->source->thread_info.state)) {
 
-            if (pollfd->revents & POLLIN) {
+            if (pollfd && (pollfd->revents & POLLIN)) {
 
                 if (hsp_process_push(u) < 0)
                     goto fail;
@@ -1022,57 +1104,63 @@ static void thread_func(void *userdata) {
             if (u->sink->thread_info.rewind_requested)
                 pa_sink_process_rewind(u->sink, 0);
 
-            if (pollfd->revents & POLLOUT)
-                writable = TRUE;
+            if (pollfd) {
+                if (pollfd->revents & POLLOUT)
+                    writable = TRUE;
 
-            if ((!u->source || !PA_SOURCE_IS_LINKED(u->source->thread_info.state)) && !do_write && writable) {
-                pa_usec_t time_passed;
-                uint64_t should_have_written;
+                if ((!u->source || !PA_SOURCE_IS_LINKED(u->source->thread_info.state)) && !do_write && writable) {
+                    pa_usec_t time_passed;
+                    uint64_t should_have_written;
 
-                /* Hmm, there is no input stream we could synchronize
-                 * to. So let's do things by time */
+                    /* Hmm, there is no input stream we could synchronize
+                     * to. So let's do things by time */
 
-                time_passed = pa_rtclock_usec() - u->started_at;
-                should_have_written = pa_usec_to_bytes(time_passed, &u->sink->sample_spec);
+                    time_passed = pa_rtclock_usec() - u->started_at;
+                    should_have_written = pa_usec_to_bytes(time_passed, &u->sink->sample_spec);
 
-                do_write = u->write_index <= should_have_written ;
+                    do_write = u->write_index <= should_have_written ;
 /*                 pa_log_debug("Time has come: %s", pa_yes_no(do_write)); */
-            }
+                }
 
-            if (writable && do_write) {
+                if (writable && do_write) {
 
-                if (u->profile == PROFILE_A2DP) {
-                    if (a2dp_process_render(u) < 0)
-                        goto fail;
-                } else {
-                    if (hsp_process_render(u) < 0)
-                        goto fail;
-                }
+                    if (u->profile == PROFILE_A2DP) {
+                        if (a2dp_process_render(u) < 0)
+                            goto fail;
+                    } else {
+                        if (hsp_process_render(u) < 0)
+                            goto fail;
+                    }
 
-                do_write = FALSE;
-                writable = FALSE;
-            }
+                    do_write = FALSE;
+                    writable = FALSE;
+                }
 
-            if ((!u->source || !PA_SOURCE_IS_LINKED(u->source->thread_info.state)) && !do_write) {
-                pa_usec_t time_passed, next_write_at, sleep_for;
+                if ((!u->source || !PA_SOURCE_IS_LINKED(u->source->thread_info.state)) && !do_write) {
+                    pa_usec_t time_passed, next_write_at, sleep_for;
 
-                /* Hmm, there is no input stream we could synchronize
-                 * to. So let's estimate when we need to wake up the latest */
+                    /* Hmm, there is no input stream we could synchronize
+                     * to. So let's estimate when we need to wake up the latest */
 
-                time_passed = pa_rtclock_usec() - u->started_at;
-                next_write_at = pa_bytes_to_usec(u->write_index, &u->sink->sample_spec);
-                sleep_for = time_passed < next_write_at ? next_write_at - time_passed : 0;
+                    time_passed = pa_rtclock_usec() - u->started_at;
+                    next_write_at = pa_bytes_to_usec(u->write_index, &u->sink->sample_spec);
+                    sleep_for = time_passed < next_write_at ? next_write_at - time_passed : 0;
 
 /*                 pa_log("Sleeping for %lu; time passed %lu, next write at %lu", (unsigned long) sleep_for, (unsigned long) time_passed, (unsigned long)next_write_at); */
 
-                pa_rtpoll_set_timer_relative(u->rtpoll, sleep_for);
+                    pa_rtpoll_set_timer_relative(u->rtpoll, sleep_for);
+                    disable_timer = FALSE;
+                }
             }
-        } else
+        }
+
+        if (disable_timer)
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
-        pollfd->events = (short) (((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state) && !writable) ? POLLOUT : 0) |
-                                  (u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state) ? POLLIN : 0));
+        if (pollfd)
+            pollfd->events = (short) (((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state) && !writable) ? POLLOUT : 0) |
+                                      (u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state) ? POLLIN : 0));
 
         if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
             goto fail;
@@ -1080,9 +1168,9 @@ static void thread_func(void *userdata) {
         if (ret == 0)
             goto finish;
 
-        pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+        pollfd = u->rtpoll_item ? pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL) : NULL;
 
-        if (pollfd->revents & ~(POLLOUT|POLLIN)) {
+        if (pollfd && (pollfd->revents & ~(POLLOUT|POLLIN))) {
             pa_log_error("FD error.");
             goto fail;
         }
@@ -1463,9 +1551,6 @@ static int setup_bt(struct userdata *u) {
         return 0;
     }
 
-    if (setup_stream_fd(u) < 0)
-        return -1;
-
     pa_log_debug("Got the stream socket");
 
     return 0;
@@ -1533,8 +1618,6 @@ static void stop_thread(struct userdata *u) {
 }
 
 static int start_thread(struct userdata *u) {
-    struct pollfd *pollfd;
-
     pa_assert(u);
     pa_assert(!u->thread);
     pa_assert(!u->rtpoll);
@@ -1549,11 +1632,6 @@ static int start_thread(struct userdata *u) {
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
 
-    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
-    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
-    pollfd->fd = u->stream_fd;
-    pollfd->events = pollfd->revents = 0;
-
     if (!(u->thread = pa_thread_new(thread_func, u))) {
         pa_log_error("Failed to create IO thread");
         stop_thread(u);
index 90bfbe7df440303f8251add050549054797b6ddd..99111868b503d9b485f9b954c4f652b12cf8eadd 100644 (file)
@@ -195,6 +195,8 @@ static pa_hook_result_t process(struct userdata *u, pa_proplist *p) {
 
     time(&now);
 
+    pa_log_debug("Looking for .desktop file for %s", pn);
+
     if ((r = pa_hashmap_get(u->cache, pn))) {
         if (now-r->timestamp > STAT_INTERVAL) {
             r->timestamp = now;
index 7f1ef24c04f8ac23605141bb4de5d812a92407fb..6ed4f1413e2412efe05a0db7477afb8d4343f001 100644 (file)
@@ -1052,8 +1052,9 @@ int pa__init(pa_module*m) {
 
     slaves = pa_modargs_get_value(ma, "slaves", NULL);
     u->automatic = !slaves;
-    ss = m->core->default_sample_spec;
 
+    ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if ((pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0)) {
         pa_log("Invalid sample specification.");
         goto fail;
index b448e84e238d0f848982f7ff3ad22f0230b3a5f8..1739f46a815906b1fb7f78a71336704721f771e3 100644 (file)
@@ -329,12 +329,18 @@ int pa__init(pa_module*m) {
     if (!channels)
         channels = m->core->default_sample_spec.channels;
 
-    if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) {
+    if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
+        channels <= 0 ||
+        channels > PA_CHANNELS_MAX) {
         pa_log("Failed to parse channels= argument.");
         goto fail;
     }
 
-    pa_channel_map_init_extend(&map, channels, PA_CHANNEL_MAP_ALSA);
+    if (channels == m->core->default_channel_map.channels)
+        map = m->core->default_channel_map;
+    else
+        pa_channel_map_init_extend(&map, channels, PA_CHANNEL_MAP_ALSA);
+
     if (pa_modargs_get_channel_map(ma, NULL, &map) < 0 || map.channels != channels) {
         pa_log("Failed to parse channel_map= argument.");
         goto fail;
index 0c7ee535143209da60c5a52a589f9da411834220..38b63751a6e84c67d12c1e4c71829228eed56f38 100644 (file)
@@ -296,12 +296,18 @@ int pa__init(pa_module*m) {
     if (!channels)
         channels = m->core->default_sample_spec.channels;
 
-    if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) {
+    if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
+        channels <= 0 ||
+        channels >= PA_CHANNELS_MAX) {
         pa_log("failed to parse channels= argument.");
         goto fail;
     }
 
-    pa_channel_map_init_extend(&map, channels, PA_CHANNEL_MAP_ALSA);
+    if (channels == m->core->default_channel_map.channels)
+        map = m->core->default_channel_map;
+    else
+        pa_channel_map_init_extend(&map, channels, PA_CHANNEL_MAP_ALSA);
+
     if (pa_modargs_get_channel_map(ma, NULL, &map) < 0 || map.channels != channels) {
         pa_log("failed to parse channel_map= argument.");
         goto fail;
index 570f8be44ad7dc9dc3a2558164e860979b6a8843..e18da5fd180022d3f9c34accf85395c0ee26bf46 100644 (file)
@@ -262,6 +262,7 @@ int pa__init(pa_module*m) {
     }
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("Invalid sample format specification or channel map");
         goto fail;
index 7dd4409892514ef0f451e1b37f8d6d10a47d2049..f3b0e8b0e6297d819c737e60414931f7fd741015 100644 (file)
@@ -234,6 +234,7 @@ int pa__init(pa_module*m) {
     }
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("Invalid sample format specification or channel map");
         goto fail;
index 975090c2da5308fb242ddf5ec769e4e104dc1453..a42c53c365f555da12b3376d90c71730a965a51c 100644 (file)
@@ -221,6 +221,7 @@ int pa__init(pa_module*m) {
     }
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("invalid sample format specification or channel map");
         goto fail;
index 3706d921198f0ef112675c224d4dfce10d53f5bb..df3931512a48346195698748540a7ad16c901863 100644 (file)
@@ -53,7 +53,7 @@
 #include "module-raop-discover-symdef.h"
 
 PA_MODULE_AUTHOR("Colin Guthrie");
-PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Discovery of Airtunes");
+PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Discovery of RAOP devices");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(TRUE);
 
@@ -172,9 +172,9 @@ static void resolver_cb(
         }
 
         if (device)
-            dname = pa_sprintf_malloc("airtunes.%s.%s", host_name, device);
+            dname = pa_sprintf_malloc("raop.%s.%s", host_name, device);
         else
-            dname = pa_sprintf_malloc("airtunes.%s", host_name);
+            dname = pa_sprintf_malloc("raop.%s", host_name);
 
         if (!(vname = pa_namereg_make_valid_name(dname))) {
             pa_log("Cannot construct valid device name from '%s'.", dname);
index 1784b2ccb83b0e8b03ce2858e58e98bcff5fe6b2..da338f5d736fb6357dcdbce085dbb2a365588f28 100644 (file)
@@ -67,7 +67,7 @@
 #include "raop_client.h"
 
 PA_MODULE_AUTHOR("Colin Guthrie");
-PA_MODULE_DESCRIPTION("RAOP Sink (Apple Airtunes)");
+PA_MODULE_DESCRIPTION("RAOP Sink");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(FALSE);
 PA_MODULE_USAGE(
@@ -77,7 +77,7 @@ PA_MODULE_USAGE(
         "channels=<number of channels> "
         "rate=<sample rate>");
 
-#define DEFAULT_SINK_NAME "airtunes"
+#define DEFAULT_SINK_NAME "raop"
 
 struct userdata {
     pa_core *core;
@@ -564,7 +564,7 @@ int pa__init(pa_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_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, server);
-    pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Airtunes sink '%s'", server);
+    pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "RAOP sink '%s'", server);
 
     u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY|PA_SINK_NETWORK);
     pa_sink_new_data_done(&data);
index 26da2575a80bd07a72e6f1ce6c4c928be01b44db..63ae740aba6ebb92c83c0488a95dd72a030ee1b3 100644 (file)
@@ -1717,6 +1717,7 @@ int pa__init(pa_module*m) {
     }
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("Invalid sample format specification");
         goto fail;
index 9a867cb51b7ca61cedac018321afeccb8f355791..5123ead897185ae1b6f0ccb42e13ec27945f51c5 100644 (file)
@@ -162,7 +162,7 @@ static void resolver_cb(
         pa_module *m;
 
         ss = u->core->default_sample_spec;
-        pa_channel_map_init_extend(&cm, ss.channels, PA_CHANNEL_MAP_DEFAULT);
+        cm = u->core->default_channel_map;
 
         for (l = txt; l; l = l->next) {
             char *key, *value;
index eac0c8e635a27a676ba4b2cd2dac7427113610b9..54d1679f74f9e90f767a988ecfc8478cac658b9a 100644 (file)
@@ -1185,6 +1185,7 @@ int pa__init(pa_module*m) {
     mode = (playback && record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
 
     ss = m->core->default_sample_spec;
+    map = m->core->default_channel_map;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {
         pa_log("Failed to parse sample specification or channel map");
         goto fail;
diff --git a/src/modules/reserve-wrap.c b/src/modules/reserve-wrap.c
new file mode 100644 (file)
index 0000000..709cb06
--- /dev/null
@@ -0,0 +1,168 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
+
+#include <pulsecore/core-error.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/shared.h>
+
+#include <modules/dbus-util.h>
+
+#include "reserve.h"
+#include "reserve-wrap.h"
+
+struct pa_reserve_wrapper {
+    PA_REFCNT_DECLARE;
+    pa_core *core;
+    pa_dbus_connection *connection;
+    pa_hook hook;
+    struct rd_device *device;
+    char *shared_name;
+};
+
+static void reserve_wrapper_free(pa_reserve_wrapper *r) {
+    pa_assert(r);
+
+    if (r->device)
+        rd_release(r->device);
+
+    pa_hook_done(&r->hook);
+
+    if (r->connection)
+        pa_dbus_connection_unref(r->connection);
+
+    if (r->shared_name) {
+        pa_assert_se(pa_shared_remove(r->core, r->shared_name) >= 0);
+        pa_xfree(r->shared_name);
+    }
+
+    pa_xfree(r);
+}
+
+static int request_cb(rd_device *d, int forced) {
+    pa_reserve_wrapper *r;
+    int k;
+
+    pa_assert(d);
+    pa_assert_se(r = rd_get_userdata(d));
+    pa_assert(PA_REFCNT_VALUE(r) >= 1);
+
+    PA_REFCNT_INC(r);
+
+    k = pa_hook_fire(&r->hook, PA_INT_TO_PTR(forced));
+    pa_log_debug("Device unlock has been requested and %s.", k < 0 ? "failed" : "succeeded");
+
+    pa_reserve_wrapper_unref(r);
+
+    return k < 0 ? -1 : 1;
+}
+
+pa_reserve_wrapper* pa_reserve_wrapper_get(pa_core *c, const char *device_name) {
+    pa_reserve_wrapper *r;
+    DBusError error;
+    int k;
+    char *t;
+
+    dbus_error_init(&error);
+
+    pa_assert(c);
+    pa_assert(device_name);
+
+    t = pa_sprintf_malloc("reserve-wrapper@%s", device_name);
+
+    if ((r = pa_shared_get(c, t))) {
+        pa_xfree(t);
+
+        pa_assert(PA_REFCNT_VALUE(r) >= 1);
+        PA_REFCNT_INC(r);
+
+        return r;
+    }
+
+    r = pa_xnew0(pa_reserve_wrapper, 1);
+    PA_REFCNT_INIT(r);
+    r->core = c;
+    pa_hook_init(&r->hook, r);
+    r->shared_name = t;
+
+    pa_assert_se(pa_shared_set(c, r->shared_name, r) >= 0);
+
+    if (!(r->connection = pa_dbus_bus_get(c, DBUS_BUS_SESSION, &error)) || dbus_error_is_set(&error)) {
+        pa_log_error("Unable to contact D-Bus session bus: %s: %s", error.name, error.message);
+        goto fail;
+    }
+
+    if ((k = rd_acquire(
+                 &r->device,
+                 pa_dbus_connection_get(r->connection),
+                 device_name,
+                 _("PulseAudio Sound Server"),
+                 0,
+                 request_cb,
+                 NULL)) < 0) {
+
+        pa_log_error("Failed to acquire reservation lock on device '%s': %s", device_name, pa_cstrerror(-k));
+        goto fail;
+    }
+
+    pa_log_debug("Successfully acquired reservation lock on device '%s'", device_name);
+
+    rd_set_userdata(r->device, r);
+
+    return r;
+
+fail:
+    dbus_error_free(&error);
+
+    reserve_wrapper_free(r);
+
+    return NULL;
+}
+
+void pa_reserve_wrapper_unref(pa_reserve_wrapper *r) {
+    pa_assert(r);
+    pa_assert(PA_REFCNT_VALUE(r) >= 1);
+
+    if (PA_REFCNT_DEC(r) > 0)
+        return;
+
+    reserve_wrapper_free(r);
+}
+
+pa_hook* pa_reserve_wrapper_hook(pa_reserve_wrapper *r) {
+    pa_assert(r);
+    pa_assert(PA_REFCNT_VALUE(r) >= 1);
+
+    return &r->hook;
+}
+
+void pa_reserve_wrapper_set_application_device_name(pa_reserve_wrapper *r, const char *name) {
+    pa_assert(r);
+    pa_assert(PA_REFCNT_VALUE(r) >= 1);
+
+    rd_set_application_device_name(r->device, name);
+}
diff --git a/src/modules/reserve-wrap.h b/src/modules/reserve-wrap.h
new file mode 100644 (file)
index 0000000..4625fe6
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef fooreservewraphfoo
+#define fooreservewraphfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <pulsecore/core.h>
+#include <pulsecore/hook-list.h>
+
+typedef struct pa_reserve_wrapper pa_reserve_wrapper;
+
+pa_reserve_wrapper* pa_reserve_wrapper_get(pa_core *c, const char *device_name);
+
+void pa_reserve_wrapper_unref(pa_reserve_wrapper *r);
+
+pa_hook* pa_reserve_wrapper_hook(pa_reserve_wrapper *r);
+
+void pa_reserve_wrapper_set_application_device_name(pa_reserve_wrapper *r, const char *name);
+
+#endif
diff --git a/src/modules/reserve.c b/src/modules/reserve.c
new file mode 100644 (file)
index 0000000..9a9591d
--- /dev/null
@@ -0,0 +1,635 @@
+/***
+  Copyright 2009 Lennart Poettering
+
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation files
+  (the "Software"), to deal in the Software without restriction,
+  including without limitation the rights to use, copy, modify, merge,
+  publish, distribute, sublicense, and/or sell copies of the Software,
+  and to permit persons to whom the Software is furnished to do so,
+  subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+***/
+
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "reserve.h"
+
+struct rd_device {
+       int ref;
+
+       char *device_name;
+       char *application_name;
+       char *application_device_name;
+       char *service_name;
+       char *object_path;
+       int32_t priority;
+
+       DBusConnection *connection;
+
+       int owning:1;
+       int registered:1;
+       int filtering:1;
+       int gave_up:1;
+
+       rd_request_cb_t request_cb;
+       void *userdata;
+};
+
+
+#define SERVICE_PREFIX "org.freedesktop.ReserveDevice1."
+#define OBJECT_PREFIX "/org/freedesktop/ReserveDevice1/"
+
+static const char introspection[] =
+       DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
+       "<node>"
+       " <!-- If you are looking for documentation make sure to check out\n"
+       "      http://git.0pointer.de/?p=reserve.git;a=blob;f=reserve.txt -->\n"
+       " <interface name=\"org.freedesktop.ReserveDevice1\">"
+       "  <method name=\"RequestRelease\">"
+       "   <arg name=\"priority\" type=\"i\" direction=\"in\"/>"
+       "   <arg name=\"result\" type=\"b\" direction=\"out\"/>"
+       "  </method>"
+       "  <property name=\"Priority\" type=\"i\" access=\"read\"/>"
+       "  <property name=\"ApplicationName\" type=\"s\" access=\"read\"/>"
+       "  <property name=\"ApplicationDeviceName\" type=\"s\" access=\"read\"/>"
+       " </interface>"
+       " <interface name=\"org.freedesktop.DBus.Properties\">"
+       "  <method name=\"Get\">"
+       "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>"
+       "   <arg name=\"property\" direction=\"in\" type=\"s\"/>"
+       "   <arg name=\"value\" direction=\"out\" type=\"v\"/>"
+       "  </method>"
+       " </interface>"
+       " <interface name=\"org.freedesktop.DBus.Introspectable\">"
+       "  <method name=\"Introspect\">"
+       "   <arg name=\"data\" type=\"s\" direction=\"out\"/>"
+       "  </method>"
+       " </interface>"
+       "</node>";
+
+static dbus_bool_t add_variant(
+       DBusMessage *m,
+       int type,
+       const void *data) {
+
+       DBusMessageIter iter, sub;
+       char t[2];
+
+       t[0] = (char) type;
+       t[1] = 0;
+
+       dbus_message_iter_init_append(m, &iter);
+
+       if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, t, &sub))
+               return FALSE;
+
+       if (!dbus_message_iter_append_basic(&sub, type, data))
+               return FALSE;
+
+       if (!dbus_message_iter_close_container(&iter, &sub))
+               return FALSE;
+
+       return TRUE;
+}
+
+static DBusHandlerResult object_handler(
+       DBusConnection *c,
+       DBusMessage *m,
+       void *userdata) {
+
+       rd_device *d;
+       DBusError error;
+       DBusMessage *reply = NULL;
+
+       dbus_error_init(&error);
+
+       d = userdata;
+       assert(d->ref >= 1);
+
+       if (dbus_message_is_method_call(
+                   m,
+                   "org.freedesktop.ReserveDevice1",
+                   "RequestRelease")) {
+
+               int32_t priority;
+               dbus_bool_t ret;
+
+               if (!dbus_message_get_args(
+                           m,
+                           &error,
+                           DBUS_TYPE_INT32, &priority,
+                           DBUS_TYPE_INVALID))
+                       goto invalid;
+
+               ret = FALSE;
+
+               if (priority > d->priority && d->request_cb) {
+                       d->ref++;
+
+                       if (d->request_cb(d, 0) > 0) {
+                               ret = TRUE;
+                               d->gave_up = 1;
+                       }
+
+                       rd_release(d);
+               }
+
+               if (!(reply = dbus_message_new_method_return(m)))
+                       goto oom;
+
+               if (!dbus_message_append_args(
+                           reply,
+                           DBUS_TYPE_BOOLEAN, &ret,
+                           DBUS_TYPE_INVALID))
+                       goto oom;
+
+               if (!dbus_connection_send(c, reply, NULL))
+                       goto oom;
+
+               dbus_message_unref(reply);
+
+               return DBUS_HANDLER_RESULT_HANDLED;
+
+       } else if (dbus_message_is_method_call(
+                          m,
+                          "org.freedesktop.DBus.Properties",
+                          "Get")) {
+
+               const char *interface, *property;
+
+               if (!dbus_message_get_args(
+                           m,
+                           &error,
+                           DBUS_TYPE_STRING, &interface,
+                           DBUS_TYPE_STRING, &property,
+                           DBUS_TYPE_INVALID))
+                       goto invalid;
+
+               if (strcmp(interface, "org.freedesktop.ReserveDevice1") == 0) {
+                       const char *empty = "";
+
+                       if (strcmp(property, "ApplicationName") == 0 && d->application_name) {
+                               if (!(reply = dbus_message_new_method_return(m)))
+                                       goto oom;
+
+                               if (!add_variant(
+                                           reply,
+                                           DBUS_TYPE_STRING,
+                                           d->application_name ? (const char**) &d->application_name : &empty))
+                                       goto oom;
+
+                       } else if (strcmp(property, "ApplicationDeviceName") == 0) {
+                               if (!(reply = dbus_message_new_method_return(m)))
+                                       goto oom;
+
+                               if (!add_variant(
+                                           reply,
+                                           DBUS_TYPE_STRING,
+                                           d->application_device_name ? (const char**) &d->application_device_name : &empty))
+                                       goto oom;
+
+                       } else if (strcmp(property, "Priority") == 0) {
+                               if (!(reply = dbus_message_new_method_return(m)))
+                                       goto oom;
+
+                               if (!add_variant(
+                                           reply,
+                                           DBUS_TYPE_INT32,
+                                           &d->priority))
+                                       goto oom;
+                       } else {
+                               if (!(reply = dbus_message_new_error_printf(
+                                             m,
+                                             DBUS_ERROR_UNKNOWN_METHOD,
+                                             "Unknown property %s",
+                                             property)))
+                                       goto oom;
+                       }
+
+                       if (!dbus_connection_send(c, reply, NULL))
+                               goto oom;
+
+                       dbus_message_unref(reply);
+
+                       return DBUS_HANDLER_RESULT_HANDLED;
+               }
+
+       } else if (dbus_message_is_method_call(
+                          m,
+                          "org.freedesktop.DBus.Introspectable",
+                          "Introspect")) {
+                           const char *i = introspection;
+
+               if (!(reply = dbus_message_new_method_return(m)))
+                       goto oom;
+
+               if (!dbus_message_append_args(
+                           reply,
+                           DBUS_TYPE_STRING,
+                           &i,
+                           DBUS_TYPE_INVALID))
+                       goto oom;
+
+               if (!dbus_connection_send(c, reply, NULL))
+                       goto oom;
+
+               dbus_message_unref(reply);
+
+               return DBUS_HANDLER_RESULT_HANDLED;
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+invalid:
+       if (reply)
+               dbus_message_unref(reply);
+
+       if (!(reply = dbus_message_new_error(
+                     m,
+                     DBUS_ERROR_INVALID_ARGS,
+                     "Invalid arguments")))
+               goto oom;
+
+       if (!dbus_connection_send(c, reply, NULL))
+               goto oom;
+
+       dbus_message_unref(reply);
+
+       dbus_error_free(&error);
+
+       return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+       if (reply)
+               dbus_message_unref(reply);
+
+       dbus_error_free(&error);
+
+       return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+static DBusHandlerResult filter_handler(
+       DBusConnection *c,
+       DBusMessage *m,
+       void *userdata) {
+
+       DBusMessage *reply;
+       rd_device *d;
+       DBusError error;
+
+       dbus_error_init(&error);
+
+       d = userdata;
+
+       if (dbus_message_is_signal(m, "org.freedesktop.DBus", "NameLost")) {
+               const char *name;
+
+               if (!dbus_message_get_args(
+                           m,
+                           &error,
+                           DBUS_TYPE_STRING, &name,
+                           DBUS_TYPE_INVALID))
+                       goto invalid;
+
+               if (strcmp(name, d->service_name) == 0 && d->owning) {
+                       d->owning = 0;
+
+                       if (!d->gave_up)  {
+                               d->ref++;
+
+                               if (d->request_cb)
+                                       d->request_cb(d, 1);
+                               d->gave_up = 1;
+
+                               rd_release(d);
+                       }
+
+                       return DBUS_HANDLER_RESULT_HANDLED;
+               }
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+invalid:
+       if (!(reply = dbus_message_new_error(
+                     m,
+                     DBUS_ERROR_INVALID_ARGS,
+                     "Invalid arguments")))
+               goto oom;
+
+       if (!dbus_connection_send(c, reply, NULL))
+               goto oom;
+
+       dbus_message_unref(reply);
+
+       dbus_error_free(&error);
+
+       return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+       if (reply)
+               dbus_message_unref(reply);
+
+       dbus_error_free(&error);
+
+       return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+
+static const struct DBusObjectPathVTable vtable ={
+       .message_function = object_handler
+};
+
+int rd_acquire(
+       rd_device **_d,
+       DBusConnection *connection,
+       const char *device_name,
+       const char *application_name,
+       int32_t priority,
+       rd_request_cb_t request_cb,
+       DBusError *error) {
+
+       rd_device *d = NULL;
+       int r, k;
+       DBusError _error;
+       DBusMessage *m = NULL, *reply = NULL;
+       dbus_bool_t good;
+
+       if (!error)
+               error = &_error;
+
+       dbus_error_init(error);
+
+       if (!_d)
+               return -EINVAL;
+
+       if (!connection)
+               return -EINVAL;
+
+       if (!device_name)
+               return -EINVAL;
+
+       if (!request_cb && priority != INT32_MAX)
+               return -EINVAL;
+
+       if (!(d = calloc(sizeof(rd_device), 1)))
+               return -ENOMEM;
+
+       d->ref = 1;
+
+       if (!(d->device_name = strdup(device_name))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       if (!(d->application_name = strdup(application_name))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       d->priority = priority;
+       d->connection = dbus_connection_ref(connection);
+       d->request_cb = request_cb;
+
+       if (!(d->service_name = malloc(sizeof(SERVICE_PREFIX) + strlen(device_name)))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+       sprintf(d->service_name, SERVICE_PREFIX "%s", d->device_name);
+
+       if (!(d->object_path = malloc(sizeof(OBJECT_PREFIX) + strlen(device_name)))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+       sprintf(d->object_path, OBJECT_PREFIX "%s", d->device_name);
+
+       if ((k = dbus_bus_request_name(
+                    d->connection,
+                    d->service_name,
+                    DBUS_NAME_FLAG_DO_NOT_QUEUE|
+                    (priority < INT32_MAX ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT : 0),
+                    error)) < 0) {
+               r = -EIO;
+               goto fail;
+       }
+
+       if (k == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+               goto success;
+
+       if (k != DBUS_REQUEST_NAME_REPLY_EXISTS) {
+               r = -EIO;
+               goto fail;
+       }
+
+       if (priority <= INT32_MIN) {
+               r = -EBUSY;
+               goto fail;
+       }
+
+       if (!(m = dbus_message_new_method_call(
+                     d->service_name,
+                     d->object_path,
+                     "org.freedesktop.ReserveDevice1",
+                     "RequestRelease"))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       if (!dbus_message_append_args(
+                   m,
+                   DBUS_TYPE_INT32, &d->priority,
+                   DBUS_TYPE_INVALID)) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       if (!(reply = dbus_connection_send_with_reply_and_block(
+                     d->connection,
+                     m,
+                     5000, /* 5s */
+                     error))) {
+
+               if (dbus_error_has_name(error, DBUS_ERROR_TIMED_OUT) ||
+                   dbus_error_has_name(error, DBUS_ERROR_UNKNOWN_METHOD) ||
+                   dbus_error_has_name(error, DBUS_ERROR_NO_REPLY)) {
+                       /* This must be treated as denied. */
+                       r = -EBUSY;
+                       goto fail;
+               }
+
+               r = -EIO;
+               goto fail;
+       }
+
+       if (!dbus_message_get_args(
+                   reply,
+                   error,
+                   DBUS_TYPE_BOOLEAN, &good,
+                   DBUS_TYPE_INVALID)) {
+               r = -EIO;
+               goto fail;
+       }
+
+       if (!good) {
+               r = -EBUSY;
+               goto fail;
+       }
+
+       if ((k = dbus_bus_request_name(
+                    d->connection,
+                    d->service_name,
+                    DBUS_NAME_FLAG_DO_NOT_QUEUE|
+                    (priority < INT32_MAX ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT : 0)|
+                    DBUS_NAME_FLAG_REPLACE_EXISTING,
+                    error)) < 0) {
+               r = -EIO;
+               goto fail;
+       }
+
+       if (k != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+               r = -EIO;
+               goto fail;
+       }
+
+success:
+       d->owning = 1;
+
+       if (!(dbus_connection_register_object_path(
+                     d->connection,
+                     d->object_path,
+                     &vtable,
+                     d))) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       d->registered = 1;
+
+       if (!dbus_connection_add_filter(
+                   d->connection,
+                   filter_handler,
+                   d,
+                   NULL)) {
+               r = -ENOMEM;
+               goto fail;
+       }
+
+       d->filtering = 1;
+
+       *_d = d;
+       return 0;
+
+fail:
+       if (m)
+               dbus_message_unref(m);
+
+       if (reply)
+               dbus_message_unref(reply);
+
+       if (&_error == error)
+               dbus_error_free(&_error);
+
+       if (d)
+               rd_release(d);
+
+       return r;
+}
+
+void rd_release(
+       rd_device *d) {
+
+       if (!d)
+               return;
+
+       assert(d->ref > 0);
+
+       if (--d->ref)
+               return;
+
+
+       if (d->filtering)
+               dbus_connection_remove_filter(
+                       d->connection,
+                       filter_handler,
+                       d);
+
+       if (d->registered)
+               dbus_connection_unregister_object_path(
+                       d->connection,
+                       d->object_path);
+
+       if (d->owning) {
+               DBusError error;
+               dbus_error_init(&error);
+
+               dbus_bus_release_name(
+                       d->connection,
+                       d->service_name,
+                       &error);
+
+               dbus_error_free(&error);
+       }
+
+       free(d->device_name);
+       free(d->application_name);
+       free(d->application_device_name);
+       free(d->service_name);
+       free(d->object_path);
+
+       if (d->connection)
+               dbus_connection_unref(d->connection);
+
+       free(d);
+}
+
+int rd_set_application_device_name(rd_device *d, const char *n) {
+       char *t;
+
+       if (!d)
+               return -EINVAL;
+
+       assert(d->ref > 0);
+
+       if (!(t = strdup(n)))
+               return -ENOMEM;
+
+       free(d->application_device_name);
+       d->application_device_name = t;
+       return 0;
+}
+
+void rd_set_userdata(rd_device *d, void *userdata) {
+
+       if (!d)
+               return;
+
+       assert(d->ref > 0);
+       d->userdata = userdata;
+}
+
+void* rd_get_userdata(rd_device *d) {
+
+       if (!d)
+               return NULL;
+
+       assert(d->ref > 0);
+
+       return d->userdata;
+}
diff --git a/src/modules/reserve.h b/src/modules/reserve.h
new file mode 100644 (file)
index 0000000..ceb1ad1
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef fooreservehfoo
+#define fooreservehfoo
+
+/***
+  Copyright 2009 Lennart Poettering
+
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation files
+  (the "Software"), to deal in the Software without restriction,
+  including without limitation the rights to use, copy, modify, merge,
+  publish, distribute, sublicense, and/or sell copies of the Software,
+  and to permit persons to whom the Software is furnished to do so,
+  subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+***/
+
+#include <dbus/dbus.h>
+#include <inttypes.h>
+
+typedef struct rd_device rd_device;
+
+/* Prototype for a function that is called whenever someone else wants
+ * your app to release the device you having locked. A return value <=
+ * 0 denies the request, a positive return value agrees to it. Before
+ * returning your application should close the device in question
+ * completely to make sure the new application may acceess it. */
+typedef int (*rd_request_cb_t)(
+       rd_device *d,
+       int forced);                  /* Non-zero if an application forcibly took the lock away without asking. If this is the case then the return value of this call is ignored. */
+
+/* Try to lock the device. Returns 0 on success, a negative errno
+ * style return value on error. The DBus error might be set as well if
+ * the error was caused D-Bus. */
+int rd_acquire(
+       rd_device **d,                /* On success a pointer to the newly allocated rd_device object will be filled in here */
+       DBusConnection *connection,
+       const char *device_name,      /* The device to lock, e.g. "Audio0" */
+       const char *application_name, /* A human readable name of the application, e.g. "PulseAudio Sound Server" */
+       int32_t priority,             /* The priority for this application. If unsure use 0 */
+       rd_request_cb_t request_cb,   /* Will be called whenever someone asks that this device shall be released. May be NULL if priority is INT32_MAX */
+       DBusError *error);            /* If we fail due to a D-Bus related issue the error will be filled in here. May be NULL. */
+
+/* Unlock (if needed) and destroy a rd_device object again */
+void rd_release(rd_device *d);
+
+/* Set the application device name for a rd_device object Returns 0 on
+ * success, a negative errno style return value on error. */
+int rd_set_application_device_name(rd_device *d, const char *name);
+
+/* Attach a userdata pointer to a rd_device */
+void rd_set_userdata(rd_device *d, void *userdata);
+
+/* Query the userdata pointer from a rd_device. Returns NULL if no
+ * userdata was set. */
+void* rd_get_userdata(rd_device *d);
+
+#endif
index 9309c6b71ae514508ad5394fb2ba11cd7f9c9d37..62fe53565d3e2022014b0bf0f44ae34f843d3bcd 100644 (file)
@@ -554,7 +554,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
     pa_context_unref(c);
 }
 
-#if ENABLE_LEGACY_RUNTIME_DIR
+#ifdef ENABLE_LEGACY_RUNTIME_DIR
 static char *get_old_legacy_runtime_dir(void) {
     char *p, u[128];
     struct stat st;
@@ -603,7 +603,7 @@ static char *get_very_old_legacy_runtime_dir(void) {
 static pa_strlist *prepend_per_user(pa_strlist *l) {
     char *ufn;
 
-#if ENABLE_LEGACY_RUNTIME_DIR
+#ifdef ENABLE_LEGACY_RUNTIME_DIR
     static char *legacy_dir;
 
     /* The very old per-user instance path (< 0.9.11). This is supported only to ease upgrades */
index 04bcd4f5c4409f505753727dffc4a243b3451dcb..befeb242fe201f79e33715337c8156f6324975be 100644 (file)
@@ -110,12 +110,17 @@ static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command,
                pa_tagstruct_gets(t, &i.default_sink_name) < 0 ||
                pa_tagstruct_gets(t, &i.default_source_name) < 0 ||
                pa_tagstruct_getu32(t, &i.cookie) < 0 ||
+               (o->context->version >= 15 &&
+                pa_tagstruct_get_channel_map(t, &i.channel_map) < 0) ||
                !pa_tagstruct_eof(t)) {
 
         pa_context_fail(o->context, PA_ERR_PROTOCOL);
         goto finish;
     }
 
+    if (p && o->context->version < 15)
+        pa_channel_map_init_extend(&i.channel_map, i.sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+
     if (o->callback) {
         pa_server_info_cb_t cb = (pa_server_info_cb_t) o->callback;
         cb(o->context, p, o->userdata);
index b873a84a1272b0d4dfe311d37b91b6ecbfc21f0e..aa67e43d5b92db5ec917b4528e0a09464e956049 100644 (file)
@@ -317,6 +317,7 @@ typedef struct pa_server_info {
     const char *default_sink_name;      /**< Name of default sink. */
     const char *default_source_name;    /**< Name of default sink. */
     uint32_t cookie;                    /**< A random cookie for identifying this instance of PulseAudio. */
+    pa_channel_map channel_map;         /**< Default channel map. \since 0.9.15 */
 } pa_server_info;
 
 /** Callback prototype for pa_context_get_server_info() */
index c0c3459367330bce1c8f0552b4c963e0967c112c..d30dc3b9e980fde44b760eff7426bf442615148c 100644 (file)
@@ -51,7 +51,7 @@ PA_C_DECL_BEGIN
 /** For streams: an XDG icon name for the media. e.g. "audio-x-mp3" */
 #define PA_PROP_MEDIA_ICON_NAME                "media.icon_name"
 
-/** For streams: logic role of this media. One of the strings "video", "music", "game", "event", "phone", "animation", "production" */
+/** For streams: logic role of this media. One of the strings "video", "music", "game", "event", "phone", "animation", "production", "a11y" */
 #define PA_PROP_MEDIA_ROLE                     "media.role"
 
 /** For event sound streams: XDG event sound name. e.g. "message-new-email" (Event sound streams are those with media.role set to "event") */
@@ -132,6 +132,9 @@ PA_C_DECL_BEGIN
 /** For clients/streams: the D-Bus host id the application runs on. e.g. "543679e7b01393ed3e3e650047d78f6e" */
 #define PA_PROP_APPLICATION_PROCESS_MACHINE_ID "application.process.machine_id"
 
+/** For clients/streams: an id for the login session the application runs in. On Unix the value of $XDG_SESSION_COOKIE. e.g. "543679e7b01393ed3e3e650047d78f6e-1235159798.76193-190367717" */
+#define PA_PROP_APPLICATION_PROCESS_SESSION_ID "application.process.session_id"
+
 /** For devices: device string in the underlying audio layer's format. e.g. "surround51:0" */
 #define PA_PROP_DEVICE_STRING                  "device.string"
 
index 5e45c1aa041fce3afc5a3bbc5a748e1defdcef07..4ce87d6df5833ba7a0794faac9401ac0d70f2abb 100644 (file)
@@ -321,6 +321,8 @@ static int pa_cli_command_source_outputs(pa_core *c, pa_tokenizer *t, pa_strbuf
 }
 
 static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+    char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
+    char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
     char s[256];
     const pa_mempool_stat *stat;
     unsigned k;
@@ -363,7 +365,10 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
                      pa_bytes_snprint(s, sizeof(s), (unsigned) pa_scache_total_size(c)));
 
     pa_strbuf_printf(buf, "Default sample spec: %s\n",
-                     pa_sample_spec_snprint(s, sizeof(s), &c->default_sample_spec));
+                     pa_sample_spec_snprint(ss, sizeof(ss), &c->default_sample_spec));
+
+    pa_strbuf_printf(buf, "Default channel map: %s\n",
+                     pa_channel_map_snprint(cm, sizeof(cm), &c->default_channel_map));
 
     def_sink = pa_namereg_get_default_sink(c);
     def_source = pa_namereg_get_default_source(c);
@@ -1345,7 +1350,7 @@ static int pa_cli_command_log_level(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
         return -1;
     }
 
-    pa_log_set_maximal_level(level);
+    pa_log_set_level(level);
 
     return 0;
 }
@@ -1369,7 +1374,7 @@ static int pa_cli_command_log_meta(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
         return -1;
     }
 
-    pa_log_set_show_meta(b);
+    pa_log_set_flags(PA_LOG_PRINT_META, b ? PA_LOG_SET : PA_LOG_UNSET);
 
     return 0;
 }
@@ -1393,7 +1398,7 @@ static int pa_cli_command_log_time(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
         return -1;
     }
 
-    pa_log_set_show_time(b);
+    pa_log_set_flags(PA_LOG_PRINT_TIME, b ? PA_LOG_SET : PA_LOG_UNSET);
 
     return 0;
 }
index 7ca7b97cc2f51bf7051a6993a5723dbd754b543d..e6e8b528e8c393273f19600bfd7662d46178783e 100644 (file)
@@ -132,15 +132,14 @@ void pa_client_set_name(pa_client *c, const char *name) {
     pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)), name);
     pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
 
-    pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
-    pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
+    pa_client_update_proplist(c, 0, NULL);
 }
 
 void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) {
     pa_assert(c);
-    pa_assert(p);
 
-    pa_proplist_update(c->proplist, mode, p);
+    if (p)
+        pa_proplist_update(c->proplist, mode, p);
 
     pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
     pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
index b7ec2b3c7138df246af5f347e089bde2ce0f0337..1d98f36c22ef717cd22dc0e7f39693cca91a3eb7 100644 (file)
@@ -127,7 +127,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
 int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void *userdata) {
     int r = -1;
     unsigned line = 0;
-    int do_close = !f;
+    pa_bool_t do_close = !f;
     char *section = NULL;
 
     pa_assert(filename);
@@ -144,7 +144,7 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
     }
 
     while (!feof(f)) {
-        char l[256];
+        char l[4096];
 
         if (!fgets(l, sizeof(l), f)) {
             if (feof(f))
index 5fd2bdfb4359cc90056f819efb2d9154ef9dc211..eef967a660973c5997c73f949e035237dbcf5a40 100644 (file)
@@ -111,6 +111,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
     c->default_sample_spec.format = PA_SAMPLE_S16NE;
     c->default_sample_spec.rate = 44100;
     c->default_sample_spec.channels = 2;
+    pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
     c->default_n_fragments = 4;
     c->default_fragment_size_msec = 25;
 
index 53e2d2c3c4ca158cd5551a790a6e8d7564cca808..7660bd3b92876667ca952ef9958a112b4b1213b7 100644 (file)
@@ -122,6 +122,7 @@ struct pa_core {
     pa_source *default_source;
     pa_sink *default_sink;
 
+    pa_channel_map default_channel_map;
     pa_sample_spec default_sample_spec;
     unsigned default_n_fragments, default_fragment_size_msec;
 
index 89b75da3046971bec1a1cafd26790c1e2f2f61f5..9931586d507abdf87aa2bc4bbd2e2d4ae9d675f0 100644 (file)
 
 #include "log.h"
 
-#define ENV_LOGLEVEL "PULSE_LOG"
-#define ENV_LOGMETA "PULSE_LOG_META"
-#define ENV_LOGTIME "PULSE_LOG_TIME"
-#define ENV_LOGBACKTRACE "PULSE_LOG_BACKTRACE"
-
-static char *log_ident = NULL, *log_ident_local = NULL;
-static pa_log_target_t log_target = PA_LOG_STDERR;
-static pa_log_func_t user_log_func = NULL;
-static pa_log_level_t maximal_level = PA_LOG_ERROR;
-static unsigned show_backtrace = 0;
-static pa_bool_t show_meta = FALSE;
-static pa_bool_t show_time = FALSE;
+#define ENV_LOG_SYSLOG "PULSE_LOG_SYSLOG"
+#define ENV_LOG_LEVEL "PULSE_LOG"
+#define ENV_LOG_COLORS "PULSE_LOG_COLORS"
+#define ENV_LOG_PRINT_TIME "PULSE_LOG_TIME"
+#define ENV_LOG_PRINT_FILE "PULSE_LOG_FILE"
+#define ENV_LOG_PRINT_META "PULSE_LOG_META"
+#define ENV_LOG_PRINT_LEVEL "PULSE_LOG_LEVEL"
+#define ENV_LOG_BACKTRACE "PULSE_LOG_BACKTRACE"
+
+static char *ident = NULL; /* in local charset format */
+static pa_log_target_t target = PA_LOG_STDERR, target_override;
+static pa_bool_t target_override_set = FALSE;
+static pa_log_level_t maximum_level = PA_LOG_ERROR, maximum_level_override = PA_LOG_ERROR;
+static unsigned show_backtrace = 0, show_backtrace_override = 0;
+static pa_log_flags_t flags = 0, flags_override = 0;
 
 #ifdef HAVE_SYSLOG_H
 static const int level_to_syslog[] = {
@@ -83,12 +86,10 @@ static const char level_to_char[] = {
 };
 
 void pa_log_set_ident(const char *p) {
-    pa_xfree(log_ident);
-    pa_xfree(log_ident_local);
+    pa_xfree(ident);
 
-    log_ident = pa_xstrdup(p);
-    if (!(log_ident_local = pa_utf8_to_locale(log_ident)))
-        log_ident_local = pa_xstrdup(log_ident);
+    if (!(ident = pa_utf8_to_locale(p)))
+        ident = pa_ascii_filter(p);
 }
 
 /* To make valgrind shut up. */
@@ -97,29 +98,30 @@ static void ident_destructor(void) {
     if (!pa_in_valgrind())
         return;
 
-    pa_xfree(log_ident);
-    pa_xfree(log_ident_local);
+    pa_xfree(ident);
 }
 
-void pa_log_set_maximal_level(pa_log_level_t l) {
+void pa_log_set_level(pa_log_level_t l) {
     pa_assert(l < PA_LOG_LEVEL_MAX);
 
-    maximal_level = l;
+    maximum_level = l;
 }
 
-void pa_log_set_target(pa_log_target_t t, pa_log_func_t func) {
-    pa_assert(t == PA_LOG_USER || !func);
+void pa_log_set_target(pa_log_target_t t) {
+    pa_assert(t < PA_LOG_TARGET_MAX);
 
-    log_target = t;
-    user_log_func = func;
+    target = t;
 }
 
-void pa_log_set_show_meta(pa_bool_t b) {
-    show_meta = b;
-}
+void pa_log_set_flags(pa_log_flags_t _flags, pa_log_merge_t merge) {
+    pa_assert(!(_flags & ~(PA_LOG_COLORS|PA_LOG_PRINT_TIME|PA_LOG_PRINT_FILE|PA_LOG_PRINT_META|PA_LOG_PRINT_LEVEL)));
 
-void pa_log_set_show_time(pa_bool_t b) {
-    show_time = b;
+    if (merge == PA_LOG_SET)
+        flags |= _flags;
+    else if (merge == PA_LOG_UNSET)
+        flags &= ~_flags;
+    else
+        flags = _flags;
 }
 
 void pa_log_set_show_backtrace(unsigned nlevels) {
@@ -135,8 +137,7 @@ static char* get_backtrace(unsigned show_nframes) {
     unsigned j, n;
     size_t a;
 
-    if (show_nframes <= 0)
-        return NULL;
+    pa_assert(show_nframes > 0);
 
     n_frames = backtrace(trace, PA_ELEMENTSOF(trace));
 
@@ -182,6 +183,50 @@ static char* get_backtrace(unsigned show_nframes) {
 
 #endif
 
+static void init_defaults(void) {
+    const char *e;
+
+    if (!ident) {
+        char binary[256];
+        if (pa_get_binary_name(binary, sizeof(binary)))
+            pa_log_set_ident(binary);
+    }
+
+    if (getenv(ENV_LOG_SYSLOG)) {
+        target_override = PA_LOG_SYSLOG;
+        target_override_set = TRUE;
+    }
+
+    if ((e = getenv(ENV_LOG_LEVEL))) {
+        maximum_level_override = (pa_log_level_t) atoi(e);
+
+        if (maximum_level_override >= PA_LOG_LEVEL_MAX)
+            maximum_level_override = PA_LOG_LEVEL_MAX-1;
+    }
+
+    if (getenv(ENV_LOG_COLORS))
+        flags_override |= PA_LOG_COLORS;
+
+    if (getenv(ENV_LOG_PRINT_TIME))
+        flags_override |= PA_LOG_PRINT_TIME;
+
+    if (getenv(ENV_LOG_PRINT_FILE))
+        flags_override |= PA_LOG_PRINT_FILE;
+
+    if (getenv(ENV_LOG_PRINT_META))
+        flags_override |= PA_LOG_PRINT_META;
+
+    if (getenv(ENV_LOG_PRINT_LEVEL))
+        flags_override |= PA_LOG_PRINT_LEVEL;
+
+    if ((e = getenv(ENV_LOG_BACKTRACE))) {
+        show_backtrace_override = (unsigned) atoi(e);
+
+        if (show_backtrace_override <= 0)
+            show_backtrace_override = 0;
+    }
+}
+
 void pa_log_levelv_meta(
         pa_log_level_t level,
         const char*file,
@@ -190,14 +235,13 @@ void pa_log_levelv_meta(
         const char *format,
         va_list ap) {
 
-    const char *e;
     char *t, *n;
     int saved_errno = errno;
     char *bt = NULL;
-    pa_log_level_t ml;
-#ifdef HAVE_EXECINFO_H
-    unsigned show_bt;
-#endif
+    pa_log_target_t _target;
+    pa_log_level_t _maximum_level;
+    unsigned _show_backtrace;
+    pa_log_flags_t _flags;
 
     /* We don't use dynamic memory allocation here to minimize the hit
      * in RT threads */
@@ -206,30 +250,30 @@ void pa_log_levelv_meta(
     pa_assert(level < PA_LOG_LEVEL_MAX);
     pa_assert(format);
 
-    ml = maximal_level;
-
-    if (PA_UNLIKELY((e = getenv(ENV_LOGLEVEL)))) {
-        pa_log_level_t eml = (pa_log_level_t) atoi(e);
+    PA_ONCE_BEGIN {
+        init_defaults();
+    } PA_ONCE_END;
 
-        if (eml > ml)
-            ml = eml;
-    }
+    _target = target_override_set ? target_override : target;
+    _maximum_level = PA_MAX(maximum_level, maximum_level_override);
+    _show_backtrace = PA_MAX(show_backtrace, show_backtrace_override);
+    _flags = flags | flags_override;
 
-    if (PA_LIKELY(level > ml)) {
+    if (PA_LIKELY(level > _maximum_level)) {
         errno = saved_errno;
         return;
     }
 
     pa_vsnprintf(text, sizeof(text), format, ap);
 
-    if ((show_meta || getenv(ENV_LOGMETA)) && file && line > 0 && func)
+    if ((_flags & PA_LOG_PRINT_META) && file && line > 0 && func)
         pa_snprintf(location, sizeof(location), "[%s:%i %s()] ", file, line, func);
-    else if (file)
+    else if (_flags & (PA_LOG_PRINT_META|PA_LOG_PRINT_FILE))
         pa_snprintf(location, sizeof(location), "%s: ", pa_path_get_filename(file));
     else
         location[0] = 0;
 
-    if (show_time || getenv(ENV_LOGTIME)) {
+    if (_flags & PA_LOG_PRINT_TIME) {
         static pa_usec_t start, last;
         pa_usec_t u, a, r;
 
@@ -257,16 +301,8 @@ void pa_log_levelv_meta(
         timestamp[0] = 0;
 
 #ifdef HAVE_EXECINFO_H
-    show_bt = show_backtrace;
-
-    if ((e = getenv(ENV_LOGBACKTRACE))) {
-        unsigned ebt = (unsigned) atoi(e);
-
-        if (ebt > show_bt)
-            show_bt = ebt;
-    }
-
-    bt = get_backtrace(show_bt);
+    if (_show_backtrace > 0)
+        bt = get_backtrace(_show_backtrace);
 #endif
 
     if (!pa_utf8_valid(text))
@@ -282,14 +318,15 @@ void pa_log_levelv_meta(
         if (t[strspn(t, "\t ")] == 0)
             continue;
 
-        switch (log_target) {
+        switch (_target) {
+
             case PA_LOG_STDERR: {
                 const char *prefix = "", *suffix = "", *grey = "";
                 char *local_t;
 
 #ifndef OS_IS_WIN32
                 /* Yes indeed. Useless, but fun! */
-                if (isatty(STDERR_FILENO)) {
+                if ((_flags & PA_LOG_COLORS) && isatty(STDERR_FILENO)) {
                     if (level <= PA_LOG_ERROR)
                         prefix = "\x1B[1;31m";
                     else if (level <= PA_LOG_WARN)
@@ -305,13 +342,15 @@ void pa_log_levelv_meta(
 
                 /* We shouldn't be using dynamic allocation here to
                  * minimize the hit in RT threads */
-                local_t = pa_utf8_to_locale(t);
-                if (!local_t)
+                if ((local_t = pa_utf8_to_locale(t)))
+                    t = local_t;
+
+                if (_flags & PA_LOG_PRINT_LEVEL)
                     fprintf(stderr, "%s%c: %s%s%s%s%s%s\n", timestamp, level_to_char[level], location, prefix, t, grey, pa_strempty(bt), suffix);
-                else {
-                    fprintf(stderr, "%s%c: %s%s%s%s%s%s\n", timestamp, level_to_char[level], location, prefix, local_t, grey, pa_strempty(bt), suffix);
-                    pa_xfree(local_t);
-                }
+                else
+                    fprintf(stderr, "%s%s%s%s%s%s%s\n", timestamp, location, prefix, t, grey, pa_strempty(bt), suffix);
+
+                pa_xfree(local_t);
 
                 break;
             }
@@ -320,29 +359,17 @@ void pa_log_levelv_meta(
             case PA_LOG_SYSLOG: {
                 char *local_t;
 
-                openlog(log_ident_local ? log_ident_local : "???", LOG_PID, LOG_USER);
-
-                local_t = pa_utf8_to_locale(t);
-                if (!local_t)
-                    syslog(level_to_syslog[level], "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
-                else {
-                    syslog(level_to_syslog[level], "%s%s%s%s", timestamp, location, local_t, pa_strempty(bt));
-                    pa_xfree(local_t);
-                }
-
-                closelog();
-                break;
-            }
-#endif
+                openlog(ident, LOG_PID, LOG_USER);
 
-            case PA_LOG_USER: {
-                char x[1024];
+                if ((local_t = pa_utf8_to_locale(t)))
+                    t = local_t;
 
-                pa_snprintf(x, sizeof(x), "%s%s%s", timestamp, location, t);
-                user_log_func(level, x);
+                syslog(level_to_syslog[level], "%s%s%s%s", timestamp, location, t, pa_strempty(bt));
+                pa_xfree(local_t);
 
                 break;
             }
+#endif
 
             case PA_LOG_NULL:
             default:
@@ -350,8 +377,8 @@ void pa_log_levelv_meta(
         }
     }
 
-    errno = saved_errno;
     pa_xfree(bt);
+    errno = saved_errno;
 }
 
 void pa_log_level_meta(
index 77adb791d6d3c15480e0c369b4a0955c8ed41315..6e7bfc35f2a85a88d4364b2fa0b51d5d52dfb247 100644 (file)
@@ -35,8 +35,8 @@
 typedef enum pa_log_target {
     PA_LOG_STDERR,  /* default */
     PA_LOG_SYSLOG,
-    PA_LOG_USER,    /* to user specified function */
-    PA_LOG_NULL     /* to /dev/null */
+    PA_LOG_NULL,    /* to /dev/null */
+    PA_LOG_TARGET_MAX
 } pa_log_target_t;
 
 typedef enum pa_log_level {
@@ -48,18 +48,33 @@ typedef enum pa_log_level {
     PA_LOG_LEVEL_MAX
 } pa_log_level_t;
 
+typedef enum pa_log_flags {
+    PA_LOG_COLORS      = 0x01, /* Show colorful output */
+    PA_LOG_PRINT_TIME  = 0x02, /* Show time */
+    PA_LOG_PRINT_FILE  = 0x04, /* Show source file */
+    PA_LOG_PRINT_META  = 0x08, /* Show extended locaton information */
+    PA_LOG_PRINT_LEVEL = 0x10, /* Show log level prefix */
+} pa_log_flags_t;
+
+typedef enum pa_log_merge {
+    PA_LOG_SET,
+    PA_LOG_UNSET,
+    PA_LOG_RESET
+} pa_log_merge_t;
+
 /* Set an identification for the current daemon. Used when logging to syslog. */
 void pa_log_set_ident(const char *p);
 
-typedef void (*pa_log_func_t)(pa_log_level_t t, const char*s);
-
-/* Set another log target. If t is PA_LOG_USER you may specify a function that is called every log string */
-void pa_log_set_target(pa_log_target_t t, pa_log_func_t func);
+/* Set a log target. */
+void pa_log_set_target(pa_log_target_t t);
 
 /* Maximal log level */
-void pa_log_set_maximal_level(pa_log_level_t l);
-void pa_log_set_show_meta(pa_bool_t b);
-void pa_log_set_show_time(pa_bool_t b);
+void pa_log_set_level(pa_log_level_t l);
+
+/* Set flags */
+void pa_log_set_flags(pa_log_flags_t flags, pa_log_merge_t merge);
+
+/* Enable backtrace */
 void pa_log_set_show_backtrace(unsigned nlevels);
 
 void pa_log_level_meta(
@@ -68,6 +83,7 @@ void pa_log_level_meta(
         int line,
         const char *func,
         const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
+
 void pa_log_levelv_meta(
         pa_log_level_t level,
         const char*file,
@@ -76,8 +92,14 @@ void pa_log_levelv_meta(
         const char *format,
         va_list ap);
 
-void pa_log_level(pa_log_level_t level, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
-void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap);
+void pa_log_level(
+        pa_log_level_t level,
+        const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
+
+void pa_log_levelv(
+        pa_log_level_t level,
+        const char *format,
+        va_list ap);
 
 #if __STDC_VERSION__ >= 199901L
 
index 866e6e0ce8df9de63b272a4cc8af5e964b8d4730..4a30f52a0ca880b05414155ac8cc590891e7fe95 100644 (file)
@@ -274,11 +274,15 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
     pa_assert(rss);
 
     ss = *rss;
-    if ((pa_modargs_get_value_u32(ma, "rate", &ss.rate)) < 0)
+    if ((pa_modargs_get_value_u32(ma, "rate", &ss.rate)) < 0 ||
+        ss.rate <= 0 ||
+        ss.rate > PA_RATE_MAX)
         return -1;
 
     channels = ss.channels;
-    if ((pa_modargs_get_value_u32(ma, "channels", &channels)) < 0)
+    if ((pa_modargs_get_value_u32(ma, "channels", &channels)) < 0 ||
+        channels <= 0 ||
+        channels >= PA_CHANNELS_MAX)
         return -1;
     ss.channels = (uint8_t) channels;
 
@@ -314,7 +318,12 @@ int pa_modargs_get_channel_map(pa_modargs *ma, const char *name, pa_channel_map
     return 0;
 }
 
-int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap, pa_channel_map_def_t def) {
+int pa_modargs_get_sample_spec_and_channel_map(
+        pa_modargs *ma,
+        pa_sample_spec *rss,
+        pa_channel_map *rmap,
+        pa_channel_map_def_t def) {
+
     pa_sample_spec ss;
     pa_channel_map map;
 
@@ -327,7 +336,10 @@ int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *r
     if (pa_modargs_get_sample_spec(ma, &ss) < 0)
         return -1;
 
-    pa_channel_map_init_extend(&map, ss.channels, def);
+    map = *rmap;
+
+    if (ss.channels != map.channels)
+        pa_channel_map_init_extend(&map, ss.channels, def);
 
     if (pa_modargs_get_channel_map(ma, NULL, &map) < 0)
         return -1;
index 86bcef740e81bb24e63192345dedfb7c25738cd1..5ab3036eaeaeaafd65fe5bba453915888b6f9338 100644 (file)
@@ -194,7 +194,11 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
 
     }
 
-    if (!name || *name == '@' || !pa_namereg_is_valid_name(name))
+    if (!name)
+        return NULL;
+
+    if ((type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE || type == PA_NAMEREG_CARD) &&
+        !pa_namereg_is_valid_name(name))
         return NULL;
 
     if ((e = pa_hashmap_get(c->namereg, name)))
index bdae0e65d324df4470172243f542eb794a8c89b7..af5f0aa615b67fa20102710893085bfac4743a0e 100644 (file)
@@ -48,6 +48,7 @@ static G_CONST_RETURN gchar* _g_get_application_name(void) PA_GCC_WEAKREF(g_get_
 #endif
 
 #if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF)
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 static G_CONST_RETURN gchar* _gtk_window_get_default_icon_name(void) PA_GCC_WEAKREF(gtk_window_get_default_icon_name);
@@ -134,8 +135,9 @@ void pa_init_proplist(pa_proplist *p) {
 
                 k = pa_xstrndup(*e+skip, kl);
 
-                if (override || !pa_proplist_contains(p, k))
-                    pa_proplist_sets(p, k, *e+skip+kl+1);
+                if (!pa_streq(k, "OVERRIDE"))
+                    if (override || !pa_proplist_contains(p, k))
+                        pa_proplist_sets(p, k, *e+skip+kl+1);
                 pa_xfree(k);
             }
         }
@@ -227,4 +229,14 @@ void pa_init_proplist(pa_proplist *p) {
             pa_xfree(m);
         }
     }
+
+    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID)) {
+        const char *t;
+
+        if ((t = getenv("XDG_SESSION_COOKIE"))) {
+            char *c = pa_utf8_filter(t);
+            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID, c);
+            pa_xfree(c);
+        }
+    }
 }
index 840f4581118cd259b977f08fd191e615d960b157..2d4e62fae0363752f7ade30df661f2d86f3f1ac0 100644 (file)
@@ -34,6 +34,7 @@
 #include <pulse/timeval.h>
 #include <pulse/utf8.h>
 #include <pulse/xmalloc.h>
+#include <pulse/proplist.h>
 
 #include <pulsecore/esound.h>
 #include <pulsecore/memblock.h>
@@ -164,10 +165,12 @@ static int esd_proto_get_latency(connection *c, esd_proto_t request, const void
 static int esd_proto_server_info(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_all_info(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_sample_pan(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_sample_cache(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_sample_get_id(connection *c, esd_proto_t request, const void *data, size_t length);
 static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_standby_mode(connection *c, esd_proto_t request, const void *data, size_t length);
 
 /* the big map of protocol handler info */
 static struct proto_handler proto_map[ESD_PROTO_MAX] = {
@@ -186,8 +189,8 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = {
     { sizeof(int),                    NULL, "sample stop" },
     { (size_t) -1,                    NULL, "TODO: sample kill" },
 
-    { ESD_KEY_LEN + sizeof(int),      esd_proto_standby_or_resume, "standby" },  /* NOOP! */
-    { ESD_KEY_LEN + sizeof(int),      esd_proto_standby_or_resume, "resume" },   /* NOOP! */         /* 13 */
+    { ESD_KEY_LEN + sizeof(int),      esd_proto_standby_or_resume, "standby" },
+    { ESD_KEY_LEN + sizeof(int),      esd_proto_standby_or_resume, "resume" },                       /* 13 */
 
     { ESD_NAME_MAX,                   esd_proto_sample_get_id, "sample getid" },                     /* 14 */
     { ESD_NAME_MAX + 2 * sizeof(int), NULL, "stream filter" },
@@ -198,9 +201,9 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = {
     { (size_t) -1,                    NULL, "TODO: unsubscribe" },
 
     { 3 * sizeof(int),                esd_proto_stream_pan, "stream pan"},
-    { 3 * sizeof(int),                NULL, "sample pan" },
+    { 3 * sizeof(int),                esd_proto_sample_pan, "sample pan" },
 
-    { sizeof(int),                    NULL, "standby mode" },
+    { sizeof(int),                    esd_proto_standby_mode, "standby mode" },
     { 0,                              esd_proto_get_latency, "get latency" }
 };
 
@@ -372,6 +375,8 @@ static int esd_proto_connect(connection *c, esd_proto_t request, const void *dat
         return -1;
     }
 
+    pa_proplist_sets(c->client->proplist, "esound.byte_order", c->swap_byte_order ? "reverse" : "native");
+
     ok = 1;
     connection_write(c, &ok, sizeof(int));
     return 0;
@@ -404,7 +409,7 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void
 
     if (c->options->default_sink) {
         sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK);
-        CHECK_VALIDITY(sink, "No such sink: %s", c->options->default_sink);
+        CHECK_VALIDITY(sink, "No such sink: %s", pa_strnull(c->options->default_sink));
     }
 
     pa_strlcpy(name, data, sizeof(name));
@@ -489,23 +494,17 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
     if (request == ESD_PROTO_STREAM_MON) {
         pa_sink* sink;
 
-        if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK))) {
-            pa_log("no such sink.");
-            return -1;
-        }
+        sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK);
+        CHECK_VALIDITY(sink, "No such sink: %s", pa_strnull(c->options->default_sink));
 
-        if (!(source = sink->monitor_source)) {
-            pa_log("no such monitor source.");
-            return -1;
-        }
+        source = sink->monitor_source;
+        CHECK_VALIDITY(source, "No such source.");
     } else {
         pa_assert(request == ESD_PROTO_STREAM_REC);
 
         if (c->options->default_source) {
-            if (!(source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE))) {
-                pa_log("no such source.");
-                return -1;
-            }
+            source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE);
+            CHECK_VALIDITY(source, "No such source: %s", pa_strnull(c->options->default_source));
         }
     }
 
@@ -570,7 +569,7 @@ static int esd_proto_get_latency(connection *c, esd_proto_t request, const void
     if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK)))
         latency = 0;
     else {
-        double usec = (double) pa_sink_get_latency(sink);
+        double usec = (double) pa_sink_get_requested_latency(sink);
         latency = (int) ((usec*44100)/1000000);
     }
 
@@ -621,7 +620,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
 
     k = sizeof(int32_t)*5+ESD_NAME_MAX;
     s = sizeof(int32_t)*6+ESD_NAME_MAX;
-    nsamples = c->protocol->core->scache ? pa_idxset_size(c->protocol->core->scache) : 0;
+    nsamples = pa_idxset_size(c->protocol->core->scache);
     t = s*(nsamples+1) + k*(c->protocol->n_player+1);
 
     connection_write_prepare(c, t);
@@ -641,7 +640,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
             pa_cvolume volume = *pa_sink_input_get_volume(conn->sink_input);
             rate = (int32_t) conn->sink_input->sample_spec.rate;
             lvolume = (int32_t) ((volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
-            rvolume = (int32_t) ((volume.values[1]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
+            rvolume = (int32_t) ((volume.values[volume.channels == 2 ? 1 : 0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
             format = format_native2esd(&conn->sink_input->sample_spec);
         }
 
@@ -688,9 +687,26 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
         for (ce = pa_idxset_first(c->protocol->core->scache, &idx); ce; ce = pa_idxset_next(c->protocol->core->scache, &idx)) {
             int32_t id, rate, lvolume, rvolume, format, len;
             char name[ESD_NAME_MAX];
+            pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } };
+            pa_cvolume volume;
+            pa_sample_spec ss;
 
             pa_assert(t >= s*2);
 
+            if (ce->volume_is_set) {
+                volume = ce->volume;
+                pa_cvolume_remap(&volume, &ce->channel_map, &stereo);
+            } else
+                pa_cvolume_reset(&volume, 2);
+
+            if (ce->memchunk.memblock)
+                ss = ce->sample_spec;
+            else {
+                ss.format = PA_SAMPLE_S16NE;
+                ss.rate = 44100;
+                ss.channels = 2;
+            }
+
             /* id */
             id = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int) (ce->index+1));
             connection_write(c, &id, sizeof(int32_t));
@@ -704,19 +720,19 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
             connection_write(c, name, ESD_NAME_MAX);
 
             /* rate */
-            rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ce->sample_spec.rate);
+            rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ss.rate);
             connection_write(c, &rate, sizeof(int32_t));
 
             /* left */
-            lvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM));
+            lvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM));
             connection_write(c, &lvolume, sizeof(int32_t));
 
             /*right*/
-            rvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM));
+            rvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((volume.values[1]*ESD_VOLUME_BASE)/PA_VOLUME_NORM));
             connection_write(c, &rvolume, sizeof(int32_t));
 
             /*format*/
-            format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ce->sample_spec));
+            format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ss));
             connection_write(c, &format, sizeof(int32_t));
 
             /*length*/
@@ -759,7 +775,8 @@ static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void *
         pa_cvolume volume;
         volume.values[0] = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
         volume.values[1] = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
-        volume.channels = 2;
+        volume.channels = conn->sink_input->sample_spec.channels;
+
         pa_sink_input_set_volume(conn->sink_input, &volume, TRUE);
         ok = 1;
     } else
@@ -770,6 +787,46 @@ static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void *
     return 0;
 }
 
+static int esd_proto_sample_pan(connection *c, esd_proto_t request, const void *data, size_t length) {
+    int32_t ok = 0;
+    uint32_t idx, lvolume, rvolume;
+    pa_cvolume volume;
+    pa_scache_entry *ce;
+
+    connection_assert_ref(c);
+    pa_assert(data);
+    pa_assert(length == sizeof(int32_t)*3);
+
+    memcpy(&idx, data, sizeof(uint32_t));
+    idx = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, idx) - 1;
+    data = (const char*)data + sizeof(uint32_t);
+
+    memcpy(&lvolume, data, sizeof(uint32_t));
+    lvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, lvolume);
+    data = (const char*)data + sizeof(uint32_t);
+
+    memcpy(&rvolume, data, sizeof(uint32_t));
+    rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume);
+    data = (const char*)data + sizeof(uint32_t);
+
+    volume.values[0] = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
+    volume.values[1] = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE;
+    volume.channels = 2;
+
+    if ((ce = pa_idxset_get_by_index(c->protocol->core->scache, idx))) {
+        pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } };
+
+        pa_cvolume_remap(&volume, &stereo, &ce->channel_map);
+        ce->volume = volume;
+        ce->volume_is_set = TRUE;
+        ok = 1;
+    }
+
+    connection_write(c, &ok, sizeof(int32_t));
+
+    return 0;
+}
+
 static int esd_proto_sample_cache(connection *c, esd_proto_t request, const void *data, size_t length) {
     pa_sample_spec ss;
     int32_t format, rate, sc_length;
@@ -880,19 +937,47 @@ static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, con
 }
 
 static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const void *data, size_t length) {
-    int32_t ok;
+    int32_t ok = 1;
 
     connection_assert_ref(c);
 
     connection_write_prepare(c, sizeof(int32_t) * 2);
-
-    ok = 1;
     connection_write(c, &ok, sizeof(int32_t));
+
+    if (request == ESD_PROTO_STANDBY)
+        ok = pa_sink_suspend_all(c->protocol->core, TRUE) >= 0;
+    else {
+        pa_assert(request == ESD_PROTO_RESUME);
+        ok = pa_sink_suspend_all(c->protocol->core, FALSE) >= 0;
+    }
+
     connection_write(c, &ok, sizeof(int32_t));
 
     return 0;
 }
 
+static int esd_proto_standby_mode(connection *c, esd_proto_t request, const void *data, size_t length) {
+    int32_t mode;
+    pa_sink *sink, *source;
+
+    connection_assert_ref(c);
+
+    mode = ESM_RUNNING;
+
+    if ((sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK)))
+        if (pa_sink_get_state(sink) == PA_SINK_SUSPENDED)
+            mode = ESM_ON_STANDBY;
+
+    if ((source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE)))
+        if (pa_source_get_state(source) == PA_SOURCE_SUSPENDED)
+            mode = ESM_ON_STANDBY;
+
+    mode = PA_MAYBE_INT32_SWAP(c->swap_byte_order, mode);
+
+    connection_write(c, &mode, sizeof(mode));
+    return 0;
+}
+
 /*** client callbacks ***/
 
 static void client_kill_cb(pa_client *c) {
@@ -912,7 +997,13 @@ static int do_read(connection *c) {
         ssize_t r;
         pa_assert(c->read_data_length < sizeof(c->request));
 
-        if ((r = pa_iochannel_read(c->io, ((uint8_t*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) {
+        if ((r = pa_iochannel_read(c->io,
+                                   ((uint8_t*) &c->request) + c->read_data_length,
+                                   sizeof(c->request) - c->read_data_length)) <= 0) {
+
+            if (r < 0 && (errno == EINTR || errno == EAGAIN))
+                return 0;
+
             pa_log_debug("read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
             return -1;
         }
@@ -962,7 +1053,10 @@ static int do_read(connection *c) {
 
         pa_assert(c->read_data && c->read_data_length < handler->data_length);
 
-        if ((r = pa_iochannel_read(c->io, (uint8_t*) c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) {
+        if ((r = pa_iochannel_read(c->io,
+                                   (uint8_t*) c->read_data + c->read_data_length,
+                                   handler->data_length - c->read_data_length)) <= 0) {
+
             if (r < 0 && (errno == EINTR || errno == EAGAIN))
                 return 0;
 
index a963f78ad0e944e462dfc9d9842c6afc15347a98..10b9e7da330909ef5ad6ed9506ebba0a9862c21d 100644 (file)
@@ -3125,6 +3125,9 @@ static void command_get_server_info(pa_pdispatch *pd, uint32_t command, uint32_t
 
     pa_tagstruct_putu32(reply, c->protocol->core->cookie);
 
+    if (c->version >= 15)
+        pa_tagstruct_put_channel_map(reply, &c->protocol->core->default_channel_map);
+
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
index 01dfd6201b1f879bb9e42b75439440c317d08722..aa8ca321da4663d505f0edf8c12c119cb816ad44 100644 (file)
@@ -478,59 +478,56 @@ static void update_timer(pa_rtpoll *p) {
 #ifdef HAVE_PPOLL
 
 #ifdef __linux__
-    if (!p->dont_use_ppoll) {
+    if (p->dont_use_ppoll)
+        return;
 #endif
 
-        if (p->timer == (timer_t) -1) {
-            struct sigevent se;
-
-            memset(&se, 0, sizeof(se));
-            se.sigev_notify = SIGEV_SIGNAL;
-            se.sigev_signo = p->rtsig;
+    if (p->timer == (timer_t) -1) {
+        struct sigevent se;
 
-            if (timer_create(CLOCK_MONOTONIC, &se, &p->timer) < 0)
-                if (timer_create(CLOCK_REALTIME, &se, &p->timer) < 0) {
-                    pa_log_warn("Failed to allocate POSIX timer: %s", pa_cstrerror(errno));
-                    p->timer = (timer_t) -1;
-                }
-        }
+        memset(&se, 0, sizeof(se));
+        se.sigev_notify = SIGEV_SIGNAL;
+        se.sigev_signo = p->rtsig;
 
-        if (p->timer != (timer_t) -1) {
-            struct itimerspec its;
-            struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
-            sigset_t ss;
+        if (timer_create(CLOCK_MONOTONIC, &se, &p->timer) < 0)
+            if (timer_create(CLOCK_REALTIME, &se, &p->timer) < 0) {
+                pa_log_warn("Failed to allocate POSIX timer: %s", pa_cstrerror(errno));
+                p->timer = (timer_t) -1;
+            }
+    }
 
-            if (p->timer_armed) {
-                /* First disarm timer */
-                memset(&its, 0, sizeof(its));
-                pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
+    if (p->timer != (timer_t) -1) {
+        struct itimerspec its;
+        struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+        sigset_t ss;
 
-                /* Remove a signal that might be waiting in the signal q */
-                pa_assert_se(sigemptyset(&ss) == 0);
-                pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
-                sigtimedwait(&ss, NULL, &ts);
-            }
+        if (p->timer_armed) {
+            /* First disarm timer */
+            memset(&its, 0, sizeof(its));
+            pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
 
-            /* And install the new timer */
-            if (p->timer_enabled) {
-                memset(&its, 0, sizeof(its));
+            /* Remove a signal that might be waiting in the signal q */
+            pa_assert_se(sigemptyset(&ss) == 0);
+            pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
+            sigtimedwait(&ss, NULL, &ts);
+        }
 
-                its.it_value.tv_sec = p->next_elapse.tv_sec;
-                its.it_value.tv_nsec = p->next_elapse.tv_usec*1000;
+        /* And install the new timer */
+        if (p->timer_enabled) {
+            memset(&its, 0, sizeof(its));
 
-                /* Make sure that 0,0 is not understood as
-                 * "disarming" */
-                if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
-                    its.it_value.tv_nsec = 1;
-                pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
-            }
+            its.it_value.tv_sec = p->next_elapse.tv_sec;
+            its.it_value.tv_nsec = p->next_elapse.tv_usec*1000;
 
-            p->timer_armed = p->timer_enabled;
+            /* Make sure that 0,0 is not understood as
+             * "disarming" */
+            if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
+                its.it_value.tv_nsec = 1;
+            pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
         }
 
-#ifdef __linux__
+        p->timer_armed = p->timer_enabled;
     }
-#endif
 
 #endif
 }
index 22419ee5b6325e15d19a9eada698cd2b58472b47..34217c86726f39db3479e1b9530686703094ef40 100644 (file)
@@ -943,9 +943,9 @@ pa_bool_t pa_sink_input_get_mute(pa_sink_input *i) {
 /* Called from main thread */
 void pa_sink_input_update_proplist(pa_sink_input *i, pa_update_mode_t mode, pa_proplist *p) {
     pa_sink_input_assert_ref(i);
-    pa_assert(p);
 
-    pa_proplist_update(i->proplist, mode, p);
+    if (p)
+        pa_proplist_update(i->proplist, mode, p);
 
     if (PA_SINK_IS_LINKED(i->state)) {
         pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], i);
index 382fb88cc8ad1602583339a98d97ba6cf67a8f02..d63aca1563141bd3caa1444e2c3b1fe6fe9809b7 100644 (file)
@@ -618,9 +618,9 @@ void pa_source_output_set_name(pa_source_output *o, const char *name) {
 /* Called from main thread */
 void pa_source_output_update_proplist(pa_source_output *o, pa_update_mode_t mode, pa_proplist *p) {
     pa_source_output_assert_ref(o);
-    pa_assert(p);
 
-    pa_proplist_update(o->proplist, mode, p);
+    if (p)
+        pa_proplist_update(o->proplist, mode, p);
 
     if (PA_SINK_IS_LINKED(o->state)) {
         pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], o);
index 3858bf7bfdb5741adb3dfb475e91131d20984179..e852c3f7a73010e8fbe892283adca28621c57a3c 100644 (file)
@@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
     snd_pcm_status_t *status;
     snd_pcm_t *pcm;
     unsigned rate = 44100;
-    unsigned periods = 0;
+    unsigned periods = 2;
     snd_pcm_uframes_t boundary, buffer_size = 44100/10; /* 100s */
     int dir = 1;
     struct timespec start, last_timestamp = { 0, 0 };
@@ -75,10 +75,13 @@ int main(int argc, char *argv[]) {
     r = snd_pcm_hw_params_current(pcm, hwparams);
     assert(r == 0);
 
+    r = snd_pcm_sw_params_current(pcm, swparams);
+    assert(r == 0);
+
     r = snd_pcm_sw_params_set_avail_min(pcm, swparams, 1);
     assert(r == 0);
 
-    r = snd_pcm_sw_params_set_period_event(pcm, swparams, 1);
+    r = snd_pcm_sw_params_set_period_event(pcm, swparams, 0);
     assert(r == 0);
 
     r = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
@@ -116,7 +119,6 @@ int main(int argc, char *argv[]) {
 
     for (;;) {
         snd_pcm_sframes_t avail, delay;
-/*         snd_pcm_uframes_t avail2; */
         struct timespec now, timestamp;
         unsigned short revents;
         int written = 0;
@@ -131,29 +133,20 @@ int main(int argc, char *argv[]) {
 
         assert((revents & ~POLLOUT) == 0);
 
-/*         state = snd_pcm_get_state(pcm); */
-
         avail = snd_pcm_avail(pcm);
         assert(avail >= 0);
 
         r = snd_pcm_status(pcm, status);
         assert(r == 0);
 
-        printf("%lu %lu\n", (unsigned long) avail, (unsigned long) snd_pcm_status_get_avail(status));
+        /* This assertion fails from time to time. ALSA seems to be broken */
+/*         assert(avail == (snd_pcm_sframes_t) snd_pcm_status_get_avail(status)); */
+/*         printf("%lu %lu\n", (unsigned long) avail, (unsigned long) snd_pcm_status_get_avail(status)); */
 
-        assert(avail == (snd_pcm_sframes_t) snd_pcm_status_get_avail(status));
         snd_pcm_status_get_htstamp(status, &timestamp);
         delay = snd_pcm_status_get_delay(status);
         state = snd_pcm_status_get_state(status);
 
-/*         r = snd_pcm_avail_delay(pcm, &avail, &delay); */
-/*         assert(r == 0); */
-
-/*         r = snd_pcm_htimestamp(pcm, &avail2, &timestamp); */
-/*         assert(r == 0); */
-
-/*         assert(avail == (snd_pcm_sframes_t) avail2); */
-
         r = clock_gettime(CLOCK_MONOTONIC, &now);
         assert(r == 0);
 
@@ -191,6 +184,10 @@ int main(int argc, char *argv[]) {
                written,
                state);
 
+        /** When this assert is hit, most likely something bad
+         * happened, i.e. the avail jumped suddenly. */
+        assert((unsigned) avail <= buffer_size);
+
         last_avail = avail;
         last_delay = delay;
         last_timestamp = timestamp;
index 4a72f5a3f624a5bbe9d84b3a03848dae2f2364d2..11a80a14f2909392126f73409699c9039aa4f87e 100644 (file)
@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
     };
 
     oil_init();
-    pa_log_set_maximal_level(PA_LOG_DEBUG);
+    pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
     pa_assert_se(envelope = pa_envelope_new(&ss));
index a2d3e69a13b147e67a4351a1fe359fce0b6aa5cb..092ba25c53800c7d3a86ca280557da65f7f7c6cd 100644 (file)
@@ -17,6 +17,8 @@
   USA.
 ***/
 
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
index c53945b44c02b1d83b1a287f157db3a1aa6cb29b..b01a4fd5293a56450780d5a4b4449fb2920f4bc9 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
     pa_memchunk chunk1, chunk2, chunk3, chunk4;
     pa_memchunk silence;
 
-    pa_log_set_maximal_level(PA_LOG_DEBUG);
+    pa_log_set_level(PA_LOG_DEBUG);
 
     p = pa_mempool_new(FALSE, 0);
 
index cc21ab0345e1bc473661a6da3d2f5f0d391971c2..db8ac6e3ae7f1724fb3dddd1bf1885baec3257a4 100644 (file)
@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) {
     pa_cvolume v;
 
     oil_init();
-    pa_log_set_maximal_level(PA_LOG_DEBUG);
+    pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
 
index 3538d7d4664297b7d77135ba078bcc349be38270..3da4ee3346d047d241e2aa66024f9bbb97029c9b 100644 (file)
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
     pa_mempool *pool;
 
     oil_init();
-    pa_log_set_maximal_level(PA_LOG_DEBUG);
+    pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
 
index 2d59186760b70c545ac889073362edfd6df41fa1..da8d3756ea53e161cdac770290a6da98492e89bc 100644 (file)
@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) {
     pa_cvolume v;
 
     oil_init();
-    pa_log_set_maximal_level(PA_LOG_DEBUG);
+    pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
 
index d3da90e636467a2e919ae780ed928195aa1bfaab..6524bf9007d9f3a57f561436b3f2ad109af5c458 100644 (file)
@@ -123,7 +123,7 @@ static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata)
 }
 
 static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
-    char s[PA_SAMPLE_SPEC_SNPRINT_MAX];
+    char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
 
     if (!i) {
         fprintf(stderr, _("Failed to get server information: %s\n"), pa_strerror(pa_context_errno(c)));
@@ -131,21 +131,24 @@ static void get_server_info_callback(pa_context *c, const pa_server_info *i, voi
         return;
     }
 
-    pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec);
+    pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
+    pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map);
 
     printf(_("User name: %s\n"
-           "Host Name: %s\n"
-           "Server Name: %s\n"
-           "Server Version: %s\n"
-           "Default Sample Specification: %s\n"
-           "Default Sink: %s\n"
-           "Default Source: %s\n"
-           "Cookie: %08x\n"),
+             "Host Name: %s\n"
+             "Server Name: %s\n"
+             "Server Version: %s\n"
+             "Default Sample Specification: %s\n"
+             "Default Channel Map: %s\n"
+             "Default Sink: %s\n"
+             "Default Source: %s\n"
+             "Cookie: %08x\n"),
            i->user_name,
            i->host_name,
            i->server_name,
            i->server_version,
-           s,
+           ss,
+           cm,
            i->default_sink_name,
            i->default_source_name,
            i->cookie);