summaryrefslogtreecommitdiffstats
path: root/polyp
diff options
context:
space:
mode:
Diffstat (limited to 'polyp')
-rw-r--r--polyp/client.c2
-rw-r--r--polyp/client.h2
-rw-r--r--polyp/native-common.h13
-rw-r--r--polyp/pacat-simple.c2
-rw-r--r--polyp/pacat.c2
-rw-r--r--polyp/parec-simple.c2
-rw-r--r--polyp/polyplib-context.c45
-rw-r--r--polyp/polyplib-context.h6
-rw-r--r--polyp/polyplib-def.h1
-rw-r--r--polyp/polyplib-internal.h2
-rw-r--r--polyp/polyplib-introspect.c197
-rw-r--r--polyp/polyplib-introspect.h46
-rw-r--r--polyp/polyplib-simple.c3
-rw-r--r--polyp/polyplib-simple.h3
-rw-r--r--polyp/polyplib-stream.c32
-rw-r--r--polyp/polyplib-stream.h5
-rw-r--r--polyp/protocol-esound.c4
-rw-r--r--polyp/protocol-native.c313
-rw-r--r--polyp/scache.c8
-rw-r--r--polyp/sink-input.c2
-rw-r--r--polyp/source-output.c2
-rw-r--r--polyp/strbuf.c12
22 files changed, 675 insertions, 29 deletions
diff --git a/polyp/client.c b/polyp/client.c
index a544b4fe..7aee2edd 100644
--- a/polyp/client.c
+++ b/polyp/client.c
@@ -82,7 +82,7 @@ void pa_client_kill(struct pa_client *c) {
c->kill(c);
}
-void pa_client_rename(struct pa_client *c, const char *name) {
+void pa_client_set_name(struct pa_client *c, const char *name) {
assert(c);
pa_xfree(c->name);
c->name = pa_xstrdup(name);
diff --git a/polyp/client.h b/polyp/client.h
index c926208e..25a4b166 100644
--- a/polyp/client.h
+++ b/polyp/client.h
@@ -46,6 +46,6 @@ void pa_client_free(struct pa_client *c);
* request destruction of the client */
void pa_client_kill(struct pa_client *c);
-void pa_client_rename(struct pa_client *c, const char *name);
+void pa_client_set_name(struct pa_client *c, const char *name);
#endif
diff --git a/polyp/native-common.h b/polyp/native-common.h
index c5192cec..45e0b1d3 100644
--- a/polyp/native-common.h
+++ b/polyp/native-common.h
@@ -38,7 +38,7 @@ enum {
PA_COMMAND_EXIT,
PA_COMMAND_REQUEST,
PA_COMMAND_AUTH,
- PA_COMMAND_SET_NAME,
+ PA_COMMAND_SET_CLIENT_NAME,
PA_COMMAND_LOOKUP_SINK,
PA_COMMAND_LOOKUP_SOURCE,
PA_COMMAND_DRAIN_PLAYBACK_STREAM,
@@ -75,6 +75,17 @@ enum {
PA_COMMAND_TRIGGER_PLAYBACK_STREAM,
PA_COMMAND_SET_DEFAULT_SINK,
PA_COMMAND_SET_DEFAULT_SOURCE,
+ PA_COMMAND_SET_PLAYBACK_STREAM_NAME,
+ PA_COMMAND_SET_RECORD_STREAM_NAME,
+ PA_COMMAND_KILL_CLIENT,
+ PA_COMMAND_KILL_SINK_INPUT,
+ PA_COMMAND_KILL_SOURCE_OUTPUT,
+ PA_COMMAND_LOAD_MODULE,
+ PA_COMMAND_UNLOAD_MODULE,
+ PA_COMMAND_ADD_AUTOLOAD,
+ PA_COMMAND_REMOVE_AUTOLOAD,
+ PA_COMMAND_GET_AUTOLOAD_INFO,
+ PA_COMMAND_GET_AUTOLOAD_INFO_LIST,
PA_COMMAND_MAX
};
diff --git a/polyp/pacat-simple.c b/polyp/pacat-simple.c
index 956728fb..2b8ffa08 100644
--- a/polyp/pacat-simple.c
+++ b/polyp/pacat-simple.c
@@ -47,7 +47,7 @@ int main(int argc, char*argv[]) {
int error;
/* Create a new playback stream */
- if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, &error))) {
+ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, PA_VOLUME_NORM, &error))) {
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
goto finish;
}
diff --git a/polyp/pacat.c b/polyp/pacat.c
index f4597714..cc7d55f4 100644
--- a/polyp/pacat.c
+++ b/polyp/pacat.c
@@ -156,7 +156,7 @@ static void context_state_callback(struct pa_context *c, void *userdata) {
pa_stream_set_read_callback(stream, stream_read_callback, NULL);
if (mode == PLAYBACK)
- pa_stream_connect_playback(stream, NULL, NULL);
+ pa_stream_connect_playback(stream, NULL, NULL, PA_VOLUME_NORM);
else
pa_stream_connect_record(stream, NULL, NULL);
diff --git a/polyp/parec-simple.c b/polyp/parec-simple.c
index 7e0931ae..cae6ff92 100644
--- a/polyp/parec-simple.c
+++ b/polyp/parec-simple.c
@@ -66,7 +66,7 @@ int main(int argc, char*argv[]) {
int error;
/* Create the recording stream */
- if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, &error))) {
+ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, 0, &error))) {
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
goto finish;
}
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c
index 7fef6b12..64f9074c 100644
--- a/polyp/polyplib-context.c
+++ b/polyp/polyplib-context.c
@@ -84,6 +84,7 @@ struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *
c->subscribe_userdata = NULL;
c->memblock_stat = pa_memblock_stat_new();
+ c->local = -1;
pa_check_signal_is_blocked(SIGPIPE);
return c;
@@ -252,7 +253,7 @@ static void setup_complete_callback(struct pa_pdispatch *pd, uint32_t command, u
struct pa_tagstruct *t;
t = pa_tagstruct_new(NULL, 0);
assert(t);
- pa_tagstruct_putu32(t, PA_COMMAND_SET_NAME);
+ pa_tagstruct_putu32(t, PA_COMMAND_SET_CLIENT_NAME);
pa_tagstruct_putu32(t, tag = c->ctag++);
pa_tagstruct_puts(t, c->name);
pa_pstream_send_tagstruct(c->pstream, t);
@@ -383,6 +384,8 @@ static int context_connect_spawn(struct pa_context *c, const struct pa_spawn_api
int fds[2] = { -1, -1} ;
struct pa_iochannel *io;
+ pa_context_ref(c);
+
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
pa_log(__FILE__": socketpair() failed: %s\n", strerror(errno));
pa_context_fail(c, PA_ERROR_INTERNAL);
@@ -417,7 +420,7 @@ static int context_connect_spawn(struct pa_context *c, const struct pa_spawn_api
putenv(t);
snprintf(t, sizeof(t), "-Lmodule-native-protocol-fd fd=%i", fds[1]);
- execl(p, p, t, NULL);
+ execl(p, p, "--daemonize=yes", "--log-target=syslog", t, NULL);
exit(1);
}
@@ -439,9 +442,14 @@ static int context_connect_spawn(struct pa_context *c, const struct pa_spawn_api
}
close(fds[1]);
+
+ c->local = 1;
io = pa_iochannel_new(c->mainloop, fds[0], fds[0]);
setup_context(c, io);
+
+ pa_context_unref(c);
+
return 0;
fail:
@@ -450,11 +458,11 @@ fail:
if (fds[1] != -1)
close(fds[1]);
+ pa_context_unref(c);
+
return -1;
}
-
-
int pa_context_connect(struct pa_context *c, const char *server, int spawn, const struct pa_spawn_api *api) {
int r = -1;
assert(c && c->ref >= 1 && c->state == PA_CONTEXT_UNCONNECTED);
@@ -483,6 +491,8 @@ int pa_context_connect(struct pa_context *c, const char *server, int spawn, cons
pa_context_fail(c, PA_ERROR_CONNECTIONREFUSED);
goto finish;
}
+
+ c->local = 1;
} else {
struct sockaddr* sa;
size_t sa_len;
@@ -499,6 +509,8 @@ int pa_context_connect(struct pa_context *c, const char *server, int spawn, cons
pa_context_fail(c, PA_ERROR_CONNECTIONREFUSED);
goto finish;
}
+
+ c->local = 0;
}
pa_socket_client_set_callback(c->client, on_connection, c);
@@ -702,3 +714,28 @@ struct pa_operation* pa_context_set_default_source(struct pa_context *c, const c
return pa_operation_ref(o);
}
+
+int pa_context_is_local(struct pa_context *c) {
+ assert(c);
+ return c->local;
+}
+
+struct pa_operation* pa_context_set_name(struct pa_context *c, const char *name, void(*cb)(struct pa_context*c, int success, void *userdata), void *userdata) {
+ struct pa_tagstruct *t;
+ struct pa_operation *o;
+ uint32_t tag;
+ assert(c && name && cb);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, PA_COMMAND_SET_CLIENT_NAME);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ 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, o);
+
+ return pa_operation_ref(o);
+}
diff --git a/polyp/polyplib-context.h b/polyp/polyplib-context.h
index 84e47b64..548a39dd 100644
--- a/polyp/polyplib-context.h
+++ b/polyp/polyplib-context.h
@@ -99,6 +99,12 @@ struct pa_operation* pa_context_set_default_sink(struct pa_context *c, const cha
/** Set the name of the default source. \since 0.4 */
struct pa_operation* pa_context_set_default_source(struct pa_context *c, const char *name, void(*cb)(struct pa_context*c, int success, void *userdata), void *userdata);
+/** Returns 1 when the connection is to a local daemon. Returns negative when no connection has been made yet. \since 0.5 */
+int pa_context_is_local(struct pa_context *c);
+
+/** Set a different application name for context on the server. \since 0.5 */
+struct pa_operation* pa_context_set_name(struct pa_context *c, const char *name, void(*cb)(struct pa_context*c, int success, void *userdata), void *userdata);
+
PA_C_DECL_END
#endif
diff --git a/polyp/polyplib-def.h b/polyp/polyplib-def.h
index 2aa33338..9bba3f32 100644
--- a/polyp/polyplib-def.h
+++ b/polyp/polyplib-def.h
@@ -94,6 +94,7 @@ enum {
PA_ERROR_CONNECTIONTERMINATED, /**< Connection terminated */
PA_ERROR_KILLED, /**< Entity killed */
PA_ERROR_INVALIDSERVER, /**< Invalid server */
+ PA_ERROR_INITFAILED, /**< Module initialization failed */
PA_ERROR_MAX /**< Not really an error but the first invalid error code */
};
diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h
index 98fd7924..4c44ee98 100644
--- a/polyp/polyplib-internal.h
+++ b/polyp/polyplib-internal.h
@@ -78,6 +78,8 @@ struct pa_context {
void *subscribe_userdata;
struct pa_memblock_stat *memblock_stat;
+
+ int local;
};
struct pa_stream {
diff --git a/polyp/polyplib-introspect.c b/polyp/polyplib-introspect.c
index e742c2db..919adb9c 100644
--- a/polyp/polyplib-introspect.c
+++ b/polyp/polyplib-introspect.c
@@ -650,7 +650,9 @@ static void context_get_sample_info_callback(struct pa_pdispatch *pd, uint32_t c
pa_tagstruct_getu32(t, &i.volume) < 0 ||
pa_tagstruct_get_usec(t, &i.duration) < 0 ||
pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 ||
- pa_tagstruct_getu32(t, &i.bytes) < 0) {
+ pa_tagstruct_getu32(t, &i.bytes) < 0 ||
+ pa_tagstruct_get_boolean(t, &i.lazy) < 0 ||
+ pa_tagstruct_gets(t, &i.filename) < 0) {
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
goto finish;
}
@@ -717,3 +719,196 @@ struct pa_operation* pa_context_get_sample_info_by_index(struct pa_context *c, u
struct pa_operation* pa_context_get_sample_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sample_info *i, int is_last, void *userdata), void *userdata) {
return pa_context_send_simple_command(c, PA_COMMAND_GET_SAMPLE_INFO_LIST, context_get_sample_info_callback, cb, userdata);
}
+
+static struct pa_operation* command_kill(struct pa_context *c, uint32_t command, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
+ struct pa_operation *o;
+ struct pa_tagstruct *t;
+ uint32_t tag;
+ assert(c && index != PA_INVALID_INDEX);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, command);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ pa_tagstruct_putu32(t, index);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
+
+ return pa_operation_ref(o);
+}
+
+struct pa_operation* pa_context_kill_client(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
+ return command_kill(c, PA_COMMAND_KILL_CLIENT, index, cb, userdata);
+}
+
+struct pa_operation* pa_context_kill_sink_input(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
+ return command_kill(c, PA_COMMAND_KILL_SINK_INPUT, index, cb, userdata);
+}
+
+struct pa_operation* pa_context_kill_source_output(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
+ return command_kill(c, PA_COMMAND_KILL_SOURCE_OUTPUT, index, cb, userdata);
+}
+
+static void load_module_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct pa_operation *o = userdata;
+ uint32_t index = -1;
+ assert(pd && o && o->context && o->ref >= 1);
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t) < 0)
+ goto finish;
+
+ } else if (pa_tagstruct_getu32(t, &index) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ pa_context_fail(o->context, PA_ERROR_PROTOCOL);
+ goto finish;
+ }
+
+ if (o->callback) {
+ void (*cb)(struct pa_context *c, uint32_t index, void *userdata) = o->callback;
+ cb(o->context, index, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+struct pa_operation* pa_context_load_module(struct pa_context *c, const char*name, const char *argument, void (*cb)(struct pa_context *c, uint32_t index, void *userdata), void *userdata) {
+ struct pa_operation *o;
+ struct pa_tagstruct *t;
+ uint32_t tag;
+ assert(c && name && argument);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, PA_COMMAND_LOAD_MODULE);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ pa_tagstruct_puts(t, name);
+ pa_tagstruct_puts(t, argument);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, load_module_callback, o);
+
+ return pa_operation_ref(o);
+}
+
+struct pa_operation* pa_context_unload_module(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
+ return command_kill(c, PA_COMMAND_UNLOAD_MODULE, index, cb, userdata);
+}
+
+/*** Autoload stuff ***/
+
+static void context_get_autoload_info_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct pa_operation *o = userdata;
+ int eof = 1;
+ assert(pd && o && o->context && o->ref >= 1);
+
+ if (command != PA_COMMAND_REPLY) {
+ if (pa_context_handle_error(o->context, command, t) < 0)
+ goto finish;
+
+ eof = -1;
+ } else {
+
+ while (!pa_tagstruct_eof(t)) {
+ struct pa_autoload_info i;
+
+ if (pa_tagstruct_gets(t, &i.name) < 0 ||
+ pa_tagstruct_getu32(t, &i.type) < 0 ||
+ pa_tagstruct_gets(t, &i.module) < 0 ||
+ pa_tagstruct_gets(t, &i.argument) < 0) {
+ pa_context_fail(o->context, PA_ERROR_PROTOCOL);
+ goto finish;
+ }
+
+ if (o->callback) {
+ void (*cb)(struct pa_context *s, const struct pa_autoload_info*i, int eof, void *userdata) = o->callback;
+ cb(o->context, &i, 0, o->userdata);
+ }
+ }
+ }
+
+ if (o->callback) {
+ void (*cb)(struct pa_context *s, const struct pa_autoload_info*i, int eof, void *userdata) = o->callback;
+ cb(o->context, NULL, eof, o->userdata);
+ }
+
+finish:
+ pa_operation_done(o);
+ pa_operation_unref(o);
+}
+
+struct pa_operation* pa_context_get_autoload_info(struct pa_context *c, const char *name, enum pa_autoload_type type, void (*cb)(struct pa_context *c, const struct pa_autoload_info *i, int is_last, void *userdata), void *userdata) {
+ struct pa_tagstruct *t;
+ struct pa_operation *o;
+ uint32_t tag;
+ assert(c && cb && name);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, PA_COMMAND_GET_AUTOLOAD_INFO);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ pa_tagstruct_puts(t, name);
+ pa_tagstruct_putu32(t, type);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, context_get_autoload_info_callback, o);
+
+ return pa_operation_ref(o);
+}
+
+struct pa_operation* pa_context_get_autoload_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_autoload_info *i, int is_last, void *userdata), void *userdata) {
+ return pa_context_send_simple_command(c, PA_COMMAND_GET_AUTOLOAD_INFO_LIST, context_get_autoload_info_callback, cb, userdata);
+}
+
+struct pa_operation* pa_context_add_autoload(struct pa_context *c, const char *name, enum pa_autoload_type type, const char *module, const char*argument, void (*cb)(struct pa_context *c, int success, void *userdata), void* userdata) {
+ struct pa_operation *o;
+ struct pa_tagstruct *t;
+ uint32_t tag;
+ assert(c && name && module && argument);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, PA_COMMAND_ADD_AUTOLOAD);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ pa_tagstruct_puts(t, name);
+ pa_tagstruct_putu32(t, type);
+ pa_tagstruct_puts(t, module);
+ pa_tagstruct_puts(t, argument);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
+
+ return pa_operation_ref(o);
+}
+
+struct pa_operation* pa_context_remove_autoload(struct pa_context *c, const char *name, enum pa_autoload_type type, void (*cb)(struct pa_context *c, int success, void *userdata), void* userdata) {
+ struct pa_operation *o;
+ struct pa_tagstruct *t;
+ uint32_t tag;
+ assert(c && name);
+
+ o = pa_operation_new(c, NULL);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(t, PA_COMMAND_REMOVE_AUTOLOAD);
+ pa_tagstruct_putu32(t, tag = c->ctag++);
+ pa_tagstruct_puts(t, name);
+ pa_tagstruct_putu32(t, type);
+ pa_pstream_send_tagstruct(c->pstream, t);
+ pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
+
+ return pa_operation_ref(o);
+}
diff --git a/polyp/polyplib-introspect.h b/polyp/polyplib-introspect.h
index 3da71b80..51210457 100644
--- a/polyp/polyplib-introspect.h
+++ b/polyp/polyplib-introspect.h
@@ -38,8 +38,7 @@
* and the structures themselves point to internal memory that may not
* be modified. That memory is only valid during the call to the
* callback function. A deep copy is required if you need this data
- * outside the callback functions. An error is signalled by a call to
- * the callback function with i=NULL and is_last=0.
+ * outside the callback functions. An error is signalled by a call to * the callback function with i=NULL and is_last=0.
*
* When using the routines that ask fo a single entry only, a callback
* with the same signature is used. However, no finishing call to the
@@ -196,6 +195,8 @@ struct pa_sample_info {
struct pa_sample_spec sample_spec; /**< Sample specification of the sampel */
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 */
};
/** Get information about a sample by its name */
@@ -207,6 +208,47 @@ struct pa_operation* pa_context_get_sample_info_by_index(struct pa_context *c, u
/** Get the complete list of samples stored in the daemon. */
struct pa_operation* pa_context_get_sample_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sample_info *i, int is_last, void *userdata), void *userdata);
+/** Kill a client. \since 0.5 */
+struct pa_operation* pa_context_kill_client(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
+
+/** Kill a sink input. \since 0.5 */
+struct pa_operation* pa_context_kill_sink_input(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
+
+/** Kill a source output. \since 0.5 */
+struct pa_operation* pa_context_kill_source_output(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
+
+/** Load a module. \since 0.5 */
+struct pa_operation* pa_context_load_module(struct pa_context *c, const char*name, const char *argument, void (*cb)(struct pa_context *c, uint32_t index, void *userdata), void *userdata);
+
+/** Unload a module. \since 0.5 */
+struct pa_operation* pa_context_unload_module(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
+
+/** Type of an autoload entry. \since 0.5 */
+enum pa_autoload_type {
+ PA_AUTOLOAD_SINK = 0,
+ PA_AUTOLOAD_SOURCE = 1,
+};
+
+/** Stores information about autoload entries. \since 0.5 */
+struct pa_autoload_info {
+ const char *name; /**< Name of the sink or source */
+ enum pa_autoload_type type; /**< Type of the autoload entry */
+ const char *module; /**< Module name to load */
+ const char *argument; /**< Argument string for module */
+};
+
+/** Get info about a specific autoload entry. \since 0.5 */
+struct pa_operation* pa_context_get_autoload_info(struct pa_context *c, const char *name, enum pa_autoload_type type, void (*cb)(struct pa_context *c, const struct pa_autoload_info *i, int is_last, void *userdata), void *userdata);
+
+/** Get the complete list of autoload entries. \since 0.5 */
+struct pa_operation* pa_context_get_autoload_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_autoload_info *i, int is_last, void *userdata), void *userdata);
+
+/** Add a new autoload entry. \since 0.5 */
+struct pa_operation* pa_context_add_autoload(struct pa_context *c, const char *name, enum pa_autoload_type type, const char *module, const char*argument, void (*cb)(struct pa_context *c, int success, void *userdata), void* userdata);
+
+/** Remove an autoload entry. \since 0.5 */
+struct pa_operation* pa_context_remove_autoload(struct pa_context *c, const char *name, enum pa_autoload_type type, void (*cb)(struct pa_context *c, int success, void *userdata), void* userdata);
+
PA_C_DECL_END
#endif
diff --git a/polyp/polyplib-simple.c b/polyp/polyplib-simple.c
index 36e6e757..5cf52d06 100644
--- a/polyp/polyplib-simple.c
+++ b/polyp/polyplib-simple.c
@@ -110,6 +110,7 @@ struct pa_simple* pa_simple_new(
const char *stream_name,
const struct pa_sample_spec *ss,
const struct pa_buffer_attr *attr,
+ pa_volume_t volume,
int *perror) {
struct pa_simple *p;
@@ -142,7 +143,7 @@ struct pa_simple* pa_simple_new(
goto fail;
if (dir == PA_STREAM_PLAYBACK)
- pa_stream_connect_playback(p->stream, dev, attr);
+ pa_stream_connect_playback(p->stream, dev, attr, volume);
else
pa_stream_connect_record(p->stream, dev, attr);
diff --git a/polyp/polyplib-simple.h b/polyp/polyplib-simple.h
index b37bdec6..1bd46dc6 100644
--- a/polyp/polyplib-simple.h
+++ b/polyp/polyplib-simple.h
@@ -54,7 +54,8 @@ struct pa_simple* pa_simple_new(
const char *stream_name, /**< A descriptive name for this client (application name, song title, ...) */
const struct pa_sample_spec *ss, /**< The sample type to use */
const struct pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */
- int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
+ pa_volume_t volume, /**< Initial volume. Only for playback streams. \since 0.5 */
+ int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
);
/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
diff --git a/polyp/polyplib-stream.c b/polyp/polyplib-stream.c
index b40b7f69..89a8d338 100644
--- a/polyp/polyplib-stream.c
+++ b/polyp/polyplib-stream.c
@@ -211,7 +211,7 @@ finish:
pa_stream_unref(s);
}
-static void create_stream(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr) {
+static void create_stream(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr, pa_volume_t volume) {
struct pa_tagstruct *t;
uint32_t tag;
assert(s && s->ref >= 1 && s->state == PA_STREAM_DISCONNECTED);
@@ -251,6 +251,7 @@ static void create_stream(struct pa_stream *s, const char *dev, const struct pa_
pa_tagstruct_putu32(t, s->buffer_attr.tlength);
pa_tagstruct_putu32(t, s->buffer_attr.prebuf);
pa_tagstruct_putu32(t, s->buffer_attr.minreq);
+ pa_tagstruct_putu32(t, volume);
} else
pa_tagstruct_putu32(t, s->buffer_attr.fragsize);
@@ -260,16 +261,16 @@ static void create_stream(struct pa_stream *s, const char *dev, const struct pa_
pa_stream_unref(s);
}
-void pa_stream_connect_playback(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr) {
+void pa_stream_connect_playback(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr, pa_volume_t volume) {
assert(s && s->context->state == PA_CONTEXT_READY && s->ref >= 1);
s->direction = PA_STREAM_PLAYBACK;
- create_stream(s, dev, attr);
+ create_stream(s, dev, attr, volume);
}
void pa_stream_connect_record(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr) {
assert(s && s->context->state == PA_CONTEXT_READY && s->ref >= 1);
s->direction = PA_STREAM_RECORD;
- create_stream(s, dev, attr);
+ create_stream(s, dev, attr, 0);
}
void pa_stream_write(struct pa_stream *s, const void *data, size_t length, void (*free_cb)(void *p), size_t delta) {
@@ -536,3 +537,26 @@ struct pa_operation* pa_stream_flush(struct pa_stream *s, void (*cb)(struct pa_s
struct pa_operation* pa_stream_trigger(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
return pa_stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata);
}
+
+struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, void(*cb)(struct pa_stream*c, int success, void *userdata), void *userdata) {
+ struct pa_operation *o;
+ struct pa_tagstruct *t;
+ uint32_t tag;
+ assert(s && s->ref >= 1 && s->state == PA_STREAM_READY && name && s->direction != PA_STREAM_UPLOAD);
+
+ o = pa_operation_new(s->context, s);
+ assert(o);
+ o->callback = cb;
+ o->userdata = userdata;
+
+ t = pa_tagstruct_new(NULL, 0);
+ assert(t);
+ pa_tagstruct_putu32(t, s->direction == PA_STREAM_RECORD ? PA_COMMAND_SET_RECORD_STREAM_NAME : PA_COMMAND_SET_PLAYBACK_STREAM_NAME);
+ pa_tagstruct_putu32(t, tag = s->context->ctag++);
+ 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, o);
+
+ return pa_operation_ref(o);
+}
diff --git a/polyp/polyplib-stream.h b/polyp/polyplib-stream.h
index d74c3cb2..257f2b99 100644
--- a/polyp/polyplib-stream.h
+++ b/polyp/polyplib-stream.h
@@ -57,7 +57,7 @@ struct pa_context* pa_stream_get_context(struct pa_stream *p);
uint32_t pa_stream_get_index(struct pa_stream *s);
/** Connect the stream to a sink */
-void pa_stream_connect_playback(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr);
+void pa_stream_connect_playback(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr, pa_volume_t volume);
/** Connect the stream to a source */
void pa_stream_connect_record(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr);
@@ -126,6 +126,9 @@ struct pa_operation* pa_stream_flush(struct pa_stream *s, void (*cb)(struct pa_s
* 0.3 */
struct pa_operation* pa_stream_trigger(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata);
+/** Rename the stream. \since 0.5 */
+struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, void(*cb)(struct pa_stream*c, int success, void *userdata), void *userdata);
+
PA_C_DECL_END
#endif
diff --git a/polyp/protocol-esound.c b/polyp/protocol-esound.c
index 8ec48a34..5abe474d 100644
--- a/polyp/protocol-esound.c
+++ b/polyp/protocol-esound.c
@@ -293,7 +293,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
strncpy(name, (char*) data + sizeof(int)*2, sizeof(name));
name[sizeof(name)-1] = 0;
- pa_client_rename(c->client, name);
+ pa_client_set_name(c->client, name);
assert(!c->input_memblockq);
@@ -357,7 +357,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
strncpy(name, (char*) data + sizeof(int)*2, sizeof(name));
name[sizeof(name)-1] = 0;
- pa_client_rename(c->client, name);
+ pa_client_set_name(c->client, name);
assert(!c->output_memblockq);
diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c
index 55b98fd4..be7b76f6 100644
--- a/polyp/protocol-native.c
+++ b/polyp/protocol-native.c
@@ -45,6 +45,7 @@
#include "util.h"
#include "subscribe.h"
#include "log.h"
+#include "autoload.h"
struct connection;
struct pa_protocol_native;
@@ -123,7 +124,7 @@ static void command_drain_playback_stream(struct pa_pdispatch *pd, uint32_t comm
static void command_create_record_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_delete_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_auth(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
-static void command_set_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_set_client_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_lookup(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_stat(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
@@ -139,6 +140,14 @@ static void command_set_volume(struct pa_pdispatch *pd, uint32_t command, uint32
static void command_cork_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_flush_or_trigger_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static void command_set_default_sink_or_source(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_set_stream_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_kill(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_load_module(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_unload_module(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_add_autoload(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_remove_autoload(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_get_autoload_info(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_get_autoload_info_list(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_ERROR] = { NULL },
@@ -152,7 +161,7 @@ static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_AUTH] = { command_auth },
[PA_COMMAND_REQUEST] = { NULL },
[PA_COMMAND_EXIT] = { command_exit },
- [PA_COMMAND_SET_NAME] = { command_set_name },
+ [PA_COMMAND_SET_CLIENT_NAME] = { command_set_client_name },
[PA_COMMAND_LOOKUP_SINK] = { command_lookup },
[PA_COMMAND_LOOKUP_SOURCE] = { command_lookup },
[PA_COMMAND_STAT] = { command_stat },
@@ -185,6 +194,17 @@ static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_TRIGGER_PLAYBACK_STREAM] = { command_flush_or_trigger_playback_stream },
[PA_COMMAND_SET_DEFAULT_SINK] = { command_set_default_sink_or_source },
[PA_COMMAND_SET_DEFAULT_SOURCE] = { command_set_default_sink_or_source },
+ [PA_COMMAND_SET_PLAYBACK_STREAM_NAME] = { command_set_stream_name },
+ [PA_COMMAND_SET_RECORD_STREAM_NAME] = { command_set_stream_name },
+ [PA_COMMAND_KILL_CLIENT] = { command_kill },
+ [PA_COMMAND_KILL_SINK_INPUT] = { command_kill },
+ [PA_COMMAND_KILL_SOURCE_OUTPUT] = { command_kill },
+ [PA_COMMAND_LOAD_MODULE] = { command_load_module },
+ [PA_COMMAND_UNLOAD_MODULE] = { command_unload_module },
+ [PA_COMMAND_GET_AUTOLOAD_INFO] = { command_get_autoload_info },
+ [PA_COMMAND_GET_AUTOLOAD_INFO_LIST] = { command_get_autoload_info_list },
+ [PA_COMMAND_ADD_AUTOLOAD] = { command_add_autoload },
+ [PA_COMMAND_REMOVE_AUTOLOAD] = { command_remove_autoload },
};
/* structure management */
@@ -265,7 +285,8 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
size_t maxlength,
size_t tlength,
size_t prebuf,
- size_t minreq) {
+ size_t minreq,
+ pa_volume_t volume) {
struct playback_stream *s;
struct pa_sink_input *sink_input;
assert(c && sink && ss && name && maxlength);
@@ -291,6 +312,8 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
s->requested_bytes = 0;
s->drain_request = 0;
+
+ s->sink_input->volume = volume;
pa_idxset_put(c->output_streams, s, &s->index);
return s;
@@ -501,6 +524,7 @@ static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t com
struct pa_sample_spec ss;
struct pa_tagstruct *reply;
struct pa_sink *sink;
+ pa_volume_t volume;
assert(c && t && c->protocol && c->protocol->core);
if (pa_tagstruct_gets(t, &name) < 0 ||
@@ -511,6 +535,7 @@ static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t com
pa_tagstruct_getu32(t, &tlength) < 0 ||
pa_tagstruct_getu32(t, &prebuf) < 0 ||
pa_tagstruct_getu32(t, &minreq) < 0 ||
+ pa_tagstruct_getu32(t, &volume) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
@@ -531,7 +556,7 @@ static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t com
return;
}
- if (!(s = playback_stream_new(c, sink, &ss, name, maxlength, tlength, prebuf, minreq))) {
+ if (!(s = playback_stream_new(c, sink, &ss, name, maxlength, tlength, prebuf, minreq, volume))) {
pa_pstream_send_error(c->pstream, tag, PA_ERROR_INVALID);
return;
}
@@ -691,7 +716,7 @@ static void command_auth(struct pa_pdispatch *pd, uint32_t command, uint32_t tag
return;
}
-static void command_set_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+static void command_set_client_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
const char *name;
assert(c && t);
@@ -702,7 +727,7 @@ static void command_set_name(struct pa_pdispatch *pd, uint32_t command, uint32_t
return;
}
- pa_client_rename(c->client, name);
+ pa_client_set_name(c->client, name);
pa_pstream_send_simple_ack(c->pstream, tag);
return;
}
@@ -1061,6 +1086,8 @@ static void scache_fill_tagstruct(struct pa_tagstruct *t, struct pa_scache_entry
pa_tagstruct_put_usec(t, pa_bytes_to_usec(e->memchunk.length, &e->sample_spec));
pa_tagstruct_put_sample_spec(t, &e->sample_spec);
pa_tagstruct_putu32(t, e->memchunk.length);
+ pa_tagstruct_put_boolean(t, e->lazy);
+ pa_tagstruct_puts(t, e->filename);
}
static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
@@ -1415,6 +1442,280 @@ static void command_set_default_sink_or_source(struct pa_pdispatch *pd, uint32_t
pa_pstream_send_simple_ack(c->pstream, tag);
}
+static void command_set_stream_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ uint32_t index;
+ const char *name;
+ assert(c && t);
+
+ if (pa_tagstruct_getu32(t, &index) < 0 ||
+ pa_tagstruct_gets(t, &name) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (command == PA_COMMAND_SET_PLAYBACK_STREAM_NAME) {
+ struct playback_stream *s;
+
+ if (!(s = pa_idxset_get_by_index(c->output_streams, index)) || s->type != PLAYBACK_STREAM) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_sink_input_set_name(s->sink_input, name);
+
+ } else {
+ struct record_stream *s;
+
+ if (!(s = pa_idxset_get_by_index(c->record_streams, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_source_output_set_name(s->source_output, name);
+ }
+
+ pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_kill(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ uint32_t index;
+ assert(c && t);
+
+ if (pa_tagstruct_getu32(t, &index) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (command == PA_COMMAND_KILL_CLIENT) {
+ struct pa_client *client;
+
+ if (!(client = pa_idxset_get_by_index(c->protocol->core->clients, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_client_kill(client);
+ } else if (command == PA_COMMAND_KILL_SINK_INPUT) {
+ struct pa_sink_input *s;
+
+ if (!(s = pa_idxset_get_by_index(c->protocol->core->sink_inputs, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_sink_input_kill(s);
+ } else {
+ struct pa_source_output *s;
+
+ assert(command == PA_COMMAND_KILL_SOURCE_OUTPUT);
+
+ if (!(s = pa_idxset_get_by_index(c->protocol->core->source_outputs, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_source_output_kill(s);
+ }
+
+ pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_load_module(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ struct pa_module *m;
+ const char *name, *argument;
+ struct pa_tagstruct *reply;
+ assert(c && t);
+
+ if (pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_gets(t, &argument) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (!(m = pa_module_load(c->protocol->core, name, argument))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_INITFAILED);
+ return;
+ }
+
+ reply = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+ pa_tagstruct_putu32(reply, tag);
+ pa_tagstruct_putu32(reply, m->index);
+ pa_pstream_send_tagstruct(c->pstream, reply);
+}
+
+static void command_unload_module(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ uint32_t index;
+ struct pa_module *m;
+ assert(c && t);
+
+ if (pa_tagstruct_getu32(t, &index) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (!(m = pa_idxset_get_by_index(c->protocol->core->modules, index))) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_module_unload_request(m);
+ pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_add_autoload(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ const char *name, *module, *argument;
+ uint32_t type;
+ assert(c && t);
+
+ if (pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_getu32(t, &type) < 0 || type > 1 ||
+ pa_tagstruct_gets(t, &module) < 0 ||
+ pa_tagstruct_gets(t, &argument) < 0 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (pa_autoload_add(c->protocol->core, name, type == 0 ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE, module, argument) < 0) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
+ return;
+ }
+
+ pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_remove_autoload(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ const char *name;
+ uint32_t type;
+ assert(c && t);
+
+ if (pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_getu32(t, &type) < 0 || type > 1 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (pa_autoload_remove(c->protocol->core, name, type == 0 ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE) < 0) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void autoload_fill_tagstruct(struct pa_tagstruct *t, struct pa_autoload_entry *e) {
+ assert(t && e);
+ pa_tagstruct_puts(t, e->name);
+ pa_tagstruct_putu32(t, e->type == PA_NAMEREG_SINK ? 0 : 1);
+ pa_tagstruct_puts(t, e->module);
+ pa_tagstruct_puts(t, e->argument);
+}
+
+static void command_get_autoload_info(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ struct pa_autoload_entry *a = NULL;
+ uint32_t type;
+ const char *name;
+ struct pa_tagstruct *reply;
+ assert(c && t);
+
+ if (pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_getu32(t, &type) < 0 || type > 1 ||
+ !pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ if (!c->protocol->core->autoload_hashmap || !(a = pa_hashmap_get(c->protocol->core->autoload_hashmap, name)) || (a->type == PA_NAMEREG_SINK && type != 0) || (a->type == PA_NAMEREG_SOURCE && type != 1)) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+ return;
+ }
+
+ reply = pa_tagstruct_new(NULL, 0);
+ assert(reply);
+ pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+ pa_tagstruct_putu32(reply, tag);
+ autoload_fill_tagstruct(reply, a);
+ pa_pstream_send_tagstruct(c->pstream, reply);
+}
+
+static void command_get_autoload_info_list(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+ struct connection *c = userdata;
+ struct pa_tagstruct *reply;
+ assert(c && t);
+
+ if (!pa_tagstruct_eof(t)) {
+ protocol_error(c);
+ return;
+ }
+
+ if (!c->authorized) {
+ pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+ return;
+ }
+
+ reply = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+ pa_tagstruct_putu32(reply, tag);
+
+ if (c->protocol->core->autoload_hashmap) {
+ struct pa_autoload_entry *a;
+ void *state = NULL;
+
+ while ((a = pa_hashmap_iterate(c->protocol->core->autoload_hashmap, &state)))
+ autoload_fill_tagstruct(reply, a);
+ }
+
+ pa_pstream_send_tagstruct(c->pstream, reply);
+}
+
/*** pstream callbacks ***/
static void pstream_packet_callback(struct pa_pstream *p, struct pa_packet *packet, void *userdata) {
diff --git a/polyp/scache.c b/polyp/scache.c
index 026f4b17..963a4f86 100644
--- a/polyp/scache.c
+++ b/polyp/scache.c
@@ -141,6 +141,7 @@ int pa_scache_add_file(struct pa_core *c, const char *name, const char *filename
r = pa_scache_add_item(c, name, &ss, &chunk, index);
pa_memblock_unref(chunk.memblock);
+
return r;
}
@@ -203,9 +204,12 @@ int pa_scache_play_item(struct pa_core *c, const char *name, struct pa_sink *sin
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 1)))
return -1;
- if (e->lazy && !e->memchunk.memblock)
+ if (e->lazy && !e->memchunk.memblock) {
if (pa_sound_file_load(e->filename, &e->sample_spec, &e->memchunk, c->memblock_stat) < 0)
return -1;
+
+ pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
+ }
if (!e->memchunk.memblock)
return -1;
@@ -276,5 +280,7 @@ void pa_scache_unload_unused(struct pa_core *c) {
pa_memblock_unref(e->memchunk.memblock);
e->memchunk.memblock = NULL;
e->memchunk.index = e->memchunk.length = 0;
+
+ pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
}
}
diff --git a/polyp/sink-input.c b/polyp/sink-input.c
index e2b9e0cf..2541c821 100644
--- a/polyp/sink-input.c
+++ b/polyp/sink-input.c
@@ -258,4 +258,6 @@ void pa_sink_input_set_name(struct pa_sink_input *i, const char *name) {
pa_xfree(i->name);
i->name = pa_xstrdup(name);
+
+ pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
}
diff --git a/polyp/source-output.c b/polyp/source-output.c
index 3abf9c18..2566ec87 100644
--- a/polyp/source-output.c
+++ b/polyp/source-output.c
@@ -146,4 +146,6 @@ void pa_source_output_set_name(struct pa_source_output *o, const char *name) {
assert(o && o->ref >= 1);
pa_xfree(o->name);
o->name = pa_xstrdup(name);
+
+ pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
}
diff --git a/polyp/strbuf.c b/polyp/strbuf.c
index 169604e8..44cae2ce 100644
--- a/polyp/strbuf.c
+++ b/polyp/strbuf.c
@@ -33,10 +33,22 @@
#include "strbuf.h"
+#ifdef __STDC_VERSION__
+#if __STDC_VERSION__ >= 199901L
+#ifndef STDC99
+#define STDC99
+#endif
+#endif
+#endif
+
struct chunk {
struct chunk *next;
size_t length;
+#ifdef STDC99
char text[];
+#else
+ char text[0];
+#endif
};
struct pa_strbuf {