diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 898211576..b3b75dd8a 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -1071,9 +1071,9 @@ static const struct pw_stream_events out_stream_events = { static int setup_streams(struct impl *impl) { int res; - uint32_t i, n_params; - uint32_t offsets[512]; - const struct spa_pod *params[512]; + uint32_t i, n_params, *offs; + struct pw_array offsets; + const struct spa_pod **params = NULL; struct spa_pod_dynamic_builder b; struct graph *graph = &impl->graph; @@ -1097,23 +1097,40 @@ static int setup_streams(struct impl *impl) &impl->playback_listener, &out_stream_events, impl); - n_params = 0; 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_PARAM_EnumFormat, &impl->capture_info); 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); } - 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); + 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++) - 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, PW_DIRECTION_INPUT, @@ -1125,7 +1142,7 @@ static int setup_streams(struct impl *impl) spa_pod_dynamic_builder_clean(&b); if (res < 0) - return res; + goto done; n_params = 0; spa_pod_dynamic_builder_init(&b, NULL, 0, 4096); @@ -1142,11 +1159,11 @@ static int setup_streams(struct impl *impl) params, n_params); spa_pod_dynamic_builder_clean(&b); - if (res < 0) - return res; +done: + free(params); + pw_array_clear(&offsets); - - return 0; + return res < 0 ? res : 0; } static uint32_t count_array(struct spa_json *json)