Various fixes and improvements to enum_params

This commit is contained in:
Wim Taymans 2017-11-08 11:22:42 +01:00
parent 4d890a2d98
commit 30a4651c51
12 changed files with 481 additions and 159 deletions

View file

@ -151,8 +151,7 @@ struct impl {
struct spa_list empty;
};
#define CHECK_PORT_NUM(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS)
#define CHECK_PORT(this,d,p) (CHECK_PORT_NUM(this,d,p) && this->io)
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS)
#define DEFAULT_LIVE false
#define DEFAULT_WAVE wave_sine
@ -182,21 +181,36 @@ static int impl_node_enum_params(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
if (id == t->param.idProps) {
if (id == t->param.idList) {
if (*index > 0)
return SPA_RESULT_ENUM_END;
spa_pod_builder_object(builder,
id, t->param.List,
":", t->param.listId, "I", t->param.idProps);
}
else if (id == t->param.idProps) {
struct props *p = &this->props;
if (*index > 0)
return SPA_RESULT_ENUM_END;
spa_pod_builder_object(builder,
id, t->props,
":", t->prop_live, "b", this->props.live,
":", t->prop_wave, "Ie", this->props.wave,
":", t->prop_live, "b", p->live,
":", t->prop_wave, "Ie", p->wave,
2, t->wave_sine,
t->wave_square,
":", t->prop_freq, "dr", this->props.freq,
":", t->prop_freq, "dr", p->freq,
2, 0.0, 50000000.0,
":", t->prop_volume, "dr", this->props.volume,
":", t->prop_volume, "dr", p->volume,
2, 0.0, 10.0);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
(*index)++;
return SPA_RESULT_OK;
}
@ -212,18 +226,20 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
t = &this->type;
if (id == t->param.idProps) {
struct props *p = &this->props;
if (param == NULL) {
reset_props(this, &this->props);
reset_props(this, p);
return SPA_RESULT_OK;
}
spa_pod_object_parse(param,
":",t->prop_live, "?b", &this->props.live,
":",t->prop_wave, "?I", &this->props.wave,
":",t->prop_freq, "?d", &this->props.freq,
":",t->prop_volume, "?d", &this->props.volume,
":",t->prop_live, "?b", &p->live,
":",t->prop_wave, "?I", &p->wave,
":",t->prop_freq, "?d", &p->freq,
":",t->prop_volume, "?d", &p->volume,
NULL);
if (this->props.live)
if (p->live)
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
else
this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE;
@ -577,13 +593,27 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (id == t->param.idEnumFormat) {
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta };
if (*index < SPA_N_ELEMENTS(list))
spa_pod_builder_object(builder, id, t->param.List,
":", t->param.listId, "I", list[*index]);
else
return SPA_RESULT_ENUM_END;
}
else if (id == t->param.idEnumFormat) {
return port_enum_formats(this, direction, port_id, index, filter, builder);
}
else if (id == t->param.idFormat) {
return port_get_format(this, direction, port_id, index, filter, builder);
}
else if (id == t->param.idBuffers) {
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
if (*index > 0)
return SPA_RESULT_ENUM_END;
@ -598,6 +628,9 @@ impl_node_port_enum_params(struct spa_node *node,
":", t->param_alloc_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
switch (*index) {
case 0:
spa_pod_builder_object(builder,
@ -793,7 +826,7 @@ impl_node_port_set_io(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT_NUM(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
this->io = io;