introspect: Get formats for sources

This gets the list of supported formats for a source in
pa_context_get_source_info*(). Also prints these in 'pactl list'.
This commit is contained in:
Colin Guthrie 2011-05-16 22:15:57 +01:00
parent 5d35375aa7
commit fdf3a08814
5 changed files with 82 additions and 18 deletions

View file

@ -254,3 +254,11 @@ New fields PA_COMMAND_CREATE_RECORD_STREAM:
One new field in reply from PA_COMMAND_CREATE_RECORD_STREAM: One new field in reply from PA_COMMAND_CREATE_RECORD_STREAM:
format_info format format_info format
New fields in reply from PA_COMMAND_GET_SOURCE_INFO (and thus
PA_COMMAND_GET_SOURCE_INFO_LIST)
uint8_t n_formats
format_info format1
...
format_info formatn

View file

@ -405,11 +405,16 @@ pa_operation* pa_context_set_sink_port_by_name(pa_context *c, const char *name,
static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_operation *o = userdata; pa_operation *o = userdata;
int eol = 1; int eol = 1;
pa_source_info i;
uint32_t j;
pa_assert(pd); pa_assert(pd);
pa_assert(o); pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1); pa_assert(PA_REFCNT_VALUE(o) >= 1);
/* For safety incase someone use fail: outside the while loop below */
pa_zero(i);
if (!o->context) if (!o->context)
goto finish; goto finish;
@ -421,11 +426,9 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
} else { } else {
while (!pa_tagstruct_eof(t)) { while (!pa_tagstruct_eof(t)) {
pa_source_info i;
pa_bool_t mute; pa_bool_t mute;
uint32_t flags; uint32_t flags;
uint32_t state; uint32_t state;
unsigned j;
const char *ap; const char *ap;
pa_zero(i); pa_zero(i);
@ -460,9 +463,7 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
(o->context->version >= 16 && (o->context->version >= 16 &&
(pa_tagstruct_getu32(t, &i.n_ports)))) { (pa_tagstruct_getu32(t, &i.n_ports)))) {
pa_context_fail(o->context, PA_ERR_PROTOCOL); goto fail;
pa_proplist_free(i.proplist);
goto finish;
} }
if (o->context->version >= 16) { if (o->context->version >= 16) {
@ -475,11 +476,7 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
pa_tagstruct_gets(t, &i.ports[0][j].description) < 0 || pa_tagstruct_gets(t, &i.ports[0][j].description) < 0 ||
pa_tagstruct_getu32(t, &i.ports[0][j].priority) < 0) { pa_tagstruct_getu32(t, &i.ports[0][j].priority) < 0) {
pa_context_fail(o->context, PA_ERR_PROTOCOL); goto fail;
pa_xfree(i.ports[0]);
pa_xfree(i.ports);
pa_proplist_free(i.proplist);
goto finish;
} }
i.ports[j] = &i.ports[0][j]; i.ports[j] = &i.ports[0][j];
@ -488,13 +485,8 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
i.ports[j] = NULL; i.ports[j] = NULL;
} }
if (pa_tagstruct_gets(t, &ap) < 0) { if (pa_tagstruct_gets(t, &ap) < 0)
pa_context_fail(o->context, PA_ERR_PROTOCOL); goto fail;
pa_xfree(i.ports[0]);
pa_xfree(i.ports);
pa_proplist_free(i.proplist);
goto finish;
}
if (ap) { if (ap) {
for (j = 0; j < i.n_ports; j++) for (j = 0; j < i.n_ports; j++)
@ -505,6 +497,22 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
} }
} }
if (o->context->version >= 22) {
uint8_t n_formats;
if (pa_tagstruct_getu8(t, &n_formats) < 0 || n_formats < 1)
goto fail;
i.formats = pa_xnew0(pa_format_info*, n_formats);
for (j = 0; j < n_formats; j++) {
i.n_formats++;
i.formats[j] = pa_format_info_new();
if (pa_tagstruct_get_format_info(t, i.formats[j]) < 0)
goto fail;
}
}
i.mute = (int) mute; i.mute = (int) mute;
i.flags = (pa_source_flags_t) flags; i.flags = (pa_source_flags_t) flags;
i.state = (pa_source_state_t) state; i.state = (pa_source_state_t) state;
@ -514,6 +522,11 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
cb(o->context, &i, 0, o->userdata); cb(o->context, &i, 0, o->userdata);
} }
if (i.formats) {
for (j = 0; j < i.n_formats; j++)
pa_format_info_free(i.formats[j]);
pa_xfree(i.formats);
}
if (i.ports) { if (i.ports) {
pa_xfree(i.ports[0]); pa_xfree(i.ports[0]);
pa_xfree(i.ports); pa_xfree(i.ports);
@ -530,6 +543,25 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
finish: finish:
pa_operation_done(o); pa_operation_done(o);
pa_operation_unref(o); pa_operation_unref(o);
return;
fail:
pa_assert(i.proplist);
pa_context_fail(o->context, PA_ERR_PROTOCOL);
if (i.formats) {
for (j = 0; j < i.n_formats; j++)
pa_format_info_free(i.formats[j]);
pa_xfree(i.formats);
}
if (i.ports) {
pa_xfree(i.ports[0]);
pa_xfree(i.ports);
}
pa_proplist_free(i.proplist);
goto finish;
} }
pa_operation* pa_context_get_source_info_list(pa_context *c, pa_source_info_cb_t cb, void *userdata) { pa_operation* pa_context_get_source_info_list(pa_context *c, pa_source_info_cb_t cb, void *userdata) {

View file

@ -310,6 +310,8 @@ typedef struct pa_source_info {
uint32_t n_ports; /**< Number of entries in port array \since 0.9.16 */ uint32_t n_ports; /**< Number of entries in port array \since 0.9.16 */
pa_source_port_info** ports; /**< Array of available ports, or NULL. Array is terminated by an entry set to NULL. The number of entries is stored in n_ports \since 0.9.16 */ pa_source_port_info** ports; /**< Array of available ports, or NULL. Array is terminated by an entry set to NULL. The number of entries is stored in n_ports \since 0.9.16 */
pa_source_port_info* active_port; /**< Pointer to active port in the array, or NULL \since 0.9.16 */ pa_source_port_info* active_port; /**< Pointer to active port in the array, or NULL \since 0.9.16 */
uint8_t n_formats; /**< Number of formats supported by the source. \since 1.0 */
pa_format_info **formats; /**< Array of formats supported by the source. \since 1.0 */
} pa_source_info; } pa_source_info;
/** Callback prototype for pa_context_get_source_info_by_name() and friends */ /** Callback prototype for pa_context_get_source_info_by_name() and friends */

View file

@ -3131,6 +3131,19 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
pa_tagstruct_puts(t, source->active_port ? source->active_port->name : NULL); pa_tagstruct_puts(t, source->active_port ? source->active_port->name : NULL);
} }
if (c->version >= 22) {
uint32_t i;
pa_format_info *f;
pa_idxset *formats = pa_source_get_formats(source);
pa_tagstruct_putu8(t, (uint8_t) pa_idxset_size(formats));
PA_IDXSET_FOREACH(f, formats, i) {
pa_tagstruct_put_format_info(t, f);
}
pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
}
} }
static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_client *client) { static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_client *client) {

View file

@ -333,7 +333,8 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
v[PA_VOLUME_SNPRINT_MAX], v[PA_VOLUME_SNPRINT_MAX],
vdb[PA_SW_VOLUME_SNPRINT_DB_MAX], vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
cm[PA_CHANNEL_MAP_SNPRINT_MAX]; cm[PA_CHANNEL_MAP_SNPRINT_MAX],
f[PA_FORMAT_INFO_SNPRINT_MAX];
char *pl; char *pl;
if (is_last < 0) { if (is_last < 0) {
@ -418,6 +419,14 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
if (i->active_port) if (i->active_port)
printf(_("\tActive Port: %s\n"), printf(_("\tActive Port: %s\n"),
i->active_port->name); i->active_port->name);
if (i->formats) {
uint8_t j;
printf(_("\tFormats:\n"));
for (j = 0; j < i->n_formats; j++)
printf("\t\t%s\n", pa_format_info_snprint(f, sizeof(f), i->formats[j]));
}
} }
static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) { static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {