From b30ff4eca3a9e303d27b716d3552898e9cc23c6e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 14 Oct 2024 16:36:04 +0200 Subject: [PATCH] filter-chain: improve output data When we allocate data on an output port, always set it immediately on the plugin. We let output nodes allocate data and input ports consume it. When we have no data on an output port, use discard data or NULL. This ensure that the ports only have data when they are used by an input port and otherwise use discards or NULL data. --- src/modules/module-filter-chain.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 1cb311e21..3f665091d 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -2357,14 +2357,20 @@ static void node_cleanup(struct node *node) static int port_ensure_data(struct port *port, uint32_t i, uint32_t max_samples) { float *data; + struct node *node = port->node; + const struct fc_descriptor *d = node->desc->desc; + if ((data = port->audio_data[i]) == NULL) { data = calloc(max_samples, sizeof(float)); if (data == NULL) { pw_log_error("cannot create port data: %m"); return -errno; } + port->audio_data[i] = data; } - port->audio_data[i] = data; + pw_log_info("connect output port %s[%d]:%s %p", + node->name, i, d->ports[port->p].name, data); + d->connect_port(port->node->hndl[i], port->p, data); return 0; } @@ -2453,12 +2459,11 @@ static int graph_instantiate(struct graph *graph) } for (j = 0; j < desc->n_output; j++) { port = &node->output_port[j]; - if ((res = port_ensure_data(port, i, max_samples)) < 0) - goto error; - pw_log_info("connect output port %s[%d]:%s %p", - node->name, i, d->ports[port->p].name, - port->audio_data[i]); - d->connect_port(node->hndl[i], port->p, port->audio_data[i]); + if (port->audio_data[i] == NULL) { + pw_log_info("connect output port %s[%d]:%s %p", + node->name, i, d->ports[port->p].name, dd); + d->connect_port(node->hndl[i], port->p, dd); + } } for (j = 0; j < desc->n_control; j++) { port = &node->control_port[j];