node: add port and node params

Add a new struct spa_param_info that lists the available params on
a node/port and if they are readable/writable/updated. We can use
this to replace and improve the PARAM_List and also to notify
property change and updates.

Update elements and code to deal with this new param stuff. Add
port and node info to most elements and signal changes.

Use async enum_params in -inspect and use the param info to know
which ones to enumerate.

Use the port info to know what parameters to update in the
remote-node.
This commit is contained in:
Wim Taymans 2019-02-27 16:43:01 +01:00
parent 3d25adc598
commit 499dd3ff22
52 changed files with 1979 additions and 1461 deletions

View file

@ -75,10 +75,9 @@ struct port {
struct spa_io_buffers *io;
struct spa_io_range *range;
double *io_volume;
int32_t *io_mute;
struct spa_port_info info;
struct spa_param_info params[8];
int valid:1;
int have_format:1;
@ -96,6 +95,9 @@ struct impl {
struct spa_log *log;
struct spa_node_info info;
struct spa_param_info params[8];
const struct spa_node_callbacks *callbacks;
void *user_data;
@ -161,6 +163,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
return 0;
}
static void emit_node_info(struct impl *this)
{
if (this->callbacks && this->callbacks->info && this->info.change_mask) {
this->callbacks->info(this->user_data, &this->info);
this->info.change_mask = 0;
}
}
static void emit_port_info(struct impl *this, struct port *port)
{
if (this->callbacks && this->callbacks->port_info && port->info.change_mask) {
@ -184,6 +194,7 @@ impl_node_set_callbacks(struct spa_node *node,
this->callbacks = callbacks;
this->user_data = user_data;
emit_node_info(this);
emit_port_info(this, GET_OUT_PORT(this, 0));
for (i = 0; i < this->last_port; i++) {
if (this->in_ports[i].valid)
@ -209,16 +220,22 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
port->id = port_id;
port_props_reset(&port->props);
port->io_volume = &port->props.volume;
port->io_mute = &port->props.mute;
spa_list_init(&port->queue);
port->info = SPA_PORT_INFO_INIT();
port->info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_REMOVABLE |
SPA_PORT_FLAG_OPTIONAL |
SPA_PORT_FLAG_IN_PLACE;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
port->info.params = port->params;
port->info.n_params = 5;
this->port_count++;
if (this->last_port <= port_id)
@ -332,22 +349,6 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_List:
{
uint32_t list[] = { SPA_PARAM_EnumFormat,
SPA_PARAM_Format,
SPA_PARAM_Buffers,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (result.index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.index]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, result.index, &param, &b)) <= 0)
return res;
@ -381,9 +382,6 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
break;
case SPA_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (result.index) {
case 0:
param = spa_pod_builder_add_object(&b,
@ -523,6 +521,16 @@ static int port_set_format(struct spa_node *node,
this, direction, port_id);
}
}
if (port->have_format) {
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
} else {
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
}
emit_port_info(this, port);
return 0;
}
@ -892,14 +900,29 @@ impl_init(const struct spa_handle_factory *factory,
}
this->node = impl_node;
this->info = SPA_NODE_INFO_INIT();
this->info.max_input_ports = MAX_PORTS;
this->info.max_output_ports = 1;
this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS;
this->info.flags = SPA_NODE_FLAG_RT | SPA_NODE_FLAG_DYNAMIC_INPUT_PORTS;
port = GET_OUT_PORT(this, 0);
port->valid = true;
port->direction = SPA_DIRECTION_OUTPUT;
port->id = 0;
port->info = SPA_PORT_INFO_INIT();
port->info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
SPA_PORT_FLAG_NO_REF;
SPA_PORT_FLAG_NO_REF;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
port->info.params = port->params;
port->info.n_params = 5;
spa_list_init(&port->queue);
return 0;

View file

@ -379,7 +379,7 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
result.index = result.next++;
if (result.index >= this->n_params)
return 0;
break;
param = this->params[result.index];
@ -390,10 +390,11 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
if (spa_pod_filter(&b, &result.param, param, filter) != 0)
continue;
pw_log_debug("client-node %p: %d param %u", this, seq, result.index);
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
return res;
if (++count != num)
if (++count == num)
break;
}
return 0;
@ -668,7 +669,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
result.index = result.next++;
if (result.index >= port->n_params)
return 0;
break;
param = port->params[result.index];
@ -683,7 +684,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
return res;
if (++count != num)
if (++count == num)
break;
}
return 0;

View file

@ -137,20 +137,6 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_List:
{
uint32_t list[] = { SPA_PARAM_Props,
SPA_PARAM_EnumFormat,
SPA_PARAM_Format };
if (result.index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.index]));
else
return 0;
break;
}
case SPA_PARAM_Props:
if (impl->adapter == impl->cnode)
return 0;
@ -326,6 +312,26 @@ static const struct spa_node_callbacks adapter_node_callbacks = {
.result = adapter_result,
};
static void emit_node_info(struct node *this)
{
if (this->callbacks && this->callbacks->info) {
struct spa_node_info info;
struct spa_param_info params[4];
info = SPA_NODE_INFO_INIT();
info.max_input_ports = 0;
info.max_output_ports = 0;
info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
params[1] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE);
params[2] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ);
params[3] = SPA_PARAM_INFO(SPA_PARAM_Profile, SPA_PARAM_INFO_WRITE);
info.params = params;
info.n_params = 4;
this->callbacks->info(this->callbacks_data, &info);
}
}
static int
impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks,
@ -342,6 +348,8 @@ impl_node_set_callbacks(struct spa_node *node,
this->callbacks = callbacks;
this->callbacks_data = data;
emit_node_info(this);
if (this->callbacks && impl->adapter && impl->adapter != impl->cnode)
spa_node_set_callbacks(impl->adapter, &adapter_node_callbacks, impl);

View file

@ -107,10 +107,18 @@ client_node_marshal_port_update(void *object,
SPA_POD_Pod(params[i]), NULL);
if (info) {
uint64_t change_mask = info->change_mask;
n_items = info->props ? info->props->n_items : 0;
change_mask &= SPA_PORT_CHANGE_MASK_FLAGS |
SPA_PORT_CHANGE_MASK_RATE |
SPA_PORT_CHANGE_MASK_PROPS |
SPA_PORT_CHANGE_MASK_PARAMS;
spa_pod_builder_push_struct(b, &f[1]);
spa_pod_builder_add(b,
SPA_POD_Long(change_mask),
SPA_POD_Int(info->flags),
SPA_POD_Int(info->rate),
SPA_POD_Int(n_items), NULL);
@ -119,7 +127,15 @@ client_node_marshal_port_update(void *object,
SPA_POD_String(info->props->items[i].key),
SPA_POD_String(info->props->items[i].value), NULL);
}
spa_pod_builder_add(b,
SPA_POD_Int(info->n_params), NULL);
for (i = 0; i < info->n_params; i++) {
spa_pod_builder_add(b,
SPA_POD_Id(info->params[i].id),
SPA_POD_Int(info->params[i].flags), NULL);
}
spa_pod_builder_pop(b, &f[1]);
} else {
spa_pod_builder_add(b,
SPA_POD_Pod(NULL), NULL);
@ -812,11 +828,17 @@ static int client_node_demarshal_port_update(void *object, void *data, size_t si
spa_pod_parser_pod(&p2, ipod);
if (spa_pod_parser_push_struct(&p2, &f2) < 0 ||
spa_pod_parser_get(&p2,
SPA_POD_Long(&info.change_mask),
SPA_POD_Int(&info.flags),
SPA_POD_Int(&info.rate),
SPA_POD_Int(&props.n_items), NULL) < 0)
return -EINVAL;
info.change_mask &= SPA_PORT_CHANGE_MASK_FLAGS |
SPA_PORT_CHANGE_MASK_RATE |
SPA_PORT_CHANGE_MASK_PROPS |
SPA_PORT_CHANGE_MASK_PARAMS;
if (props.n_items > 0) {
info.props = &props;
@ -828,6 +850,19 @@ static int client_node_demarshal_port_update(void *object, void *data, size_t si
return -EINVAL;
}
}
if (spa_pod_parser_get(&p2,
SPA_POD_Int(&info.n_params), NULL) < 0)
return -EINVAL;
if (info.n_params > 0) {
info.params = alloca(info.n_params * sizeof(struct spa_param_info));
for (i = 0; i < info.n_params; i++) {
if (spa_pod_parser_get(&p2,
SPA_POD_Id(&info.params[i].id),
SPA_POD_Int(&info.params[i].flags), NULL) < 0)
return -EINVAL;
}
}
}
pw_resource_do(resource, struct pw_client_node_proxy_methods, port_update, 0, direction,

View file

@ -406,27 +406,14 @@ static int add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_
int res;
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
uint32_t idx1, idx2, id;
uint32_t i, idx2, id;
uint8_t buf[2048];
struct spa_pod_builder b = { 0 };
for (idx1 = 0;;) {
for (i = 0; i < port->info.n_params; i++) {
struct spa_pod *param;
spa_pod_builder_init(&b, buf, sizeof(buf));
if (spa_node_port_enum_params_sync(port->node->node,
port->direction, port->port_id,
SPA_PARAM_List, &idx1,
NULL, &param, &b,
port->node->pending) != 1)
break;
spa_pod_parse_object(param,
SPA_TYPE_OBJECT_ParamList, NULL,
SPA_PARAM_LIST_id, SPA_POD_Id(&id));
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
params[n_params++] = spa_pod_copy(param);
id = port->info.params[i].id;
for (idx2 = 0;;) {
spa_pod_builder_init(&b, buf, sizeof(buf));

View file

@ -113,7 +113,7 @@ static struct pw_port *get_port(struct pw_node *node, enum spa_direction directi
if (port_id == SPA_ID_INVALID)
return NULL;
p = pw_port_new(direction, port_id, 0, NULL, 0);
p = pw_port_new(direction, port_id, NULL, 0);
if (p == NULL)
return NULL;

View file

@ -119,6 +119,21 @@ static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict)
spa_pod_builder_pop(b, &f);
}
static void push_params(struct spa_pod_builder *b, uint32_t n_params,
const struct spa_param_info *params)
{
uint32_t i;
struct spa_pod_frame f;
spa_pod_builder_push_struct(b, &f);
spa_pod_builder_int(b, n_params);
for (i = 0; i < n_params; i++) {
spa_pod_builder_id(b, params[i].id);
spa_pod_builder_int(b, params[i].flags);
}
spa_pod_builder_pop(b, &f);
}
static int
core_method_marshal_create_object(void *object,
const char *factory_name,
@ -612,6 +627,7 @@ static int device_marshal_info(void *object, const struct pw_device_info *info)
SPA_POD_Long(info->change_mask),
NULL);
push_dict(b, info->props);
push_params(b, info->n_params, info->params);
spa_pod_builder_pop(b, &f);
return pw_protocol_native_end_resource(resource, b);
@ -647,6 +663,22 @@ static int device_demarshal_info(void *object, void *data, size_t size)
SPA_POD_String(&props.items[i].value), NULL) < 0)
return -EINVAL;
}
spa_pod_parser_pop(&prs, &f[1]);
if (spa_pod_parser_push_struct(&prs, &f[1]) < 0 ||
spa_pod_parser_get(&prs,
SPA_POD_Int(&info.n_params),
NULL) < 0)
return -EINVAL;
info.params = alloca(info.n_params * sizeof(struct spa_param_info));
for (i = 0; i < info.n_params; i++) {
if (spa_pod_parser_get(&prs,
SPA_POD_Id(&info.params[i].id),
SPA_POD_Int(&info.params[i].flags), NULL) < 0)
return -EINVAL;
}
return pw_proxy_notify(proxy, struct pw_device_proxy_events, info, 0, &info);
}
@ -838,6 +870,7 @@ static int node_marshal_info(void *object, const struct pw_node_info *info)
SPA_POD_String(info->error),
NULL);
push_dict(b, info->props);
push_params(b, info->n_params, info->params);
spa_pod_builder_pop(b, &f);
return pw_protocol_native_end_resource(resource, b);
@ -879,6 +912,22 @@ static int node_demarshal_info(void *object, void *data, size_t size)
SPA_POD_String(&props.items[i].value), NULL) < 0)
return -EINVAL;
}
spa_pod_parser_pop(&prs, &f[1]);
if (spa_pod_parser_push_struct(&prs, &f[1]) < 0 ||
spa_pod_parser_get(&prs,
SPA_POD_Int(&info.n_params),
NULL) < 0)
return -EINVAL;
info.params = alloca(info.n_params * sizeof(struct spa_param_info));
for (i = 0; i < info.n_params; i++) {
if (spa_pod_parser_get(&prs,
SPA_POD_Id(&info.params[i].id),
SPA_POD_Int(&info.params[i].flags), NULL) < 0)
return -EINVAL;
}
return pw_proxy_notify(proxy, struct pw_node_proxy_events, info, 0, &info);
}
@ -1032,6 +1081,7 @@ static int port_marshal_info(void *object, const struct pw_port_info *info)
SPA_POD_Long(info->change_mask),
NULL);
push_dict(b, info->props);
push_params(b, info->n_params, info->params);
spa_pod_builder_pop(b, &f);
return pw_protocol_native_end_resource(resource, b);
@ -1067,6 +1117,21 @@ static int port_demarshal_info(void *object, void *data, size_t size)
SPA_POD_String(&props.items[i].value), NULL) < 0)
return -EINVAL;
}
spa_pod_parser_pop(&prs, &f[1]);
if (spa_pod_parser_push_struct(&prs, &f[1]) < 0 ||
spa_pod_parser_get(&prs,
SPA_POD_Int(&info.n_params),
NULL) < 0)
return -EINVAL;
info.params = alloca(info.n_params * sizeof(struct spa_param_info));
for (i = 0; i < info.n_params; i++) {
if (spa_pod_parser_get(&prs,
SPA_POD_Id(&info.params[i].id),
SPA_POD_Int(&info.params[i].flags), NULL) < 0)
return -EINVAL;
}
return pw_proxy_notify(proxy, struct pw_port_proxy_events, info, 0, &info);
}