summaryrefslogtreecommitdiffstats
path: root/src/pulse
diff options
context:
space:
mode:
authorColin Guthrie <pulse@colin.guthr.ie>2008-08-22 10:56:45 +0100
committerColin Guthrie <pulse@colin.guthr.ie>2008-08-22 10:56:45 +0100
commit4282b726ee57ebae846ce400fd1cae43c4dfb2ae (patch)
tree2cb32c3bc52a9b9eab50a6195f3ccb190332f7d8 /src/pulse
parentbf17dbb101d509e885bf689f4f13f75e4b3ab58d (diff)
parentdc9b8dce309728b47059b9b44fd3bbd3798667ae (diff)
Merge branch 'master' of git://git.0pointer.de/pulseaudio
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/channelmap.c135
-rw-r--r--src/pulse/client-conf-x11.c5
-rw-r--r--src/pulse/client-conf.c3
-rw-r--r--src/pulse/context.c200
-rw-r--r--src/pulse/error.c49
-rw-r--r--src/pulse/ext-stream-restore.c326
-rw-r--r--src/pulse/ext-stream-restore.h107
-rw-r--r--src/pulse/glib-mainloop.c14
-rw-r--r--src/pulse/i18n.c38
-rw-r--r--src/pulse/i18n.h62
-rw-r--r--src/pulse/internal.h18
-rw-r--r--src/pulse/introspect.c22
-rw-r--r--src/pulse/introspect.h9
-rw-r--r--src/pulse/lock-autospawn.c330
-rw-r--r--src/pulse/lock-autospawn.h32
-rw-r--r--src/pulse/mainloop-api.c5
-rw-r--r--src/pulse/mainloop-signal.c5
-rw-r--r--src/pulse/mainloop.c96
-rw-r--r--src/pulse/proplist.c5
-rw-r--r--src/pulse/sample.c8
-rw-r--r--src/pulse/scache.c3
-rw-r--r--src/pulse/simple.c1
-rw-r--r--src/pulse/stream.c86
-rw-r--r--src/pulse/subscribe.c3
-rw-r--r--src/pulse/thread-mainloop.c3
-rw-r--r--src/pulse/timeval.c18
-rw-r--r--src/pulse/utf8.c12
-rw-r--r--src/pulse/util.c23
-rw-r--r--src/pulse/volume.c101
-rw-r--r--src/pulse/volume.h7
-rw-r--r--src/pulse/xmalloc.c2
31 files changed, 1455 insertions, 273 deletions
diff --git a/src/pulse/channelmap.c b/src/pulse/channelmap.c
index 7348b32e..1766e729 100644
--- a/src/pulse/channelmap.c
+++ b/src/pulse/channelmap.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
@@ -98,66 +99,66 @@ const char *const table[PA_CHANNEL_POSITION_MAX] = {
};
const char *const pretty_table[PA_CHANNEL_POSITION_MAX] = {
- [PA_CHANNEL_POSITION_MONO] = "Mono",
-
- [PA_CHANNEL_POSITION_FRONT_CENTER] = "Front Center",
- [PA_CHANNEL_POSITION_FRONT_LEFT] = "Front Left",
- [PA_CHANNEL_POSITION_FRONT_RIGHT] = "Front Right",
-
- [PA_CHANNEL_POSITION_REAR_CENTER] = "Rear Center",
- [PA_CHANNEL_POSITION_REAR_LEFT] = "Rear Left",
- [PA_CHANNEL_POSITION_REAR_RIGHT] = "Rear Right",
-
- [PA_CHANNEL_POSITION_LFE] = "Low Frequency Emmiter",
-
- [PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = "Front Left-of-center",
- [PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = "Front Right-of-center",
-
- [PA_CHANNEL_POSITION_SIDE_LEFT] = "Side Left",
- [PA_CHANNEL_POSITION_SIDE_RIGHT] = "Side Right",
-
- [PA_CHANNEL_POSITION_AUX0] = "Auxiliary 0",
- [PA_CHANNEL_POSITION_AUX1] = "Auxiliary 1",
- [PA_CHANNEL_POSITION_AUX2] = "Auxiliary 2",
- [PA_CHANNEL_POSITION_AUX3] = "Auxiliary 3",
- [PA_CHANNEL_POSITION_AUX4] = "Auxiliary 4",
- [PA_CHANNEL_POSITION_AUX5] = "Auxiliary 5",
- [PA_CHANNEL_POSITION_AUX6] = "Auxiliary 6",
- [PA_CHANNEL_POSITION_AUX7] = "Auxiliary 7",
- [PA_CHANNEL_POSITION_AUX8] = "Auxiliary 8",
- [PA_CHANNEL_POSITION_AUX9] = "Auxiliary 9",
- [PA_CHANNEL_POSITION_AUX10] = "Auxiliary 10",
- [PA_CHANNEL_POSITION_AUX11] = "Auxiliary 11",
- [PA_CHANNEL_POSITION_AUX12] = "Auxiliary 12",
- [PA_CHANNEL_POSITION_AUX13] = "Auxiliary 13",
- [PA_CHANNEL_POSITION_AUX14] = "Auxiliary 14",
- [PA_CHANNEL_POSITION_AUX15] = "Auxiliary 15",
- [PA_CHANNEL_POSITION_AUX16] = "Auxiliary 16",
- [PA_CHANNEL_POSITION_AUX17] = "Auxiliary 17",
- [PA_CHANNEL_POSITION_AUX18] = "Auxiliary 18",
- [PA_CHANNEL_POSITION_AUX19] = "Auxiliary 19",
- [PA_CHANNEL_POSITION_AUX20] = "Auxiliary 20",
- [PA_CHANNEL_POSITION_AUX21] = "Auxiliary 21",
- [PA_CHANNEL_POSITION_AUX22] = "Auxiliary 22",
- [PA_CHANNEL_POSITION_AUX23] = "Auxiliary 23",
- [PA_CHANNEL_POSITION_AUX24] = "Auxiliary 24",
- [PA_CHANNEL_POSITION_AUX25] = "Auxiliary 25",
- [PA_CHANNEL_POSITION_AUX26] = "Auxiliary 26",
- [PA_CHANNEL_POSITION_AUX27] = "Auxiliary 27",
- [PA_CHANNEL_POSITION_AUX28] = "Auxiliary 28",
- [PA_CHANNEL_POSITION_AUX29] = "Auxiliary 29",
- [PA_CHANNEL_POSITION_AUX30] = "Auxiliary 30",
- [PA_CHANNEL_POSITION_AUX31] = "Auxiliary 31",
-
- [PA_CHANNEL_POSITION_TOP_CENTER] = "Top Center",
-
- [PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = "Top Front Center",
- [PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = "Top Front Left",
- [PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = "Top Front Right",
-
- [PA_CHANNEL_POSITION_TOP_REAR_CENTER] = "Top Rear Center",
- [PA_CHANNEL_POSITION_TOP_REAR_LEFT] = "Top Rear left",
- [PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = "Top Rear Right"
+ [PA_CHANNEL_POSITION_MONO] = N_("Mono"),
+
+ [PA_CHANNEL_POSITION_FRONT_CENTER] = N_("Front Center"),
+ [PA_CHANNEL_POSITION_FRONT_LEFT] = N_("Front Left"),
+ [PA_CHANNEL_POSITION_FRONT_RIGHT] = N_("Front Right"),
+
+ [PA_CHANNEL_POSITION_REAR_CENTER] = N_("Rear Center"),
+ [PA_CHANNEL_POSITION_REAR_LEFT] = N_("Rear Left"),
+ [PA_CHANNEL_POSITION_REAR_RIGHT] = N_("Rear Right"),
+
+ [PA_CHANNEL_POSITION_LFE] = N_("Low Frequency Emmiter"),
+
+ [PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = N_("Front Left-of-center"),
+ [PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = N_("Front Right-of-center"),
+
+ [PA_CHANNEL_POSITION_SIDE_LEFT] = N_("Side Left"),
+ [PA_CHANNEL_POSITION_SIDE_RIGHT] = N_("Side Right"),
+
+ [PA_CHANNEL_POSITION_AUX0] = N_("Auxiliary 0"),
+ [PA_CHANNEL_POSITION_AUX1] = N_("Auxiliary 1"),
+ [PA_CHANNEL_POSITION_AUX2] = N_("Auxiliary 2"),
+ [PA_CHANNEL_POSITION_AUX3] = N_("Auxiliary 3"),
+ [PA_CHANNEL_POSITION_AUX4] = N_("Auxiliary 4"),
+ [PA_CHANNEL_POSITION_AUX5] = N_("Auxiliary 5"),
+ [PA_CHANNEL_POSITION_AUX6] = N_("Auxiliary 6"),
+ [PA_CHANNEL_POSITION_AUX7] = N_("Auxiliary 7"),
+ [PA_CHANNEL_POSITION_AUX8] = N_("Auxiliary 8"),
+ [PA_CHANNEL_POSITION_AUX9] = N_("Auxiliary 9"),
+ [PA_CHANNEL_POSITION_AUX10] = N_("Auxiliary 10"),
+ [PA_CHANNEL_POSITION_AUX11] = N_("Auxiliary 11"),
+ [PA_CHANNEL_POSITION_AUX12] = N_("Auxiliary 12"),
+ [PA_CHANNEL_POSITION_AUX13] = N_("Auxiliary 13"),
+ [PA_CHANNEL_POSITION_AUX14] = N_("Auxiliary 14"),
+ [PA_CHANNEL_POSITION_AUX15] = N_("Auxiliary 15"),
+ [PA_CHANNEL_POSITION_AUX16] = N_("Auxiliary 16"),
+ [PA_CHANNEL_POSITION_AUX17] = N_("Auxiliary 17"),
+ [PA_CHANNEL_POSITION_AUX18] = N_("Auxiliary 18"),
+ [PA_CHANNEL_POSITION_AUX19] = N_("Auxiliary 19"),
+ [PA_CHANNEL_POSITION_AUX20] = N_("Auxiliary 20"),
+ [PA_CHANNEL_POSITION_AUX21] = N_("Auxiliary 21"),
+ [PA_CHANNEL_POSITION_AUX22] = N_("Auxiliary 22"),
+ [PA_CHANNEL_POSITION_AUX23] = N_("Auxiliary 23"),
+ [PA_CHANNEL_POSITION_AUX24] = N_("Auxiliary 24"),
+ [PA_CHANNEL_POSITION_AUX25] = N_("Auxiliary 25"),
+ [PA_CHANNEL_POSITION_AUX26] = N_("Auxiliary 26"),
+ [PA_CHANNEL_POSITION_AUX27] = N_("Auxiliary 27"),
+ [PA_CHANNEL_POSITION_AUX28] = N_("Auxiliary 28"),
+ [PA_CHANNEL_POSITION_AUX29] = N_("Auxiliary 29"),
+ [PA_CHANNEL_POSITION_AUX30] = N_("Auxiliary 30"),
+ [PA_CHANNEL_POSITION_AUX31] = N_("Auxiliary 31"),
+
+ [PA_CHANNEL_POSITION_TOP_CENTER] = N_("Top Center"),
+
+ [PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = N_("Top Front Center"),
+ [PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = N_("Top Front Left"),
+ [PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = N_("Top Front Right"),
+
+ [PA_CHANNEL_POSITION_TOP_REAR_CENTER] = N_("Top Rear Center"),
+ [PA_CHANNEL_POSITION_TOP_REAR_LEFT] = N_("Top Rear Left"),
+ [PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = N_("Top Rear Right")
};
pa_channel_map* pa_channel_map_init(pa_channel_map *m) {
@@ -200,7 +201,7 @@ pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, p
pa_channel_map_init(m);
- m->channels = channels;
+ m->channels = (uint8_t) channels;
switch (def) {
case PA_CHANNEL_MAP_AIFF:
@@ -414,7 +415,7 @@ pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels,
i++;
}
- m->channels = channels;
+ m->channels = (uint8_t) channels;
return m;
}
@@ -432,10 +433,13 @@ const char* pa_channel_position_to_string(pa_channel_position_t pos) {
}
const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos) {
+
+ pa_init_i18n();
+
if (pos < 0 || pos >= PA_CHANNEL_POSITION_MAX)
return NULL;
- return pretty_table[pos];
+ return _(pretty_table[pos]);
}
int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) {
@@ -456,7 +460,7 @@ int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) {
char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map) {
unsigned channel;
- int first = 1;
+ pa_bool_t first = TRUE;
char *e;
pa_assert(s);
@@ -471,7 +475,7 @@ char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map) {
pa_channel_position_to_string(map->map[channel]));
e = strchr(e, 0);
- first = 0;
+ first = FALSE;
}
return s;
@@ -552,7 +556,6 @@ int pa_channel_map_valid(const pa_channel_map *map) {
if (map->map[c] < 0 ||map->map[c] >= PA_CHANNEL_POSITION_MAX)
return 0;
-
}
return 1;
diff --git a/src/pulse/client-conf-x11.c b/src/pulse/client-conf-x11.c
index 393a7cd3..a8a90fb8 100644
--- a/src/pulse/client-conf-x11.c
+++ b/src/pulse/client-conf-x11.c
@@ -29,6 +29,7 @@
#include <X11/Xatom.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/x11prop.h>
#include <pulsecore/log.h>
@@ -51,7 +52,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
goto finish;
if (!(d = XOpenDisplay(dname))) {
- pa_log("XOpenDisplay() failed");
+ pa_log(_("XOpenDisplay() failed"));
goto finish;
}
@@ -74,7 +75,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
- pa_log("failed to parse cookie data");
+ pa_log(_("Failed to parse cookie data"));
goto finish;
}
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index 915d0ccb..739ef161 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-error.h>
@@ -113,7 +114,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
if (filename) {
if (!(f = fopen(filename, "r"))) {
- pa_log("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
+ pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
goto finish;
}
diff --git a/src/pulse/context.c b/src/pulse/context.c
index f56cb241..99a47a18 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -53,6 +53,8 @@
#include <pulse/xmalloc.h>
#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>
@@ -80,7 +82,7 @@
#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] = {
[PA_COMMAND_REQUEST] = pa_command_request,
@@ -93,23 +95,27 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_PLAYBACK_STREAM_SUSPENDED] = pa_command_stream_suspended,
[PA_COMMAND_RECORD_STREAM_SUSPENDED] = pa_command_stream_suspended,
[PA_COMMAND_STARTED] = pa_command_stream_started,
- [PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event
+ [PA_COMMAND_SUBSCRIBE_EVENT] = pa_command_subscribe_event,
+ [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);
@@ -126,6 +132,9 @@ static void reset_callbacks(pa_context *c) {
c->subscribe_callback = NULL;
c->subscribe_userdata = NULL;
+
+ c->ext_stream_restore.callback = NULL;
+ c->ext_stream_restore.userdata = NULL;
}
pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
@@ -133,6 +142,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
pa_assert(mainloop);
+ pa_init_i18n();
+
if (!name && !pa_proplist_contains(p, PA_PROP_APPLICATION_NAME))
return NULL;
@@ -165,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);
@@ -237,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);
@@ -398,11 +413,11 @@ int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa
err = PA_ERR_UNKNOWN;
if (fail) {
- pa_context_fail(c, err);
+ pa_context_fail(c, (int) err);
return -1;
}
- pa_context_set_error(c, err);
+ pa_context_set_error(c, (int) err);
return 0;
}
@@ -424,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)) {
@@ -524,7 +539,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX);
if (!c->conf->cookie_valid)
- pa_log_info("No cookie loaded. Attempting to connect without.");
+ pa_log_info(_("No cookie loaded. Attempting to connect without."));
t = pa_tagstruct_command(c, PA_COMMAND_AUTH, &tag);
@@ -578,7 +593,7 @@ static int context_connect_spawn(pa_context *c) {
pa_context_ref(c);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
- pa_log_error("socketpair(): %s", pa_cstrerror(errno));
+ pa_log_error(_("socketpair(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
goto fail;
}
@@ -592,7 +607,7 @@ static int context_connect_spawn(pa_context *c) {
c->spawn_api.prefork();
if ((pid = fork()) < 0) {
- pa_log_error("fork(): %s", pa_cstrerror(errno));
+ pa_log_error(_("fork(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
if (c->spawn_api.postfork)
@@ -655,7 +670,7 @@ static int context_connect_spawn(pa_context *c) {
c->spawn_api.postfork();
if (r < 0) {
- pa_log("waitpid(): %s", pa_cstrerror(errno));
+ pa_log(_("waitpid(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
goto fail;
} else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@@ -665,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);
@@ -677,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);
@@ -759,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;
+ }
-static char *get_legacy_runtime_dir(void) {
+finish:
+
+ pa_context_unref(c);
+}
+
+static char *get_old_legacy_runtime_dir(void) {
char *p, u[128];
struct stat st;
@@ -789,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,
@@ -816,6 +886,7 @@ int pa_context_connect(
pa_context_fail(c, PA_ERR_INVALIDSERVER);
goto finish;
}
+
} else {
char *d, *ufn;
static char *legacy_dir;
@@ -840,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);
@@ -856,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;
+
+ pa_assert(c->autospawn_fd < 0);
+ pa_assert(!c->autospawn_locked);
- if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
+ /* 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;
+ }
+
}
}
@@ -929,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);
}
@@ -985,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;
@@ -1137,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;
}
@@ -1230,3 +1328,31 @@ pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[]
return o;
}
+
+void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_context *c = userdata;
+ uint32_t idx;
+ const char *name;
+
+ pa_assert(pd);
+ pa_assert(command == PA_COMMAND_EXTENSION);
+ pa_assert(t);
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ pa_context_ref(c);
+
+ if (pa_tagstruct_getu32(t, &idx) < 0 ||
+ pa_tagstruct_gets(t, &name) < 0) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!strcmp(name, "module-stream-restore"))
+ pa_ext_stream_restore_command(c, tag, t);
+ else
+ pa_log(_("Received message for unknown extension '%s'"), name);
+
+finish:
+ pa_context_unref(c);
+}
diff --git a/src/pulse/error.c b/src/pulse/error.c
index 50bbf703..d9d0a8c6 100644
--- a/src/pulse/error.c
+++ b/src/pulse/error.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/native-common.h>
@@ -39,32 +40,34 @@
const char*pa_strerror(int error) {
static const char* const errortab[PA_ERR_MAX] = {
- [PA_OK] = "OK",
- [PA_ERR_ACCESS] = "Access denied",
- [PA_ERR_COMMAND] = "Unknown command",
- [PA_ERR_INVALID] = "Invalid argument",
- [PA_ERR_EXIST] = "Entity exists",
- [PA_ERR_NOENTITY] = "No such entity",
- [PA_ERR_CONNECTIONREFUSED] = "Connection refused",
- [PA_ERR_PROTOCOL] = "Protocol error",
- [PA_ERR_TIMEOUT] = "Timeout",
- [PA_ERR_AUTHKEY] = "No authorization key",
- [PA_ERR_INTERNAL] = "Internal error",
- [PA_ERR_CONNECTIONTERMINATED] = "Connection terminated",
- [PA_ERR_KILLED] = "Entity killed",
- [PA_ERR_INVALIDSERVER] = "Invalid server",
- [PA_ERR_MODINITFAILED] = "Module initalization failed",
- [PA_ERR_BADSTATE] = "Bad state",
- [PA_ERR_NODATA] = "No data",
- [PA_ERR_VERSION] = "Incompatible protocol version",
- [PA_ERR_TOOLARGE] = "Too large",
- [PA_ERR_NOTSUPPORTED] = "Not supported",
- [PA_ERR_UNKNOWN] = "Unknown error code",
- [PA_ERR_NOEXTENSION] = "No such extension"
+ [PA_OK] = N_("OK"),
+ [PA_ERR_ACCESS] = N_("Access denied"),
+ [PA_ERR_COMMAND] = N_("Unknown command"),
+ [PA_ERR_INVALID] = N_("Invalid argument"),
+ [PA_ERR_EXIST] = N_("Entity exists"),
+ [PA_ERR_NOENTITY] = N_("No such entity"),
+ [PA_ERR_CONNECTIONREFUSED] = N_("Connection refused"),
+ [PA_ERR_PROTOCOL] = N_("Protocol error"),
+ [PA_ERR_TIMEOUT] = N_("Timeout"),
+ [PA_ERR_AUTHKEY] = N_("No authorization key"),
+ [PA_ERR_INTERNAL] = N_("Internal error"),
+ [PA_ERR_CONNECTIONTERMINATED] = N_("Connection terminated"),
+ [PA_ERR_KILLED] = N_("Entity killed"),
+ [PA_ERR_INVALIDSERVER] = N_("Invalid server"),
+ [PA_ERR_MODINITFAILED] = N_("Module initalization failed"),
+ [PA_ERR_BADSTATE] = N_("Bad state"),
+ [PA_ERR_NODATA] = N_("No data"),
+ [PA_ERR_VERSION] = N_("Incompatible protocol version"),
+ [PA_ERR_TOOLARGE] = N_("Too large"),
+ [PA_ERR_NOTSUPPORTED] = N_("Not supported"),
+ [PA_ERR_UNKNOWN] = N_("Unknown error code"),
+ [PA_ERR_NOEXTENSION] = N_("No such extension")
};
+ pa_init_i18n();
+
if (error < 0 || error >= PA_ERR_MAX)
return NULL;
- return errortab[error];
+ return _(errortab[error]);
}
diff --git a/src/pulse/ext-stream-restore.c b/src/pulse/ext-stream-restore.c
new file mode 100644
index 00000000..703179c5
--- /dev/null
+++ b/src/pulse/ext-stream-restore.c
@@ -0,0 +1,326 @@
+/***
+ 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 <pulse/context.h>
+#include <pulse/gccmacro.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/pstream-util.h>
+
+#include "internal.h"
+
+#include "ext-stream-restore.h"
+
+enum {
+ SUBCOMMAND_TEST,
+ SUBCOMMAND_READ,
+ SUBCOMMAND_WRITE,
+ SUBCOMMAND_DELETE,
+ SUBCOMMAND_SUBSCRIBE,
+ SUBCOMMAND_EVENT
+};
+
+static void ext_stream_restore_test_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_operation *o = userdata;
+ uint32_t version = PA_INVALID_INDEX;
+
+ pa_assert(pd);
+ pa_assert(o);
+ pa_assert(PA_REFCNT_VALUE(o) >= 1);
+
+ if (!o->context)
+ goto finish;
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
+ goto finish;
+
+ } else if (pa_tagstruct_getu32(t, &version) < 0 ||
+ !pa_tagstruct_eof(t)) {
+
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (o->callback) {
+ pa_ext_stream_restore_test_cb_t cb = (pa_ext_stream_restore_test_cb_t) o->callback;
+ cb(o->context, version, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+pa_operation *pa_ext_stream_restore_test(
+ pa_context *c,
+ pa_ext_stream_restore_test_cb_t cb,
+ void *userdata) {
+
+ uint32_t tag;
+ pa_operation *o;
+ pa_tagstruct *t;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, "module-stream-restore");
+ pa_tagstruct_putu32(t, SUBCOMMAND_TEST);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, ext_stream_restore_test_cb, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+static void ext_stream_restore_read_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_operation *o = userdata;
+ int eol = 1;
+
+ pa_assert(pd);
+ pa_assert(o);
+ pa_assert(PA_REFCNT_VALUE(o) >= 1);
+
+ if (!o->context)
+ goto finish;
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
+ goto finish;
+
+ eol = -1;
+ } else {
+
+ while (!pa_tagstruct_eof(t)) {
+ pa_ext_stream_restore_info i;
+ pa_bool_t mute = FALSE;
+
+ memset(&i, 0, sizeof(i));
+
+ if (pa_tagstruct_gets(t, &i.name) < 0 ||
+ pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
+ pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
+ pa_tagstruct_gets(t, &i.device) < 0 ||
+ pa_tagstruct_get_boolean(t, &mute) < 0) {
+
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ i.mute = (int) mute;
+
+ if (o->callback) {
+ pa_ext_stream_restore_read_cb_t cb = (pa_ext_stream_restore_read_cb_t) o->callback;
+ cb(o->context, &i, 0, o->userdata);
+ }
+ }
+ }
+
+ if (o->callback) {
+ pa_ext_stream_restore_read_cb_t cb = (pa_ext_stream_restore_read_cb_t) o->callback;
+ cb(o->context, NULL, eol, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+pa_operation *pa_ext_stream_restore_read(
+ pa_context *c,
+ pa_ext_stream_restore_read_cb_t cb,
+ void *userdata) {
+
+ uint32_t tag;
+ pa_operation *o;
+ pa_tagstruct *t;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, "module-stream-restore");
+ pa_tagstruct_putu32(t, SUBCOMMAND_READ);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, ext_stream_restore_read_cb, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+pa_operation *pa_ext_stream_restore_write(
+ pa_context *c,
+ pa_update_mode_t mode,
+ const pa_ext_stream_restore_info data[],
+ unsigned n,
+ int apply_immediately,
+ pa_context_success_cb_t cb,
+ void *userdata) {
+
+ uint32_t tag;
+ pa_operation *o;
+ pa_tagstruct *t;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ pa_assert(mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE || mode == PA_UPDATE_SET);
+ pa_assert(data);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, "module-stream-restore");
+ pa_tagstruct_putu32(t, SUBCOMMAND_WRITE);
+
+ pa_tagstruct_putu32(t, mode);
+ pa_tagstruct_put_boolean(t, apply_immediately);
+
+ for (; n > 0; n--, data++) {
+ pa_tagstruct_puts(t, data->name);
+ pa_tagstruct_put_channel_map(t, &data->channel_map);
+ pa_tagstruct_put_cvolume(t, &data->volume);
+ pa_tagstruct_puts(t, data->device);
+ pa_tagstruct_put_boolean(t, data->mute);
+ }
+
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+pa_operation *pa_ext_stream_restore_delete(
+ pa_context *c,
+ const char *const s[],
+ pa_context_success_cb_t cb,
+ void *userdata) {
+
+ uint32_t tag;
+ pa_operation *o;
+ pa_tagstruct *t;
+ const char *const *k;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ pa_assert(s);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, "module-stream-restore");
+ pa_tagstruct_putu32(t, SUBCOMMAND_DELETE);
+
+ for (k = s; *k; k++)
+ pa_tagstruct_puts(t, *k);
+
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+pa_operation *pa_ext_stream_restore_subscribe(
+ pa_context *c,
+ int enable,
+ pa_context_success_cb_t cb,
+ void *userdata) {
+
+ uint32_t tag;
+ pa_operation *o;
+ pa_tagstruct *t;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, "module-stream-restore");
+ pa_tagstruct_putu32(t, SUBCOMMAND_SUBSCRIBE);
+ pa_tagstruct_put_boolean(t, enable);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+void pa_ext_stream_restore_set_subscribe_cb(
+ pa_context *c,
+ pa_ext_stream_restore_subscribe_cb_t cb,
+ void *userdata) {
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ c->ext_stream_restore.callback = cb;
+ c->ext_stream_restore.userdata = userdata;
+}
+
+void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t) {
+ uint32_t subcommand;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ pa_assert(t);
+
+ if (pa_tagstruct_getu32(t, &subcommand) < 0 ||
+ !pa_tagstruct_eof(t)) {
+
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ return;
+ }
+
+ if (subcommand != SUBCOMMAND_EVENT) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ return;
+ }
+
+ if (c->ext_stream_restore.callback)
+ c->ext_stream_restore.callback(c, c->ext_stream_restore.userdata);
+
+}
diff --git a/src/pulse/ext-stream-restore.h b/src/pulse/ext-stream-restore.h
new file mode 100644
index 00000000..2038eb4a
--- /dev/null
+++ b/src/pulse/ext-stream-restore.h
@@ -0,0 +1,107 @@
+#ifndef foopulseextstreamrestorehfoo
+#define foopulseextstreamrestorehfoo
+
+/***
+ 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.
+***/
+
+#include <pulse/context.h>
+
+/** \file
+ *
+ * Routines for controlling module-stream-restore
+ */
+
+PA_C_DECL_BEGIN
+
+/** Stores information about one entry in the stream database that is
+ * maintained by module-stream-restore. \since 0.9.12 */
+typedef struct pa_ext_stream_restore_info {
+ const char *name; /**< Identifier string of the stream. A string like "sink-input-by-role:" or similar followed by some arbitrary property value. */
+ pa_channel_map channel_map; /**< The channel map for the volume field */
+ pa_cvolume volume; /**< The volume of the stream when it was seen last, if applicable */
+ const char *device; /**< The sink/source of the stream when it was last seen */
+ int mute; /**< The boolean mute state of the stream when it was last seen, if applicable */
+} pa_ext_stream_restore_info;
+
+/** Callback prototype for pa_ext_stream_restore_test(). \since 0.9.12 */
+typedef void (*pa_ext_stream_restore_test_cb_t)(
+ pa_context *c,
+ uint32_t version,
+ void *userdata);
+
+/** Test if this extension module is available in the server. \since 0.9.12 */
+pa_operation *pa_ext_stream_restore_test(
+ pa_context *c,
+ pa_ext_stream_restore_test_cb_t cb,
+ void *userdata);
+
+/** Callback prototype for pa_ext_stream_restore_read(). \since 0.9.12 */
+typedef void (*pa_ext_stream_restore_read_cb_t)(
+ pa_context *c,
+ const pa_ext_stream_restore_info *info,
+ int eol,
+ void *userdata);
+
+/** Read all entries from the stream database. \since 0.9.12 */
+pa_operation *pa_ext_stream_restore_read(
+ pa_context *c,
+ pa_ext_stream_restore_read_cb_t cb,
+ void *userdata);
+
+/** Store entries in the stream database. \since 0.9.12 */
+pa_operation *pa_ext_stream_restore_write(
+ pa_context *c,
+ pa_update_mode_t mode,
+ const pa_ext_stream_restore_info data[],
+ unsigned n,
+ int apply_immediately,
+ pa_context_success_cb_t cb,
+ void *userdata);
+
+/** Delete entries from the stream database. \since 0.9.12 */
+pa_operation *pa_ext_stream_restore_delete(
+ pa_context *c,
+ const char *const s[],
+ pa_context_success_cb_t cb,
+ void *userdata);
+
+/** Subscribe to changes in the stream database. \since 0.9.12 */
+pa_operation *pa_ext_stream_restore_subscribe(
+ pa_context *c,
+ int enable,
+ pa_context_success_cb_t cb,
+ void *userdata);
+
+/** Callback prototype for pa_ext_stream_restore_set_subscribe_cb(). \since 0.9.12 */
+typedef void (*pa_ext_stream_restore_subscribe_cb_t)(
+ pa_context *c,
+ void *userdata);
+
+/** Set the subscription callback that is called when
+ * pa_ext_stream_restore_subscribe() was called. \since 0.9.12 */
+void pa_ext_stream_restore_set_subscribe_cb(
+ pa_context *c,
+ pa_ext_stream_restore_subscribe_cb_t cb,
+ void *userdata);
+
+PA_C_DECL_END
+
+#endif
diff --git a/src/pulse/glib-mainloop.c b/src/pulse/glib-mainloop.c
index 6ddb0faa..5f5dc494 100644
--- a/src/pulse/glib-mainloop.c
+++ b/src/pulse/glib-mainloop.c
@@ -195,11 +195,11 @@ static void cleanup_defer_events(pa_glib_mainloop *g, int force) {
}
static gushort map_flags_to_glib(pa_io_event_flags_t flags) {
- return
- (flags & PA_IO_EVENT_INPUT ? G_IO_IN : 0) |
- (flags & PA_IO_EVENT_OUTPUT ? G_IO_OUT : 0) |
- (flags & PA_IO_EVENT_ERROR ? G_IO_ERR : 0) |
- (flags & PA_IO_EVENT_HANGUP ? G_IO_HUP : 0);
+ return (gushort)
+ ((flags & PA_IO_EVENT_INPUT ? G_IO_IN : 0) |
+ (flags & PA_IO_EVENT_OUTPUT ? G_IO_OUT : 0) |
+ (flags & PA_IO_EVENT_ERROR ? G_IO_ERR : 0) |
+ (flags & PA_IO_EVENT_HANGUP ? G_IO_HUP : 0));
}
static pa_io_event_flags_t map_flags_from_glib(gushort flags) {
@@ -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/i18n.c b/src/pulse/i18n.c
new file mode 100644
index 00000000..7f25b20d
--- /dev/null
+++ b/src/pulse/i18n.c
@@ -0,0 +1,38 @@
+/***
+ 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.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulsecore/once.h>
+
+#include "i18n.h"
+
+void pa_init_i18n(void) {
+
+ PA_ONCE_BEGIN {
+
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+ bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+
+ } PA_ONCE_END;
+}
diff --git a/src/pulse/i18n.h b/src/pulse/i18n.h
new file mode 100644
index 00000000..4c0ef9d3
--- /dev/null
+++ b/src/pulse/i18n.h
@@ -0,0 +1,62 @@
+#ifndef foopulsei18nhfoo
+#define foopulsei18nhfoo
+
+/***
+ 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 <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
+
+PA_C_DECL_BEGIN
+
+#if !defined(GETTEXT_PACKAGE)
+#error "Something is very wrong here, config.h needs to be included first"
+#endif
+
+#ifdef ENABLE_NLS
+
+#include <libintl.h>
+
+#define _(String) dgettext(GETTEXT_PACKAGE, String)
+#ifdef gettext_noop
+#define N_(String) gettext_noop(String)
+#else
+#define N_(String) (String)
+#endif
+
+#else /* NLS is disabled */
+
+#define _(String) (String)
+#define N_(String) (String)
+#define textdomain(String) (String)
+#define gettext(String) (String)
+#define dgettext(Domain,String) (String)
+#define dcgettext(Domain,String,Type) (String)
+#define bindtextdomain(Domain,Directory) (Domain)
+#define bind_textdomain_codeset(Domain,Codeset) (Codeset)
+
+#endif /* ENABLE_NLS */
+
+void pa_init_i18n(void);
+
+PA_C_DECL_END
+
+#endif
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index 9ed541d1..9167bf1b 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -28,6 +28,7 @@
#include <pulse/stream.h>
#include <pulse/operation.h>
#include <pulse/subscribe.h>
+#include <pulse/ext-stream-restore.h>
#include <pulsecore/socket-client.h>
#include <pulsecore/pstream.h>
@@ -63,7 +64,7 @@ struct pa_context {
uint32_t version;
uint32_t ctag;
uint32_t csyncid;
- uint32_t error;
+ int error;
pa_context_state_t state;
pa_context_notify_cb_t state_callback;
@@ -74,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;
@@ -86,6 +90,12 @@ struct pa_context {
pa_client_conf *conf;
uint32_t client_index;
+
+ /* Extension specific data */
+ struct {
+ pa_ext_stream_restore_subscribe_cb_t callback;
+ void *userdata;
+ } ext_stream_restore;
};
#define PA_MAX_WRITE_INDEX_CORRECTIONS 32
@@ -233,4 +243,6 @@ pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *ta
#define PA_CHECK_VALIDITY_RETURN_NULL(context, expression, error) PA_CHECK_VALIDITY_RETURN_ANY(context, expression, error, NULL)
+void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
+
#endif
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/introspect.h b/src/pulse/introspect.h
index 6a6755e7..ca79f5b7 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -52,14 +52,14 @@
* Some objects can have multiple entries at the server. When requesting all
* of these at once, the callback will be called multiple times, once for
* each object. When the list has been exhausted, the callback will be called
- * without an information structure and the eol parameter set to a non-zero
+ * without an information structure and the eol parameter set to a positive
* value.
*
* Note that even if a single object is requested, and not the entire list,
* the terminating call will still be made.
*
* If an error occurs, the callback will be called without and information
- * structure and eol set to zero.
+ * structure and eol set to a negative value..
*
* Data members in the information structures are only valid during the
* duration of the callback. If they are required after the callback is
@@ -210,11 +210,6 @@
PA_C_DECL_BEGIN
-#define PA_PORT_DIGITAL "spdif"
-#define PA_PORT_ANALOG_STEREO "analog-stereo"
-#define PA_PORT_ANALOG_5_1 "analog-5-1"
-#define PA_PORT_ANALOG_4_0 "analog-4-0"
-
/** @{ \name Sinks */
/** Stores information about sinks. Please note that this structure
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 90aff164..4b862f9a 100644
--- a/src/pulse/mainloop-api.c
+++ b/src/pulse/mainloop-api.c
@@ -27,6 +27,7 @@
#include <pulse/xmalloc.h>
#include <pulse/gccmacro.h>
+#include <pulse/i18n.h>
#include <pulsecore/macro.h>
@@ -50,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);
@@ -65,6 +66,8 @@ void pa_mainloop_api_once(pa_mainloop_api* m, void (*callback)(pa_mainloop_api *
pa_assert(m);
pa_assert(callback);
+ pa_init_i18n();
+
i = pa_xnew(struct once_info, 1);
i->callback = callback;
i->userdata = userdata;
diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
index 9161dec4..d09f4b0a 100644
--- a/src/pulse/mainloop-signal.c
+++ b/src/pulse/mainloop-signal.c
@@ -38,6 +38,7 @@
#include <pulse/xmalloc.h>
#include <pulse/gccmacro.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
@@ -89,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;
@@ -165,6 +166,8 @@ pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t _callback, void *userdata
pa_assert(sig > 0);
pa_assert(_callback);
+ pa_init_i18n();
+
for (e = signals; e; e = e->next)
if (e->sig == sig)
goto fail;
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index aaed3caf..60e5d1ff 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -44,6 +44,7 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/llist.h>
@@ -56,7 +57,7 @@
struct pa_io_event {
pa_mainloop *mainloop;
- int dead;
+ pa_bool_t dead:1;
int fd;
pa_io_event_flags_t events;
@@ -71,9 +72,9 @@ struct pa_io_event {
struct pa_time_event {
pa_mainloop *mainloop;
- int dead;
+ pa_bool_t dead:1;
- int enabled;
+ pa_bool_t enabled:1;
struct timeval timeval;
pa_time_event_cb_t callback;
@@ -85,9 +86,9 @@ struct pa_time_event {
struct pa_defer_event {
pa_mainloop *mainloop;
- int dead;
+ pa_bool_t dead:1;
- int enabled;
+ pa_bool_t enabled:1;
pa_defer_event_cb_t callback;
void *userdata;
@@ -101,22 +102,24 @@ struct pa_mainloop {
PA_LLIST_HEAD(pa_time_event, time_events);
PA_LLIST_HEAD(pa_defer_event, defer_events);
- int n_enabled_defer_events, n_enabled_time_events, n_io_events;
- int io_events_please_scan, time_events_please_scan, defer_events_please_scan;
+ unsigned n_enabled_defer_events, n_enabled_time_events, n_io_events;
+ unsigned io_events_please_scan, time_events_please_scan, defer_events_please_scan;
+ pa_bool_t rebuild_pollfds:1;
struct pollfd *pollfds;
unsigned max_pollfds, n_pollfds;
- int rebuild_pollfds;
int prepared_timeout;
pa_time_event *cached_next_time_event;
- int quit, retval;
pa_mainloop_api api;
+ int retval;
+ pa_bool_t quit:1;
+
+ pa_bool_t wakeup_requested:1;
int wakeup_pipe[2];
int wakeup_pipe_type;
- int wakeup_requested;
enum {
STATE_PASSIVE,
@@ -132,11 +135,11 @@ struct pa_mainloop {
};
static short map_flags_to_libc(pa_io_event_flags_t flags) {
- return
- (flags & PA_IO_EVENT_INPUT ? POLLIN : 0) |
- (flags & PA_IO_EVENT_OUTPUT ? POLLOUT : 0) |
- (flags & PA_IO_EVENT_ERROR ? POLLERR : 0) |
- (flags & PA_IO_EVENT_HANGUP ? POLLHUP : 0);
+ return (short)
+ ((flags & PA_IO_EVENT_INPUT ? POLLIN : 0) |
+ (flags & PA_IO_EVENT_OUTPUT ? POLLOUT : 0) |
+ (flags & PA_IO_EVENT_ERROR ? POLLERR : 0) |
+ (flags & PA_IO_EVENT_HANGUP ? POLLHUP : 0));
}
static pa_io_event_flags_t map_flags_from_libc(short flags) {
@@ -168,7 +171,7 @@ static pa_io_event* mainloop_io_new(
e = pa_xnew(pa_io_event, 1);
e->mainloop = m;
- e->dead = 0;
+ e->dead = FALSE;
e->fd = fd;
e->events = events;
@@ -193,13 +196,13 @@ static pa_io_event* mainloop_io_new(
SELECT_TYPE_ARG5 &tv) == -1) &&
(WSAGetLastError() == WSAENOTSOCK)) {
pa_log_warn("Cannot monitor non-socket file descriptors.");
- e->dead = 1;
+ e->dead = TRUE;
}
}
#endif
PA_LLIST_PREPEND(pa_io_event, m->io_events, e);
- m->rebuild_pollfds = 1;
+ m->rebuild_pollfds = TRUE;
m->n_io_events ++;
pa_mainloop_wakeup(m);
@@ -219,7 +222,7 @@ static void mainloop_io_enable(pa_io_event *e, pa_io_event_flags_t events) {
if (e->pollfd)
e->pollfd->events = map_flags_to_libc(events);
else
- e->mainloop->rebuild_pollfds = 1;
+ e->mainloop->rebuild_pollfds = TRUE;
pa_mainloop_wakeup(e->mainloop);
}
@@ -228,11 +231,11 @@ static void mainloop_io_free(pa_io_event *e) {
pa_assert(e);
pa_assert(!e->dead);
- e->dead = 1;
+ e->dead = TRUE;
e->mainloop->io_events_please_scan ++;
e->mainloop->n_io_events --;
- e->mainloop->rebuild_pollfds = 1;
+ e->mainloop->rebuild_pollfds = TRUE;
pa_mainloop_wakeup(e->mainloop);
}
@@ -261,9 +264,9 @@ static pa_defer_event* mainloop_defer_new(
e = pa_xnew(pa_defer_event, 1);
e->mainloop = m;
- e->dead = 0;
+ e->dead = FALSE;
- e->enabled = 1;
+ e->enabled = TRUE;
m->n_enabled_defer_events++;
e->callback = callback;
@@ -296,13 +299,13 @@ static void mainloop_defer_free(pa_defer_event *e) {
pa_assert(e);
pa_assert(!e->dead);
- e->dead = 1;
+ e->dead = TRUE;
e->mainloop->defer_events_please_scan ++;
if (e->enabled) {
pa_assert(e->mainloop->n_enabled_defer_events > 0);
e->mainloop->n_enabled_defer_events--;
- e->enabled = 0;
+ e->enabled = FALSE;
}
}
@@ -332,7 +335,7 @@ static pa_time_event* mainloop_time_new(
e = pa_xnew(pa_time_event, 1);
e->mainloop = m;
- e->dead = 0;
+ e->dead = FALSE;
if ((e->enabled = !!tv)) {
e->timeval = *tv;
@@ -387,13 +390,13 @@ static void mainloop_time_free(pa_time_event *e) {
pa_assert(e);
pa_assert(!e->dead);
- e->dead = 1;
+ e->dead = TRUE;
e->mainloop->time_events_please_scan ++;
if (e->enabled) {
pa_assert(e->mainloop->n_enabled_time_events > 0);
e->mainloop->n_enabled_time_events--;
- e->enabled = 0;
+ e->enabled = FALSE;
}
if (e->mainloop->cached_next_time_event == e)
@@ -446,6 +449,8 @@ static const pa_mainloop_api vtable = {
pa_mainloop *pa_mainloop_new(void) {
pa_mainloop *m;
+ pa_init_i18n();
+
m = pa_xnew(pa_mainloop, 1);
m->wakeup_pipe_type = 0;
@@ -459,7 +464,7 @@ pa_mainloop *pa_mainloop_new(void) {
pa_make_fd_nonblock(m->wakeup_pipe[1]);
pa_make_fd_cloexec(m->wakeup_pipe[0]);
pa_make_fd_cloexec(m->wakeup_pipe[1]);
- m->wakeup_requested = 0;
+ m->wakeup_requested = FALSE;
PA_LLIST_HEAD_INIT(pa_io_event, m->io_events);
PA_LLIST_HEAD_INIT(pa_time_event, m->time_events);
@@ -473,9 +478,10 @@ pa_mainloop *pa_mainloop_new(void) {
m->pollfds = NULL;
m->max_pollfds = m->n_pollfds = 0;
- m->rebuild_pollfds = 1;
+ m->rebuild_pollfds = TRUE;
- m->quit = m->retval = 0;
+ m->quit = FALSE;
+ m->retval = 0;
m->api = vtable;
m->api.userdata = m;
@@ -489,7 +495,7 @@ pa_mainloop *pa_mainloop_new(void) {
return m;
}
-static void cleanup_io_events(pa_mainloop *m, int force) {
+static void cleanup_io_events(pa_mainloop *m, pa_bool_t force) {
pa_io_event *e;
e = m->io_events;
@@ -512,7 +518,7 @@ static void cleanup_io_events(pa_mainloop *m, int force) {
pa_xfree(e);
- m->rebuild_pollfds = 1;
+ m->rebuild_pollfds = TRUE;
}
e = n;
@@ -521,7 +527,7 @@ static void cleanup_io_events(pa_mainloop *m, int force) {
pa_assert(m->io_events_please_scan == 0);
}
-static void cleanup_time_events(pa_mainloop *m, int force) {
+static void cleanup_time_events(pa_mainloop *m, pa_bool_t force) {
pa_time_event *e;
e = m->time_events;
@@ -542,7 +548,7 @@ static void cleanup_time_events(pa_mainloop *m, int force) {
if (!e->dead && e->enabled) {
pa_assert(m->n_enabled_time_events > 0);
m->n_enabled_time_events--;
- e->enabled = 0;
+ e->enabled = FALSE;
}
if (e->destroy_callback)
@@ -557,7 +563,7 @@ static void cleanup_time_events(pa_mainloop *m, int force) {
pa_assert(m->time_events_please_scan == 0);
}
-static void cleanup_defer_events(pa_mainloop *m, int force) {
+static void cleanup_defer_events(pa_mainloop *m, pa_bool_t force) {
pa_defer_event *e;
e = m->defer_events;
@@ -578,7 +584,7 @@ static void cleanup_defer_events(pa_mainloop *m, int force) {
if (!e->dead && e->enabled) {
pa_assert(m->n_enabled_defer_events > 0);
m->n_enabled_defer_events--;
- e->enabled = 0;
+ e->enabled = FALSE;
}
if (e->destroy_callback)
@@ -597,9 +603,9 @@ static void cleanup_defer_events(pa_mainloop *m, int force) {
void pa_mainloop_free(pa_mainloop* m) {
pa_assert(m);
- cleanup_io_events(m, 1);
- cleanup_defer_events(m, 1);
- cleanup_time_events(m, 1);
+ cleanup_io_events(m, TRUE);
+ cleanup_defer_events(m, TRUE);
+ cleanup_time_events(m, TRUE);
pa_xfree(m->pollfds);
@@ -612,13 +618,13 @@ static void scan_dead(pa_mainloop *m) {
pa_assert(m);
if (m->io_events_please_scan)
- cleanup_io_events(m, 0);
+ cleanup_io_events(m, FALSE);
if (m->time_events_please_scan)
- cleanup_time_events(m, 0);
+ cleanup_time_events(m, FALSE);
if (m->defer_events_please_scan)
- cleanup_defer_events(m, 0);
+ cleanup_defer_events(m, FALSE);
}
static void rebuild_pollfds(pa_mainloop *m) {
@@ -659,7 +665,7 @@ static void rebuild_pollfds(pa_mainloop *m) {
m->n_pollfds++;
}
- m->rebuild_pollfds = 0;
+ m->rebuild_pollfds = FALSE;
}
static int dispatch_pollfds(pa_mainloop *m) {
@@ -945,7 +951,7 @@ int pa_mainloop_run(pa_mainloop *m, int *retval) {
void pa_mainloop_quit(pa_mainloop *m, int retval) {
pa_assert(m);
- m->quit = 1;
+ m->quit = TRUE;
m->retval = retval;
pa_mainloop_wakeup(m);
}
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index 74aea20a..93bc0034 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -27,6 +27,7 @@
#include <pulse/xmalloc.h>
#include <pulse/utf8.h>
+#include <pulse/i18n.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/strbuf.h>
@@ -63,6 +64,8 @@ static void property_free(struct property *prop) {
}
pa_proplist* pa_proplist_new(void) {
+ pa_init_i18n();
+
return MAKE_PROPLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func));
}
@@ -277,7 +280,7 @@ char *pa_proplist_to_string(pa_proplist *p) {
char *c;
pa_assert_se(pa_proplist_get(p, key, &value, &nbytes) == 0);
- c = pa_xnew(char, nbytes*2+1);
+ c = pa_xmalloc(nbytes*2+1);
pa_hexstr((const uint8_t*) value, nbytes, c, nbytes*2+1);
pa_strbuf_printf(buf, "%s = hex:%s\n", key, c);
diff --git a/src/pulse/sample.c b/src/pulse/sample.c
index 4aef5bb0..93da2465 100644
--- a/src/pulse/sample.c
+++ b/src/pulse/sample.c
@@ -28,9 +28,11 @@
#include <math.h>
#include <string.h>
+#include <pulse/timeval.h>
+#include <pulse/i18n.h>
+
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
-#include <pulse/timeval.h>
#include "sample.h"
@@ -126,8 +128,10 @@ char *pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) {
pa_assert(l);
pa_assert(spec);
+ pa_init_i18n();
+
if (!pa_sample_spec_valid(spec))
- pa_snprintf(s, l, "Invalid");
+ pa_snprintf(s, l, _("Invalid"));
else
pa_snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels, spec->rate);
diff --git a/src/pulse/scache.c b/src/pulse/scache.c
index 5e31e7af..fd3b9876 100644
--- a/src/pulse/scache.c
+++ b/src/pulse/scache.c
@@ -47,6 +47,7 @@ int pa_stream_connect_upload(pa_stream *s, size_t length) {
PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_UNCONNECTED, PA_ERR_BADSTATE);
PA_CHECK_VALIDITY(s->context, length > 0, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY(s->context, length == (size_t) (uint32_t) length, PA_ERR_INVALID);
if (!(name = pa_proplist_gets(s->proplist, PA_PROP_EVENT_ID)))
name = pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME);
@@ -63,7 +64,7 @@ int pa_stream_connect_upload(pa_stream *s, size_t length) {
pa_tagstruct_puts(t, name);
pa_tagstruct_put_sample_spec(t, &s->sample_spec);
pa_tagstruct_put_channel_map(t, &s->channel_map);
- pa_tagstruct_putu32(t, length);
+ pa_tagstruct_putu32(t, (uint32_t) length);
if (s->context->version >= 13) {
pa_init_proplist(s->proplist);
diff --git a/src/pulse/simple.c b/src/pulse/simple.c
index 70396835..51160ad7 100644
--- a/src/pulse/simple.c
+++ b/src/pulse/simple.c
@@ -453,4 +453,3 @@ unlock_and_fail:
pa_threaded_mainloop_unlock(p->mainloop);
return (pa_usec_t) -1;
}
-
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 585518f0..536a82ce 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -124,7 +124,7 @@ pa_stream *pa_stream_new_with_proplist(
* what older PA versions provided. */
s->buffer_attr.maxlength = (uint32_t) -1;
- s->buffer_attr.tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
+ s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
s->buffer_attr.minreq = (uint32_t) -1;
s->buffer_attr.prebuf = (uint32_t) -1;
s->buffer_attr.fragsize = (uint32_t) -1;
@@ -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);
@@ -694,7 +694,7 @@ static void create_stream_complete(pa_stream *s) {
if (s->flags & PA_STREAM_AUTO_TIMING_UPDATE) {
struct timeval tv;
pa_gettimeofday(&tv);
- tv.tv_usec += LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */
+ tv.tv_usec += (suseconds_t) LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */
pa_assert(!s->auto_timing_update_event);
s->auto_timing_update_event = s->mainloop->time_new(s->mainloop, &tv, &auto_timing_update_callback, s);
@@ -722,7 +722,7 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s
attr->maxlength = 4*1024*1024; /* 4MB is the maximum queue length PulseAudio <= 0.9.9 supported. */
if (attr->tlength == (uint32_t) -1)
- attr->tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
+ attr->tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
if (attr->minreq == (uint32_t) -1)
attr->minreq = (attr->tlength)/5; /* Ask for more data when there are only 200ms left in the playback buffer */
@@ -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);
@@ -930,7 +931,7 @@ static int create_stream(
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM,
+ (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM),
&tag);
if (s->context->version < 13)
@@ -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);
@@ -1093,7 +1105,7 @@ int pa_stream_write(
free_cb((void*) data);
if (length < s->requested_bytes)
- s->requested_bytes -= length;
+ s->requested_bytes -= (uint32_t) length;
else
s->requested_bytes = 0;
@@ -1107,10 +1119,10 @@ int pa_stream_write(
if (seek == PA_SEEK_ABSOLUTE) {
s->write_index_corrections[s->current_write_index_correction].corrupt = FALSE;
s->write_index_corrections[s->current_write_index_correction].absolute = TRUE;
- s->write_index_corrections[s->current_write_index_correction].value = offset + length;
+ s->write_index_corrections[s->current_write_index_correction].value = offset + (int64_t) length;
} else if (seek == PA_SEEK_RELATIVE) {
if (!s->write_index_corrections[s->current_write_index_correction].corrupt)
- s->write_index_corrections[s->current_write_index_correction].value += offset + length;
+ s->write_index_corrections[s->current_write_index_correction].value += offset + (int64_t) length;
} else
s->write_index_corrections[s->current_write_index_correction].corrupt = TRUE;
}
@@ -1120,10 +1132,10 @@ int pa_stream_write(
if (seek == PA_SEEK_ABSOLUTE) {
s->timing_info.write_index_corrupt = FALSE;
- s->timing_info.write_index = offset + length;
+ s->timing_info.write_index = offset + (int64_t) length;
} else if (seek == PA_SEEK_RELATIVE) {
if (!s->timing_info.write_index_corrupt)
- s->timing_info.write_index += offset + length;
+ s->timing_info.write_index += offset + (int64_t) length;
} else
s->timing_info.write_index_corrupt = TRUE;
}
@@ -1173,7 +1185,7 @@ int pa_stream_drop(pa_stream *s) {
/* Fix the simulated local read index */
if (s->timing_info_valid && !s->timing_info.read_index_corrupt)
- s->timing_info.read_index += s->peek_memchunk.length;
+ s->timing_info.read_index += (int64_t) s->peek_memchunk.length;
pa_assert(s->peek_data);
pa_memblock_release(s->peek_memchunk.memblock);
@@ -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);
@@ -1340,7 +1354,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
i->read_index_corrupt = FALSE;
i->playing = (int) playing;
- i->since_underrun = playing ? playing_for : underrun_for;
+ i->since_underrun = (int64_t) (playing ? playing_for : underrun_for);
pa_gettimeofday(&now);
@@ -1418,7 +1432,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
/* Read index correction */
if (!i->read_index_corrupt)
- i->read_index -= pa_memblockq_get_length(o->stream->record_memblockq);
+ i->read_index -= (int64_t) pa_memblockq_get_length(o->stream->record_memblockq);
}
/* Update smoother */
@@ -1435,7 +1449,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
* speakers. Since we follow that timing here, we need
* to try to fix this up */
- su = pa_bytes_to_usec(i->since_underrun, &o->stream->sample_spec);
+ su = pa_bytes_to_usec((uint64_t) i->since_underrun, &o->stream->sample_spec);
if (su < i->sink_usec)
x += i->sink_usec - su;
@@ -1494,7 +1508,7 @@ pa_operation* pa_stream_update_timing_info(pa_stream *s, pa_stream_success_cb_t
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_GET_PLAYBACK_LATENCY : PA_COMMAND_GET_RECORD_LATENCY,
+ (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_GET_PLAYBACK_LATENCY : PA_COMMAND_GET_RECORD_LATENCY),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_tagstruct_put_timeval(t, pa_gettimeofday(&now));
@@ -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);
@@ -1557,8 +1571,8 @@ int pa_stream_disconnect(pa_stream *s) {
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_DELETE_PLAYBACK_STREAM :
- (s->direction == PA_STREAM_RECORD ? PA_COMMAND_DELETE_RECORD_STREAM : PA_COMMAND_DELETE_UPLOAD_STREAM),
+ (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_DELETE_PLAYBACK_STREAM :
+ (s->direction == PA_STREAM_RECORD ? PA_COMMAND_DELETE_RECORD_STREAM : PA_COMMAND_DELETE_UPLOAD_STREAM)),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_pstream_send_tagstruct(s->context->pstream, t);
@@ -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;
@@ -1715,7 +1729,7 @@ pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, voi
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CORK_PLAYBACK_STREAM : PA_COMMAND_CORK_RECORD_STREAM,
+ (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CORK_PLAYBACK_STREAM : PA_COMMAND_CORK_RECORD_STREAM),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_tagstruct_put_boolean(t, !!b);
@@ -1760,7 +1774,7 @@ pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *use
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE);
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
- if (!(o = stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata)))
+ if (!(o = stream_send_simple_command(s, (uint32_t) (s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM), cb, userdata)))
return NULL;
if (s->direction == PA_STREAM_PLAYBACK) {
@@ -1846,7 +1860,7 @@ pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_succe
o = pa_operation_new(s->context, s, (pa_operation_cb_t) cb, userdata);
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_NAME : PA_COMMAND_SET_PLAYBACK_STREAM_NAME,
+ (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_NAME : PA_COMMAND_SET_PLAYBACK_STREAM_NAME),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_tagstruct_puts(t, name);
@@ -1932,7 +1946,7 @@ int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative) {
if (cindex < 0)
cindex = 0;
- c = pa_bytes_to_usec(cindex, &s->sample_spec);
+ c = pa_bytes_to_usec((uint64_t) cindex, &s->sample_spec);
if (s->direction == PA_STREAM_PLAYBACK)
*r_usec = time_counter_diff(s, c, t, negative);
@@ -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;
@@ -2046,7 +2060,7 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR : PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR,
+ (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR : PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR),
&tag);
pa_tagstruct_putu32(t, s->channel);
@@ -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;
@@ -2177,7 +2191,7 @@ pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_strea
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE : PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE,
+ (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE : PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_tagstruct_putu32(t, rate);
@@ -2205,7 +2219,7 @@ pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST : PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST,
+ (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST : PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST),
&tag);
pa_tagstruct_putu32(t, s->channel);
pa_tagstruct_putu32(t, (uint32_t) mode);
@@ -2238,7 +2252,7 @@ pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[],
t = pa_tagstruct_command(
s->context,
- s->direction == PA_STREAM_RECORD ? PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST : PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST,
+ (uint32_t) (s->direction == PA_STREAM_RECORD ? PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST : PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST),
&tag);
pa_tagstruct_putu32(t, s->channel);
diff --git a/src/pulse/subscribe.c b/src/pulse/subscribe.c
index d9c06b7e..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;
@@ -61,7 +61,6 @@ finish:
pa_context_unref(c);
}
-
pa_operation* pa_context_subscribe(pa_context *c, pa_subscription_mask_t m, pa_context_success_cb_t cb, void *userdata) {
pa_operation *o;
pa_tagstruct *t;
diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c
index 6b66696c..fb73ff1b 100644
--- a/src/pulse/thread-mainloop.c
+++ b/src/pulse/thread-mainloop.c
@@ -35,6 +35,7 @@
#include <pulse/xmalloc.h>
#include <pulse/mainloop.h>
+#include <pulse/i18n.h>
#include <pulsecore/log.h>
#include <pulsecore/hashmap.h>
@@ -94,6 +95,8 @@ static void thread(void *userdata) {
pa_threaded_mainloop *pa_threaded_mainloop_new(void) {
pa_threaded_mainloop *m;
+ pa_init_i18n();
+
m = pa_xnew(pa_threaded_mainloop, 1);
if (!(m->real_mainloop = pa_mainloop_new())) {
diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index 9708a735..376cf13c 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -90,13 +90,13 @@ pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
}
/* Calculate the second difference*/
- r = ((pa_usec_t) a->tv_sec - b->tv_sec) * PA_USEC_PER_SEC;
+ r = ((pa_usec_t) a->tv_sec - (pa_usec_t) b->tv_sec) * PA_USEC_PER_SEC;
/* Calculate the microsecond difference */
if (a->tv_usec > b->tv_usec)
- r += ((pa_usec_t) a->tv_usec - b->tv_usec);
+ r += ((pa_usec_t) a->tv_usec - (pa_usec_t) b->tv_usec);
else if (a->tv_usec < b->tv_usec)
- r -= ((pa_usec_t) b->tv_usec - a->tv_usec);
+ r -= ((pa_usec_t) b->tv_usec - (pa_usec_t) a->tv_usec);
return r;
}
@@ -132,7 +132,7 @@ struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
pa_assert(tv);
secs = (unsigned long) (v/PA_USEC_PER_SEC);
- tv->tv_sec += secs;
+ tv->tv_sec += (time_t) secs;
v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC;
tv->tv_usec += (suseconds_t) v;
@@ -140,7 +140,7 @@ struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
/* Normalize */
while ((unsigned) tv->tv_usec >= PA_USEC_PER_SEC) {
tv->tv_sec++;
- tv->tv_usec -= PA_USEC_PER_SEC;
+ tv->tv_usec -= (suseconds_t) PA_USEC_PER_SEC;
}
return tv;
@@ -151,14 +151,14 @@ struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) {
pa_assert(tv);
secs = (unsigned long) (v/PA_USEC_PER_SEC);
- tv->tv_sec -= secs;
+ tv->tv_sec -= (time_t) secs;
v -= ((pa_usec_t) secs) * PA_USEC_PER_SEC;
if (tv->tv_usec >= (suseconds_t) v)
tv->tv_usec -= (suseconds_t) v;
else {
tv->tv_sec --;
- tv->tv_usec = tv->tv_usec + PA_USEC_PER_SEC - v;
+ tv->tv_usec += (suseconds_t) (PA_USEC_PER_SEC - v);
}
return tv;
@@ -167,8 +167,8 @@ struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) {
struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) {
pa_assert(tv);
- tv->tv_sec = v / PA_USEC_PER_SEC;
- tv->tv_usec = v % PA_USEC_PER_SEC;
+ tv->tv_sec = (time_t) (v / PA_USEC_PER_SEC);
+ tv->tv_usec = (suseconds_t) (v % PA_USEC_PER_SEC);
return tv;
}
diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c
index 119be542..91aa9c81 100644
--- a/src/pulse/utf8.c
+++ b/src/pulse/utf8.c
@@ -109,17 +109,17 @@ static char* utf8_validate(const char *str, char *output) {
if ((*p & 0xe0) == 0xc0) { /* 110xxxxx two-char seq. */
size = 2;
min = 128;
- val = *p & 0x1e;
+ val = (uint32_t) (*p & 0x1e);
goto ONE_REMAINING;
} else if ((*p & 0xf0) == 0xe0) { /* 1110xxxx three-char seq.*/
size = 3;
min = (1 << 11);
- val = *p & 0x0f;
+ val = (uint32_t) (*p & 0x0f);
goto TWO_REMAINING;
} else if ((*p & 0xf8) == 0xf0) { /* 11110xxx four-char seq */
size = 4;
min = (1 << 16);
- val = *p & 0x07;
+ val = (uint32_t) (*p & 0x07);
} else {
size = 1;
goto error;
@@ -149,7 +149,7 @@ ONE_REMAINING:
goto error;
if (o) {
- memcpy(o, last, size);
+ memcpy(o, last, (size_t) size);
o += size - 1;
}
@@ -189,7 +189,7 @@ char* pa_utf8_filter (const char *str) {
char *new_str;
pa_assert(str);
- new_str = pa_xnew(char, strlen(str) + 1);
+ new_str = pa_xmalloc(strlen(str) + 1);
return utf8_validate(str, new_str);
}
@@ -212,7 +212,7 @@ static char* iconv_simple(const char *str, const char *to, const char *from) {
return NULL;
inlen = len = strlen(str) + 1;
- new_str = pa_xnew(char, len);
+ new_str = pa_xmalloc(len);
for (;;) {
inbuf = (ICONV_CONST char*) str; /* Brain dead prototype for iconv() */
diff --git a/src/pulse/util.c b/src/pulse/util.c
index c0911b51..b20ea46a 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 */
}
@@ -113,10 +116,8 @@ char *pa_get_host_name(char *s, size_t l) {
pa_assert(s);
pa_assert(l > 0);
- if (gethostname(s, l) < 0) {
- pa_log("gethostname(): %s", pa_cstrerror(errno));
+ if (gethostname(s, l) < 0)
return NULL;
- }
s[l-1] = 0;
return s;
@@ -140,20 +141,25 @@ 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) {
- pa_log("getpwuid_r() failed");
#else
/* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X)
* that do not support getpwuid_r. */
if ((r = getpwuid(getuid())) == NULL) {
- pa_log("getpwuid_r() failed");
#endif
+ if (!errno)
+ errno = ENOENT;
+
return NULL;
}
return pa_strlcpy(s, r->pw_dir, l);
#else /* HAVE_PWD_H */
+
+ errno = ENOENT;
return NULL;
#endif
}
@@ -204,6 +210,7 @@ char *pa_get_binary_name(char *s, size_t l) {
}
#endif
+ errno = ENOENT;
return NULL;
}
@@ -253,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 = (time_t) (t/1000UL);
+ ts.tv_nsec = (long) ((t % 1000UL) * 1000000UL);
return nanosleep(&ts, NULL);
#else
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index 70d6f86a..768bf49c 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -53,7 +53,7 @@ pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) {
pa_assert(channels > 0);
pa_assert(channels <= PA_CHANNELS_MAX);
- a->channels = channels;
+ a->channels = (uint8_t) channels;
for (i = 0; i < a->channels; i++)
a->values[i] = v;
@@ -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));
}
@@ -163,7 +175,7 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const
i < b->channels ? b->values[i] : PA_VOLUME_NORM);
}
- dest->channels = i;
+ dest->channels = (uint8_t) i;
return dest;
}
@@ -176,3 +188,88 @@ int pa_cvolume_valid(const pa_cvolume *v) {
return 1;
}
+
+static pa_bool_t on_left(pa_channel_position_t p) {
+
+ return
+ p == PA_CHANNEL_POSITION_FRONT_LEFT ||
+ p == PA_CHANNEL_POSITION_REAR_LEFT ||
+ p == PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER ||
+ p == PA_CHANNEL_POSITION_SIDE_LEFT ||
+ p == PA_CHANNEL_POSITION_TOP_FRONT_LEFT ||
+ p == PA_CHANNEL_POSITION_TOP_REAR_LEFT;
+}
+
+static pa_bool_t on_right(pa_channel_position_t p) {
+
+ return
+ p == PA_CHANNEL_POSITION_FRONT_RIGHT ||
+ p == PA_CHANNEL_POSITION_REAR_RIGHT ||
+ p == PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER ||
+ p == PA_CHANNEL_POSITION_SIDE_RIGHT ||
+ p == PA_CHANNEL_POSITION_TOP_FRONT_RIGHT ||
+ p == PA_CHANNEL_POSITION_TOP_REAR_RIGHT;
+}
+
+static pa_bool_t on_center(pa_channel_position_t p) {
+
+ return
+ p == PA_CHANNEL_POSITION_FRONT_CENTER ||
+ p == PA_CHANNEL_POSITION_REAR_CENTER ||
+ p == PA_CHANNEL_POSITION_TOP_CENTER ||
+ p == PA_CHANNEL_POSITION_TOP_FRONT_CENTER ||
+ p == PA_CHANNEL_POSITION_TOP_REAR_CENTER;
+}
+
+static pa_bool_t on_lfe(pa_channel_position_t p) {
+ return
+ p == PA_CHANNEL_POSITION_LFE;
+}
+
+pa_cvolume *pa_cvolume_remap(pa_cvolume *v, pa_channel_map *from, pa_channel_map *to) {
+ int a, b;
+ pa_cvolume result;
+
+ pa_assert(v);
+ pa_assert(from);
+ pa_assert(to);
+ pa_assert(v->channels == from->channels);
+
+ if (pa_channel_map_equal(from, to))
+ return v;
+
+ result.channels = to->channels;
+
+ for (b = 0; b < to->channels; b++) {
+ pa_volume_t k = 0;
+ int n = 0;
+
+ for (a = 0; a < from->channels; a++)
+ if (from->map[a] == to->map[b]) {
+ k += v->values[a];
+ n ++;
+ }
+
+ if (n <= 0) {
+ for (a = 0; a < from->channels; a++)
+ if ((on_left(from->map[a]) && on_left(to->map[b])) ||
+ (on_right(from->map[a]) && on_right(to->map[b])) ||
+ (on_center(from->map[a]) && on_center(to->map[b])) ||
+ (on_lfe(from->map[a]) && on_lfe(to->map[b]))) {
+
+ k += v->values[a];
+ n ++;
+ }
+ }
+
+ if (n <= 0)
+ k = pa_cvolume_avg(v);
+ else
+ k /= n;
+
+ result.values[b] = k;
+ }
+
+ *v = result;
+ return v;
+}
diff --git a/src/pulse/volume.h b/src/pulse/volume.h
index 5cce083e..d612c7f9 100644
--- a/src/pulse/volume.h
+++ b/src/pulse/volume.h
@@ -28,6 +28,7 @@
#include <pulse/cdecl.h>
#include <pulse/gccmacro.h>
#include <pulse/sample.h>
+#include <pulse/channelmap.h>
/** \page volume Volume Control
*
@@ -133,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;
@@ -170,6 +174,9 @@ double pa_sw_volume_to_linear(pa_volume_t v) PA_GCC_CONST;
#define PA_DECIBEL_MININFTY ((double) -200.0)
#endif
+/** Remap a volume from one channel mapping to a different channel mapping. \since 0.9.12 */
+pa_cvolume *pa_cvolume_remap(pa_cvolume *v, pa_channel_map *from, pa_channel_map *to);
+
PA_C_DECL_END
#endif
diff --git a/src/pulse/xmalloc.c b/src/pulse/xmalloc.c
index 90237013..d1138d65 100644
--- a/src/pulse/xmalloc.c
+++ b/src/pulse/xmalloc.c
@@ -113,7 +113,7 @@ char *pa_xstrndup(const char *s, size_t l) {
return NULL;
if ((e = memchr(s, 0, l)))
- return pa_xmemdup(s, e-s+1);
+ return pa_xmemdup(s, (size_t) (e-s+1));
r = pa_xmalloc(l+1);
memcpy(r, s, l);