filter-graph: handle NULL in and out

We need to pass exactly n_inputs and n_outputs pointers to the process
function but make it possible to set some to NULL so that the data is
ignored.
This commit is contained in:
Wim Taymans 2024-12-18 12:21:55 +01:00
parent 49f48a5fda
commit 3cf9ccf4a7
2 changed files with 14 additions and 2 deletions

View file

@ -246,17 +246,20 @@ static int impl_process(void *object,
for (i = 0, j = 0; i < impl->info.n_inputs; i++) {
while (j < graph->n_input) {
port = &graph->input[j++];
if (port->desc)
if (port->desc && in[i])
port->desc->connect_port(*port->hndl, port->port, (float*)in[i]);
if (!port->next)
break;
}
}
for (i = 0; i < impl->info.n_outputs; i++) {
if (out[i] == NULL)
continue;
port = i < graph->n_output ? &graph->output[i] : NULL;
if (port && port->desc)
port->desc->connect_port(*port->hndl, port->port, (float*)out[i]);
port->desc->connect_port(*port->hndl, port->port, out[i]);
else
memset(out[i], 0, n_samples * sizeof(float));
}

View file

@ -842,6 +842,8 @@ struct impl {
struct spa_handle *handle;
struct spa_filter_graph *graph;
struct spa_hook graph_listener;
uint32_t n_inputs;
uint32_t n_outputs;
};
static void capture_destroy(void *d)
@ -907,6 +909,8 @@ static void playback_process(void *d)
data_size = i == 0 ? size : SPA_MIN(data_size, size);
stride = SPA_MAX(stride, bd->chunk->stride);
}
for (; i < impl->n_inputs; i++)
cin[i] = NULL;
for (i = 0; i < out->buffer->n_datas; i++) {
bd = &out->buffer->datas[i];
@ -919,6 +923,8 @@ static void playback_process(void *d)
bd->chunk->size = data_size;
bd->chunk->stride = stride;
}
for (; i < impl->n_outputs; i++)
cout[i] = NULL;
pw_log_trace_fp("%p: stride:%d size:%d requested:%"PRIu64" (%"PRIu64")", impl,
stride, data_size, out->requested, out->requested * stride);
@ -1224,6 +1230,9 @@ static void graph_info(void *object, const struct spa_filter_graph_info *info)
if (impl->playback_info.channels == 0)
impl->playback_info.channels = info->n_outputs;
impl->n_inputs = info->n_inputs;
impl->n_outputs = info->n_outputs;
if (impl->capture_info.channels == impl->playback_info.channels) {
copy_position(&impl->capture_info, &impl->playback_info);
copy_position(&impl->playback_info, &impl->capture_info);