convert: refactor node_set_param functions

Move them to their own function to make the main function shorter.

Also make sure we emit the new ports first and then the node info.
This commit is contained in:
Wim Taymans 2025-05-12 10:31:01 +02:00
parent 8dfa086c3c
commit 2420c3a8c8
2 changed files with 130 additions and 102 deletions

View file

@ -1828,6 +1828,8 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
i = dir->n_ports++;
init_port(this, direction, i, 0, false, false, true);
}
/* emit all port changes */
emit_info(this, false);
this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
@ -1836,19 +1838,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
return 0;
}
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
static int node_set_param_port_config(struct impl *this, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
if (param == NULL)
return 0;
switch (id) {
case SPA_PARAM_PortConfig:
{
struct spa_audio_info info = { 0, }, *infop = NULL;
struct spa_pod *format = NULL;
enum spa_direction direction;
@ -1856,6 +1848,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
bool monitor = false, control = false;
int res;
if (param == NULL)
return 0;
if (spa_pod_parse_object(param,
SPA_TYPE_OBJECT_ParamPortConfig, NULL,
SPA_PARAM_PORT_CONFIG_direction, SPA_POD_Id(&direction),
@ -1885,15 +1880,18 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
infop = &info;
}
return reconfigure_mode(this, mode, direction, monitor, control, infop);
}
if ((res = reconfigure_mode(this, mode, direction, monitor, control, infop)) < 0)
return res;
break;
}
case SPA_PARAM_Props:
{
static int node_set_param_props(struct impl *this, uint32_t flags,
const struct spa_pod *param)
{
bool have_graph = false;
struct filter_graph *g, *t;
if (param == NULL)
return 0;
this->filter_props_count = 0;
spa_list_for_each_safe(g, t, &this->active_graphs, link) {
@ -1902,8 +1900,7 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
have_graph = true;
this->in_filter_props++;
spa_filter_graph_set_props(g->graph,
SPA_DIRECTION_INPUT, param);
spa_filter_graph_set_props(g->graph, SPA_DIRECTION_INPUT, param);
this->filter_props_count++;
this->in_filter_props--;
}
@ -1911,13 +1908,29 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
apply_props(this, param);
clean_filter_handles(this, false);
return 0;
}
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this = object;
int res;
spa_return_val_if_fail(this != NULL, -EINVAL);
switch (id) {
case SPA_PARAM_PortConfig:
res = node_set_param_port_config(this, flags, param);
break;
case SPA_PARAM_Props:
res = node_set_param_props(this, flags, param);
break;
}
default:
return -ENOENT;
}
emit_info(this, false);
return 0;
return res;
}
static int int32_cmp(const void *v1, const void *v2)

View file

@ -472,10 +472,10 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
port->latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
port->latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
port->info = SPA_PORT_INFO_INIT();
port->info.change_mask = port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
SPA_PORT_CHANGE_MASK_PROPS |
SPA_PORT_CHANGE_MASK_PARAMS;
port->info = SPA_PORT_INFO_INIT();
port->info.flags = SPA_PORT_FLAG_NO_REF |
SPA_PORT_FLAG_DYNAMIC_DATA;
port->params[IDX_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
@ -788,6 +788,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
init_port(this, direction, i, false, false, true);
}
/* emit all port info first, then the node props and flags */
emit_info(this, false);
this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS;
this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE;
this->params[IDX_PortConfig].user++;
@ -795,19 +798,9 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m
return 0;
}
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
static int node_set_param_port_config(struct impl *this, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
if (param == NULL)
return 0;
switch (id) {
case SPA_PARAM_PortConfig:
{
struct spa_video_info info = { 0, }, *infop = NULL;
struct spa_pod *format = NULL;
enum spa_direction direction;
@ -815,6 +808,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
bool monitor = false, control = false;
int res;
if (param == NULL)
return 0;
if (spa_pod_parse_object(param,
SPA_TYPE_OBJECT_ParamPortConfig, NULL,
SPA_PARAM_PORT_CONFIG_direction, SPA_POD_Id(&direction),
@ -833,19 +829,38 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
infop = &info;
}
return reconfigure_mode(this, mode, direction, monitor, control, infop);
}
static int node_set_param_props(struct impl *this, uint32_t flags,
const struct spa_pod *param)
{
if (param == NULL)
return 0;
if ((res = reconfigure_mode(this, mode, direction, monitor, control, infop)) < 0)
return res;
break;
}
case SPA_PARAM_Props:
apply_props(this, param);
return 0;
}
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this = object;
int res;
spa_return_val_if_fail(this != NULL, -EINVAL);
switch (id) {
case SPA_PARAM_PortConfig:
res = node_set_param_port_config(this, flags, param);
break;
case SPA_PARAM_Props:
res = node_set_param_props(this, flags, param);
break;
default:
return -ENOENT;
}
emit_info(this, false);
return 0;
return res;
}
static inline void free_decoder(struct impl *this)