filter-chain: first create instances and then link port

First make instances of all the plugins and then try to link them up.

Otherwise, depending on the order the plugins are defined in the config,
a link will try to create port data and set it on the instance, which is
still NULL and we crash.
This commit is contained in:
Wim Taymans 2024-10-24 10:55:50 +02:00
parent cdb3c64753
commit 9697b67802

View file

@ -2348,19 +2348,12 @@ static int graph_instantiate(struct graph *graph)
graph->instantiated = true; graph->instantiated = true;
/* first make instances */
spa_list_for_each(node, &graph->node_list, link) { spa_list_for_each(node, &graph->node_list, link) {
node_cleanup(node); node_cleanup(node);
desc = node->desc; desc = node->desc;
d = desc->desc; d = desc->desc;
if (d->flags & FC_DESCRIPTOR_SUPPORTS_NULL_DATA) {
sd = dd = NULL;
}
else {
sd = impl->silence_data;
dd = impl->discard_data;
}
for (i = 0; i < node->n_hndl; i++) { for (i = 0; i < node->n_hndl; i++) {
pw_log_info("instantiate %s %d rate:%lu", d->name, i, impl->rate); pw_log_info("instantiate %s %d rate:%lu", d->name, i, impl->rate);
@ -2370,6 +2363,21 @@ static int graph_instantiate(struct graph *graph)
res = -errno; res = -errno;
goto error; goto error;
} }
}
}
/* then link ports and activate */
spa_list_for_each(node, &graph->node_list, link) {
desc = node->desc;
d = desc->desc;
if (d->flags & FC_DESCRIPTOR_SUPPORTS_NULL_DATA) {
sd = dd = NULL;
}
else {
sd = impl->silence_data;
dd = impl->discard_data;
}
for (i = 0; i < node->n_hndl; i++) {
for (j = 0; j < desc->n_input; j++) { for (j = 0; j < desc->n_input; j++) {
port = &node->input_port[j]; port = &node->input_port[j];
d->connect_port(node->hndl[i], port->p, sd); d->connect_port(node->hndl[i], port->p, sd);