filter-chain: dynamically allocate the params

Dynamically allocate the offsets and params arrays so that it can
support more than 512 params.

Fixes #2933
This commit is contained in:
Wim Taymans 2023-01-06 12:40:05 +01:00
parent be2757c121
commit 4f458b5d9a

View file

@ -1071,9 +1071,9 @@ static const struct pw_stream_events out_stream_events = {
static int setup_streams(struct impl *impl) static int setup_streams(struct impl *impl)
{ {
int res; int res;
uint32_t i, n_params; uint32_t i, n_params, *offs;
uint32_t offsets[512]; struct pw_array offsets;
const struct spa_pod *params[512]; const struct spa_pod **params = NULL;
struct spa_pod_dynamic_builder b; struct spa_pod_dynamic_builder b;
struct graph *graph = &impl->graph; struct graph *graph = &impl->graph;
@ -1097,23 +1097,40 @@ static int setup_streams(struct impl *impl)
&impl->playback_listener, &impl->playback_listener,
&out_stream_events, impl); &out_stream_events, impl);
n_params = 0;
spa_pod_dynamic_builder_init(&b, NULL, 0, 4096); spa_pod_dynamic_builder_init(&b, NULL, 0, 4096);
pw_array_init(&offsets, 512);
offsets[n_params++] = b.b.state.offset; if ((offs = pw_array_add(&offsets, sizeof(uint32_t))) == NULL) {
res = -errno;
goto done;
}
*offs = b.b.state.offset;
spa_format_audio_raw_build(&b.b, spa_format_audio_raw_build(&b.b,
SPA_PARAM_EnumFormat, &impl->capture_info); SPA_PARAM_EnumFormat, &impl->capture_info);
for (i = 0; i < graph->n_control; i++) { for (i = 0; i < graph->n_control; i++) {
offsets[n_params++] = b.b.state.offset; if ((offs = pw_array_add(&offsets, sizeof(uint32_t))) != NULL)
*offs = b.b.state.offset;
get_prop_info(graph, &b.b, i); get_prop_info(graph, &b.b, i);
} }
offsets[n_params++] = b.b.state.offset; if ((offs = pw_array_add(&offsets, sizeof(uint32_t))) != NULL)
*offs = b.b.state.offset;
get_props_param(graph, &b.b); get_props_param(graph, &b.b);
n_params = pw_array_get_len(&offsets, uint32_t);
if (n_params == 0) {
res = -ENOMEM;
goto done;
}
if ((params = calloc(n_params, sizeof(struct spa_pod*))) == NULL) {
res = -errno;
goto done;
}
offs = offsets.data;
for (i = 0; i < n_params; i++) for (i = 0; i < n_params; i++)
params[i] = spa_pod_builder_deref(&b.b, offsets[i]); params[i] = spa_pod_builder_deref(&b.b, offs[i]);
res = pw_stream_connect(impl->capture, res = pw_stream_connect(impl->capture,
PW_DIRECTION_INPUT, PW_DIRECTION_INPUT,
@ -1125,7 +1142,7 @@ static int setup_streams(struct impl *impl)
spa_pod_dynamic_builder_clean(&b); spa_pod_dynamic_builder_clean(&b);
if (res < 0) if (res < 0)
return res; goto done;
n_params = 0; n_params = 0;
spa_pod_dynamic_builder_init(&b, NULL, 0, 4096); spa_pod_dynamic_builder_init(&b, NULL, 0, 4096);
@ -1142,11 +1159,11 @@ static int setup_streams(struct impl *impl)
params, n_params); params, n_params);
spa_pod_dynamic_builder_clean(&b); spa_pod_dynamic_builder_clean(&b);
if (res < 0) done:
return res; free(params);
pw_array_clear(&offsets);
return res < 0 ? res : 0;
return 0;
} }
static uint32_t count_array(struct spa_json *json) static uint32_t count_array(struct spa_json *json)