From 369a908db761e7f59481000a68bffb476aa6e056 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 16 Aug 2004 19:55:02 +0000 Subject: add sink input/source output support to the native protocol git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@126 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/native-common.h | 3 + polyp/polyplib-introspect.c | 139 +++++++++++++++++++++++++++++++++++++++++++- polyp/polyplib-introspect.h | 4 +- polyp/protocol-native.c | 70 ++++++++++++++++++---- 4 files changed, 203 insertions(+), 13 deletions(-) diff --git a/polyp/native-common.h b/polyp/native-common.h index 0fc44165..debb9bba 100644 --- a/polyp/native-common.h +++ b/polyp/native-common.h @@ -63,8 +63,11 @@ enum { PA_COMMAND_GET_CLIENT_INFO, PA_COMMAND_GET_CLIENT_INFO_LIST, PA_COMMAND_GET_SINK_INPUT_INFO, + PA_COMMAND_GET_SINK_INPUT_INFO_LIST, PA_COMMAND_GET_SOURCE_OUTPUT_INFO, + PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST, PA_COMMAND_GET_SAMPLE_INFO, + PA_COMMAND_GET_SAMPLE_INFO_LIST, PA_COMMAND_SUBSCRIBE, PA_COMMAND_SUBSCRIBE_EVENT, diff --git a/polyp/polyplib-introspect.c b/polyp/polyplib-introspect.c index 345a9cd5..aa70a111 100644 --- a/polyp/polyplib-introspect.c +++ b/polyp/polyplib-introspect.c @@ -297,7 +297,6 @@ struct pa_operation* pa_context_get_client_info(struct pa_context *c, uint32_t i pa_tagstruct_putu32(t, PA_COMMAND_GET_CLIENT_INFO); pa_tagstruct_putu32(t, tag = c->ctag++); pa_tagstruct_putu32(t, index); - pa_tagstruct_puts(t, ""); pa_pstream_send_tagstruct(c->pstream, t); pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, context_get_client_info_callback, o); @@ -375,6 +374,144 @@ struct pa_operation* pa_context_get_module_info_list(struct pa_context *c, void return pa_context_send_simple_command(c, PA_COMMAND_GET_MODULE_INFO_LIST, context_get_module_info_callback, cb, userdata); } +/*** Sink input info ***/ + +static void context_get_sink_input_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_sink_input_info i; + + 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_getu32(t, &i.client) < 0 || + pa_tagstruct_getu32(t, &i.sink) < 0 || + pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0 || + pa_tagstruct_getu32(t, &i.volume) < 0 || + pa_tagstruct_getu32(t, &i.latency) < 0) { + pa_context_fail(o->context, PA_ERROR_PROTOCOL); + goto finish; + } + + if (o->callback) { + void (*cb)(struct pa_context *s, const struct pa_sink_input_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_sink_input_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_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata) { + struct pa_tagstruct *t; + struct pa_operation *o; + uint32_t tag; + assert(c && 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_GET_SINK_INPUT_INFO); + 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, context_get_sink_input_info_callback, o); + + return pa_operation_ref(o); +} + +struct pa_operation* pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata) { + return pa_context_send_simple_command(c, PA_COMMAND_GET_SINK_INPUT_INFO_LIST, context_get_sink_input_info_callback, cb, userdata); +} + +/*** Source output info ***/ + +static void context_get_source_output_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_source_output_info i; + + 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_getu32(t, &i.client) < 0 || + pa_tagstruct_getu32(t, &i.source) < 0 || + pa_tagstruct_get_sample_spec(t, &i.sample_spec) < 0) { + pa_context_fail(o->context, PA_ERROR_PROTOCOL); + goto finish; + } + + if (o->callback) { + void (*cb)(struct pa_context *s, const struct pa_source_output_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_source_output_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_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata) { + struct pa_tagstruct *t; + struct pa_operation *o; + uint32_t tag; + assert(c && 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_GET_SOURCE_OUTPUT_INFO); + 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, context_get_source_output_info_callback, o); + + return pa_operation_ref(o); +} + +struct pa_operation* pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata) { + return pa_context_send_simple_command(c, PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST, context_get_source_output_info_callback, cb, userdata); +} + /*** Volume manipulation ***/ struct pa_operation* pa_context_set_sink_volume_by_index(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) { diff --git a/polyp/polyplib-introspect.h b/polyp/polyplib-introspect.h index bca752e2..e83ba73b 100644 --- a/polyp/polyplib-introspect.h +++ b/polyp/polyplib-introspect.h @@ -93,7 +93,7 @@ struct pa_sink_input_info { uint32_t index; const char *name; uint32_t owner_module; - uint32_t owner_client; + uint32_t client; uint32_t sink; struct pa_sample_spec sample_spec; uint32_t volume; @@ -107,7 +107,7 @@ struct pa_source_output_info { uint32_t index; const char *name; uint32_t owner_module; - uint32_t owner_client; + uint32_t client; uint32_t source; struct pa_sample_spec sample_spec; }; diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c index 7df39fe3..35c78f61 100644 --- a/polyp/protocol-native.c +++ b/polyp/protocol-native.c @@ -162,13 +162,18 @@ static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = { [PA_COMMAND_GET_SOURCE_INFO] = { command_get_info }, [PA_COMMAND_GET_CLIENT_INFO] = { command_get_info }, [PA_COMMAND_GET_MODULE_INFO] = { command_get_info }, + [PA_COMMAND_GET_SINK_INPUT_INFO] = { command_get_info }, + [PA_COMMAND_GET_SOURCE_OUTPUT_INFO] = { command_get_info }, [PA_COMMAND_GET_SINK_INFO_LIST] = { command_get_info_list }, [PA_COMMAND_GET_SOURCE_INFO_LIST] = { command_get_info_list }, [PA_COMMAND_GET_MODULE_INFO_LIST] = { command_get_info_list }, [PA_COMMAND_GET_CLIENT_INFO_LIST] = { command_get_info_list }, + [PA_COMMAND_GET_SINK_INPUT_INFO_LIST] = { command_get_info_list }, + [PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST] = { command_get_info_list }, [PA_COMMAND_GET_SERVER_INFO] = { command_get_server_info }, [PA_COMMAND_SUBSCRIBE] = { command_subscribe }, [PA_COMMAND_SET_SINK_VOLUME] = { command_set_volume }, + [PA_COMMAND_SET_SINK_INPUT_VOLUME] = { command_set_volume }, }; /* structure management */ @@ -988,6 +993,28 @@ static void module_fill_tagstruct(struct pa_tagstruct *t, struct pa_module *modu pa_tagstruct_putu32(t, module->auto_unload); } +static void sink_input_fill_tagstruct(struct pa_tagstruct *t, struct pa_sink_input *s) { + assert(t && s); + pa_tagstruct_putu32(t, s->index); + pa_tagstruct_puts(t, s->name ? s->name : ""); + pa_tagstruct_putu32(t, s->owner ? s->owner->index : (uint32_t) -1); + pa_tagstruct_putu32(t, s->client ? s->client->index : (uint32_t) -1); + pa_tagstruct_putu32(t, s->sink->index); + pa_tagstruct_put_sample_spec(t, &s->sample_spec); + pa_tagstruct_putu32(t, s->volume); + pa_tagstruct_putu32(t, pa_sink_input_get_latency(s)); +} + +static void source_output_fill_tagstruct(struct pa_tagstruct *t, struct pa_source_output *s) { + assert(t && s); + pa_tagstruct_putu32(t, s->index); + pa_tagstruct_puts(t, s->name ? s->name : ""); + pa_tagstruct_putu32(t, s->owner ? s->owner->index : (uint32_t) -1); + pa_tagstruct_putu32(t, s->client ? s->client->index : (uint32_t) -1); + pa_tagstruct_putu32(t, s->source->index); + pa_tagstruct_put_sample_spec(t, &s->sample_spec); +} + static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) { struct connection *c = userdata; uint32_t index; @@ -995,12 +1022,19 @@ static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t struct pa_source *source = NULL; struct pa_client *client = NULL; struct pa_module *module = NULL; + struct pa_sink_input *si = NULL; + struct pa_source_output *so = NULL; const char *name; struct pa_tagstruct *reply; assert(c && t); + if (pa_tagstruct_getu32(t, &index) < 0 || - pa_tagstruct_gets(t, &name) < 0 || + (command != PA_COMMAND_GET_CLIENT_INFO && + command != PA_COMMAND_GET_MODULE_INFO && + command != PA_COMMAND_GET_SINK_INPUT_INFO && + command != PA_COMMAND_GET_SOURCE_OUTPUT_INFO && + pa_tagstruct_gets(t, &name) < 0) || !pa_tagstruct_eof(t)) { protocol_error(c); return; @@ -1023,12 +1057,16 @@ static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t source = pa_namereg_get(c->protocol->core, *name ? name : NULL, PA_NAMEREG_SOURCE, 1); } else if (command == PA_COMMAND_GET_CLIENT_INFO) client = pa_idxset_get_by_index(c->protocol->core->clients, index); - else { - assert(command == PA_COMMAND_GET_MODULE_INFO); + else if (command == PA_COMMAND_GET_MODULE_INFO) module = pa_idxset_get_by_index(c->protocol->core->modules, index); + else if (command == PA_COMMAND_GET_SINK_INPUT_INFO) + si = pa_idxset_get_by_index(c->protocol->core->sink_inputs, index); + else { + assert(command == PA_COMMAND_GET_SOURCE_OUTPUT_INFO); + so = pa_idxset_get_by_index(c->protocol->core->source_outputs, index); } - - if (!sink && !source && !client && !module) { + + if (!sink && !source && !client && !module && !si && !so) { pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY); return; } @@ -1043,8 +1081,12 @@ static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t source_fill_tagstruct(reply, source); else if (client) client_fill_tagstruct(reply, client); - else + else if (module) module_fill_tagstruct(reply, module); + else if (si) + sink_input_fill_tagstruct(reply, si); + else + source_output_fill_tagstruct(reply, so); pa_pstream_send_tagstruct(c->pstream, reply); } @@ -1077,9 +1119,13 @@ static void command_get_info_list(struct pa_pdispatch *pd, uint32_t command, uin i = c->protocol->core->sources; else if (command == PA_COMMAND_GET_CLIENT_INFO_LIST) i = c->protocol->core->clients; - else { - assert(command == PA_COMMAND_GET_MODULE_INFO_LIST); + else if (command == PA_COMMAND_GET_MODULE_INFO_LIST) i = c->protocol->core->modules; + else if (command == PA_COMMAND_GET_SINK_INPUT_INFO_LIST) + i = c->protocol->core->sink_inputs; + else { + assert(command == PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST); + i = c->protocol->core->source_outputs; } for (p = pa_idxset_first(i, &index); p; p = pa_idxset_next(i, &index)) { @@ -1089,9 +1135,13 @@ static void command_get_info_list(struct pa_pdispatch *pd, uint32_t command, uin source_fill_tagstruct(reply, p); else if (command == PA_COMMAND_GET_CLIENT_INFO_LIST) client_fill_tagstruct(reply, p); - else { - assert(command == PA_COMMAND_GET_MODULE_INFO_LIST); + else if (command == PA_COMMAND_GET_MODULE_INFO_LIST) module_fill_tagstruct(reply, p); + else if (command == PA_COMMAND_GET_SINK_INPUT_INFO_LIST) + sink_input_fill_tagstruct(reply, p); + else { + assert(command == PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST); + source_output_fill_tagstruct(reply, p); } } -- cgit