adapter: move node.params to impl-node.c

Move configuration of initial Params from the adapter to the node to
make it more generally useful.

Add the same device.param config to devices.

This makes it possible to configure the default settings statically
while creating the nodes and devices.
This commit is contained in:
Wim Taymans 2024-02-13 16:01:10 +01:00
parent 4ab3ab6081
commit 59ea4ef897
4 changed files with 105 additions and 44 deletions

View file

@ -70,30 +70,6 @@ static const struct pw_impl_node_events node_events = {
.free = node_free,
};
static int handle_node_param(struct pw_impl_node *node, const char *key, const char *value)
{
const struct spa_type_info *ti;
uint8_t buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
struct spa_pod *pod;
int res;
ti = spa_debug_type_find_short(spa_type_param, key);
if (ti == NULL)
return -ENOENT;
if ((res = spa_json_to_pod(&b, 0, ti, value, strlen(value))) < 0)
return res;
if ((pod = spa_pod_builder_deref(&b, 0)) == NULL)
return -ENOSPC;
if ((res = pw_impl_node_set_param(node, ti->type, 0, pod)) < 0)
return res;
return 0;
}
static int find_format(struct spa_node *node, enum pw_direction direction,
uint32_t *media_type, uint32_t *media_subtype)
{
@ -172,8 +148,6 @@ struct pw_impl_node *pw_adapter_new(struct pw_context *context,
enum pw_direction direction;
int res;
uint32_t media_type, media_subtype;
const struct spa_dict_item *it;
struct pw_properties *copy;
struct info_data info;
spa_zero(info);
@ -233,16 +207,10 @@ struct pw_impl_node *pw_adapter_new(struct pw_context *context,
goto error;
}
copy = pw_properties_new(NULL, NULL);
spa_dict_for_each(it, &props->dict) {
if (!spa_strstartswith(it->key, "node.param.") &&
!spa_strstartswith(it->key, "port.param."))
pw_properties_set(copy, it->key, it->value);
}
node = pw_spa_node_load(context,
factory_name,
PW_SPA_NODE_FLAG_ACTIVATE | PW_SPA_NODE_FLAG_NO_REGISTER,
copy, sizeof(struct node) + user_data_size);
pw_properties_copy(props), sizeof(struct node) + user_data_size);
if (node == NULL) {
res = -errno;
pw_log_error("can't load spa node: %m");
@ -264,12 +232,6 @@ struct pw_impl_node *pw_adapter_new(struct pw_context *context,
pw_impl_node_add_listener(node, &n->node_listener, &node_events, n);
spa_dict_for_each(it, &props->dict) {
if (spa_strstartswith(it->key, "node.param.")) {
if ((res = handle_node_param(node, &it->key[11], it->value)) < 0)
pw_log_warn("can't set node param: %s", spa_strerror(res));
}
}
return node;
error: