summaryrefslogtreecommitdiffstats
path: root/src/pulse
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-05-15 23:34:41 +0000
committerLennart Poettering <lennart@poettering.net>2008-05-15 23:34:41 +0000
commit045c1d602dcba57868845ba3270510593c39480f (patch)
treeb3d61f180e6fa40f97a80aa3e46d7c910ed7c2a6 /src/pulse
parent91f092eadcc5e9075e04ae42df11de28ef5047a8 (diff)
merge glitch-free branch back into trunk
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2445 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/browser.c13
-rw-r--r--src/pulse/cdecl.h18
-rw-r--r--src/pulse/channelmap.h3
-rw-r--r--src/pulse/client-conf-x11.c7
-rw-r--r--src/pulse/client-conf.c20
-rw-r--r--src/pulse/context.c482
-rw-r--r--src/pulse/context.h38
-rw-r--r--src/pulse/def.h164
-rw-r--r--src/pulse/gccmacro.h98
-rw-r--r--src/pulse/internal.h53
-rw-r--r--src/pulse/introspect.c108
-rw-r--r--src/pulse/introspect.h297
-rw-r--r--src/pulse/mainloop-api.c3
-rw-r--r--src/pulse/mainloop-signal.c25
-rw-r--r--src/pulse/mainloop-signal.h16
-rw-r--r--src/pulse/operation.c33
-rw-r--r--src/pulse/proplist.c88
-rw-r--r--src/pulse/proplist.h185
-rw-r--r--src/pulse/sample.c10
-rw-r--r--src/pulse/sample.h3
-rw-r--r--src/pulse/scache.c122
-rw-r--r--src/pulse/scache.h31
-rw-r--r--src/pulse/simple.h4
-rw-r--r--src/pulse/stream.c1066
-rw-r--r--src/pulse/stream.h80
-rw-r--r--src/pulse/subscribe.c6
-rw-r--r--src/pulse/timeval.c18
-rw-r--r--src/pulse/timeval.h8
-rw-r--r--src/pulse/utf8.h1
-rw-r--r--src/pulse/util.h1
-rw-r--r--src/pulse/version.h.in13
-rw-r--r--src/pulse/volume.c4
-rw-r--r--src/pulse/volume.h22
-rw-r--r--src/pulse/xmalloc.c7
34 files changed, 2223 insertions, 824 deletions
diff --git a/src/pulse/browser.c b/src/pulse/browser.c
index 55e0b2cd..5e4aa87b 100644
--- a/src/pulse/browser.c
+++ b/src/pulse/browser.c
@@ -313,10 +313,15 @@ static void client_callback(AvahiClient *s, AvahiClientState state, void *userda
static void browser_free(pa_browser *b);
+
+PA_WARN_REFERENCE(pa_browser_new, "libpulse-browse is being phased out.");
+
pa_browser *pa_browser_new(pa_mainloop_api *mainloop) {
return pa_browser_new_full(mainloop, PA_BROWSE_FOR_SERVERS|PA_BROWSE_FOR_SINKS|PA_BROWSE_FOR_SOURCES, NULL);
}
+PA_WARN_REFERENCE(pa_browser_new_full, "libpulse-browse is being phased out.");
+
pa_browser *pa_browser_new_full(pa_mainloop_api *mainloop, pa_browse_flags_t flags, const char **error_string) {
pa_browser *b;
int error;
@@ -420,6 +425,8 @@ static void browser_free(pa_browser *b) {
pa_xfree(b);
}
+PA_WARN_REFERENCE(pa_browser_ref, "libpulse-browse is being phased out.");
+
pa_browser *pa_browser_ref(pa_browser *b) {
pa_assert(b);
pa_assert(PA_REFCNT_VALUE(b) >= 1);
@@ -428,6 +435,8 @@ pa_browser *pa_browser_ref(pa_browser *b) {
return b;
}
+PA_WARN_REFERENCE(pa_browser_unref, "libpulse-browse is being phased out.");
+
void pa_browser_unref(pa_browser *b) {
pa_assert(b);
pa_assert(PA_REFCNT_VALUE(b) >= 1);
@@ -436,6 +445,8 @@ void pa_browser_unref(pa_browser *b) {
browser_free(b);
}
+PA_WARN_REFERENCE(pa_browser_set_callback, "libpulse-browse is being phased out.");
+
void pa_browser_set_callback(pa_browser *b, pa_browse_cb_t cb, void *userdata) {
pa_assert(b);
pa_assert(PA_REFCNT_VALUE(b) >= 1);
@@ -444,6 +455,8 @@ void pa_browser_set_callback(pa_browser *b, pa_browse_cb_t cb, void *userdata) {
b->userdata = userdata;
}
+PA_WARN_REFERENCE(pa_browser_set_error_callback, "libpulse-browse is being phased out.");
+
void pa_browser_set_error_callback(pa_browser *b, pa_browser_error_cb_t cb, void *userdata) {
pa_assert(b);
pa_assert(PA_REFCNT_VALUE(b) >= 1);
diff --git a/src/pulse/cdecl.h b/src/pulse/cdecl.h
index e1f23d25..922ad276 100644
--- a/src/pulse/cdecl.h
+++ b/src/pulse/cdecl.h
@@ -41,22 +41,4 @@
#endif
-#ifndef PA_GCC_PURE
-#ifdef __GNUCC__
-#define PA_GCC_PURE __attribute__ ((pure))
-#else
-/** This function's return value depends only the arguments list and global state **/
-#define PA_GCC_PURE
-#endif
-#endif
-
-#ifndef PA_GCC_CONST
-#ifdef __GNUCC__
-#define PA_GCC_CONST __attribute__ ((pure))
-#else
-/** This function's return value depends only the arguments list (stricter version of PA_GCC_CONST) **/
-#define PA_GCC_CONST
-#endif
-#endif
-
#endif
diff --git a/src/pulse/channelmap.h b/src/pulse/channelmap.h
index a05e1911..00d3eb0d 100644
--- a/src/pulse/channelmap.h
+++ b/src/pulse/channelmap.h
@@ -27,6 +27,7 @@
#include <pulse/sample.h>
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
/** \page channelmap Channel Maps
*
@@ -183,7 +184,7 @@ const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos);
/** Make a humand readable string from the specified channel map */
char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map);
-/** Parse a channel position list into a channel map structure. \since 0.8.1 */
+/** Parse a channel position list into a channel map structure. */
pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s);
/** Compare two channel maps. Return 1 if both match. */
diff --git a/src/pulse/client-conf-x11.c b/src/pulse/client-conf-x11.c
index e240ba88..49df4b6c 100644
--- a/src/pulse/client-conf-x11.c
+++ b/src/pulse/client-conf-x11.c
@@ -46,7 +46,10 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
pa_assert(c);
- if (!dname && (!(dname = getenv("DISPLAY")) || *dname == '\0'))
+ if (!dname && !(dname = getenv("DISPLAY")))
+ goto finish;
+
+ if (*dname == 0)
goto finish;
if (!(d = XOpenDisplay(dname))) {
@@ -80,7 +83,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
pa_assert(sizeof(cookie) == sizeof(c->cookie));
memcpy(c->cookie, cookie, sizeof(cookie));
- c->cookie_valid = 1;
+ c->cookie_valid = TRUE;
pa_xfree(c->cookie_file);
c->cookie_file = NULL;
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index c054f663..75f44182 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -112,13 +112,20 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
table[6].data = &c->cookie_file;
table[7].data = &c->disable_shm;
- f = filename ?
- fopen((fn = pa_xstrdup(filename)), "r") :
- pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn, "r");
+ if (filename) {
- if (!f && errno != EINTR) {
- pa_log_warn("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
- goto finish;
+ if (!(f = fopen(filename, "r"))) {
+ pa_log("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
+ goto finish;
+ }
+
+ fn = pa_xstrdup(fn);
+
+ } else {
+
+ if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn)))
+ if (errno != ENOENT)
+ goto finish;
}
r = f ? pa_config_parse(fn, f, table, NULL) : 0;
@@ -126,7 +133,6 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
if (!r)
r = pa_client_conf_load_cookie(c);
-
finish:
pa_xfree(fn);
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 7243a29d..f9f021af 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -3,7 +3,7 @@
/***
This file is part of PulseAudio.
- Copyright 2004-2006 Lennart Poettering
+ Copyright 2004-2008 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
@@ -35,6 +35,7 @@
#include <errno.h>
#include <signal.h>
#include <limits.h>
+#include <locale.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
@@ -52,6 +53,8 @@
#include <pulse/version.h>
#include <pulse/xmalloc.h>
+#include <pulse/utf8.h>
+#include <pulse/util.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
@@ -90,6 +93,7 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_RECORD_STREAM_MOVED] = pa_command_stream_moved,
[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
};
@@ -97,10 +101,12 @@ static void unlock_autospawn_lock_file(pa_context *c) {
pa_assert(c);
if (c->autospawn_lock_fd >= 0) {
- char lf[PATH_MAX];
- pa_runtime_path(AUTOSPAWN_LOCK, lf, sizeof(lf));
+ char *lf;
+ lf = pa_runtime_path(AUTOSPAWN_LOCK);
pa_unlock_lockfile(lf, c->autospawn_lock_fd);
+ pa_xfree(lf);
+
c->autospawn_lock_fd = -1;
}
}
@@ -108,20 +114,42 @@ static void unlock_autospawn_lock_file(pa_context *c) {
static void context_free(pa_context *c);
pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) {
+ return pa_context_new_with_proplist(mainloop, name, NULL);
+}
+
+static void reset_callbacks(pa_context *c) {
+ pa_assert(c);
+
+ c->state_callback = NULL;
+ c->state_userdata = NULL;
+
+ c->subscribe_callback = NULL;
+ c->subscribe_userdata = NULL;
+}
+
+pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
pa_context *c;
pa_assert(mainloop);
- pa_assert(name);
+
+ if (!name && !pa_proplist_contains(p, PA_PROP_APPLICATION_NAME))
+ return NULL;
c = pa_xnew(pa_context, 1);
PA_REFCNT_INIT(c);
- c->name = pa_xstrdup(name);
+
+ c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new();
+
+ if (name)
+ pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
+
c->mainloop = mainloop;
c->client = NULL;
c->pstream = NULL;
c->pdispatch = NULL;
c->playback_streams = pa_dynarray_new();
c->record_streams = pa_dynarray_new();
+ c->client_index = PA_INVALID_INDEX;
PA_LLIST_HEAD_INIT(pa_stream, c->streams);
PA_LLIST_HEAD_INIT(pa_operation, c->operations);
@@ -131,18 +159,14 @@ pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) {
c->ctag = 0;
c->csyncid = 0;
- c->state_callback = NULL;
- c->state_userdata = NULL;
-
- c->subscribe_callback = NULL;
- c->subscribe_userdata = NULL;
+ reset_callbacks(c);
- c->is_local = -1;
+ 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 = 0;
+ c->do_autospawn = FALSE;
#ifndef MSG_NOSIGNAL
#ifdef SIGPIPE
@@ -171,26 +195,48 @@ pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) {
return c;
}
-static void context_free(pa_context *c) {
+static void context_unlink(pa_context *c) {
+ pa_stream *s;
+
pa_assert(c);
- unlock_autospawn_lock_file(c);
+ s = c->streams ? pa_stream_ref(c->streams) : NULL;
+ while (s) {
+ pa_stream *n = s->next ? pa_stream_ref(s->next) : NULL;
+ pa_stream_set_state(s, c->state == PA_CONTEXT_FAILED ? PA_STREAM_FAILED : PA_STREAM_TERMINATED);
+ pa_stream_unref(s);
+ s = n;
+ }
while (c->operations)
pa_operation_cancel(c->operations);
- while (c->streams)
- pa_stream_set_state(c->streams, PA_STREAM_TERMINATED);
-
- if (c->client)
- pa_socket_client_unref(c->client);
- if (c->pdispatch)
+ if (c->pdispatch) {
pa_pdispatch_unref(c->pdispatch);
+ c->pdispatch = NULL;
+ }
+
if (c->pstream) {
pa_pstream_unlink(c->pstream);
pa_pstream_unref(c->pstream);
+ c->pstream = NULL;
}
+ if (c->client) {
+ pa_socket_client_unref(c->client);
+ c->client = NULL;
+ }
+
+ reset_callbacks(c);
+}
+
+static void context_free(pa_context *c) {
+ pa_assert(c);
+
+ context_unlink(c);
+
+ unlock_autospawn_lock_file(c);
+
if (c->record_streams)
pa_dynarray_free(c->record_streams, NULL, NULL);
if (c->playback_streams)
@@ -204,7 +250,9 @@ static void context_free(pa_context *c) {
pa_strlist_free(c->server_list);
- pa_xfree(c->name);
+ if (c->proplist)
+ pa_proplist_free(c->proplist);
+
pa_xfree(c->server);
pa_xfree(c);
}
@@ -235,46 +283,16 @@ void pa_context_set_state(pa_context *c, pa_context_state_t st) {
pa_context_ref(c);
c->state = st;
+
if (c->state_callback)
c->state_callback(c, c->state_userdata);
- if (st == PA_CONTEXT_FAILED || st == PA_CONTEXT_TERMINATED) {
- pa_stream *s;
-
- s = c->streams ? pa_stream_ref(c->streams) : NULL;
- while (s) {
- pa_stream *n = s->next ? pa_stream_ref(s->next) : NULL;
- pa_stream_set_state(s, st == PA_CONTEXT_FAILED ? PA_STREAM_FAILED : PA_STREAM_TERMINATED);
- pa_stream_unref(s);
- s = n;
- }
-
- if (c->pdispatch)
- pa_pdispatch_unref(c->pdispatch);
- c->pdispatch = NULL;
-
- if (c->pstream) {
- pa_pstream_unlink(c->pstream);
- pa_pstream_unref(c->pstream);
- }
- c->pstream = NULL;
-
- if (c->client)
- pa_socket_client_unref(c->client);
- c->client = NULL;
- }
+ if (st == PA_CONTEXT_FAILED || st == PA_CONTEXT_TERMINATED)
+ context_unlink(c);
pa_context_unref(c);
}
-void pa_context_fail(pa_context *c, int error) {
- pa_assert(c);
- pa_assert(PA_REFCNT_VALUE(c) >= 1);
-
- pa_context_set_error(c, error);
- pa_context_set_state(c, PA_CONTEXT_FAILED);
-}
-
int pa_context_set_error(pa_context *c, int error) {
pa_assert(error >= 0);
pa_assert(error < PA_ERR_MAX);
@@ -285,6 +303,14 @@ int pa_context_set_error(pa_context *c, int error) {
return error;
}
+void pa_context_fail(pa_context *c, int error) {
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ pa_context_set_error(c, error);
+ pa_context_set_state(c, PA_CONTEXT_FAILED);
+}
+
static void pstream_die_callback(pa_pstream *p, void *userdata) {
pa_context *c = userdata;
@@ -341,25 +367,41 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o
pa_context_unref(c);
}
-int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t) {
+int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa_bool_t fail) {
+ uint32_t err;
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
if (command == PA_COMMAND_ERROR) {
pa_assert(t);
- if (pa_tagstruct_getu32(t, &c->error) < 0) {
+ if (pa_tagstruct_getu32(t, &err) < 0) {
pa_context_fail(c, PA_ERR_PROTOCOL);
return -1;
-
}
+
} else if (command == PA_COMMAND_TIMEOUT)
- c->error = PA_ERR_TIMEOUT;
+ err = PA_ERR_TIMEOUT;
else {
pa_context_fail(c, PA_ERR_PROTOCOL);
return -1;
}
+ if (err == PA_OK) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ return -1;
+ }
+
+ if (err >= PA_ERR_MAX)
+ err = PA_ERR_UNKNOWN;
+
+ if (fail) {
+ pa_context_fail(c, err);
+ return -1;
+ }
+
+ pa_context_set_error(c, err);
+
return 0;
}
@@ -373,11 +415,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
pa_context_ref(c);
if (command != PA_COMMAND_REPLY) {
-
- if (pa_context_handle_error(c, command, t) < 0)
- pa_context_fail(c, PA_ERR_PROTOCOL);
-
- pa_context_fail(c, c->error);
+ pa_context_handle_error(c, command, t, TRUE);
goto finish;
}
@@ -400,7 +438,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
/* Enable shared memory support if possible */
if (c->version >= 10 &&
pa_mempool_is_shared(c->mempool) &&
- c->is_local > 0) {
+ c->is_local) {
/* Only enable SHM if both sides are owned by the same
* user. This is a security measure because otherwise
@@ -410,12 +448,18 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
const pa_creds *creds;
if ((creds = pa_pdispatch_creds(pd)))
if (getuid() == creds->uid)
- pa_pstream_use_shm(c->pstream, 1);
+ pa_pstream_enable_shm(c->pstream, TRUE);
#endif
}
reply = pa_tagstruct_command(c, PA_COMMAND_SET_CLIENT_NAME, &tag);
- pa_tagstruct_puts(reply, c->name);
+
+ if (c->version >= 13) {
+ pa_init_proplist(c->proplist);
+ pa_tagstruct_put_proplist(reply, c->proplist);
+ } else
+ pa_tagstruct_puts(reply, pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME));
+
pa_pstream_send_tagstruct(c->pstream, reply);
pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, setup_complete_callback, c, NULL);
@@ -424,11 +468,19 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
}
case PA_CONTEXT_SETTING_NAME :
+
+ if ((c->version >= 13 && (pa_tagstruct_getu32(t, &c->client_index) < 0 ||
+ c->client_index == PA_INVALID_INDEX)) ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
pa_context_set_state(c, PA_CONTEXT_READY);
break;
default:
- pa_assert(0);
+ pa_assert_not_reached();
}
finish:
@@ -455,7 +507,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_warn("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);
pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION);
@@ -494,10 +546,13 @@ static int context_connect_spawn(pa_context *c) {
int fds[2] = { -1, -1} ;
pa_iochannel *io;
+ if (getuid() == 0)
+ return -1;
+
pa_context_ref(c);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
- pa_log("socketpair(): %s", pa_cstrerror(errno));
+ pa_log_error("socketpair(): %s", pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
goto fail;
}
@@ -511,7 +566,7 @@ static int context_connect_spawn(pa_context *c) {
c->spawn_api.prefork();
if ((pid = fork()) < 0) {
- pa_log("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)
@@ -526,9 +581,13 @@ static int context_connect_spawn(pa_context *c) {
#define MAX_ARGS 64
const char * argv[MAX_ARGS+1];
int n;
+ char *f;
+
+ pa_close_all(fds[1], -1);
- /* Not required, since fds[0] has CLOEXEC enabled anyway */
- pa_assert_se(pa_close(fds[0]) == 0);
+ f = pa_sprintf_malloc("%i", fds[1]);
+ pa_set_env("PULSE_PASSED_FD", f);
+ pa_xfree(f);
if (c->spawn_api.atfork)
c->spawn_api.atfork();
@@ -561,6 +620,8 @@ static int context_connect_spawn(pa_context *c) {
/* Parent */
+ pa_assert_se(pa_close(fds[1]) == 0);
+
r = waitpid(pid, &status, 0);
if (c->spawn_api.postfork)
@@ -575,14 +636,12 @@ static int context_connect_spawn(pa_context *c) {
goto fail;
}
- pa_assert_se(pa_close(fds[1]) == 0);
+ c->is_local = TRUE;
- c->is_local = 1;
+ unlock_autospawn_lock_file(c);
io = pa_iochannel_new(c->mainloop, fds[0], fds[0]);
-
setup_context(c, io);
- unlock_autospawn_lock_file(c);
pa_context_unref(c);
@@ -634,7 +693,7 @@ static int try_next_connection(pa_context *c) {
if (!(c->client = pa_socket_client_new_string(c->mainloop, u, PA_NATIVE_DEFAULT_PORT)))
continue;
- c->is_local = pa_socket_client_is_local(c->client);
+ c->is_local = !!pa_socket_client_is_local(c->client);
pa_socket_client_set_callback(c->client, on_connection, c);
break;
}
@@ -649,6 +708,7 @@ finish:
static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata) {
pa_context *c = userdata;
+ int saved_errno = errno;
pa_assert(client);
pa_assert(c);
@@ -661,7 +721,9 @@ static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userd
if (!io) {
/* Try the item in the list */
- if (errno == ECONNREFUSED || errno == ETIMEDOUT || errno == EHOSTUNREACH) {
+ if (saved_errno == ECONNREFUSED ||
+ saved_errno == ETIMEDOUT ||
+ saved_errno == EHOSTUNREACH) {
try_next_connection(c);
goto finish;
}
@@ -677,6 +739,25 @@ finish:
pa_context_unref(c);
}
+
+static char *get_legacy_runtime_dir(void) {
+ char *p, u[128];
+ struct stat st;
+
+ if (!pa_get_user_name(u, sizeof(u)))
+ return NULL;
+
+ p = pa_sprintf_malloc("/tmp/pulse-%s", u);
+
+ if (stat(p, &st) < 0)
+ return NULL;
+
+ if (st.st_uid != getuid())
+ return NULL;
+
+ return p;
+}
+
int pa_context_connect(
pa_context *c,
const char *server,
@@ -705,8 +786,8 @@ int pa_context_connect(
goto finish;
}
} else {
- char *d;
- char ufn[PATH_MAX];
+ char *d, *ufn;
+ static char *legacy_dir;
/* Prepend in reverse order */
@@ -726,25 +807,34 @@ int pa_context_connect(
c->server_list = pa_strlist_prepend(c->server_list, "tcp4:localhost");
/* The system wide instance */
- c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH "/" PA_NATIVE_DEFAULT_UNIX_SOCKET);
+ 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 easy upgrades */
+ if ((legacy_dir = get_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 per-user instance */
- c->server_list = pa_strlist_prepend(c->server_list, pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET, ufn, sizeof(ufn)));
+ c->server_list = pa_strlist_prepend(c->server_list, ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET));
+ pa_xfree(ufn);
/* Wrap the connection attempts in a single transaction for sane autospawn locking */
if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) {
- char lf[PATH_MAX];
+ char *lf;
- pa_runtime_path(AUTOSPAWN_LOCK, lf, sizeof(lf));
- pa_make_secure_parent_dir(lf, 0700, (uid_t)-1, (gid_t)-1);
+ lf = pa_runtime_path(AUTOSPAWN_LOCK);
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 = 1;
- }
+ c->do_autospawn = TRUE;
+ }
}
pa_context_set_state(c, PA_CONTEXT_CONNECTING);
@@ -760,7 +850,8 @@ void pa_context_disconnect(pa_context *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
- pa_context_set_state(c, PA_CONTEXT_TERMINATED);
+ if (PA_CONTEXT_IS_GOOD(c->state))
+ pa_context_set_state(c, PA_CONTEXT_TERMINATED);
}
pa_context_state_t pa_context_get_state(pa_context *c) {
@@ -781,6 +872,9 @@ void pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, voi
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ if (c->state == PA_CONTEXT_TERMINATED || c->state == PA_CONTEXT_FAILED)
+ return;
+
c->state_callback = cb;
c->state_userdata = userdata;
}
@@ -789,11 +883,7 @@ int pa_context_is_pending(pa_context *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
- PA_CHECK_VALIDITY(c,
- c->state == PA_CONTEXT_CONNECTING ||
- c->state == PA_CONTEXT_AUTHORIZING ||
- c->state == PA_CONTEXT_SETTING_NAME ||
- c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE);
return (c->pstream && pa_pstream_is_pending(c->pstream)) ||
(c->pdispatch && pa_pdispatch_is_pending(c->pdispatch)) ||
@@ -870,7 +960,7 @@ void pa_context_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_U
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
success = 0;
@@ -889,7 +979,7 @@ finish:
pa_operation_unref(o);
}
-pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata) {
+pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, pa_pdispatch_cb_t internal_cb, pa_operation_cb_t cb, void *userdata) {
pa_tagstruct *t;
pa_operation *o;
uint32_t tag;
@@ -899,32 +989,20 @@ pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb,
PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
- o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+ o = pa_operation_new(c, NULL, cb, userdata);
- t = pa_tagstruct_command(c, PA_COMMAND_EXIT, &tag);
+ t = pa_tagstruct_command(c, command, &tag);
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);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, internal_cb, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
return o;
}
-pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, pa_pdispatch_cb_t internal_cb, pa_operation_cb_t cb, void *userdata) {
- pa_tagstruct *t;
- pa_operation *o;
- uint32_t tag;
-
+pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
- PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
-
- o = pa_operation_new(c, NULL, cb, userdata);
-
- t = pa_tagstruct_command(c, command, &tag);
- pa_pstream_send_tagstruct(c->pstream, t);
- pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, internal_cb, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
-
- return o;
+ return pa_context_send_simple_command(c, PA_COMMAND_EXIT, pa_context_simple_ack_callback, (pa_operation_cb_t) cb, userdata);
}
pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) {
@@ -938,7 +1016,6 @@ pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_co
PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
-
t = pa_tagstruct_command(c, PA_COMMAND_SET_DEFAULT_SINK, &tag);
pa_tagstruct_puts(t, name);
pa_pstream_send_tagstruct(c->pstream, t);
@@ -958,7 +1035,6 @@ pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_
PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
-
t = pa_tagstruct_command(c, PA_COMMAND_SET_DEFAULT_SOURCE, &tag);
pa_tagstruct_puts(t, name);
pa_pstream_send_tagstruct(c->pstream, t);
@@ -971,15 +1047,13 @@ int pa_context_is_local(pa_context *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
- PA_CHECK_VALIDITY(c, c->is_local >= 0, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_ANY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE, -1);
- return c->is_local;
+ return !!c->is_local;
}
pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) {
- pa_tagstruct *t;
pa_operation *o;
- uint32_t tag;
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
@@ -987,12 +1061,22 @@ pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_su
PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
- o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+ if (c->version >= 13) {
+ pa_proplist *p = pa_proplist_new();
- t = pa_tagstruct_command(c, PA_COMMAND_SET_CLIENT_NAME, &tag);
- pa_tagstruct_puts(t, name);
- 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);
+ pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, name);
+ o = pa_context_proplist_update(c, PA_UPDATE_REPLACE, p, cb, userdata);
+ pa_proplist_free(p);
+ } else {
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+ t = pa_tagstruct_command(c, PA_COMMAND_SET_CLIENT_NAME, &tag);
+ pa_tagstruct_puts(t, name);
+ 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;
}
@@ -1024,6 +1108,8 @@ uint32_t pa_context_get_server_protocol_version(pa_context *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ PA_CHECK_VALIDITY_RETURN_ANY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE, PA_INVALID_INDEX);
+
return c->version;
}
@@ -1039,3 +1125,153 @@ pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *ta
return t;
}
+
+uint32_t pa_context_get_index(pa_context *c) {
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_ANY(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE, PA_INVALID_INDEX);
+ PA_CHECK_VALIDITY_RETURN_ANY(c, c->version >= 13, PA_ERR_NOTSUPPORTED, PA_INVALID_INDEX);
+
+ return c->client_index;
+}
+
+pa_operation *pa_context_proplist_update(pa_context *c, pa_update_mode_t mode, pa_proplist *p, pa_context_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, mode == PA_UPDATE_SET || mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_UPDATE_CLIENT_PROPLIST, &tag);
+ pa_tagstruct_putu32(t, (uint32_t) mode);
+ pa_tagstruct_put_proplist(t, p);
+
+ 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);
+
+ /* Please note that we don't update c->proplist here, because we
+ * don't export that field */
+
+ return o;
+}
+
+pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[], pa_context_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+ const char * const *k;
+
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(c, keys && keys[0], PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ t = pa_tagstruct_command(c, PA_COMMAND_REMOVE_CLIENT_PROPLIST, &tag);
+
+ for (k = keys; *k; k++)
+ pa_tagstruct_puts(t, *k);
+
+ pa_tagstruct_puts(t, NULL);
+
+ 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);
+
+ /* Please note that we don't update c->proplist here, because we
+ * don't export that field */
+
+ return o;
+}
+
+void pa_init_proplist(pa_proplist *p) {
+ int a, b;
+#ifndef HAVE_DECL_ENVIRON
+ extern char **environ;
+#endif
+ char **e;
+
+ pa_assert(p);
+
+ for (e = environ; *e; e++) {
+
+ if (pa_startswith(*e, "PULSE_PROP_")) {
+ size_t kl = strcspn(*e+11, "=");
+ char *k;
+
+ if ((*e)[11+kl] != '=')
+ continue;
+
+ if (!pa_utf8_valid(*e+11+kl+1))
+ continue;
+
+ k = pa_xstrndup(*e+11, kl);
+
+ if (pa_proplist_contains(p, k)) {
+ pa_xfree(k);
+ continue;
+ }
+
+ pa_proplist_sets(p, k, *e+11+kl+1);
+ pa_xfree(k);
+ }
+ }
+
+ if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_ID)) {
+ char t[32];
+ pa_snprintf(t, sizeof(t), "%lu", (unsigned long) getpid());
+ pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_ID, t);
+ }
+
+ if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
+ char t[64];
+ if (pa_get_user_name(t, sizeof(t))) {
+ char *c = pa_utf8_filter(t);
+ pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, c);
+ pa_xfree(c);
+ }
+ }
+
+ if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
+ char t[64];
+ if (pa_get_host_name(t, sizeof(t))) {
+ char *c = pa_utf8_filter(t);
+ pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, c);
+ pa_xfree(c);
+ }
+ }
+
+ a = pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY);
+ b = pa_proplist_contains(p, PA_PROP_APPLICATION_NAME);
+
+ if (!a || !b) {
+ char t[PATH_MAX];
+ if (pa_get_binary_name(t, sizeof(t))) {
+ char *c = pa_utf8_filter(t);
+
+ if (!a)
+ pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
+ if (!b)
+ pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, c);
+
+ pa_xfree(c);
+ }
+ }
+
+ if (!pa_proplist_contains(p, PA_PROP_APPLICATION_LANGUAGE)) {
+ const char *l;
+
+ if ((l = setlocale(LC_MESSAGES, NULL)))
+ pa_proplist_sets(p, PA_PROP_APPLICATION_LANGUAGE, l);
+ }
+}
diff --git a/src/pulse/context.h b/src/pulse/context.h
index 1de3abad..143508f4 100644
--- a/src/pulse/context.h
+++ b/src/pulse/context.h
@@ -30,6 +30,7 @@
#include <pulse/mainloop-api.h>
#include <pulse/cdecl.h>
#include <pulse/operation.h>
+#include <pulse/proplist.h>
/** \page async Asynchronous API
*
@@ -166,9 +167,15 @@ typedef void (*pa_context_notify_cb_t)(pa_context *c, void *userdata);
typedef void (*pa_context_success_cb_t) (pa_context *c, int success, void *userdata);
/** Instantiate a new connection context with an abstract mainloop API
- * and an application name */
+ * and an application name. It is recommended to use pa_context_new_with_proplist()
+ * instead and specify some initial properties.*/
pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name);
+/** Instantiate a new connection context with an abstract mainloop API
+ * and an application name, and specify the the initial client property
+ * list. \since 0.9.11 */
+pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist);
+
/** Decrease the reference counter of the context by one */
void pa_context_unref(pa_context *c);
@@ -207,27 +214,42 @@ pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *u
* returning a success notification */
pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata);
-/** Set the name of the default sink. \since 0.4 */
+/** Set the name of the default sink. */
pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);
-/** Set the name of the default source. \since 0.4 */
+/** Set the name of the default source. */
pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);
-/** Returns 1 when the connection is to a local daemon. Returns negative when no connection has been made yet. \since 0.5 */
+/** Returns 1 when the connection is to a local daemon. Returns negative when no connection has been made yet. */
int pa_context_is_local(pa_context *c);
-/** Set a different application name for context on the server. \since 0.5 */
+/** Set a different application name for context on the server. */
pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);
-/** Return the server name this context is connected to. \since 0.7 */
+/** Return the server name this context is connected to. */
const char* pa_context_get_server(pa_context *c);
-/** Return the protocol version of the library. \since 0.8 */
+/** Return the protocol version of the library. */
uint32_t pa_context_get_protocol_version(pa_context *c);
-/** Return the protocol version of the connected server. \since 0.8 */
+/** Return the protocol version of the connected server. */
uint32_t pa_context_get_server_protocol_version(pa_context *c);
+/* Update the property list of the client, adding new entries. Please
+ * note that it is highly recommended to set as much properties
+ * initially via pa_context_new_with_proplist() as possible instead a
+ * posteriori with this function, since that information may then be
+ * used to route streams of the client to the right device. \since 0.9.11 */
+pa_operation *pa_context_proplist_update(pa_context *c, pa_update_mode_t mode, pa_proplist *p, pa_context_success_cb_t cb, void *userdata);
+
+/* Update the property list of the client, remove entries. \since 0.9.11 */
+pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[], pa_context_success_cb_t cb, void *userdata);
+
+/** Return the client index this context is
+ * identified in the server with. This is useful for usage with the
+ * introspection functions, such as pa_context_get_client_info(). \since 0.9.11 */
+uint32_t pa_context_get_index(pa_context *s);
+
PA_C_DECL_END
#endif
diff --git a/src/pulse/def.h b/src/pulse/def.h
index dabbc5eb..10722329 100644
--- a/src/pulse/def.h
+++ b/src/pulse/def.h
@@ -48,6 +48,15 @@ typedef enum pa_context_state {
PA_CONTEXT_TERMINATED /**< The connection was terminated cleanly */
} pa_context_state_t;
+/** Return non-zero if the passed state is one of the connected states */
+static inline int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
+ return
+ x == PA_CONTEXT_CONNECTING ||
+ x == PA_CONTEXT_AUTHORIZING ||
+ x == PA_CONTEXT_SETTING_NAME ||
+ x == PA_CONTEXT_READY;
+}
+
/** The state of a stream */
typedef enum pa_stream_state {
PA_STREAM_UNCONNECTED, /**< The stream is not yet connected to any sink or source */
@@ -57,6 +66,13 @@ typedef enum pa_stream_state {
PA_STREAM_TERMINATED /**< The stream has been terminated cleanly */
} pa_stream_state_t;
+/** Return non-zero if the passed state is one of the connected states */
+static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
+ return
+ x == PA_STREAM_CREATING ||
+ x == PA_STREAM_READY;
+}
+
/** The state of an operation */
typedef enum pa_operation_state {
PA_OPERATION_RUNNING, /**< The operation is still running */
@@ -67,7 +83,7 @@ typedef enum pa_operation_state {
/** An invalid index */
#define PA_INVALID_INDEX ((uint32_t) -1)
-/** Some special flags for contexts. \since 0.8 */
+/** Some special flags for contexts. */
typedef enum pa_context_flags {
PA_CONTEXT_NOAUTOSPAWN = 1 /**< Disabled autospawning of the PulseAudio daemon if required */
} pa_context_flags_t;
@@ -80,7 +96,7 @@ typedef enum pa_stream_direction {
PA_STREAM_UPLOAD /**< Sample upload stream */
} pa_stream_direction_t;
-/** Some special flags for stream connections. \since 0.6 */
+/** Some special flags for stream connections. */
typedef enum pa_stream_flags {
PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
PA_STREAM_INTERPOLATE_TIMING = 2, /**< Interpolate the latency for
@@ -209,15 +225,73 @@ typedef enum pa_stream_flags {
* least PA 0.9.8. It is ignored
* on older servers. \since
* 0.9.8 */
+ PA_STREAM_PEAK_DETECT = 2048, /**< Find peaks instead of
+ * resampling. \since 0.9.11 */
+
+ PA_STREAM_START_MUTED = 4096, /**< Create in muted state. \since 0.9.11 */
+
+
+ PA_STREAM_ADJUST_LATENCY = 8192, /**< Try to adjust the latency of
+ * the sink/source based on the
+ * requested buffer metrics and
+ * adjust buffer metrics
+ * accordingly. \since 0.9.11 */
} pa_stream_flags_t;
+
+/** English is an evil language \since 0.9.11 */
+#define PA_STREAM_NOT_MONOTONIC PA_STREAM_NOT_MONOTONOUS
+
/** Playback and record buffer metrics */
typedef struct pa_buffer_attr {
- uint32_t maxlength; /**< Maximum length of the buffer */
- uint32_t tlength; /**< Playback only: target length of the buffer. The server tries to assure that at least tlength bytes are always available in the buffer */
- uint32_t prebuf; /**< Playback only: pre-buffering. The server does not start with playback before at least prebug bytes are available in the buffer */
- uint32_t minreq; /**< Playback only: minimum request. The server does not request less than minreq bytes from the client, instead waints until the buffer is free enough to request more bytes at once */
- uint32_t fragsize; /**< Recording only: fragment size. The server sends data in blocks of fragsize bytes size. Large values deminish interactivity with other operations on the connection context but decrease control overhead. */
+ uint32_t maxlength; /**< Maximum length of the
+ * buffer. Setting this to 0 will
+ * initialize this to the maximum value
+ * supported by server, which is
+ * recommended. */
+ uint32_t tlength; /**< Playback only: target length of the
+ * buffer. The server tries to assure
+ * that at least tlength bytes are always
+ * available in the buffer. It is
+ * recommended to set this to 0, which
+ * will initialize this to a value that
+ * is deemed sensible by the
+ * server. However, this value will
+ * default to something like 2s, i.e. for
+ * applications that have specific
+ * latency requirements this value should
+ * be set to the maximum latency that the
+ * application can deal with. */
+ uint32_t prebuf; /**< Playback only: pre-buffering. The
+ * server does not start with playback
+ * before at least prebug bytes are
+ * available in the buffer. It is
+ * recommended to set this to 0, which
+ * will initialize this to the same value
+ * as tlength, whatever that may be. */
+ uint32_t minreq; /**< Playback only: minimum request. The
+ * server does not request less than
+ * minreq bytes from the client, instead
+ * waits until the buffer is free enough
+ * to request more bytes at once. It is
+ * recommended to set this to 0, which
+ * will initialize this to a value that
+ * is deemed sensible by the server. */
+ uint32_t fragsize; /**< Recording only: fragment size. The
+ * server sends data in blocks of
+ * fragsize bytes size. Large values
+ * deminish interactivity with other
+ * operations on the connection context
+ * but decrease control overhead. It is
+ * recommended to set this to 0, which
+ * will initialize this to a value that
+ * is deemed sensible by the
+ * server. However, this value will
+ * default to something like 2s, i.e. for
+ * applications that have specific
+ * latency requirements this value should
+ * be set to the maximum latency that the
+ * application can deal with. */
} pa_buffer_attr;
/** Error values as used by pa_context_errno(). Use pa_strerror() to convert these values to human readable strings */
@@ -239,9 +313,10 @@ enum {
PA_ERR_MODINITFAILED, /**< Module initialization failed */
PA_ERR_BADSTATE, /**< Bad state */
PA_ERR_NODATA, /**< No data */
- PA_ERR_VERSION, /**< Incompatible protocol version \since 0.8 */
- PA_ERR_TOOLARGE, /**< Data too large \since 0.8.1 */
+ PA_ERR_VERSION, /**< Incompatible protocol version */
+ PA_ERR_TOOLARGE, /**< Data too large */
PA_ERR_NOTSUPPORTED, /**< Operation not supported \since 0.9.5 */
+ PA_ERR_UNKNOWN, /**< The error code was unknown to the client */
PA_ERR_MAX /**< Not really an error but the first invalid error code */
};
@@ -255,9 +330,9 @@ typedef enum pa_subscription_mask {
PA_SUBSCRIPTION_MASK_MODULE = 16, /**< Module events */
PA_SUBSCRIPTION_MASK_CLIENT = 32, /**< Client events */
PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 64, /**< Sample cache events */
- PA_SUBSCRIPTION_MASK_SERVER = 128, /**< Other global server changes. \since 0.4 */
- PA_SUBSCRIPTION_MASK_AUTOLOAD = 256, /**< Autoload table events. \since 0.5 */
- PA_SUBSCRIPTION_MASK_ALL = 511 /**< Catch all events \since 0.8 */
+ PA_SUBSCRIPTION_MASK_SERVER = 128, /**< Other global server changes. */
+ PA_SUBSCRIPTION_MASK_AUTOLOAD = 256, /**< Autoload table events. */
+ PA_SUBSCRIPTION_MASK_ALL = 511 /**< Catch all events */
} pa_subscription_mask_t;
/** Subscription event types, as used by pa_context_subscribe() */
@@ -269,8 +344,8 @@ typedef enum pa_subscription_event_type {
PA_SUBSCRIPTION_EVENT_MODULE = 4, /**< Event type: Module */
PA_SUBSCRIPTION_EVENT_CLIENT = 5, /**< Event type: Client */
PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE = 6, /**< Event type: Sample cache item */
- PA_SUBSCRIPTION_EVENT_SERVER = 7, /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. \since 0.4 */
- PA_SUBSCRIPTION_EVENT_AUTOLOAD = 8, /**< Event type: Autoload table changes. \since 0.5 */
+ PA_SUBSCRIPTION_EVENT_SERVER = 7, /**< Event type: Global server change, only occuring with PA_SUBSCRIPTION_EVENT_CHANGE. */
+ PA_SUBSCRIPTION_EVENT_AUTOLOAD = 8, /**< Event type: Autoload table changes. */
PA_SUBSCRIPTION_EVENT_FACILITY_MASK = 15, /**< A mask to extract the event type from an event value */
PA_SUBSCRIPTION_EVENT_NEW = 0, /**< A new object was created */
@@ -297,7 +372,9 @@ typedef enum pa_subscription_event_type {
* source_usec+buffer_usec+transport_usec-sink_usec. (Take care of
* sign issues!) When connected to a monitor source sink_usec contains
* the latency of the owning sink. The two latency estimations
- * described here are implemented in pa_stream_get_latency().*/
+ * described here are implemented in pa_stream_get_latency(). Please
+ * note that this structure can be extended as part of evolutionary
+ * API updates at any time in any new release.*/
typedef struct pa_timing_info {
struct timeval timestamp; /**< The time when this timing info structure was current */
int synchronized_clocks; /**< Non-zero if the local and the
@@ -306,14 +383,21 @@ typedef struct pa_timing_info {
* detected transport_usec becomes much
* more reliable. However, the code that
* detects synchronized clocks is very
- * limited und unreliable itself. \since
- * 0.5 */
+ * limited und unreliable itself. */
pa_usec_t sink_usec; /**< Time in usecs a sample takes to be played on the sink. For playback streams and record streams connected to a monitor source. */
- pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. \since 0.5*/
- pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. \since 0.5 */
-
- int playing; /**< Non-zero when the stream is currently playing. Only for playback streams. */
+ pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. */
+ pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. */
+
+ int playing; /**< Non-zero when the stream is
+ * currently not underrun and data is
+ * being passed on to the device. Only
+ * for playback streams. This field does
+ * not say whether the data is actually
+ * already being played. To determine
+ * this check whether since_underrun
+ * (converted to usec) is larger than
+ * sink_usec.*/
int write_index_corrupt; /**< Non-zero if write_index is not
* up-to-date because a local write
@@ -322,20 +406,19 @@ typedef struct pa_timing_info {
* info was current . Only write
* commands with SEEK_RELATIVE_ON_READ
* and SEEK_RELATIVE_END can corrupt
- * write_index. \since 0.8 */
+ * write_index. */
int64_t write_index; /**< Current write index into the
* playback buffer in bytes. Think twice before
* using this for seeking purposes: it
* might be out of date a the time you
* want to use it. Consider using
- * PA_SEEK_RELATIVE instead. \since
- * 0.8 */
+ * PA_SEEK_RELATIVE instead. */
int read_index_corrupt; /**< Non-zero if read_index is not
* up-to-date because a local pause or
* flush request that corrupted it has
* been issued in the time since this
- * latency info was current. \since 0.8 */
+ * latency info was current. */
int64_t read_index; /**< Current read index into the
* playback buffer in bytes. Think twice before
@@ -343,7 +426,20 @@ typedef struct pa_timing_info {
* might be out of date a the time you
* want to use it. Consider using
* PA_SEEK_RELATIVE_ON_READ
- * instead. \since 0.8 */
+ * instead. */
+
+ pa_usec_t configured_sink_usec; /**< The static configured latency for
+ * the sink. \since 0.9.11 */
+ pa_usec_t configured_source_usec; /**< The static configured latency for
+ * the source. \since 0.9.11 */
+
+ int64_t since_underrun; /**< Bytes that were handed to the sink
+ since the last underrun happened, or
+ since playback started again after
+ the last underrun. playing will tell
+ you which case it is. \since
+ 0.9.11 */
+
} pa_timing_info;
/** A structure for the spawn api. This may be used to integrate auto
@@ -352,7 +448,7 @@ typedef struct pa_timing_info {
* waitpid() is used on the child's PID. The spawn routine will not
* block or ignore SIGCHLD signals, since this cannot be done in a
* thread compatible way. You might have to do this in
- * prefork/postfork. \since 0.4 */
+ * prefork/postfork. */
typedef struct pa_spawn_api {
void (*prefork)(void); /**< Is called just before the fork in the parent process. May be NULL. */
void (*postfork)(void); /**< Is called immediately after the fork in the parent process. May be NULL.*/
@@ -365,7 +461,7 @@ typedef struct pa_spawn_api {
* passed to the new process. */
} pa_spawn_api;
-/** Seek type for pa_stream_write(). \since 0.8*/
+/** Seek type for pa_stream_write(). */
typedef enum pa_seek_mode {
PA_SEEK_RELATIVE = 0, /**< Seek relatively to the write index */
PA_SEEK_ABSOLUTE = 1, /**< Seek relatively to the start of the buffer queue */
@@ -373,20 +469,24 @@ typedef enum pa_seek_mode {
PA_SEEK_RELATIVE_END = 3 /**< Seek relatively to the current end of the buffer queue. */
} pa_seek_mode_t;
-/** Special sink flags. \since 0.8 */
+/** Special sink flags. */
typedef enum pa_sink_flags {
PA_SINK_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */
PA_SINK_LATENCY = 2, /**< Supports latency querying */
PA_SINK_HARDWARE = 4, /**< Is a hardware sink of some kind, in contrast to "virtual"/software sinks \since 0.9.3 */
- PA_SINK_NETWORK = 8 /**< Is a networked sink of some kind. \since 0.9.7 */
+ PA_SINK_NETWORK = 8, /**< Is a networked sink of some kind. \since 0.9.7 */
+ PA_SINK_HW_MUTE_CTRL = 16, /**< Supports hardware mute control \since 0.9.11 */
+ PA_SINK_DECIBEL_VOLUME = 32 /**< Volume can be translated to dB with pa_sw_volume_to_dB() \since 0.9.11 */
} pa_sink_flags_t;
-/** Special source flags. \since 0.8 */
+/** Special source flags. */
typedef enum pa_source_flags {
PA_SOURCE_HW_VOLUME_CTRL = 1, /**< Supports hardware volume control */
PA_SOURCE_LATENCY = 2, /**< Supports latency querying */
PA_SOURCE_HARDWARE = 4, /**< Is a hardware source of some kind, in contrast to "virtual"/software source \since 0.9.3 */
- PA_SOURCE_NETWORK = 8 /**< Is a networked sink of some kind. \since 0.9.7 */
+ PA_SOURCE_NETWORK = 8, /**< Is a networked sink of some kind. \since 0.9.7 */
+ PA_SOURCE_HW_MUTE_CTRL = 16, /**< Supports hardware mute control \since 0.9.11 */
+ PA_SOURCE_DECIBEL_VOLUME = 32 /**< Volume can be translated to dB with pa_sw_volume_to_dB() \since 0.9.11 */
} pa_source_flags_t;
/** A generic free() like callback prototype */
diff --git a/src/pulse/gccmacro.h b/src/pulse/gccmacro.h
new file mode 100644
index 00000000..032c3bae
--- /dev/null
+++ b/src/pulse/gccmacro.h
@@ -0,0 +1,98 @@
+#ifndef foopulsegccmacrohfoo
+#define foopulsegccmacrohfoo
+
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2006 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 __GNUC__
+#define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
+#else
+/** If we're in GNU C, use some magic for detecting invalid format strings */
+#define PA_GCC_PRINTF_ATTR(a,b)
+#endif
+
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define PA_GCC_SENTINEL __attribute__ ((sentinel))
+#else
+/** Macro for usage of GCC's sentinel compilation warnings */
+#define PA_GCC_SENTINEL
+#endif
+
+#ifdef __GNUC__
+#define PA_GCC_NORETURN __attribute__((noreturn))
+#else
+/** Macro for no-return functions */
+#define PA_GCC_NORETURN
+#endif
+
+#ifdef __GNUC__
+#define PA_GCC_UNUSED __attribute__ ((unused))
+#else
+/** Macro for not used parameter */
+#define PA_GCC_UNUSED
+#endif
+
+#ifdef __GNUC__
+#define PA_GCC_DESTRUCTOR __attribute__ ((destructor))
+#else
+/** Call this function when process terminates */
+#define PA_GCC_DESTRUCTOR
+#endif
+
+#ifndef PA_GCC_PURE
+#ifdef __GNUC__
+#define PA_GCC_PURE __attribute__ ((pure))
+#else
+/** This function's return value depends only the arguments list and global state **/
+#define PA_GCC_PURE
+#endif
+#endif
+
+#ifndef PA_GCC_CONST
+#ifdef __GNUC__
+#define PA_GCC_CONST __attribute__ ((const))
+#else
+/** This function's return value depends only the arguments list (stricter version of PA_GCC_PURE) **/
+#define PA_GCC_CONST
+#endif
+#endif
+
+#ifndef PA_GCC_DEPRECATED
+#ifdef __GNUC__
+#define PA_GCC_DEPRECATED __attribute__ ((deprecated))
+#else
+/** This function is deprecated **/
+#define PA_GCC_DEPRECATED
+#endif
+#endif
+
+#ifndef PA_GCC_PACKED
+#ifdef __GNUCC__
+#define PA_GCC_PACKED __attribute__ ((packed))
+#else
+/** Structure shall be packed in memory **/
+#define PA_GCC_PACKED
+#endif
+#endif
+
+#endif
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index 873f1363..d346e945 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -42,6 +42,7 @@
#include <pulsecore/memblockq.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/refcnt.h>
+#include <pulsecore/time-smoother.h>
#include "client-conf.h"
@@ -50,7 +51,7 @@
struct pa_context {
PA_REFCNT_DECLARE;
- char *name;
+ pa_proplist *proplist;
pa_mainloop_api* mainloop;
pa_socket_client *client;
@@ -69,14 +70,13 @@ struct pa_context {
pa_context_notify_cb_t state_callback;
void *state_userdata;
-
pa_context_subscribe_cb_t subscribe_callback;
void *subscribe_userdata;
pa_mempool *mempool;
- int is_local;
- int do_autospawn;
+ pa_bool_t is_local;
+ pa_bool_t do_autospawn;
int autospawn_lock_fd;
pa_spawn_api spawn_api;
@@ -85,38 +85,43 @@ struct pa_context {
char *server;
pa_client_conf *conf;
+
+ uint32_t client_index;
};
-#define PA_MAX_WRITE_INDEX_CORRECTIONS 10
+#define PA_MAX_WRITE_INDEX_CORRECTIONS 32
typedef struct pa_index_correction {
uint32_t tag;
- int valid;
int64_t value;
- int absolute, corrupt;
+ pa_bool_t valid:1;
+ pa_bool_t absolute:1;
+ pa_bool_t corrupt:1;
} pa_index_correction;
struct pa_stream {
PA_REFCNT_DECLARE;
+ PA_LLIST_FIELDS(pa_stream);
+
pa_context *context;
pa_mainloop_api *mainloop;
- PA_LLIST_FIELDS(pa_stream);
- char *name;
- pa_bool_t manual_buffer_attr;
- pa_buffer_attr buffer_attr;
+ pa_stream_direction_t direction;
+ pa_stream_state_t state;
+ pa_stream_flags_t flags;
+
pa_sample_spec sample_spec;
pa_channel_map channel_map;
- pa_stream_flags_t flags;
+
+ pa_proplist *proplist;
+
uint32_t channel;
+ pa_bool_t channel_valid;
uint32_t syncid;
- int channel_valid;
uint32_t stream_index;
- pa_stream_direction_t direction;
- pa_stream_state_t state;
- pa_bool_t buffer_attr_not_ready, timing_info_not_ready;
uint32_t requested_bytes;
+ pa_buffer_attr buffer_attr;
uint32_t device_index;
char *device_name;
@@ -126,11 +131,11 @@ struct pa_stream {
void *peek_data;
pa_memblockq *record_memblockq;
- int corked;
+ pa_bool_t corked;
/* Store latest latency info */
pa_timing_info timing_info;
- int timing_info_valid;
+ pa_bool_t timing_info_valid;
/* Use to make sure that time advances monotonically */
pa_usec_t previous_time;
@@ -145,10 +150,9 @@ struct pa_stream {
/* Latency interpolation stuff */
pa_time_event *auto_timing_update_event;
- int auto_timing_update_requested;
+ pa_bool_t auto_timing_update_requested;
- pa_usec_t cached_time;
- int cached_time_valid;
+ pa_smoother *smoother;
/* Callbacks */
pa_stream_notify_cb_t state_callback;
@@ -167,6 +171,8 @@ struct pa_stream {
void *moved_userdata;
pa_stream_notify_cb_t suspended_callback;
void *suspended_userdata;
+ pa_stream_notify_cb_t started_callback;
+ void *started_userdata;
};
typedef void (*pa_operation_cb_t)(void);
@@ -192,7 +198,7 @@ void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag
void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, 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);
void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
-
+void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t callback, void *userdata);
void pa_operation_done(pa_operation *o);
@@ -204,7 +210,7 @@ void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t
void pa_context_fail(pa_context *c, int error);
int pa_context_set_error(pa_context *c, int error);
void pa_context_set_state(pa_context *c, pa_context_state_t st);
-int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t);
+int pa_context_handle_error(pa_context *c, uint32_t command, pa_tagstruct *t, pa_bool_t fail);
pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, void (*internal_callback)(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata), void (*cb)(void), void *userdata);
void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
@@ -226,5 +232,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_init_proplist(pa_proplist *p);
#endif
diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index 6610a724..857e82b4 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -27,8 +27,8 @@
#endif
#include <pulse/context.h>
+#include <pulse/gccmacro.h>
-#include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include <pulsecore/pstream-util.h>
@@ -52,7 +52,7 @@ static void context_stat_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNU
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
p = NULL;
@@ -95,7 +95,7 @@ static void context_get_server_info_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
p = NULL;
@@ -140,7 +140,7 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, P
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -149,7 +149,10 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, P
while (!pa_tagstruct_eof(t)) {
pa_sink_info i;
+ pa_bool_t mute = FALSE;
+
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -158,23 +161,30 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, P
pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
- pa_tagstruct_get_boolean(t, &i.mute) < 0 ||
+ pa_tagstruct_get_boolean(t, &mute) < 0 ||
pa_tagstruct_getu32(t, &i.monitor_source) < 0 ||
pa_tagstruct_gets(t, &i.monitor_source_name) < 0 ||
pa_tagstruct_get_usec(t, &i.latency) < 0 ||
pa_tagstruct_gets(t, &i.driver) < 0 ||
- pa_tagstruct_getu32(t, &flags) < 0) {
+ pa_tagstruct_getu32(t, &flags) < 0 ||
+ (o->context->version >= 13 &&
+ (pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
+ pa_tagstruct_get_usec(t, &i.configured_latency) < 0))) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_proplist_free(i.proplist);
goto finish;
}
+ i.mute = (int) mute;
i.flags = (pa_sink_flags_t) flags;
if (o->callback) {
pa_sink_info_cb_t cb = (pa_sink_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -251,7 +261,7 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -260,7 +270,10 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
while (!pa_tagstruct_eof(t)) {
pa_source_info i;
uint32_t flags;
+ pa_bool_t mute = FALSE;
+
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -269,23 +282,30 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
- pa_tagstruct_get_boolean(t, &i.mute) < 0 ||
+ pa_tagstruct_get_boolean(t, &mute) < 0 ||
pa_tagstruct_getu32(t, &i.monitor_of_sink) < 0 ||
pa_tagstruct_gets(t, &i.monitor_of_sink_name) < 0 ||
pa_tagstruct_get_usec(t, &i.latency) < 0 ||
pa_tagstruct_gets(t, &i.driver) < 0 ||
- pa_tagstruct_getu32(t, &flags) < 0) {
+ pa_tagstruct_getu32(t, &flags) < 0 ||
+ (o->context->version >= 13 &&
+ (pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
+ pa_tagstruct_get_usec(t, &i.configured_latency) < 0))) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_proplist_free(i.proplist);
goto finish;
}
+ i.mute = (int) mute;
i.flags = (pa_source_flags_t) flags;
if (o->callback) {
pa_source_info_cb_t cb = (pa_source_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -362,7 +382,7 @@ static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -370,13 +390,18 @@ static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command,
while (!pa_tagstruct_eof(t)) {
pa_client_info i;
+
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
- pa_tagstruct_gets(t, &i.driver) < 0 ) {
+ pa_tagstruct_gets(t, &i.driver) < 0 ||
+ (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
+
pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_proplist_free(i.proplist);
goto finish;
}
@@ -384,6 +409,8 @@ static void context_get_client_info_callback(pa_pdispatch *pd, uint32_t command,
pa_client_info_cb_t cb = (pa_client_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -437,7 +464,7 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -445,17 +472,20 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command,
while (!pa_tagstruct_eof(t)) {
pa_module_info i;
+ pa_bool_t auto_unload = FALSE;
memset(&i, 0, sizeof(i));
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
pa_tagstruct_gets(t, &i.argument) < 0 ||
pa_tagstruct_getu32(t, &i.n_used) < 0 ||
- pa_tagstruct_get_boolean(t, &i.auto_unload) < 0) {
+ pa_tagstruct_get_boolean(t, &auto_unload) < 0) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
goto finish;
}
+ i.auto_unload = (int) auto_unload;
+
if (o->callback) {
pa_module_info_cb_t cb = (pa_module_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
@@ -513,7 +543,7 @@ static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t comm
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -521,7 +551,10 @@ static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t comm
while (!pa_tagstruct_eof(t)) {
pa_sink_input_info i;
+ pa_bool_t mute = FALSE;
+
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -535,16 +568,22 @@ static void context_get_sink_input_info_callback(pa_pdispatch *pd, uint32_t comm
pa_tagstruct_get_usec(t, &i.sink_usec) < 0 ||
pa_tagstruct_gets(t, &i.resample_method) < 0 ||
pa_tagstruct_gets(t, &i.driver) < 0 ||
- (o->context->version >= 11 && pa_tagstruct_get_boolean(t, &i.mute) < 0)) {
+ (o->context->version >= 11 && pa_tagstruct_get_boolean(t, &mute) < 0) ||
+ (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_proplist_free(i.proplist);
goto finish;
}
+ i.mute = (int) mute;
+
if (o->callback) {
pa_sink_input_info_cb_t cb = (pa_sink_input_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -598,7 +637,7 @@ static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t c
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -608,6 +647,7 @@ static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t c
pa_source_output_info i;
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -619,9 +659,11 @@ static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t c
pa_tagstruct_get_usec(t, &i.buffer_usec) < 0 ||
pa_tagstruct_get_usec(t, &i.source_usec) < 0 ||
pa_tagstruct_gets(t, &i.resample_method) < 0 ||
- pa_tagstruct_gets(t, &i.driver) < 0) {
+ pa_tagstruct_gets(t, &i.driver) < 0 ||
+ (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ pa_proplist_free(i.proplist);
goto finish;
}
@@ -629,6 +671,8 @@ static void context_get_source_output_info_callback(pa_pdispatch *pd, uint32_t c
pa_source_output_info_cb_t cb = (pa_source_output_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -923,7 +967,7 @@ static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -931,8 +975,10 @@ static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command,
while (!pa_tagstruct_eof(t)) {
pa_sample_info i;
+ pa_bool_t lazy = FALSE;
memset(&i, 0, sizeof(i));
+ i.proplist = pa_proplist_new();
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
pa_tagstruct_gets(t, &i.name) < 0 ||
@@ -941,17 +987,22 @@ static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command,
pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
pa_tagstruct_getu32(t, &i.bytes) < 0 ||
- pa_tagstruct_get_boolean(t, &i.lazy) < 0 ||
- pa_tagstruct_gets(t, &i.filename) < 0) {
+ pa_tagstruct_get_boolean(t, &lazy) < 0 ||
+ pa_tagstruct_gets(t, &i.filename) < 0 ||
+ (o->context->version >= 13 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) {
pa_context_fail(o->context, PA_ERR_PROTOCOL);
goto finish;
}
+ i.lazy = (int) lazy;
+
if (o->callback) {
pa_sample_info_cb_t cb = (pa_sample_info_cb_t) o->callback;
cb(o->context, &i, 0, o->userdata);
}
+
+ pa_proplist_free(i.proplist);
}
}
@@ -1060,7 +1111,7 @@ static void context_index_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UN
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
idx = PA_INVALID_INDEX;
@@ -1121,7 +1172,7 @@ static void context_get_autoload_info_callback(pa_pdispatch *pd, uint32_t comman
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
eol = -1;
@@ -1158,6 +1209,8 @@ finish:
pa_operation_unref(o);
}
+PA_WARN_REFERENCE(pa_context_get_autoload_info_by_name, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_get_autoload_info_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_autoload_info_cb_t cb, void *userdata) {
pa_tagstruct *t;
pa_operation *o;
@@ -1182,6 +1235,8 @@ pa_operation* pa_context_get_autoload_info_by_name(pa_context *c, const char *na
return o;
}
+PA_WARN_REFERENCE(pa_context_get_autoload_info_by_index, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_get_autoload_info_by_index(pa_context *c, uint32_t idx, pa_autoload_info_cb_t cb, void *userdata) {
pa_tagstruct *t;
pa_operation *o;
@@ -1204,10 +1259,15 @@ pa_operation* pa_context_get_autoload_info_by_index(pa_context *c, uint32_t idx,
return o;
}
+
+PA_WARN_REFERENCE(pa_context_get_autoload_info_list, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_get_autoload_info_list(pa_context *c, pa_autoload_info_cb_t cb, void *userdata) {
return pa_context_send_simple_command(c, PA_COMMAND_GET_AUTOLOAD_INFO_LIST, context_get_autoload_info_callback, (pa_operation_cb_t) cb, userdata);
}
+PA_WARN_REFERENCE(pa_context_add_autoload, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_add_autoload(pa_context *c, const char *name, pa_autoload_type_t type, const char *module, const char*argument, pa_context_index_cb_t cb, void* userdata) {
pa_operation *o;
pa_tagstruct *t;
@@ -1234,6 +1294,8 @@ pa_operation* pa_context_add_autoload(pa_context *c, const char *name, pa_autolo
return o;
}
+PA_WARN_REFERENCE(pa_context_remove_autoload_by_name, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_remove_autoload_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_context_success_cb_t cb, void* userdata) {
pa_operation *o;
pa_tagstruct *t;
@@ -1257,6 +1319,8 @@ pa_operation* pa_context_remove_autoload_by_name(pa_context *c, const char *name
return o;
}
+PA_WARN_REFERENCE(pa_context_remove_autoload_by_index, "Autoload will no longer be implemented by future versions of the PulseAudio server.");
+
pa_operation* pa_context_remove_autoload_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void* userdata) {
pa_operation *o;
pa_tagstruct *t;
diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
index c148ee5e..d185a3a6 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -30,8 +30,10 @@
#include <pulse/operation.h>
#include <pulse/context.h>
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
#include <pulse/channelmap.h>
#include <pulse/volume.h>
+#include <pulse/proplist.h>
/** \page introspect Server Query and Control
*
@@ -206,21 +208,32 @@
PA_C_DECL_BEGIN
-/** Stores information about sinks */
+#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
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_sink_info {
const char *name; /**< Name of the sink */
uint32_t index; /**< Index of the sink */
const char *description; /**< Description of this sink */
pa_sample_spec sample_spec; /**< Sample spec of this sink */
- pa_channel_map channel_map; /**< Channel map \since 0.8 */
+ pa_channel_map channel_map; /**< Channel map */
uint32_t owner_module; /**< Index of the owning module of this sink, or PA_INVALID_INDEX */
pa_cvolume volume; /**< Volume of the sink */
- int mute; /**< Mute switch of the sink \since 0.8 */
+ int mute; /**< Mute switch of the sink */
uint32_t monitor_source; /**< Index of the monitor source connected to this sink */
const char *monitor_source_name; /**< The name of the monitor source */
- pa_usec_t latency; /**< Length of filled playback buffer of this sink */
- const char *driver; /**< Driver name. \since 0.8 */
- pa_sink_flags_t flags; /**< Flags \since 0.8 */
+ pa_usec_t latency; /**< Length of queued audio in the output buffer. */
+ const char *driver; /**< Driver name. */
+ pa_sink_flags_t flags; /**< Flags */
+ pa_proplist *proplist; /**< Property list \since 0.9.11 */
+ pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */
} pa_sink_info;
/** Callback prototype for pa_context_get_sink_info_by_name() and friends */
@@ -235,21 +248,47 @@ pa_operation* pa_context_get_sink_info_by_index(pa_context *c, uint32_t id, pa_s
/** Get the complete sink list */
pa_operation* pa_context_get_sink_info_list(pa_context *c, pa_sink_info_cb_t cb, void *userdata);
-/** Stores information about sources */
+/** Set the volume of a sink device specified by its index */
+pa_operation* pa_context_set_sink_volume_by_index(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the volume of a sink device specified by its name */
+pa_operation* pa_context_set_sink_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a sink device specified by its index */
+pa_operation* pa_context_set_sink_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a sink device specified by its name */
+pa_operation* pa_context_set_sink_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Suspend/Resume a sink. \since 0.9.7 */
+pa_operation* pa_context_suspend_sink_by_name(pa_context *c, char *sink_name, int suspend, pa_context_success_cb_t cb, void* userdata);
+
+/** Suspend/Resume a sink. If idx is PA_INVALID_INDEX all sinks will be suspended. \since 0.9.7 */
+pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata);
+
+/** @} */
+
+/** @{ \name Sources */
+
+/** Stores information about sources. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_source_info {
- const char *name ; /**< Name of the source */
+ const char *name; /**< Name of the source */
uint32_t index; /**< Index of the source */
const char *description; /**< Description of this source */
pa_sample_spec sample_spec; /**< Sample spec of this source */
- pa_channel_map channel_map; /**< Channel map \since 0.8 */
+ pa_channel_map channel_map; /**< Channel map */
uint32_t owner_module; /**< Owning module index, or PA_INVALID_INDEX */
- pa_cvolume volume; /**< Volume of the source \since 0.8 */
- int mute; /**< Mute switch of the sink \since 0.8 */
+ pa_cvolume volume; /**< Volume of the source */
+ int mute; /**< Mute switch of the sink */
uint32_t monitor_of_sink; /**< If this is a monitor source the index of the owning sink, otherwise PA_INVALID_INDEX */
const char *monitor_of_sink_name; /**< Name of the owning sink, or PA_INVALID_INDEX */
- pa_usec_t latency; /**< Length of filled record buffer of this source. \since 0.5 */
- const char *driver; /**< Driver name \since 0.8 */
- pa_source_flags_t flags; /**< Flags \since 0.8 */
+ pa_usec_t latency; /**< Length of filled record buffer of this source. */
+ const char *driver; /**< Driver name */
+ pa_source_flags_t flags; /**< Flags */
+ pa_proplist *proplist; /**< Property list \since 0.9.11 */
+ pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */
} pa_source_info;
/** Callback prototype for pa_context_get_source_info_by_name() and friends */
@@ -264,16 +303,34 @@ pa_operation* pa_context_get_source_info_by_index(pa_context *c, uint32_t id, pa
/** Get the complete source list */
pa_operation* pa_context_get_source_info_list(pa_context *c, pa_source_info_cb_t cb, void *userdata);
-/** Server information */
+/** Set the volume of a source device specified by its index */
+pa_operation* pa_context_set_source_volume_by_index(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the volume of a source device specified by its name */
+pa_operation* pa_context_set_source_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a source device specified by its index */
+pa_operation* pa_context_set_source_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a source device specified by its name */
+pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** @} */
+
+/** @{ \name Server */
+
+/** Server information. Please note that this structure can be
+ * extended as part of evolutionary API updates at any time in any new
+ * release. */
typedef struct pa_server_info {
const char *user_name; /**< User name of the daemon process */
const char *host_name; /**< Host name the daemon is running on */
const char *server_version; /**< Version string of the daemon */
const char *server_name; /**< Server package name (usually "pulseaudio") */
pa_sample_spec sample_spec; /**< Default sample specification */
- const char *default_sink_name; /**< Name of default sink. \since 0.4 */
- const char *default_source_name; /**< Name of default sink. \since 0.4*/
- uint32_t cookie; /**< A random cookie for identifying this instance of PulseAudio. \since 0.8 */
+ const char *default_sink_name; /**< Name of default sink. */
+ const char *default_source_name; /**< Name of default sink. */
+ uint32_t cookie; /**< A random cookie for identifying this instance of PulseAudio. */
} pa_server_info;
/** Callback prototype for pa_context_get_server_info() */
@@ -282,7 +339,13 @@ typedef void (*pa_server_info_cb_t) (pa_context *c, const pa_server_info*i, void
/** Get some information about the server */
pa_operation* pa_context_get_server_info(pa_context *c, pa_server_info_cb_t cb, void *userdata);
-/** Stores information about modules */
+/** @} */
+
+/** @{ \name Modules */
+
+/** Stores information about modules. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_module_info {
uint32_t index; /**< Index of the module */
const char*name, /**< Name of the module */
@@ -300,12 +363,28 @@ pa_operation* pa_context_get_module_info(pa_context *c, uint32_t idx, pa_module_
/** Get the complete list of currently loaded modules */
pa_operation* pa_context_get_module_info_list(pa_context *c, pa_module_info_cb_t cb, void *userdata);
-/** Stores information about clients */
+/** Callback prototype for pa_context_load_module() */
+typedef void (*pa_context_index_cb_t)(pa_context *c, uint32_t idx, void *userdata);
+
+/** Load a module. */
+pa_operation* pa_context_load_module(pa_context *c, const char*name, const char *argument, pa_context_index_cb_t cb, void *userdata);
+
+/** Unload a module. */
+pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+
+/** @} */
+
+/** @{ \name Clients */
+
+/** Stores information about clients. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_client_info {
uint32_t index; /**< Index of this client */
const char *name; /**< Name of this client */
uint32_t owner_module; /**< Index of the owning module, or PA_INVALID_INDEX */
- const char *driver; /**< Driver name \since 0.8 */
+ const char *driver; /**< Driver name */
+ pa_proplist *proplist; /**< Property list \since 0.9.11 */
} pa_client_info;
/** Callback prototype for pa_context_get_client_info() and firends*/
@@ -317,7 +396,16 @@ pa_operation* pa_context_get_client_info(pa_context *c, uint32_t idx, pa_client_
/** Get the complete client list */
pa_operation* pa_context_get_client_info_list(pa_context *c, pa_client_info_cb_t cb, void *userdata);
-/** Stores information about sink inputs */
+/** Kill a client. */
+pa_operation* pa_context_kill_client(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+
+/** @} */
+
+/** @{ \name Sink Inputs */
+
+/** Stores information about sink inputs. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_sink_input_info {
uint32_t index; /**< Index of the sink input */
const char *name; /**< Name of the sink input */
@@ -329,9 +417,10 @@ typedef struct pa_sink_input_info {
pa_cvolume volume; /**< The volume of this sink input */
pa_usec_t buffer_usec; /**< Latency due to buffering in sink input, see pa_latency_info for details */
pa_usec_t sink_usec; /**< Latency of the sink device, see pa_latency_info for details */
- const char *resample_method; /**< Thre resampling method used by this sink input. \since 0.7 */
- const char *driver; /**< Driver name \since 0.8 */
+ const char *resample_method; /**< Thre resampling method used by this sink input. */
+ const char *driver; /**< Driver name */
int mute; /**< Stream muted \since 0.9.7 */
+ pa_proplist *proplist; /**< Property list \since 0.9.11 */
} pa_sink_input_info;
/** Callback prototype for pa_context_get_sink_input_info() and firends*/
@@ -343,7 +432,28 @@ pa_operation* pa_context_get_sink_input_info(pa_context *c, uint32_t idx, pa_sin
/** Get the complete sink input list */
pa_operation* pa_context_get_sink_input_info_list(pa_context *c, pa_sink_input_info_cb_t cb, void *userdata);
-/** Stores information about source outputs */
+/** Move the specified sink input to a different sink. \since 0.9.5 */
+pa_operation* pa_context_move_sink_input_by_name(pa_context *c, uint32_t idx, char *sink_name, pa_context_success_cb_t cb, void* userdata);
+
+/** Move the specified sink input to a different sink. \since 0.9.5 */
+pa_operation* pa_context_move_sink_input_by_index(pa_context *c, uint32_t idx, uint32_t sink_idx, pa_context_success_cb_t cb, void* userdata);
+
+/** Set the volume of a sink input stream */
+pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a sink input stream \since 0.9.7 */
+pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Kill a sink input. */
+pa_operation* pa_context_kill_sink_input(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+
+/** @} */
+
+/** @{ \name Source Outputs */
+
+/** Stores information about source outputs. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_source_output_info {
uint32_t index; /**< Index of the sink input */
const char *name; /**< Name of the sink input */
@@ -352,10 +462,11 @@ typedef struct pa_source_output_info {
uint32_t source; /**< Index of the connected source */
pa_sample_spec sample_spec; /**< The sample specification of the source output */
pa_channel_map channel_map; /**< Channel map */
- pa_usec_t buffer_usec; /**< Latency due to buffering in the source output, see pa_latency_info for details. \since 0.5 */
- pa_usec_t source_usec; /**< Latency of the source device, see pa_latency_info for details. \since 0.5 */
- const char *resample_method; /**< Thre resampling method used by this source output. \since 0.7 */
- const char *driver; /**< Driver name \since 0.8 */
+ pa_usec_t buffer_usec; /**< Latency due to buffering in the source output, see pa_latency_info for details. */
+ pa_usec_t source_usec; /**< Latency of the source device, see pa_latency_info for details. */
+ const char *resample_method; /**< Thre resampling method used by this source output. */
+ const char *driver; /**< Driver name */
+ pa_proplist *proplist; /**< Property list \since 0.9.11 */
} pa_source_output_info;
/** Callback prototype for pa_context_get_source_output_info() and firends*/
@@ -367,43 +478,34 @@ pa_operation* pa_context_get_source_output_info(pa_context *c, uint32_t idx, pa_
/** Get the complete list of source outputs */
pa_operation* pa_context_get_source_output_info_list(pa_context *c, pa_source_output_info_cb_t cb, void *userdata);
-/** Set the volume of a sink device specified by its index */
-pa_operation* pa_context_set_sink_volume_by_index(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
-
-/** Set the volume of a sink device specified by its name */
-pa_operation* pa_context_set_sink_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
-
-/** Set the mute switch of a sink device specified by its index \since 0.8 */
-pa_operation* pa_context_set_sink_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
-
-/** Set the mute switch of a sink device specified by its name \since 0.8 */
-pa_operation* pa_context_set_sink_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
+/** Move the specified source output to a different source. \since 0.9.5 */
+pa_operation* pa_context_move_source_output_by_name(pa_context *c, uint32_t idx, char *source_name, pa_context_success_cb_t cb, void* userdata);
-/** Set the volume of a sink input stream */
-pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+/** Move the specified source output to a different source. \since 0.9.5 */
+pa_operation* pa_context_move_source_output_by_index(pa_context *c, uint32_t idx, uint32_t source_idx, pa_context_success_cb_t cb, void* userdata);
-/** Set the mute switch of a sink input stream \since 0.9.7 */
-pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+/** Suspend/Resume a source. \since 0.9.7 */
+pa_operation* pa_context_suspend_source_by_name(pa_context *c, char *source_name, int suspend, pa_context_success_cb_t cb, void* userdata);
-/** Set the volume of a source device specified by its index \since 0.8 */
-pa_operation* pa_context_set_source_volume_by_index(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+/** Suspend/Resume a source. If idx is PA_INVALID_INDEX all sources will be suspended. \since 0.9.7 */
+pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata);
-/** Set the volume of a source device specified by its name \since 0.8 */
-pa_operation* pa_context_set_source_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+/** Kill a source output. */
+pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
-/** Set the mute switch of a source device specified by its index \since 0.8 */
-pa_operation* pa_context_set_source_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+/** @} */
-/** Set the mute switch of a source device specified by its name \since 0.8 */
-pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
+/** @{ \name Statistics */
-/** Memory block statistics */
+/** Memory block statistics. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_stat_info {
uint32_t memblock_total; /**< Currently allocated memory blocks */
uint32_t memblock_total_size; /**< Currentl total size of allocated memory blocks */
uint32_t memblock_allocated; /**< Allocated memory blocks during the whole lifetime of the daemon */
uint32_t memblock_allocated_size; /**< Total size of all memory blocks allocated during the whole lifetime of the daemon */
- uint32_t scache_size; /**< Total size of all sample cache entries. \since 0.4 */
+ uint32_t scache_size; /**< Total size of all sample cache entries. */
} pa_stat_info;
/** Callback prototype for pa_context_stat() */
@@ -412,7 +514,13 @@ typedef void (*pa_stat_info_cb_t) (pa_context *c, const pa_stat_info *i, void *u
/** Get daemon memory block statistics */
pa_operation* pa_context_stat(pa_context *c, pa_stat_info_cb_t cb, void *userdata);
-/** Stores information about sample cache entries */
+/** @} */
+
+/** @{ \name Cached Samples */
+
+/** Stores information about sample cache entries. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_sample_info {
uint32_t index; /**< Index of this entry */
const char *name; /**< Name of this entry */
@@ -420,9 +528,10 @@ typedef struct pa_sample_info {
pa_sample_spec sample_spec; /**< Sample specification of the sample */
pa_channel_map channel_map; /**< The channel map */
pa_usec_t duration; /**< Duration of this entry */
- uint32_t bytes; /**< Length of this sample in bytes. \since 0.4 */
- int lazy; /**< Non-zero when this is a lazy cache entry. \since 0.5 */
- const char *filename; /**< In case this is a lazy cache entry, the filename for the sound file to be loaded on demand. \since 0.5 */
+ uint32_t bytes; /**< Length of this sample in bytes. */
+ int lazy; /**< Non-zero when this is a lazy cache entry. */
+ const char *filename; /**< In case this is a lazy cache entry, the filename for the sound file to be loaded on demand. */
+ pa_proplist *proplist; /**< Property list for this sample. \since 0.9.11 */
} pa_sample_info;
/** Callback prototype for pa_context_get_sample_info_by_name() and firends */
@@ -437,31 +546,21 @@ pa_operation* pa_context_get_sample_info_by_index(pa_context *c, uint32_t idx, p
/** Get the complete list of samples stored in the daemon. */
pa_operation* pa_context_get_sample_info_list(pa_context *c, pa_sample_info_cb_t cb, void *userdata);
-/** Kill a client. \since 0.5 */
-pa_operation* pa_context_kill_client(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+/** @} */
-/** Kill a sink input. \since 0.5 */
-pa_operation* pa_context_kill_sink_input(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+/** \cond fulldocs */
-/** Kill a source output. \since 0.5 */
-pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
-
-/** Callback prototype for pa_context_load_module() and pa_context_add_autoload() */
-typedef void (*pa_context_index_cb_t)(pa_context *c, uint32_t idx, void *userdata);
-
-/** Load a module. \since 0.5 */
-pa_operation* pa_context_load_module(pa_context *c, const char*name, const char *argument, pa_context_index_cb_t cb, void *userdata);
-
-/** Unload a module. \since 0.5 */
-pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata);
+/** @{ \name Autoload Entries */
-/** Type of an autoload entry. \since 0.5 */
+/** Type of an autoload entry. */
typedef enum pa_autoload_type {
PA_AUTOLOAD_SINK = 0,
PA_AUTOLOAD_SOURCE = 1
} pa_autoload_type_t;
-/** Stores information about autoload entries. \since 0.5 */
+/** Stores information about autoload entries. Please note that this structure
+ * can be extended as part of evolutionary API updates at any time in
+ * any new release. */
typedef struct pa_autoload_info {
uint32_t index; /**< Index of this autoload entry */
const char *name; /**< Name of the sink or source */
@@ -473,47 +572,27 @@ typedef struct pa_autoload_info {
/** Callback prototype for pa_context_get_autoload_info_by_name() and firends */
typedef void (*pa_autoload_info_cb_t)(pa_context *c, const pa_autoload_info *i, int eol, void *userdata);
-/** Get info about a specific autoload entry. \since 0.6 */
-pa_operation* pa_context_get_autoload_info_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_autoload_info_cb_t cb, void *userdata);
+/** Get info about a specific autoload entry. */
+pa_operation* pa_context_get_autoload_info_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_autoload_info_cb_t cb, void *userdata) PA_GCC_DEPRECATED;
-/** Get info about a specific autoload entry. \since 0.6 */
-pa_operation* pa_context_get_autoload_info_by_index(pa_context *c, uint32_t idx, pa_autoload_info_cb_t cb, void *userdata);
+/** Get info about a specific autoload entry. */
+pa_operation* pa_context_get_autoload_info_by_index(pa_context *c, uint32_t idx, pa_autoload_info_cb_t cb, void *userdata) PA_GCC_DEPRECATED;
-/** Get the complete list of autoload entries. \since 0.5 */
-pa_operation* pa_context_get_autoload_info_list(pa_context *c, pa_autoload_info_cb_t cb, void *userdata);
+/** Get the complete list of autoload entries. */
+pa_operation* pa_context_get_autoload_info_list(pa_context *c, pa_autoload_info_cb_t cb, void *userdata) PA_GCC_DEPRECATED;
-/** Add a new autoload entry. \since 0.5 */
-pa_operation* pa_context_add_autoload(pa_context *c, const char *name, pa_autoload_type_t type, const char *module, const char*argument, pa_context_index_cb_t, void* userdata);
+/** Add a new autoload entry. */
+pa_operation* pa_context_add_autoload(pa_context *c, const char *name, pa_autoload_type_t type, const char *module, const char*argument, pa_context_index_cb_t, void* userdata) PA_GCC_DEPRECATED;
-/** Remove an autoload entry. \since 0.6 */
-pa_operation* pa_context_remove_autoload_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_context_success_cb_t cb, void* userdata);
+/** Remove an autoload entry. */
+pa_operation* pa_context_remove_autoload_by_name(pa_context *c, const char *name, pa_autoload_type_t type, pa_context_success_cb_t cb, void* userdata) PA_GCC_DEPRECATED;
-/** Remove an autoload entry. \since 0.6 */
-pa_operation* pa_context_remove_autoload_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void* userdata);
+/** Remove an autoload entry. */
+pa_operation* pa_context_remove_autoload_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void* userdata) PA_GCC_DEPRECATED;
-/** Move the specified sink input to a different sink. \since 0.9.5 */
-pa_operation* pa_context_move_sink_input_by_name(pa_context *c, uint32_t idx, char *sink_name, pa_context_success_cb_t cb, void* userdata);
-
-/** Move the specified sink input to a different sink. \since 0.9.5 */
-pa_operation* pa_context_move_sink_input_by_index(pa_context *c, uint32_t idx, uint32_t sink_idx, pa_context_success_cb_t cb, void* userdata);
-
-/** Move the specified source output to a different source. \since 0.9.5 */
-pa_operation* pa_context_move_source_output_by_name(pa_context *c, uint32_t idx, char *source_name, pa_context_success_cb_t cb, void* userdata);
+/** @} */
-/** Move the specified source output to a different source. \since 0.9.5 */
-pa_operation* pa_context_move_source_output_by_index(pa_context *c, uint32_t idx, uint32_t source_idx, pa_context_success_cb_t cb, void* userdata);
-
-/** Suspend/Resume a sink. \since 0.9.7 */
-pa_operation* pa_context_suspend_sink_by_name(pa_context *c, char *sink_name, int suspend, pa_context_success_cb_t cb, void* userdata);
-
-/** Suspend/Resume a sink. If idx is PA_INVALID_INDEX all sinks will be suspended. \since 0.9.7 */
-pa_operation* pa_context_suspend_sink_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata);
-
-/** Suspend/Resume a source. \since 0.9.7 */
-pa_operation* pa_context_suspend_source_by_name(pa_context *c, char *source_name, int suspend, pa_context_success_cb_t cb, void* userdata);
-
-/** Suspend/Resume a source. If idx is PA_INVALID_INDEX all sources will be suspended. \since 0.9.7 */
-pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata);
+/** \endcond */
PA_C_DECL_END
diff --git a/src/pulse/mainloop-api.c b/src/pulse/mainloop-api.c
index b2ed3434..dda51297 100644
--- a/src/pulse/mainloop-api.c
+++ b/src/pulse/mainloop-api.c
@@ -28,8 +28,8 @@
#include <stdlib.h>
#include <pulse/xmalloc.h>
+#include <pulse/gccmacro.h>
-#include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include "mainloop-api.h"
@@ -75,4 +75,3 @@ void pa_mainloop_api_once(pa_mainloop_api* m, void (*callback)(pa_mainloop_api *
pa_assert_se(e = m->defer_new(m, once_callback, i));
m->defer_set_destroy(e, free_callback);
}
-
diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
index e41ed14c..91c6bf6d 100644
--- a/src/pulse/mainloop-signal.c
+++ b/src/pulse/mainloop-signal.c
@@ -3,7 +3,7 @@
/***
This file is part of PulseAudio.
- Copyright 2004-2006 Lennart Poettering
+ Copyright 2004-2008 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
@@ -39,11 +39,11 @@
#endif
#include <pulse/xmalloc.h>
+#include <pulse/gccmacro.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
-#include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include "mainloop-signal.h"
@@ -55,9 +55,9 @@ struct pa_signal_event {
#else
void (*saved_handler)(int sig);
#endif
- void (*callback) (pa_mainloop_api*a, pa_signal_event *e, int sig, void *userdata);
void *userdata;
- void (*destroy_callback) (pa_mainloop_api*a, pa_signal_event*e, void *userdata);
+ pa_signal_cb_t callback;
+ pa_signal_destroy_cb_t destroy_callback;
pa_signal_event *previous, *next;
};
@@ -74,6 +74,7 @@ static void signal_handler(int sig) {
#ifndef HAVE_SIGACTION
signal(sig, signal_handler);
#endif
+
pa_write(signal_pipe[1], &sig, sizeof(sig), NULL);
errno = saved_errno;
@@ -142,23 +143,21 @@ int pa_signal_init(pa_mainloop_api *a) {
}
void pa_signal_done(void) {
- pa_assert(api);
- pa_assert(signal_pipe[0] >= 0);
- pa_assert(signal_pipe[1] >= 0);
- pa_assert(io_event);
-
while (signals)
pa_signal_free(signals);
- api->io_free(io_event);
- io_event = NULL;
+ if (io_event) {
+ pa_assert(api);
+ api->io_free(io_event);
+ io_event = NULL;
+ }
pa_close_pipe(signal_pipe);
api = NULL;
}
-pa_signal_event* pa_signal_new(int sig, void (*_callback) (pa_mainloop_api *api, pa_signal_event*e, int sig, void *userdata), void *userdata) {
+pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t _callback, void *userdata) {
pa_signal_event *e = NULL;
#ifdef HAVE_SIGACTION
@@ -223,7 +222,7 @@ void pa_signal_free(pa_signal_event *e) {
pa_xfree(e);
}
-void pa_signal_set_destroy(pa_signal_event *e, void (*_callback) (pa_mainloop_api *api, pa_signal_event*e, void *userdata)) {
+void pa_signal_set_destroy(pa_signal_event *e, pa_signal_destroy_cb_t _callback) {
pa_assert(e);
e->destroy_callback = _callback;
diff --git a/src/pulse/mainloop-signal.h b/src/pulse/mainloop-signal.h
index 50aa99ce..bdb0f738 100644
--- a/src/pulse/mainloop-signal.h
+++ b/src/pulse/mainloop-signal.h
@@ -6,7 +6,7 @@
/***
This file is part of PulseAudio.
- Copyright 2004-2006 Lennart Poettering
+ Copyright 2004-2008 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
@@ -39,23 +39,27 @@ PA_C_DECL_BEGIN
* signals. However, you may hook signal support into an abstract main loop via the routines defined herein.
*/
+/** An opaque UNIX signal event source object */
+typedef struct pa_signal_event pa_signal_event;
+
+typedef void (*pa_signal_cb_t) (pa_mainloop_api *api, pa_signal_event*e, int sig, void *userdata);
+
+typedef void (*pa_signal_destroy_cb_t) (pa_mainloop_api *api, pa_signal_event*e, void *userdata);
+
/** Initialize the UNIX signal subsystem and bind it to the specified main loop */
int pa_signal_init(pa_mainloop_api *api);
/** Cleanup the signal subsystem */
void pa_signal_done(void);
-/** An opaque UNIX signal event source object */
-typedef struct pa_signal_event pa_signal_event;
-
/** Create a new UNIX signal event source object */
-pa_signal_event* pa_signal_new(int sig, void (*callback) (pa_mainloop_api *api, pa_signal_event*e, int sig, void *userdata), void *userdata);
+pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t callback, void *userdata);
/** Free a UNIX signal event source object */
void pa_signal_free(pa_signal_event *e);
/** Set a function that is called when the signal event source is destroyed. Use this to free the userdata argument if required */
-void pa_signal_set_destroy(pa_signal_event *e, void (*callback) (pa_mainloop_api *api, pa_signal_event*e, void *userdata));
+void pa_signal_set_destroy(pa_signal_event *e, pa_signal_destroy_cb_t callback);
PA_C_DECL_END
diff --git a/src/pulse/operation.c b/src/pulse/operation.c
index 5d2da5b8..6b5c142a 100644
--- a/src/pulse/operation.c
+++ b/src/pulse/operation.c
@@ -77,6 +77,23 @@ void pa_operation_unref(pa_operation *o) {
}
}
+static void operation_unlink(pa_operation *o) {
+ pa_assert(o);
+
+ if (o->context) {
+ pa_assert(PA_REFCNT_VALUE(o) >= 2);
+
+ PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
+ pa_operation_unref(o);
+
+ o->context = NULL;
+ }
+
+ o->stream = NULL;
+ o->callback = NULL;
+ o->userdata = NULL;
+}
+
static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
@@ -88,20 +105,8 @@ static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
o->state = st;
- if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED)) {
-
- if (o->context) {
- pa_assert(PA_REFCNT_VALUE(o) >= 2);
-
- PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
- pa_operation_unref(o);
- }
-
- o->context = NULL;
- o->stream = NULL;
- o->callback = NULL;
- o->userdata = NULL;
- }
+ if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED))
+ operation_unlink(o);
pa_operation_unref(o);
}
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index c27c9d84..33bd274f 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -69,16 +69,14 @@ pa_proplist* pa_proplist_new(void) {
}
void pa_proplist_free(pa_proplist* p) {
- struct property *prop;
-
- while ((prop = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
- property_free(prop);
+ pa_assert(p);
+ pa_proplist_clear(p);
pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
}
/** Will accept only valid UTF-8 */
-int pa_proplist_puts(pa_proplist *p, const char *key, const char *value) {
+int pa_proplist_sets(pa_proplist *p, const char *key, const char *value) {
struct property *prop;
pa_bool_t add = FALSE;
@@ -104,7 +102,29 @@ int pa_proplist_puts(pa_proplist *p, const char *key, const char *value) {
return 0;
}
-int pa_proplist_put(pa_proplist *p, const char *key, const void *data, size_t nbytes) {
+/** Will accept only valid UTF-8 */
+int pa_proplist_setf(pa_proplist *p, const char *key, const char *format, ...) {
+ va_list ap;
+ int r;
+ char *t;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key) || !pa_utf8_valid(format))
+ return -1;
+
+ va_start(ap, format);
+ t = pa_vsprintf_malloc(format, ap);
+ va_end(ap);
+
+ r = pa_proplist_sets(p, key, t);
+
+ pa_xfree(t);
+ return r;
+}
+
+int pa_proplist_set(pa_proplist *p, const char *key, const void *data, size_t nbytes) {
struct property *prop;
pa_bool_t add = FALSE;
@@ -175,18 +195,27 @@ int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *
return 0;
}
-void pa_proplist_merge(pa_proplist *p, pa_proplist *other) {
+void pa_proplist_update(pa_proplist *p, pa_update_mode_t mode, pa_proplist *other) {
struct property *prop;
void *state = NULL;
pa_assert(p);
+ pa_assert(mode == PA_UPDATE_SET || mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE);
pa_assert(other);
- while ((prop = pa_hashmap_iterate(MAKE_HASHMAP(other), &state, NULL)))
- pa_assert_se(pa_proplist_put(p, prop->key, prop->value, prop->nbytes) == 0);
+ if (mode == PA_UPDATE_SET)
+ pa_proplist_clear(p);
+
+ while ((prop = pa_hashmap_iterate(MAKE_HASHMAP(other), &state, NULL))) {
+
+ if (mode == PA_UPDATE_MERGE && pa_proplist_contains(p, prop->key))
+ continue;
+
+ pa_assert_se(pa_proplist_set(p, prop->key, prop->value, prop->nbytes) == 0);
+ }
}
-int pa_proplist_remove(pa_proplist *p, const char *key) {
+int pa_proplist_unset(pa_proplist *p, const char *key) {
struct property *prop;
pa_assert(p);
@@ -196,12 +225,30 @@ int pa_proplist_remove(pa_proplist *p, const char *key) {
return -1;
if (!(prop = pa_hashmap_remove(MAKE_HASHMAP(p), key)))
- return -1;
+ return -2;
property_free(prop);
return 0;
}
+int pa_proplist_unset_many(pa_proplist *p, const char * const keys[]) {
+ const char * const * k;
+ int n = 0;
+
+ pa_assert(p);
+ pa_assert(keys);
+
+ for (k = keys; *k; k++)
+ if (!property_name_valid(*k))
+ return -1;
+
+ for (k = keys; *k; k++)
+ if (pa_proplist_unset(p, *k) >= 0)
+ n++;
+
+ return n;
+}
+
const char *pa_proplist_iterate(pa_proplist *p, void **state) {
struct property *prop;
@@ -255,3 +302,22 @@ int pa_proplist_contains(pa_proplist *p, const char *key) {
return 1;
}
+
+void pa_proplist_clear(pa_proplist *p) {
+ struct property *prop;
+ pa_assert(p);
+
+ while ((prop = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
+ property_free(prop);
+}
+
+pa_proplist* pa_proplist_copy(pa_proplist *template) {
+ pa_proplist *p;
+
+ pa_assert_se(p = pa_proplist_new());
+
+ if (template)
+ pa_proplist_update(p, PA_UPDATE_REPLACE, template);
+
+ return p;
+}
diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h
index c4cf9ac9..f433ec62 100644
--- a/src/pulse/proplist.h
+++ b/src/pulse/proplist.h
@@ -24,67 +24,176 @@
USA.
***/
-#include <pulsecore/macro.h>
+#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
+
+PA_C_DECL_BEGIN
/* Defined properties:
*
- * x11.xid
- * x11.display
- * x11.x_pointer
- * x11.y_pointer
- * x11.button
- * media.name
- * media.title
- * media.artist
- * media.language
+ * media.name "Guns'N'Roses: Civil War"
+ * media.title "Civil War"
+ * media.artist "Guns'N'Roses"
+ * media.language "de_DE"
* media.filename
* media.icon
* media.icon_name
- * media.role video, music, game, event, phone, production
- * application.name
+ * media.role video, music, game, event, phone, production, filter, abstract, stream
+ * event.id button-click, session-login
+ * event.x11.display
+ * event.x11.xid
+ * event.x11.x_pointer
+ * event.x11.y_pointer
+ * event.x11.button
+ * application.name "Rhythmbox Media Player"
+ * application.id "org.gnome.rhythmbox"
* application.version
* application.icon
* application.icon_name
+ * application.process.id
+ * application.process.binary
+ * application.process.user
+ * application.process.host
+ * device.string
+ * device.api oss, alsa, sunaudio
+ * device.description
+ * device.bus_path
+ * device.serial
+ * device.vendor_product_id
+ * device.class sound, modem, monitor, filter
+ * device.form_factor laptop-speakers, external-speakers, telephone, tv-capture, webcam-capture, microphone-capture, headset
+ * device.connector isa, pci, usb, firewire, bluetooth
+ * device.access_mode mmap, mmap_rewrite, serial
+ * device.master_device
+ * device.buffer_size
*/
-#define PA_PROP_X11_XID "x11.xid"
-#define PA_PROP_X11_DISPLAY "x11.display"
-#define PA_PROP_X11_X_POINTER "x11.x_pointer"
-#define PA_PROP_X11_Y_POINTER "x11.y_pointer"
-#define PA_PROP_X11_BUTTON "x11.button"
-#define PA_PROP_MEDIA_NAME "media.name"
-#define PA_PROP_MEDIA_TITLE "media.title"
-#define PA_PROP_MEDIA_ARTIST "media.artist"
-#define PA_PROP_MEDIA_LANGUAGE "media.language"
-#define PA_PROP_MEDIA_FILENAME "media.filename"
-#define PA_PROP_MEDIA_ICON "media.icon"
-#define PA_PROP_MEDIA_ICON_NAME "media.icon_name"
-#define PA_PROP_MEDIA_ROLE "media.role"
-#define PA_PROP_APPLICATION_NAME "application.name"
-#define PA_PROP_APPLICATION_VERSION "application.version"
-#define PA_PROP_APPLICATION_ICON "application.icon"
-#define PA_PROP_APPLICATION_ICON_NAME "application.icon_name"
-
+#define PA_PROP_MEDIA_NAME "media.name"
+#define PA_PROP_MEDIA_TITLE "media.title"
+#define PA_PROP_MEDIA_ARTIST "media.artist"
+#define PA_PROP_MEDIA_LANGUAGE "media.language"
+#define PA_PROP_MEDIA_FILENAME "media.filename"
+#define PA_PROP_MEDIA_ICON "media.icon"
+#define PA_PROP_MEDIA_ICON_NAME "media.icon_name"
+#define PA_PROP_MEDIA_ROLE "media.role"
+#define PA_PROP_EVENT_ID "event.id"
+#define PA_PROP_EVENT_X11_DISPLAY "event.x11.display"
+#define PA_PROP_EVENT_X11_XID "event.x11.xid"
+#define PA_PROP_EVENT_MOUSE_X "event.mouse.x"
+#define PA_PROP_EVENT_MOUSE_Y "event.mouse.y"
+#define PA_PROP_EVENT_MOUSE_BUTTON "event.mouse.button"
+#define PA_PROP_APPLICATION_NAME "application.name"
+#define PA_PROP_APPLICATION_ID "application.id"
+#define PA_PROP_APPLICATION_VERSION "application.version"
+#define PA_PROP_APPLICATION_ICON "application.icon"
+#define PA_PROP_APPLICATION_ICON_NAME "application.icon_name"
+#define PA_PROP_APPLICATION_LANGUAGE "application.language"
+#define PA_PROP_APPLICATION_PROCESS_ID "application.process.id"
+#define PA_PROP_APPLICATION_PROCESS_BINARY "application.process.binary"
+#define PA_PROP_APPLICATION_PROCESS_USER "application.process.user"
+#define PA_PROP_APPLICATION_PROCESS_HOST "application.process.host"
+#define PA_PROP_DEVICE_STRING "device.string"
+#define PA_PROP_DEVICE_API "device.api"
+#define PA_PROP_DEVICE_DESCRIPTION "device.description"
+#define PA_PROP_DEVICE_BUS_PATH "device.bus_path"
+#define PA_PROP_DEVICE_SERIAL "device.serial"
+#define PA_PROP_DEVICE_VENDOR_PRODUCT_ID "device.vendor_product_id"
+#define PA_PROP_DEVICE_CLASS "device.class"
+#define PA_PROP_DEVICE_FORM_FACTOR "device.form_factor"
+#define PA_PROP_DEVICE_CONNECTOR "device.connector"
+#define PA_PROP_DEVICE_ACCESS_MODE "device.access_mode"
+#define PA_PROP_DEVICE_MASTER_DEVICE "device.master_device"
+#define PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE "device.buffering.buffer_size"
+#define PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE "device.buffering.fragment_size"
+
+/** A property list object. Basically a dictionary with UTF-8 strings
+ * as keys and arbitrary data as values. \since 0.9.11 */
typedef struct pa_proplist pa_proplist;
+/** Allocate a property list. \since 0.9.11 */
pa_proplist* pa_proplist_new(void);
-void pa_proplist_free(pa_proplist* p);
-/** Will accept only valid UTF-8 */
-int pa_proplist_puts(pa_proplist *p, const char *key, const char *value);
-int pa_proplist_put(pa_proplist *p, const char *key, const void *data, size_t nbytes);
+/** Free the property list. \since 0.9.11 */
+void pa_proplist_free(pa_proplist* p);
-/* Will return NULL if the data is not valid UTF-8 */
+/** Append a new string entry to the property list, possibly
+ * overwriting an already existing entry with the same key. An
+ * internal copy of the data passed is made. Will accept only valid
+ * UTF-8. \since 0.9.11 */
+int pa_proplist_sets(pa_proplist *p, const char *key, const char *value);
+
+/** Append a new string entry to the property list, possibly
+ * overwriting an already existing entry with the same key. An
+ * internal copy of the data passed is made. Will accept only valid
+ * UTF-8. The data can be passed as printf()-style format string with
+ * arguments. \since 0.9.11 */
+int pa_proplist_setf(pa_proplist *p, const char *key, const char *format, ...) PA_GCC_PRINTF_ATTR(3,4);
+
+/** Append a new arbitrary data entry to the property list, possibly
+ * overwriting an already existing entry with the same key. An
+ * internal copy of the data passed is made. \since 0.9.11 */
+int pa_proplist_set(pa_proplist *p, const char *key, const void *data, size_t nbytes);
+
+/* Return a string entry for the specified key. Will return NULL if
+ * the data is not valid UTF-8. Will return a NUL-terminated string in
+ * an internally allocated buffer. The caller should make a copy of
+ * the data before accessing the property list again. \since 0.9.11 */
const char *pa_proplist_gets(pa_proplist *p, const char *key);
-int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *nbytes);
-void pa_proplist_merge(pa_proplist *p, pa_proplist *other);
-int pa_proplist_remove(pa_proplist *p, const char *key);
+/** Return the the value for the specified key. Will return a
+ * NUL-terminated string for string entries. The pointer returned will
+ * point to an internally allocated buffer. The caller should make a
+ * copy of the data before the property list is accessed again. \since
+ * 0.9.11 */
+int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *nbytes);
+/** Update mode enum for pa_proplist_update(). \since 0.9.11 */
+typedef enum pa_update_mode {
+ PA_UPDATE_SET, /*< Replace the entirey property list with the new one. Don't keep any of the old data around */
+ PA_UPDATE_MERGE, /*< Merge new property list into the existing one, not replacing any old entries if they share a common key with the new property list. */
+ PA_UPDATE_REPLACE /*< Merge new property list into the existing one, replacing all old entries that share a common key with the new property list. */
+} pa_update_mode_t;
+
+/** Merge property list "other" into "p", adhering the merge mode as
+ * specified in "mode". \since 0.9.11 */
+void pa_proplist_update(pa_proplist *p, pa_update_mode_t mode, pa_proplist *other);
+
+/** Removes a single entry from the property list, identified be the
+ * specified key name. \since 0.9.11 */
+int pa_proplist_unset(pa_proplist *p, const char *key);
+
+/** Similar to pa_proplist_remove() but takes an array of keys to
+ * remove. The array should be terminated by a NULL pointer. Return -1
+ * on failure, otherwise the number of entries actually removed (which
+ * might even be 0, if there where no matching entries to
+ * remove). \since 0.9.11 */
+int pa_proplist_unset_many(pa_proplist *p, const char * const keys[]);
+
+/** Iterate through the property list. The user should allocate a
+ * state variable of type void* and initialize it with NULL. A pointer
+ * to this variable should then be passed to pa_proplist_iterate()
+ * which should be called in a loop until it returns NULL which
+ * signifies EOL. The property list should not be modified during
+ * iteration through the list. On each invication this function will
+ * return the key string for the next entry. The keys in the property
+ * list do not have any particular order. \since 0.9.11 */
const char *pa_proplist_iterate(pa_proplist *p, void **state);
+/** Format the property list nicely as a human readable string. Call pa_xfree() on the result. \since
+ * 0.9.11 */
char *pa_proplist_to_string(pa_proplist *p);
+/** Returns 1 if an entry for the specified key is existant in the
+ * property list. \since 0.9.11 */
int pa_proplist_contains(pa_proplist *p, const char *key);
+/** Remove all entries from the property list object. \since 0.9.11 */
+void pa_proplist_clear(pa_proplist *p);
+
+/** Allocate a new property list and copy over every single entry from
+ * the specific list. \since 0.9.11 */
+pa_proplist* pa_proplist_copy(pa_proplist *t);
+
+PA_C_DECL_END
+
#endif
diff --git a/src/pulse/sample.c b/src/pulse/sample.c
index 27c0df03..43340f20 100644
--- a/src/pulse/sample.c
+++ b/src/pulse/sample.c
@@ -32,6 +32,7 @@
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
+#include <pulse/timeval.h>
#include "sample.h"
@@ -70,13 +71,13 @@ size_t pa_bytes_per_second(const pa_sample_spec *spec) {
pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) {
pa_assert(spec);
- return (pa_usec_t) (((double) length/pa_frame_size(spec)*1000000)/spec->rate);
+ return (((pa_usec_t) (length / pa_frame_size(spec)) * PA_USEC_PER_SEC) / spec->rate);
}
size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) {
pa_assert(spec);
- return (size_t) (((double) t * spec->rate / 1000000))*pa_frame_size(spec);
+ return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * pa_frame_size(spec);
}
int pa_sample_spec_valid(const pa_sample_spec *spec) {
@@ -97,7 +98,10 @@ int pa_sample_spec_equal(const pa_sample_spec*a, const pa_sample_spec*b) {
pa_assert(a);
pa_assert(b);
- return (a->format == b->format) && (a->rate == b->rate) && (a->channels == b->channels);
+ return
+ (a->format == b->format) &&
+ (a->rate == b->rate) &&
+ (a->channels == b->channels);
}
const char *pa_sample_format_to_string(pa_sample_format_t f) {
diff --git a/src/pulse/sample.h b/src/pulse/sample.h
index f0b839fd..dedd72de 100644
--- a/src/pulse/sample.h
+++ b/src/pulse/sample.h
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <math.h>
+#include <pulse/gccmacro.h>
#include <pulse/cdecl.h>
/** \page sample Sample Format Specifications
@@ -172,7 +173,7 @@ typedef struct pa_sample_spec {
uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
} pa_sample_spec;
-/** Type for usec specifications (unsigned). May be either 32 or 64 bit, depending on the architecture */
+/** Type for usec specifications (unsigned). Always 64 bit. */
typedef uint64_t pa_usec_t;
/** Return the amount of bytes playback of a second of audio with the specified sample type takes */
diff --git a/src/pulse/scache.c b/src/pulse/scache.c
index 186b0a3e..e43a0b9f 100644
--- a/src/pulse/scache.c
+++ b/src/pulse/scache.c
@@ -49,12 +49,22 @@ int pa_stream_connect_upload(pa_stream *s, size_t length) {
pa_stream_ref(s);
s->direction = PA_STREAM_UPLOAD;
+ s->flags = 0;
t = pa_tagstruct_command(s->context, PA_COMMAND_CREATE_UPLOAD_STREAM, &tag);
- pa_tagstruct_puts(t, s->name);
+
+ if (s->context->version < 13)
+ pa_tagstruct_puts(t, pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME));
+
pa_tagstruct_put_sample_spec(t, &s->sample_spec);
pa_tagstruct_put_channel_map(t, &s->channel_map);
pa_tagstruct_putu32(t, length);
+
+ if (s->context->version >= 13) {
+ pa_init_proplist(s->proplist);
+ pa_tagstruct_put_proplist(t, s->proplist);
+ }
+
pa_pstream_send_tagstruct(s->context->pstream, t);
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL);
@@ -85,6 +95,73 @@ int pa_stream_finish_upload(pa_stream *s) {
return 0;
}
+static void play_sample_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_operation *o = userdata;
+ int success = 1;
+ uint32_t idx = 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;
+
+ success = 0;
+ } else if ((o->context->version >= 13 && pa_tagstruct_getu32(t, &idx) < 0) ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ } else if (o->context->version >= 13 && idx == PA_INVALID_INDEX)
+ success = 0;
+
+ if (o->callback) {
+ pa_context_success_cb_t cb = (pa_context_success_cb_t) o->callback;
+ cb(o->context, success, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+static void play_sample_with_proplist_ack_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_operation *o = userdata;
+ uint32_t idx;
+
+ 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;
+
+ idx = PA_INVALID_INDEX;
+ } else if (pa_tagstruct_getu32(t, &idx) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (o->callback) {
+ pa_context_play_sample_cb_t cb = (pa_context_play_sample_cb_t) o->callback;
+ cb(o->context, idx, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+
pa_operation *pa_context_play_sample(pa_context *c, const char *name, const char *dev, pa_volume_t volume, pa_context_success_cb_t cb, void *userdata) {
pa_operation *o;
pa_tagstruct *t;
@@ -107,8 +184,47 @@ pa_operation *pa_context_play_sample(pa_context *c, const char *name, const char
pa_tagstruct_puts(t, dev);
pa_tagstruct_putu32(t, volume);
pa_tagstruct_puts(t, name);
+
+ if (c->version >= 13) {
+ pa_proplist *p = pa_proplist_new();
+ pa_tagstruct_put_proplist(t, p);
+ pa_proplist_free(p);
+ }
+
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);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, play_sample_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ return o;
+}
+
+pa_operation *pa_context_play_sample_with_proplist(pa_context *c, const char *name, const char *dev, pa_volume_t volume, pa_proplist *p, pa_context_play_sample_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ 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, name && *name, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, !dev || *dev, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, p, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED);
+
+ o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+ if (!dev)
+ dev = c->conf->default_sink;
+
+ t = pa_tagstruct_command(c, PA_COMMAND_PLAY_SAMPLE, &tag);
+ pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+ pa_tagstruct_puts(t, dev);
+ pa_tagstruct_putu32(t, volume);
+ pa_tagstruct_puts(t, name);
+ pa_tagstruct_put_proplist(t, p);
+
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, play_sample_with_proplist_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
return o;
}
@@ -128,9 +244,9 @@ pa_operation* pa_context_remove_sample(pa_context *c, const char *name, pa_conte
t = pa_tagstruct_command(c, PA_COMMAND_REMOVE_SAMPLE, &tag);
pa_tagstruct_puts(t, name);
+
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;
}
-
diff --git a/src/pulse/scache.h b/src/pulse/scache.h
index 31fd8956..46d86a19 100644
--- a/src/pulse/scache.h
+++ b/src/pulse/scache.h
@@ -79,14 +79,25 @@
PA_C_DECL_BEGIN
+/** Callback prototype for pa_context_play_sample_with_proplist(). The
+ * idx value is the index of the sink input object, or
+ * PA_INVALID_INDEX on failure. \since 0.9.11 */
+typedef void (*pa_context_play_sample_cb_t)(pa_context *c, uint32_t idx, void *userdata);
+
/** Make this stream a sample upload stream */
int pa_stream_connect_upload(pa_stream *s, size_t length);
-/** Finish the sample upload, the stream name will become the sample name. You cancel a samp
- * le upload by issuing pa_stream_disconnect() */
+/** Finish the sample upload, the stream name will become the sample
+ * name. You cancel a sample upload by issuing
+ * pa_stream_disconnect() */
int pa_stream_finish_upload(pa_stream *s);
-/** Play a sample from the sample cache to the specified device. If the latter is NULL use the default sink. Returns an operation object */
+/** Remove a sample from the sample cache. Returns an operation object which may be used to cancel the operation while it is running */
+pa_operation* pa_context_remove_sample(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);
+
+/** Play a sample from the sample cache to the specified device. If
+ * the latter is NULL use the default sink. Returns an operation
+ * object */
pa_operation* pa_context_play_sample(
pa_context *c /**< Context */,
const char *name /**< Name of the sample to play */,
@@ -95,8 +106,18 @@ pa_operation* pa_context_play_sample(
pa_context_success_cb_t cb /**< Call this function after successfully starting playback, or NULL */,
void *userdata /**< Userdata to pass to the callback */);
-/** Remove a sample from the sample cache. Returns an operation object which may be used to cancel the operation while it is running */
-pa_operation* pa_context_remove_sample(pa_context *c, const char *name, pa_context_success_cb_t, void *userdata);
+/** Play a sample from the sample cache to the specified device,
+ * allowing specification of a property list for the playback
+ * stream. If the latter is NULL use the default sink. Returns an
+ * operation object. \since 0.9.11 */
+pa_operation* pa_context_play_sample_with_proplist(
+ pa_context *c /**< Context */,
+ const char *name /**< Name of the sample to play */,
+ const char *dev /**< Sink to play this sample on */,
+ pa_volume_t volume /**< Volume to play this sample with */ ,
+ pa_proplist *proplist /**< Property list for this sound. The property list of the cached entry will be merged into this property list */,
+ pa_context_play_sample_cb_t cb /**< Call this function after successfully starting playback, or NULL */,
+ void *userdata /**< Userdata to pass to the callback */);
PA_C_DECL_END
diff --git a/src/pulse/simple.h b/src/pulse/simple.h
index 0ddd57e0..7fca6ac3 100644
--- a/src/pulse/simple.h
+++ b/src/pulse/simple.h
@@ -138,10 +138,10 @@ int pa_simple_drain(pa_simple *s, int *error);
/** Read some data from the server */
int pa_simple_read(pa_simple *s, void*data, size_t bytes, int *error);
-/** Return the playback latency. \since 0.5 */
+/** Return the playback latency. */
pa_usec_t pa_simple_get_latency(pa_simple *s, int *error);
-/** Flush the playback buffer. \since 0.5 */
+/** Flush the playback buffer. */
int pa_simple_flush(pa_simple *s, int *error);
PA_C_DECL_END
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index c44323fc..4268fd6f 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -38,12 +38,48 @@
#include <pulsecore/log.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/macro.h>
+#include <pulsecore/rtclock.h>
#include "internal.h"
-#define LATENCY_IPOL_INTERVAL_USEC (100000L)
+#define LATENCY_IPOL_INTERVAL_USEC (333*PA_USEC_PER_MSEC)
+
+#define SMOOTHER_ADJUST_TIME (1000*PA_USEC_PER_MSEC)
+#define SMOOTHER_HISTORY_TIME (5000*PA_USEC_PER_MSEC)
+#define SMOOTHER_MIN_HISTORY (4)
pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *ss, const pa_channel_map *map) {
+ return pa_stream_new_with_proplist(c, name, ss, map, NULL);
+}
+
+static void reset_callbacks(pa_stream *s) {
+ s->read_callback = NULL;
+ s->read_userdata = NULL;
+ s->write_callback = NULL;
+ s->write_userdata = NULL;
+ s->state_callback = NULL;
+ s->state_userdata = NULL;
+ s->overflow_callback = NULL;
+ s->overflow_userdata = NULL;
+ s->underflow_callback = NULL;
+ s->underflow_userdata = NULL;
+ s->latency_update_callback = NULL;
+ s->latency_update_userdata = NULL;
+ s->moved_callback = NULL;
+ s->moved_userdata = NULL;
+ s->suspended_callback = NULL;
+ s->suspended_userdata = NULL;
+ s->started_callback = NULL;
+ s->started_userdata = NULL;
+}
+
+pa_stream *pa_stream_new_with_proplist(
+ pa_context *c,
+ const char *name,
+ const pa_sample_spec *ss,
+ const pa_channel_map *map,
+ pa_proplist *p) {
+
pa_stream *s;
int i;
pa_channel_map tmap;
@@ -54,6 +90,7 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
PA_CHECK_VALIDITY_RETURN_NULL(c, ss && pa_sample_spec_valid(ss), PA_ERR_INVALID);
PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 12 || (ss->format != PA_SAMPLE_S32LE || ss->format != PA_SAMPLE_S32NE), PA_ERR_NOTSUPPORTED);
PA_CHECK_VALIDITY_RETURN_NULL(c, !map || (pa_channel_map_valid(map) && map->channels == ss->channels), PA_ERR_INVALID);
+ PA_CHECK_VALIDITY_RETURN_NULL(c, name || (p && pa_proplist_contains(p, PA_PROP_MEDIA_NAME)), PA_ERR_INVALID);
if (!map)
PA_CHECK_VALIDITY_RETURN_NULL(c, map = pa_channel_map_init_auto(&tmap, ss->channels, PA_CHANNEL_MAP_DEFAULT), PA_ERR_INVALID);
@@ -63,67 +100,53 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
s->context = c;
s->mainloop = c->mainloop;
- s->buffer_attr_not_ready = s->timing_info_not_ready = FALSE;
-
- s->read_callback = NULL;
- s->read_userdata = NULL;
- s->write_callback = NULL;
- s->write_userdata = NULL;
- s->state_callback = NULL;
- s->state_userdata = NULL;
- s->overflow_callback = NULL;
- s->overflow_userdata = NULL;
- s->underflow_callback = NULL;
- s->underflow_userdata = NULL;
- s->latency_update_callback = NULL;
- s->latency_update_userdata = NULL;
- s->moved_callback = NULL;
- s->moved_userdata = NULL;
- s->suspended_callback = NULL;
- s->suspended_userdata = NULL;
-
s->direction = PA_STREAM_NODIRECTION;
- s->name = pa_xstrdup(name);
+ s->state = PA_STREAM_UNCONNECTED;
+ s->flags = 0;
+
s->sample_spec = *ss;
s->channel_map = *map;
- s->flags = 0;
+
+ s->proplist = p ? pa_proplist_copy(p) : pa_proplist_new();
+ if (name)
+ pa_proplist_sets(s->proplist, PA_PROP_MEDIA_NAME, name);
s->channel = 0;
- s->channel_valid = 0;
+ s->channel_valid = FALSE;
s->syncid = c->csyncid++;
s->stream_index = PA_INVALID_INDEX;
- s->requested_bytes = 0;
- s->state = PA_STREAM_UNCONNECTED;
- s->manual_buffer_attr = FALSE;
+ s->requested_bytes = 0;
memset(&s->buffer_attr, 0, sizeof(s->buffer_attr));
s->device_index = PA_INVALID_INDEX;
s->device_name = NULL;
s->suspended = FALSE;
- s->peek_memchunk.index = 0;
- s->peek_memchunk.length = 0;
- s->peek_memchunk.memblock = NULL;
+ pa_memchunk_reset(&s->peek_memchunk);
s->peek_data = NULL;
s->record_memblockq = NULL;
+ s->corked = FALSE;
+
+ memset(&s->timing_info, 0, sizeof(s->timing_info));
+ s->timing_info_valid = FALSE;
+
s->previous_time = 0;
- s->timing_info_valid = 0;
+
s->read_index_not_before = 0;
s->write_index_not_before = 0;
-
for (i = 0; i < PA_MAX_WRITE_INDEX_CORRECTIONS; i++)
s->write_index_corrections[i].valid = 0;
s->current_write_index_correction = 0;
- s->corked = 0;
+ s->auto_timing_update_event = NULL;
+ s->auto_timing_update_requested = FALSE;
- s->cached_time_valid = 0;
+ reset_callbacks(s);
- s->auto_timing_update_event = NULL;
- s->auto_timing_update_requested = 0;
+ s->smoother = NULL;
/* Refcounting is strictly one-way: from the "bigger" to the "smaller" object. */
PA_LLIST_PREPEND(pa_stream, c->streams, s);
@@ -132,16 +155,51 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *
return s;
}
-static void stream_free(pa_stream *s) {
+static void stream_unlink(pa_stream *s) {
+ pa_operation *o, *n;
pa_assert(s);
- pa_assert(!s->context);
- pa_assert(!s->channel_valid);
+
+ if (!s->context)
+ return;
+
+ /* Detach from context */
+
+ /* Unref all operatio object that point to us */
+ for (o = s->context->operations; o; o = n) {
+ n = o->next;
+
+ if (o->stream == s)
+ pa_operation_cancel(o);
+ }
+
+ /* Drop all outstanding replies for this stream */
+ if (s->context->pdispatch)
+ pa_pdispatch_unregister_reply(s->context->pdispatch, s);
+
+ if (s->channel_valid) {
+ pa_dynarray_put((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, s->channel, NULL);
+ s->channel = 0;
+ s->channel_valid = FALSE;
+ }
+
+ PA_LLIST_REMOVE(pa_stream, s->context->streams, s);
+ pa_stream_unref(s);
+
+ s->context = NULL;
if (s->auto_timing_update_event) {
pa_assert(s->mainloop);
s->mainloop->time_free(s->auto_timing_update_event);
}
+ reset_callbacks(s);
+}
+
+static void stream_free(pa_stream *s) {
+ pa_assert(s);
+
+ stream_unlink(s);
+
if (s->peek_memchunk.memblock) {
if (s->peek_data)
pa_memblock_release(s->peek_memchunk.memblock);
@@ -151,7 +209,12 @@ static void stream_free(pa_stream *s) {
if (s->record_memblockq)
pa_memblockq_free(s->record_memblockq);
- pa_xfree(s->name);
+ if (s->proplist)
+ pa_proplist_free(s->proplist);
+
+ if (s->smoother)
+ pa_smoother_free(s->smoother);
+
pa_xfree(s->device_name);
pa_xfree(s);
}
@@ -205,46 +268,41 @@ void pa_stream_set_state(pa_stream *s, pa_stream_state_t st) {
pa_stream_ref(s);
s->state = st;
+
if (s->state_callback)
s->state_callback(s, s->state_userdata);
- if ((st == PA_STREAM_FAILED || st == PA_STREAM_TERMINATED) && s->context) {
-
- /* Detach from context */
- pa_operation *o, *n;
-
- /* Unref all operatio object that point to us */
- for (o = s->context->operations; o; o = n) {
- n = o->next;
-
- if (o->stream == s)
- pa_operation_cancel(o);
- }
+ if ((st == PA_STREAM_FAILED || st == PA_STREAM_TERMINATED))
+ stream_unlink(s);
- /* Drop all outstanding replies for this stream */
- if (s->context->pdispatch)
- pa_pdispatch_unregister_reply(s->context->pdispatch, s);
+ pa_stream_unref(s);
+}
- if (s->channel_valid)
- pa_dynarray_put((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, s->channel, NULL);
+static void request_auto_timing_update(pa_stream *s, pa_bool_t force) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
- PA_LLIST_REMOVE(pa_stream, s->context->streams, s);
- pa_stream_unref(s);
+ if (!(s->flags & PA_STREAM_AUTO_TIMING_UPDATE))
+ return;
- s->channel = 0;
- s->channel_valid = 0;
+ if (s->state == PA_STREAM_READY &&
+ (force || !s->auto_timing_update_requested)) {
+ pa_operation *o;
- s->context = NULL;
+/* pa_log("automatically requesting new timing data"); */
- s->read_callback = NULL;
- s->write_callback = NULL;
- s->state_callback = NULL;
- s->overflow_callback = NULL;
- s->underflow_callback = NULL;
- s->latency_update_callback = NULL;
+ if ((o = pa_stream_update_timing_info(s, NULL, NULL))) {
+ pa_operation_unref(o);
+ s->auto_timing_update_requested = TRUE;
+ }
}
- pa_stream_unref(s);
+ if (s->auto_timing_update_event) {
+ struct timeval next;
+ pa_gettimeofday(&next);
+ pa_timeval_add(&next, LATENCY_IPOL_INTERVAL_USEC);
+ s->mainloop->time_restart(s->auto_timing_update_event, &next);
+ }
}
void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
@@ -269,6 +327,9 @@ void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_KILLED ? c->playback_streams : c->record_streams, channel)))
goto finish;
+ if (s->state != PA_STREAM_READY)
+ goto finish;
+
pa_context_set_error(c, PA_ERR_KILLED);
pa_stream_set_state(s, PA_STREAM_FAILED);
@@ -281,8 +342,10 @@ void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED u
pa_stream *s;
uint32_t channel;
const char *dn;
- int suspended;
+ pa_bool_t suspended;
uint32_t di;
+ pa_usec_t usec;
+ uint32_t maxlength = 0, fragsize = 0, minreq = 0, tlength = 0, prebuf = 0;
pa_assert(pd);
pa_assert(command == PA_COMMAND_PLAYBACK_STREAM_MOVED || command == PA_COMMAND_RECORD_STREAM_MOVED);
@@ -300,8 +363,33 @@ void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED u
if (pa_tagstruct_getu32(t, &channel) < 0 ||
pa_tagstruct_getu32(t, &di) < 0 ||
pa_tagstruct_gets(t, &dn) < 0 ||
- pa_tagstruct_get_boolean(t, &suspended) < 0 ||
- !pa_tagstruct_eof(t)) {
+ pa_tagstruct_get_boolean(t, &suspended) < 0) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (c->version >= 13) {
+
+ if (command == PA_COMMAND_RECORD_STREAM_MOVED) {
+ if (pa_tagstruct_getu32(t, &maxlength) < 0 ||
+ pa_tagstruct_getu32(t, &fragsize) < 0 ||
+ pa_tagstruct_get_usec(t, &usec) < 0) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+ } else {
+ if (pa_tagstruct_getu32(t, &maxlength) < 0 ||
+ pa_tagstruct_getu32(t, &tlength) < 0 ||
+ pa_tagstruct_getu32(t, &prebuf) < 0 ||
+ pa_tagstruct_getu32(t, &minreq) < 0 ||
+ pa_tagstruct_get_usec(t, &usec) < 0) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+ }
+ }
+
+ if (!pa_tagstruct_eof(t)) {
pa_context_fail(c, PA_ERR_PROTOCOL);
goto finish;
}
@@ -314,12 +402,30 @@ void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED u
if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_MOVED ? c->playback_streams : c->record_streams, channel)))
goto finish;
+ if (s->state != PA_STREAM_READY)
+ goto finish;
+
+ if (c->version >= 13) {
+ if (s->direction == PA_STREAM_RECORD)
+ s->timing_info.configured_source_usec = usec;
+ else
+ s->timing_info.configured_sink_usec = usec;
+
+ s->buffer_attr.maxlength = maxlength;
+ s->buffer_attr.fragsize = fragsize;
+ s->buffer_attr.tlength = tlength;
+ s->buffer_attr.prebuf = prebuf;
+ s->buffer_attr.minreq = minreq;
+ }
+
pa_xfree(s->device_name);
s->device_name = pa_xstrdup(dn);
s->device_index = di;
s->suspended = suspended;
+ request_auto_timing_update(s, TRUE);
+
if (s->moved_callback)
s->moved_callback(s, s->moved_userdata);
@@ -331,7 +437,7 @@ void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUS
pa_context *c = userdata;
pa_stream *s;
uint32_t channel;
- int suspended;
+ pa_bool_t suspended;
pa_assert(pd);
pa_assert(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED || command == PA_COMMAND_RECORD_STREAM_SUSPENDED);
@@ -356,8 +462,23 @@ void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUS
if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED ? c->playback_streams : c->record_streams, channel)))
goto finish;
+ if (s->state != PA_STREAM_READY)
+ goto finish;
+
s->suspended = suspended;
+ if (s->smoother) {
+ pa_usec_t x = pa_rtclock_usec();
+
+ if (s->timing_info_valid)
+ x -= s->timing_info.transport_usec;
+
+ if (s->suspended || s->corked)
+ pa_smoother_pause(s->smoother, x);
+ }
+
+ request_auto_timing_update(s, TRUE);
+
if (s->suspended_callback)
s->suspended_callback(s, s->suspended_userdata);
@@ -365,6 +486,45 @@ finish:
pa_context_unref(c);
}
+void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+ pa_context *c = userdata;
+ pa_stream *s;
+ uint32_t channel;
+
+ pa_assert(pd);
+ pa_assert(command == PA_COMMAND_STARTED);
+ pa_assert(t);
+ pa_assert(c);
+ pa_assert(PA_REFCNT_VALUE(c) >= 1);
+
+ pa_context_ref(c);
+
+ if (c->version < 13) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (pa_tagstruct_getu32(t, &channel) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(c, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (!(s = pa_dynarray_get(c->playback_streams, channel)))
+ goto finish;
+
+ if (s->state != PA_STREAM_READY)
+ goto finish;
+
+ request_auto_timing_update(s, TRUE);
+
+ if (s->started_callback)
+ s->started_callback(s, s->suspended_userdata);
+
+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) {
pa_stream *s;
pa_context *c = userdata;
@@ -388,12 +548,13 @@ void pa_command_request(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32
if (!(s = pa_dynarray_get(c->playback_streams, channel)))
goto finish;
- if (s->state == PA_STREAM_READY) {
- s->requested_bytes += bytes;
+ if (s->state != PA_STREAM_READY)
+ goto finish;
- if (s->requested_bytes > 0 && s->write_callback)
- s->write_callback(s, s->requested_bytes, s->write_userdata);
- }
+ s->requested_bytes += bytes;
+
+ if (s->requested_bytes > 0 && s->write_callback)
+ s->write_callback(s, s->requested_bytes, s->write_userdata);
finish:
pa_context_unref(c);
@@ -421,6 +582,21 @@ void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, PA_GCC
if (!(s = pa_dynarray_get(c->playback_streams, channel)))
goto finish;
+ if (s->state != PA_STREAM_READY)
+ goto finish;
+
+ if (s->smoother)
+ if (s->direction == PA_STREAM_PLAYBACK && s->buffer_attr.prebuf > 0) {
+ pa_usec_t x = pa_rtclock_usec();
+
+ if (s->timing_info_valid)
+ x -= s->timing_info.transport_usec;
+
+ pa_smoother_pause(s->smoother, x);
+ }
+
+ request_auto_timing_update(s, TRUE);
+
if (s->state == PA_STREAM_READY) {
if (command == PA_COMMAND_OVERFLOW) {
@@ -436,34 +612,7 @@ void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, PA_GCC
pa_context_unref(c);
}
-static void request_auto_timing_update(pa_stream *s, int force) {
- pa_assert(s);
- pa_assert(PA_REFCNT_VALUE(s) >= 1);
-
- if (!(s->flags & PA_STREAM_AUTO_TIMING_UPDATE))
- return;
-
- if (s->state == PA_STREAM_READY &&
- (force || !s->auto_timing_update_requested)) {
- pa_operation *o;
-
-/* pa_log("automatically requesting new timing data"); */
-
- if ((o = pa_stream_update_timing_info(s, NULL, NULL))) {
- pa_operation_unref(o);
- s->auto_timing_update_requested = 1;
- }
- }
-
- if (s->auto_timing_update_event) {
- struct timeval next;
- pa_gettimeofday(&next);
- pa_timeval_add(&next, LATENCY_IPOL_INTERVAL_USEC);
- s->mainloop->time_restart(s->auto_timing_update_event, &next);
- }
-}
-
-static void invalidate_indexes(pa_stream *s, int r, int w) {
+static void invalidate_indexes(pa_stream *s, pa_bool_t r, pa_bool_t w) {
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@@ -490,11 +639,7 @@ static void invalidate_indexes(pa_stream *s, int r, int w) {
/* pa_log("read_index invalidated"); */
}
- if ((s->direction == PA_STREAM_PLAYBACK && r) ||
- (s->direction == PA_STREAM_RECORD && w))
- s->cached_time_valid = 0;
-
- request_auto_timing_update(s, 1);
+ 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) {
@@ -503,10 +648,8 @@ static void auto_timing_update_callback(PA_GCC_UNUSED pa_mainloop_api *m, PA_GCC
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
-/* pa_log("time event"); */
-
pa_stream_ref(s);
- request_auto_timing_update(s, 0);
+ request_auto_timing_update(s, FALSE);
pa_stream_unref(s);
}
@@ -515,9 +658,6 @@ static void create_stream_complete(pa_stream *s) {
pa_assert(PA_REFCNT_VALUE(s) >= 1);
pa_assert(s->state == PA_STREAM_CREATING);
- if (s->buffer_attr_not_ready || s->timing_info_not_ready)
- return;
-
pa_stream_set_state(s, PA_STREAM_READY);
if (s->requested_bytes > 0 && s->write_callback)
@@ -529,18 +669,36 @@ static void create_stream_complete(pa_stream *s) {
tv.tv_usec += 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);
+
+ request_auto_timing_update(s, TRUE);
}
}
-static void automatic_buffer_attr(pa_buffer_attr *attr, pa_sample_spec *ss) {
+static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_sample_spec *ss) {
+ pa_assert(s);
pa_assert(attr);
pa_assert(ss);
- attr->tlength = pa_bytes_per_second(ss)/2;
- attr->maxlength = (attr->tlength*3)/2;
- attr->minreq = attr->tlength/50;
- attr->prebuf = attr->tlength - attr->minreq;
- attr->fragsize = attr->tlength/50;
+ if (s->context->version >= 13)
+ return;
+
+ /* Version older than 0.9.10 didn't do server side buffer_attr
+ * selection, hence we have to fake it on the client side */
+
+ if (!attr->maxlength <= 0)
+ attr->maxlength = 4*1024*1024; /* 4MB is the maximum queue length PulseAudio <= 0.9.9 supported. */
+
+ if (!attr->tlength <= 0)
+ attr->tlength = pa_bytes_per_second(ss)*2; /* 2s of buffering */
+
+ if (!attr->minreq <= 0)
+ attr->minreq = (2*attr->tlength)/10; /* Ask for more data when there are only 200ms left in the playback buffer */
+
+ if (!attr->prebuf)
+ attr->prebuf = attr->tlength; /* Start to play only when the playback is fully filled up once */
+
+ if (!attr->fragsize)
+ 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) {
@@ -554,7 +712,7 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
pa_stream_ref(s);
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(s->context, command, t) < 0)
+ if (pa_context_handle_error(s->context, command, t, FALSE) < 0)
goto finish;
pa_stream_set_state(s, PA_STREAM_FAILED);
@@ -562,7 +720,8 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
}
if (pa_tagstruct_getu32(t, &s->channel) < 0 ||
- ((s->direction != PA_STREAM_UPLOAD) && pa_tagstruct_getu32(t, &s->stream_index) < 0) ||
+ s->channel == PA_INVALID_INDEX ||
+ ((s->direction != PA_STREAM_UPLOAD) && (pa_tagstruct_getu32(t, &s->stream_index) < 0 || s->stream_index == PA_INVALID_INDEX)) ||
((s->direction != PA_STREAM_RECORD) && pa_tagstruct_getu32(t, &s->requested_bytes) < 0)) {
pa_context_fail(s->context, PA_ERR_PROTOCOL);
goto finish;
@@ -590,7 +749,7 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
pa_sample_spec ss;
pa_channel_map cm;
const char *dn = NULL;
- int suspended;
+ pa_bool_t suspended;
if (pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
pa_tagstruct_get_channel_map(t, &cm) < 0 ||
@@ -616,26 +775,22 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
s->device_name = pa_xstrdup(dn);
s->suspended = suspended;
- if (!s->manual_buffer_attr && pa_bytes_per_second(&ss) != pa_bytes_per_second(&s->sample_spec)) {
- pa_buffer_attr attr;
- pa_operation *o;
-
- automatic_buffer_attr(&attr, &ss);
-
- /* If we need to update the buffer metrics, we wait for
- * the the OK for that call before we go to
- * PA_STREAM_READY */
+ s->channel_map = cm;
+ s->sample_spec = ss;
+ }
- s->state = PA_STREAM_READY;
- pa_assert_se(o = pa_stream_set_buffer_attr(s, &attr, NULL, NULL));
- pa_operation_unref(o);
- s->state = PA_STREAM_CREATING;
+ if (s->context->version >= 13 && s->direction != PA_STREAM_UPLOAD) {
+ pa_usec_t usec;
- s->buffer_attr_not_ready = TRUE;
+ if (pa_tagstruct_get_usec(t, &usec) < 0) {
+ pa_context_fail(s->context, PA_ERR_PROTOCOL);
+ goto finish;
}
- s->channel_map = cm;
- s->sample_spec = ss;
+ if (s->direction == PA_STREAM_RECORD)
+ s->timing_info.configured_source_usec = usec;
+ else
+ s->timing_info.configured_sink_usec = usec;
}
if (!pa_tagstruct_eof(t)) {
@@ -653,25 +808,13 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED
pa_frame_size(&s->sample_spec),
1,
0,
+ 0,
NULL);
}
- s->channel_valid = 1;
+ s->channel_valid = TRUE;
pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
- if (s->direction != PA_STREAM_UPLOAD && s->flags & PA_STREAM_AUTO_TIMING_UPDATE) {
-
- /* If automatic timing updates are active, we wait for the
- * first timing update before going to PA_STREAM_READY
- * state */
-
- s->state = PA_STREAM_READY;
- request_auto_timing_update(s, 1);
- s->state = PA_STREAM_CREATING;
-
- s->timing_info_not_ready = TRUE;
- }
-
create_stream_complete(s);
finish:
@@ -692,19 +835,33 @@ static int create_stream(
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ pa_assert(direction == PA_STREAM_PLAYBACK || direction == PA_STREAM_RECORD);
PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_UNCONNECTED, PA_ERR_BADSTATE);
- PA_CHECK_VALIDITY(s->context, !(flags & ~((direction != PA_STREAM_UPLOAD ?
- PA_STREAM_START_CORKED|
- PA_STREAM_INTERPOLATE_TIMING|
- PA_STREAM_NOT_MONOTONOUS|
- PA_STREAM_AUTO_TIMING_UPDATE|
- PA_STREAM_NO_REMAP_CHANNELS|
- PA_STREAM_NO_REMIX_CHANNELS|
- PA_STREAM_FIX_FORMAT|
- PA_STREAM_FIX_RATE|
- PA_STREAM_FIX_CHANNELS|
- PA_STREAM_DONT_MOVE : 0))), PA_ERR_INVALID);
+ PA_CHECK_VALIDITY(s->context, !(flags & ~(PA_STREAM_START_CORKED|
+ PA_STREAM_INTERPOLATE_TIMING|
+ PA_STREAM_NOT_MONOTONOUS|
+ PA_STREAM_AUTO_TIMING_UPDATE|
+ PA_STREAM_NO_REMAP_CHANNELS|
+ PA_STREAM_NO_REMIX_CHANNELS|
+ PA_STREAM_FIX_FORMAT|
+ PA_STREAM_FIX_RATE|
+ PA_STREAM_FIX_CHANNELS|
+ PA_STREAM_DONT_MOVE|
+ PA_STREAM_VARIABLE_RATE|
+ PA_STREAM_PEAK_DETECT|
+ PA_STREAM_START_MUTED|
+ PA_STREAM_ADJUST_LATENCY)), PA_ERR_INVALID);
+
+ PA_CHECK_VALIDITY(s->context, s->context->version >= 12 || !(flags & PA_STREAM_VARIABLE_RATE), PA_ERR_NOTSUPPORTED);
+ PA_CHECK_VALIDITY(s->context, s->context->version >= 13 || !(flags & PA_STREAM_PEAK_DETECT), PA_ERR_NOTSUPPORTED);
+ /* Althought some of the other flags are not supported on older
+ * version, we don't check for them here, because it doesn't hurt
+ * when they are passed but actually not supported. This makes
+ * client development easier */
+
+ PA_CHECK_VALIDITY(s->context, direction != PA_STREAM_PLAYBACK || !(flags & (PA_STREAM_START_MUTED)), PA_ERR_INVALID);
+ PA_CHECK_VALIDITY(s->context, direction != PA_STREAM_RECORD || !(flags & (PA_STREAM_PEAK_DETECT)), PA_ERR_INVALID);
PA_CHECK_VALIDITY(s->context, !volume || volume->channels == s->sample_spec.channels, PA_ERR_INVALID);
PA_CHECK_VALIDITY(s->context, !sync_stream || (direction == PA_STREAM_PLAYBACK && sync_stream->direction == PA_STREAM_PLAYBACK), PA_ERR_INVALID);
@@ -716,17 +873,21 @@ static int create_stream(
if (sync_stream)
s->syncid = sync_stream->syncid;
- if (attr) {
+ if (attr)
s->buffer_attr = *attr;
- s->manual_buffer_attr = TRUE;
- } else {
- /* half a second, with minimum request of 10 ms */
- s->buffer_attr.tlength = pa_bytes_per_second(&s->sample_spec)/2;
- s->buffer_attr.maxlength = (s->buffer_attr.tlength*3)/2;
- s->buffer_attr.minreq = s->buffer_attr.tlength/50;
- s->buffer_attr.prebuf = s->buffer_attr.tlength - s->buffer_attr.minreq;
- s->buffer_attr.fragsize = s->buffer_attr.tlength/50;
- s->manual_buffer_attr = FALSE;
+ automatic_buffer_attr(s, &s->buffer_attr, &s->sample_spec);
+
+ if (flags & PA_STREAM_INTERPOLATE_TIMING) {
+ pa_usec_t x;
+
+ if (s->smoother)
+ pa_smoother_free(s->smoother);
+
+ s->smoother = pa_smoother_new(SMOOTHER_ADJUST_TIME, SMOOTHER_HISTORY_TIME, !(flags & PA_STREAM_NOT_MONOTONOUS), SMOOTHER_MIN_HISTORY);
+
+ x = pa_rtclock_usec();
+ pa_smoother_set_time_offset(s->smoother, x);
+ pa_smoother_pause(s->smoother, x);
}
if (!dev)
@@ -737,9 +898,11 @@ static int create_stream(
s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM,
&tag);
+ if (s->context->version < 13)
+ pa_tagstruct_puts(t, pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME));
+
pa_tagstruct_put(
t,
- PA_TAG_STRING, s->name,
PA_TAG_SAMPLE_SPEC, &s->sample_spec,
PA_TAG_CHANNEL_MAP, &s->channel_map,
PA_TAG_U32, PA_INVALID_INDEX,
@@ -766,7 +929,7 @@ static int create_stream(
} else
pa_tagstruct_putu32(t, s->buffer_attr.fragsize);
- if (s->context->version >= 12 && s->direction != PA_STREAM_UPLOAD) {
+ if (s->context->version >= 12) {
pa_tagstruct_put(
t,
PA_TAG_BOOLEAN, flags & PA_STREAM_NO_REMAP_CHANNELS,
@@ -779,6 +942,20 @@ static int create_stream(
PA_TAG_INVALID);
}
+ if (s->context->version >= 13) {
+
+ if (s->direction == PA_STREAM_PLAYBACK)
+ pa_tagstruct_put_boolean(t, flags & PA_STREAM_START_MUTED);
+ else
+ pa_tagstruct_put_boolean(t, flags & PA_STREAM_PEAK_DETECT);
+
+ pa_tagstruct_put(
+ t,
+ PA_TAG_BOOLEAN, flags & PA_STREAM_ADJUST_LATENCY,
+ PA_TAG_PROPLIST, s->proplist,
+ 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);
@@ -823,6 +1000,10 @@ int pa_stream_write(
pa_seek_mode_t seek) {
pa_memchunk chunk;
+ pa_seek_mode_t t_seek;
+ int64_t t_offset;
+ size_t t_length;
+ const void *t_data;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@@ -836,21 +1017,42 @@ int pa_stream_write(
if (length <= 0)
return 0;
- if (free_cb)
- chunk.memblock = pa_memblock_new_user(s->context->mempool, (void*) data, length, free_cb, 1);
- else {
- void *tdata;
- chunk.memblock = pa_memblock_new(s->context->mempool, length);
- tdata = pa_memblock_acquire(chunk.memblock);
- memcpy(tdata, data, length);
- pa_memblock_release(chunk.memblock);
- }
+ t_seek = seek;
+ t_offset = offset;
+ t_length = length;
+ t_data = data;
+
+ while (t_length > 0) {
+
+ chunk.index = 0;
+
+ if (free_cb && !pa_pstream_get_shm(s->context->pstream)) {
+ chunk.memblock = pa_memblock_new_user(s->context->mempool, (void*) t_data, t_length, free_cb, 1);
+ chunk.length = t_length;
+ } else {
+ void *d;
+
+ chunk.length = PA_MIN(t_length, pa_mempool_block_size_max(s->context->mempool));
+ chunk.memblock = pa_memblock_new(s->context->mempool, chunk.length);
+
+ d = pa_memblock_acquire(chunk.memblock);
+ memcpy(d, t_data, chunk.length);
+ pa_memblock_release(chunk.memblock);
+ }
- chunk.index = 0;
- chunk.length = length;
+ pa_pstream_send_memblock(s->context->pstream, s->channel, t_offset, t_seek, &chunk);
- pa_pstream_send_memblock(s->context->pstream, s->channel, offset, seek, &chunk);
- pa_memblock_unref(chunk.memblock);
+ t_offset = 0;
+ t_seek = PA_SEEK_RELATIVE;
+
+ t_data = (const uint8_t*) t_data + chunk.length;
+ t_length -= chunk.length;
+
+ pa_memblock_unref(chunk.memblock);
+ }
+
+ if (free_cb && pa_pstream_get_shm(s->context->pstream))
+ free_cb((void*) data);
if (length < s->requested_bytes)
s->requested_bytes -= length;
@@ -863,31 +1065,31 @@ int pa_stream_write(
if (s->write_index_corrections[s->current_write_index_correction].valid) {
if (seek == PA_SEEK_ABSOLUTE) {
- s->write_index_corrections[s->current_write_index_correction].corrupt = 0;
- s->write_index_corrections[s->current_write_index_correction].absolute = 1;
+ 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;
} 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;
} else
- s->write_index_corrections[s->current_write_index_correction].corrupt = 1;
+ s->write_index_corrections[s->current_write_index_correction].corrupt = TRUE;
}
/* Update the write index in the already available latency data */
if (s->timing_info_valid) {
if (seek == PA_SEEK_ABSOLUTE) {
- s->timing_info.write_index_corrupt = 0;
+ s->timing_info.write_index_corrupt = FALSE;
s->timing_info.write_index = offset + length;
} else if (seek == PA_SEEK_RELATIVE) {
if (!s->timing_info.write_index_corrupt)
s->timing_info.write_index += offset + length;
} else
- s->timing_info.write_index_corrupt = 1;
+ s->timing_info.write_index_corrupt = TRUE;
}
if (!s->timing_info_valid || s->timing_info.write_index_corrupt)
- request_auto_timing_update(s, 1);
+ request_auto_timing_update(s, TRUE);
}
return 0;
@@ -936,9 +1138,7 @@ int pa_stream_drop(pa_stream *s) {
pa_assert(s->peek_data);
pa_memblock_release(s->peek_memchunk.memblock);
pa_memblock_unref(s->peek_memchunk.memblock);
- s->peek_memchunk.length = 0;
- s->peek_memchunk.index = 0;
- s->peek_memchunk.memblock = NULL;
+ pa_memchunk_reset(&s->peek_memchunk);
return 0;
}
@@ -984,10 +1184,71 @@ pa_operation * pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *us
return o;
}
+static pa_usec_t calc_time(pa_stream *s, pa_bool_t ignore_transport) {
+ pa_usec_t usec;
+
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ pa_assert(s->state == PA_STREAM_READY);
+ pa_assert(s->direction != PA_STREAM_UPLOAD);
+ pa_assert(s->timing_info_valid);
+ pa_assert(s->direction != PA_STREAM_PLAYBACK || !s->timing_info.read_index_corrupt);
+ pa_assert(s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt);
+
+ if (s->direction == PA_STREAM_PLAYBACK) {
+ /* The last byte that was written into the output device
+ * had this time value associated */
+ usec = pa_bytes_to_usec(s->timing_info.read_index < 0 ? 0 : (uint64_t) s->timing_info.read_index, &s->sample_spec);
+
+ if (!s->corked && !s->suspended) {
+
+ if (!ignore_transport)
+ /* Because the latency info took a little time to come
+ * to us, we assume that the real output time is actually
+ * a little ahead */
+ usec += s->timing_info.transport_usec;
+
+ /* However, the output device usually maintains a buffer
+ too, hence the real sample currently played is a little
+ back */
+ if (s->timing_info.sink_usec >= usec)
+ usec = 0;
+ else
+ usec -= s->timing_info.sink_usec;
+ }
+
+ } else if (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);
+
+ if (!s->corked && !s->suspended) {
+
+ if (!ignore_transport)
+ /* Add transport latency */
+ usec += s->timing_info.transport_usec;
+
+ /* Add latency of data in device buffer */
+ usec += s->timing_info.source_usec;
+
+ /* If this is a monitor source, we need to correct the
+ * time by the playback device buffer */
+ if (s->timing_info.sink_usec >= usec)
+ usec = 0;
+ else
+ usec -= s->timing_info.sink_usec;
+ }
+ }
+
+ return usec;
+}
+
static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata;
struct timeval local, remote, now;
pa_timing_info *i;
+ pa_bool_t playing = FALSE;
+ uint64_t underrun_for = 0, playing_for = 0;
pa_assert(pd);
pa_assert(o);
@@ -1000,29 +1261,48 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
/* pa_log("pre corrupt w:%u r:%u\n", !o->stream->timing_info_valid || i->write_index_corrupt,!o->stream->timing_info_valid || i->read_index_corrupt); */
- o->stream->timing_info_valid = 0;
- i->write_index_corrupt = 0;
- i->read_index_corrupt = 0;
+ o->stream->timing_info_valid = FALSE;
+ i->write_index_corrupt = FALSE;
+ i->read_index_corrupt = FALSE;
/* pa_log("timing update %u\n", tag); */
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
- } else if (pa_tagstruct_get_usec(t, &i->sink_usec) < 0 ||
- pa_tagstruct_get_usec(t, &i->source_usec) < 0 ||
- pa_tagstruct_get_boolean(t, &i->playing) < 0 ||
- pa_tagstruct_get_timeval(t, &local) < 0 ||
- pa_tagstruct_get_timeval(t, &remote) < 0 ||
- pa_tagstruct_gets64(t, &i->write_index) < 0 ||
- pa_tagstruct_gets64(t, &i->read_index) < 0 ||
- !pa_tagstruct_eof(t)) {
- pa_context_fail(o->context, PA_ERR_PROTOCOL);
- goto finish;
-
} else {
- o->stream->timing_info_valid = 1;
+
+ if (pa_tagstruct_get_usec(t, &i->sink_usec) < 0 ||
+ pa_tagstruct_get_usec(t, &i->source_usec) < 0 ||
+ pa_tagstruct_get_boolean(t, &playing) < 0 ||
+ pa_tagstruct_get_timeval(t, &local) < 0 ||
+ pa_tagstruct_get_timeval(t, &remote) < 0 ||
+ pa_tagstruct_gets64(t, &i->write_index) < 0 ||
+ pa_tagstruct_gets64(t, &i->read_index) < 0) {
+
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ if (o->context->version >= 13 &&
+ o->stream->direction == PA_STREAM_PLAYBACK)
+ if (pa_tagstruct_getu64(t, &underrun_for) < 0 ||
+ pa_tagstruct_getu64(t, &playing_for) < 0) {
+
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+
+ if (!pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERR_PROTOCOL);
+ goto finish;
+ }
+
+ o->stream->timing_info_valid = TRUE;
+ i->playing = (int) playing;
+ i->since_underrun = playing ? playing_for : underrun_for;
pa_gettimeofday(&now);
@@ -1035,22 +1315,22 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
else
i->transport_usec = pa_timeval_diff(&now, &remote);
- i->synchronized_clocks = 1;
+ i->synchronized_clocks = TRUE;
i->timestamp = remote;
} else {
/* clocks are not synchronized, let's estimate latency then */
i->transport_usec = pa_timeval_diff(&now, &local)/2;
- i->synchronized_clocks = 0;
+ i->synchronized_clocks = FALSE;
i->timestamp = local;
pa_timeval_add(&i->timestamp, i->transport_usec);
}
/* Invalidate read and write indexes if necessary */
if (tag < o->stream->read_index_not_before)
- i->read_index_corrupt = 1;
+ i->read_index_corrupt = TRUE;
if (tag < o->stream->write_index_not_before)
- i->write_index_corrupt = 1;
+ i->write_index_corrupt = TRUE;
if (o->stream->direction == PA_STREAM_PLAYBACK) {
/* Write index correction */
@@ -1076,11 +1356,11 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
if (o->stream->write_index_corrections[j].corrupt) {
/* A corrupting seek was made */
i->write_index = 0;
- i->write_index_corrupt = 1;
+ i->write_index_corrupt = TRUE;
} else if (o->stream->write_index_corrections[j].absolute) {
/* An absolute seek was made */
i->write_index = o->stream->write_index_corrections[j].value;
- i->write_index_corrupt = 0;
+ i->write_index_corrupt = FALSE;
} else if (!i->write_index_corrupt) {
/* A relative seek was made */
i->write_index += o->stream->write_index_corrections[j].value;
@@ -1095,31 +1375,57 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
i->read_index -= pa_memblockq_get_length(o->stream->record_memblockq);
}
- o->stream->cached_time_valid = 0;
- }
-
- o->stream->auto_timing_update_requested = 0;
/* pa_log("post corrupt w:%u r:%u\n", i->write_index_corrupt || !o->stream->timing_info_valid, i->read_index_corrupt || !o->stream->timing_info_valid); */
- /* Clear old correction entries */
- if (o->stream->direction == PA_STREAM_PLAYBACK) {
- int n;
+ /* Clear old correction entries */
+ if (o->stream->direction == PA_STREAM_PLAYBACK) {
+ int n;
- for (n = 0; n < PA_MAX_WRITE_INDEX_CORRECTIONS; n++) {
- if (!o->stream->write_index_corrections[n].valid)
- continue;
+ for (n = 0; n < PA_MAX_WRITE_INDEX_CORRECTIONS; n++) {
+ if (!o->stream->write_index_corrections[n].valid)
+ continue;
- if (o->stream->write_index_corrections[n].tag <= tag)
- o->stream->write_index_corrections[n].valid = 0;
+ if (o->stream->write_index_corrections[n].tag <= tag)
+ o->stream->write_index_corrections[n].valid = FALSE;
+ }
}
- }
- /* First, let's complete the initialization, if necessary. */
- if (o->stream->state == PA_STREAM_CREATING) {
- o->stream->timing_info_not_ready = FALSE;
- create_stream_complete(o->stream);
+ /* Update smoother */
+ if (o->stream->smoother) {
+ pa_usec_t u, x;
+
+ u = x = pa_rtclock_usec() - i->transport_usec;
+
+ if (o->stream->direction == PA_STREAM_PLAYBACK &&
+ o->context->version >= 13) {
+ pa_usec_t su;
+
+ /* If we weren't playing then it will take some time
+ * until the audio will actually come out through the
+ * 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);
+
+ if (su < i->sink_usec)
+ x += i->sink_usec - su;
+ }
+
+ if (!i->playing)
+ pa_smoother_pause(o->stream->smoother, x);
+
+ /* Update the smoother */
+ if ((o->stream->direction == PA_STREAM_PLAYBACK && !i->read_index_corrupt) ||
+ (o->stream->direction == PA_STREAM_RECORD && !i->write_index_corrupt))
+ pa_smoother_put(o->stream->smoother, u, calc_time(o->stream, TRUE));
+
+ if (i->playing)
+ pa_smoother_resume(o->stream->smoother, x);
+ }
}
+ o->stream->auto_timing_update_requested = FALSE;
+
if (o->stream->latency_update_callback)
o->stream->latency_update_callback(o->stream, o->stream->latency_update_userdata);
@@ -1168,15 +1474,15 @@ pa_operation* pa_stream_update_timing_info(pa_stream *s, pa_stream_success_cb_t
if (s->direction == PA_STREAM_PLAYBACK) {
/* Fill in initial correction data */
- o->stream->current_write_index_correction = cidx;
- o->stream->write_index_corrections[cidx].valid = 1;
- o->stream->write_index_corrections[cidx].tag = tag;
- o->stream->write_index_corrections[cidx].absolute = 0;
- o->stream->write_index_corrections[cidx].value = 0;
- o->stream->write_index_corrections[cidx].corrupt = 0;
- }
-/* pa_log("requesting update %u\n", tag); */
+ s->current_write_index_correction = cidx;
+
+ s->write_index_corrections[cidx].valid = TRUE;
+ s->write_index_corrections[cidx].absolute = FALSE;
+ s->write_index_corrections[cidx].corrupt = FALSE;
+ s->write_index_corrections[cidx].tag = tag;
+ s->write_index_corrections[cidx].value = 0;
+ }
return o;
}
@@ -1191,7 +1497,7 @@ void pa_stream_disconnect_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UN
pa_stream_ref(s);
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(s->context, command, t) < 0)
+ if (pa_context_handle_error(s->context, command, t, FALSE) < 0)
goto finish;
pa_stream_set_state(s, PA_STREAM_FAILED);
@@ -1236,6 +1542,9 @@ void pa_stream_set_read_callback(pa_stream *s, pa_stream_request_cb_t cb, void *
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->read_callback = cb;
s->read_userdata = userdata;
}
@@ -1244,6 +1553,9 @@ void pa_stream_set_write_callback(pa_stream *s, pa_stream_request_cb_t cb, void
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->write_callback = cb;
s->write_userdata = userdata;
}
@@ -1252,6 +1564,9 @@ void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->state_callback = cb;
s->state_userdata = userdata;
}
@@ -1260,6 +1575,9 @@ void pa_stream_set_overflow_callback(pa_stream *s, pa_stream_notify_cb_t cb, voi
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->overflow_callback = cb;
s->overflow_userdata = userdata;
}
@@ -1268,6 +1586,9 @@ void pa_stream_set_underflow_callback(pa_stream *s, pa_stream_notify_cb_t cb, vo
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->underflow_callback = cb;
s->underflow_userdata = userdata;
}
@@ -1276,6 +1597,9 @@ void pa_stream_set_latency_update_callback(pa_stream *s, pa_stream_notify_cb_t c
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->latency_update_callback = cb;
s->latency_update_userdata = userdata;
}
@@ -1284,6 +1608,9 @@ void pa_stream_set_moved_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->moved_callback = cb;
s->moved_userdata = userdata;
}
@@ -1292,10 +1619,24 @@ void pa_stream_set_suspended_callback(pa_stream *s, pa_stream_notify_cb_t cb, vo
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
s->suspended_callback = cb;
s->suspended_userdata = userdata;
}
+void pa_stream_set_started_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ if (s->state == PA_STREAM_TERMINATED || s->state == PA_STREAM_FAILED)
+ return;
+
+ s->started_callback = cb;
+ 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) {
pa_operation *o = userdata;
int success = 1;
@@ -1308,7 +1649,7 @@ void pa_stream_simple_ack_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UN
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
success = 0;
@@ -1351,8 +1692,18 @@ pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, voi
pa_pstream_send_tagstruct(s->context->pstream, t);
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+ if (s->smoother) {
+ pa_usec_t x = pa_rtclock_usec();
+
+ if (s->timing_info_valid)
+ x += s->timing_info.transport_usec;
+
+ if (s->suspended || s->corked)
+ pa_smoother_pause(s->smoother, x);
+ }
+
if (s->direction == PA_STREAM_PLAYBACK)
- invalidate_indexes(s, 1, 0);
+ invalidate_indexes(s, TRUE, FALSE);
return o;
}
@@ -1383,23 +1734,34 @@ pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *use
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ 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 (s->direction == PA_STREAM_PLAYBACK) {
if (s->write_index_corrections[s->current_write_index_correction].valid)
- s->write_index_corrections[s->current_write_index_correction].corrupt = 1;
+ s->write_index_corrections[s->current_write_index_correction].corrupt = TRUE;
if (s->timing_info_valid)
- s->timing_info.write_index_corrupt = 1;
+ s->timing_info.write_index_corrupt = TRUE;
if (s->buffer_attr.prebuf > 0)
- invalidate_indexes(s, 1, 0);
+ invalidate_indexes(s, TRUE, FALSE);
else
- request_auto_timing_update(s, 1);
+ request_auto_timing_update(s, TRUE);
+
+ if (s->smoother && s->buffer_attr.prebuf > 0) {
+ pa_usec_t x = pa_rtclock_usec();
+
+ if (s->timing_info_valid)
+ x += s->timing_info.transport_usec;
+
+ pa_smoother_pause(s->smoother, x);
+ }
+
} else
- invalidate_indexes(s, 0, 1);
+ invalidate_indexes(s, FALSE, TRUE);
}
return o;
@@ -1411,11 +1773,12 @@ pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *us
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ 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_PLAYBACK, PA_ERR_BADSTATE);
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->buffer_attr.prebuf > 0, PA_ERR_BADSTATE);
if ((o = stream_send_simple_command(s, PA_COMMAND_PREBUF_PLAYBACK_STREAM, cb, userdata)))
- invalidate_indexes(s, 1, 0);
+ invalidate_indexes(s, TRUE, FALSE);
return o;
}
@@ -1426,19 +1789,18 @@ pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *u
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
+ 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_PLAYBACK, PA_ERR_BADSTATE);
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->buffer_attr.prebuf > 0, PA_ERR_BADSTATE);
if ((o = stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata)))
- invalidate_indexes(s, 1, 0);
+ invalidate_indexes(s, TRUE, FALSE);
return o;
}
pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata) {
pa_operation *o;
- pa_tagstruct *t;
- uint32_t tag;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@@ -1447,22 +1809,32 @@ pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_succe
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);
- o = pa_operation_new(s->context, s, (pa_operation_cb_t) cb, userdata);
+ if (s->context->version >= 13) {
+ pa_proplist *p = pa_proplist_new();
- t = pa_tagstruct_command(
- s->context,
- 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);
- pa_pstream_send_tagstruct(s->context->pstream, t);
- pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+ pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, name);
+ o = pa_stream_proplist_update(s, PA_UPDATE_REPLACE, p, cb, userdata);
+ pa_proplist_free(p);
+ } else {
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ 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,
+ &tag);
+ pa_tagstruct_putu32(t, s->channel);
+ pa_tagstruct_puts(t, name);
+ pa_pstream_send_tagstruct(s->context->pstream, t);
+ pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+ }
return o;
}
int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) {
- pa_usec_t usec = 0;
+ pa_usec_t usec;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@@ -1473,65 +1845,10 @@ int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) {
PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_PLAYBACK || !s->timing_info.read_index_corrupt, PA_ERR_NODATA);
PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt, PA_ERR_NODATA);
- if (s->cached_time_valid)
- /* We alredy calculated the time value for this timing info, so let's reuse it */
- usec = s->cached_time;
- else {
- if (s->direction == PA_STREAM_PLAYBACK) {
- /* The last byte that was written into the output device
- * had this time value associated */
- usec = pa_bytes_to_usec(s->timing_info.read_index < 0 ? 0 : (uint64_t) s->timing_info.read_index, &s->sample_spec);
-
- if (!s->corked) {
- /* Because the latency info took a little time to come
- * to us, we assume that the real output time is actually
- * a little ahead */
- usec += s->timing_info.transport_usec;
-
- /* However, the output device usually maintains a buffer
- too, hence the real sample currently played is a little
- back */
- if (s->timing_info.sink_usec >= usec)
- usec = 0;
- else
- usec -= s->timing_info.sink_usec;
- }
-
- } else if (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);
-
- if (!s->corked) {
- /* Add transport latency */
- usec += s->timing_info.transport_usec;
-
- /* Add latency of data in device buffer */
- usec += s->timing_info.source_usec;
-
- /* If this is a monitor source, we need to correct the
- * time by the playback device buffer */
- if (s->timing_info.sink_usec >= usec)
- usec = 0;
- else
- usec -= s->timing_info.sink_usec;
- }
- }
-
- s->cached_time = usec;
- s->cached_time_valid = 1;
- }
-
- /* Interpolate if requested */
- if (s->flags & PA_STREAM_INTERPOLATE_TIMING) {
-
- /* We just add the time that passed since the latency info was
- * current */
- if (!s->corked && s->timing_info.playing) {
- struct timeval now;
- usec += pa_timeval_diff(pa_gettimeofday(&now), &s->timing_info.timestamp);
- }
- }
+ if (s->smoother)
+ usec = pa_smoother_get(s->smoother, pa_rtclock_usec());
+ else
+ usec = calc_time(s, FALSE);
/* Make sure the time runs monotonically */
if (!(s->flags & PA_STREAM_NOT_MONOTONOUS)) {
@@ -1632,7 +1949,7 @@ const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s) {
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);
- PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 9, PA_ERR_NODATA);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 9, PA_ERR_NOTSUPPORTED);
return &s->buffer_attr;
}
@@ -1649,7 +1966,7 @@ static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command,
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
success = 0;
@@ -1675,13 +1992,6 @@ static void stream_set_buffer_attr_callback(pa_pdispatch *pd, uint32_t command,
pa_context_fail(o->context, PA_ERR_PROTOCOL);
goto finish;
}
-
- o->stream->manual_buffer_attr = TRUE;
- }
-
- if (o->stream->state == PA_STREAM_CREATING) {
- o->stream->buffer_attr_not_ready = FALSE;
- create_stream_complete(o->stream);
}
if (o->callback) {
@@ -1728,6 +2038,9 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr
else
pa_tagstruct_putu32(t, attr->fragsize);
+ if (s->context->version >= 13)
+ pa_tagstruct_put_boolean(t, !!(s->flags & PA_STREAM_ADJUST_LATENCY));
+
pa_pstream_send_tagstruct(s->context->pstream, t);
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_set_buffer_attr_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
@@ -1769,6 +2082,16 @@ int pa_stream_is_suspended(pa_stream *s) {
return s->suspended;
}
+int pa_stream_is_corked(pa_stream *s) {
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE);
+ PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
+
+ 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) {
pa_operation *o = userdata;
int success = 1;
@@ -1781,7 +2104,7 @@ static void stream_update_sample_rate_callback(pa_pdispatch *pd, uint32_t comman
goto finish;
if (command != PA_COMMAND_REPLY) {
- if (pa_context_handle_error(o->context, command, t) < 0)
+ if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
goto finish;
success = 0;
@@ -1835,5 +2158,72 @@ pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_strea
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_update_sample_rate_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
return o;
+}
+
+pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, mode == PA_UPDATE_SET || mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE, PA_ERR_INVALID);
+ 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);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 13, PA_ERR_NOTSUPPORTED);
+
+ 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_UPDATE_RECORD_STREAM_PROPLIST : PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST,
+ &tag);
+ pa_tagstruct_putu32(t, s->channel);
+ pa_tagstruct_putu32(t, (uint32_t) mode);
+ pa_tagstruct_put_proplist(t, p);
+
+ pa_pstream_send_tagstruct(s->context->pstream, t);
+ pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ /* Please note that we don't update s->proplist here, because we
+ * don't export that field */
+
+ return o;
+}
+
+pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata) {
+ pa_operation *o;
+ pa_tagstruct *t;
+ uint32_t tag;
+ const char * const*k;
+
+ pa_assert(s);
+ pa_assert(PA_REFCNT_VALUE(s) >= 1);
+
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, keys && keys[0], PA_ERR_INVALID);
+ 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);
+ PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->context->version >= 13, PA_ERR_NOTSUPPORTED);
+ 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_REMOVE_RECORD_STREAM_PROPLIST : PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST,
+ &tag);
+ pa_tagstruct_putu32(t, s->channel);
+
+ for (k = keys; *k; k++)
+ pa_tagstruct_puts(t, *k);
+
+ pa_tagstruct_puts(t, NULL);
+
+ pa_pstream_send_tagstruct(s->context->pstream, t);
+ pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+ /* Please note that we don't update s->proplist here, because we
+ * don't export that field */
+
+ return o;
}
diff --git a/src/pulse/stream.h b/src/pulse/stream.h
index 85473227..ebb45f2b 100644
--- a/src/pulse/stream.h
+++ b/src/pulse/stream.h
@@ -276,13 +276,25 @@ typedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t bytes, void *userdat
/** A generic notification callback */
typedef void (*pa_stream_notify_cb_t)(pa_stream *p, void *userdata);
-/** Create a new, unconnected stream with the specified name and sample type */
+/** Create a new, unconnected stream with the specified name and
+ * sample type. It is recommended to use pa_stream_new_with_proplist()
+ * instead and specify some initial properties. */
pa_stream* pa_stream_new(
pa_context *c /**< The context to create this stream in */,
const char *name /**< A name for this stream */,
const pa_sample_spec *ss /**< The desired sample format */,
const pa_channel_map *map /**< The desired channel map, or NULL for default */);
+/** Create a new, unconnected stream with the specified name and
+ * sample type, and specify the the initial stream property
+ * list. \since 0.9.11 */
+pa_stream* pa_stream_new_with_proplist(
+ pa_context *c /**< The context to create this stream in */,
+ const char *name /**< A name for this stream */,
+ const pa_sample_spec *ss /**< The desired sample format */,
+ const pa_channel_map *map /**< The desired channel map, or NULL for default */,
+ pa_proplist *p /**< The initial property list */);
+
/** Decrease the reference counter by one */
void pa_stream_unref(pa_stream *s);
@@ -327,6 +339,10 @@ const char *pa_stream_get_device_name(pa_stream *s);
* server is older than 0.9.8. \since 0.9.8 */
int pa_stream_is_suspended(pa_stream *s);
+/** Return 1 if the this stream has been corked. This will return 0 if
+ * not, and negative on error. \since 0.9.11 */
+int pa_stream_is_corked(pa_stream *s);
+
/** Connect the stream to a sink */
int pa_stream_connect_playback(
pa_stream *s /**< The stream to connect to a sink */,
@@ -356,7 +372,7 @@ int pa_stream_disconnect(pa_stream *s);
int pa_stream_write(
pa_stream *p /**< The stream to use */,
const void *data /**< The data to write */,
- size_t bytes /**< The length of the data to write in bytes*/,
+ size_t nbytes /**< The length of the data to write in bytes*/,
pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */,
int64_t offset, /**< Offset for seeking, must be 0 for upload streams */
pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */);
@@ -365,20 +381,20 @@ int pa_stream_write(
* data will point to the actual data and length will contain the size
* of the data in bytes (which can be less than a complete framgnet).
* Use pa_stream_drop() to actually remove the data from the
- * buffer. If no data is available will return a NULL pointer \since 0.8 */
+ * buffer. If no data is available will return a NULL pointer */
int pa_stream_peek(
pa_stream *p /**< The stream to use */,
const void **data /**< Pointer to pointer that will point to data */,
- size_t *bytes /**< The length of the data read in bytes */);
+ size_t *nbytes /**< The length of the data read in bytes */);
/** Remove the current fragment on record streams. It is invalid to do this without first
- * calling pa_stream_peek(). \since 0.8 */
+ * calling pa_stream_peek(). */
int pa_stream_drop(pa_stream *p);
/** Return the number of bytes that may be written using pa_stream_write() */
size_t pa_stream_writable_size(pa_stream *p);
-/** Return the number of bytes that may be read using pa_stream_read() \since 0.8 */
+/** Return the number of bytes that may be read using pa_stream_read()*/
size_t pa_stream_readable_size(pa_stream *p);
/** Drain a playback stream. Use this for notification when the buffer is empty */
@@ -398,18 +414,25 @@ void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *
void pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
/** Set the callback function that is called when new data is available from the stream.
- * Return the number of bytes read. \since 0.8 */
+ * Return the number of bytes read.*/
void pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
-/** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) \since 0.8 */
+/** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) */
void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
-/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) \since 0.8 */
+/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) */
void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
+/** Set the callback function that is called when a the server starts
+ * playback after an underrun or on initial startup. This only informs
+ * that audio is flowing again, it is no indication that audio startet
+ * to reach the speakers already. (Only for playback streams). \since
+ * 0.9.11 */
+void pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
+
/** Set the callback function that is called whenever a latency
* information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE
- * streams only. (Only for playback streams) \since 0.8.2 */
+ * streams only. (Only for playback streams) */
void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
/** Set the callback function that is called whenever the stream is
@@ -429,24 +452,25 @@ void pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *
* 0.9.8. \since 0.9.8 */
void pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
-/** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. \since 0.3 */
+/** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. */
pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);
/** Flush the playback buffer of this stream. Most of the time you're
- * better off using the parameter delta of pa_stream_write() instead of this
- * function. Available on both playback and recording streams. \since 0.3 */
+ * better off using the parameter delta of pa_stream_write() instead
+ * of this function. Available on both playback and recording
+ * streams. */
pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
/** Reenable prebuffering as specified in the pa_buffer_attr
- * structure. Available for playback streams only. \since 0.6 */
+ * structure. Available for playback streams only. */
pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
/** Request immediate start of playback on this stream. This disables
- * prebuffering as specified in the pa_buffer_attr
- * structure, temporarily. Available for playback streams only. \since 0.3 */
+ * prebuffering as specified in the pa_buffer_attr structure,
+ * temporarily. Available for playback streams only. */
pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
-/** Rename the stream. \since 0.5 */
+/** Rename the stream. */
pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata);
/** Return the current playback/recording time. This is based on the
@@ -463,13 +487,13 @@ pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_succe
* be disabled by using PA_STREAM_NOT_MONOTONOUS. This may be
* desirable to deal better with bad estimations of transport
* latencies, but may have strange effects if the application is not
- * able to deal with time going 'backwards'. \since 0.6 */
+ * able to deal with time going 'backwards'. */
int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec);
/** Return the total stream latency. This function is based on
* pa_stream_get_time(). In case the stream is a monitoring stream the
* result can be negative, i.e. the captured samples are not yet
- * played. In this case *negative is set to 1. \since 0.6 */
+ * played. In this case *negative is set to 1. */
int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative);
/** Return the latest raw timing data structure. The returned pointer
@@ -481,13 +505,13 @@ int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative);
* function will fail with PA_ERR_NODATA. Please note that the
* write_index member field (and only this field) is updated on each
* pa_stream_write() call, not just when a timing update has been
- * recieved. \since 0.8 */
+ * recieved. */
const pa_timing_info* pa_stream_get_timing_info(pa_stream *s);
-/** Return a pointer to the stream's sample specification. \since 0.6 */
+/** Return a pointer to the stream's sample specification. */
const pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s);
-/** Return a pointer to the stream's channel map. \since 0.8 */
+/** Return a pointer to the stream's channel map. */
const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
/** Return the buffer metrics of the stream. Only valid after the
@@ -510,6 +534,18 @@ pa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr
* is at least PulseAudio 0.9.8. \since 0.9.8 */
pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata);
+/* Update the property list of the sink input/source output of this
+ * stream, adding new entries. Please note that it is highly
+ * recommended to set as much properties initially via
+ * pa_stream_new_with_proplist() as possible instead a posteriori with
+ * this function, since that information may then be used to route
+ * this stream to the right device. \since 0.9.11 */
+pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata);
+
+/* Update the property list of the sink input/source output of this
+ * stream, remove entries. \since 0.9.11 */
+pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata);
+
PA_C_DECL_END
#endif
diff --git a/src/pulse/subscribe.c b/src/pulse/subscribe.c
index 580038cc..0c5686b7 100644
--- a/src/pulse/subscribe.c
+++ b/src/pulse/subscribe.c
@@ -27,7 +27,8 @@
#include <stdio.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
+
#include <pulsecore/macro.h>
#include <pulsecore/pstream-util.h>
@@ -87,6 +88,9 @@ void pa_context_set_subscribe_callback(pa_context *c, pa_context_subscribe_cb_t
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
+ if (c->state == PA_CONTEXT_TERMINATED || c->state == PA_CONTEXT_FAILED)
+ return;
+
c->subscribe_callback = cb;
c->subscribe_userdata = userdata;
}
diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index 70ceb71e..180e0159 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -148,6 +148,24 @@ struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
return tv;
}
+struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v) {
+ unsigned long secs;
+ pa_assert(tv);
+
+ secs = (unsigned long) (v/PA_USEC_PER_SEC);
+ tv->tv_sec -= 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;
+ }
+
+ return tv;
+}
+
struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) {
pa_assert(tv);
diff --git a/src/pulse/timeval.h b/src/pulse/timeval.h
index 65a0e513..09d53974 100644
--- a/src/pulse/timeval.h
+++ b/src/pulse/timeval.h
@@ -26,6 +26,7 @@
***/
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
#include <pulse/sample.h>
/** \file
@@ -37,6 +38,8 @@ PA_C_DECL_BEGIN
#define PA_USEC_PER_SEC 1000000
#define PA_NSEC_PER_SEC 1000000000
#define PA_USEC_PER_MSEC 1000
+#define PA_NSEC_PER_MSEC 1000000
+#define PA_NSEC_PER_USEC 1000
struct timeval;
@@ -54,7 +57,10 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) PA_GCC_PURE
pa_usec_t pa_timeval_age(const struct timeval *tv);
/** Add the specified time inmicroseconds to the specified timeval structure */
-struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) PA_GCC_PURE;
+struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v);
+
+/** Subtract the specified time inmicroseconds to the specified timeval structure. \since 0.9.11 */
+struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v);
/** Store the specified uec value in the timeval struct. \since 0.9.7 */
struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v);
diff --git a/src/pulse/utf8.h b/src/pulse/utf8.h
index 1e08047c..840c74e0 100644
--- a/src/pulse/utf8.h
+++ b/src/pulse/utf8.h
@@ -26,6 +26,7 @@
***/
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
/** \file
* UTF8 Validation functions
diff --git a/src/pulse/util.h b/src/pulse/util.h
index 764678e5..666ccce4 100644
--- a/src/pulse/util.h
+++ b/src/pulse/util.h
@@ -28,6 +28,7 @@
#include <stddef.h>
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
/** \file
* Assorted utility functions */
diff --git a/src/pulse/version.h.in b/src/pulse/version.h.in
index 20c7a9c0..dc0f8e3b 100644
--- a/src/pulse/version.h.in
+++ b/src/pulse/version.h.in
@@ -8,17 +8,17 @@
Copyright 2004-2006 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
-
+
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
@@ -39,7 +39,8 @@ a macro and not a function, so it is impossible to get the pointer of
it. */
#define pa_get_headers_version() ("@PACKAGE_VERSION@")
-/** Return the version of the library the current application is linked to. */
+/** Return the version of the library the current application is
+ * linked to. */
const char* pa_get_library_version(void);
/** The current API version. Version 6 relates to Polypaudio
@@ -47,8 +48,8 @@ const char* pa_get_library_version(void);
* PA_API_VERSION undefined. */
#define PA_API_VERSION @PA_API_VERSION@
-/** The current protocol version. Version 8 relates to Polypaudio 0.8/PulseAudio 0.9.
- * \since 0.8 */
+/** The current protocol version. Version 8 relates to Polypaudio
+ * 0.8/PulseAudio 0.9. */
#define PA_PROTOCOL_VERSION @PA_PROTOCOL_VERSION@
PA_C_DECL_END
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index 3688b847..33ab1c5f 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -80,10 +80,10 @@ 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));
}
-#define USER_DECIBEL_RANGE 30
+#define USER_DECIBEL_RANGE 60
pa_volume_t pa_sw_volume_from_dB(double dB) {
- if (dB <= -USER_DECIBEL_RANGE)
+ if (isinf(dB) < 0 || dB <= -USER_DECIBEL_RANGE)
return PA_VOLUME_MUTED;
return (pa_volume_t) ((dB/USER_DECIBEL_RANGE+1)*PA_VOLUME_NORM);
diff --git a/src/pulse/volume.h b/src/pulse/volume.h
index 22e5b8a4..e7ceb0d7 100644
--- a/src/pulse/volume.h
+++ b/src/pulse/volume.h
@@ -26,7 +26,9 @@
***/
#include <inttypes.h>
+
#include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
#include <pulse/sample.h>
/** \page volume Volume Control
@@ -101,10 +103,10 @@ PA_C_DECL_BEGIN
typedef uint32_t pa_volume_t;
/** Normal volume (100%) */
-#define PA_VOLUME_NORM (0x10000)
+#define PA_VOLUME_NORM ((pa_volume_t) 0x10000)
/** Muted volume (0%) */
-#define PA_VOLUME_MUTED (0)
+#define PA_VOLUME_MUTED ((pa_volume_t) 0)
/** A structure encapsulating a per-channel volume */
typedef struct pa_cvolume {
@@ -149,25 +151,25 @@ int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) PA_GCC_PURE
pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) PA_GCC_CONST;
/** Multiply to per-channel volumes and return the result in *dest. This is only valid for software volumes! */
-pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) PA_GCC_PURE;
+pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
-/** Convert a decibel value to a volume. This is only valid for software volumes! \since 0.4 */
+/** Convert a decibel value to a volume. This is only valid for software volumes! */
pa_volume_t pa_sw_volume_from_dB(double f) PA_GCC_CONST;
-/** Convert a volume to a decibel value. This is only valid for software volumes! \since 0.4 */
+/** Convert a volume to a decibel value. This is only valid for software volumes! */
double pa_sw_volume_to_dB(pa_volume_t v) PA_GCC_CONST;
-/** Convert a linear factor to a volume. This is only valid for software volumes! \since 0.8 */
+/** Convert a linear factor to a volume. This is only valid for software volumes! */
pa_volume_t pa_sw_volume_from_linear(double v) PA_GCC_CONST;
-/** Convert a volume to a linear factor. This is only valid for software volumes! \since 0.8 */
+/** Convert a volume to a linear factor. This is only valid for software volumes! */
double pa_sw_volume_to_linear(pa_volume_t v) PA_GCC_CONST;
#ifdef INFINITY
-#define PA_DECIBEL_MININFTY (-INFINITY)
+#define PA_DECIBEL_MININFTY ((double) -INFINITY)
#else
-/** This value is used as minus infinity when using pa_volume_{to,from}_dB(). \since 0.4 */
-#define PA_DECIBEL_MININFTY (-200)
+/** This value is used as minus infinity when using pa_volume_{to,from}_dB(). */
+#define PA_DECIBEL_MININFTY ((double) -200)
#endif
PA_C_DECL_END
diff --git a/src/pulse/xmalloc.c b/src/pulse/xmalloc.c
index 5348dda4..a64761bf 100644
--- a/src/pulse/xmalloc.c
+++ b/src/pulse/xmalloc.c
@@ -29,9 +29,10 @@
#include <signal.h>
#include <unistd.h>
#include <string.h>
+#include <errno.h>
+#include <pulse/gccmacro.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include "xmalloc.h"
@@ -123,8 +124,12 @@ char *pa_xstrndup(const char *s, size_t l) {
}
void pa_xfree(void *p) {
+ int saved_errno;
+
if (!p)
return;
+ saved_errno = errno;
free(p);
+ errno = saved_errno;
}