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.
This commit is contained in:
Wim Taymans 2025-09-19 13:07:19 +02:00
parent 83242a5c3c
commit b57c6d3729
15 changed files with 115 additions and 89 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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. */

View file

@ -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);

View file

@ -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<<SPA_DATA_MemPtr) | (1<<SPA_DATA_DmaBuf)));
/* we are done */
pw_stream_update_params(stream, params, 1);
pw_stream_update_params(stream, params, n_params);
}
/* these are the stream events we listen for */
@ -369,14 +370,16 @@ static int build_formats(struct data *data, struct spa_pod_builder *b, const str
SDL_GetRendererInfo(data->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;
}

View file

@ -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<<SPA_DATA_MemPtr)));
/* a header metadata with timing information */
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)));
/* video cropping information */
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_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 * 4)
/* cursor information */
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_Cursor),
SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int(
@ -447,7 +448,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
CURSOR_META_SIZE(256,256)));
/* we are done */
pw_stream_update_params(stream, params, 4);
pw_stream_update_params(stream, params, n_params);
}
/* these are the stream events we listen for */
@ -463,15 +464,16 @@ static const struct pw_stream_events stream_events = {
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
{
uint32_t n_params = 0;
SDL_RendererInfo info;
SDL_GetRendererInfo(data->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)

View file

@ -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<<SPA_DATA_MemPtr)));
/* we are done */
pw_stream_update_params(stream, params, 1);
pw_stream_update_params(stream, params, n_params);
}
/* these are the stream events we listen for */
@ -256,15 +257,16 @@ static const struct pw_stream_events stream_events = {
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
{
uint32_t n_params = 0;
SDL_RendererInfo info;
SDL_GetRendererInfo(data->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;

View file

@ -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<<SPA_DATA_MemPtr)));
/* a header metadata with timing information */
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)));
/* video cropping information */
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_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 * 4)
/* cursor information */
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_Cursor),
SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int(
@ -415,7 +416,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
CURSOR_META_SIZE(256,256)));
/* we are done */
pw_stream_update_params(stream, params, 4);
pw_stream_update_params(stream, params, n_params);
}
/* these are the stream events we listen for */
@ -429,15 +430,16 @@ static const struct pw_stream_events stream_events = {
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
{
uint32_t n_params = 0;
SDL_RendererInfo info;
SDL_GetRendererInfo(data->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)

View file

@ -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<<SPA_DATA_MemFd));
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 const struct pw_stream_events stream_events = {
@ -352,6 +353,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));
@ -400,7 +402,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),
@ -423,7 +425,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);

View file

@ -378,6 +378,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;
int blocks, size, stride, buffertypes;
if (param == NULL || id != SPA_PARAM_Format)
@ -414,11 +415,10 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
modifier = modifiers[rand()%n_modifiers];
}
params[0] = fixate_format(&b, SPA_VIDEO_FORMAT_RGBA, &modifier);
params[1] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
supported_modifiers, sizeof(supported_modifiers)/sizeof(supported_modifiers[0]));
params[2] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
params[n_params++] = fixate_format(&b, SPA_VIDEO_FORMAT_RGBA, &modifier);
params[n_params++] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
supported_modifiers, SPA_N_ELEMENTS(supported_modifiers));
params[n_params++] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
NULL, 0);
printf("announcing fixated EnumFormats\n");
@ -426,7 +426,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
spa_debug_format(4, NULL, params[i]);
}
pw_stream_update_params(stream, params, 3);
pw_stream_update_params(stream, params, n_params);
return;
}
printf("no fixation required\n");
@ -436,7 +436,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
buffertypes = (1<<SPA_DATA_DmaBuf);
}
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),
@ -444,31 +444,31 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(buffertypes));
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 const struct pw_stream_events stream_events = {
@ -490,6 +490,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));
@ -540,9 +541,9 @@ 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] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
supported_modifiers, sizeof(supported_modifiers)/sizeof(supported_modifiers[0]));
params[1] = build_format(&b, SPA_VIDEO_FORMAT_RGBA, NULL, 0);
params[n_params++] = build_format(&b, SPA_VIDEO_FORMAT_RGBA,
supported_modifiers, SPA_N_ELEMENTS(supported_modifiers));
params[n_params++] = build_format(&b, SPA_VIDEO_FORMAT_RGBA, NULL, 0);
printf("announcing starting EnumFormats\n");
for (unsigned int i=0; i < 2; i++) {
@ -561,7 +562,7 @@ int main(int argc, char *argv[])
PW_ID_ANY,
PW_STREAM_FLAG_DRIVER |
PW_STREAM_FLAG_ALLOC_BUFFERS,
params, 2);
params, n_params);
/* unlock, run the loop and wait, this will trigger the callbacks */
pw_thread_loop_wait(data.loop);

View file

@ -304,6 +304,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;
@ -313,7 +314,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),
@ -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<<SPA_DATA_MemFd));
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 const struct pw_stream_events stream_events = {
@ -363,13 +364,14 @@ static void on_reneg_timeout(void *userdata, uint64_t expirations)
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;
width = data->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);

View file

@ -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