summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PROTOCOL4
-rw-r--r--configure.ac6
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am14
-rw-r--r--src/daemon/cpulimit.c2
-rw-r--r--src/daemon/daemon-conf.c22
-rwxr-xr-xsrc/daemon/default.pa.in2
-rw-r--r--src/daemon/dumpmodules.c2
-rw-r--r--src/daemon/ltdl-bind-now.c8
-rw-r--r--src/daemon/main.c42
-rw-r--r--src/modules/alsa-util.c84
-rw-r--r--src/modules/alsa-util.h6
-rw-r--r--src/modules/dbus-util.c2
-rw-r--r--src/modules/module-alsa-sink.c268
-rw-r--r--src/modules/module-alsa-source.c260
-rw-r--r--src/modules/module-device-restore.c8
-rw-r--r--src/modules/module-esound-sink.c4
-rw-r--r--src/modules/module-hal-detect.c2
-rw-r--r--src/modules/module-lirc.c6
-rw-r--r--src/modules/module-mmkbd-evdev.c6
-rw-r--r--src/modules/module-native-protocol-fd.c13
-rw-r--r--src/modules/module-protocol-stub.c7
-rw-r--r--src/modules/module-stream-restore.c42
-rw-r--r--src/modules/rtp/module-rtp-send.c23
-rw-r--r--src/pulse/context.c151
-rw-r--r--src/pulse/glib-mainloop.c4
-rw-r--r--src/pulse/internal.h7
-rw-r--r--src/pulse/introspect.c22
-rw-r--r--src/pulse/lock-autospawn.c330
-rw-r--r--src/pulse/lock-autospawn.h32
-rw-r--r--src/pulse/mainloop-api.c2
-rw-r--r--src/pulse/mainloop-signal.c2
-rw-r--r--src/pulse/stream.c38
-rw-r--r--src/pulse/subscribe.c2
-rw-r--r--src/pulse/util.c17
-rw-r--r--src/pulse/volume.c12
-rw-r--r--src/pulse/volume.h3
-rw-r--r--src/pulsecore/autoload.c2
-rw-r--r--src/pulsecore/cli-command.c8
-rw-r--r--src/pulsecore/cli-text.c8
-rw-r--r--src/pulsecore/conf-parser.c6
-rw-r--r--src/pulsecore/core-scache.c4
-rw-r--r--src/pulsecore/core-subscribe.c12
-rw-r--r--src/pulsecore/core-util.c160
-rw-r--r--src/pulsecore/core.c2
-rw-r--r--src/pulsecore/endianmacros.h11
-rw-r--r--src/pulsecore/memblock.c14
-rw-r--r--src/pulsecore/modargs.c2
-rw-r--r--src/pulsecore/module.c4
-rw-r--r--src/pulsecore/pdispatch.c2
-rw-r--r--src/pulsecore/pid.c21
-rw-r--r--src/pulsecore/protocol-esound.c18
-rw-r--r--src/pulsecore/protocol-native.c155
-rw-r--r--src/pulsecore/pstream.c2
-rw-r--r--src/pulsecore/sample-util.c199
-rw-r--r--src/pulsecore/sink-input.h18
-rw-r--r--src/pulsecore/sink.c21
-rw-r--r--src/pulsecore/sink.h20
-rw-r--r--src/pulsecore/socket-client.c4
-rw-r--r--src/pulsecore/source-output.h7
-rw-r--r--src/pulsecore/source.c21
-rw-r--r--src/pulsecore/source.h20
-rw-r--r--src/pulsecore/thread-posix.c9
-rw-r--r--src/pulsecore/tokenizer.c2
-rw-r--r--src/pulsecore/x11wrap.c4
-rw-r--r--src/tests/channelmap-test.c2
-rw-r--r--src/tests/cpulimit-test.c4
-rw-r--r--src/tests/lock-autospawn-test.c109
-rw-r--r--src/tests/mainloop-test.c2
-rw-r--r--src/tests/mcalign-test.c2
-rw-r--r--src/tests/pacat-simple.c2
-rw-r--r--src/tests/parec-simple.c2
-rw-r--r--src/tests/strlist-test.c2
-rw-r--r--src/tests/thread-mainloop-test.c2
-rw-r--r--src/tests/voltest.c2
-rw-r--r--src/utils/pacmd.c2
76 files changed, 1648 insertions, 695 deletions
diff --git a/PROTOCOL b/PROTOCOL
index 4885b3d1..581eeefa 100644
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -140,3 +140,7 @@ new message:
new message:
PA_COMMAND_EXTENSION
+
+PA_COMMAND_CREATE_RECORD_STREAM, PA_COMMAND_CREATE_PLAYBACK_STREAM:
+
+ bool volume_set at the end
diff --git a/configure.ac b/configure.ac
index c5b394dd..6978f4b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,7 @@ AC_PREREQ(2.62)
m4_define(PA_MAJOR, [0])
m4_define(PA_MINOR, [9])
-m4_define(PA_MICRO, [11])
+m4_define(PA_MICRO, [12])
AC_INIT([pulseaudio], PA_MAJOR.PA_MINOR.PA_MICRO,[mzchyfrnhqvb (at) 0pointer (dot) net])
AC_CONFIG_SRCDIR([src/daemon/main.c])
@@ -465,6 +465,10 @@ if test "x${with_caps}" != "xno"; then
fi])
fi
+#### Valgrind (optional) ####
+
+AC_CHECK_HEADERS([valgrind/memcheck.h])
+
#### pkg-config ####
# Check for pkg-config manually first, as if its not installed the
diff --git a/src/.gitignore b/src/.gitignore
index 6902eb9f..543f4e8e 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,3 +1,4 @@
+lock-autospawn-test
*.lo
*.o
*.la
diff --git a/src/Makefile.am b/src/Makefile.am
index 29a6ef47..21584ad9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -262,7 +262,8 @@ noinst_PROGRAMS = \
envelope-test \
proplist-test \
rtstutter \
- stripnul
+ stripnul \
+ lock-autospawn-test
if HAVE_SIGXCPU
noinst_PROGRAMS += \
@@ -452,6 +453,11 @@ stripnul_LDADD = $(AM_LDADD) libpulsecore.la
stripnul_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
stripnul_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBOIL_LIBS)
+lock_autospawn_test_SOURCES = tests/lock-autospawn-test.c
+lock_autospawn_test_LDADD = $(AM_LDADD) libpulsecore.la
+lock_autospawn_test_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
+lock_autospawn_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBOIL_LIBS)
+
###################################
# Client library #
###################################
@@ -535,7 +541,8 @@ libpulse_la_SOURCES = \
pulse/xmalloc.c pulse/xmalloc.h \
pulse/proplist.c pulse/proplist.h \
pulse/ext-stream-restore.c pulse/ext-stream-restore.h \
- pulse/i18n.c pulse/i18n.h
+ pulse/i18n.c pulse/i18n.h \
+ pulse/lock-autospawn.c pulse/lock-autospawn.h
# Internal stuff that is shared with libpulsecore
libpulse_la_SOURCES += \
@@ -731,7 +738,8 @@ libpulsecore_la_SOURCES = \
pulse/volume.c pulse/volume.h \
pulse/xmalloc.c pulse/xmalloc.h \
pulse/proplist.c pulse/proplist.h \
- pulse/i18n.c pulse/i18n.h
+ pulse/i18n.c pulse/i18n.h \
+ pulse/lock-autospawn.c pulse/lock-autospawn.h
# Pure core stuff (some are shared in libpulse though).
libpulsecore_la_SOURCES += \
diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index 42a71f7e..b5ed71e0 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -235,7 +235,7 @@ void pa_cpu_limit_done(void) {
#else /* HAVE_SIGXCPU */
-int pa_cpu_limit_init(PA_GCC_UNUSED pa_mainloop_api *m) {
+int pa_cpu_limit_init(pa_mainloop_api *m) {
return 0;
}
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 05c86c87..4f7470ba 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -191,7 +191,7 @@ int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *string) {
return 0;
}
-static int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
pa_assert(filename);
@@ -207,7 +207,7 @@ static int parse_log_target(const char *filename, unsigned line, const char *lva
return 0;
}
-static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_log_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
pa_assert(filename);
@@ -223,7 +223,7 @@ static int parse_log_level(const char *filename, unsigned line, const char *lval
return 0;
}
-static int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
pa_assert(filename);
@@ -239,7 +239,7 @@ static int parse_resample_method(const char *filename, unsigned line, const char
return 0;
}
-static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_rlimit(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
#ifdef HAVE_SYS_RESOURCE_H
struct pa_rlimit *r = data;
@@ -268,7 +268,7 @@ static int parse_rlimit(const char *filename, unsigned line, const char *lvalue,
return 0;
}
-static int parse_sample_format(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_sample_format(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
pa_sample_format_t f;
@@ -286,7 +286,7 @@ static int parse_sample_format(const char *filename, unsigned line, const char *
return 0;
}
-static int parse_sample_rate(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_sample_rate(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t r;
@@ -304,7 +304,7 @@ static int parse_sample_rate(const char *filename, unsigned line, const char *lv
return 0;
}
-static int parse_sample_channels(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_sample_channels(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t n;
@@ -322,7 +322,7 @@ static int parse_sample_channels(const char *filename, unsigned line, const char
return 0;
}
-static int parse_fragments(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_fragments(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t n;
@@ -340,7 +340,7 @@ static int parse_fragments(const char *filename, unsigned line, const char *lval
return 0;
}
-static int parse_fragment_size_msec(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_fragment_size_msec(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t n;
@@ -358,7 +358,7 @@ static int parse_fragment_size_msec(const char *filename, unsigned line, const c
return 0;
}
-static int parse_nice_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_nice_level(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t level;
@@ -376,7 +376,7 @@ static int parse_nice_level(const char *filename, unsigned line, const char *lva
return 0;
}
-static int parse_rtprio(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+static int parse_rtprio(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
pa_daemon_conf *c = data;
int32_t rtprio;
diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in
index cdaa8bbd..5f35e3ec 100755
--- a/src/daemon/default.pa.in
+++ b/src/daemon/default.pa.in
@@ -23,7 +23,7 @@
### Load something into the sample cache
#load-sample-lazy x11-bell /usr/share/sounds/gtk-events/activate.wav
-load-sample-lazy pulse-hotplug /usr/share/sounds/startup3.wav
+#load-sample-lazy pulse-hotplug /usr/share/sounds/startup3.wav
#load-sample-lazy pulse-coldplug /usr/share/sounds/startup3.wav
#load-sample-lazy pulse-access /usr/share/sounds/generic.wav
diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c
index 26fb8eef..9c9f1c81 100644
--- a/src/daemon/dumpmodules.c
+++ b/src/daemon/dumpmodules.c
@@ -40,7 +40,7 @@
#define PREFIX "module-"
-static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
+static void short_info(const char *name, const char *path, pa_modinfo *i) {
pa_assert(name);
pa_assert(i);
diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c
index 1215d125..42c3b231 100644
--- a/src/daemon/ltdl-bind-now.c
+++ b/src/daemon/ltdl-bind-now.c
@@ -57,8 +57,6 @@
static pa_mutex *libtool_mutex = NULL;
-PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls);
-
static void libtool_lock(void) {
pa_mutex_lock(libtool_mutex);
}
@@ -67,6 +65,10 @@ static void libtool_unlock(void) {
pa_mutex_unlock(libtool_mutex);
}
+#endif
+
+PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls);
+
static void libtool_set_error(const char *error) {
PA_STATIC_TLS_SET(libtool_tls, (char*) error);
}
@@ -75,8 +77,6 @@ static const char *libtool_get_error(void) {
return PA_STATIC_TLS_GET(libtool_tls);
}
-#endif
-
#ifdef PA_BIND_NOW
/*
diff --git a/src/daemon/main.c b/src/daemon/main.c
index ab438320..b57a74a2 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -65,6 +65,7 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
+#include <pulse/lock-autospawn.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
@@ -95,8 +96,6 @@
#include "ltdl-bind-now.h"
#include "polkit.h"
-#define AUTOSPAWN_LOCK "autospawn.lock"
-
#ifdef HAVE_LIBWRAP
/* Only one instance of these variables */
int allow_severity = LOG_INFO;
@@ -112,7 +111,7 @@ int __padsp_disabled__ = 7;
#ifdef OS_IS_WIN32
-static void message_cb(pa_mainloop_api*a, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval *tv, void *userdata) {
MSG msg;
struct timeval tvnext;
@@ -131,7 +130,7 @@ static void message_cb(pa_mainloop_api*a, pa_time_event*e, PA_GCC_UNUSED const s
#endif
-static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e, int sig, void *userdata) {
+static void signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
pa_log_info(_("Got signal %s."), pa_sig2str(sig));
switch (sig) {
@@ -346,7 +345,8 @@ int main(int argc, char *argv[]) {
struct timeval win32_tv;
#endif
char *lf = NULL;
- int autospawn_lock_fd = -1;
+ int autospawn_fd = -1;
+ pa_bool_t autospawn_locked = FALSE;
#if defined(__linux__) && defined(__OPTIMIZE__)
/*
@@ -606,7 +606,7 @@ int main(int argc, char *argv[]) {
case PA_CMD_KILL:
if (pa_pid_file_kill(SIGINT, NULL, "pulseaudio") < 0)
- pa_log(_("Failed to kill daemon."));
+ pa_log(_("Failed to kill daemon: %s"), pa_cstrerror(errno));
else
retval = 0;
@@ -656,8 +656,17 @@ int main(int argc, char *argv[]) {
* first take the autospawn lock to make things
* synchronous. */
- lf = pa_runtime_path(AUTOSPAWN_LOCK);
- autospawn_lock_fd = pa_lock_lockfile(lf);
+ if ((autospawn_fd = pa_autospawn_lock_init()) < 0) {
+ pa_log("Failed to initialize autospawn lock");
+ goto finish;
+ }
+
+ if ((pa_autospawn_lock_acquire(TRUE) < 0)) {
+ pa_log("Failed to acquire autospawn lock");
+ goto finish;
+ }
+
+ autospawn_locked = TRUE;
}
if (conf->daemonize) {
@@ -703,12 +712,15 @@ int main(int argc, char *argv[]) {
goto finish;
}
- if (autospawn_lock_fd >= 0) {
+ if (autospawn_fd >= 0) {
/* The lock file is unlocked from the parent, so we need
* to close it in the child */
- pa_close(autospawn_lock_fd);
- autospawn_lock_fd = -1;
+ pa_autospawn_lock_release();
+ pa_autospawn_lock_done(TRUE);
+
+ autospawn_locked = FALSE;
+ autospawn_fd = -1;
}
pa_assert_se(pa_close(daemon_pipe[0]) == 0);
@@ -917,8 +929,12 @@ int main(int argc, char *argv[]) {
finish:
- if (autospawn_lock_fd >= 0)
- pa_unlock_lockfile(lf, autospawn_lock_fd);
+ if (autospawn_fd >= 0) {
+ if (autospawn_locked)
+ pa_autospawn_lock_release();
+
+ pa_autospawn_lock_done(FALSE);
+ }
if (lf)
pa_xfree(lf);
diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c
index 8abf834d..e3e8c85c 100644
--- a/src/modules/alsa-util.c
+++ b/src/modules/alsa-util.c
@@ -56,7 +56,7 @@ struct pa_alsa_fdlist {
void *userdata;
};
-static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void *userdata) {
+static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
struct pa_alsa_fdlist *fdl = userdata;
int err, i;
@@ -102,7 +102,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io
snd_mixer_handle_events(fdl->mixer);
}
-static void defer_cb(pa_mainloop_api*a, PA_GCC_UNUSED pa_defer_event* e, void *userdata) {
+static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) {
struct pa_alsa_fdlist *fdl = userdata;
int num_fds, i, err;
struct pollfd *temp;
@@ -808,7 +808,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel
if (channel_map->channels > 1 &&
((playback && snd_mixer_selem_has_playback_volume_joined(elem)) ||
(!playback && snd_mixer_selem_has_capture_volume_joined(elem)))) {
- pa_log_info("ALSA device lacks independant volume controls for each channel, falling back to software volume control.");
+ pa_log_info("ALSA device lacks independant volume controls for each channel.");
return -1;
}
@@ -820,7 +820,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel
id = alsa_channel_ids[channel_map->map[i]];
if (!is_mono && id == SND_MIXER_SCHN_UNKNOWN) {
- pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer. Falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i]));
+ pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer.", pa_channel_position_to_string(channel_map->map[i]));
return -1;
}
@@ -832,7 +832,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel
if ((playback && (!snd_mixer_selem_has_playback_channel(elem, id) || (is_mono && !snd_mixer_selem_is_playback_mono(elem)))) ||
(!playback && (!snd_mixer_selem_has_capture_channel(elem, id) || (is_mono && !snd_mixer_selem_is_capture_mono(elem))))) {
- pa_log_info("ALSA device lacks separate volumes control for channel '%s', falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i]));
+ pa_log_info("ALSA device lacks separate volumes control for channel '%s'", pa_channel_position_to_string(channel_map->map[i]));
return -1;
}
@@ -850,56 +850,6 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel
return 0;
}
-void pa_alsa_0dB_playback(snd_mixer_elem_t *elem) {
- long min, max, v;
-
- pa_assert(elem);
-
- /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use
- * raw volume levels and fix them to 75% */
-
- if (snd_mixer_selem_set_playback_dB_all(elem, 0, -1) >= 0)
- return;
-
- if (snd_mixer_selem_set_playback_dB_all(elem, 0, 1) >= 0)
- return;
-
- if (snd_mixer_selem_get_playback_volume_range(elem, &min, &max) < 0)
- return;
-
- v = min + ((max - min) * 3) / 4; /* 75% */
-
- if (v <= min)
- v = max;
-
- snd_mixer_selem_set_playback_volume_all(elem, v);
-}
-
-void pa_alsa_0dB_capture(snd_mixer_elem_t *elem) {
- long min, max, v;
-
- pa_assert(elem);
-
- /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use
- * raw volume levels and fix them to 75% */
-
- if (snd_mixer_selem_set_capture_dB_all(elem, 0, -1) >= 0)
- return;
-
- if (snd_mixer_selem_set_capture_dB_all(elem, 0, 1) >= 0)
- return;
-
- if (snd_mixer_selem_get_capture_volume_range(elem, &min, &max) < 0)
- return;
-
- v = min + ((max - min) * 3) / 4; /* 75% */
-
- if (v <= min)
- v = max;
-
- snd_mixer_selem_set_capture_volume_all(elem, v);
-}
-
void pa_alsa_dump(snd_pcm_t *pcm) {
int err;
snd_output_t *out;
@@ -1117,3 +1067,27 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) {
return item;
}
+
+pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t) {
+ unsigned i;
+
+ pa_assert(r);
+ pa_assert(t);
+ pa_assert(r->channels == t->channels);
+
+ for (i = 0; i < r->channels; i++) {
+ double a, b, c;
+
+ a = pa_sw_volume_to_linear(r->values[i]); /* the hw volume */
+ b = pa_sw_volume_to_linear(t->values[i]); /* the intended volume */
+
+ if (a <= 0)
+ c = 0;
+ else
+ c = b / a;
+
+ r->values[i] = pa_sw_volume_from_linear(c);
+ }
+
+ return r;
+}
diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h
index 4de8bcd2..7991a107 100644
--- a/src/modules/alsa-util.h
+++ b/src/modules/alsa-util.h
@@ -26,6 +26,7 @@
#include <asoundlib.h>
#include <pulse/sample.h>
+#include <pulse/volume.h>
#include <pulse/mainloop-api.h>
#include <pulse/channelmap.h>
#include <pulse/proplist.h>
@@ -79,9 +80,6 @@ snd_pcm_t *pa_alsa_open_by_device_string(
int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback);
-void pa_alsa_0dB_playback(snd_mixer_elem_t *elem);
-void pa_alsa_0dB_capture(snd_mixer_elem_t *elem);
-
void pa_alsa_dump(snd_pcm_t *pcm);
void pa_alsa_dump_status(snd_pcm_t *pcm);
@@ -94,4 +92,6 @@ 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);
+pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t);
+
#endif
diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c
index 8e0066bc..c9c32a15 100644
--- a/src/modules/dbus-util.c
+++ b/src/modules/dbus-util.c
@@ -90,7 +90,7 @@ static pa_io_event_flags_t get_watch_flags(DBusWatch *watch) {
}
/* pa_io_event_cb_t IO event handler */
-static void handle_io_event(PA_GCC_UNUSED pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
+static void handle_io_event(pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
unsigned int flags = 0;
DBusWatch *watch = userdata;
diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c
index aad6801e..8980ba24 100644
--- a/src/modules/module-alsa-sink.c
+++ b/src/modules/module-alsa-sink.c
@@ -28,6 +28,10 @@
#include <asoundlib.h>
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
+
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulse/timeval.h>
@@ -68,8 +72,7 @@ PA_MODULE_USAGE(
"mmap=<enable memory mapping?> "
"tsched=<enable system timer based scheduling mode?> "
"tsched_buffer_size=<buffer size when using timer based scheduling> "
- "tsched_buffer_watermark=<lower fill watermark> "
- "mixer_reset=<reset hw volume and mute settings to sane defaults when falling back to software?>");
+ "tsched_buffer_watermark=<lower fill watermark>");
static const char* const valid_modargs[] = {
"sink_name",
@@ -85,7 +88,6 @@ static const char* const valid_modargs[] = {
"tsched",
"tsched_buffer_size",
"tsched_buffer_watermark",
- "mixer_reset",
NULL
};
@@ -112,6 +114,8 @@ struct userdata {
long hw_volume_max, hw_volume_min;
long hw_dB_max, hw_dB_min;
pa_bool_t hw_dB_supported;
+ pa_bool_t mixer_seperate_channels;
+ pa_cvolume hardware_volume;
size_t frame_size, fragment_size, hwbuf_size, tsched_watermark;
unsigned nfragments;
@@ -239,7 +243,7 @@ static size_t check_left_to_play(struct userdata *u, snd_pcm_sframes_t n) {
static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) {
int work_done = 0;
- pa_usec_t max_sleep_usec, process_usec;
+ pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_play;
pa_assert(u);
@@ -354,7 +358,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) {
static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) {
int work_done = 0;
- pa_usec_t max_sleep_usec, process_usec;
+ pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_play;
pa_assert(u);
@@ -737,8 +741,8 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
return 0;
if (mask & SND_CTL_EVENT_MASK_VALUE) {
- pa_sink_get_volume(u->sink);
- pa_sink_get_mute(u->sink);
+ pa_sink_get_volume(u->sink, TRUE);
+ pa_sink_get_mute(u->sink, TRUE);
}
return 0;
@@ -747,30 +751,68 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
static int sink_get_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
int err;
- int i;
+ unsigned i;
+ pa_cvolume r;
+ char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
pa_assert(u->mixer_elem);
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
+ if (u->mixer_seperate_channels) {
- pa_assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, u->mixer_map[i]));
+ r.channels = s->sample_spec.channels;
- if (u->hw_dB_supported) {
+ for (i = 0; i < s->sample_spec.channels; i++) {
+ long alsa_vol;
- if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) >= 0) {
- s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0);
- continue;
- }
+ if (u->hw_dB_supported) {
+
+ if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
+#endif
+
+ r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ } else {
- u->hw_dB_supported = FALSE;
+ if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+ r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ }
}
- if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ } else {
+ long alsa_vol;
+
+ pa_assert(u->hw_dB_supported);
+
+ if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
+#endif
+
+ pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ }
+
+ pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
+
+ if (!pa_cvolume_equal(&u->hardware_volume, &r)) {
+
+ u->hardware_volume = s->volume = r;
+
+ if (u->hw_dB_supported) {
+ pa_cvolume reset;
+
+ /* Hmm, so the hardware volume changed, let's reset our software volume */
+
+ pa_cvolume_reset(&reset, s->sample_spec.channels);
+ pa_sink_set_soft_volume(s, &reset);
+ }
}
return 0;
@@ -784,45 +826,90 @@ fail:
static int sink_set_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
int err;
- int i;
+ unsigned i;
+ pa_cvolume r;
pa_assert(u);
pa_assert(u->mixer_elem);
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
- pa_volume_t vol;
+ if (u->mixer_seperate_channels) {
- pa_assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, u->mixer_map[i]));
+ r.channels = s->sample_spec.channels;
- vol = PA_MIN(s->volume.values[i], PA_VOLUME_NORM);
+ for (i = 0; i < s->sample_spec.channels; i++) {
+ long alsa_vol;
+ pa_volume_t vol;
- if (u->hw_dB_supported) {
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
+ vol = s->volume.values[i];
- if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, -1)) >= 0) {
+ if (u->hw_dB_supported) {
- if (snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0)
- s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0);
+ alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
- continue;
- }
+ if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
+ goto fail;
+
+ if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
- u->hw_dB_supported = FALSE;
+ r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ } else {
+
+ alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
+
+ if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
+ goto fail;
+
+ if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+ r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ }
}
- alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
+ } else {
+ pa_volume_t vol;
+ long alsa_vol;
+
+ pa_assert(u->hw_dB_supported);
+
+ vol = pa_cvolume_max(&s->volume);
- if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
+ alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
+
+ if ((err = snd_mixer_selem_set_playback_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
+ goto fail;
+
+ if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- if (snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0)
- s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
}
+ u->hardware_volume = r;
+
+ if (u->hw_dB_supported) {
+ char t[PA_CVOLUME_SNPRINT_MAX];
+
+ /* Match exactly what the user requested by software */
+
+ pa_alsa_volume_divide(&r, &s->volume);
+ pa_sink_set_soft_volume(s, &r);
+
+ pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume));
+ pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
+ pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
+
+ } else
+
+ /* We can't match exactly what the user requested, hence let's
+ * at least tell the user about it */
+
+ s->volume = r;
+
return 0;
fail:
@@ -974,7 +1061,7 @@ static void thread_func(void *userdata) {
/* Render some data and write it to the dsp */
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
int work_done;
- pa_usec_t sleep_usec;
+ pa_usec_t sleep_usec = 0;
if (u->sink->thread_info.rewind_requested)
if (process_rewind(u) < 0)
@@ -1100,7 +1187,7 @@ int pa__init(pa_module*m) {
const char *name;
char *name_buf = NULL;
pa_bool_t namereg_fail;
- pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, mixer_reset = TRUE;
+ pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d;
pa_usec_t usec;
pa_sink_new_data data;
@@ -1157,11 +1244,6 @@ int pa__init(pa_module*m) {
use_tsched = FALSE;
}
- if (pa_modargs_get_value_boolean(ma, "mixer_reset", &mixer_reset) < 0) {
- pa_log("Failed to parse mixer_reset argument.");
- goto fail;
- }
-
u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
@@ -1322,6 +1404,8 @@ int pa__init(pa_module*m) {
u->hw_dB_supported = FALSE;
u->hw_dB_min = u->hw_dB_max = 0;
u->hw_volume_min = u->hw_volume_max = 0;
+ u->mixer_seperate_channels = FALSE;
+ pa_cvolume_mute(&u->hardware_volume, u->sink->sample_spec.channels);
if (use_tsched)
fix_tsched_watermark(u);
@@ -1349,76 +1433,56 @@ int pa__init(pa_module*m) {
if (u->mixer_handle) {
pa_assert(u->mixer_elem);
- if (snd_mixer_selem_has_playback_volume(u->mixer_elem))
-
- if (pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, TRUE) >= 0 &&
- snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) >= 0) {
-
- pa_bool_t suitable = TRUE;
+ if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) {
+ pa_bool_t suitable = TRUE;
+ if (snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) {
+ pa_log_info("Failed to get volume range. Falling back to software volume control.");
+ suitable = FALSE;
+ } else {
pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
+ pa_assert(u->hw_volume_min < u->hw_volume_max);
+ }
- if (u->hw_volume_min > u->hw_volume_max) {
-
- pa_log_info("Minimal volume %li larger than maximum volume %li. Strange stuff Falling back to software volume control.", u->hw_volume_min, u->hw_volume_max);
- suitable = FALSE;
-
- } else if (u->hw_volume_max - u->hw_volume_min < 3) {
-
- pa_log_info("Device has less than 4 volume levels. Falling back to software volume control.");
- suitable = FALSE;
-
- } else if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) >= 0) {
-
- /* u->hw_dB_max = 0; u->hw_dB_min = -3000; Use this to make valgrind shut up */
-
- pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0);
-
- /* Let's see if this thing actually is useful for muting */
- if (u->hw_dB_min > -6000) {
- pa_log_info("Device cannot attenuate for more than -60 dB (only %0.2f dB supported), falling back to software volume control.", ((double) u->hw_dB_min) / 100);
-
- suitable = FALSE;
- } else if (u->hw_dB_max < 0) {
-
- pa_log_info("Device is still attenuated at maximum volume setting (%0.2f dB is maximum). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_max) / 100);
- suitable = FALSE;
+ if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
+ pa_log_info("Mixer doesn't support dB information.");
+ else {
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min));
+ VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
+#endif
- } else if (u->hw_dB_min >= u->hw_dB_max) {
+ pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0);
+ pa_assert(u->hw_dB_min < u->hw_dB_max);
+ u->hw_dB_supported = TRUE;
+ }
- pa_log_info("Minimal dB (%0.2f) larger or equal to maximum dB (%0.2f). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_min) / 100, ((double) u->hw_dB_max) / 100);
- suitable = FALSE;
+ if (suitable &&
+ !u->hw_dB_supported &&
+ u->hw_volume_max - u->hw_volume_min < 3) {
- } else {
+ pa_log_info("Device doesn't do dB volume and has less than 4 volume levels. Falling back to software volume control.");
+ suitable = FALSE;
+ }
- if (u->hw_dB_max > 0) {
- /* dB > 0 means overamplification, and clipping, we don't want that here */
- pa_log_info("Device can do overamplification for %0.2f dB. Limiting to 0 db", ((double) u->hw_dB_max) / 100);
- u->hw_dB_max = 0;
- }
+ if (suitable) {
+ u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, TRUE) >= 0;
- u->hw_dB_supported = TRUE;
- }
- }
+ u->sink->get_volume = sink_get_volume_cb;
+ u->sink->set_volume = sink_set_volume_cb;
+ u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SINK_DECIBEL_VOLUME : 0);
+ pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
- if (suitable) {
- u->sink->get_volume = sink_get_volume_cb;
- u->sink->set_volume = sink_set_volume_cb;
- u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SINK_DECIBEL_VOLUME : 0);
- pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
-
- } else if (mixer_reset) {
- pa_log_info("Using software volume control. Trying to reset sound card to 0 dB.");
- pa_alsa_0dB_playback(u->mixer_elem);
- } else
- pa_log_info("Using software volume control. Leaving hw mixer controls untouched.");
- }
+ } else
+ pa_log_info("Using software volume control.");
+ }
if (snd_mixer_selem_has_playback_switch(u->mixer_elem)) {
u->sink->get_mute = sink_get_mute_cb;
u->sink->set_mute = sink_set_mute_cb;
u->sink->flags |= PA_SINK_HW_MUTE_CTRL;
- }
+ } else
+ pa_log_info("Using software mute control.");
u->mixer_fdl = pa_alsa_fdlist_new();
diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c
index 1cc467d9..9cf5aaf6 100644
--- a/src/modules/module-alsa-source.c
+++ b/src/modules/module-alsa-source.c
@@ -28,6 +28,10 @@
#include <asoundlib.h>
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
+
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulse/timeval.h>
@@ -69,8 +73,7 @@ PA_MODULE_USAGE(
"mmap=<enable memory mapping?> "
"tsched=<enable system timer based scheduling mode?> "
"tsched_buffer_size=<buffer size when using timer based scheduling> "
- "tsched_buffer_watermark=<upper fill watermark> "
- "mixer_reset=<reset hw volume and mute settings to sane defaults when falling back to software?>");
+ "tsched_buffer_watermark=<upper fill watermark>");
static const char* const valid_modargs[] = {
"source_name",
@@ -86,7 +89,6 @@ static const char* const valid_modargs[] = {
"tsched",
"tsched_buffer_size",
"tsched_buffer_watermark",
- "mixer_reset",
NULL
};
@@ -113,6 +115,9 @@ struct userdata {
long hw_volume_max, hw_volume_min;
long hw_dB_max, hw_dB_min;
pa_bool_t hw_dB_supported;
+ pa_bool_t mixer_seperate_channels;
+
+ pa_cvolume hardware_volume;
size_t frame_size, fragment_size, hwbuf_size, tsched_watermark;
unsigned nfragments;
@@ -234,7 +239,7 @@ static size_t check_left_to_record(struct userdata *u, snd_pcm_sframes_t n) {
static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) {
int work_done = 0;
- pa_usec_t max_sleep_usec, process_usec;
+ pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_record;
pa_assert(u);
@@ -331,7 +336,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) {
static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) {
int work_done = 0;
- pa_usec_t max_sleep_usec, process_usec;
+ pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_record;
pa_assert(u);
@@ -680,8 +685,8 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
return 0;
if (mask & SND_CTL_EVENT_MASK_VALUE) {
- pa_source_get_volume(u->source);
- pa_source_get_mute(u->source);
+ pa_source_get_volume(u->source, TRUE);
+ pa_source_get_mute(u->source, TRUE);
}
return 0;
@@ -690,30 +695,68 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
static int source_get_volume_cb(pa_source *s) {
struct userdata *u = s->userdata;
int err;
- int i;
+ unsigned i;
+ pa_cvolume r;
+ char t[PA_CVOLUME_SNPRINT_MAX];
pa_assert(u);
pa_assert(u->mixer_elem);
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
+ if (u->mixer_seperate_channels) {
- pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i]));
+ r.channels = s->sample_spec.channels;
- if (u->hw_dB_supported) {
+ for (i = 0; i < s->sample_spec.channels; i++) {
+ long alsa_vol;
- if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) >= 0) {
- s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0);
- continue;
- }
+ if (u->hw_dB_supported) {
+
+ if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
+#endif
- u->hw_dB_supported = FALSE;
+ r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ } else {
+
+ if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+ r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ }
}
- if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ } else {
+ long alsa_vol;
+
+ pa_assert(u->hw_dB_supported);
+
+ if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
+#endif
+
+ pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ }
+
+ pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
+
+ if (!pa_cvolume_equal(&u->hardware_volume, &r)) {
+
+ u->hardware_volume = s->volume = r;
+
+ if (u->hw_dB_supported) {
+ pa_cvolume reset;
+
+ /* Hmm, so the hardware volume changed, let's reset our software volume */
+
+ pa_cvolume_reset(&reset, s->sample_spec.channels);
+ pa_source_set_soft_volume(s, &reset);
+ }
}
return 0;
@@ -727,45 +770,90 @@ fail:
static int source_set_volume_cb(pa_source *s) {
struct userdata *u = s->userdata;
int err;
- int i;
+ unsigned i;
+ pa_cvolume r;
pa_assert(u);
pa_assert(u->mixer_elem);
- for (i = 0; i < s->sample_spec.channels; i++) {
- long alsa_vol;
- pa_volume_t vol;
+ if (u->mixer_seperate_channels) {
- pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i]));
+ r.channels = s->sample_spec.channels;
- vol = PA_MIN(s->volume.values[i], PA_VOLUME_NORM);
+ for (i = 0; i < s->sample_spec.channels; i++) {
+ long alsa_vol;
+ pa_volume_t vol;
- if (u->hw_dB_supported) {
- alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
+ vol = s->volume.values[i];
+ if (u->hw_dB_supported) {
- if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, -1)) >= 0) {
+ alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
- if (snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0)
- s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0);
+ if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
+ goto fail;
- continue;
- }
+ if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+ r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ } else {
+
+ alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
+
+ if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
+ goto fail;
- u->hw_dB_supported = FALSE;
+ if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
+ goto fail;
+
+ r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ }
}
- alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
- alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
+ } else {
+ pa_volume_t vol;
+ long alsa_vol;
+
+ pa_assert(u->hw_dB_supported);
+
+ vol = pa_cvolume_max(&s->volume);
+
+ alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
+
+ if ((err = snd_mixer_selem_set_capture_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
+ goto fail;
- if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0)
+ if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- if (snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0)
- s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
+ pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
}
+ u->hardware_volume = r;
+
+ if (u->hw_dB_supported) {
+ char t[PA_CVOLUME_SNPRINT_MAX];
+
+ /* Match exactly what the user requested by software */
+
+ pa_alsa_volume_divide(&r, &s->volume);
+ pa_source_set_soft_volume(s, &r);
+
+ pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume));
+ pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
+ pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
+
+ } else
+
+ /* We can't match exactly what the user requested, hence let's
+ * at least tell the user about it */
+
+ s->volume = r;
+
return 0;
fail:
@@ -837,7 +925,7 @@ static void thread_func(void *userdata) {
/* Read some data and pass it to the sources */
if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
int work_done = 0;
- pa_usec_t sleep_usec;
+ pa_usec_t sleep_usec = 0;
if (u->use_mmap)
work_done = mmap_read(u, &sleep_usec);
@@ -932,7 +1020,7 @@ int pa__init(pa_module*m) {
const char *name;
char *name_buf = NULL;
pa_bool_t namereg_fail;
- pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, mixer_reset = TRUE;
+ pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d;
pa_source_new_data data;
snd_pcm_info_alloca(&pcm_info);
@@ -988,11 +1076,6 @@ int pa__init(pa_module*m) {
use_tsched = FALSE;
}
- if (pa_modargs_get_value_boolean(ma, "mixer_reset", &mixer_reset) < 0) {
- pa_log("Failed to parse mixer_reset argument.");
- goto fail;
- }
-
u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
@@ -1146,6 +1229,8 @@ int pa__init(pa_module*m) {
u->hw_dB_supported = FALSE;
u->hw_dB_min = u->hw_dB_max = 0;
u->hw_volume_min = u->hw_volume_max = 0;
+ u->mixer_seperate_channels = FALSE;
+ pa_cvolume_mute(&u->hardware_volume, u->source->sample_spec.channels);
if (use_tsched)
fix_tsched_watermark(u);
@@ -1168,67 +1253,56 @@ int pa__init(pa_module*m) {
if (u->mixer_handle) {
pa_assert(u->mixer_elem);
- if (snd_mixer_selem_has_capture_volume(u->mixer_elem))
- if (pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0 &&
- snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) >= 0) {
-
- pa_bool_t suitable = TRUE;
+ if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) {
+ pa_bool_t suitable = TRUE;
+ if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) {
+ pa_log_info("Failed to get volume range. Falling back to software volume control.");
+ suitable = FALSE;
+ } else {
pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
+ pa_assert(u->hw_volume_min < u->hw_volume_max);
+ }
- if (u->hw_volume_min > u->hw_volume_max) {
-
- pa_log_info("Minimal volume %li larger than maximum volume %li. Strange stuff Falling back to software volume control.", u->hw_volume_min, u->hw_volume_max);
- suitable = FALSE;
-
- } else if (u->hw_volume_max - u->hw_volume_min < 3) {
-
- pa_log_info("Device has less than 4 volume levels. Falling back to software volume control.");
- suitable = FALSE;
-
- } else if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) >= 0) {
-
- pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0);
-
- /* Let's see if this thing actually is useful for muting */
- if (u->hw_dB_min > -6000) {
- pa_log_info("Device cannot attenuate for more than -60 dB (only %0.2f dB supported), falling back to software volume control.", ((double) u->hw_dB_min) / 100);
-
- suitable = FALSE;
- } else if (u->hw_dB_max < 0) {
-
- pa_log_info("Device is still attenuated at maximum volume setting (%0.2f dB is maximum). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_max) / 100);
- suitable = FALSE;
-
- } else if (u->hw_dB_min >= u->hw_dB_max) {
+ if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
+ pa_log_info("Mixer doesn't support dB information.");
+ else {
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min));
+ VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
+#endif
- pa_log_info("Minimal dB (%0.2f) larger or equal to maximum dB (%0.2f). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_min) / 100, ((double) u->hw_dB_max) / 100);
- suitable = FALSE;
+ pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0);
+ pa_assert(u->hw_dB_min < u->hw_dB_max);
+ u->hw_dB_supported = TRUE;
+ }
- } else
- u->hw_dB_supported = TRUE;
- }
+ if (suitable &&
+ !u->hw_dB_supported &&
+ u->hw_volume_max - u->hw_volume_min < 3) {
- if (suitable) {
- u->source->get_volume = source_get_volume_cb;
- u->source->set_volume = source_set_volume_cb;
- u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0);
- pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
+ pa_log_info("Device has less than 4 volume levels. Falling back to software volume control.");
+ suitable = FALSE;
+ }
- } else if (mixer_reset) {
- pa_log_info("Using software volume control. Trying to reset sound card to 0 dB.");
- pa_alsa_0dB_capture(u->mixer_elem);
- } else
- pa_log_info("Using software volume control. Leaving hw mixer controls untouched.");
- }
+ if (suitable) {
+ u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0;
+ u->source->get_volume = source_get_volume_cb;
+ u->source->set_volume = source_set_volume_cb;
+ u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0);
+ pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
+ } else
+ pa_log_info("Using software volume control.");
+ }
if (snd_mixer_selem_has_capture_switch(u->mixer_elem)) {
u->source->get_mute = source_get_mute_cb;
u->source->set_mute = source_set_mute_cb;
u->source->flags |= PA_SOURCE_HW_MUTE_CTRL;
- }
+ } else
+ pa_log_info("Using software mute control.");
u->mixer_fdl = pa_alsa_fdlist_new();
diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c
index 3d731f12..f7d82e4d 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -179,8 +179,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
name = pa_sprintf_malloc("sink:%s", sink->name);
entry.channel_map = sink->channel_map;
- entry.volume = *pa_sink_get_volume(sink);
- entry.muted = pa_sink_get_mute(sink);
+ entry.volume = *pa_sink_get_volume(sink, FALSE);
+ entry.muted = pa_sink_get_mute(sink, FALSE);
} else {
pa_source *source;
@@ -192,8 +192,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
name = pa_sprintf_malloc("source:%s", source->name);
entry.channel_map = source->channel_map;
- entry.volume = *pa_source_get_volume(source);
- entry.muted = pa_source_get_mute(source);
+ entry.volume = *pa_source_get_volume(source, FALSE);
+ entry.muted = pa_source_get_mute(source, FALSE);
}
if ((old = read_entry(u, name))) {
diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index f748808e..e0c07d56 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -468,7 +468,7 @@ static int do_read(struct userdata *u) {
return 0;
}
-static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void*userdata) {
+static void io_callback(pa_iochannel *io, void*userdata) {
struct userdata *u = userdata;
pa_assert(u);
@@ -483,7 +483,7 @@ static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void*userdata) {
}
}
-static void on_connection(PA_GCC_UNUSED pa_socket_client *c, pa_iochannel*io, void *userdata) {
+static void on_connection(pa_socket_client *c, pa_iochannel*io, void *userdata) {
struct userdata *u = userdata;
pa_socket_client_unref(u->client);
diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c
index caa7a1fa..ce766258 100644
--- a/src/modules/module-hal-detect.c
+++ b/src/modules/module-hal-detect.c
@@ -108,7 +108,7 @@ static void hal_device_free(struct device* d) {
pa_xfree(d);
}
-static void hal_device_free_cb(void *d, PA_GCC_UNUSED void *data) {
+static void hal_device_free_cb(void *d, void *data) {
hal_device_free(d);
}
diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c
index f34f7be3..97e97dc7 100644
--- a/src/modules/module-lirc.c
+++ b/src/modules/module-lirc.c
@@ -65,7 +65,7 @@ struct userdata {
static int lirc_in_use = 0;
-static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {
+static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) {
struct userdata *u = userdata;
char *name = NULL, *code = NULL;
@@ -122,7 +122,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
pa_log("Failed to get sink '%s'", u->sink_name);
else {
int i;
- pa_cvolume cv = *pa_sink_get_volume(s);
+ pa_cvolume cv = *pa_sink_get_volume(s, FALSE);
#define DELTA (PA_VOLUME_NORM/20)
@@ -159,7 +159,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
case MUTE_TOGGLE:
- pa_sink_set_mute(s, !pa_sink_get_mute(s));
+ pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE));
break;
case INVALID:
diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c
index 7da77c0d..21f176a4 100644
--- a/src/modules/module-mmkbd-evdev.c
+++ b/src/modules/module-mmkbd-evdev.c
@@ -76,7 +76,7 @@ struct userdata {
pa_module *module;
};
-static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {
+static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) {
struct userdata *u = userdata;
pa_assert(io);
@@ -113,7 +113,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
pa_log("Failed to get sink '%s'", u->sink_name);
else {
int i;
- pa_cvolume cv = *pa_sink_get_volume(s);
+ pa_cvolume cv = *pa_sink_get_volume(s, FALSE);
#define DELTA (PA_VOLUME_NORM/20)
@@ -142,7 +142,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
case MUTE_TOGGLE:
- pa_sink_set_mute(s, !pa_sink_get_mute(s));
+ pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE));
break;
case INVALID:
diff --git a/src/modules/module-native-protocol-fd.c b/src/modules/module-native-protocol-fd.c
index fa9c0e4f..f17f435a 100644
--- a/src/modules/module-native-protocol-fd.c
+++ b/src/modules/module-native-protocol-fd.c
@@ -48,7 +48,8 @@ static const char* const valid_modargs[] = {
int pa__init(pa_module*m) {
pa_iochannel *io;
pa_modargs *ma;
- int fd, r = -1;
+ int32_t fd;
+ int r = -1;
pa_native_options *options = NULL;
pa_assert(m);
@@ -63,18 +64,16 @@ int pa__init(pa_module*m) {
goto finish;
}
- options = pa_native_options_new();
- options->module = m;
- options->auth_anonymous = TRUE;
+ m->userdata = pa_native_protocol_get(m->core);
io = pa_iochannel_new(m->core->mainloop, fd, fd);
- m->userdata = pa_native_protocol_get(m->core);
+ options = pa_native_options_new();
+ options->module = m;
+ options->auth_anonymous = TRUE;
pa_native_protocol_connect(m->userdata, io, options);
- pa_native_options_unref(options);
-
r = 0;
finish:
diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c
index 8136c6fc..4fe439f9 100644
--- a/src/modules/module-protocol-stub.c
+++ b/src/modules/module-protocol-stub.c
@@ -260,7 +260,7 @@ int pa__init(pa_module*m) {
goto fail;
}
- u = pa_xnew0(struct userdata, 1);
+ m->userdata = u = pa_xnew0(struct userdata, 1);
u->module = m;
#if defined(USE_PROTOCOL_SIMPLE)
@@ -368,8 +368,6 @@ int pa__init(pa_module*m) {
# endif
#endif
- m->userdata = u;
-
if (ma)
pa_modargs_free(ma);
@@ -390,7 +388,8 @@ void pa__done(pa_module*m) {
pa_assert(m);
- u = m->userdata;
+ if (!(u = m->userdata))
+ return;
#if defined(USE_PROTOCOL_SIMPLE)
if (u->simple_protocol) {
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index ec4e7c79..7bbb47d5 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -306,8 +306,11 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
if (u->restore_device &&
(s = pa_namereg_get(c, e->device, PA_NAMEREG_SINK, TRUE))) {
- pa_log_info("Restoring device for stream %s.", name);
- new_data->sink = s;
+ if (!new_data->sink) {
+ pa_log_info("Restoring device for stream %s.", name);
+ new_data->sink = s;
+ } else
+ pa_log_info("Not restore device for stream %s, because already set.", name);
}
pa_xfree(e);
@@ -330,13 +333,20 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
if ((e = read_entry(u, name))) {
if (u->restore_volume) {
- pa_log_info("Restoring volume for sink input %s.", name);
- pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map));
+
+ if (!new_data->volume_is_set) {
+ pa_log_info("Restoring volume for sink input %s.", name);
+ pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map));
+ } else
+ pa_log_debug("Not restoring volume for sink input %s, because already set.", name);
}
if (u->restore_muted) {
- pa_log_info("Restoring mute state for sink input %s.", name);
- pa_sink_input_new_data_set_muted(new_data, e->muted);
+ if (!new_data->muted_is_set) {
+ pa_log_info("Restoring mute state for sink input %s.", name);
+ pa_sink_input_new_data_set_muted(new_data, e->muted);
+ } else
+ pa_log_debug("Not restoring mute state for sink input %s, because already set.", name);
}
pa_xfree(e);
@@ -360,10 +370,14 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
pa_source *s;
if (u->restore_device &&
+ !new_data->direct_on_input &&
(s = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE, TRUE))) {
- pa_log_info("Restoring device for stream %s.", name);
- new_data->source = s;
+ if (!new_data->source) {
+ pa_log_info("Restoring device for stream %s.", name);
+ new_data->source = s;
+ } else
+ pa_log_info("Not restroing device for stream %s, because already set", name);
}
pa_xfree(e);
@@ -408,7 +422,7 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
char *n;
pa_sink *s;
- if (!(n = get_name(si->proplist, "sink_input")))
+ if (!(n = get_name(si->proplist, "sink-input")))
continue;
if (strcmp(name, n)) {
@@ -417,8 +431,9 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
}
if (u->restore_volume) {
+ pa_cvolume v = e->volume;
pa_log_info("Restoring volume for sink input %s.", name);
- pa_sink_input_set_volume(si, pa_cvolume_remap(&e->volume, &e->channel_map, &si->channel_map));
+ pa_sink_input_set_volume(si, pa_cvolume_remap(&v, &e->channel_map, &si->channel_map));
}
if (u->restore_muted) {
@@ -490,7 +505,7 @@ static void dump_database(struct userdata *u) {
static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connection *c, uint32_t tag, pa_tagstruct *t) {
struct userdata *u;
uint32_t command;
- pa_tagstruct *reply;
+ pa_tagstruct *reply = NULL;
pa_assert(p);
pa_assert(m);
@@ -552,7 +567,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
case SUBCOMMAND_WRITE: {
uint32_t mode;
- pa_bool_t apply_immediately;
+ pa_bool_t apply_immediately = FALSE;
if (pa_tagstruct_getu32(t, &mode) < 0 ||
pa_tagstruct_get_boolean(t, &apply_immediately) < 0)
@@ -571,6 +586,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
pa_bool_t muted;
struct entry entry;
datum key, data;
+ int k;
memset(&entry, 0, sizeof(entry));
@@ -593,7 +609,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
data.dptr = (void*) &entry;
data.dsize = sizeof(entry);
- if (gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT) == 1)
+ if ((k = gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT)) == 0)
if (apply_immediately)
apply_entry(u, name, &entry);
}
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c
index 5e542253..1423cbc1 100644
--- a/src/modules/rtp/module-rtp-send.c
+++ b/src/modules/rtp/module-rtp-send.c
@@ -67,10 +67,12 @@ PA_MODULE_USAGE(
"destination=<destination IP address> "
"port=<port number> "
"mtu=<maximum transfer unit> "
- "loop=<loopback to local host?>"
+ "loop=<loopback to local host?> "
+ "ttl=<ttl value>"
);
#define DEFAULT_PORT 46000
+#define DEFAULT_TTL 1
#define SAP_PORT 9875
#define DEFAULT_DESTINATION "224.0.0.56"
#define MEMBLOCKQ_MAXLENGTH (1024*170)
@@ -86,6 +88,7 @@ static const char* const valid_modargs[] = {
"port",
"mtu" ,
"loop",
+ "ttl",
NULL
};
@@ -167,6 +170,7 @@ int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
const char *dest;
uint32_t port = DEFAULT_PORT, mtu;
+ uint32_t ttl = DEFAULT_TTL;
int af, fd = -1, sap_fd = -1;
pa_source *s;
pa_sample_spec ss;
@@ -235,6 +239,11 @@ int pa__init(pa_module*m) {
if (port & 1)
pa_log_warn("Port number not even as suggested in RFC3550!");
+ if (pa_modargs_get_value_u32(ma, "ttl", &ttl) < 0 || ttl < 1 || ttl > 0xFF) {
+ pa_log("ttl= expects a numerical argument between 1 and 255.");
+ goto fail;
+ }
+
dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION);
if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
@@ -279,6 +288,15 @@ int pa__init(pa_module*m) {
goto fail;
}
+ if (ttl != DEFAULT_TTL) {
+ int _ttl = (int) ttl;
+
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &_ttl, sizeof(_ttl)) < 0) {
+ pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno));
+ goto fail;
+ }
+ }
+
/* If the socket queue is full, let's drop packets */
pa_make_fd_nonblock(fd);
pa_make_udp_socket_low_delay(fd);
@@ -290,6 +308,7 @@ int pa__init(pa_module*m) {
pa_proplist_sets(data.proplist, "rtp.destination", dest);
pa_proplist_setf(data.proplist, "rtp.mtu", "%lu", (unsigned long) mtu);
pa_proplist_setf(data.proplist, "rtp.port", "%lu", (unsigned long) port);
+ pa_proplist_setf(data.proplist, "rtp.ttl", "%lu", (unsigned long) ttl);
data.driver = __FILE__;
data.module = m;
data.source = s;
@@ -342,7 +361,7 @@ int pa__init(pa_module*m) {
pa_rtp_context_init_send(&u->rtp_context, fd, m->core->cookie, payload, pa_frame_size(&ss));
pa_sap_context_init_send(&u->sap_context, sap_fd, p);
- pa_log_info("RTP stream initialized with mtu %u on %s:%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, u->rtp_context.ssrc, payload, u->rtp_context.sequence);
+ pa_log_info("RTP stream initialized with mtu %u on %s:%u ttl=%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, ttl, u->rtp_context.ssrc, payload, u->rtp_context.sequence);
pa_log_info("SDP-Data:\n%s\nEOF", p);
pa_sap_send(&u->sap_context, 0);
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 5be4078b..ed6415b0 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -54,6 +54,7 @@
#include <pulse/utf8.h>
#include <pulse/util.h>
#include <pulse/i18n.h>
+#include <pulse/lock-autospawn.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
@@ -81,8 +82,6 @@
#include "context.h"
-#define AUTOSPAWN_LOCK "autospawn.lock"
-
void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
@@ -100,20 +99,23 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_EXTENSION] = pa_command_extension
};
-static void unlock_autospawn_lock_file(pa_context *c) {
+static void unlock_autospawn(pa_context *c) {
pa_assert(c);
- if (c->autospawn_lock_fd >= 0) {
- char *lf;
+ if (c->autospawn_fd >= 0) {
- if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
- pa_log_warn(_("Cannot unlock autospawn because runtime path is no more."));
+ if (c->autospawn_locked)
+ pa_autospawn_lock_release();
- pa_unlock_lockfile(lf, c->autospawn_lock_fd);
- pa_xfree(lf);
+ if (c->autospawn_event)
+ c->mainloop->io_free(c->autospawn_event);
- c->autospawn_lock_fd = -1;
+ pa_autospawn_lock_done(FALSE);
}
+
+ c->autospawn_locked = FALSE;
+ c->autospawn_fd = -1;
+ c->autospawn_event = NULL;
}
static void context_free(pa_context *c);
@@ -174,11 +176,15 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
c->is_local = FALSE;
c->server_list = NULL;
c->server = NULL;
- c->autospawn_lock_fd = -1;
- memset(&c->spawn_api, 0, sizeof(c->spawn_api));
- c->do_autospawn = FALSE;
+
c->do_shm = FALSE;
+ c->do_autospawn = FALSE;
+ c->autospawn_fd = -1;
+ c->autospawn_locked = FALSE;
+ c->autospawn_event = NULL;
+ memset(&c->spawn_api, 0, sizeof(c->spawn_api));
+
#ifndef MSG_NOSIGNAL
#ifdef SIGPIPE
pa_check_signal_is_blocked(SIGPIPE);
@@ -246,7 +252,7 @@ static void context_free(pa_context *c) {
context_unlink(c);
- unlock_autospawn_lock_file(c);
+ unlock_autospawn(c);
if (c->record_streams)
pa_dynarray_free(c->record_streams, NULL, NULL);
@@ -433,7 +439,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
switch(c->state) {
case PA_CONTEXT_AUTHORIZING: {
pa_tagstruct *reply;
- pa_bool_t shm_on_remote;
+ pa_bool_t shm_on_remote = FALSE;
if (pa_tagstruct_getu32(t, &c->version) < 0 ||
!pa_tagstruct_eof(t)) {
@@ -674,7 +680,7 @@ static int context_connect_spawn(pa_context *c) {
c->is_local = TRUE;
- unlock_autospawn_lock_file(c);
+ unlock_autospawn(c);
io = pa_iochannel_new(c->mainloop, fds[0], fds[0]);
setup_context(c, io);
@@ -686,7 +692,7 @@ static int context_connect_spawn(pa_context *c) {
fail:
pa_close_pipe(fds);
- unlock_autospawn_lock_file(c);
+ unlock_autospawn(c);
pa_context_unref(c);
@@ -768,15 +774,48 @@ static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userd
goto finish;
}
- unlock_autospawn_lock_file(c);
+ unlock_autospawn(c);
setup_context(c, io);
finish:
pa_context_unref(c);
}
+static void autospawn_cb(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
+ pa_context *c = userdata;
+ int k;
+
+ pa_assert(a);
+ pa_assert(e);
+ pa_assert(fd >= 0);
+ pa_assert(events = PA_IO_EVENT_INPUT);
+ pa_assert(c);
+ pa_assert(e == c->autospawn_event);
+ pa_assert(fd == c->autospawn_fd);
+
+ pa_context_ref(c);
+
+ /* Check whether we can get the lock right now*/
+ if ((k = pa_autospawn_lock_acquire(FALSE)) < 0) {
+ pa_context_fail(c, PA_ERR_ACCESS);
+ goto finish;
+ }
+
+ if (k > 0) {
+ /* So we got it, rock on! */
+ c->autospawn_locked = TRUE;
+ try_next_connection(c);
+
+ c->mainloop->io_free(c->autospawn_event);
+ c->autospawn_event = NULL;
+ }
+
+finish:
-static char *get_legacy_runtime_dir(void) {
+ pa_context_unref(c);
+}
+
+static char *get_old_legacy_runtime_dir(void) {
char *p, u[128];
struct stat st;
@@ -798,6 +837,28 @@ static char *get_legacy_runtime_dir(void) {
return p;
}
+static char *get_very_old_legacy_runtime_dir(void) {
+ char *p, h[128];
+ struct stat st;
+
+ if (!pa_get_home_dir(h, sizeof(h)))
+ return NULL;
+
+ p = pa_sprintf_malloc("%s/.pulse", h);
+
+ if (stat(p, &st) < 0) {
+ pa_xfree(p);
+ return NULL;
+ }
+
+ if (st.st_uid != getuid()) {
+ pa_xfree(p);
+ return NULL;
+ }
+
+ return p;
+}
+
int pa_context_connect(
pa_context *c,
const char *server,
@@ -825,6 +886,7 @@ int pa_context_connect(
pa_context_fail(c, PA_ERR_INVALIDSERVER);
goto finish;
}
+
} else {
char *d, *ufn;
static char *legacy_dir;
@@ -849,8 +911,16 @@ int pa_context_connect(
/* The system wide instance */
c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET);
- /* The old per-user instance path. This is supported only to ease upgrades */
- if ((legacy_dir = get_legacy_runtime_dir())) {
+ /* The very old per-user instance path (< 0.9.11). This is supported only to ease upgrades */
+ if ((legacy_dir = get_very_old_legacy_runtime_dir())) {
+ char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir);
+ c->server_list = pa_strlist_prepend(c->server_list, p);
+ pa_xfree(p);
+ pa_xfree(legacy_dir);
+ }
+
+ /* The old per-user instance path (< 0.9.12). This is supported only to ease upgrades */
+ if ((legacy_dir = get_old_legacy_runtime_dir())) {
char *p = pa_sprintf_malloc("%s" PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET, legacy_dir);
c->server_list = pa_strlist_prepend(c->server_list, p);
pa_xfree(p);
@@ -865,21 +935,40 @@ int pa_context_connect(
/* Wrap the connection attempts in a single transaction for sane autospawn locking */
if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) {
- char *lf;
+ int k;
- if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
+ pa_assert(c->autospawn_fd < 0);
+ pa_assert(!c->autospawn_locked);
+
+ /* Start the locking procedure */
+ if ((c->autospawn_fd = pa_autospawn_lock_init()) < 0) {
pa_context_fail(c, PA_ERR_ACCESS);
goto finish;
}
- pa_assert(c->autospawn_lock_fd <= 0);
- c->autospawn_lock_fd = pa_lock_lockfile(lf);
- pa_xfree(lf);
-
if (api)
c->spawn_api = *api;
c->do_autospawn = TRUE;
+
+ /* Check whether we can get the lock right now*/
+ if ((k = pa_autospawn_lock_acquire(FALSE)) < 0) {
+ pa_context_fail(c, PA_ERR_ACCESS);
+ goto finish;
+ }
+
+ if (k > 0)
+ /* So we got it, rock on! */
+ c->autospawn_locked = TRUE;
+ else {
+ /* Hmm, we didn't get it, so let's wait for it */
+ c->autospawn_event = c->mainloop->io_new(c->mainloop, c->autospawn_fd, PA_IO_EVENT_INPUT, autospawn_cb, c);
+
+ pa_context_set_state(c, PA_CONTEXT_CONNECTING);
+ r = 0;
+ goto finish;
+ }
+
}
}
@@ -938,11 +1027,11 @@ int pa_context_is_pending(pa_context *c) {
static void set_dispatch_callbacks(pa_operation *o);
-static void pdispatch_drain_callback(PA_GCC_UNUSED pa_pdispatch*pd, void *userdata) {
+static void pdispatch_drain_callback(pa_pdispatch*pd, void *userdata) {
set_dispatch_callbacks(userdata);
}
-static void pstream_drain_callback(PA_GCC_UNUSED pa_pstream *s, void *userdata) {
+static void pstream_drain_callback(pa_pstream *s, void *userdata) {
set_dispatch_callbacks(userdata);
}
@@ -994,7 +1083,7 @@ pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *u
return o;
}
-void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int success = 1;
@@ -1146,7 +1235,7 @@ const char* pa_context_get_server(pa_context *c) {
return c->server;
}
-uint32_t pa_context_get_protocol_version(PA_GCC_UNUSED pa_context *c) {
+uint32_t pa_context_get_protocol_version(pa_context *c) {
return PA_PROTOCOL_VERSION;
}
diff --git a/src/pulse/glib-mainloop.c b/src/pulse/glib-mainloop.c
index 6ddb0faa..392133f0 100644
--- a/src/pulse/glib-mainloop.c
+++ b/src/pulse/glib-mainloop.c
@@ -425,7 +425,7 @@ static void glib_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy_cb_
/* quit() */
-static void glib_quit(pa_mainloop_api*a, PA_GCC_UNUSED int retval) {
+static void glib_quit(pa_mainloop_api*a, int retval) {
g_warning("quit() ignored");
@@ -536,7 +536,7 @@ static gboolean check_func(GSource *source) {
return FALSE;
}
-static gboolean dispatch_func(GSource *source, PA_GCC_UNUSED GSourceFunc callback, PA_GCC_UNUSED gpointer userdata) {
+static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer userdata) {
pa_glib_mainloop *g = (pa_glib_mainloop*) source;
pa_io_event *e;
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index bfe888ee..26fb04d4 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -75,9 +75,12 @@ struct pa_context {
pa_mempool *mempool;
pa_bool_t is_local:1;
- pa_bool_t do_autospawn:1;
pa_bool_t do_shm:1;
- int autospawn_lock_fd;
+
+ pa_bool_t do_autospawn:1;
+ pa_bool_t autospawn_locked:1;
+ int autospawn_fd;
+ pa_io_event *autospawn_event;
pa_spawn_api spawn_api;
pa_strlist *server_list;
diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index 4be2c62a..4e362fd8 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -36,7 +36,7 @@
/*** Statistics ***/
-static void context_stat_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_stat_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
pa_stat_info i, *p = &i;
@@ -79,7 +79,7 @@ pa_operation* pa_context_stat(pa_context *c, pa_stat_info_cb_t cb, void *userdat
/*** Server Info ***/
-static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
pa_server_info i, *p = &i;
@@ -127,7 +127,7 @@ pa_operation* pa_context_get_server_info(pa_context *c, pa_server_info_cb_t cb,
/*** Sink Info ***/
-static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -248,7 +248,7 @@ pa_operation* pa_context_get_sink_info_by_name(pa_context *c, const char *name,
/*** Source info ***/
-static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -369,7 +369,7 @@ pa_operation* pa_context_get_source_info_by_name(pa_context *c, const char *name
/*** Client info ***/
-static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -451,7 +451,7 @@ pa_operation* pa_context_get_client_info_list(pa_context *c, pa_client_info_cb_t
/*** Module info ***/
-static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -530,7 +530,7 @@ pa_operation* pa_context_get_module_info_list(pa_context *c, pa_module_info_cb_t
/*** Sink input info ***/
-static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -624,7 +624,7 @@ pa_operation* pa_context_get_sink_input_info_list(pa_context *c, void (*cb)(pa_c
/*** Source output info ***/
-static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -954,7 +954,7 @@ pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name
/** Sample Cache **/
-static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
@@ -1098,7 +1098,7 @@ pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_cont
return command_kill(c, PA_COMMAND_KILL_SOURCE_OUTPUT, idx, cb, userdata);
}
-static void context_index_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_index_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
uint32_t idx;
@@ -1159,7 +1159,7 @@ pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_s
/*** Autoload stuff ***/
-static void context_get_autoload_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void context_get_autoload_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int eol = 1;
diff --git a/src/pulse/lock-autospawn.c b/src/pulse/lock-autospawn.c
new file mode 100644
index 00000000..d36b669e
--- /dev/null
+++ b/src/pulse/lock-autospawn.c
@@ -0,0 +1,330 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2008 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/poll.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include <pulse/i18n.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/mutex.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/core-util.h>
+
+#include "lock-autospawn.h"
+
+/* So, why do we have this complex code here with threads and pipes
+ * and stuff? For two reasons: POSIX file locks are per-process, not
+ * per-file descriptor. That means that two contexts within the same
+ * process that try to create the autospawn lock might end up assuming
+ * they both managed to lock the file. And then, POSIX locking
+ * operations are synchronous. If two contexts run from the same event
+ * loop it must be made sure that they do not block each other, but
+ * that the locking operation can happen asynchronously. */
+
+#define AUTOSPAWN_LOCK "autospawn.lock"
+
+static pa_mutex *mutex;
+
+static unsigned n_ref = 0;
+static int lock_fd = -1;
+static pa_mutex *lock_fd_mutex = NULL;
+static pa_bool_t taken = FALSE;
+static pa_thread *thread;
+static int pipe_fd[2] = { -1, -1 };
+
+static void destroy_mutex(void) PA_GCC_DESTRUCTOR;
+
+static int ref(void) {
+
+ if (n_ref > 0) {
+
+ pa_assert(pipe_fd[0] >= 0);
+ pa_assert(pipe_fd[1] >= 0);
+
+ n_ref++;
+
+ return 0;
+ }
+
+ pa_assert(lock_fd < 0);
+ pa_assert(!lock_fd_mutex);
+ pa_assert(!taken);
+ pa_assert(!thread);
+ pa_assert(pipe_fd[0] < 0);
+ pa_assert(pipe_fd[1] < 0);
+
+ if (pipe(pipe_fd) < 0)
+ return -1;
+
+ lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
+
+ pa_make_fd_cloexec(pipe_fd[0]);
+ pa_make_fd_cloexec(pipe_fd[1]);
+
+ pa_make_fd_nonblock(pipe_fd[1]);
+ pa_make_fd_nonblock(pipe_fd[0]);
+
+ n_ref = 1;
+ return 0;
+}
+
+static void unref(pa_bool_t after_fork) {
+
+ pa_assert(n_ref > 0);
+ pa_assert(pipe_fd[0] >= 0);
+ pa_assert(pipe_fd[1] >= 0);
+ pa_assert(lock_fd_mutex);
+
+ n_ref--;
+
+ if (n_ref > 0)
+ return;
+
+ pa_assert(!taken);
+
+ if (thread) {
+ pa_thread_free(thread);
+ thread = NULL;
+ }
+
+ pa_mutex_lock(lock_fd_mutex);
+ if (lock_fd >= 0) {
+
+ if (after_fork)
+ pa_close(lock_fd);
+ else {
+ char *lf;
+
+ if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
+ pa_log_warn(_("Cannot access autospawn lock."));
+
+ pa_unlock_lockfile(lf, lock_fd);
+ pa_xfree(lf);
+
+ lock_fd = -1;
+ }
+ }
+ pa_mutex_unlock(lock_fd_mutex);
+
+ pa_mutex_free(lock_fd_mutex);
+ lock_fd_mutex = NULL;
+
+ pa_close(pipe_fd[0]);
+ pa_close(pipe_fd[1]);
+ pipe_fd[0] = pipe_fd[1] = -1;
+}
+
+static void ping(void) {
+ ssize_t s;
+
+ pa_assert(pipe_fd[1] >= 0);
+
+ for (;;) {
+ char x = 'x';
+
+ if ((s = write(pipe_fd[1], &x, 1)) == 1)
+ break;
+
+ pa_assert(s < 0);
+
+ if (errno == EAGAIN)
+ break;
+
+ pa_assert(errno == EINTR);
+ }
+}
+
+static void wait_for_ping(void) {
+ ssize_t s;
+ char x;
+ struct pollfd pfd;
+ int k;
+
+ pa_assert(pipe_fd[0] >= 0);
+
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.fd = pipe_fd[0];
+ pfd.events = POLLIN;
+
+ if ((k = poll(&pfd, 1, -1)) != 1) {
+ pa_assert(k < 0);
+ pa_assert(errno == EINTR);
+ } else if ((s = read(pipe_fd[0], &x, 1)) != 1) {
+ pa_assert(s < 0);
+ pa_assert(errno == EAGAIN);
+ }
+}
+
+static void empty_pipe(void) {
+ char x[16];
+ ssize_t s;
+
+ pa_assert(pipe_fd[0] >= 0);
+
+ if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) {
+ pa_assert(s < 0);
+ pa_assert(errno == EAGAIN);
+ }
+}
+
+static void thread_func(void *u) {
+ int fd;
+ char *lf;
+ sigset_t fullset;
+
+ /* No signals in this thread please */
+ sigfillset(&fullset);
+ pthread_sigmask(SIG_BLOCK, &fullset, NULL);
+
+ if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
+ pa_log_warn(_("Cannot access autospawn lock."));
+ goto finish;
+ }
+
+ if ((fd = pa_lock_lockfile(lf)) < 0)
+ goto finish;
+
+ pa_mutex_lock(lock_fd_mutex);
+ pa_assert(lock_fd < 0);
+ lock_fd = fd;
+ pa_mutex_unlock(lock_fd_mutex);
+
+finish:
+ pa_xfree(lf);
+
+ ping();
+}
+
+static int start_thread(void) {
+
+ if (!thread)
+ if (!(thread = pa_thread_new(thread_func, NULL)))
+ return -1;
+
+ return 0;
+}
+
+static void create_mutex(void) {
+ PA_ONCE_BEGIN {
+ mutex = pa_mutex_new(FALSE, FALSE);
+ } PA_ONCE_END;
+}
+
+static void destroy_mutex(void) {
+
+ if (mutex)
+ pa_mutex_free(mutex);
+}
+
+
+int pa_autospawn_lock_init(void) {
+ int ret = -1;
+
+ create_mutex();
+ pa_mutex_lock(mutex);
+
+ if (ref() < 0)
+ ret = -1;
+ else
+ ret = pipe_fd[0];
+
+ pa_mutex_unlock(mutex);
+
+ return ret;
+}
+
+int pa_autospawn_lock_acquire(pa_bool_t block) {
+ int ret = -1;
+
+ create_mutex();
+ pa_mutex_lock(mutex);
+ pa_assert(n_ref >= 1);
+
+ pa_mutex_lock(lock_fd_mutex);
+
+ for (;;) {
+
+ empty_pipe();
+
+ if (lock_fd >= 0 && !taken) {
+ taken = TRUE;
+ ret = 1;
+ break;
+ }
+
+ if (lock_fd < 0)
+ if (start_thread() < 0)
+ break;
+
+ if (!block) {
+ ret = 0;
+ break;
+ }
+
+ pa_mutex_unlock(lock_fd_mutex);
+ pa_mutex_unlock(mutex);
+
+ wait_for_ping();
+
+ pa_mutex_lock(mutex);
+ pa_mutex_lock(lock_fd_mutex);
+ }
+
+ pa_mutex_unlock(lock_fd_mutex);
+
+ pa_mutex_unlock(mutex);
+
+ return ret;
+}
+
+void pa_autospawn_lock_release(void) {
+
+ create_mutex();
+ pa_mutex_lock(mutex);
+ pa_assert(n_ref >= 1);
+
+ pa_assert(taken);
+ taken = FALSE;
+
+ ping();
+
+ pa_mutex_unlock(mutex);
+}
+
+void pa_autospawn_lock_done(pa_bool_t after_fork) {
+
+ create_mutex();
+ pa_mutex_lock(mutex);
+ pa_assert(n_ref >= 1);
+
+ unref(after_fork);
+
+ pa_mutex_unlock(mutex);
+}
diff --git a/src/pulse/lock-autospawn.h b/src/pulse/lock-autospawn.h
new file mode 100644
index 00000000..c04c4bd1
--- /dev/null
+++ b/src/pulse/lock-autospawn.h
@@ -0,0 +1,32 @@
+#ifndef foopulselockautospawnhfoo
+#define foopulselockautospawnhfoo
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2008 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <pulsecore/macro.h>
+
+int pa_autospawn_lock_init(void);
+int pa_autospawn_lock_acquire(pa_bool_t block);
+void pa_autospawn_lock_release(void);
+void pa_autospawn_lock_done(pa_bool_t after_fork);
+
+#endif
diff --git a/src/pulse/mainloop-api.c b/src/pulse/mainloop-api.c
index 4e3b135a..4b862f9a 100644
--- a/src/pulse/mainloop-api.c
+++ b/src/pulse/mainloop-api.c
@@ -51,7 +51,7 @@ static void once_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata)
m->defer_free(e);
}
-static void free_callback(pa_mainloop_api *m, PA_GCC_UNUSED pa_defer_event *e, void *userdata) {
+static void free_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
struct once_info *i = userdata;
pa_assert(m);
diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
index e95968ae..d09f4b0a 100644
--- a/src/pulse/mainloop-signal.c
+++ b/src/pulse/mainloop-signal.c
@@ -90,7 +90,7 @@ static void dispatch(pa_mainloop_api*a, int sig) {
}
}
-static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, PA_GCC_UNUSED void *userdata) {
+static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) {
ssize_t r;
int sig;
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 585518f0..6769fc09 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -315,7 +315,7 @@ static void request_auto_timing_update(pa_stream *s, pa_bool_t force) {
}
}
-void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_context *c = userdata;
pa_stream *s;
uint32_t channel;
@@ -382,7 +382,7 @@ static void check_smoother_status(pa_stream *s, pa_bool_t aposteriori, pa_bool_t
* if prebuf is non-zero! */
}
-void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_context *c = userdata;
pa_stream *s;
uint32_t channel;
@@ -479,7 +479,7 @@ finish:
pa_context_unref(c);
}
-void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_context *c = userdata;
pa_stream *s;
uint32_t channel;
@@ -563,7 +563,7 @@ finish:
pa_context_unref(c);
}
-void pa_command_request(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_stream *s;
pa_context *c = userdata;
uint32_t bytes, channel;
@@ -598,7 +598,7 @@ finish:
pa_context_unref(c);
}
-void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_stream *s;
pa_context *c = userdata;
uint32_t channel;
@@ -670,7 +670,7 @@ static void invalidate_indexes(pa_stream *s, pa_bool_t r, pa_bool_t w) {
request_auto_timing_update(s, TRUE);
}
-static void auto_timing_update_callback(PA_GCC_UNUSED pa_mainloop_api *m, PA_GCC_UNUSED pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) {
pa_stream *s = userdata;
pa_assert(s);
@@ -734,7 +734,7 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s
attr->fragsize = attr->tlength; /* Pass data to the app only when the buffer is filled up once */
}
-void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_stream *s = userdata;
pa_assert(pd);
@@ -865,6 +865,7 @@ static int create_stream(
pa_tagstruct *t;
uint32_t tag;
+ pa_bool_t volume_set = FALSE;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@@ -957,6 +958,8 @@ static int create_stream(
PA_TAG_U32, s->syncid,
PA_TAG_INVALID);
+ volume_set = !!volume;
+
if (!volume)
volume = pa_cvolume_reset(&cv, s->sample_spec.channels);
@@ -994,6 +997,15 @@ static int create_stream(
pa_tagstruct_putu32(t, s->direct_on_input);
}
+ if (s->context->version >= 14 &&
+ s->direction == PA_STREAM_PLAYBACK) {
+
+ pa_tagstruct_put(
+ t,
+ PA_TAG_BOOLEAN, volume_set,
+ PA_TAG_INVALID);
+ }
+
pa_pstream_send_tagstruct(s->context->pstream, t);
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL);
@@ -1257,7 +1269,9 @@ static pa_usec_t calc_time(pa_stream *s, pa_bool_t ignore_transport) {
usec -= s->timing_info.sink_usec;
}
- } else if (s->direction == PA_STREAM_RECORD) {
+ } else {
+ pa_assert(s->direction == PA_STREAM_RECORD);
+
/* The last byte written into the server side queue had
* this time value associated */
usec = pa_bytes_to_usec(s->timing_info.write_index < 0 ? 0 : (uint64_t) s->timing_info.write_index, &s->sample_spec);
@@ -1517,7 +1531,7 @@ pa_operation* pa_stream_update_timing_info(pa_stream *s, pa_stream_success_cb_t
return o;
}
-void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_stream *s = userdata;
pa_assert(pd);
@@ -1667,7 +1681,7 @@ void pa_stream_set_started_callback(pa_stream *s, pa_stream_notify_cb_t cb, void
s->started_userdata = userdata;
}
-void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int success = 1;
@@ -1978,7 +1992,7 @@ const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s) {
return &s->buffer_attr;
}
-static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int success = 1;
@@ -2120,7 +2134,7 @@ int pa_stream_is_corked(pa_stream *s) {
return s->corked;
}
-static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
int success = 1;
diff --git a/src/pulse/subscribe.c b/src/pulse/subscribe.c
index b8d3be89..e12d1446 100644
--- a/src/pulse/subscribe.c
+++ b/src/pulse/subscribe.c
@@ -34,7 +34,7 @@
#include "subscribe.h"
-void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
+void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_context *c = userdata;
pa_subscription_event_type_t e;
uint32_t idx;
diff --git a/src/pulse/util.c b/src/pulse/util.c
index f785a2e9..44fad4aa 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -95,12 +95,15 @@ char *pa_get_user_name(char *s, size_t l) {
#elif defined(OS_IS_WIN32) /* HAVE_PWD_H */
DWORD size = sizeof(buf);
- if (!GetUserName(buf, &size))
+ if (!GetUserName(buf, &size)) {
+ errno = ENOENT;
return NULL;
+ }
p = buf;
#else /* HAVE_PWD_H */
+
return NULL;
#endif /* HAVE_PWD_H */
}
@@ -138,6 +141,8 @@ char *pa_get_home_dir(char *s, size_t l) {
return pa_strlcpy(s, e, l);
#ifdef HAVE_PWD_H
+
+ errno = 0;
#ifdef HAVE_GETPWUID_R
if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
#else
@@ -145,11 +150,16 @@ char *pa_get_home_dir(char *s, size_t l) {
* that do not support getpwuid_r. */
if ((r = getpwuid(getuid())) == NULL) {
#endif
+ if (!errno)
+ errno = ENOENT;
+
return NULL;
}
return pa_strlcpy(s, r->pw_dir, l);
#else /* HAVE_PWD_H */
+
+ errno = ENOENT;
return NULL;
#endif
}
@@ -200,6 +210,7 @@ char *pa_get_binary_name(char *s, size_t l) {
}
#endif
+ errno = ENOENT;
return NULL;
}
@@ -249,8 +260,8 @@ int pa_msleep(unsigned long t) {
#elif defined(HAVE_NANOSLEEP)
struct timespec ts;
- ts.tv_sec = t/1000;
- ts.tv_nsec = (t % 1000) * 1000000;
+ ts.tv_sec = t/1000UL;
+ ts.tv_nsec = (t % 1000UL) * 1000000UL;
return nanosleep(&ts, NULL);
#else
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index 625eb19a..f0d45275 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -74,6 +74,18 @@ pa_volume_t pa_cvolume_avg(const pa_cvolume *a) {
return (pa_volume_t) sum;
}
+pa_volume_t pa_cvolume_max(const pa_cvolume *a) {
+ pa_volume_t m = 0;
+ int i;
+ pa_assert(a);
+
+ for (i = 0; i < a->channels; i++)
+ if (a->values[i] > m)
+ m = a->values[i];
+
+ return m;
+}
+
pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) {
return pa_sw_volume_from_linear(pa_sw_volume_to_linear(a)* pa_sw_volume_to_linear(b));
}
diff --git a/src/pulse/volume.h b/src/pulse/volume.h
index 4fdbf658..a356f749 100644
--- a/src/pulse/volume.h
+++ b/src/pulse/volume.h
@@ -134,6 +134,9 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c);
/** Return the average volume of all channels */
pa_volume_t pa_cvolume_avg(const pa_cvolume *a) PA_GCC_PURE;
+/** Return the maximum volume of all channels. \since 0.9.12 */
+pa_volume_t pa_cvolume_max(const pa_cvolume *a) PA_GCC_PURE;
+
/** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */
int pa_cvolume_valid(const pa_cvolume *v) PA_GCC_PURE;
diff --git a/src/pulsecore/autoload.c b/src/pulsecore/autoload.c
index 26c294b2..8c84cee5 100644
--- a/src/pulsecore/autoload.c
+++ b/src/pulsecore/autoload.c
@@ -158,7 +158,7 @@ void pa_autoload_request(pa_core *c, const char *name, pa_namereg_type_t type) {
e->in_action = 0;
}
-static void free_func(void *p, PA_GCC_UNUSED void *userdata) {
+static void free_func(void *p, void *userdata) {
pa_autoload_entry *e = p;
pa_idxset_remove_by_data(e->core->autoload_idxset, e, NULL);
entry_free(e);
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index a80933fa..aa05a464 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1251,8 +1251,8 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
nl = 1;
}
- pa_strbuf_printf(buf, "set-sink-volume %s 0x%03x\n", sink->name, pa_cvolume_avg(pa_sink_get_volume(sink)));
- pa_strbuf_printf(buf, "set-sink-mute %s %s\n", sink->name, pa_yes_no(pa_sink_get_mute(sink)));
+ pa_strbuf_printf(buf, "set-sink-volume %s 0x%03x\n", sink->name, pa_cvolume_avg(pa_sink_get_volume(sink, FALSE)));
+ pa_strbuf_printf(buf, "set-sink-mute %s %s\n", sink->name, pa_yes_no(pa_sink_get_mute(sink, FALSE)));
pa_strbuf_printf(buf, "suspend-sink %s %s\n", sink->name, pa_yes_no(pa_sink_get_state(sink) == PA_SINK_SUSPENDED));
}
@@ -1265,8 +1265,8 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
nl = 1;
}
- pa_strbuf_printf(buf, "set-source-volume %s 0x%03x\n", source->name, pa_cvolume_avg(pa_source_get_volume(source)));
- pa_strbuf_printf(buf, "set-source-mute %s %s\n", source->name, pa_yes_no(pa_source_get_mute(source)));
+ pa_strbuf_printf(buf, "set-source-volume %s 0x%03x\n", source->name, pa_cvolume_avg(pa_source_get_volume(source, FALSE)));
+ pa_strbuf_printf(buf, "set-source-mute %s %s\n", source->name, pa_yes_no(pa_source_get_mute(source, FALSE)));
pa_strbuf_printf(buf, "suspend-source %s %s\n", source->name, pa_yes_no(pa_source_get_state(source) == PA_SOURCE_SUSPENDED));
}
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index c92fca20..4cbe7c34 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -149,8 +149,8 @@ char *pa_sink_list_to_string(pa_core *c) {
sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
state_table[pa_sink_get_state(sink)],
- pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
- pa_yes_no(pa_sink_get_mute(sink)),
+ pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, FALSE)),
+ pa_yes_no(pa_sink_get_mute(sink, FALSE)),
(double) pa_sink_get_latency(sink) / PA_USEC_PER_MSEC,
(double) pa_sink_get_requested_latency(sink) / PA_USEC_PER_MSEC, (double) min_latency / PA_USEC_PER_MSEC, (double) max_latency / PA_USEC_PER_MSEC,
(unsigned long) pa_sink_get_max_request(sink) / 1024,
@@ -222,8 +222,8 @@ char *pa_source_list_to_string(pa_core *c) {
source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
state_table[pa_source_get_state(source)],
- pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
- pa_yes_no(pa_source_get_mute(source)),
+ pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source, FALSE)),
+ pa_yes_no(pa_source_get_mute(source, FALSE)),
(double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
(double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC, (double) min_latency / PA_USEC_PER_MSEC, (double) max_latency / PA_USEC_PER_MSEC,
(unsigned long) pa_source_get_max_rewind(source) / 1024,
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index 4aec45d7..6b0e1d56 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -148,7 +148,7 @@ finish:
return r;
}
-int pa_config_parse_int(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+int pa_config_parse_int(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
int *i = data;
int32_t k;
@@ -166,7 +166,7 @@ int pa_config_parse_int(const char *filename, unsigned line, const char *lvalue,
return 0;
}
-int pa_config_parse_bool(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+int pa_config_parse_bool(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
int k;
pa_bool_t *b = data;
@@ -185,7 +185,7 @@ int pa_config_parse_bool(const char *filename, unsigned line, const char *lvalue
return 0;
}
-int pa_config_parse_string(const char *filename, PA_GCC_UNUSED unsigned line, const char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+int pa_config_parse_string(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) {
char **s = data;
pa_assert(filename);
diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c
index 75fa2ff1..814dff59 100644
--- a/src/pulsecore/core-scache.c
+++ b/src/pulsecore/core-scache.c
@@ -63,7 +63,7 @@
#define UNLOAD_POLL_TIME 60
-static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) {
pa_core *c = userdata;
struct timeval ntv;
@@ -282,7 +282,7 @@ int pa_scache_remove_item(pa_core *c, const char *name) {
return 0;
}
-static void free_cb(void *p, PA_GCC_UNUSED void *userdata) {
+static void free_cb(void *p, void *userdata) {
pa_scache_entry *e = p;
pa_assert(e);
diff --git a/src/pulsecore/core-subscribe.c b/src/pulsecore/core-subscribe.c
index 6107002b..c70d8adc 100644
--- a/src/pulsecore/core-subscribe.c
+++ b/src/pulsecore/core-subscribe.c
@@ -42,7 +42,7 @@
struct pa_subscription {
pa_core *core;
- int dead;
+ pa_bool_t dead;
pa_subscription_cb_t callback;
void *userdata;
@@ -72,7 +72,7 @@ pa_subscription* pa_subscription_new(pa_core *c, pa_subscription_mask_t m, pa_su
s = pa_xnew(pa_subscription, 1);
s->core = c;
- s->dead = 0;
+ s->dead = FALSE;
s->callback = callback;
s->userdata = userdata;
s->mask = m;
@@ -86,7 +86,7 @@ void pa_subscription_free(pa_subscription*s) {
pa_assert(s);
pa_assert(!s->dead);
- s->dead = 1;
+ s->dead = TRUE;
sched_event(s->core);
}
@@ -145,7 +145,7 @@ static void dump_event(const char * prefix, pa_subscription_event*e) {
[PA_SUBSCRIPTION_EVENT_REMOVE] = "REMOVE"
};
- pa_log("%s event (%s|%s|%u)",
+ pa_log_debug("%s event (%s|%s|%u)",
prefix,
fac_table[e->type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK],
type_table[e->type & PA_SUBSCRIPTION_EVENT_TYPE_MASK],
@@ -234,7 +234,7 @@ void pa_subscription_post(pa_core *c, pa_subscription_event_type_t t, uint32_t i
* entry in the queue. */
free_event(i);
- pa_log_debug("dropped redundant event.");
+ pa_log_debug("Dropped redundant event due to remove event.");
continue;
}
@@ -242,7 +242,7 @@ void pa_subscription_post(pa_core *c, pa_subscription_event_type_t t, uint32_t i
/* This object has changed. If a "new" or "change" event for
* this object is still in the queue we can exit. */
- pa_log_debug("dropped redundant event.");
+ pa_log_debug("Dropped redundant event due to change event.");
return;
}
}
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index b2c91e45..5841df0c 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -40,6 +40,8 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <dirent.h>
+#include <regex.h>
+#include <langinfo.h>
#ifdef HAVE_STRTOF_L
#include <locale.h>
@@ -111,6 +113,8 @@ int pa_set_root(HANDLE handle) {
strcpy(library_path, PULSE_ROOTENV "=");
+ /* FIXME: Needs to set errno */
+
if (!GetModuleFileName(handle, library_path + sizeof(PULSE_ROOTENV), MAX_PATH))
return 0;
@@ -168,7 +172,7 @@ void pa_make_fd_cloexec(int fd) {
/** Creates a directory securely */
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
struct stat st;
- int r;
+ int r, saved_errno;
pa_assert(dir);
@@ -220,7 +224,10 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
return 0;
fail:
+ saved_errno = errno;
rmdir(dir);
+ errno = saved_errno;
+
return -1;
}
@@ -230,6 +237,7 @@ char *pa_parent_dir(const char *fn) {
if ((slash = (char*) pa_path_get_filename(dir)) == dir) {
pa_xfree(dir);
+ errno = ENOENT;
return NULL;
}
@@ -546,6 +554,8 @@ int pa_make_realtime(int rtprio) {
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i.", sp.sched_priority);
return 0;
#else
+
+ errno = ENOTSUP;
return -1;
#endif
}
@@ -653,6 +663,7 @@ int pa_raise_priority(int nice_level) {
if (nice_level < 0) {
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
pa_log_warn("SetPriorityClass() failed: 0x%08X", GetLastError());
+ errno = EPERM;
return .-1;
} else
pa_log_info("Successfully gained high priority class.");
@@ -679,15 +690,55 @@ void pa_reset_priority(void) {
#endif
}
+static int match(const char *expr, const char *v) {
+ int k;
+ regex_t re;
+ int r;
+
+ if (regcomp(&re, expr, REG_NOSUB|REG_EXTENDED) != 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if ((k = regexec(&re, v, 0, NULL, 0)) == 0)
+ r = 1;
+ else if (k == REG_NOMATCH)
+ r = 0;
+ else
+ r = -1;
+
+ regfree(&re);
+
+ if (r < 0)
+ errno = EINVAL;
+
+ return r;
+}
+
/* Try to parse a boolean string value.*/
int pa_parse_boolean(const char *v) {
+ const char *expr;
+ int r;
pa_assert(v);
+ /* First we check language independant */
if (!strcmp(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
return 1;
else if (!strcmp(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
return 0;
+ /* And then we check language dependant */
+ if ((expr = nl_langinfo(YESEXPR)))
+ if (expr[0])
+ if ((r = match(expr, v)) > 0)
+ return 1;
+
+ if ((expr = nl_langinfo(NOEXPR)))
+ if (expr[0])
+ if ((r = match(expr, v)) > 0)
+ return 0;
+
+ errno = EINVAL;
return -1;
}
@@ -875,11 +926,18 @@ static int is_group(gid_t gid, const char *name) {
#else
n = -1;
#endif
- if (n < 0) n = 512;
+ if (n < 0)
+ n = 512;
+
data = pa_xmalloc(n);
+ errno = 0;
if (getgrgid_r(gid, &group, data, n, &result) < 0 || !result) {
- pa_log("getgrgid_r(%u): %s", (unsigned)gid, pa_cstrerror(errno));
+ pa_log("getgrgid_r(%u): %s", (unsigned) gid, pa_cstrerror(errno));
+
+ if (!errno)
+ errno = ENOENT;
+
goto finish;
}
@@ -890,8 +948,14 @@ finish:
#else
/* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X) that do not
* support getgrgid_r. */
+
+ errno = 0;
if ((result = getgrgid(gid)) == NULL) {
pa_log("getgrgid(%u): %s", gid, pa_cstrerror(errno));
+
+ if (!errno)
+ errno = ENOENT;
+
goto finish;
}
@@ -907,7 +971,7 @@ finish:
int pa_own_uid_in_group(const char *name, gid_t *gid) {
GETGROUPS_T *gids, tgid;
int n = sysconf(_SC_NGROUPS_MAX);
- int r = -1, i;
+ int r = -1, i, k;
pa_assert(n > 0);
@@ -919,14 +983,19 @@ int pa_own_uid_in_group(const char *name, gid_t *gid) {
}
for (i = 0; i < n; i++) {
- if (is_group(gids[i], name) > 0) {
+
+ if ((k = is_group(gids[i], name)) < 0)
+ goto finish;
+ else if (k > 0) {
*gid = gids[i];
r = 1;
goto finish;
}
}
- if (is_group(tgid = getgid(), name) > 0) {
+ if ((k = is_group(tgid = getgid(), name)) < 0)
+ goto finish;
+ else if (k > 0) {
*gid = tgid;
r = 1;
goto finish;
@@ -954,13 +1023,20 @@ int pa_uid_in_group(uid_t uid, const char *name) {
p_n = sysconf(_SC_GETPW_R_SIZE_MAX);
p_buf = pa_xmalloc(p_n);
- if (getgrnam_r(name, &grbuf, g_buf, (size_t) g_n, &gr) != 0 || !gr)
+ errno = 0;
+ if (getgrnam_r(name, &grbuf, g_buf, (size_t) g_n, &gr) != 0 || !gr) {
+
+ if (!errno)
+ errno = ENOENT;
+
goto finish;
+ }
r = 0;
for (i = gr->gr_mem; *i; i++) {
struct passwd pwbuf, *pw;
+ errno = 0;
if (getpwnam_r(*i, &pwbuf, p_buf, (size_t) p_n, &pw) != 0 || !pw)
continue;
@@ -987,8 +1063,14 @@ gid_t pa_get_gid_of_group(const char *name) {
g_n = sysconf(_SC_GETGR_R_SIZE_MAX);
g_buf = pa_xmalloc(g_n);
- if (getgrnam_r(name, &grbuf, g_buf, (size_t) g_n, &gr) != 0 || !gr)
+ errno = 0;
+ if (getgrnam_r(name, &grbuf, g_buf, (size_t) g_n, &gr) != 0 || !gr) {
+
+ if (!errno)
+ errno = ENOENT;
+
goto finish;
+ }
ret = gr->gr_gid;
@@ -1014,19 +1096,23 @@ int pa_check_in_group(gid_t g) {
#else /* HAVE_GRP_H */
int pa_own_uid_in_group(const char *name, gid_t *gid) {
+ errno = ENOSUP;
return -1;
}
int pa_uid_in_group(uid_t uid, const char *name) {
+ errno = ENOSUP;
return -1;
}
gid_t pa_get_gid_of_group(const char *name) {
+ errno = ENOSUP;
return (gid_t) -1;
}
int pa_check_in_group(gid_t g) {
+ errno = ENOSUP;
return -1;
}
@@ -1067,6 +1153,8 @@ int pa_lock_fd(int fd, int b) {
return 0;
pa_log("%slock failed: 0x%08X", !b ? "un" : "", GetLastError());
+
+ /* FIXME: Needs to set errno! */
#endif
return -1;
@@ -1133,8 +1221,11 @@ int pa_lock_lockfile(const char *fn) {
fail:
- if (fd >= 0)
+ if (fd >= 0) {
+ int saved_errno = errno;
pa_close(fd);
+ errno = saved_errno;
+ }
return -1;
}
@@ -1180,6 +1271,7 @@ static char *get_pulse_home(void) {
if (st.st_uid != getuid()) {
pa_log_error("Home directory %s not ours.", h);
+ errno = EACCES;
return NULL;
}
@@ -1332,6 +1424,7 @@ char *pa_get_runtime_dir(void) {
/* Make sure that this actually makes sense */
if (!pa_is_path_absolute(p)) {
pa_log_error("Path %s in link %s is not absolute.", p, k);
+ errno = ENOENT;
goto fail;
}
@@ -1423,6 +1516,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(fn, buf, PATH_MAX))
+ /* FIXME: Needs to set errno! */
return NULL;
fn = buf;
#endif
@@ -1453,6 +1547,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(lfn, buf, PATH_MAX)) {
+ /* FIXME: Needs to set errno! */
pa_xfree(lfn);
return NULL;
}
@@ -1481,6 +1576,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(global, buf, PATH_MAX))
+ /* FIXME: Needs to set errno! */
return NULL;
global = buf;
#endif
@@ -1492,9 +1588,9 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
return f;
}
- } else
- errno = ENOENT;
+ }
+ errno = ENOENT;
return NULL;
}
@@ -1511,6 +1607,7 @@ char *pa_find_config_file(const char *global, const char *local, const char *env
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(fn, buf, PATH_MAX))
+ /* FIXME: Needs to set errno! */
return NULL;
fn = buf;
#endif
@@ -1536,6 +1633,7 @@ char *pa_find_config_file(const char *global, const char *local, const char *env
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(lfn, buf, PATH_MAX)) {
+ /* FIXME: Needs to set errno! */
pa_xfree(lfn);
return NULL;
}
@@ -1560,14 +1658,16 @@ char *pa_find_config_file(const char *global, const char *local, const char *env
if (global) {
#ifdef OS_IS_WIN32
if (!ExpandEnvironmentStrings(global, buf, PATH_MAX))
+ /* FIXME: Needs to set errno! */
return NULL;
global = buf;
#endif
if (access(global, R_OK) == 0)
return pa_xstrdup(global);
- } else
- errno = ENOENT;
+ }
+
+ errno = ENOENT;
return NULL;
}
@@ -1604,6 +1704,7 @@ static int hexc(char c) {
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
+ errno = EINVAL;
return -1;
}
@@ -1742,11 +1843,16 @@ int pa_atoi(const char *s, int32_t *ret_i) {
errno = 0;
l = strtol(s, &x, 0);
- if (!x || *x || errno != 0)
+ if (!x || *x || errno) {
+ if (!errno)
+ errno = EINVAL;
return -1;
+ }
- if ((int32_t) l != l)
+ if ((int32_t) l != l) {
+ errno = ERANGE;
return -1;
+ }
*ret_i = (int32_t) l;
@@ -1764,11 +1870,16 @@ int pa_atou(const char *s, uint32_t *ret_u) {
errno = 0;
l = strtoul(s, &x, 0);
- if (!x || *x || errno != 0)
+ if (!x || *x || errno) {
+ if (!errno)
+ errno = EINVAL;
return -1;
+ }
- if ((uint32_t) l != l)
+ if ((uint32_t) l != l) {
+ errno = ERANGE;
return -1;
+ }
*ret_u = (uint32_t) l;
@@ -1786,7 +1897,6 @@ static void c_locale_destroy(void) {
int pa_atod(const char *s, double *ret_d) {
char *x = NULL;
double f;
- int r = 0;
pa_assert(s);
pa_assert(ret_d);
@@ -1812,12 +1922,15 @@ int pa_atod(const char *s, double *ret_d) {
f = strtod(s, &x);
}
- if (!x || *x || errno != 0)
- r = -1;
- else
- *ret_d = f;
+ if (!x || *x || errno) {
+ if (!errno)
+ errno = EINVAL;
+ return -1;
+ }
- return r;
+ *ret_d = f;
+
+ return 0;
}
/* Same as snprintf, but guarantees NUL-termination on every platform */
@@ -1921,6 +2034,7 @@ void *pa_will_need(const void *p, size_t l) {
if (rlim.rlim_cur < PA_PAGE_SIZE) {
pa_log_debug("posix_madvise() failed (or doesn't exist), resource limits don't allow mlock(), can't page in data: %s", pa_cstrerror(r));
+ errno = EPERM;
return (void*) p;
}
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 5c594b02..b9f04b68 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -200,7 +200,7 @@ static void core_free(pa_object *o) {
pa_xfree(c);
}
-static void exit_callback(pa_mainloop_api*m, pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void exit_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
pa_core *c = userdata;
pa_assert(c->exit_event == e);
diff --git a/src/pulsecore/endianmacros.h b/src/pulsecore/endianmacros.h
index 26336918..1b94de17 100644
--- a/src/pulsecore/endianmacros.h
+++ b/src/pulsecore/endianmacros.h
@@ -46,9 +46,14 @@
#endif
static inline float PA_FLOAT32_SWAP(float x) {
- uint32_t i = *(uint32_t*) &x;
- i = PA_UINT32_SWAP(i);
- return *(float*) &i;
+ union {
+ float f;
+ uint32_t u;
+ } t;
+
+ t.f = x;
+ t.u = PA_UINT32_SWAP(t.u);
+ return t.f;
}
#define PA_MAYBE_INT16_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : x)
diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
index b43113d6..47909cdc 100644
--- a/src/pulsecore/memblock.c
+++ b/src/pulsecore/memblock.c
@@ -31,6 +31,10 @@
#include <signal.h>
#include <errno.h>
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
+
#include <pulse/xmalloc.h>
#include <pulse/def.h>
@@ -257,6 +261,10 @@ static struct mempool_slot* mempool_allocate_slot(pa_mempool *p) {
}
}
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_MALLOCLIKE_BLOCK(slot, p->block_size, 0, 0);
+#endif
+
return slot;
}
@@ -519,7 +527,7 @@ static void memblock_free(pa_memblock *b) {
case PA_MEMBLOCK_POOL_EXTERNAL:
case PA_MEMBLOCK_POOL: {
struct mempool_slot *slot;
- int call_free;
+ pa_bool_t call_free;
slot = mempool_slot_by_ptr(b->pool, pa_atomic_ptr_load(&b->data));
pa_assert(slot);
@@ -532,6 +540,10 @@ static void memblock_free(pa_memblock *b) {
while (pa_flist_push(b->pool->free_slots, slot) < 0)
;
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+ VALGRIND_FREELIKE_BLOCK(slot, b->pool->block_size);
+#endif
+
if (call_free)
if (pa_flist_push(PA_STATIC_FLIST_GET(unused_memblocks), b) < 0)
pa_xfree(b);
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index d257b4ce..9e60125e 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -183,7 +183,7 @@ fail:
return NULL;
}
-static void free_func(void *p, PA_GCC_UNUSED void*userdata) {
+static void free_func(void *p, void*userdata) {
struct entry *e = p;
pa_assert(e);
diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c
index dbafa8c9..29003af8 100644
--- a/src/pulsecore/module.c
+++ b/src/pulsecore/module.c
@@ -48,7 +48,7 @@
#define UNLOAD_POLL_TIME 2
-static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) {
pa_core *c = PA_CORE(userdata);
struct timeval ntv;
@@ -190,7 +190,7 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx, pa_bool_t force) {
pa_assert(c);
pa_assert(idx != PA_IDXSET_INVALID);
- if (m->core->disallow_module_loading && !force)
+ if (c->disallow_module_loading && !force)
return;
if (!(m = pa_idxset_remove_by_index(c->modules, idx)))
diff --git a/src/pulsecore/pdispatch.c b/src/pulsecore/pdispatch.c
index e6a6ae4d..00df0f79 100644
--- a/src/pulsecore/pdispatch.c
+++ b/src/pulsecore/pdispatch.c
@@ -255,7 +255,7 @@ finish:
return ret;
}
-static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
+static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, const struct timeval *tv, void *userdata) {
struct reply_info*r = userdata;
pa_assert(r);
diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c
index addb17cc..81148da4 100644
--- a/src/pulsecore/pid.c
+++ b/src/pulsecore/pid.c
@@ -73,6 +73,7 @@ static pid_t read_pid(const char *fn, int fd) {
if (pa_atou(t, &pid) < 0) {
pa_log_warn("Failed to parse PID file '%s'", fn);
+ errno = EINVAL;
return (pid_t) -1;
}
@@ -110,7 +111,7 @@ static int open_pid_file(const char *fn, int mode) {
goto fail;
}
- /* Does the file still exist in the file system? When ye, w're done, otherwise restart */
+ /* Does the file still exist in the file system? When yes, we're done, otherwise restart */
if (st.st_nlink >= 1)
break;
@@ -131,8 +132,10 @@ static int open_pid_file(const char *fn, int mode) {
fail:
if (fd >= 0) {
+ int saved_errno = errno;
pa_lock_fd(fd, 0);
pa_close(fd);
+ errno = saved_errno;
}
return -1;
@@ -154,8 +157,11 @@ static int proc_name_ours(pid_t pid, const char *procname) {
char stored[64];
if (!(fgets(stored, sizeof(stored), f))) {
+ int saved_errno = feof(f) ? EINVAL : errno;
pa_log_info("Failed to read from %s: %s", bn, feof(f) ? "EOF" : pa_cstrerror(errno));
fclose(f);
+
+ errno = saved_errno;
return -1;
}
@@ -342,8 +348,13 @@ int pa_pid_file_kill(int sig, pid_t *pid, const char *procname) {
if (!(fn = pa_runtime_path("pid")))
goto fail;
- if ((fd = open_pid_file(fn, O_RDONLY)) < 0)
+ if ((fd = open_pid_file(fn, O_RDONLY)) < 0) {
+
+ if (errno == ENOENT)
+ errno = ESRCH;
+
goto fail;
+ }
if ((*pid = read_pid(fn, fd)) == (pid_t) -1)
goto fail;
@@ -354,8 +365,10 @@ int pa_pid_file_kill(int sig, pid_t *pid, const char *procname) {
if ((ours = proc_name_ours(*pid, procname)) < 0)
goto fail;
- if (!ours)
+ if (!ours) {
+ errno = ESRCH;
goto fail;
+ }
}
ret = kill(*pid, sig);
@@ -363,8 +376,10 @@ int pa_pid_file_kill(int sig, pid_t *pid, const char *procname) {
fail:
if (fd >= 0) {
+ int saved_errno = errno;
pa_lock_fd(fd, 0);
pa_close(fd);
+ errno = saved_errno;
}
#ifdef __linux__
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index 4f121a3a..36d1b458 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -334,7 +334,7 @@ static int format_native2esd(pa_sample_spec *ss) {
/*** esound commands ***/
-static int esd_proto_connect(connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
+static int esd_proto_connect(connection *c, esd_proto_t request, const void *data, size_t length) {
uint32_t ekey;
int ok;
@@ -377,7 +377,7 @@ static int esd_proto_connect(connection *c, PA_GCC_UNUSED esd_proto_t request, c
return 0;
}
-static int esd_proto_stream_play(connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
+static int esd_proto_stream_play(connection *c, esd_proto_t request, const void *data, size_t length) {
char name[ESD_NAME_MAX], *utf8_name;
int32_t format, rate;
pa_sample_spec ss;
@@ -561,7 +561,7 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
return 0;
}
-static int esd_proto_get_latency(connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
+static int esd_proto_get_latency(connection *c, esd_proto_t request, const void *data, size_t length) {
pa_sink *sink;
int32_t latency;
@@ -581,7 +581,7 @@ static int esd_proto_get_latency(connection *c, PA_GCC_UNUSED esd_proto_t reques
return 0;
}
-static int esd_proto_server_info(connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
+static int esd_proto_server_info(connection *c, esd_proto_t request, const void *data, size_t length) {
int32_t rate = 44100, format = ESD_STEREO|ESD_BITS16;
int32_t response;
pa_sink *sink;
@@ -736,7 +736,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
return 0;
}
-static int esd_proto_stream_pan(connection *c, PA_GCC_UNUSED 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) {
int32_t ok;
uint32_t idx, lvolume, rvolume;
connection *conn;
@@ -772,7 +772,7 @@ static int esd_proto_stream_pan(connection *c, PA_GCC_UNUSED esd_proto_t request
return 0;
}
-static int esd_proto_sample_cache(connection *c, PA_GCC_UNUSED 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) {
pa_sample_spec ss;
int32_t format, rate, sc_length;
uint32_t idx;
@@ -824,7 +824,7 @@ static int esd_proto_sample_cache(connection *c, PA_GCC_UNUSED esd_proto_t reque
return 0;
}
-static int esd_proto_sample_get_id(connection *c, PA_GCC_UNUSED 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) {
int32_t ok;
uint32_t idx;
char name[ESD_NAME_MAX+sizeof(SCACHE_PREFIX)-1];
@@ -881,7 +881,7 @@ static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, con
return 0;
}
-static int esd_proto_standby_or_resume(connection *c, PA_GCC_UNUSED esd_proto_t request, PA_GCC_UNUSED const void *data, PA_GCC_UNUSED size_t length) {
+static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const void *data, size_t length) {
int32_t ok;
connection_assert_ref(c);
@@ -1574,7 +1574,7 @@ int pa_esound_options_parse(pa_esound_options *o, pa_core *c, pa_modargs *ma) {
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
pa_ip_acl *ipa;
- if (!(o->auth_ip_acl = pa_ip_acl_new(acl))) {
+ if (!(ipa = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
return -1;
}
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index b9f6f083..b7466022 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -883,7 +883,6 @@ static playback_stream* playback_stream_new(
pa_assert(tlength);
pa_assert(prebuf);
pa_assert(minreq);
- pa_assert(volume);
pa_assert(missing);
pa_assert(p);
@@ -916,7 +915,8 @@ static playback_stream* playback_stream_new(
data.sink = sink;
pa_sink_input_new_data_set_sample_spec(&data, ss);
pa_sink_input_new_data_set_channel_map(&data, map);
- pa_sink_input_new_data_set_volume(&data, volume);
+ if (volume)
+ pa_sink_input_new_data_set_volume(&data, volume);
pa_sink_input_new_data_set_muted(&data, muted);
data.sync_base = ssync ? ssync->sink_input : NULL;
@@ -1572,7 +1572,7 @@ static pa_tagstruct *reply_new(uint32_t tag) {
return reply;
}
-static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
playback_stream *s;
uint32_t maxlength, tlength, prebuf, minreq, sink_index, syncid, missing;
@@ -1596,6 +1596,7 @@ static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
pa_sink_input_flags_t flags = 0;
pa_proplist *p;
+ pa_bool_t volume_set = TRUE;
pa_native_connection_assert_ref(c);
pa_assert(t);
@@ -1621,7 +1622,9 @@ static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, sink_index != PA_INVALID_INDEX || !sink_name || (*sink_name && pa_utf8_valid(sink_name)), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !sink_name || pa_namereg_is_valid_name(sink_name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, sink_index == PA_INVALID_INDEX || !sink_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !sink_name || sink_index == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_channel_map_valid(&map), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_sample_spec_valid(&ss), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_cvolume_valid(&volume), tag, PA_ERR_INVALID);
@@ -1660,6 +1663,15 @@ static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
}
}
+ if (c->version >= 14) {
+
+ if (pa_tagstruct_get_boolean(t, &volume_set) < 0) {
+ protocol_error(c);
+ pa_proplist_free(p);
+ return;
+ }
+ }
+
if (!pa_tagstruct_eof(t)) {
protocol_error(c);
pa_proplist_free(p);
@@ -1693,7 +1705,7 @@ static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
(no_move ? PA_SINK_INPUT_DONT_MOVE : 0) |
(variable_rate ? PA_SINK_INPUT_VARIABLE_RATE : 0);
- s = playback_stream_new(c, sink, &ss, &map, &maxlength, &tlength, &prebuf, &minreq, &volume, muted, syncid, &missing, flags, p, adjust_latency);
+ s = playback_stream_new(c, sink, &ss, &map, &maxlength, &tlength, &prebuf, &minreq, volume_set ? &volume : NULL, muted, syncid, &missing, flags, p, adjust_latency);
pa_proplist_free(p);
CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID);
@@ -1735,7 +1747,7 @@ static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_delete_stream(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_delete_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t channel;
@@ -1793,7 +1805,7 @@ static void command_delete_stream(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t comma
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_create_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_create_record_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
record_stream *s;
uint32_t maxlength, fragment_size;
@@ -1835,9 +1847,11 @@ static void command_create_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, !source_name || pa_namereg_is_valid_name(source_name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, source_index == PA_INVALID_INDEX || !source_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !source_name || source_index == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_sample_spec_valid(&ss), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_channel_map_valid(&map), tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, source_index != PA_INVALID_INDEX || !source_name || (*source_name && pa_utf8_valid(source_name)), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, map.channels == ss.channels, tag, PA_ERR_INVALID);
p = pa_proplist_new();
@@ -1953,7 +1967,7 @@ static void command_create_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_exit(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_exit(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
int ret;
@@ -1972,7 +1986,7 @@ static void command_exit(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t
pa_pstream_send_simple_ack(c->pstream, tag); /* nonsense */
}
-static void command_auth(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_auth(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const void*cookie;
pa_tagstruct *reply;
@@ -2103,7 +2117,7 @@ static void command_auth(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t
#endif
}
-static void command_set_client_name(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_set_client_name(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *name = NULL;
pa_proplist *p;
@@ -2143,7 +2157,7 @@ static void command_set_client_name(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSE
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_lookup(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_lookup(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *name;
uint32_t idx = PA_IDXSET_INVALID;
@@ -2158,7 +2172,7 @@ static void command_lookup(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uin
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, name && *name && pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
if (command == PA_COMMAND_LOOKUP_SINK) {
pa_sink *sink;
@@ -2181,7 +2195,7 @@ static void command_lookup(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uin
}
}
-static void command_drain_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_drain_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
playback_stream *s;
@@ -2203,7 +2217,7 @@ static void command_drain_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC
pa_asyncmsgq_post(s->sink_input->sink->asyncmsgq, PA_MSGOBJECT(s->sink_input), SINK_INPUT_MESSAGE_DRAIN, PA_UINT_TO_PTR(tag), 0, NULL, NULL);
}
-static void command_stat(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_stat(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_tagstruct *reply;
const pa_mempool_stat *stat;
@@ -2229,7 +2243,7 @@ static void command_stat(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_get_playback_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_playback_latency(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_tagstruct *reply;
playback_stream *s;
@@ -2275,7 +2289,7 @@ static void command_get_playback_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_get_record_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_record_latency(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_tagstruct *reply;
record_stream *s;
@@ -2307,7 +2321,7 @@ static void command_get_record_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UN
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_create_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_create_upload_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
upload_stream *s;
uint32_t length;
@@ -2349,7 +2363,7 @@ static void command_create_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
if (!(name = pa_proplist_gets(p, PA_PROP_EVENT_ID)))
name = pa_proplist_gets(p, PA_PROP_MEDIA_NAME);
- CHECK_VALIDITY(c->pstream, name && *name && pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
s = upload_stream_new(c, &ss, &map, name, length, p);
pa_proplist_free(p);
@@ -2362,7 +2376,7 @@ static void command_create_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_finish_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_finish_upload_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t channel;
upload_stream *s;
@@ -2391,7 +2405,7 @@ static void command_finish_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
upload_stream_unlink(s);
}
-static void command_play_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_play_sample(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t sink_index;
pa_volume_t volume;
@@ -2414,8 +2428,10 @@ static void command_play_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED ui
return;
}
- CHECK_VALIDITY(c->pstream, sink_index != PA_INVALID_INDEX || !sink_name || (*sink_name && pa_utf8_valid(name)), tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, name && *name && pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !sink_name || pa_namereg_is_valid_name(sink_name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, sink_index == PA_INVALID_INDEX || !sink_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !sink_name || sink_index == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
if (sink_index != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, sink_index);
@@ -2451,7 +2467,7 @@ static void command_play_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED ui
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_remove_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_remove_sample(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *name;
@@ -2465,7 +2481,7 @@ static void command_remove_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, name && *name && pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
if (pa_scache_remove_item(c->protocol->core, name) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
@@ -2509,8 +2525,8 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
PA_TAG_SAMPLE_SPEC, &fixed_ss,
PA_TAG_CHANNEL_MAP, &sink->channel_map,
PA_TAG_U32, sink->module ? sink->module->index : PA_INVALID_INDEX,
- PA_TAG_CVOLUME, pa_sink_get_volume(sink),
- PA_TAG_BOOLEAN, pa_sink_get_mute(sink),
+ PA_TAG_CVOLUME, pa_sink_get_volume(sink, FALSE),
+ PA_TAG_BOOLEAN, pa_sink_get_mute(sink, FALSE),
PA_TAG_U32, sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
PA_TAG_STRING, sink->monitor_source ? sink->monitor_source->name : NULL,
PA_TAG_USEC, pa_sink_get_latency(sink),
@@ -2540,8 +2556,8 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
PA_TAG_SAMPLE_SPEC, &fixed_ss,
PA_TAG_CHANNEL_MAP, &source->channel_map,
PA_TAG_U32, source->module ? source->module->index : PA_INVALID_INDEX,
- PA_TAG_CVOLUME, pa_source_get_volume(source),
- PA_TAG_BOOLEAN, pa_source_get_mute(source),
+ PA_TAG_CVOLUME, pa_source_get_volume(source, FALSE),
+ PA_TAG_BOOLEAN, pa_source_get_mute(source, FALSE),
PA_TAG_U32, source->monitor_of ? source->monitor_of->index : PA_INVALID_INDEX,
PA_TAG_STRING, source->monitor_of ? source->monitor_of->name : NULL,
PA_TAG_USEC, pa_source_get_latency(source),
@@ -2658,7 +2674,7 @@ static void scache_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
pa_tagstruct_put_proplist(t, e->proplist);
}
-static void command_get_info(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
pa_sink *sink = NULL;
@@ -2686,7 +2702,10 @@ static void command_get_info(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, u
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || (*name && pa_utf8_valid(name)), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_GET_SINK_INFO) {
if (idx != PA_INVALID_INDEX)
@@ -2737,7 +2756,7 @@ static void command_get_info(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, u
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_get_info_list(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_info_list(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_idxset *i;
uint32_t idx;
@@ -2797,7 +2816,7 @@ static void command_get_info_list(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t comma
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_get_server_info(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_server_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_tagstruct *reply;
char txt[256];
@@ -2847,7 +2866,7 @@ static void subscription_cb(pa_core *core, pa_subscription_event_type_t e, uint3
pa_pstream_send_tagstruct(c->pstream, t);
}
-static void command_subscribe(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_subscribe(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_subscription_mask_t m;
@@ -2876,7 +2895,7 @@ static void command_subscribe(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint
}
static void command_set_volume(
- PA_GCC_UNUSED pa_pdispatch *pd,
+ pa_pdispatch *pd,
uint32_t command,
uint32_t tag,
pa_tagstruct *t,
@@ -2903,7 +2922,10 @@ static void command_set_volume(
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || (*name && pa_utf8_valid(name)), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_cvolume_valid(&volume), tag, PA_ERR_INVALID);
switch (command) {
@@ -2943,7 +2965,7 @@ static void command_set_volume(
}
static void command_set_mute(
- PA_GCC_UNUSED pa_pdispatch *pd,
+ pa_pdispatch *pd,
uint32_t command,
uint32_t tag,
pa_tagstruct *t,
@@ -2970,7 +2992,10 @@ static void command_set_mute(
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || (*name && pa_utf8_valid(name)), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
switch (command) {
@@ -3011,7 +3036,7 @@ static void command_set_mute(
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_cork_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_cork_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
pa_bool_t b;
@@ -3037,7 +3062,7 @@ static void command_cork_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_trigger_or_flush_or_prebuf_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_trigger_or_flush_or_prebuf_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
playback_stream *s;
@@ -3077,7 +3102,7 @@ static void command_trigger_or_flush_or_prebuf_playback_stream(PA_GCC_UNUSED pa_
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_cork_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_cork_record_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
record_stream *s;
@@ -3102,7 +3127,7 @@ static void command_cork_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UN
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_flush_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_flush_record_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
record_stream *s;
@@ -3413,7 +3438,7 @@ static void command_remove_proplist(pa_pdispatch *pd, uint32_t command, uint32_t
}
}
-static void command_set_default_sink_or_source(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *s;
@@ -3427,13 +3452,13 @@ static void command_set_default_sink_or_source(PA_GCC_UNUSED pa_pdispatch *pd, u
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, !s || (*s && pa_utf8_valid(s)), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !s || pa_namereg_is_valid_name(s), tag, PA_ERR_INVALID);
pa_namereg_set_default(c->protocol->core, s, command == PA_COMMAND_SET_DEFAULT_SOURCE ? PA_NAMEREG_SOURCE : PA_NAMEREG_SINK);
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_set_stream_name(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_set_stream_name(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
const char *name;
@@ -3473,7 +3498,7 @@ static void command_set_stream_name(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t com
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_kill(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_kill(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
@@ -3521,7 +3546,7 @@ static void command_kill(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint3
pa_native_connection_unref(c);
}
-static void command_load_module(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_load_module(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_module *m;
const char *name, *argument;
@@ -3551,7 +3576,7 @@ static void command_load_module(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED ui
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_unload_module(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_unload_module(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx;
pa_module *m;
@@ -3573,7 +3598,7 @@ static void command_unload_module(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_add_autoload(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_add_autoload(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *name, *module, *argument;
uint32_t type;
@@ -3608,7 +3633,7 @@ static void command_add_autoload(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED u
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_remove_autoload(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_remove_autoload(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const char *name = NULL;
uint32_t type, idx = PA_IDXSET_INVALID;
@@ -3649,7 +3674,7 @@ static void autoload_fill_tagstruct(pa_tagstruct *t, const pa_autoload_entry *e)
pa_tagstruct_puts(t, e->argument);
}
-static void command_get_autoload_info(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_autoload_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
const pa_autoload_entry *a = NULL;
uint32_t type, idx;
@@ -3683,7 +3708,7 @@ static void command_get_autoload_info(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNU
pa_pstream_send_tagstruct(c->pstream, reply);
}
-static void command_get_autoload_info_list(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_get_autoload_info_list(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_tagstruct *reply;
@@ -3713,14 +3738,14 @@ static void command_get_autoload_info_list(PA_GCC_UNUSED pa_pdispatch *pd, PA_GC
static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx = PA_INVALID_INDEX, idx_device = PA_INVALID_INDEX;
- const char *name = NULL;
+ const char *name_device = NULL;
pa_native_connection_assert_ref(c);
pa_assert(t);
if (pa_tagstruct_getu32(t, &idx) < 0 ||
pa_tagstruct_getu32(t, &idx_device) < 0 ||
- pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_gets(t, &name_device) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
@@ -3728,7 +3753,11 @@ static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX, tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, idx_device != PA_INVALID_INDEX || !name || (*name && pa_utf8_valid(name)), tag, PA_ERR_INVALID);
+
+ CHECK_VALIDITY(c->pstream, !name_device || pa_namereg_is_valid_name(name_device), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx_device != PA_INVALID_INDEX || name_device, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx_device == PA_INVALID_INDEX || !name_device, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name_device || idx_device == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_MOVE_SINK_INPUT) {
pa_sink_input *si = NULL;
@@ -3739,7 +3768,7 @@ static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag
if (idx_device != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, idx_device);
else
- sink = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SINK, 1);
+ sink = pa_namereg_get(c->protocol->core, name_device, PA_NAMEREG_SINK, 1);
CHECK_VALIDITY(c->pstream, si && sink, tag, PA_ERR_NOENTITY);
@@ -3758,7 +3787,7 @@ static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag
if (idx_device != PA_INVALID_INDEX)
source = pa_idxset_get_by_index(c->protocol->core->sources, idx_device);
else
- source = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SOURCE, 1);
+ source = pa_namereg_get(c->protocol->core, name_device, PA_NAMEREG_SOURCE, 1);
CHECK_VALIDITY(c->pstream, so && source, tag, PA_ERR_NOENTITY);
@@ -3789,7 +3818,10 @@ static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || !*name || pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_SUSPEND_SINK) {
@@ -3862,7 +3894,10 @@ static void command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag,
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || !*name || pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || pa_utf8_valid(name), tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
if (idx != PA_INVALID_INDEX)
m = pa_idxset_get_by_index(c->protocol->core->modules, idx);
@@ -4299,7 +4334,7 @@ int pa_native_options_parse(pa_native_options *o, pa_core *c, pa_modargs *ma) {
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
pa_ip_acl *ipa;
- if (!(o->auth_ip_acl = pa_ip_acl_new(acl))) {
+ if (!(ipa = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
return -1;
}
diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index 6b1af67b..48404cca 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -283,7 +283,7 @@ pa_pstream *pa_pstream_new(pa_mainloop_api *m, pa_iochannel *io, pa_mempool *poo
return p;
}
-static void item_free(void *item, PA_GCC_UNUSED void *q) {
+static void item_free(void *item, void *q) {
struct item_info *i = item;
pa_assert(i);
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index b42b79d1..0cdbcd02 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -160,7 +160,8 @@ size_t pa_mix(
pa_cvolume full_volume;
unsigned k;
- size_t d = 0;
+ unsigned z;
+ void *end;
pa_assert(streams);
pa_assert(data);
@@ -170,9 +171,20 @@ size_t pa_mix(
if (!volume)
volume = pa_cvolume_reset(&full_volume, spec->channels);
+ if (mute || pa_cvolume_is_muted(volume) || nstreams <= 0) {
+ pa_silence_memory(data, length, spec);
+ return length;
+ }
+
for (k = 0; k < nstreams; k++)
streams[k].ptr = (uint8_t*) pa_memblock_acquire(streams[k].chunk.memblock) + streams[k].chunk.index;
+ for (z = 0; z < nstreams; z++)
+ if (length > streams[z].chunk.length)
+ length = streams[z].chunk.length;
+
+ end = (uint8_t*) data + length;
+
switch (spec->format) {
case PA_SAMPLE_S16NE:{
@@ -182,21 +194,15 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d += sizeof(int16_t)) {
+ while (data < end) {
int32_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int32_t v, cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = *((int16_t*) m->ptr);
@@ -207,8 +213,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + sizeof(int16_t);
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
*((int16_t*) data) = (int16_t) sum;
data = (uint8_t*) data + sizeof(int16_t);
@@ -227,21 +233,15 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d += sizeof(int16_t)) {
+ while (data < end) {
int32_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int32_t v, cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = PA_INT16_SWAP(*((int16_t*) m->ptr));
@@ -252,8 +252,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + sizeof(int16_t);
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
*((int16_t*) data) = PA_INT16_SWAP((int16_t) sum);
data = (uint8_t*) data + sizeof(int16_t);
@@ -272,22 +272,16 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d += sizeof(int32_t)) {
+ while (data < end) {
int64_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int64_t v;
int32_t cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = *((int32_t*) m->ptr);
@@ -298,8 +292,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + sizeof(int32_t);
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL);
*((int32_t*) data) = (int32_t) sum;
data = (uint8_t*) data + sizeof(int32_t);
@@ -318,22 +312,16 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d += sizeof(int32_t)) {
+ while (data < end) {
int64_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int64_t v;
int32_t cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = PA_INT32_SWAP(*((int32_t*) m->ptr));
@@ -344,8 +332,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + sizeof(int32_t);
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL);
*((int32_t*) data) = PA_INT32_SWAP((int32_t) sum);
data = (uint8_t*) data + sizeof(int32_t);
@@ -364,21 +352,15 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d ++) {
+ while (data < end) {
int32_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int32_t v, cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = (int32_t) *((uint8_t*) m->ptr) - 0x80;
@@ -409,21 +391,15 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d ++) {
+ while (data < end) {
int32_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int32_t v, cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = (int32_t) st_ulaw2linear16(*((uint8_t*) m->ptr));
@@ -434,8 +410,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + 1;
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
*((uint8_t*) data) = (uint8_t) st_14linear2ulaw(sum >> 2);
data = (uint8_t*) data + 1;
@@ -454,21 +430,15 @@ size_t pa_mix(
calc_linear_integer_stream_volumes(streams, nstreams, spec);
calc_linear_integer_volume(linear, volume);
- for (d = 0;; d ++) {
+ while (data < end) {
int32_t sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
int32_t v, cv = m->linear[channel].i;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = (int32_t) st_alaw2linear16(*((uint8_t*) m->ptr));
@@ -479,8 +449,8 @@ size_t pa_mix(
m->ptr = (uint8_t*) m->ptr + 1;
}
- sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
sum = (sum * linear[channel]) / 0x10000;
+ sum = PA_CLAMP_UNLIKELY(sum, -0x8000, 0x7FFF);
*((uint8_t*) data) = (uint8_t) st_13linear2alaw(sum >> 3);
data = (uint8_t*) data + 1;
@@ -499,21 +469,15 @@ size_t pa_mix(
calc_linear_float_stream_volumes(streams, nstreams, spec);
calc_linear_float_volume(linear, volume);
- for (d = 0;; d += sizeof(float)) {
+ while (data < end) {
float sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
float v, cv = m->linear[channel].f;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
else {
v = *((float*) m->ptr);
@@ -543,35 +507,25 @@ size_t pa_mix(
calc_linear_float_stream_volumes(streams, nstreams, spec);
calc_linear_float_volume(linear, volume);
- for (d = 0;; d += sizeof(float)) {
+ while (data < end) {
float sum = 0;
unsigned i;
- if (PA_UNLIKELY(d >= length))
- goto finish;
-
for (i = 0; i < nstreams; i++) {
pa_mix_info *m = streams + i;
float v, cv = m->linear[channel].f;
- if (PA_UNLIKELY(d >= m->chunk.length))
- goto finish;
-
- if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(!!mute) || PA_UNLIKELY(linear[channel] <= 0))
+ if (PA_UNLIKELY(cv <= 0) || PA_UNLIKELY(linear[channel] <= 0))
v = 0;
- else {
- uint32_t z = *(uint32_t*) m->ptr;
- z = PA_UINT32_SWAP(z);
- v = *((float*) &z);
- v *= cv;
- }
+ else
+ v = PA_FLOAT32_SWAP(*(float*) m->ptr) *cv;
sum += v;
m->ptr = (uint8_t*) m->ptr + sizeof(float);
}
sum *= linear[channel];
- *((uint32_t*) data) = PA_UINT32_SWAP(*(uint32_t*) &sum);
+ *((float*) data) = PA_FLOAT32_SWAP(sum);
data = (uint8_t*) data + sizeof(float);
@@ -583,16 +537,14 @@ size_t pa_mix(
}
default:
- pa_log_error("ERROR: Unable to mix audio data of format %s.", pa_sample_format_to_string(spec->format));
+ pa_log_error("Unable to mix audio data of format %s.", pa_sample_format_to_string(spec->format));
pa_assert_not_reached();
}
-finish:
-
for (k = 0; k < nstreams; k++)
pa_memblock_release(streams[k].chunk.memblock);
- return d;
+ return length;
}
@@ -624,14 +576,15 @@ void pa_volume_memchunk(
switch (spec->format) {
case PA_SAMPLE_S16NE: {
- int16_t *d;
- size_t n;
+ int16_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int16_t); n > 0; d++, n--) {
+ e = (int16_t*) ptr + c->length/sizeof(int16_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t)(*d);
@@ -646,17 +599,18 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S16RE: {
- int16_t *d;
- size_t n;
+ int16_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int16_t); n > 0; d++, n--) {
+ e = (int16_t*) ptr + c->length/sizeof(int16_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
- t = (int32_t)(PA_INT16_SWAP(*d));
+ t = (int32_t) PA_INT16_SWAP(*d);
t = (t * linear[channel]) / 0x10000;
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*d = PA_INT16_SWAP((int16_t) t);
@@ -669,14 +623,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S32NE: {
- int32_t *d;
- size_t n;
+ int32_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int32_t); n > 0; d++, n--) {
+ e = (int32_t*) ptr + c->length/sizeof(int32_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int64_t t;
t = (int64_t)(*d);
@@ -691,17 +646,18 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S32RE: {
- int32_t *d;
- size_t n;
+ int32_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int32_t); n > 0; d++, n--) {
+ e = (int32_t*) ptr + c->length/sizeof(int32_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int64_t t;
- t = (int64_t)(PA_INT32_SWAP(*d));
+ t = (int64_t) PA_INT32_SWAP(*d);
t = (t * linear[channel]) / 0x10000;
t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
*d = PA_INT32_SWAP((int32_t) t);
@@ -714,14 +670,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_U8: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) *d - 0x80;
@@ -736,14 +693,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_ULAW: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) st_ulaw2linear16(*d);
@@ -758,14 +716,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_ALAW: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) st_alaw2linear16(*d);
@@ -803,22 +762,20 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_FLOAT32RE: {
- uint32_t *d;
- size_t n;
+ float *d, *e;
unsigned channel;
float linear[PA_CHANNELS_MAX];
calc_linear_float_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(float); n > 0; d++, n--) {
+ e = (float*) ptr + c->length/sizeof(float);
+
+ for (channel = 0, d = ptr; d < e; d++) {
float t;
- uint32_t z;
- z = PA_UINT32_SWAP(*d);
- t = *(float*) &z;
+ t = PA_FLOAT32_SWAP(*d);
t *= linear[channel];
- z = *(uint32_t*) &t;
- *d = PA_UINT32_SWAP(z);
+ *d = PA_FLOAT32_SWAP(t);
if (PA_UNLIKELY(++channel >= spec->channels))
channel = 0;
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index c07a7404..7663f22c 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -212,19 +212,19 @@ typedef struct pa_sink_input_new_data {
pa_sink *sink;
+ pa_resample_method_t resample_method;
+
+ pa_sink_input *sync_base;
+
pa_sample_spec sample_spec;
- pa_bool_t sample_spec_is_set;
pa_channel_map channel_map;
- pa_bool_t channel_map_is_set;
-
pa_cvolume volume;
- pa_bool_t volume_is_set;
- pa_bool_t muted;
- pa_bool_t muted_is_set;
-
- pa_resample_method_t resample_method;
+ pa_bool_t muted:1;
- pa_sink_input *sync_base;
+ pa_bool_t sample_spec_is_set:1;
+ pa_bool_t channel_map_is_set:1;
+ pa_bool_t volume_is_set:1;
+ pa_bool_t muted_is_set:1;
} pa_sink_input_new_data;
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 4102f31d..24fb8913 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -856,18 +856,29 @@ void pa_sink_set_volume(pa_sink *s, const pa_cvolume *volume) {
s->set_volume = NULL;
if (!s->set_volume)
- pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_VOLUME, volume, 0, NULL);
+ pa_sink_set_soft_volume(s, volume);
if (changed)
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
/* Called from main thread */
-const pa_cvolume *pa_sink_get_volume(pa_sink *s) {
+void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume) {
+ pa_sink_assert_ref(s);
+ pa_assert(volume);
+
+ if (PA_SINK_IS_LINKED(s->state))
+ pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_VOLUME, volume, 0, NULL);
+ else
+ s->thread_info.soft_volume = *volume;
+}
+
+/* Called from main thread */
+const pa_cvolume *pa_sink_get_volume(pa_sink *s, pa_bool_t force_refresh) {
pa_sink_assert_ref(s);
pa_assert(PA_SINK_IS_LINKED(s->state));
- if (s->refresh_volume) {
+ if (s->refresh_volume || force_refresh) {
struct pa_cvolume old_volume = s->volume;
if (s->get_volume && s->get_volume(s) < 0)
@@ -904,12 +915,12 @@ void pa_sink_set_mute(pa_sink *s, pa_bool_t mute) {
}
/* Called from main thread */
-pa_bool_t pa_sink_get_mute(pa_sink *s) {
+pa_bool_t pa_sink_get_mute(pa_sink *s, pa_bool_t force_refresh) {
pa_sink_assert_ref(s);
pa_assert(PA_SINK_IS_LINKED(s->state));
- if (s->refresh_muted) {
+ if (s->refresh_muted || force_refresh) {
pa_bool_t old_muted = s->muted;
if (s->get_mute && s->get_mute(s) < 0)
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 604be269..672bdd39 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -180,21 +180,22 @@ typedef enum pa_sink_message {
typedef struct pa_sink_new_data {
char *name;
- pa_bool_t namereg_fail;
pa_proplist *proplist;
const char *driver;
pa_module *module;
pa_sample_spec sample_spec;
- pa_bool_t sample_spec_is_set;
pa_channel_map channel_map;
- pa_bool_t channel_map_is_set;
-
pa_cvolume volume;
- pa_bool_t volume_is_set;
- pa_bool_t muted;
- pa_bool_t muted_is_set;
+ pa_bool_t muted :1;
+
+ pa_bool_t sample_spec_is_set:1;
+ pa_bool_t channel_map_is_set:1;
+ pa_bool_t volume_is_set:1;
+ pa_bool_t muted_is_set:1;
+
+ pa_bool_t namereg_fail:1;
} pa_sink_new_data;
pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data);
@@ -239,9 +240,10 @@ int pa_sink_suspend(pa_sink *s, pa_bool_t suspend);
int pa_sink_suspend_all(pa_core *c, pa_bool_t suspend);
void pa_sink_set_volume(pa_sink *sink, const pa_cvolume *volume);
-const pa_cvolume *pa_sink_get_volume(pa_sink *sink);
+void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume);
+const pa_cvolume *pa_sink_get_volume(pa_sink *sink, pa_bool_t force_refresh);
void pa_sink_set_mute(pa_sink *sink, pa_bool_t mute);
-pa_bool_t pa_sink_get_mute(pa_sink *sink);
+pa_bool_t pa_sink_get_mute(pa_sink *sink, pa_bool_t force_refres);
unsigned pa_sink_linked_by(pa_sink *s); /* Number of connected streams */
unsigned pa_sink_used_by(pa_sink *s); /* Number of connected streams which are not corked */
diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c
index e69a63da..7be0e242 100644
--- a/src/pulsecore/socket-client.c
+++ b/src/pulsecore/socket-client.c
@@ -187,7 +187,7 @@ static void connect_defer_cb(pa_mainloop_api *m, pa_defer_event *e, void *userda
do_call(c);
}
-static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
pa_socket_client *c = userdata;
pa_assert(m);
@@ -370,7 +370,7 @@ pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[
#ifdef HAVE_LIBASYNCNS
-static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
pa_socket_client *c = userdata;
struct addrinfo *res = NULL;
int ret;
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index 61825b22..a7aac814 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -174,12 +174,13 @@ typedef struct pa_source_output_new_data {
pa_source *source;
+ pa_resample_method_t resample_method;
+
pa_sample_spec sample_spec;
- pa_bool_t sample_spec_is_set;
pa_channel_map channel_map;
- pa_bool_t channel_map_is_set;
- pa_resample_method_t resample_method;
+ pa_bool_t sample_spec_is_set:1;
+ pa_bool_t channel_map_is_set:1;
} pa_source_output_new_data;
pa_source_output_new_data* pa_source_output_new_data_init(pa_source_output_new_data *data);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 31620690..7ed32e92 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -520,18 +520,29 @@ void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) {
s->set_volume = NULL;
if (!s->set_volume)
- pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_VOLUME, volume, 0, NULL);
+ pa_source_set_soft_volume(s, volume);
if (changed)
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
/* Called from main thread */
-const pa_cvolume *pa_source_get_volume(pa_source *s) {
+void pa_source_set_soft_volume(pa_source *s, const pa_cvolume *volume) {
+ pa_source_assert_ref(s);
+ pa_assert(volume);
+
+ if (PA_SOURCE_IS_LINKED(s->state))
+ pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_VOLUME, volume, 0, NULL);
+ else
+ s->thread_info.soft_volume = *volume;
+}
+
+/* Called from main thread */
+const pa_cvolume *pa_source_get_volume(pa_source *s, pa_bool_t force_refresh) {
pa_source_assert_ref(s);
pa_assert(PA_SOURCE_IS_LINKED(s->state));
- if (s->refresh_volume) {
+ if (s->refresh_volume || force_refresh) {
pa_cvolume old_volume = s->volume;
if (s->get_volume && s->get_volume(s) < 0)
@@ -568,12 +579,12 @@ void pa_source_set_mute(pa_source *s, pa_bool_t mute) {
}
/* Called from main thread */
-pa_bool_t pa_source_get_mute(pa_source *s) {
+pa_bool_t pa_source_get_mute(pa_source *s, pa_bool_t force_refresh) {
pa_source_assert_ref(s);
pa_assert(PA_SOURCE_IS_LINKED(s->state));
- if (s->refresh_muted) {
+ if (s->refresh_muted || force_refresh) {
pa_bool_t old_muted = s->muted;
if (s->get_mute && s->get_mute(s) < 0)
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index f4a17e8d..cae78693 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -168,21 +168,22 @@ typedef enum pa_source_message {
typedef struct pa_source_new_data {
char *name;
- pa_bool_t namereg_fail;
pa_proplist *proplist;
const char *driver;
pa_module *module;
pa_sample_spec sample_spec;
- pa_bool_t sample_spec_is_set;
pa_channel_map channel_map;
- pa_bool_t channel_map_is_set;
-
pa_cvolume volume;
- pa_bool_t volume_is_set;
- pa_bool_t muted;
- pa_bool_t muted_is_set;
+ pa_bool_t muted:1;
+
+ pa_bool_t volume_is_set:1;
+ pa_bool_t muted_is_set:1;
+ pa_bool_t sample_spec_is_set:1;
+ pa_bool_t channel_map_is_set:1;
+
+ pa_bool_t namereg_fail:1;
} pa_source_new_data;
pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data);
@@ -226,9 +227,10 @@ int pa_source_suspend(pa_source *s, pa_bool_t suspend);
int pa_source_suspend_all(pa_core *c, pa_bool_t suspend);
void pa_source_set_volume(pa_source *source, const pa_cvolume *volume);
-const pa_cvolume *pa_source_get_volume(pa_source *source);
+void pa_source_set_soft_volume(pa_source *s, const pa_cvolume *volume);
+const pa_cvolume *pa_source_get_volume(pa_source *source, pa_bool_t force_refresh);
void pa_source_set_mute(pa_source *source, pa_bool_t mute);
-pa_bool_t pa_source_get_mute(pa_source *source);
+pa_bool_t pa_source_get_mute(pa_source *source, pa_bool_t force_refresh);
unsigned pa_source_linked_by(pa_source *s); /* Number of connected streams */
unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that are not corked */
diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c
index 20ed16d9..ade398f9 100644
--- a/src/pulsecore/thread-posix.c
+++ b/src/pulsecore/thread-posix.c
@@ -41,6 +41,7 @@ struct pa_thread {
pa_thread_func_t thread_func;
void *userdata;
pa_atomic_t running;
+ pa_bool_t joined;
};
struct pa_tls {
@@ -82,6 +83,7 @@ pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) {
t = pa_xnew(pa_thread, 1);
t->thread_func = thread_func;
t->userdata = userdata;
+ t->joined = FALSE;
pa_atomic_store(&t->running, 0);
if (pthread_create(&t->id, NULL, internal_thread_func, t) < 0) {
@@ -115,7 +117,12 @@ void pa_thread_free(pa_thread *t) {
int pa_thread_join(pa_thread *t) {
pa_assert(t);
+ pa_assert(t->thread_func);
+
+ if (t->joined)
+ return -1;
+ t->joined = TRUE;
return pthread_join(t->id, NULL);
}
@@ -132,6 +139,7 @@ pa_thread* pa_thread_self(void) {
t->id = pthread_self();
t->thread_func = NULL;
t->userdata = NULL;
+ t->joined = TRUE;
pa_atomic_store(&t->running, 2);
PA_STATIC_TLS_SET(current_thread, t);
@@ -192,4 +200,3 @@ void *pa_tls_set(pa_tls *t, void *userdata) {
pa_assert_se(pthread_setspecific(t->key, userdata) == 0);
return r;
}
-
diff --git a/src/pulsecore/tokenizer.c b/src/pulsecore/tokenizer.c
index d1e0836b..07a9f3ac 100644
--- a/src/pulsecore/tokenizer.c
+++ b/src/pulsecore/tokenizer.c
@@ -34,7 +34,7 @@
#include "tokenizer.h"
-static void token_free(void *p, PA_GCC_UNUSED void *userdata) {
+static void token_free(void *p, void *userdata) {
pa_xfree(p);
}
diff --git a/src/pulsecore/x11wrap.c b/src/pulsecore/x11wrap.c
index 17f8e6a4..332ebb2e 100644
--- a/src/pulsecore/x11wrap.c
+++ b/src/pulsecore/x11wrap.c
@@ -91,7 +91,7 @@ static void work(pa_x11_wrapper *w) {
}
/* IO notification event for the X11 display connection */
-static void display_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void display_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
pa_x11_wrapper *w = userdata;
pa_assert(m);
@@ -118,7 +118,7 @@ static void defer_event(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
}
/* IO notification event for X11 internal connections */
-static void internal_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void internal_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
pa_x11_wrapper *w = userdata;
pa_assert(m);
diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c
index 9c234602..12b39f10 100644
--- a/src/tests/channelmap-test.c
+++ b/src/tests/channelmap-test.c
@@ -4,7 +4,7 @@
#include <pulse/channelmap.h>
#include <pulse/gccmacro.h>
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
pa_channel_map map, map2;
diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c
index b7145e8a..fdc0162e 100644
--- a/src/tests/cpulimit-test.c
+++ b/src/tests/cpulimit-test.c
@@ -42,7 +42,7 @@ static time_t start;
#ifdef TEST2
-static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UNUSED int sig, PA_GCC_UNUSED void *userdata) {
+static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
time_t now;
time(&now);
@@ -55,7 +55,7 @@ static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UN
#endif
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
pa_mainloop *m;
m = pa_mainloop_new();
diff --git a/src/tests/lock-autospawn-test.c b/src/tests/lock-autospawn-test.c
new file mode 100644
index 00000000..cb3dc87c
--- /dev/null
+++ b/src/tests/lock-autospawn-test.c
@@ -0,0 +1,109 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2008 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/poll.h>
+#include <string.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/thread.h>
+#include <pulse/lock-autospawn.h>
+#include <pulse/util.h>
+
+static void thread_func(void*k) {
+ pa_assert_se(pa_autospawn_lock_init() >= 0);
+
+ pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
+
+ pa_assert_se(pa_autospawn_lock_acquire(TRUE) > 0);
+
+ pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k));
+
+ pa_msleep(5000);
+
+ pa_log("%i, Releasing", PA_PTR_TO_INT(k));
+
+ pa_autospawn_lock_release();
+
+ pa_autospawn_lock_done(FALSE);
+}
+
+static void thread_func2(void *k) {
+ int fd;
+
+ pa_assert_se((fd = pa_autospawn_lock_init()) >= 0);
+
+ pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
+
+ for (;;) {
+ struct pollfd pollfd;
+ int j;
+
+ if ((j = pa_autospawn_lock_acquire(FALSE)) > 0)
+ break;
+
+ pa_assert(j == 0);
+
+ memset(&pollfd, 0, sizeof(pollfd));
+ pollfd.fd = fd;
+ pollfd.events = POLLIN;
+
+ pa_assert_se(poll(&pollfd, 1, -1) == 1);
+
+ pa_log("%i, woke up", PA_PTR_TO_INT(k));
+ }
+
+ pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k));
+
+ pa_msleep(5000);
+
+ pa_log("%i, Releasing", PA_PTR_TO_INT(k));
+
+ pa_autospawn_lock_release();
+
+ pa_autospawn_lock_done(FALSE);
+}
+
+int main(int argc, char**argv) {
+ pa_thread *a, *b, *c, *d;
+
+ pa_assert_se((a = pa_thread_new(thread_func, PA_INT_TO_PTR(1))));
+ pa_assert_se((b = pa_thread_new(thread_func2, PA_INT_TO_PTR(2))));
+ pa_assert_se((c = pa_thread_new(thread_func2, PA_INT_TO_PTR(3))));
+ pa_assert_se((d = pa_thread_new(thread_func, PA_INT_TO_PTR(4))));
+
+ pa_thread_join(a);
+ pa_thread_join(b);
+ pa_thread_join(c);
+ pa_thread_join(d);
+
+ pa_thread_free(a);
+ pa_thread_free(b);
+ pa_thread_free(c);
+ pa_thread_free(d);
+
+ pa_log("End");
+
+ return 0;
+}
diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c
index 9fa2e466..2580fa72 100644
--- a/src/tests/mainloop-test.c
+++ b/src/tests/mainloop-test.c
@@ -66,7 +66,7 @@ static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, v
#endif
}
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
pa_mainloop_api *a;
pa_io_event *ioe;
pa_time_event *te;
diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c
index 9e358359..e23f098c 100644
--- a/src/tests/mcalign-test.c
+++ b/src/tests/mcalign-test.c
@@ -36,7 +36,7 @@
/* A simple program for testing pa_mcalign */
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
pa_mempool *p;
pa_mcalign *a;
pa_memchunk c;
diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c
index b26e4b68..ed54f57d 100644
--- a/src/tests/pacat-simple.c
+++ b/src/tests/pacat-simple.c
@@ -33,7 +33,7 @@
#define BUFSIZE 1024
-int main(PA_GCC_UNUSED int argc, char*argv[]) {
+int main(int argc, char*argv[]) {
/* The Sample format to use */
static const pa_sample_spec ss = {
diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c
index 6c0d529b..ea34a075 100644
--- a/src/tests/parec-simple.c
+++ b/src/tests/parec-simple.c
@@ -53,7 +53,7 @@ static ssize_t loop_write(int fd, const void*data, size_t size) {
return ret;
}
-int main(PA_GCC_UNUSED int argc, char*argv[]) {
+int main(int argc, char*argv[]) {
/* The sample type to use */
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c
index 2bd1645c..10f370c2 100644
--- a/src/tests/strlist-test.c
+++ b/src/tests/strlist-test.c
@@ -5,7 +5,7 @@
#include <pulsecore/strlist.h>
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) {
+int main(int argc, char* argv[]) {
char *t, *u;
pa_strlist *l = NULL;
diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c
index 7a62f85a..263cd57d 100644
--- a/src/tests/thread-mainloop-test.c
+++ b/src/tests/thread-mainloop-test.c
@@ -39,7 +39,7 @@ static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, v
fprintf(stderr, "TIME EVENT END\n");
}
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
pa_mainloop_api *a;
pa_threaded_mainloop *m;
struct timeval tv;
diff --git a/src/tests/voltest.c b/src/tests/voltest.c
index d2c0ff69..5b26c0f1 100644
--- a/src/tests/voltest.c
+++ b/src/tests/voltest.c
@@ -3,7 +3,7 @@
#include <pulse/volume.h>
#include <pulse/gccmacro.h>
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
+int main(int argc, char *argv[]) {
pa_volume_t v;
for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 256) {
diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index 24cddaa3..2c89c8d9 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -42,7 +42,7 @@
#include <pulsecore/log.h>
#include <pulsecore/pid.h>
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
+int main(int argc, char*argv[]) {
pid_t pid ;
int fd = -1;
int ret = 1, i;