mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
merge glitch-free branch back into trunk
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2445 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
91f092eadc
commit
045c1d602d
189 changed files with 12559 additions and 4959 deletions
|
|
@ -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;
|
||||
reset_callbacks(c);
|
||||
|
||||
c->subscribe_callback = NULL;
|
||||
c->subscribe_userdata = NULL;
|
||||
|
||||
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;
|
||||
|
||||
/* Not required, since fds[0] has CLOEXEC enabled anyway */
|
||||
pa_assert_se(pa_close(fds[0]) == 0);
|
||||
pa_close_all(fds[1], -1);
|
||||
|
||||
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,25 +979,6 @@ finish:
|
|||
pa_operation_unref(o);
|
||||
}
|
||||
|
||||
pa_operation* pa_context_exit_daemon(pa_context *c, 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);
|
||||
|
||||
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_EXIT, &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);
|
||||
|
||||
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;
|
||||
|
|
@ -927,6 +998,13 @@ pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, pa
|
|||
return o;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
pa_tagstruct *t;
|
||||
pa_operation *o;
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue