From b57c6d3729a2214133b4e84d3733640aea6c1964 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 19 Sep 2025 13:07:19 +0200 Subject: [PATCH] examples: count the params as we add them Count the params as we add them to the param arrays and use that to update the stream params instead of using hardcoded indexes and sizes. This makes it easier to add params and it also revealed a miscounted param. --- src/examples/audio-capture.c | 5 +++-- src/examples/audio-dsp-filter.c | 5 +++-- src/examples/audio-src-ring.c | 5 +++-- src/examples/audio-src-ring2.c | 5 +++-- src/examples/audio-src.c | 5 +++-- src/examples/midi-src.c | 5 +++-- src/examples/video-dsp-src.c | 20 ++++++++++--------- src/examples/video-play-fixate.c | 11 +++++++---- src/examples/video-play-pull.c | 18 +++++++++-------- src/examples/video-play-reneg.c | 20 +++++++++++-------- src/examples/video-play.c | 18 +++++++++-------- src/examples/video-src-alloc.c | 18 +++++++++-------- src/examples/video-src-fixate.c | 33 ++++++++++++++++---------------- src/examples/video-src-reneg.c | 23 ++++++++++++---------- src/examples/video-src.c | 13 +++++++------ 15 files changed, 115 insertions(+), 89 deletions(-) diff --git a/src/examples/audio-capture.c b/src/examples/audio-capture.c index c44f905f6..2429a2d34 100644 --- a/src/examples/audio-capture.c +++ b/src/examples/audio-capture.c @@ -118,6 +118,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct pw_properties *props; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -164,7 +165,7 @@ int main(int argc, char *argv[]) * id means that this is a format enumeration (of 1 value). * We leave the channels and rate empty to accept the native graph * rate and channels. */ - params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, + params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &SPA_AUDIO_INFO_RAW_INIT( .format = SPA_AUDIO_FORMAT_F32)); @@ -176,7 +177,7 @@ int main(int argc, char *argv[]) PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, - params, 1); + params, n_params); /* and wait while we let things run */ pw_main_loop_run(data.loop); diff --git a/src/examples/audio-dsp-filter.c b/src/examples/audio-dsp-filter.c index f5bda85c9..8a43147a6 100644 --- a/src/examples/audio-dsp-filter.c +++ b/src/examples/audio-dsp-filter.c @@ -80,6 +80,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -133,7 +134,7 @@ int main(int argc, char *argv[]) NULL), NULL, 0); - params[0] = spa_process_latency_build(&b, + params[n_params++] = spa_process_latency_build(&b, SPA_PARAM_ProcessLatency, &SPA_PROCESS_LATENCY_INFO_INIT( .ns = 10 * SPA_NSEC_PER_MSEC @@ -144,7 +145,7 @@ int main(int argc, char *argv[]) * called in a realtime thread. */ if (pw_filter_connect(data.filter, PW_FILTER_FLAG_RT_PROCESS, - params, 1) < 0) { + params, n_params) < 0) { fprintf(stderr, "can't connect\n"); return -1; } diff --git a/src/examples/audio-src-ring.c b/src/examples/audio-src-ring.c index b96e26f10..c53f65f5c 100644 --- a/src/examples/audio-src-ring.c +++ b/src/examples/audio-src-ring.c @@ -162,6 +162,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct pw_properties *props; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -198,7 +199,7 @@ int main(int argc, char *argv[]) /* Make one parameter with the supported formats. The SPA_PARAM_EnumFormat * id means that this is a format enumeration (of 1 value). */ - params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, + params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &SPA_AUDIO_INFO_RAW_INIT( .format = SPA_AUDIO_FORMAT_F32, .channels = DEFAULT_CHANNELS, @@ -212,7 +213,7 @@ int main(int argc, char *argv[]) PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, - params, 1); + params, n_params); /* and wait while we let things run */ pw_main_loop_run(data.main_loop); diff --git a/src/examples/audio-src-ring2.c b/src/examples/audio-src-ring2.c index b3943cd11..734cbf885 100644 --- a/src/examples/audio-src-ring2.c +++ b/src/examples/audio-src-ring2.c @@ -191,6 +191,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct pw_properties *props; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -228,7 +229,7 @@ int main(int argc, char *argv[]) /* Make one parameter with the supported formats. The SPA_PARAM_EnumFormat * id means that this is a format enumeration (of 1 value). */ - params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, + params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &SPA_AUDIO_INFO_RAW_INIT( .format = SPA_AUDIO_FORMAT_F32, .channels = DEFAULT_CHANNELS, @@ -242,7 +243,7 @@ int main(int argc, char *argv[]) PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, - params, 1); + params, n_params); /* prefill the ringbuffer */ fill_f32(&data, samples, BUFFER_SIZE); diff --git a/src/examples/audio-src.c b/src/examples/audio-src.c index 08c93421e..914d18fe9 100644 --- a/src/examples/audio-src.c +++ b/src/examples/audio-src.c @@ -101,6 +101,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct pw_properties *props; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -141,7 +142,7 @@ int main(int argc, char *argv[]) /* Make one parameter with the supported formats. The SPA_PARAM_EnumFormat * id means that this is a format enumeration (of 1 value). */ - params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, + params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &SPA_AUDIO_INFO_RAW_INIT( .format = SPA_AUDIO_FORMAT_F32, .channels = DEFAULT_CHANNELS, @@ -155,7 +156,7 @@ int main(int argc, char *argv[]) PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, - params, 1); + params, n_params); /* and wait while we let things run */ pw_main_loop_run(data.loop); diff --git a/src/examples/midi-src.c b/src/examples/midi-src.c index edcaa0f08..90fd36c3d 100644 --- a/src/examples/midi-src.c +++ b/src/examples/midi-src.c @@ -178,6 +178,7 @@ int main(int argc, char *argv[]) uint8_t buffer[1024]; struct spa_pod_builder builder; struct spa_pod *params[1]; + uint32_t n_params = 0; pw_init(&argc, &argv); @@ -226,7 +227,7 @@ int main(int argc, char *argv[]) */ spa_pod_builder_init(&builder, buffer, sizeof(buffer)); - params[0] = spa_pod_builder_add_object(&builder, + params[n_params++] = spa_pod_builder_add_object(&builder, /* POD Object for the buffer parameter */ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, /* Default 1 buffer, minimum of 1, max of 32 buffers. @@ -242,7 +243,7 @@ int main(int argc, char *argv[]) SPA_PARAM_BUFFERS_stride, SPA_POD_Int(1)); pw_filter_update_params(data.filter, data.port, - (const struct spa_pod **)params, SPA_N_ELEMENTS(params)); + (const struct spa_pod **)params, n_params); /* Now connect this filter. We ask that our process function is * called in a realtime thread. */ diff --git a/src/examples/video-dsp-src.c b/src/examples/video-dsp-src.c index 5992088e7..61a189cfd 100644 --- a/src/examples/video-dsp-src.c +++ b/src/examples/video-dsp-src.c @@ -238,6 +238,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[5]; + uint32_t n_params = 0; if (param != NULL && id == SPA_PARAM_Tag) { spa_debug_pod(0, NULL, param); @@ -250,38 +251,38 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) data->stride = SPA_ROUND_UP_N(data->position->video.size.width * BPP, 4); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_size, SPA_POD_Int(data->stride * data->position->video.size.height), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride)); - params[1] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header), SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))); - params[2] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoDamage), SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int( sizeof(struct spa_meta_region) * 16, sizeof(struct spa_meta_region) * 1, sizeof(struct spa_meta_region) * 16)); - params[3] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoCrop), SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_region))); #define CURSOR_META_SIZE(w,h) (sizeof(struct spa_meta_cursor) + \ sizeof(struct spa_meta_bitmap) + w * h * CURSOR_BPP) - params[4] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Cursor), SPA_PARAM_META_size, SPA_POD_Int( CURSOR_META_SIZE(CURSOR_WIDTH,CURSOR_HEIGHT))); - pw_stream_update_params(stream, params, 5); + pw_stream_update_params(stream, params, n_params); } static void @@ -309,6 +310,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[2]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -335,7 +337,7 @@ int main(int argc, char *argv[]) PW_KEY_MEDIA_CLASS, "Video/Source", NULL)); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp), @@ -348,7 +350,7 @@ int main(int argc, char *argv[]) spa_tag_build_start(&b, &f, SPA_PARAM_Tag, SPA_DIRECTION_OUTPUT); items[0] = SPA_DICT_ITEM_INIT("my-tag-key", "my-special-tag-value"); spa_tag_build_add_dict(&b, &SPA_DICT_INIT(items, 1)); - params[1] = spa_tag_build_end(&b, &f); + params[n_params++] = spa_tag_build_end(&b, &f); } pw_stream_add_listener(data.stream, @@ -361,7 +363,7 @@ int main(int argc, char *argv[]) PW_ID_ANY, PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_MAP_BUFFERS, - params, 2); + params, n_params); pw_main_loop_run(data.loop); diff --git a/src/examples/video-play-fixate.c b/src/examples/video-play-fixate.c index 1a9128351..feb97b23c 100644 --- a/src/examples/video-play-fixate.c +++ b/src/examples/video-play-fixate.c @@ -297,6 +297,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[1]; + uint32_t n_params = 0; Uint32 sdl_format; void *d; @@ -341,7 +342,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) /* a SPA_TYPE_OBJECT_ParamBuffers object defines the acceptable size, * number, stride etc of the buffers */ - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), @@ -350,7 +351,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<renderer, &info); if (data->mod_info[0].n_modifiers > 0) { - params[n_params++] = build_format(b, &info, SPA_VIDEO_FORMAT_RGB, data->mod_info[0].modifiers, data->mod_info[0].n_modifiers); + params[n_params++] = build_format(b, + &info, SPA_VIDEO_FORMAT_RGB, + data->mod_info[0].modifiers, + data->mod_info[0].n_modifiers); } params[n_params++] = build_format(b, &info, SPA_VIDEO_FORMAT_RGB, NULL, 0); for (int i=0; i < n_params; i++) { spa_debug_format(2, NULL, params[i]); } - return n_params; } diff --git a/src/examples/video-play-pull.c b/src/examples/video-play-pull.c index f0c5892ac..13cc21cf8 100644 --- a/src/examples/video-play-pull.c +++ b/src/examples/video-play-pull.c @@ -330,6 +330,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[5]; + uint32_t n_params = 0; Uint32 sdl_format; void *d; int32_t mult, size, blocks; @@ -417,7 +418,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) /* a SPA_TYPE_OBJECT_ParamBuffers object defines the acceptable size, * number, stride etc of the buffers */ - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(blocks), @@ -426,19 +427,19 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<renderer, &info); - params[0] = sdl_build_formats(&info, b); + params[n_params++] = sdl_build_formats(&info, b); fprintf(stderr, "supported SDL formats:\n"); spa_debug_format(2, NULL, params[0]); - params[1] = spa_pod_builder_add_object(b, + params[n_params++] = spa_pod_builder_add_object(b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp), @@ -480,7 +482,7 @@ static int build_format(struct data *data, struct spa_pod_builder *b, const stru fprintf(stderr, "supported DSP formats:\n"); spa_debug_format(2, NULL, params[1]); - return 2; + return n_params; } static void do_quit(void *userdata, int signal_number) diff --git a/src/examples/video-play-reneg.c b/src/examples/video-play-reneg.c index 60a3a8bb4..3c9a1e984 100644 --- a/src/examples/video-play-reneg.c +++ b/src/examples/video-play-reneg.c @@ -190,6 +190,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[1]; + uint32_t n_params = 0; Uint32 sdl_format; void *d; @@ -234,7 +235,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) /* a SPA_TYPE_OBJECT_ParamBuffers object defines the acceptable size, * number, stride etc of the buffers */ - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), @@ -243,7 +244,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<renderer, &info); - params[0] = sdl_build_formats(&info, b); + params[n_params++] = sdl_build_formats(&info, b); fprintf(stderr, "supported SDL formats:\n"); spa_debug_format(2, NULL, params[0]); - return 1; + return n_params; } static int reneg_format(struct data *data) @@ -272,6 +274,7 @@ static int reneg_format(struct data *data) uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); const struct spa_pod *params[2]; + uint32_t n_params = 0; int32_t width, height; if (data->format.info.raw.format == 0) @@ -281,7 +284,7 @@ static int reneg_format(struct data *data) height = data->counter & 1 ? 240 : 480; fprintf(stderr, "renegotiate to %dx%d:\n", width, height); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), @@ -289,7 +292,7 @@ static int reneg_format(struct data *data) SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&SPA_RECTANGLE(width, height)), SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&data->format.info.raw.framerate)); - pw_stream_update_params(data->stream, params, 1); + pw_stream_update_params(data->stream, params, n_params); data->counter++; return 0; @@ -300,16 +303,17 @@ static int reneg_buffers(struct data *data) uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); const struct spa_pod *params[2]; + uint32_t n_params = 0; fprintf(stderr, "renegotiate buffers\n"); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_size, SPA_POD_Int(data->stride * data->size.height), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride)); - pw_stream_update_params(data->stream, params, 1); + pw_stream_update_params(data->stream, params, n_params); data->counter++; return 0; diff --git a/src/examples/video-play.c b/src/examples/video-play.c index 55c656277..f4f65bb8f 100644 --- a/src/examples/video-play.c +++ b/src/examples/video-play.c @@ -289,6 +289,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[5]; + uint32_t n_params = 0; Uint32 sdl_format; void *d; int32_t mult, size, blocks; @@ -385,7 +386,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) /* a SPA_TYPE_OBJECT_ParamBuffers object defines the acceptable size, * number, stride etc of the buffers */ - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(blocks), @@ -394,19 +395,19 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<renderer, &info); - params[0] = sdl_build_formats(&info, b); + params[n_params++] = sdl_build_formats(&info, b); fprintf(stderr, "supported SDL formats:\n"); spa_debug_format(2, NULL, params[0]); - params[1] = spa_pod_builder_add_object(b, + params[n_params++] = spa_pod_builder_add_object(b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp), @@ -446,7 +448,7 @@ static int build_format(struct data *data, struct spa_pod_builder *b, const stru fprintf(stderr, "supported DSP formats:\n"); spa_debug_format(2, NULL, params[1]); - return 2; + return n_params; } static void do_quit(void *userdata, int signal_number) diff --git a/src/examples/video-src-alloc.c b/src/examples/video-src-alloc.c index 8348fdf92..add9597ed 100644 --- a/src/examples/video-src-alloc.c +++ b/src/examples/video-src-alloc.c @@ -290,6 +290,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[5]; + uint32_t n_params = 0; if (param == NULL || id != SPA_PARAM_Format) return; @@ -298,7 +299,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) data->stride = SPA_ROUND_UP_N(data->format.size.width * BPP, 4); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), @@ -306,31 +307,31 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride), SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(1<stride = SPA_ROUND_UP_N(data->format.size.width * BPP, 4); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), @@ -321,31 +322,31 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride), SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(1<cycle & 1 ? 320 : 640; height = data->cycle & 1 ? 240 : 480; fprintf(stderr, "renegotiate to %dx%d:\n", width, height); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), @@ -377,7 +379,7 @@ static void on_reneg_timeout(void *userdata, uint64_t expirations) SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&SPA_RECTANGLE(width, height)), SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(25, 1))); - pw_stream_update_params(data->stream, params, 1); + pw_stream_update_params(data->stream, params, n_params); data->cycle++; } @@ -392,6 +394,7 @@ int main(int argc, char *argv[]) { struct data data = { 0, }; const struct spa_pod *params[1]; + uint32_t n_params = 0; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -445,7 +448,7 @@ int main(int argc, char *argv[]) * The server will select a format that matches and informs us about this * in the stream param_changed event. */ - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), @@ -468,7 +471,7 @@ int main(int argc, char *argv[]) PW_ID_ANY, PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_ALLOC_BUFFERS, - params, 1); + params, n_params); /* unlock, run the loop and wait, this will trigger the callbacks */ pw_thread_loop_wait(data.loop); diff --git a/src/examples/video-src.c b/src/examples/video-src.c index cba32c94e..452924e59 100644 --- a/src/examples/video-src.c +++ b/src/examples/video-src.c @@ -217,6 +217,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) uint8_t params_buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); const struct spa_pod *params[5]; + uint32_t n_params = 0; if (param != NULL && id == SPA_PARAM_Tag) { spa_debug_pod(0, NULL, param); @@ -232,38 +233,38 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param) data->stride = SPA_ROUND_UP_N(data->format.size.width * BPP, 4); - params[0] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_size, SPA_POD_Int(data->stride * data->format.size.height), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride)); - params[1] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header), SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))); - params[2] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoDamage), SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int( sizeof(struct spa_meta_region) * 16, sizeof(struct spa_meta_region) * 1, sizeof(struct spa_meta_region) * 16)); - params[3] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoCrop), SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_region))); #define CURSOR_META_SIZE(w,h) (sizeof(struct spa_meta_cursor) + \ sizeof(struct spa_meta_bitmap) + w * h * CURSOR_BPP) - params[4] = spa_pod_builder_add_object(&b, + params[n_params++] = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Cursor), SPA_PARAM_META_size, SPA_POD_Int( CURSOR_META_SIZE(CURSOR_WIDTH,CURSOR_HEIGHT))); - pw_stream_update_params(stream, params, 5); + pw_stream_update_params(stream, params, n_params); } static void