From cc842cbdc8a5b69bda752ff85569b4efef02fd16 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 5 Sep 2018 16:41:07 +0200 Subject: [PATCH] Type changes Only allow properties inside objects, this makes it easier to iterate the object, which is needed for efficiently processing control streams. Add a choice type to mark variable properties. SPA_TYPE_Enum -> SPA_TYPE_Id to avoid confusion with choice enum Make it easier to allocate and initialize properties on the stack Make more efficient methods to make objects. --- spa/include/spa/debug/format.h | 77 ++-- spa/include/spa/debug/pod.h | 170 ++++---- spa/include/spa/monitor/type-info.h | 6 +- spa/include/spa/node/type-info.h | 4 +- spa/include/spa/param/audio/format-utils.h | 13 +- spa/include/spa/param/type-info.h | 42 +- spa/include/spa/param/video/format-utils.h | 11 +- spa/include/spa/pod/builder.h | 382 ++++++++++++------ spa/include/spa/pod/compare.h | 27 +- spa/include/spa/pod/filter.h | 259 ++++++------ spa/include/spa/pod/iter.h | 64 ++- spa/include/spa/pod/parser.h | 26 +- spa/include/spa/pod/pod.h | 85 ++-- spa/include/spa/utils/type-info.h | 18 +- spa/include/spa/utils/type.h | 8 +- spa/plugins/alsa/alsa-monitor.c | 120 +++--- spa/plugins/alsa/alsa-sink.c | 98 +++-- spa/plugins/alsa/alsa-source.c | 93 +++-- spa/plugins/alsa/alsa-utils.c | 54 +-- spa/plugins/audioconvert/audioconvert.c | 21 +- spa/plugins/audioconvert/channelmix.c | 76 ++-- spa/plugins/audioconvert/fmtconvert.c | 107 ++--- spa/plugins/audioconvert/merger.c | 97 ++--- spa/plugins/audioconvert/resample.c | 67 +-- spa/plugins/audioconvert/splitter.c | 104 ++--- spa/plugins/audiomixer/audiomixer.c | 71 ++-- spa/plugins/audiotestsrc/audiotestsrc.c | 140 ++++--- spa/plugins/audiotestsrc/render.c | 6 +- spa/plugins/bluez5/a2dp-sink.c | 69 ++-- spa/plugins/bluez5/bluez5-monitor.c | 46 ++- spa/plugins/ffmpeg/ffmpeg-dec.c | 6 +- spa/plugins/ffmpeg/ffmpeg-enc.c | 6 +- spa/plugins/test/fakesink.c | 29 +- spa/plugins/test/fakesrc.c | 34 +- spa/plugins/v4l2/v4l2-monitor.c | 63 +-- spa/plugins/v4l2/v4l2-source.c | 114 +++--- spa/plugins/v4l2/v4l2-utils.c | 152 ++++--- spa/plugins/videotestsrc/videotestsrc.c | 86 ++-- spa/plugins/volume/volume.c | 81 ++-- spa/tests/meson.build | 8 +- spa/tests/test-control.c | 27 +- spa/tests/test-graph.c | 12 +- spa/tests/test-mixer.c | 23 +- spa/tests/test-perf.c | 5 +- spa/tests/test-props.c | 240 +++++++---- spa/tests/test-props2.c | 16 +- spa/tests/test-ringbuffer.c | 8 +- spa/tests/test-v4l2.c | 3 +- src/examples/export-sink.c | 46 ++- src/examples/export-source.c | 129 +++--- src/examples/local-v4l2.c | 139 +------ src/examples/sdl.h | 41 +- src/examples/video-play.c | 17 +- src/examples/video-src.c | 43 +- src/gst/gstpipewireformat.c | 254 ++++++------ src/gst/gstpipewiresink.c | 24 +- src/gst/gstpipewiresrc.c | 16 +- .../module-client-node/protocol-native.c | 30 +- src/modules/module-media-session/floatmix.c | 56 +-- .../module-protocol-native/protocol-native.c | 26 +- src/modules/spa/spa-monitor.c | 6 +- src/modules/spa/spa-node.c | 16 +- src/pipewire/stream.c | 16 +- 63 files changed, 2253 insertions(+), 1880 deletions(-) diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 9a8371c59..b9fb2a6a3 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -37,7 +37,7 @@ spa_debug_format_value(const struct spa_type_info *info, case SPA_TYPE_Bool: fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false"); break; - case SPA_TYPE_Enum: + case SPA_TYPE_Id: { const char *str = spa_debug_type_find_name(info, *(int32_t *) body); char tmp[64]; @@ -85,6 +85,20 @@ spa_debug_format_value(const struct spa_type_info *info, case SPA_TYPE_Bytes: fprintf(stderr, "Bytes"); break; + case SPA_TYPE_Array: + { + void *p; + struct spa_pod_array_body *b = body; + int i = 0; + fprintf(stderr, "< "); + SPA_POD_ARRAY_BODY_FOREACH(b, size, p) { + if (i++ > 0) + fprintf(stderr, ", "); + spa_debug_format_value(info, b->child.type, p, b->child.size); + } + fprintf(stderr, " >"); + break; + } default: fprintf(stderr, "INVALID type %d", type); break; @@ -98,12 +112,12 @@ static inline int spa_debug_format(int indent, int i; const char *media_type; const char *media_subtype; - struct spa_pod *pod; + struct spa_pod_prop *prop; uint32_t mtype, mstype; const char *pod_type_names[] = { [SPA_TYPE_None] = "none", [SPA_TYPE_Bool] = "bool", - [SPA_TYPE_Enum] = "enum", + [SPA_TYPE_Id] = "id", [SPA_TYPE_Int] = "int", [SPA_TYPE_Long] = "long", [SPA_TYPE_Float] = "float", @@ -118,7 +132,7 @@ static inline int spa_debug_format(int indent, [SPA_TYPE_Object] = "object", [SPA_TYPE_Pointer] = "pointer", [SPA_TYPE_Fd] = "fd", - [SPA_TYPE_Prop] = "prop", + [SPA_TYPE_Choice] = "choice", [SPA_TYPE_Pod] = "pod" }; @@ -138,50 +152,45 @@ static inline int spa_debug_format(int indent, media_type ? rindex(media_type, ':') + 1 : "unknown", media_subtype ? rindex(media_subtype, ':') + 1 : "unknown"); - SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, pod) { - struct spa_pod_prop *prop; + SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, prop) { const char *key; const struct spa_type_info *ti; + uint32_t type, size, n_vals, choice; + const struct spa_pod *val; + void *vals; - if (pod->type != SPA_TYPE_Prop) + if (prop->key == SPA_FORMAT_mediaType || + prop->key == SPA_FORMAT_mediaSubtype) continue; - prop = (struct spa_pod_prop *)pod; + val = spa_pod_get_values(&prop->value, &n_vals, &choice); - if ((prop->body.flags & SPA_POD_PROP_FLAG_UNSET) && - (prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL)) - continue; + type = val->type; + size = val->size; + vals = SPA_POD_BODY(val); - if (prop->body.key == SPA_FORMAT_mediaType || - prop->body.key == SPA_FORMAT_mediaSubtype) - continue; - - ti = spa_debug_type_find(info, prop->body.key); + ti = spa_debug_type_find(info, prop->key); key = ti ? ti->name : NULL; fprintf(stderr, "%*s %16s : (%s) ", indent, "", key ? rindex(key, ':') + 1 : "unknown", - pod_type_names[prop->body.value.type]); + pod_type_names[type]); - if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) { - spa_debug_format_value(ti->values, - prop->body.value.type, - SPA_POD_BODY(&prop->body.value), - prop->body.value.size); + if (choice == SPA_CHOICE_None) { + spa_debug_format_value(ti->values, type, vals, size); } else { const char *ssep, *esep, *sep; - void *alt; - switch (prop->body.flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_MIN_MAX: - case SPA_POD_PROP_RANGE_STEP: + switch (choice) { + case SPA_CHOICE_Range: + case SPA_CHOICE_Step: ssep = "[ "; sep = ", "; esep = " ]"; break; default: - case SPA_POD_PROP_RANGE_ENUM: - case SPA_POD_PROP_RANGE_FLAGS: + case SPA_CHOICE_Enum: + case SPA_CHOICE_Flags: ssep = "{ "; sep = ", "; esep = " }"; @@ -190,15 +199,11 @@ static inline int spa_debug_format(int indent, fprintf(stderr, "%s", ssep); - i = 0; - SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) { - if (i > 0) + for (i = 1; i < n_vals; i++) { + vals = SPA_MEMBER(vals, size, void); + if (i > 1) fprintf(stderr, "%s", sep); - spa_debug_format_value(ti->values, - prop->body.value.type, - alt, - prop->body.value.size); - i++; + spa_debug_format_value(ti->values, type, vals, size); } fprintf(stderr, "%s", esep); } diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index e14b5ad66..777c7cc9a 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -33,6 +33,73 @@ extern "C" { #define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); }) #endif +#if 0 +static inline int +spa_debug_pod_prop(int indent, const struct spa_type_info *info, struct spa_pod_prop *prop) +{ + void *alt; + int i; + const struct spa_type_info *ti = spa_debug_type_find(info, prop->key); + + spa_debug("%*s" "Prop: key %s, flags %d", indent, "", + ti ? ti->name : "unknown", prop->flags); + + info = ti ? ti->values : info; + + if (prop->flags & SPA_POD_PROP_FLAG_UNSET) + spa_debug("%*s" "Unset (Default):", indent + 2, ""); + else + spa_debug("%*s" "Value: size %u", indent + 2, "", prop->value.size); + + spa_debug_pod_value(indent + 4, info, prop->value.type, SPA_POD_BODY(&prop->value), + prop->value.size); + + i = 0; + switch (prop->flags & SPA_POD_PROP_RANGE_MASK) { + case SPA_POD_PROP_RANGE_NONE: + break; + case SPA_POD_PROP_RANGE_MIN_MAX: + SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { + if (i == 0) + spa_debug("%*s" "Min: ", indent + 2, ""); + else if (i == 1) + spa_debug("%*s" "Max: ", indent + 2, ""); + else + break; + spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size); + i++; + } + break; + case SPA_POD_PROP_RANGE_STEP: + SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { + if (i == 0) + spa_debug("%*s" "Min: ", indent + 2, ""); + else if (i == 1) + spa_debug("%*s" "Max: ", indent + 2, ""); + else if (i == 2) + spa_debug("%*s" "Step: ", indent + 2, ""); + else + break; + spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size); + i++; + } + break; + case SPA_POD_PROP_RANGE_ENUM: + SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { + if (i == 0) { + spa_debug("%*s" "Enum:", indent + 2, ""); + } + spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size); + i++; + } + break; + case SPA_POD_PROP_RANGE_FLAGS: + break; + } + break; +} +#endif + static inline int spa_debug_pod_value(int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) @@ -41,8 +108,8 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, case SPA_TYPE_Bool: spa_debug("%*s" "Bool %d", indent, "", *(int32_t *) body); break; - case SPA_TYPE_Enum: - spa_debug("%*s" "Enum %d (%s)", indent, "", *(int32_t *) body, + case SPA_TYPE_Id: + spa_debug("%*s" "Id %d (%s)", indent, "", *(int32_t *) body, spa_debug_type_find_name(info, *(int32_t *) body)); break; case SPA_TYPE_Int: @@ -89,17 +156,28 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, { struct spa_pod_array_body *b = body; void *p; - const struct spa_type_info *ti = spa_debug_type_find(info, b->child.type); + const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type); spa_debug("%*s" "Array: child.size %d, child.type %s", indent, "", b->child.size, ti ? ti->name : "unknown"); - info = ti ? ti->values : info; - SPA_POD_ARRAY_BODY_FOREACH(b, size, p) spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size); break; } + case SPA_TYPE_Choice: + { + struct spa_pod_choice_body *b = body; + void *p; + const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type); + + spa_debug("%*s" "Choice: type %s, flags %08x %d %d", indent, "", + ti ? ti->name : "unknown", b->flags, size, b->child.size); + + SPA_POD_CHOICE_BODY_FOREACH(b, size, p) + spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size); + break; + } case SPA_TYPE_Struct: { struct spa_pod *b = body, *p; @@ -111,7 +189,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, case SPA_TYPE_Object: { struct spa_pod_object_body *b = body; - struct spa_pod *p; + struct spa_pod_prop *p; const struct spa_type_info *ti, *ii; ti = spa_debug_type_find(info, b->type); @@ -123,9 +201,17 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, info = ti ? ti->values : info; - SPA_POD_OBJECT_BODY_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, info, - p->type, SPA_POD_BODY(p), p->size); + SPA_POD_OBJECT_BODY_FOREACH(b, size, p) { + ii = spa_debug_type_find(info, p->key); + + spa_debug("%*s" "Prop: key %s, flags %08x", indent+2, "", + ii ? ii->name : "unknown", p->flags); + + spa_debug_pod_value(indent + 4, ii->values, + p->value.type, + SPA_POD_CONTENTS(struct spa_pod_prop, p), + p->value.size); + } break; } case SPA_TYPE_Sequence: @@ -145,77 +231,13 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, spa_debug("%*s" "Control: offset %d, type %s", indent+2, "", c->offset, ii ? ii->name : "unknown"); - spa_debug_pod_value(indent + 2, info, + spa_debug_pod_value(indent + 4, ii->values, c->value.type, SPA_POD_CONTENTS(struct spa_pod_control, c), c->value.size); } break; } - case SPA_TYPE_Prop: - { - struct spa_pod_prop_body *b = body; - void *alt; - int i; - const struct spa_type_info *ti = spa_debug_type_find(info, b->key); - - spa_debug("%*s" "Prop: key %s, flags %d", indent, "", - ti ? ti->name : "unknown", b->flags); - - info = ti ? ti->values : info; - - if (b->flags & SPA_POD_PROP_FLAG_UNSET) - spa_debug("%*s" "Unset (Default):", indent + 2, ""); - else - spa_debug("%*s" "Value: size %u", indent + 2, "", b->value.size); - - spa_debug_pod_value(indent + 4, info, b->value.type, SPA_POD_BODY(&b->value), - b->value.size); - - i = 0; - switch (b->flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: - break; - case SPA_POD_PROP_RANGE_MIN_MAX: - SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { - if (i == 0) - spa_debug("%*s" "Min: ", indent + 2, ""); - else if (i == 1) - spa_debug("%*s" "Max: ", indent + 2, ""); - else - break; - spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); - i++; - } - break; - case SPA_POD_PROP_RANGE_STEP: - SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { - if (i == 0) - spa_debug("%*s" "Min: ", indent + 2, ""); - else if (i == 1) - spa_debug("%*s" "Max: ", indent + 2, ""); - else if (i == 2) - spa_debug("%*s" "Step: ", indent + 2, ""); - else - break; - spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); - i++; - } - break; - case SPA_POD_PROP_RANGE_ENUM: - SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) { - if (i == 0) { - spa_debug("%*s" "Enum:", indent + 2, ""); - } - spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); - i++; - } - break; - case SPA_POD_PROP_RANGE_FLAGS: - break; - } - break; - } case SPA_TYPE_Bytes: spa_debug("%*s" "Bytes", indent, ""); spa_debug_mem(indent + 2, body, size); diff --git a/spa/include/spa/monitor/type-info.h b/spa/include/spa/monitor/type-info.h index 08ce5d0e4..1f20e2725 100644 --- a/spa/include/spa/monitor/type-info.h +++ b/spa/include/spa/monitor/type-info.h @@ -38,7 +38,7 @@ static const struct spa_type_info spa_type_monitor_event_id[] = { }; static const struct spa_type_info spa_type_monitor_event[] = { - { 0, SPA_TYPE_MONITOR_EVENT_BASE, SPA_TYPE_Enum, spa_type_monitor_event_id }, + { 0, SPA_TYPE_MONITOR_EVENT_BASE, SPA_TYPE_Id, spa_type_monitor_event_id }, { 0, NULL, }, }; @@ -66,9 +66,9 @@ static const struct spa_type_info spa_type_monitor_item_state[] = { static const struct spa_type_info spa_type_monitor_item[] = { { SPA_MONITOR_ITEM_START, SPA_TYPE_MONITOR_ITEM_BASE, SPA_TYPE_Int, }, { SPA_MONITOR_ITEM_id, SPA_TYPE_MONITOR_ITEM_BASE "id", SPA_TYPE_String, }, - { SPA_MONITOR_ITEM_flags, SPA_TYPE_MONITOR_ITEM_BASE "flags", SPA_TYPE_Enum, + { SPA_MONITOR_ITEM_flags, SPA_TYPE_MONITOR_ITEM_BASE "flags", SPA_TYPE_Id, spa_type_monitor_item_flags }, - { SPA_MONITOR_ITEM_state, SPA_TYPE_MONITOR_ITEM_BASE "state", SPA_TYPE_Enum, + { SPA_MONITOR_ITEM_state, SPA_TYPE_MONITOR_ITEM_BASE "state", SPA_TYPE_Id, spa_type_monitor_item_state }, { SPA_MONITOR_ITEM_name, SPA_TYPE_MONITOR_ITEM_BASE "name", SPA_TYPE_String, }, { SPA_MONITOR_ITEM_class, SPA_TYPE_MONITOR_ITEM_BASE "class", SPA_TYPE_String, }, diff --git a/spa/include/spa/node/type-info.h b/spa/include/spa/node/type-info.h index a5a253055..493b09d9b 100644 --- a/spa/include/spa/node/type-info.h +++ b/spa/include/spa/node/type-info.h @@ -55,7 +55,7 @@ static const struct spa_type_info spa_type_node_event_id[] = { }; static const struct spa_type_info spa_type_node_event[] = { - { 0, SPA_TYPE_NODE_EVENT_BASE, SPA_TYPE_Enum, spa_type_node_event_id }, + { 0, SPA_TYPE_NODE_EVENT_BASE, SPA_TYPE_Id, spa_type_node_event_id }, { 0, NULL, }, }; @@ -75,7 +75,7 @@ static const struct spa_type_info spa_type_node_command_id[] = { }; static const struct spa_type_info spa_type_node_command[] = { - { 0, SPA_TYPE_NODE_COMMAND_BASE, SPA_TYPE_Enum, spa_type_node_command_id }, + { 0, SPA_TYPE_NODE_COMMAND_BASE, SPA_TYPE_Id, spa_type_node_command_id }, { 0, NULL, }, }; diff --git a/spa/include/spa/param/audio/format-utils.h b/spa/include/spa/param/audio/format-utils.h index 1c39724c0..4203447b8 100644 --- a/spa/include/spa/param/audio/format-utils.h +++ b/spa/include/spa/param/audio/format-utils.h @@ -47,12 +47,13 @@ spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct { return spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, id, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", info->format, - ":", SPA_FORMAT_AUDIO_layout, "I", info->layout, - ":", SPA_FORMAT_AUDIO_rate, "i", info->rate, - ":", SPA_FORMAT_AUDIO_channels, "i", info->channels); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(info->format), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(info->layout), + SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(info->rate), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(info->channels), + 0); } #ifdef __cplusplus diff --git a/spa/include/spa/param/type-info.h b/spa/include/spa/param/type-info.h index 9e5f33091..84ed4040b 100644 --- a/spa/include/spa/param/type-info.h +++ b/spa/include/spa/param/type-info.h @@ -56,8 +56,8 @@ static const struct spa_type_info spa_type_param[] = { #define SPA_TYPE_PARAM_LIST_BASE SPA_TYPE_PARAM__List ":" static const struct spa_type_info spa_type_param_list[] = { - { SPA_PARAM_LIST_START, SPA_TYPE_PARAM_LIST_BASE, SPA_TYPE_Enum, spa_type_param }, - { SPA_PARAM_LIST_id, SPA_TYPE_PARAM_LIST_BASE "id", SPA_TYPE_Enum, spa_type_param }, + { SPA_PARAM_LIST_START, SPA_TYPE_PARAM_LIST_BASE, SPA_TYPE_Id, spa_type_param }, + { SPA_PARAM_LIST_id, SPA_TYPE_PARAM_LIST_BASE "id", SPA_TYPE_Id, spa_type_param }, { 0, NULL, }, }; @@ -65,7 +65,7 @@ static const struct spa_type_info spa_type_param_list[] = { #define SPA_TYPE_PROPS_BASE SPA_TYPE__Props ":" static const struct spa_type_info spa_type_props[] = { - { SPA_PROP_START, SPA_TYPE_PROPS_BASE, SPA_TYPE_Enum, spa_type_param, }, + { SPA_PROP_START, SPA_TYPE_PROPS_BASE, SPA_TYPE_Id, spa_type_param, }, { SPA_PROP_unknown, SPA_TYPE_PROPS_BASE "unknown", SPA_TYPE_None, }, { SPA_PROP_device, SPA_TYPE_PROPS_BASE "device", SPA_TYPE_String, }, { SPA_PROP_deviceName, SPA_TYPE_PROPS_BASE "deviceName", SPA_TYPE_String, }, @@ -78,12 +78,12 @@ static const struct spa_type_info spa_type_props[] = { { SPA_PROP_periodSize, SPA_TYPE_PROPS_BASE "periodSize", SPA_TYPE_Int, }, { SPA_PROP_periodEvent, SPA_TYPE_PROPS_BASE "periodEvent", SPA_TYPE_Bool, }, { SPA_PROP_live, SPA_TYPE_PROPS_BASE "live", SPA_TYPE_Bool, }, - { SPA_PROP_waveType, SPA_TYPE_PROPS_BASE "waveType", SPA_TYPE_Enum, }, + { SPA_PROP_waveType, SPA_TYPE_PROPS_BASE "waveType", SPA_TYPE_Id, }, { SPA_PROP_frequency, SPA_TYPE_PROPS_BASE "frequency", SPA_TYPE_Int, }, { SPA_PROP_volume, SPA_TYPE_PROPS_BASE "volume", SPA_TYPE_Float, }, { SPA_PROP_mute, SPA_TYPE_PROPS_BASE "mute", SPA_TYPE_Bool, }, - { SPA_PROP_patternType, SPA_TYPE_PROPS_BASE "patternType", SPA_TYPE_Enum, }, - { SPA_PROP_ditherType, SPA_TYPE_PROPS_BASE "ditherType", SPA_TYPE_Enum, }, + { SPA_PROP_patternType, SPA_TYPE_PROPS_BASE "patternType", SPA_TYPE_Id, }, + { SPA_PROP_ditherType, SPA_TYPE_PROPS_BASE "ditherType", SPA_TYPE_Id, }, { SPA_PROP_truncate, SPA_TYPE_PROPS_BASE "truncate", SPA_TYPE_Bool, }, { SPA_PROP_brightness, SPA_TYPE_PROPS_BASE "brightness", SPA_TYPE_Int, }, { SPA_PROP_contrast, SPA_TYPE_PROPS_BASE "contrast", SPA_TYPE_Int, }, @@ -101,10 +101,10 @@ static const struct spa_type_info spa_type_props[] = { #define SPA_TYPE_PROP_INFO_BASE SPA_TYPE__PropInfo ":" static const struct spa_type_info spa_type_prop_info[] = { - { SPA_PROP_INFO_START, SPA_TYPE_PROP_INFO_BASE, SPA_TYPE_Enum, spa_type_param, }, - { SPA_PROP_INFO_id, SPA_TYPE_PROP_INFO_BASE "id", SPA_TYPE_Enum, spa_type_props }, + { SPA_PROP_INFO_START, SPA_TYPE_PROP_INFO_BASE, SPA_TYPE_Id, spa_type_param, }, + { SPA_PROP_INFO_id, SPA_TYPE_PROP_INFO_BASE "id", SPA_TYPE_Id, spa_type_props }, { SPA_PROP_INFO_name, SPA_TYPE_PROP_INFO_BASE "name", SPA_TYPE_String, }, - { SPA_PROP_INFO_type, SPA_TYPE_PROP_INFO_BASE "type", SPA_TYPE_Prop, }, + { SPA_PROP_INFO_type, SPA_TYPE_PROP_INFO_BASE "type", SPA_TYPE_Id, }, { SPA_PROP_INFO_labels, SPA_TYPE_PROP_INFO_BASE "labels", SPA_TYPE_Struct, }, { 0, NULL, }, }; @@ -113,8 +113,8 @@ static const struct spa_type_info spa_type_prop_info[] = { #define SPA_TYPE_PARAM_META_BASE SPA_TYPE_PARAM__Meta ":" static const struct spa_type_info spa_type_param_meta[] = { - { SPA_PARAM_META_START, SPA_TYPE_PARAM_META_BASE, SPA_TYPE_Enum, spa_type_param, }, - { SPA_PARAM_META_type, SPA_TYPE_PARAM_META_BASE "type", SPA_TYPE_Enum, }, + { SPA_PARAM_META_START, SPA_TYPE_PARAM_META_BASE, SPA_TYPE_Id, spa_type_param, }, + { SPA_PARAM_META_type, SPA_TYPE_PARAM_META_BASE "type", SPA_TYPE_Id, }, { SPA_PARAM_META_size, SPA_TYPE_PARAM_META_BASE "size", SPA_TYPE_Int, }, { 0, NULL, }, }; @@ -126,8 +126,8 @@ static const struct spa_type_info spa_type_param_meta[] = { #define SPA_TYPE_PARAM_IO_BASE SPA_TYPE_PARAM__IO ":" static const struct spa_type_info spa_type_param_io[] = { - { SPA_PARAM_IO_START, SPA_TYPE_PARAM_IO_BASE, SPA_TYPE_Enum, spa_type_param, }, - { SPA_PARAM_IO_id, SPA_TYPE_PARAM_IO_BASE "id", SPA_TYPE_Enum, spa_type_io }, + { SPA_PARAM_IO_START, SPA_TYPE_PARAM_IO_BASE, SPA_TYPE_Id, spa_type_param, }, + { SPA_PARAM_IO_id, SPA_TYPE_PARAM_IO_BASE "id", SPA_TYPE_Id, spa_type_io }, { SPA_PARAM_IO_size, SPA_TYPE_PARAM_IO_BASE "size", SPA_TYPE_Int, }, { 0, NULL, }, }; @@ -198,24 +198,24 @@ static const struct spa_type_info spa_type_media_subtype[] = { #define SPA_TYPE_FORMAT_VIDEO_BASE SPA_TYPE__FormatVideo ":" static const struct spa_type_info spa_type_format[] = { - { SPA_FORMAT_START, SPA_TYPE_FORMAT_BASE, SPA_TYPE_Enum, spa_type_param, }, + { SPA_FORMAT_START, SPA_TYPE_FORMAT_BASE, SPA_TYPE_Id, spa_type_param, }, - { SPA_FORMAT_mediaType, SPA_TYPE_FORMAT_BASE "mediaType", SPA_TYPE_Enum, + { SPA_FORMAT_mediaType, SPA_TYPE_FORMAT_BASE "mediaType", SPA_TYPE_Id, spa_type_media_type, }, - { SPA_FORMAT_mediaSubtype, SPA_TYPE_FORMAT_BASE "mediaSubtype", SPA_TYPE_Enum, + { SPA_FORMAT_mediaSubtype, SPA_TYPE_FORMAT_BASE "mediaSubtype", SPA_TYPE_Id, spa_type_media_subtype, }, - { SPA_FORMAT_AUDIO_format, SPA_TYPE_FORMAT_AUDIO_BASE "format", SPA_TYPE_Enum, + { SPA_FORMAT_AUDIO_format, SPA_TYPE_FORMAT_AUDIO_BASE "format", SPA_TYPE_Id, spa_type_audio_format }, - { SPA_FORMAT_AUDIO_flags, SPA_TYPE_FORMAT_AUDIO_BASE "flags", SPA_TYPE_Enum, + { SPA_FORMAT_AUDIO_flags, SPA_TYPE_FORMAT_AUDIO_BASE "flags", SPA_TYPE_Id, spa_type_audio_flags }, - { SPA_FORMAT_AUDIO_layout, SPA_TYPE_FORMAT_AUDIO_BASE "layout", SPA_TYPE_Enum, + { SPA_FORMAT_AUDIO_layout, SPA_TYPE_FORMAT_AUDIO_BASE "layout", SPA_TYPE_Id, spa_type_audio_layout }, { SPA_FORMAT_AUDIO_rate, SPA_TYPE_FORMAT_AUDIO_BASE "rate", SPA_TYPE_Int, }, { SPA_FORMAT_AUDIO_channels, SPA_TYPE_FORMAT_AUDIO_BASE "channels", SPA_TYPE_Int, }, { SPA_FORMAT_AUDIO_channelMask, SPA_TYPE_FORMAT_AUDIO_BASE "channelMask", SPA_TYPE_Int, }, - { SPA_FORMAT_VIDEO_format, SPA_TYPE_FORMAT_VIDEO_BASE "format", SPA_TYPE_Enum, + { SPA_FORMAT_VIDEO_format, SPA_TYPE_FORMAT_VIDEO_BASE "format", SPA_TYPE_Id, spa_type_video_format, }, { SPA_FORMAT_VIDEO_size, SPA_TYPE_FORMAT_VIDEO_BASE "size", SPA_TYPE_Rectangle, }, { SPA_FORMAT_VIDEO_framerate, SPA_TYPE_FORMAT_VIDEO_BASE "framerate", SPA_TYPE_Fraction, }, @@ -244,7 +244,7 @@ static const struct spa_type_info spa_type_format[] = { #define SPA_TYPE_PARAM_BLOCK_INFO_BASE SPA_TYPE_PARAM__BlockInfo ":" static const struct spa_type_info spa_type_param_buffers[] = { - { SPA_PARAM_BUFFERS_START, SPA_TYPE_PARAM_BUFFERS_BASE, SPA_TYPE_Enum, spa_type_param, }, + { SPA_PARAM_BUFFERS_START, SPA_TYPE_PARAM_BUFFERS_BASE, SPA_TYPE_Id, spa_type_param, }, { SPA_PARAM_BUFFERS_buffers, SPA_TYPE_PARAM_BUFFERS_BASE "buffers", SPA_TYPE_Int, }, { SPA_PARAM_BUFFERS_blocks, SPA_TYPE_PARAM_BUFFERS_BASE "blocks", SPA_TYPE_Int, }, { SPA_PARAM_BUFFERS_size, SPA_TYPE_PARAM_BLOCK_INFO_BASE "size", SPA_TYPE_Int, }, diff --git a/spa/include/spa/param/video/format-utils.h b/spa/include/spa/param/video/format-utils.h index c58a02676..146a51b09 100644 --- a/spa/include/spa/param/video/format-utils.h +++ b/spa/include/spa/param/video/format-utils.h @@ -56,11 +56,12 @@ spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id, { return spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, id, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_video, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "I", &info->format, - ":", SPA_FORMAT_VIDEO_size, "R", &info->size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &info->framerate); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_video), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_VIDEO_format, &SPA_POD_Id(info->format), + SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(info->size), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(info->framerate), + 0); } static inline int diff --git a/spa/include/spa/pod/builder.h b/spa/include/spa/pod/builder.h index 59bba1ac5..9760e4e5a 100644 --- a/spa/include/spa/pod/builder.h +++ b/spa/include/spa/pod/builder.h @@ -45,7 +45,7 @@ struct spa_pod_builder { uint32_t size; uint32_t (*write) (struct spa_pod_builder *builder, const void *data, uint32_t size); - void * (*deref) (struct spa_pod_builder *builder, uint32_t ref); + void * (*deref) (struct spa_pod_builder *builder, uint32_t ref, bool safe); void (*reset) (struct spa_pod_builder *builder, struct spa_pod_builder_state *state); struct spa_pod_builder_state state; @@ -75,20 +75,26 @@ static inline void spa_pod_builder_init(struct spa_pod_builder *builder, void *d } static inline void * -spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t ref) +spa_pod_builder_deref_checked(struct spa_pod_builder *builder, uint32_t ref, bool safe) { if (ref == SPA_ID_INVALID) return NULL; else if (builder->deref) - return builder->deref(builder, ref); + return builder->deref(builder, ref, safe); else if (ref + 8 <= builder->size) { struct spa_pod *pod = SPA_MEMBER(builder->data, ref, struct spa_pod); - if (SPA_POD_SIZE(pod) <= builder->size) + if (!safe || SPA_POD_SIZE(pod) <= builder->size) return (void *) pod; } return NULL; } +static inline void * +spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t ref) +{ + return spa_pod_builder_deref_checked(builder, ref, false); +} + static inline uint32_t spa_pod_builder_push(struct spa_pod_builder *builder, const struct spa_pod *pod, @@ -98,7 +104,7 @@ spa_pod_builder_push(struct spa_pod_builder *builder, frame->pod = *pod; frame->ref = ref; builder->state.in_array = builder->state.first = - (pod->type == SPA_TYPE_Array || pod->type == SPA_TYPE_Prop); + (pod->type == SPA_TYPE_Array || pod->type == SPA_TYPE_Choice); return ref; } @@ -113,7 +119,7 @@ spa_pod_builder_raw(struct spa_pod_builder *builder, const void *data, uint32_t } else { ref = builder->state.offset; if (ref + size > builder->size) - ref = -1; + ref = SPA_ID_INVALID; else memcpy(SPA_MEMBER(builder->data, ref, void), data, size); } @@ -148,94 +154,130 @@ static inline void *spa_pod_builder_pop(struct spa_pod_builder *builder) struct spa_pod *pod; frame = &builder->frame[--builder->state.depth]; - if ((pod = (struct spa_pod *) spa_pod_builder_deref(builder, frame->ref)) != NULL) + if ((pod = (struct spa_pod *) spa_pod_builder_deref_checked(builder, frame->ref, true)) != NULL) *pod = frame->pod; top = builder->state.depth > 0 ? &builder->frame[builder->state.depth-1] : NULL; builder->state.in_array = (top && - (top->pod.type == SPA_TYPE_Array || top->pod.type == SPA_TYPE_Prop)); + (top->pod.type == SPA_TYPE_Array || top->pod.type == SPA_TYPE_Choice)); spa_pod_builder_pad(builder, builder->state.offset); return pod; } +#define SPA_TYPE_Collect 0x100 +struct spa_pod_collect { + struct spa_pod pod; + struct spa_pod child; + const void *value; +}; + static inline uint32_t spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p) { - const void *data; - uint32_t size, ref; + const void *head, *body; + uint32_t head_size, body_size, ref; + bool collect = p->type == SPA_TYPE_Collect; + + if (collect) { + struct spa_pod_collect *col = (struct spa_pod_collect *)p; + head = &col->child; + head_size = sizeof(struct spa_pod); + body = col->value; + } else { + head = p; + head_size = SPA_POD_SIZE(p); + body = SPA_POD_BODY_CONST(p); + } + body_size = SPA_POD_BODY_SIZE(head); if (builder->state.in_array && !builder->state.first) { - data = SPA_POD_BODY_CONST(p); - size = SPA_POD_BODY_SIZE(p); + head = body; + head_size = body_size; + collect = false; } else { - data = p; - size = SPA_POD_SIZE(p); builder->state.first = false; } - ref = spa_pod_builder_raw(builder, data, size); + + ref = spa_pod_builder_raw(builder, head, head_size); + if (ref != SPA_ID_INVALID && collect) { + ref = spa_pod_builder_raw(builder, body, body_size); + head_size += body_size; + } if (!builder->state.in_array) - spa_pod_builder_pad(builder, size); + spa_pod_builder_pad(builder, head_size); return ref; } -#define SPA_POD_NONE_INIT() (struct spa_pod) { 0, SPA_TYPE_None } +#define SPA_POD_INIT(size,type) (struct spa_pod) { size, type } + +#define SPA_POD_None() SPA_POD_INIT(0, SPA_TYPE_None) static inline uint32_t spa_pod_builder_none(struct spa_pod_builder *builder) { - const struct spa_pod p = SPA_POD_NONE_INIT(); + const struct spa_pod p = SPA_POD_None(); return spa_pod_builder_primitive(builder, &p); } -#define SPA_POD_BOOL_INIT(val) (struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, val ? 1 : 0, 0 } +#define SPA_POD_Bool(val) (struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, val ? 1 : 0, 0 } static inline uint32_t spa_pod_builder_bool(struct spa_pod_builder *builder, bool val) { - const struct spa_pod_bool p = SPA_POD_BOOL_INIT(val); + const struct spa_pod_bool p = SPA_POD_Bool(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_ENUM_INIT(val) (struct spa_pod_enum){ { sizeof(uint32_t), SPA_TYPE_Enum }, val, 0 } +#define SPA_POD_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, val, 0 } -static inline uint32_t spa_pod_builder_enum(struct spa_pod_builder *builder, uint32_t val) +static inline uint32_t spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val) { - const struct spa_pod_enum p = SPA_POD_ENUM_INIT(val); + const struct spa_pod_id p = SPA_POD_Id(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_INT_INIT(val) (struct spa_pod_int){ { sizeof(uint32_t), SPA_TYPE_Int }, val, 0 } +#define SPA_POD_Int(val) (struct spa_pod_int){ { sizeof(uint32_t), SPA_TYPE_Int }, val, 0 } static inline uint32_t spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val) { - const struct spa_pod_int p = SPA_POD_INT_INIT(val); + const struct spa_pod_int p = SPA_POD_Int(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_LONG_INIT(val) (struct spa_pod_long){ { sizeof(uint64_t), SPA_TYPE_Long }, val } +#define SPA_POD_Long(val) (struct spa_pod_long){ { sizeof(uint64_t), SPA_TYPE_Long }, val } static inline uint32_t spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val) { - const struct spa_pod_long p = SPA_POD_LONG_INIT(val); + const struct spa_pod_long p = SPA_POD_Long(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_FLOAT_INIT(val) (struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, val } +#define SPA_POD_Float(val) (struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, val } static inline uint32_t spa_pod_builder_float(struct spa_pod_builder *builder, float val) { - const struct spa_pod_float p = SPA_POD_FLOAT_INIT(val); + const struct spa_pod_float p = SPA_POD_Float(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_DOUBLE_INIT(val) (struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, val } +#define SPA_POD_Double(val) (struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, val } static inline uint32_t spa_pod_builder_double(struct spa_pod_builder *builder, double val) { - const struct spa_pod_double p = SPA_POD_DOUBLE_INIT(val); + const struct spa_pod_double p = SPA_POD_Double(val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_STRING_INIT(len) (struct spa_pod_string){ { len, SPA_TYPE_String } } +#define SPA_POD_Stringv(str) \ + (struct spa_pod_collect) \ + { { 0, SPA_TYPE_Collect }, { strlen(str)+1, SPA_TYPE_String }, str } + +#define SPA_POD_String(str, len) \ + (struct spa_pod_collect) \ + { { 0, SPA_TYPE_Collect }, { len, SPA_TYPE_String }, str } + +#define SPA_POD_Stringc(str) \ + (struct { struct spa_pod_string pod; char val[sizeof(str)]; }) \ + { { { sizeof(str), SPA_TYPE_String } }, { str } } static inline uint32_t spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len) @@ -252,7 +294,7 @@ spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, u static inline uint32_t spa_pod_builder_string_len(struct spa_pod_builder *builder, const char *str, uint32_t len) { - const struct spa_pod_string p = SPA_POD_STRING_INIT(len+1); + const struct spa_pod_string p = { { len + 1, SPA_TYPE_String } }; uint32_t ref = spa_pod_builder_raw(builder, &p, sizeof(p)); if (spa_pod_builder_write_string(builder, str, len) == SPA_ID_INVALID) ref = SPA_ID_INVALID; @@ -265,50 +307,50 @@ static inline uint32_t spa_pod_builder_string(struct spa_pod_builder *builder, c return spa_pod_builder_string_len(builder, str ? str : "", len); } -#define SPA_POD_BYTES_INIT(len) (struct spa_pod_bytes){ { len, SPA_TYPE_Bytes } } +#define SPA_POD_Bytes(len) (struct spa_pod_bytes){ { len, SPA_TYPE_Bytes } } static inline uint32_t spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len) { - const struct spa_pod_bytes p = SPA_POD_BYTES_INIT(len); + const struct spa_pod_bytes p = SPA_POD_Bytes(len); uint32_t ref = spa_pod_builder_raw(builder, &p, sizeof(p)); if (spa_pod_builder_raw_padded(builder, bytes, len) == SPA_ID_INVALID) ref = SPA_ID_INVALID; return ref; } -#define SPA_POD_POINTER_INIT(type,value) (struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { type, value } } +#define SPA_POD_Pointer(type,value) (struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { type, value } } static inline uint32_t spa_pod_builder_pointer(struct spa_pod_builder *builder, uint32_t type, void *val) { - const struct spa_pod_pointer p = SPA_POD_POINTER_INIT(type, val); + const struct spa_pod_pointer p = SPA_POD_Pointer(type, val); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_FD_INIT(fd) (struct spa_pod_fd){ { sizeof(int), SPA_TYPE_Fd }, fd } +#define SPA_POD_Fd(fd) (struct spa_pod_fd){ { sizeof(int), SPA_TYPE_Fd }, fd } static inline uint32_t spa_pod_builder_fd(struct spa_pod_builder *builder, int fd) { - const struct spa_pod_fd p = SPA_POD_FD_INIT(fd); + const struct spa_pod_fd p = SPA_POD_Fd(fd); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_RECTANGLE_INIT(width,height) (struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, { width, height } } +#define SPA_POD_Rectangle(val) (struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, val } static inline uint32_t spa_pod_builder_rectangle(struct spa_pod_builder *builder, uint32_t width, uint32_t height) { - const struct spa_pod_rectangle p = SPA_POD_RECTANGLE_INIT(width, height); + const struct spa_pod_rectangle p = SPA_POD_Rectangle(SPA_RECTANGLE(width, height)); return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_FRACTION_INIT(num,denom) (struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, { num, denom } } +#define SPA_POD_Fraction(val) (struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, val } static inline uint32_t spa_pod_builder_fraction(struct spa_pod_builder *builder, uint32_t num, uint32_t denom) { - const struct spa_pod_fraction p = SPA_POD_FRACTION_INIT(num, denom); + const struct spa_pod_fraction p = SPA_POD_Fraction(SPA_FRACTION(num, denom)); return spa_pod_builder_primitive(builder, &p.pod); } @@ -337,48 +379,64 @@ spa_pod_builder_array(struct spa_pod_builder *builder, return ref; } -#define SPA_POD_STRUCT_INIT(size) (struct spa_pod_struct){ { size, SPA_TYPE_Struct } } +#define SPA_POD_CHOICE_BODY_INIT(type, flags, child_size, child_type) \ + (struct spa_pod_choice_body) { type, flags, { child_size, child_type }} + +#define SPA_POD_Choice(type, ctype, child_type, n_vals, ...) \ + (struct { struct spa_pod_choice choice; ctype vals[n_vals];}) \ + { { { n_vals * sizeof(ctype) + sizeof(struct spa_pod_choice_body), SPA_TYPE_Choice }, \ + { type, 0, { sizeof(ctype), child_type } } }, { __VA_ARGS__ } } static inline uint32_t -spa_pod_builder_push_struct(struct spa_pod_builder *builder) +spa_pod_builder_push_choice(struct spa_pod_builder *builder, uint32_t type, uint32_t flags) { - const struct spa_pod_struct p = SPA_POD_STRUCT_INIT(0); - return spa_pod_builder_push(builder, &p.pod, - spa_pod_builder_raw(builder, &p, sizeof(p))); -} - -#define SPA_POD_OBJECT_INIT(size,type,id,...) (struct spa_pod_object){ { size, SPA_TYPE_Object }, { type, id }, ##__VA_ARGS__ } - -static inline uint32_t -spa_pod_builder_push_object(struct spa_pod_builder *builder, uint32_t type, uint32_t id) -{ - const struct spa_pod_object p = - SPA_POD_OBJECT_INIT(sizeof(struct spa_pod_object_body), type, id); - return spa_pod_builder_push(builder, &p.pod, - spa_pod_builder_raw(builder, &p, sizeof(p))); -} - -#define SPA_POD_PROP_INIT(size,key,flags,val_size,val_type) \ - (struct spa_pod_prop){ { size, SPA_TYPE_Prop}, {key, flags, { val_size, val_type } } } - -static inline uint32_t -spa_pod_builder_push_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags) -{ - const struct spa_pod_prop p = SPA_POD_PROP_INIT (sizeof(struct spa_pod_prop_body) - - sizeof(struct spa_pod), key, flags, 0, 0); + const struct spa_pod_choice p = + { {sizeof(struct spa_pod_choice_body) - sizeof(struct spa_pod), SPA_TYPE_Choice}, + { type, flags, {0, 0}} }; return spa_pod_builder_push(builder, &p.pod, spa_pod_builder_raw(builder, &p, sizeof(p) - sizeof(struct spa_pod))); } -#define SPA_POD_SEQUENCE_INIT(size,unit,...) \ +#define SPA_POD_Struct(size) (struct spa_pod_struct){ { size, SPA_TYPE_Struct } } + +static inline uint32_t +spa_pod_builder_push_struct(struct spa_pod_builder *builder) +{ + const struct spa_pod_struct p = SPA_POD_Struct(0); + return spa_pod_builder_push(builder, &p.pod, + spa_pod_builder_raw(builder, &p, sizeof(p))); +} + +#define SPA_POD_Object(size,type,id,...) (struct spa_pod_object){ { size, SPA_TYPE_Object }, { type, id }, ##__VA_ARGS__ } + +static inline uint32_t +spa_pod_builder_push_object(struct spa_pod_builder *builder, uint32_t type, uint32_t id) +{ + const struct spa_pod_object p = + SPA_POD_Object(sizeof(struct spa_pod_object_body), type, id); + return spa_pod_builder_push(builder, &p.pod, + spa_pod_builder_raw(builder, &p, sizeof(p))); +} + +#define SPA_POD_Prop(key,flags,size,type) \ + (struct spa_pod_prop){ key, flags, { size, type } } + +static inline uint32_t +spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags) +{ + const struct { uint32_t key; uint32_t flags; } p = { key, flags }; + return spa_pod_builder_raw(builder, &p, sizeof(p)); +} + +#define SPA_POD_Sequence(size,unit,...) \ (struct spa_pod_sequence){ { size, SPA_TYPE_Sequence}, {unit, 0 }, ##__VA_ARGS__ } static inline uint32_t spa_pod_builder_push_sequence(struct spa_pod_builder *builder, uint32_t unit) { const struct spa_pod_sequence p = - SPA_POD_SEQUENCE_INIT(sizeof(struct spa_pod_sequence_body), unit); + SPA_POD_Sequence(sizeof(struct spa_pod_sequence_body), unit); return spa_pod_builder_push(builder, &p.pod, spa_pod_builder_raw(builder, &p, sizeof(p))); } @@ -390,27 +448,26 @@ spa_pod_builder_control_header(struct spa_pod_builder *builder, uint32_t offset, return spa_pod_builder_raw(builder, &p, sizeof(p)); } -static inline uint32_t spa_pod_range_from_id(char id) +static inline uint32_t spa_choice_from_id(char id) { switch (id) { case 'r': - return SPA_POD_PROP_RANGE_MIN_MAX; + return SPA_CHOICE_Range; case 's': - return SPA_POD_PROP_RANGE_STEP; + return SPA_CHOICE_Step; case 'e': - return SPA_POD_PROP_RANGE_ENUM; + return SPA_CHOICE_Enum; case 'f': - return SPA_POD_PROP_RANGE_FLAGS; + return SPA_CHOICE_Flags; + case 'n': default: - return SPA_POD_PROP_RANGE_NONE; + return SPA_CHOICE_None; } } static inline uint32_t spa_pod_flag_from_id(char id) { switch (id) { - case 'u': - return SPA_POD_PROP_FLAG_UNSET; case 'o': return SPA_POD_PROP_FLAG_OPTIONAL; case 'r': @@ -433,7 +490,7 @@ do { \ spa_pod_builder_bool(builder, va_arg(args, int)); \ break; \ case 'I': \ - spa_pod_builder_enum(builder, va_arg(args, uint32_t)); \ + spa_pod_builder_id(builder, va_arg(args, uint32_t)); \ break; \ case 'i': \ spa_pod_builder_int(builder, va_arg(args, int)); \ @@ -523,9 +580,9 @@ spa_pod_builder_addv(struct spa_pod_builder *builder, const char *format, va_list args) { while (format) { - char t = *format; - next: - switch (t) { + int n_values = 1; + bool do_pop = false; + switch (*format) { case '{': { uint32_t type = va_arg(args, uint32_t); @@ -552,46 +609,34 @@ spa_pod_builder_addv(struct spa_pod_builder *builder, spa_pod_builder_control_header(builder, offset, type); break; } + case '?': + { + uint32_t choice, flags = 0; + + format++; + choice = spa_choice_from_id(*format); + if (*format != '\0') + format++; + + spa_pod_builder_push_choice(builder, choice, flags); + + n_values = va_arg(args, int); + do_pop = true; + goto do_collect; + } case ':': { - int n_values; - uint32_t key, flags; + uint32_t key, flags = 0; key = va_arg(args, uint32_t); - format = va_arg(args, const char *); - t = *format; - if (*format != '\0') - format++; - flags = spa_pod_range_from_id(*format); - if (*format != '\0') - format++; - for (;*format;format++) + for (format++;*format;format++) SPA_FLAG_SET(flags, spa_pod_flag_from_id(*format)); - spa_pod_builder_push_prop(builder, key, flags); - - if (t == '{' || t == '[' || t == '<') - goto next; - - n_values = -1; - while (n_values-- != 0) { - SPA_POD_BUILDER_COLLECT(builder, t, args); - - if ((flags & SPA_POD_PROP_RANGE_MASK) == 0) - break; - - if (n_values == -2) - n_values = va_arg(args, int); - } - spa_pod_builder_pop(builder); - /* don't advance format */ - continue; + spa_pod_builder_prop(builder, key, flags); + break; } case ']': case ')': case '>': case '}': spa_pod_builder_pop(builder); - if (builder->state.depth > 0 && - builder->frame[builder->state.depth-1].pod.type == SPA_TYPE_Prop) - spa_pod_builder_pop(builder); break; case ' ': case '\n': case '\t': case '\r': break; @@ -599,13 +644,17 @@ spa_pod_builder_addv(struct spa_pod_builder *builder, format = va_arg(args, const char *); continue; default: - SPA_POD_BUILDER_COLLECT(builder, t, args); + do_collect: + while (n_values-- > 0) + SPA_POD_BUILDER_COLLECT(builder, *format, args); + if (do_pop) + spa_pod_builder_pop(builder); break;; } if (*format != '\0') format++; } - return spa_pod_builder_deref(builder, builder->frame[builder->state.depth].ref); + return spa_pod_builder_deref_checked(builder, builder->frame[builder->state.depth].ref,true); } static inline void *spa_pod_builder_add(struct spa_pod_builder *builder, const char *format, ...) @@ -620,13 +669,44 @@ static inline void *spa_pod_builder_add(struct spa_pod_builder *builder, const c return res; } +static inline void spa_pod_builder_propsv(struct spa_pod_builder *builder, + uint32_t key, va_list args) +{ + while (key) { + spa_pod_builder_prop(builder, key, 0); + spa_pod_builder_primitive(builder, va_arg(args, struct spa_pod *)); + key = va_arg(args, uint32_t); + } +} + +static inline void spa_pod_builder_props(struct spa_pod_builder *builder, uint32_t key, ...) +{ + va_list args; + va_start(args, key); + spa_pod_builder_propsv(builder, key, args); + va_end(args); +} + +static inline void *spa_pod_builder_object(struct spa_pod_builder *builder, + uint32_t type, uint32_t id, uint32_t key, ...) +{ + va_list args; + + spa_pod_builder_push_object(builder, type, id); + va_start(args, key); + spa_pod_builder_propsv(builder, key, args); + va_end(args); + + return spa_pod_builder_pop(builder); +} + #define SPA_POD_OBJECT(type,id,...) \ "{", type, id, ##__VA_ARGS__, "}" #define SPA_POD_STRUCT(...) \ "[", ##__VA_ARGS__, "]" -#define SPA_POD_PROP(key,spec,type,value,...) \ +#define SPA_POD_PROP(key,spec,value,...) \ ":", key, spec, value, ##__VA_ARGS__ #define SPA_POD_SEQUENCE(unit,...) \ @@ -635,19 +715,73 @@ static inline void *spa_pod_builder_add(struct spa_pod_builder *builder, const c #define SPA_POD_CONTROL(offset,type,...) \ ".", offset, type, ##__VA_ARGS__ -#define SPA_POD_PROP_MIN_MAX(min,max) 2,(min),(max) -#define SPA_POD_PROP_STEP(min,max,step) 3,(min),(max),(step) -#define SPA_POD_PROP_ENUM(n_vals,...) (n_vals),__VA_ARGS__ - -#define spa_pod_builder_object(b,type,id,...) \ +#define spa_pod_builder_add_object(b,type,id,...) \ spa_pod_builder_add(b, SPA_POD_OBJECT(type,id,##__VA_ARGS__), NULL) -#define spa_pod_builder_struct(b,...) \ +#define spa_pod_builder_add_struct(b,...) \ spa_pod_builder_add(b, SPA_POD_STRUCT(__VA_ARGS__), NULL) -#define spa_pod_builder_sequence(b,unit,...) \ +#define spa_pod_builder_add_sequence(b,unit,...) \ spa_pod_builder_add(b, SPA_POD_SEQUENCE(unit,__VA_ARGS__), NULL) +#define SPA_CHOICE_RANGE(def,min,max) 3,(def),(min),(max) +#define SPA_CHOICE_STEP(def,min,max,step) 4,(def),(min),(max),(step) +#define SPA_CHOICE_ENUM(n_vals,...) (n_vals),__VA_ARGS__ +#define SPA_CHOICE_BOOL(def) 3,(def),(def),!(def) + +#define SPA_POD_CHOICE_Bool(def) \ + SPA_POD_Choice(SPA_CHOICE_Enum, int32_t, SPA_TYPE_Bool, 3, (def), (def), !(def)) + +#define SPA_POD_CHOICE_Int(type, n_vals, ...) \ + SPA_POD_Choice(type, uint32_t, SPA_TYPE_Int, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Int(n_vals, ...) \ + SPA_POD_CHOICE_Int(SPA_CHOICE_Enum, SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)) +#define SPA_POD_CHOICE_RANGE_Int(def, min, max) \ + SPA_POD_CHOICE_Int(SPA_CHOICE_Range, SPA_CHOICE_RANGE(def, min, max)) +#define SPA_POD_CHOICE_STEP_Int(def, min, max, step) \ + SPA_POD_CHOICE_Int(SPA_CHOICE_Step, SPA_CHOICE_STEP(def, min, max, step)) + +#define SPA_POD_CHOICE_Id(type, n_vals, ...) \ + SPA_POD_Choice(type, uint32_t, SPA_TYPE_Id, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Id(n_vals, ...) \ + SPA_POD_CHOICE_Id(SPA_CHOICE_Enum, n_vals, __VA_ARGS__) + +#define SPA_POD_CHOICE_Float(type, n_vals, ...) \ + SPA_POD_Choice(type, float, SPA_TYPE_Float, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Float(n_vals, ...) \ + SPA_POD_CHOICE_Float(SPA_CHOICE_Enum, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_RANGE_Float(def, min, max) \ + SPA_POD_CHOICE_Float(SPA_CHOICE_Range, 3, (def), (min), (max)) +#define SPA_POD_CHOICE_STEP_Float(def, min, max, step) \ + SPA_POD_CHOICE_Float(SPA_CHOICE_Step, 4, (def), (min), (max), (step)) + +#define SPA_POD_CHOICE_Double(type, n_vals, ...) \ + SPA_POD_Choice(type, double, SPA_TYPE_Double, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Double(n_vals, ...) \ + SPA_POD_CHOICE_Double(SPA_CHOICE_Enum, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_RANGE_Double(def, min, max) \ + SPA_POD_CHOICE_Double(SPA_CHOICE_Range, 3, (def), (min), (max)) +#define SPA_POD_CHOICE_STEP_Double(def, min, max, step) \ + SPA_POD_CHOICE_Double(SPA_CHOICE_Step, 4, (def), (min), (max), (step)) + +#define SPA_POD_CHOICE_Rectangle(type, n_vals, ...) \ + SPA_POD_Choice(type, struct spa_rectangle, SPA_TYPE_Rectangle, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Rectangle(n_vals, ...) \ + SPA_POD_CHOICE_Rectangle(SPA_CHOICE_Enum, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_RANGE_Rectangle(def, min, max) \ + SPA_POD_CHOICE_Rectangle(SPA_CHOICE_Range, 3, (def), (min), (max)) +#define SPA_POD_CHOICE_STEP_Rectangle(def, min, max, step) \ + SPA_POD_CHOICE_Rectangle(SPA_CHOICE_Step, 4, (def), (min), (max), (step)) + +#define SPA_POD_CHOICE_Fraction(type, n_vals, ...) \ + SPA_POD_Choice(type, struct spa_fraction, SPA_TYPE_Fraction, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_ENUM_Fraction(n_vals, ...) \ + SPA_POD_CHOICE_Fraction(SPA_CHOICE_Enum, n_vals, __VA_ARGS__) +#define SPA_POD_CHOICE_RANGE_Fraction(def, min, max) \ + SPA_POD_CHOICE_Fraction(SPA_CHOICE_Range, 3, (def), (min), (max)) +#define SPA_POD_CHOICE_STEP_Fraction(def, min, max, step) \ + SPA_POD_CHOICE_Fraction(SPA_CHOICE_Step, 4, (def), (min), (max), (step)) + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/pod/compare.h b/spa/include/spa/pod/compare.h index d5b045bd2..b686578cd 100644 --- a/spa/include/spa/pod/compare.h +++ b/spa/include/spa/pod/compare.h @@ -33,7 +33,7 @@ static inline int spa_pod_compare_value(uint32_t type, const void *r1, const voi case SPA_TYPE_None: return 0; case SPA_TYPE_Bool: - case SPA_TYPE_Enum: + case SPA_TYPE_Id: return *(int32_t *) r1 == *(uint32_t *) r2 ? 0 : 1; case SPA_TYPE_Int: return *(int32_t *) r1 - *(int32_t *) r2; @@ -104,31 +104,6 @@ static inline int spa_pod_compare_part(const struct spa_pod *pod1, uint32_t pod1 do_advance = true; break; - case SPA_TYPE_Prop: - { - struct spa_pod_prop *pr1, *pr2; - void *a1, *a2; - - pr1 = (struct spa_pod_prop *) p1; - pr2 = spa_pod_contents_find_prop(pod2, pod2_size, pr1->body.key); - - if (pr2 == NULL) - return -EINVAL; - - /* incompatible property types */ - if (pr1->body.value.type != pr2->body.value.type) - return -EINVAL; - - if (pr1->body.flags & SPA_POD_PROP_FLAG_UNSET || - pr2->body.flags & SPA_POD_PROP_FLAG_UNSET) - return -EINVAL; - - a1 = SPA_MEMBER(pr1, sizeof(struct spa_pod_prop), void); - a2 = SPA_MEMBER(pr2, sizeof(struct spa_pod_prop), void); - - res = spa_pod_compare_value(pr1->body.value.type, a1, a2); - break; - } default: if (SPA_POD_TYPE(p1) != SPA_POD_TYPE(p2)) return -EINVAL; diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 8ae81c6f7..703af05a8 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -28,49 +28,57 @@ #include #include -static inline void spa_pod_prop_fix_default(struct spa_pod_prop *prop) +static inline int spa_pod_choice_fix_default(struct spa_pod_choice *choice) { - void *val = SPA_MEMBER(prop, sizeof(struct spa_pod_prop), void), - *alt = SPA_MEMBER(val, prop->body.value.size, void); - int i, nalt = SPA_POD_PROP_N_VALUES(prop) - 1; + void *val, *alt; + int i, nvals; + uint32_t type, size; - switch (prop->body.flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: + nvals = SPA_POD_CHOICE_N_VALUES(choice); + type = SPA_POD_CHOICE_VALUE_TYPE(choice); + size = SPA_POD_CHOICE_VALUE_SIZE(choice); + alt = val = SPA_POD_CHOICE_VALUES(choice); + + switch (choice->body.type) { + case SPA_CHOICE_None: break; - case SPA_POD_PROP_RANGE_MIN_MAX: - case SPA_POD_PROP_RANGE_STEP: - if (spa_pod_compare_value(prop->body.value.type, val, alt) < 0) - memcpy(val, alt, prop->body.value.size); - alt = SPA_MEMBER(alt, prop->body.value.size, void); - if (spa_pod_compare_value(prop->body.value.type, val, alt) > 0) - memcpy(val, alt, prop->body.value.size); + case SPA_CHOICE_Range: + case SPA_CHOICE_Step: + if (nvals > 1) { + alt = SPA_MEMBER(alt, size, void); + if (spa_pod_compare_value(type, val, alt) < 0) + memcpy(val, alt, size); + } + if (nvals > 2) { + alt = SPA_MEMBER(alt, size, void); + if (spa_pod_compare_value(type, val, alt) > 0) + memcpy(val, alt, size); + } break; - case SPA_POD_PROP_RANGE_ENUM: + case SPA_CHOICE_Enum: { void *best = NULL; - for (i = 0; i < nalt; i++) { - if (spa_pod_compare_value(prop->body.value.type, val, alt) == 0) { + for (i = 1; i < nvals; i++) { + alt = SPA_MEMBER(alt, size, void); + if (spa_pod_compare_value(type, val, alt) == 0) { best = alt; break; } if (best == NULL) best = alt; - alt = SPA_MEMBER(alt, prop->body.value.size, void); } if (best) - memcpy(val, best, prop->body.value.size); + memcpy(val, best, size); - if (nalt <= 1) { - prop->body.flags &= ~SPA_POD_PROP_FLAG_UNSET; - prop->body.flags &= ~SPA_POD_PROP_RANGE_MASK; - prop->body.flags |= SPA_POD_PROP_RANGE_NONE; - } + if (nvals <= 1) + choice->body.type = SPA_CHOICE_None; break; } - case SPA_POD_PROP_RANGE_FLAGS: + case SPA_CHOICE_Flags: break; } + return 0; } static inline int @@ -78,159 +86,159 @@ spa_pod_filter_prop(struct spa_pod_builder *b, const struct spa_pod_prop *p1, const struct spa_pod_prop *p2) { - struct spa_pod_prop *np; - int nalt1, nalt2; + const struct spa_pod *v1, *v2; + struct spa_pod_choice *nc; + uint32_t nalt1, nalt2; void *alt1, *alt2, *a1, *a2; - uint32_t rt1, rt2; + uint32_t type, size, p1c, p2c; int j, k; + v1 = spa_pod_get_values(&p1->value, &nalt1, &p1c); + alt1 = SPA_POD_BODY(v1); + v2 = spa_pod_get_values(&p2->value, &nalt2, &p2c); + alt2 = SPA_POD_BODY(v2); + + type = v1->type; + size = v1->size; + /* incompatible property types */ - if (p1->body.value.type != p2->body.value.type) + if (type != v2->type || size != v2->size || p1->key != p2->key) return -EINVAL; - rt1 = p1->body.flags & SPA_POD_PROP_RANGE_MASK; - rt2 = p2->body.flags & SPA_POD_PROP_RANGE_MASK; - - alt1 = SPA_MEMBER(p1, sizeof(struct spa_pod_prop), void); - nalt1 = SPA_POD_PROP_N_VALUES(p1); - alt2 = SPA_MEMBER(p2, sizeof(struct spa_pod_prop), void); - nalt2 = SPA_POD_PROP_N_VALUES(p2); - - if (p1->body.flags & SPA_POD_PROP_FLAG_UNSET) { - alt1 = SPA_MEMBER(alt1, p1->body.value.size, void); - nalt1--; - } else { + if (p1c == SPA_CHOICE_None) { nalt1 = 1; - rt1 = SPA_POD_PROP_RANGE_NONE; + } else { + alt1 = SPA_MEMBER(alt1, size, void); + nalt1--; } - if (p2->body.flags & SPA_POD_PROP_FLAG_UNSET) { - alt2 = SPA_MEMBER(alt2, p2->body.value.size, void); - nalt2--; - } else { + if (p2c == SPA_CHOICE_None) { nalt2 = 1; - rt2 = SPA_POD_PROP_RANGE_NONE; + } else { + alt2 = SPA_MEMBER(alt2, size, void); + nalt2--; } /* start with copying the property */ - np = spa_pod_builder_deref(b, spa_pod_builder_push_prop(b, p1->body.key, 0)); + spa_pod_builder_prop(b, p1->key, 0); + nc = spa_pod_builder_deref(b, spa_pod_builder_push_choice(b, 0, 0)); /* default value */ - spa_pod_builder_raw(b, &p1->body.value, sizeof(p1->body.value) + p1->body.value.size); + spa_pod_builder_primitive(b, v1); - if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_NONE) || - (rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_ENUM) || - (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_NONE) || - (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_ENUM)) { + if ((p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_None) || + (p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Enum) || + (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_None) || + (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Enum)) { int n_copied = 0; /* copy all equal values but don't copy the default value again */ - for (j = 0, a1 = alt1; j < nalt1; j++, a1 += p1->body.value.size) { - for (k = 0, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) { - if (spa_pod_compare_value(p1->body.value.type, a1, a2) == 0) { - if (rt1 == SPA_POD_PROP_RANGE_ENUM || j > 0) - spa_pod_builder_raw(b, a1, p1->body.value.size); + for (j = 0, a1 = alt1; j < nalt1; j++, a1 += size) { + for (k = 0, a2 = alt2; k < nalt2; k++, a2 += size) { + if (spa_pod_compare_value(type, a1, a2) == 0) { + if (p1c == SPA_CHOICE_Enum || j > 0) + spa_pod_builder_raw(b, a1, size); n_copied++; } } } if (n_copied == 0) return -EINVAL; - np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET; + nc->body.type = SPA_CHOICE_Enum; } - if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) || - (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)) { + if ((p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Range) || + (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Range)) { int n_copied = 0; /* copy all values inside the range */ - for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 += p1->body.value.size) { - if (spa_pod_compare_value(p1->body.value.type, a1, a2) < 0) + for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 += size) { + if (spa_pod_compare_value(type, a1, a2) < 0) continue; - if (spa_pod_compare_value(p1->body.value.type, a1, a2 + p2->body.value.size) > 0) + if (spa_pod_compare_value(type, a1, a2 + size) > 0) continue; - spa_pod_builder_raw(b, a1, p1->body.value.size); + spa_pod_builder_raw(b, a1, size); n_copied++; } if (n_copied == 0) return -EINVAL; - np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET; + nc->body.type = SPA_CHOICE_Enum; } - if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_STEP) || - (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_STEP)) { + if ((p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Step) || + (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Step)) { return -ENOTSUP; } - if ((rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_NONE) || - (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_ENUM)) { + if ((p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_None) || + (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Enum)) { int n_copied = 0; /* copy all values inside the range */ - for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) { - if (spa_pod_compare_value(p1->body.value.type, a2, a1) < 0) + for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 += size) { + if (spa_pod_compare_value(type, a2, a1) < 0) continue; - if (spa_pod_compare_value(p1->body.value.type, a2, a1 + p1->body.value.size) > 0) + if (spa_pod_compare_value(type, a2, a1 + size) > 0) continue; - spa_pod_builder_raw(b, a2, p2->body.value.size); + spa_pod_builder_raw(b, a2, size); n_copied++; } if (n_copied == 0) return -EINVAL; - np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET; + nc->body.type = SPA_CHOICE_Enum; } - if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) { - if (spa_pod_compare_value(p1->body.value.type, alt1, alt2) < 0) - spa_pod_builder_raw(b, alt2, p2->body.value.size); + if (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Range) { + if (spa_pod_compare_value(type, alt1, alt2) < 0) + spa_pod_builder_raw(b, alt2, size); else - spa_pod_builder_raw(b, alt1, p1->body.value.size); + spa_pod_builder_raw(b, alt1, size); - alt1 += p1->body.value.size; - alt2 += p2->body.value.size; + alt1 += size; + alt2 += size; - if (spa_pod_compare_value(p1->body.value.type, alt1, alt2) < 0) - spa_pod_builder_raw(b, alt1, p1->body.value.size); + if (spa_pod_compare_value(type, alt1, alt2) < 0) + spa_pod_builder_raw(b, alt1, size); else - spa_pod_builder_raw(b, alt2, p2->body.value.size); + spa_pod_builder_raw(b, alt2, size); - np->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET; + nc->body.type = SPA_CHOICE_Range; } - if (rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_FLAGS) + if (p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Flags) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_STEP) + if (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Step) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_FLAGS) + if (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Flags) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_FLAGS) + if (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Flags) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_NONE) + if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_None) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) + if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Range) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_STEP) + if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Step) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_ENUM) + if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Enum) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_FLAGS) + if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Flags) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_NONE) + if (p1c == SPA_CHOICE_Flags && p2c == SPA_CHOICE_None) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) + if (p1c == SPA_CHOICE_Flags && p2c == SPA_CHOICE_Range) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_STEP) + if (p1c == SPA_CHOICE_Flags && p2c == SPA_CHOICE_Step) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_ENUM) + if (p1c == SPA_CHOICE_Flags && p2c == SPA_CHOICE_Enum) return -ENOTSUP; - if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_FLAGS) + if (p1c == SPA_CHOICE_Flags && p2c == SPA_CHOICE_Flags) return -ENOTSUP; spa_pod_builder_pop(b); - spa_pod_prop_fix_default(np); + spa_pod_choice_fix_default(nc); return 0; } @@ -249,39 +257,50 @@ static inline int spa_pod_filter_part(struct spa_pod_builder *b, uint32_t filter_offset = 0; switch (SPA_POD_TYPE(pp)) { - case SPA_TYPE_Struct: case SPA_TYPE_Object: if (pf != NULL) { + struct spa_pod_object *obj = (struct spa_pod_object *) pp; + struct spa_pod_prop *p1, *p2; + if (SPA_POD_TYPE(pf) != SPA_POD_TYPE(pp)) return -EINVAL; - if (SPA_POD_TYPE(pp) == SPA_TYPE_Struct) { - filter_offset = sizeof(struct spa_pod_struct); - spa_pod_builder_push_struct(b); - } else { - struct spa_pod_object *p1 = (struct spa_pod_object *) pp; - filter_offset = sizeof(struct spa_pod_object); - spa_pod_builder_push_object(b, p1->body.type, p1->body.id); + spa_pod_builder_push_object(b, obj->body.type, obj->body.id); + SPA_POD_OBJECT_FOREACH(obj, p1) { + p2 = spa_pod_find_prop(pf, p1->key); + if (p2 != NULL) + res = spa_pod_filter_prop(b, p1, p2); + else + spa_pod_builder_raw_padded(b, p1, SPA_POD_PROP_SIZE(p1)); + if (res < 0) + break; } + spa_pod_builder_pop(b); do_advance = true; } else do_copy = true; break; - case SPA_TYPE_Prop: - { - struct spa_pod_prop *p1, *p2; + case SPA_TYPE_Struct: + if (pf != NULL) { + if (SPA_POD_TYPE(pf) != SPA_POD_TYPE(pp)) + return -EINVAL; - p1 = (struct spa_pod_prop *) pp; - p2 = spa_pod_contents_find_prop(filter, filter_size, p1->body.key); - - if (p2 != NULL) - res = spa_pod_filter_prop(b, p1, p2); + filter_offset = sizeof(struct spa_pod_struct); + spa_pod_builder_push_struct(b); + res = spa_pod_filter_part(b, + SPA_MEMBER(pp,filter_offset,void), + SPA_POD_SIZE(pp) - filter_offset, + SPA_MEMBER(pf,filter_offset,void), + SPA_POD_SIZE(pf) - filter_offset); + spa_pod_builder_pop(b); + do_advance = true; + } else do_copy = true; break; - } + default: if (pf != NULL) { if (SPA_POD_SIZE(pp) != SPA_POD_SIZE(pf)) @@ -295,14 +314,6 @@ static inline int spa_pod_filter_part(struct spa_pod_builder *b, } if (do_copy) spa_pod_builder_raw_padded(b, pp, SPA_POD_SIZE(pp)); - else if (filter_offset) { - res = spa_pod_filter_part(b, - SPA_MEMBER(pp,filter_offset,void), - SPA_POD_SIZE(pp) - filter_offset, - SPA_MEMBER(pf,filter_offset,void), - SPA_POD_SIZE(pf) - filter_offset); - spa_pod_builder_pop(b); - } if (do_advance) { pf = spa_pod_next(pf); if (!spa_pod_is_inside(filter, filter_size, pf)) diff --git a/spa/include/spa/pod/iter.h b/spa/include/spa/pod/iter.h index 97e19d0a6..bbf9ecc44 100644 --- a/spa/include/spa/pod/iter.h +++ b/spa/include/spa/pod/iter.h @@ -69,6 +69,11 @@ static inline void *spa_pod_next(const void *iter) return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_SIZE (iter), 8), void); } +static inline struct spa_pod_prop *spa_pod_prop_next(const struct spa_pod_prop *iter) +{ + return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_PROP_SIZE (iter), 8), struct spa_pod_prop); +} + static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_control *iter) { return SPA_MEMBER(iter, SPA_ROUND_UP_N (SPA_POD_CONTROL_SIZE (iter), 8), struct spa_pod_control); @@ -79,6 +84,11 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_ (iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \ (iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter)))) +#define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter) \ + for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_choice_body), __typeof__(*(iter))); \ + (iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \ + (iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter)))) + #define SPA_POD_FOREACH(pod, size, iter) \ for ((iter) = (pod); \ spa_pod_is_inside(pod, size, iter); \ @@ -88,9 +98,9 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_ SPA_POD_FOREACH(SPA_MEMBER((pod), (offset), void),SPA_POD_SIZE (pod)-(offset),iter) #define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter) \ - for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_object_body), struct spa_pod); \ + for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_object_body), struct spa_pod_prop); \ spa_pod_is_inside(body, size, iter); \ - (iter) = spa_pod_next(iter)) + (iter) = spa_pod_prop_next(iter)) #define SPA_POD_OBJECT_FOREACH(obj, iter) \ SPA_POD_OBJECT_BODY_FOREACH(&(obj)->body, SPA_POD_BODY_SIZE(obj), iter) @@ -103,56 +113,38 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_ #define SPA_POD_SEQUENCE_FOREACH(seq, iter) \ SPA_POD_SEQUENCE_BODY_FOREACH(&(seq)->body, SPA_POD_BODY_SIZE(seq), iter) +#if 0 #define SPA_POD_PROP_ALTERNATIVE_FOREACH(body, _size, iter) \ for ((iter) = SPA_MEMBER((body), (body)->value.size + \ - sizeof(struct spa_pod_prop_body), __typeof__(*iter)); \ + sizeof(struct spa_pod_prop), __typeof__(*iter)); \ (iter) <= SPA_MEMBER((body), (_size)-(body)->value.size, __typeof__(*iter)); \ (iter) = SPA_MEMBER((iter), (body)->value.size, __typeof__(*iter))) +#endif -static inline struct spa_pod_prop *spa_pod_contents_find_prop(const struct spa_pod *pod, - uint32_t size, uint32_t key) +static inline struct spa_pod_prop *spa_pod_find_prop(const struct spa_pod *pod, uint32_t key) { - const struct spa_pod *res; - SPA_POD_FOREACH(pod, size, res) { - if (res->type == SPA_TYPE_Prop - && ((struct spa_pod_prop *) res)->body.key == key) - return (struct spa_pod_prop *) res; + struct spa_pod_prop *res; + if (pod->type != SPA_TYPE_Object) + return NULL; + SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)pod, res) { + if (res->key == key) + return res; } return NULL; } -static inline struct spa_pod_prop *spa_pod_find_prop(const struct spa_pod *pod, uint32_t key) -{ - uint32_t offset; - - if (pod->type == SPA_TYPE_Object) - offset = sizeof(struct spa_pod_object); - else if (pod->type == SPA_TYPE_Struct) - offset = sizeof(struct spa_pod_struct); - else - return NULL; - - return spa_pod_contents_find_prop(SPA_MEMBER(pod, offset, const struct spa_pod), - SPA_POD_SIZE(pod) - offset, key); -} - static inline int spa_pod_fixate(struct spa_pod *pod) { - struct spa_pod *res; - uint32_t offset; + struct spa_pod_prop *res; - if (pod->type == SPA_TYPE_Object) - offset = sizeof(struct spa_pod_object); - else if (pod->type == SPA_TYPE_Struct) - offset = sizeof(struct spa_pod_struct); - else + if (pod->type != SPA_TYPE_Object) return -EINVAL; - SPA_POD_CONTENTS_FOREACH(pod, offset, res) { - if (res->type == SPA_TYPE_Prop) - SPA_FLAG_UNSET (((struct spa_pod_prop *) res)->body.flags, - SPA_POD_PROP_FLAG_UNSET); + SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)pod, res) { + if (res->value.type == SPA_TYPE_Choice) + ((struct spa_pod_choice*)&res->value)->body.type = SPA_CHOICE_None; } + return 0; } diff --git a/spa/include/spa/pod/parser.h b/spa/include/spa/pod/parser.h index 7ab9cf899..8683075e9 100644 --- a/spa/include/spa/pod/parser.h +++ b/spa/include/spa/pod/parser.h @@ -57,7 +57,7 @@ static inline bool spa_pod_parser_can_collect(struct spa_pod *pod, char type) return type == 'T' || type == 'O' || type == 'V' || type == 's'; case SPA_TYPE_Bool: return type == 'b'; - case SPA_TYPE_Enum: + case SPA_TYPE_Id: return type == 'I'; case SPA_TYPE_Int: return type == 'i'; @@ -87,8 +87,9 @@ static inline bool spa_pod_parser_can_collect(struct spa_pod *pod, char type) return type == 'p'; case SPA_TYPE_Fd: return type == 'h'; - case SPA_TYPE_Prop: - return type == 'V'; + case SPA_TYPE_Choice: + return type == 'V' || + spa_pod_parser_can_collect(SPA_POD_CHOICE_CHILD(pod), type); default: return false; } @@ -146,7 +147,7 @@ do { \ { \ struct spa_pod_pointer_body *b = \ (struct spa_pod_pointer_body *) SPA_POD_BODY(pod); \ - *(va_arg(args, void **)) = b->value; \ + *(va_arg(args, const void **)) = b->value; \ break; \ } \ case 'h': \ @@ -211,12 +212,7 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser, case '{': if (pod == NULL || SPA_POD_TYPE(pod) != SPA_TYPE_Object) return -EINVAL; - if (++parser->depth >= SPA_POD_MAX_DEPTH) - return -EINVAL; - - it = &parser->iter[parser->depth]; - spa_pod_iter_init(it, pod, SPA_POD_SIZE(pod), sizeof(struct spa_pod_object)); - goto read_pod; + break; case '[': if (pod == NULL || SPA_POD_TYPE(pod) != SPA_TYPE_Struct) return -EINVAL; @@ -226,12 +222,13 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser, it = &parser->iter[parser->depth]; spa_pod_iter_init(it, pod, SPA_POD_SIZE(pod), sizeof(struct spa_pod_struct)); goto read_pod; - case ']': case '}': + case ']': if (current != NULL) return -EINVAL; if (--parser->depth < 0) return -EINVAL; + case '}': it = &parser->iter[parser->depth]; current = spa_pod_iter_current(it); spa_pod_iter_advance(it, current); @@ -253,8 +250,8 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser, const struct spa_pod *obj = (const struct spa_pod *) parser->iter[parser->depth].data; prop = spa_pod_find_prop(obj, key); - if (prop != NULL && (prop->body.flags & SPA_POD_PROP_FLAG_UNSET) == 0) - pod = &prop->body.value; + if (prop != NULL) + pod = &prop->value; else pod = NULL; @@ -275,6 +272,9 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser, skip = true; } collect: + if (pod->type == SPA_TYPE_Choice) + pod = SPA_POD_CHOICE_CHILD(pod); + if (suppress) suppress = false; else if (skip) diff --git a/spa/include/spa/pod/pod.h b/spa/include/spa/pod/pod.h index 92853a8f2..38df6fdbc 100644 --- a/spa/include/spa/pod/pod.h +++ b/spa/include/spa/pod/pod.h @@ -56,7 +56,7 @@ struct spa_pod_bool { int32_t __padding; }; -struct spa_pod_enum { +struct spa_pod_id { struct spa_pod pod; uint32_t value; int32_t __padding; @@ -109,8 +109,10 @@ struct spa_pod_bitmap { /* array of uint8_t follows with the bitmap */ }; -#define SPA_POD_ARRAY_TYPE(arr) ((arr)->body.child.type) -#define SPA_POD_ARRAY_N_VALUES(arr) (((arr)->pod.size - sizeof(struct spa_pod_array_body)) / (arr)->body.child.size) +#define SPA_POD_ARRAY_CHILD(arr) (&((struct spa_pod_array*)(arr))->body.child) +#define SPA_POD_ARRAY_TYPE(arr) (SPA_POD_TYPE(SPA_POD_ARRAY_CHILD(arr))) +#define SPA_POD_ARRAY_SIZE(arr) (SPA_POD_BODY_SIZE(SPA_POD_ARRAY_CHILD(arr))) +#define SPA_POD_ARRAY_N_VALUES(arr) ((SPA_POD_BODY_SIZE(arr) - sizeof(struct spa_pod_array_body)) / SPA_POD_ARRAY_SIZE(arr)) struct spa_pod_array_body { struct spa_pod child; @@ -122,6 +124,33 @@ struct spa_pod_array { struct spa_pod_array_body body; }; +#define SPA_POD_CHOICE_CHILD(choice) (&((struct spa_pod_choice*)(choice))->body.child) +#define SPA_POD_CHOICE_TYPE(choice) (((struct spa_pod_choice*)(choice))->body.type) +#define SPA_POD_CHOICE_VALUE_TYPE(choice) (SPA_POD_TYPE(SPA_POD_CHOICE_CHILD(choice))) +#define SPA_POD_CHOICE_VALUE_SIZE(choice) (SPA_POD_BODY_SIZE(SPA_POD_CHOICE_CHILD(choice))) +#define SPA_POD_CHOICE_N_VALUES(choice) ((SPA_POD_BODY_SIZE(choice) - sizeof(struct spa_pod_choice_body)) / SPA_POD_CHOICE_VALUE_SIZE(choice)) +#define SPA_POD_CHOICE_VALUES(choice) (SPA_POD_CONTENTS(struct spa_pod_choice, choice)) + +enum spa_choice_type { + SPA_CHOICE_None, /**< no choice, first value is current */ + SPA_CHOICE_Range, /**< range: default, min, max */ + SPA_CHOICE_Step, /**< range with step: default, min, max, step */ + SPA_CHOICE_Enum, /**< list: default, alternative,... */ + SPA_CHOICE_Flags, /**< flags: default, possible flags,... */ +}; + +struct spa_pod_choice_body { + uint32_t type; /**< type of choice, one of enum spa_choice_type */ + uint32_t flags; /**< extra flags */ + struct spa_pod child; + /* array with elements of child.size follows */ +}; + +struct spa_pod_choice { + struct spa_pod pod; + struct spa_pod_choice_body body; +}; + struct spa_pod_struct { struct spa_pod pod; /* one or more spa_pod follow */ @@ -152,7 +181,7 @@ static inline bool spa_pod_is_object_id(const struct spa_pod *pod, uint32_t id) struct spa_pod_pointer_body { uint32_t type; /**< pointer id, one of enum spa_type */ - void *value; + const void *value; }; struct spa_pod_pointer { @@ -165,33 +194,33 @@ struct spa_pod_fd { int value; }; -#define SPA_POD_PROP_N_VALUES(prop) (((prop)->pod.size - sizeof(struct spa_pod_prop_body)) / (prop)->body.value.size) +static inline struct spa_pod *spa_pod_get_values(const struct spa_pod *pod, uint32_t *n_vals, uint32_t *choice) +{ + if (pod->type == SPA_TYPE_Choice) { + *choice = SPA_POD_CHOICE_TYPE(pod); + *n_vals = *choice == SPA_CHOICE_None ? 1 : SPA_POD_CHOICE_N_VALUES(pod); + return (struct spa_pod*)SPA_POD_CHOICE_CHILD(pod); + } else { + *n_vals = 1; + *choice = SPA_CHOICE_None; + return (struct spa_pod*)pod; + } +} -struct spa_pod_prop_body { - uint32_t key; /**< key of property, list of valid keys depends on the - * object type */ -#define SPA_POD_PROP_RANGE_NONE 0 /**< no range */ -#define SPA_POD_PROP_RANGE_MIN_MAX 1 /**< property has range */ -#define SPA_POD_PROP_RANGE_STEP 2 /**< property has range with step */ -#define SPA_POD_PROP_RANGE_ENUM 3 /**< property has enumeration */ -#define SPA_POD_PROP_RANGE_FLAGS 4 /**< property has flags */ -#define SPA_POD_PROP_RANGE_MASK 0xf /**< mask to select range type */ -#define SPA_POD_PROP_FLAG_UNSET (1 << 4) /**< property value is unset */ -#define SPA_POD_PROP_FLAG_OPTIONAL (1 << 5) /**< property value is optional */ -#define SPA_POD_PROP_FLAG_READONLY (1 << 6) /**< property is readonly */ -#define SPA_POD_PROP_FLAG_DEPRECATED (1 << 7) /**< property is deprecated */ -#define SPA_POD_PROP_FLAG_INFO (1 << 8) /**< property is informational and is not - * used when filtering */ -#define SPA_POD_PROP_FLAG_CONTROLLABLE (1 << 9) /**< property can be controlled */ - uint32_t flags; - struct spa_pod value; - /* array with elements of value.size follows, - * first element is value/default, rest are alternatives */ -}; +#define SPA_POD_PROP_SIZE(prop) (sizeof(struct spa_pod_prop) + (prop)->value.size) struct spa_pod_prop { - struct spa_pod pod; - struct spa_pod_prop_body body; + uint32_t key; /**< key of property, list of valid keys depends on the + * object type */ +#define SPA_POD_PROP_FLAG_OPTIONAL (1 << 0) /**< property value is optional */ +#define SPA_POD_PROP_FLAG_READONLY (1 << 1) /**< property is readonly */ +#define SPA_POD_PROP_FLAG_DEPRECATED (1 << 2) /**< property is deprecated */ +#define SPA_POD_PROP_FLAG_INFO (1 << 3) /**< property is informational and is not + * used when filtering */ +#define SPA_POD_PROP_FLAG_CONTROLLABLE (1 << 4) /**< property can be controlled */ + uint32_t flags; + struct spa_pod value; + /* value follows */ }; #define SPA_POD_CONTROL_SIZE(ev) (sizeof(struct spa_pod_control) + (ev)->value.size) diff --git a/spa/include/spa/utils/type-info.h b/spa/include/spa/utils/type-info.h index 541ebfeee..44f231934 100644 --- a/spa/include/spa/utils/type-info.h +++ b/spa/include/spa/utils/type-info.h @@ -30,7 +30,6 @@ extern "C" { #define SPA_TYPE_ROOT spa_types #endif - static inline bool spa_type_is_a(const char *type, const char *parent) { return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; @@ -77,12 +76,25 @@ struct spa_type_info { #include #include +/* base for parameter object enumerations */ +#define SPA_TYPE__Choice SPA_TYPE_ENUM_BASE "Choice" +#define SPA_TYPE_CHOICE_BASE SPA_TYPE__Choice ":" + +static const struct spa_type_info spa_type_choice[] = { + { SPA_CHOICE_None, SPA_TYPE_CHOICE_BASE "None", SPA_TYPE_Int, }, + { SPA_CHOICE_Range, SPA_TYPE_CHOICE_BASE "Range", SPA_TYPE_Int, }, + { SPA_CHOICE_Step, SPA_TYPE_CHOICE_BASE "Step", SPA_TYPE_Int, }, + { SPA_CHOICE_Enum, SPA_TYPE_CHOICE_BASE "Enum", SPA_TYPE_Int, }, + { SPA_CHOICE_Flags, SPA_TYPE_CHOICE_BASE "Flags", SPA_TYPE_Int, }, + { 0, NULL, } +}; + static const struct spa_type_info spa_types[] = { /* Basic types */ { SPA_TYPE_START, SPA_TYPE_BASE, SPA_TYPE_START, }, { SPA_TYPE_None, SPA_TYPE_BASE "None", SPA_TYPE_None, }, { SPA_TYPE_Bool, SPA_TYPE_BASE "Bool", SPA_TYPE_Bool, }, - { SPA_TYPE_Enum, SPA_TYPE__Enum, SPA_TYPE_Int, }, + { SPA_TYPE_Id, SPA_TYPE_BASE "Id", SPA_TYPE_Int, }, { SPA_TYPE_Int, SPA_TYPE_BASE "Int", SPA_TYPE_Int, }, { SPA_TYPE_Long, SPA_TYPE_BASE "Long", SPA_TYPE_Long, }, { SPA_TYPE_Float, SPA_TYPE_BASE "Float", SPA_TYPE_Float, }, @@ -99,7 +111,7 @@ static const struct spa_type_info spa_types[] = { { SPA_TYPE_Sequence, SPA_TYPE_POD_BASE "Sequence", SPA_TYPE_Pod, }, { SPA_TYPE_Pointer, SPA_TYPE__Pointer, SPA_TYPE_Pointer, }, { SPA_TYPE_Fd, SPA_TYPE_BASE "Fd", SPA_TYPE_Fd, }, - { SPA_TYPE_Prop, SPA_TYPE_POD_BASE "Prop", SPA_TYPE_Pod, }, + { SPA_TYPE_Choice, SPA_TYPE_POD_BASE "Choice", SPA_TYPE_Pod, }, { SPA_TYPE_POINTER_START, SPA_TYPE__Pointer, SPA_TYPE_Pointer, }, { SPA_TYPE_POINTER_Buffer, SPA_TYPE_POINTER_BASE "Buffer", SPA_TYPE_Pointer, }, diff --git a/spa/include/spa/utils/type.h b/spa/include/spa/utils/type.h index bb58e2569..c2e5b09cf 100644 --- a/spa/include/spa/utils/type.h +++ b/spa/include/spa/utils/type.h @@ -31,7 +31,7 @@ enum { SPA_TYPE_START = 0x00000, SPA_TYPE_None, SPA_TYPE_Bool, - SPA_TYPE_Enum, + SPA_TYPE_Id, SPA_TYPE_Int, SPA_TYPE_Long, SPA_TYPE_Float, @@ -47,7 +47,7 @@ enum { SPA_TYPE_Sequence, SPA_TYPE_Pointer, SPA_TYPE_Fd, - SPA_TYPE_Prop, + SPA_TYPE_Choice, SPA_TYPE_Pod, /* Pointers */ @@ -91,9 +91,9 @@ enum { SPA_TYPE_OBJECT_ParamIO, /* vendor extensions */ - SPA_TYPE_VENDOR_PipeWire = 0x01000000, + SPA_TYPE_VENDOR_PipeWire = 0x02000000, - SPA_TYPE_VENDOR_Other = 0x7f000000, + SPA_TYPE_VENDOR_Other = 0x7f000000, }; diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index c15539c04..6badc2606 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -32,6 +32,7 @@ #include #include #include +#include #define NAME "alsa-monitor" @@ -112,6 +113,19 @@ static const char *path_get_card_id(const char *path) return e + 5; } +static inline void add_dict(struct spa_pod_builder *builder, const char *key, ...) +{ + va_list args; + + va_start(args, key); + while (key) { + spa_pod_builder_string(builder, key); + spa_pod_builder_string(builder, va_arg(args, const char*)); + key = va_arg(args, const char *); + } + va_end(args); +} + static int fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev_info, struct card *card, @@ -160,57 +174,59 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, if (!(name && *name)) name = "Unknown"; - spa_pod_builder_add(builder, - "{", SPA_TYPE_OBJECT_MonitorItem, 0, - ":", SPA_MONITOR_ITEM_id, "s", id, - ":", SPA_MONITOR_ITEM_flags, "I", SPA_MONITOR_ITEM_FLAG_NONE, - ":", SPA_MONITOR_ITEM_state, "I", SPA_MONITOR_ITEM_STATE_Available, - ":", SPA_MONITOR_ITEM_name, "s", name, - ":", SPA_MONITOR_ITEM_class, "s", klass, - ":", SPA_MONITOR_ITEM_factory, "p", SPA_TYPE_INTERFACE_HandleFactory, factory, - ":", SPA_MONITOR_ITEM_info, "[", NULL); + spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_MonitorItem, 0); + spa_pod_builder_props(builder, + SPA_MONITOR_ITEM_id, &SPA_POD_String(id, sizeof(id)), + SPA_MONITOR_ITEM_flags, &SPA_POD_Id(SPA_MONITOR_ITEM_FLAG_NONE), + SPA_MONITOR_ITEM_state, &SPA_POD_Id(SPA_MONITOR_ITEM_STATE_Available), + SPA_MONITOR_ITEM_name, &SPA_POD_Stringv(name), + SPA_MONITOR_ITEM_class, &SPA_POD_Stringv(klass), + SPA_MONITOR_ITEM_factory, &SPA_POD_Pointer(SPA_TYPE_INTERFACE_HandleFactory, factory), + 0); - spa_pod_builder_add(builder, - "s", "alsa.card", "s", card->name, - "s", "alsa.device", "s", device_name, - "s", "alsa.card.id", "s", snd_ctl_card_info_get_id(card_info), - "s", "alsa.card.components", "s", snd_ctl_card_info_get_components(card_info), - "s", "alsa.card.driver", "s", snd_ctl_card_info_get_driver(card_info), - "s", "alsa.card.name", "s", snd_ctl_card_info_get_name(card_info), - "s", "alsa.card.longname", "s", snd_ctl_card_info_get_longname(card_info), - "s", "alsa.card.mixername", "s", snd_ctl_card_info_get_mixername(card_info), - "s", "udev-probed", "s", "1", - "s", "device.api", "s", "alsa", - "s", "device.name", "s", snd_ctl_card_info_get_id(card_info), - "s", "alsa.pcm.id", "s", snd_pcm_info_get_id(dev_info), - "s", "alsa.pcm.name", "s", snd_pcm_info_get_name(dev_info), - "s", "alsa.pcm.subname", "s", snd_pcm_info_get_subdevice_name(dev_info), + spa_pod_builder_prop(builder, SPA_MONITOR_ITEM_info, 0); + spa_pod_builder_push_struct(builder), + add_dict(builder, + "alsa.card", card->name, + "alsa.device", device_name, + "alsa.card.id", snd_ctl_card_info_get_id(card_info), + "alsa.card.components", snd_ctl_card_info_get_components(card_info), + "alsa.card.driver", snd_ctl_card_info_get_driver(card_info), + "alsa.card.name", snd_ctl_card_info_get_name(card_info), + "alsa.card.longname", snd_ctl_card_info_get_longname(card_info), + "alsa.card.mixername", snd_ctl_card_info_get_mixername(card_info), + "udev-probed", "1", + "device.api", "alsa", + "device.name", snd_ctl_card_info_get_id(card_info), + "alsa.pcm.id", snd_pcm_info_get_id(dev_info), + "alsa.pcm.name", snd_pcm_info_get_name(dev_info), + "alsa.pcm.subname", snd_pcm_info_get_subdevice_name(dev_info), NULL); if ((str = udev_device_get_property_value(dev, "SOUND_CLASS")) && *str) { - spa_pod_builder_add(builder, "s", "device.class", "s", str, NULL); + add_dict(builder, "device.class", str, NULL); } str = udev_device_get_property_value(dev, "ID_PATH"); if (!(str && *str)) str = udev_device_get_syspath(dev); if (str && *str) { - spa_pod_builder_add(builder, "s", "device.bus_path", "s", str, 0); + add_dict(builder, "device.bus_path", str, 0); } if ((str = udev_device_get_syspath(dev)) && *str) { - spa_pod_builder_add(builder, "s", "sysfs.path", "s", str, 0); + add_dict(builder, "sysfs.path", str, 0); } if ((str = udev_device_get_property_value(dev, "ID_ID")) && *str) { - spa_pod_builder_add(builder, "s", "udev.id", "s", str, 0); + add_dict(builder, "udev.id", str, 0); } if ((str = udev_device_get_property_value(dev, "ID_BUS")) && *str) { - spa_pod_builder_add(builder, "s", "device.bus", "s", str, 0); + add_dict(builder, "device.bus", str, 0); } if ((str = udev_device_get_property_value(dev, "SUBSYSTEM")) && *str) { - spa_pod_builder_add(builder, "s", "device.subsystem", "s", str, 0); + add_dict(builder, "device.subsystem", str, 0); } if ((str = udev_device_get_property_value(dev, "ID_VENDOR_ID")) && *str) { - spa_pod_builder_add(builder, "s", "device.vendor.id", "s", str, 0); + add_dict(builder, "device.vendor.id", str, 0); } str = udev_device_get_property_value(dev, "ID_VENDOR_FROM_DATABASE"); if (!(str && *str)) { @@ -220,20 +236,23 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, } } if (str && *str) { - spa_pod_builder_add(builder, "s", "device.vendor.name", "s", str, 0); + add_dict(builder, "device.vendor.name", str, 0); } if ((str = udev_device_get_property_value(dev, "ID_MODEL_ID")) && *str) { - spa_pod_builder_add(builder, "s", "device.product.id", "s", str, 0); + add_dict(builder, "device.product.id", str, 0); } - spa_pod_builder_add(builder, "s", "device.product.name", "s", name, 0); + add_dict(builder, "device.product.name", name, 0); if ((str = udev_device_get_property_value(dev, "ID_SERIAL")) && *str) { - spa_pod_builder_add(builder, "s", "device.serial", "s", str, 0); + add_dict(builder, "device.serial", str, 0); } if ((str = udev_device_get_property_value(dev, "SOUND_FORM_FACTOR")) && *str) { - spa_pod_builder_add(builder, "s", "device.form_factor", "s", str, 0); + add_dict(builder, "device.form_factor", str, 0); } - *item = spa_pod_builder_add(builder, "]}", NULL); + spa_pod_builder_pop(builder); + *item = spa_pod_builder_pop(builder); + + spa_debug_pod(0, NULL, *item); return 0; } @@ -347,7 +366,7 @@ static void impl_on_fd_events(struct spa_source *source) struct impl *this = source->data; struct udev_device *dev; const char *action; - uint32_t id; + uint32_t type; struct card *card; struct spa_event *event; @@ -357,18 +376,18 @@ static void impl_on_fd_events(struct spa_source *source) action = "change"; if (strcmp(action, "add") == 0) { - id = SPA_MONITOR_EVENT_Added; + type = SPA_MONITOR_EVENT_Added; } else if (strcmp(action, "change") == 0) { - id = SPA_MONITOR_EVENT_Changed; + type = SPA_MONITOR_EVENT_Changed; } else if (strcmp(action, "remove") == 0) { - id = SPA_MONITOR_EVENT_Removed; + type = SPA_MONITOR_EVENT_Removed; } else return; if ((card = find_card(this, dev)) == NULL) return; - if (id == SPA_MONITOR_EVENT_Removed) { + if (type == SPA_MONITOR_EVENT_Removed) { int i; for (i = 0; i < MAX_DEVICES; i++) { @@ -377,23 +396,24 @@ static void impl_on_fd_events(struct spa_source *source) char id[64]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); - if (SPA_FLAG_CHECK(device->flags, DEVICE_FLAG_PLAYBACK)) { snprintf(id, 64, "%s,%d/P", card->name, device->id); - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, type, 0); spa_pod_builder_object(&b, SPA_TYPE_OBJECT_MonitorItem, 0, - ":", SPA_MONITOR_ITEM_id, "s", id, - ":", SPA_MONITOR_ITEM_name, "s", id); + SPA_MONITOR_ITEM_id, SPA_POD_Stringv(id), + SPA_MONITOR_ITEM_name, SPA_POD_Stringv(id), + 0); this->callbacks->event(this->callbacks_data, event); } if (SPA_FLAG_CHECK(device->flags, DEVICE_FLAG_RECORD)) { snprintf(id, 64, "%s,%d/C", card->name, device->id); - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, type, 0); spa_pod_builder_object(&b, SPA_TYPE_OBJECT_MonitorItem, 0, - ":", SPA_MONITOR_ITEM_id, "s", id, - ":", SPA_MONITOR_ITEM_name, "s", id); + SPA_MONITOR_ITEM_id, SPA_POD_Stringv(id), + SPA_MONITOR_ITEM_name, SPA_POD_Stringv(id), + 0); this->callbacks->event(this->callbacks_data, event); } device->flags = 0; @@ -408,7 +428,7 @@ static void impl_on_fd_events(struct spa_source *source) struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); struct spa_pod *item; - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, type, 0); if (get_next_device(this, card, &item, &b) < 0) break; diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index f87e77e73..ec41b0ca5 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -69,8 +69,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -83,39 +85,42 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, - ":", SPA_PROP_INFO_name, "s", "The ALSA device", - ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_device), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA device"), + SPA_PROP_INFO_type, &SPA_POD_String(p->device, sizeof(p->device)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, - ":", SPA_PROP_INFO_name, "s", "The ALSA device name", - ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceName), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA device name"), + SPA_PROP_INFO_type, &SPA_POD_String(p->device_name, sizeof(p->device_name)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName, - ":", SPA_PROP_INFO_name, "s", "The ALSA card name", - ":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_cardName), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA card name"), + SPA_PROP_INFO_type, &SPA_POD_String(p->card_name, sizeof(p->card_name)), + 0); break; case 3: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, - ":", SPA_PROP_INFO_name, "s", "The minimum latency", - ":", SPA_PROP_INFO_type, "ir", p->min_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_minLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The minimum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX), + 0); break; case 4: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, - ":", SPA_PROP_INFO_name, "s", "The maximum latency", - ":", SPA_PROP_INFO_type, "ir", p->max_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_maxLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The maximum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX), + 0); break; default: return 0; @@ -130,11 +135,12 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_device, "S", p->device, sizeof(p->device), - ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), - ":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name), - ":", SPA_PROP_minLatency, "i", p->min_latency, - ":", SPA_PROP_maxLatency, "i", p->max_latency); + SPA_PROP_device, &SPA_POD_String(p->device, sizeof(p->device)), + SPA_PROP_deviceName, &SPA_POD_String(p->device_name, sizeof(p->device_name)), + SPA_PROP_cardName, &SPA_POD_String(p->card_name, sizeof(p->card_name)), + SPA_PROP_minLatency, &SPA_POD_Int(p->min_latency), + SPA_PROP_maxLatency, &SPA_POD_Int(p->max_latency), + 0); break; default: return 0; @@ -327,8 +333,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO, }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -353,15 +361,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", - this->props.max_latency * this->frame_size, - SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, - INT32_MAX), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + this->props.max_latency * this->frame_size, + this->props.min_latency * this->frame_size, + INT32_MAX), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -372,8 +380,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -385,20 +394,23 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Clock, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Clock), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_clock)), + 0); break; default: return 0; diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index 0ca34c7dd..dd699b3bf 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -73,8 +73,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props, }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -84,39 +86,42 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, - ":", SPA_PROP_INFO_name, "s", "The ALSA device", - ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_device), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA device"), + SPA_PROP_INFO_type, &SPA_POD_String(p->device, sizeof(p->device)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, - ":", SPA_PROP_INFO_name, "s", "The ALSA device name", - ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceName), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA device name"), + SPA_PROP_INFO_type, &SPA_POD_String(p->device_name, sizeof(p->device_name)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName, - ":", SPA_PROP_INFO_name, "s", "The ALSA card name", - ":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_cardName), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The ALSA card name"), + SPA_PROP_INFO_type, &SPA_POD_String(p->card_name, sizeof(p->card_name)), + 0); break; case 3: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, - ":", SPA_PROP_INFO_name, "s", "The minimum latency", - ":", SPA_PROP_INFO_type, "ir", p->min_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_minLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The minimum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX), + 0); break; case 4: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, - ":", SPA_PROP_INFO_name, "s", "The maximum latency", - ":", SPA_PROP_INFO_type, "ir", p->max_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_maxLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The maximum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX), + 0); break; default: return 0; @@ -128,11 +133,12 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_device, "S", p->device, sizeof(p->device), - ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), - ":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name), - ":", SPA_PROP_minLatency, "i", p->min_latency, - ":", SPA_PROP_maxLatency, "i", p->max_latency); + SPA_PROP_device, &SPA_POD_String(p->device, sizeof(p->device)), + SPA_PROP_deviceName, &SPA_POD_String(p->device_name, sizeof(p->device_name)), + SPA_PROP_cardName, &SPA_POD_String(p->card_name, sizeof(p->card_name)), + SPA_PROP_minLatency, &SPA_POD_Int(p->min_latency), + SPA_PROP_maxLatency, &SPA_POD_Int(p->max_latency), + 0); break; default: return 0; @@ -338,8 +344,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Meta }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -364,15 +372,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", this->props.max_latency * - this->frame_size, - SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, - INT32_MAX), - ":", SPA_PARAM_BUFFERS_stride, "i", this->frame_size, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + this->props.max_latency * this->frame_size, + this->props.min_latency * this->frame_size, + INT32_MAX), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(this->frame_size), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -383,8 +391,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -396,14 +405,16 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Clock, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Clock), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_clock)), + 0); break; default: return 0; diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index d940d7660..4f5011434 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -112,7 +112,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, unsigned int min, max; uint8_t buffer[4096]; struct spa_pod_builder b = { 0 }; - struct spa_pod_prop *prop; + struct spa_pod_choice *choice; struct spa_pod *fmt; int res; bool opened; @@ -134,76 +134,82 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, CHECK(snd_pcm_hw_params_any(hndl, params), "Broken configuration: no configurations available"); spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); - spa_pod_builder_add(&b, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, 0); + spa_pod_builder_props(&b, + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + 0); snd_pcm_format_mask_alloca(&fmask); snd_pcm_hw_params_get_format_mask(params, fmask); - prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_format, - SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_prop(&b, SPA_FORMAT_AUDIO_format, 0); + + choice = spa_pod_builder_deref(&b, + spa_pod_builder_push_choice(&b, SPA_CHOICE_None, 0)); for (i = 1, j = 0; i < SPA_N_ELEMENTS(format_info); i++) { const struct format_info *fi = &format_info[i]; if (snd_pcm_format_mask_test(fmask, fi->format)) { if (j++ == 0) - spa_pod_builder_enum(&b, fi->spa_format); - spa_pod_builder_enum(&b, fi->spa_format); + spa_pod_builder_id(&b, fi->spa_format); + spa_pod_builder_id(&b, fi->spa_format); } } if (j > 1) - prop->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET; + choice->body.type = SPA_CHOICE_Enum; spa_pod_builder_pop(&b); snd_pcm_access_mask_alloca(&amask); snd_pcm_hw_params_get_access_mask(params, amask); - prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_layout, - SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_prop(&b, SPA_FORMAT_AUDIO_layout, 0); + + choice = spa_pod_builder_deref(&b, + spa_pod_builder_push_choice(&b, SPA_CHOICE_None, 0)); j = 0; if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_INTERLEAVED)) { if (j++ == 0) - spa_pod_builder_enum(&b, SPA_AUDIO_LAYOUT_INTERLEAVED); - spa_pod_builder_enum(&b, SPA_AUDIO_LAYOUT_INTERLEAVED); + spa_pod_builder_id(&b, SPA_AUDIO_LAYOUT_INTERLEAVED); + spa_pod_builder_id(&b, SPA_AUDIO_LAYOUT_INTERLEAVED); } if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED)) { if (j++ == 0) - spa_pod_builder_enum(&b, SPA_AUDIO_LAYOUT_NON_INTERLEAVED); - spa_pod_builder_enum(&b, SPA_AUDIO_LAYOUT_NON_INTERLEAVED); + spa_pod_builder_id(&b, SPA_AUDIO_LAYOUT_NON_INTERLEAVED); + spa_pod_builder_id(&b, SPA_AUDIO_LAYOUT_NON_INTERLEAVED); } if (j > 1) - prop->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET; + choice->body.type = SPA_CHOICE_Enum; spa_pod_builder_pop(&b); CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min"); CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max"); - prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_rate, SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_prop(&b, SPA_FORMAT_AUDIO_rate, 0); + + choice = spa_pod_builder_deref(&b, + spa_pod_builder_push_choice(&b, SPA_CHOICE_None, 0)); spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_RATE, min, max)); if (min != max) { spa_pod_builder_int(&b, min); spa_pod_builder_int(&b, max); - prop->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET; + choice->body.type = SPA_CHOICE_Range; } spa_pod_builder_pop(&b); CHECK(snd_pcm_hw_params_get_channels_min(params, &min), "get_channels_min"); CHECK(snd_pcm_hw_params_get_channels_max(params, &max), "get_channels_max"); - prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_channels, SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_prop(&b, SPA_FORMAT_AUDIO_channels, 0); + choice = spa_pod_builder_deref(&b, + spa_pod_builder_push_choice(&b, SPA_CHOICE_None, 0)); spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_CHANNELS, min, max)); if (min != max) { spa_pod_builder_int(&b, min); spa_pod_builder_int(&b, max); - prop->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET; + choice->body.type = SPA_CHOICE_Range; } spa_pod_builder_pop(&b); diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index ffb6eed13..b317b06e7 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -564,9 +564,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, - ":", SPA_PROP_INFO_type, "fru", 1.0, - SPA_POD_PROP_MIN_MAX(0.0, 10.0)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_volume), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Float(1.0, 0.0, 10.0), + 0); break; default: return 0; @@ -578,20 +578,23 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; case 2: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index ab3a40de3..159509bb0 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -309,24 +309,23 @@ static int port_enum_formats(struct spa_node *node, if (other->have_format) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", other->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(other->format.info.raw.rate), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(DEFAULT_CHANNELS, 1, INT32_MAX), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(DEFAULT_RATE, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(DEFAULT_CHANNELS, 1, INT32_MAX), + 0); } break; default: @@ -374,8 +373,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -413,13 +414,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, - ":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(buffers, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(port->blocks), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + size * port->stride, + 16 * port->stride, + INT32_MAX / port->stride), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; } case SPA_PARAM_Meta: @@ -430,8 +433,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -443,14 +447,16 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; @@ -707,15 +713,13 @@ static int process_control(struct impl *this, struct port *port, struct spa_pod_ { struct props *p = &this->props; float volume = p->volume; - struct spa_pod *pod; + struct spa_pod_prop *prop; struct spa_pod_object *obj = (struct spa_pod_object *) &c->value; - SPA_POD_OBJECT_FOREACH(obj, pod) { - struct spa_pod_prop *prop = (struct spa_pod_prop *)pod; - - switch (prop->body.key) { + SPA_POD_OBJECT_FOREACH(obj, prop) { + switch (prop->key) { case SPA_PROP_volume: - volume = SPA_POD_VALUE(struct spa_pod_float, &prop->body.value); + volume = SPA_POD_VALUE(struct spa_pod_float, &prop->value); if (volume != p->volume) { p->volume = volume; setup_matrix(this, diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index 5fe5a6352..eeb22382a 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -422,41 +422,47 @@ static int port_enum_formats(struct spa_node *node, if (other->info.raw.channels > 0) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", other->info.raw.format, - SPA_POD_PROP_ENUM(3, other->info.raw.format, - SPA_AUDIO_FORMAT_F32, - SPA_AUDIO_FORMAT_F32_OE), - ":", SPA_FORMAT_AUDIO_layout, "Ieu", other->info.raw.layout, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", SPA_FORMAT_AUDIO_rate, "i", other->info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", other->info.raw.channels); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(4, + other->info.raw.format, + other->info.raw.format, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE), + SPA_FORMAT_AUDIO_layout, &SPA_POD_CHOICE_ENUM_Id(3, + other->info.raw.layout, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(other->info.raw.rate), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(other->info.raw.channels), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16, - SPA_POD_PROP_ENUM(11, SPA_AUDIO_FORMAT_U8, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16_OE, - SPA_AUDIO_FORMAT_F32, - SPA_AUDIO_FORMAT_F32_OE, - SPA_AUDIO_FORMAT_S32, - SPA_AUDIO_FORMAT_S32_OE, - SPA_AUDIO_FORMAT_S24, - SPA_AUDIO_FORMAT_S24_OE, - SPA_AUDIO_FORMAT_S24_32, - SPA_AUDIO_FORMAT_S24_32_OE), - ":", SPA_FORMAT_AUDIO_layout, "Ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(12, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_U8, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE), + SPA_FORMAT_AUDIO_layout, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int( + DEFAULT_RATE, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int( + DEFAULT_CHANNELS, 1, INT32_MAX), + 0); } break; default: @@ -506,7 +512,7 @@ impl_node_port_enum_params(struct spa_node *node, if (*index < SPA_N_ELEMENTS(list)) param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), 0); else return 0; break; @@ -527,8 +533,8 @@ impl_node_port_enum_params(struct spa_node *node, case SPA_PARAM_Buffers: { - uint32_t buffers, size; - const char *size_fmt; + uint32_t buffers; + void *pod; if (!port->have_format) return -EIO; @@ -537,23 +543,22 @@ impl_node_port_enum_params(struct spa_node *node, if (other->n_buffers > 0) { buffers = other->n_buffers; - size = other->size / other->stride; - size_fmt = "ir"; + pod = &SPA_POD_Int(other->size / other->stride * port->stride); } else { buffers = 1; - size = 1024; - size_fmt = "iru"; + pod = &SPA_POD_CHOICE_RANGE_Int(1024 * port->stride, + 16 * port->stride, + INT32_MAX / port->stride); } param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, - SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, - ":", SPA_PARAM_BUFFERS_size, size_fmt, size * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(buffers, 2, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(port->blocks), + SPA_PARAM_BUFFERS_size, pod, + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; } case SPA_PARAM_Meta: @@ -564,8 +569,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -577,8 +583,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; default: return 0; diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index eac378425..107e26a72 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -303,55 +303,53 @@ static int port_enum_formats(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - uint32_t rate; - const char *rspec; + void *rate; switch (*index) { case 0: if (this->have_format || this->force_rate) { - rate = this->format.info.raw.rate; - rspec = "ir"; + rate = &SPA_POD_Int(this->format.info.raw.rate); } else { - rate = DEFAULT_RATE; - rspec = "iru"; + rate = &SPA_POD_CHOICE_RANGE_Int(DEFAULT_RATE, 1, INT32_MAX); } if (direction == SPA_DIRECTION_OUTPUT) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_F32, - SPA_POD_PROP_ENUM(11, - SPA_AUDIO_FORMAT_F32, - SPA_AUDIO_FORMAT_F32_OE, - SPA_AUDIO_FORMAT_S32, - SPA_AUDIO_FORMAT_S32_OE, - SPA_AUDIO_FORMAT_S24_32, - SPA_AUDIO_FORMAT_S24_32_OE, - SPA_AUDIO_FORMAT_S24, - SPA_AUDIO_FORMAT_S24_OE, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16_OE, - SPA_AUDIO_FORMAT_U8), - ":", SPA_FORMAT_AUDIO_layout, "Ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", SPA_FORMAT_AUDIO_rate, rspec, rate, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "i", this->port_count); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(12, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_U8), + SPA_FORMAT_AUDIO_layout, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, rate, + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(this->port_count), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, rspec, rate, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "i", 1); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, rate, + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(1), + 0); } break; default: @@ -400,8 +398,9 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO, }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), 0); else return 0; } @@ -425,13 +424,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(port->blocks), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * port->stride, + 16 * port->stride, + MAX_SAMPLES * port->stride), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: if (!port->have_format) @@ -441,8 +442,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "i", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -453,8 +455,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; default: return 0; diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index 5c4df94eb..c8139041e 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -283,24 +283,24 @@ static int port_enum_formats(struct spa_node *node, if (other->have_format) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "iru", other->format.info.raw.rate, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "i", other->format.info.raw.channels); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int( + other->format.info.raw.rate, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(other->format.info.raw.channels), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(DEFAULT_RATE, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(DEFAULT_CHANNELS, 1, INT32_MAX), + 0); } break; default: @@ -348,8 +348,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -386,13 +388,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, - ":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(buffers, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(port->blocks), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + size * port->stride, + 16 * port->stride, + INT32_MAX / port->stride), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; } case SPA_PARAM_Meta: @@ -403,8 +407,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -415,14 +420,16 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; default: return 0; diff --git a/spa/plugins/audioconvert/splitter.c b/spa/plugins/audioconvert/splitter.c index b1fec715d..71205a7d0 100644 --- a/spa/plugins/audioconvert/splitter.c +++ b/spa/plugins/audioconvert/splitter.c @@ -303,55 +303,51 @@ static int port_enum_formats(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - uint32_t rate; - const char *rspec; + struct spa_pod *prate; switch (*index) { case 0: - if (this->have_format || this->force_rate) { - rate = this->format.info.raw.rate; - rspec = "ir"; - } - else { - rate = DEFAULT_RATE; - rspec = "iru"; - } + if (this->have_format || this->force_rate) + prate = (struct spa_pod*)&SPA_POD_Int(this->format.info.raw.rate); + else + prate = (struct spa_pod*)&SPA_POD_CHOICE_RANGE_Int(DEFAULT_RATE, 1, INT32_MAX); if (direction == SPA_DIRECTION_INPUT) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_F32, - SPA_POD_PROP_ENUM(11, - SPA_AUDIO_FORMAT_F32, - SPA_AUDIO_FORMAT_F32_OE, - SPA_AUDIO_FORMAT_S32, - SPA_AUDIO_FORMAT_S32_OE, - SPA_AUDIO_FORMAT_S24_32, - SPA_AUDIO_FORMAT_S24_32_OE, - SPA_AUDIO_FORMAT_S24, - SPA_AUDIO_FORMAT_S24_OE, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16_OE, - SPA_AUDIO_FORMAT_U8), - ":", SPA_FORMAT_AUDIO_layout, "Ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", SPA_FORMAT_AUDIO_rate, rspec, rate, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "i", this->port_count); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(12, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_U8), + SPA_FORMAT_AUDIO_layout, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, prate, + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(this->port_count), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, rspec, rate, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "i", 1); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, prate, + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(1), + 0); } break; default: @@ -400,8 +396,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -426,13 +424,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(port->blocks), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * port->stride, + 16 * port->stride, + MAX_SAMPLES * port->stride), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -443,8 +443,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -455,8 +456,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; default: return 0; diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 857239adf..40309242a 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -328,23 +328,24 @@ static int port_enum_formats(struct spa_node *node, if (this->have_format) { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(this->format.info.raw.format), + SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(this->format.info.raw.rate), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(this->format.info.raw.channels), + 0); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_F32), - ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Int(3, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(2, 1, INT32_MAX), + 0); } break; default: @@ -391,8 +392,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO, }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -417,13 +420,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * this->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * this->bpf, + 16 * this->bpf, + INT32_MAX / this->bpf), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: if (!port->have_format) @@ -433,8 +438,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -445,20 +451,23 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 7062bee24..b8d055a75 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -53,8 +53,8 @@ enum wave_type { struct props { bool live; uint32_t wave; - double freq; - double volume; + float freq; + float volume; }; static void reset_props(struct props *props) @@ -100,15 +100,11 @@ struct impl { struct spa_io_range *io_range; struct spa_io_sequence *io_control; - uint32_t *io_wave; - double *io_freq; - double *io_volume; - bool have_format; struct spa_audio_info current_format; size_t bpf; render_func_t render_func; - double accumulator; + float accumulator; struct buffer buffers[MAX_BUFFERS]; uint32_t n_buffers; @@ -150,8 +146,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -164,35 +162,42 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_live, - ":", SPA_PROP_INFO_name, "s", "Configure live mode of the source", - ":", SPA_PROP_INFO_type, "b", p->live); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_live), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Configure live mode of the source"), + SPA_PROP_INFO_type, &SPA_POD_Bool(p->live), + 0); break; case 1: - param = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_waveType, - ":", SPA_PROP_INFO_name, "s", "Select the waveform", - ":", SPA_PROP_INFO_type, "i", p->wave, - ":", SPA_PROP_INFO_labels, "[-i", - "i", WAVE_SINE, "s", "Sine wave", - "i", WAVE_SQUARE, "s", "Square wave", "]"); + spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_PropInfo, id); + spa_pod_builder_props(&b, + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_waveType), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Select the waveform"), + SPA_PROP_INFO_type, &SPA_POD_Int(p->wave), + 0); + spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, SPA_POD_PROP_FLAG_INFO); + spa_pod_builder_push_struct(&b); + spa_pod_builder_int(&b, WAVE_SINE); + spa_pod_builder_string(&b, "Sine wave"); + spa_pod_builder_int(&b, WAVE_SQUARE); + spa_pod_builder_string(&b, "Square wave"); + spa_pod_builder_pop(&b); + param = spa_pod_builder_pop(&b); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_frequency, - ":", SPA_PROP_INFO_name, "s", "Select the frequency", - ":", SPA_PROP_INFO_type, "dr", p->freq, - SPA_POD_PROP_MIN_MAX(0.0, 50000000.0)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_frequency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Select the frequency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Float(p->freq, 0.0, 50000000.0), + 0); break; case 3: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, - ":", SPA_PROP_INFO_name, "s", "Select the volume", - ":", SPA_PROP_INFO_type, "dr", p->volume, - SPA_POD_PROP_MIN_MAX(0.0, 10.0)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_volume), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Select the volume"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0), + 0); break; default: return 0; @@ -207,10 +212,11 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_live, "b", p->live, - ":", SPA_PROP_waveType, "i", p->wave, - ":", SPA_PROP_frequency, "d", p->freq, - ":", SPA_PROP_volume, "d", p->volume); + SPA_PROP_live, &SPA_POD_Bool(p->live), + SPA_PROP_waveType, &SPA_POD_Int(p->wave), + SPA_PROP_frequency, &SPA_POD_Float(p->freq), + SPA_PROP_volume, &SPA_POD_Float(p->volume), + 0); break; default: return 0; @@ -527,18 +533,18 @@ port_enum_formats(struct impl *this, case 0: *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16, - SPA_POD_PROP_ENUM(4, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32, - SPA_AUDIO_FORMAT_F32, - SPA_AUDIO_FORMAT_F64), - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(5, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F64), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(2, 1, INT32_MAX), + 0); break; default: return 0; @@ -581,8 +587,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO, }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -609,13 +617,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * this->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * this->bpf, + 16 * this->bpf, + INT32_MAX / this->bpf), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: if (!this->have_format) @@ -625,8 +635,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -637,20 +648,23 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; @@ -1041,10 +1055,6 @@ impl_init(const struct spa_handle_factory *factory, this->node = impl_node; reset_props(&this->props); - this->io_wave = &this->props.wave; - this->io_freq = &this->props.freq; - this->io_volume = &this->props.volume; - spa_list_init(&this->empty); this->timer_source.func = on_output; diff --git a/spa/plugins/audiotestsrc/render.c b/spa/plugins/audiotestsrc/render.c index 12dd1d3d5..083af2001 100644 --- a/spa/plugins/audiotestsrc/render.c +++ b/spa/plugins/audiotestsrc/render.c @@ -26,9 +26,9 @@ static void \ audio_test_src_create_sine_##type (struct impl *this, type *samples, size_t n_samples) \ { \ int i, c, channels; \ - double step, amp; \ - double freq = *this->io_freq; \ - double volume = *this->io_volume; \ + float step, amp; \ + float freq = this->props.freq; \ + float volume = this->props.volume; \ \ channels = this->current_format.info.raw.channels; \ step = M_PI_M2 * freq / this->current_format.info.raw.rate; \ diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 140764245..5c719040a 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -166,8 +166,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -180,18 +182,18 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, - ":", SPA_PROP_INFO_name, "s", "The minimum latency", - ":", SPA_PROP_INFO_type, "ir", p->min_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_minLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The minimum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, - ":", SPA_PROP_INFO_name, "s", "The maximum latency", - ":", SPA_PROP_INFO_type, "ir", p->max_latency, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_maxLatency), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The maximum latency"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX), + 0); break; default: return 0; @@ -206,8 +208,9 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_minLatency, "i", p->min_latency, - ":", SPA_PROP_maxLatency, "i", p->max_latency); + SPA_PROP_minLatency, &SPA_POD_Int(p->min_latency), + SPA_PROP_maxLatency, &SPA_POD_Int(p->max_latency), + 0); break; default: return 0; @@ -946,8 +949,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Meta }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -967,12 +972,13 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Format, id, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", rate, - ":", SPA_FORMAT_AUDIO_channels, "i", channels); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_S16), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(rate), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(channels), + 0); } else return -EIO; @@ -995,15 +1001,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", this->props.min_latency * - this->frame_size, - SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, - INT32_MAX), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 2, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + this->props.min_latency * this->frame_size, + this->props.min_latency * this->frame_size, + INT32_MAX), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -1014,8 +1020,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; diff --git a/spa/plugins/bluez5/bluez5-monitor.c b/spa/plugins/bluez5/bluez5-monitor.c index 6d65e12d4..f180f557d 100644 --- a/spa/plugins/bluez5/bluez5-monitor.c +++ b/spa/plugins/bluez5/bluez5-monitor.c @@ -64,33 +64,39 @@ struct spa_bt_monitor { struct spa_handle_factory spa_a2dp_sink_factory; +static inline void add_dict(struct spa_pod_builder *builder, const char *key, const char *val) +{ + spa_pod_builder_string(builder, key); + spa_pod_builder_string(builder, val); +} + static void fill_item(struct spa_bt_monitor *this, struct spa_bt_transport *transport, struct spa_pod **result, struct spa_pod_builder *builder) { char trans[16]; - spa_pod_builder_add(builder, - "{", SPA_TYPE_OBJECT_MonitorItem, 0, - ":", SPA_MONITOR_ITEM_id, "s", transport->path, - ":", SPA_MONITOR_ITEM_flags, "I", SPA_MONITOR_ITEM_FLAG_NONE, - ":", SPA_MONITOR_ITEM_state, "I", SPA_MONITOR_ITEM_STATE_Available, - ":", SPA_MONITOR_ITEM_name, "s", transport->path, - ":", SPA_MONITOR_ITEM_class, "s", "Adapter/Bluetooth", - ":", SPA_MONITOR_ITEM_factory, "p", SPA_TYPE_INTERFACE_HandleFactory, &spa_a2dp_sink_factory, - ":", SPA_MONITOR_ITEM_info, "[", - NULL); + spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_MonitorItem, 0); + spa_pod_builder_props(builder, + SPA_MONITOR_ITEM_id, &SPA_POD_Stringv(transport->path), + SPA_MONITOR_ITEM_flags, &SPA_POD_Id(SPA_MONITOR_ITEM_FLAG_NONE), + SPA_MONITOR_ITEM_state, &SPA_POD_Id(SPA_MONITOR_ITEM_STATE_Available), + SPA_MONITOR_ITEM_name, &SPA_POD_Stringv(transport->path), + SPA_MONITOR_ITEM_class, &SPA_POD_Stringc("Adapter/Bluetooth"), + SPA_MONITOR_ITEM_factory, &SPA_POD_Pointer(SPA_TYPE_INTERFACE_HandleFactory, &spa_a2dp_sink_factory), + 0); + spa_pod_builder_prop(builder, SPA_MONITOR_ITEM_info, 0); + spa_pod_builder_push_struct(builder); snprintf(trans, sizeof(trans), "%p", transport); - spa_pod_builder_add(builder, - "s", "device.api", "s", "bluez5", - "s", "device.name", "s", transport->device->name, - "s", "device.icon", "s", transport->device->icon, - "s", "device.bluez5.address", "s", transport->device->address, - "s", "bluez5.transport", "s", trans, - NULL); + add_dict(builder, "device.api", "bluez5"); + add_dict(builder, "device.name", transport->device->name); + add_dict(builder, "device.icon", transport->device->icon); + add_dict(builder, "device.bluez5.address", transport->device->address); + add_dict(builder, "bluez5.transport", trans); - *result = spa_pod_builder_add(builder, "]}", NULL); + spa_pod_builder_pop(builder); + *result = spa_pod_builder_pop(builder); } static uint8_t a2dp_default_bitpool(struct spa_bt_monitor *monitor, uint8_t freq, uint8_t mode) { @@ -640,7 +646,7 @@ static struct spa_bt_node *node_create(struct spa_bt_monitor *monitor, struct sp struct spa_pod *item; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, SPA_MONITOR_EVENT_Added); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, SPA_MONITOR_EVENT_Added, 0); fill_item(monitor, transport, &item, &b); monitor->callbacks->event(monitor->callbacks_data, event); @@ -656,7 +662,7 @@ static struct spa_bt_node *node_destroy(struct spa_bt_monitor *monitor, struct s struct spa_pod *item; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, SPA_MONITOR_EVENT_Removed); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, SPA_MONITOR_EVENT_Removed, 0); fill_item(monitor, transport, &item, &b); monitor->callbacks->event(monitor->callbacks_data, event); diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index d48805292..aad3f1e9b 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -275,8 +275,10 @@ spa_ffmpeg_dec_node_port_enum_params(struct spa_node *node, SPA_PARAM_Format }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index 03eb619c8..66b99a497 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -264,8 +264,10 @@ spa_ffmpeg_enc_node_port_enum_params(struct spa_node *node, SPA_PARAM_Format }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c index 8377057c7..9600b4fe3 100644 --- a/spa/plugins/test/fakesink.c +++ b/spa/plugins/test/fakesink.c @@ -117,7 +117,8 @@ static int impl_node_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", SPA_PARAM_Props); + SPA_PARAM_LIST_id, &SPA_POD_Id(SPA_PARAM_Props), + 0); break; case SPA_PARAM_Props: if (*index > 0) @@ -125,7 +126,8 @@ static int impl_node_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_live, "b", this->props.live); + SPA_PROP_live, &SPA_POD_Bool(this->props.live), + 0); break; default: return -ENOENT; @@ -460,8 +462,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Meta }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -480,20 +484,21 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(1, 32), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", 128, - ":", SPA_PARAM_BUFFERS_stride, "i", 1, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, 32), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(128), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: switch (*index) { case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index 73fc00217..a19633375 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -121,8 +121,9 @@ static int impl_node_enum_params(struct spa_node *node, return 0; param = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", SPA_PARAM_Props); + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(SPA_PARAM_Props), + 0); break; case SPA_PARAM_Props: @@ -134,9 +135,9 @@ static int impl_node_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_live, "b", p->live, - ":", SPA_PROP_patternType, "Ie", p->pattern, - SPA_POD_PROP_ENUM(1, p->pattern)); + SPA_PROP_live, &SPA_POD_Bool(p->live), + SPA_PROP_patternType, &SPA_POD_CHOICE_ENUM_Id(2, p->pattern, p->pattern), + 0); break; } default: @@ -476,8 +477,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Meta }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -496,20 +499,21 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 32, - SPA_POD_PROP_MIN_MAX(2, 32), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", 128, - ":", SPA_PARAM_BUFFERS_stride, "i", 1, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(32, 2, 32), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(128), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: switch (*index) { case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index 1615b92b0..efc4b2de4 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -73,6 +73,12 @@ static int impl_udev_open(struct impl *this) return 0; } +static inline void add_dict(struct spa_pod_builder *builder, const char *key, const char *val) +{ + spa_pod_builder_string(builder, key); + spa_pod_builder_string(builder, val); +} + static void fill_item(struct impl *this, struct item *item, struct udev_device *udevice, struct spa_pod **result, struct spa_pod_builder *builder) { @@ -97,43 +103,43 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device * if (!(name && *name)) name = "Unknown"; - spa_pod_builder_add(builder, - "{", SPA_TYPE_OBJECT_MonitorItem, 0, - ":", SPA_MONITOR_ITEM_id, "s", udev_device_get_syspath(item->udevice), - ":", SPA_MONITOR_ITEM_flags, "I", SPA_MONITOR_ITEM_FLAG_NONE, - ":", SPA_MONITOR_ITEM_state, "I", SPA_MONITOR_ITEM_STATE_Available, - ":", SPA_MONITOR_ITEM_name, "s", name, - ":", SPA_MONITOR_ITEM_class, "s", "Video/Source", - ":", SPA_MONITOR_ITEM_factory, "p", SPA_TYPE_INTERFACE_HandleFactory, &spa_v4l2_source_factory, - ":", SPA_MONITOR_ITEM_info, "[", - NULL); + spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_MonitorItem, 0); + spa_pod_builder_props(builder, + SPA_MONITOR_ITEM_id, &SPA_POD_Stringv(udev_device_get_syspath(item->udevice)), + SPA_MONITOR_ITEM_flags, &SPA_POD_Id(SPA_MONITOR_ITEM_FLAG_NONE), + SPA_MONITOR_ITEM_state, &SPA_POD_Id(SPA_MONITOR_ITEM_STATE_Available), + SPA_MONITOR_ITEM_name, &SPA_POD_Stringv(name), + SPA_MONITOR_ITEM_class, &SPA_POD_Stringc("Video/Source"), + SPA_MONITOR_ITEM_factory, &SPA_POD_Pointer(SPA_TYPE_INTERFACE_HandleFactory, &spa_v4l2_source_factory), + 0); + + spa_pod_builder_prop(builder, SPA_MONITOR_ITEM_info, 0); + spa_pod_builder_push_struct(builder); + add_dict(builder, "udev-probed", "1"); + add_dict(builder, "device.api", "v4l2"); + add_dict(builder, "device.path", udev_device_get_devnode(item->udevice)); - spa_pod_builder_add(builder, - "s", "udev-probed", "s", "1", - "s", "device.api", "s", "v4l2", - "s", "device.path", "s", udev_device_get_devnode(item->udevice), - NULL); str = udev_device_get_property_value(item->udevice, "ID_PATH"); if (!(str && *str)) str = udev_device_get_syspath(item->udevice); if (str && *str) { - spa_pod_builder_add(builder, "s", "device.bus_path", "s", str, 0); + add_dict(builder, "device.bus_path", str); } if ((str = udev_device_get_syspath(item->udevice)) && *str) { - spa_pod_builder_add(builder, "s", "sysfs.path", "s", str, 0); + add_dict(builder, "sysfs.path", str); } if ((str = udev_device_get_property_value(item->udevice, "ID_ID")) && *str) { - spa_pod_builder_add(builder, "s", "udev.id", "s", str, 0); + add_dict(builder, "udev.id", str); } if ((str = udev_device_get_property_value(item->udevice, "ID_BUS")) && *str) { - spa_pod_builder_add(builder, "s", "device.bus", "s", str, 0); + add_dict(builder, "device.bus", str); } if ((str = udev_device_get_property_value(item->udevice, "SUBSYSTEM")) && *str) { - spa_pod_builder_add(builder, "s", "device.subsystem", "s", str, 0); + add_dict(builder, "device.subsystem", str); } if ((str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ID")) && *str) { - spa_pod_builder_add(builder, "s", "device.vendor.id", "s", str, 0); + add_dict(builder, "device.vendor.id", str); } str = udev_device_get_property_value(item->udevice, "ID_VENDOR_FROM_DATABASE"); if (!(str && *str)) { @@ -143,20 +149,21 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device * } } if (str && *str) { - spa_pod_builder_add(builder, "s", "device.vendor.name", "s", str, 0); + add_dict(builder, "device.vendor.name", str); } if ((str = udev_device_get_property_value(item->udevice, "ID_MODEL_ID")) && *str) { - spa_pod_builder_add(builder, "s", "device.product.id", "s", str, 0); + add_dict(builder, "device.product.id", str); } - spa_pod_builder_add(builder, "s", "device.product.name", "s", name, 0); + add_dict(builder, "device.product.name", name); if ((str = udev_device_get_property_value(item->udevice, "ID_SERIAL")) && *str) { - spa_pod_builder_add(builder, "s", "device.serial", "s", str, 0); + add_dict(builder, "device.serial", str); } if ((str = udev_device_get_property_value(item->udevice, "ID_V4L_CAPABILITIES")) && *str) { - spa_pod_builder_add(builder, "s", "device.capabilities", "s", str, 0); + add_dict(builder, "device.capabilities", str); } - *result = spa_pod_builder_add(builder, "]}", NULL); + spa_pod_builder_pop(builder); + *result = spa_pod_builder_pop(builder); } static void impl_on_fd_events(struct spa_source *source) @@ -187,7 +194,7 @@ static void impl_on_fd_events(struct spa_source *source) return; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id); + event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id, 0); fill_item(this, &this->uitem, dev, &item, &b); this->callbacks->event(this->callbacks_data, event); diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index c375acb90..0ba945403 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -164,8 +164,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -178,23 +180,26 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, - ":", SPA_PROP_INFO_name, "s", "The V4L2 device", - ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_device), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 device"), + SPA_PROP_INFO_type, &SPA_POD_Stringv(p->device), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, - ":", SPA_PROP_INFO_name, "s", "The V4L2 device name", - ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceName), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 device name"), + SPA_PROP_INFO_type, &SPA_POD_Stringv(p->device_name), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceFd, - ":", SPA_PROP_INFO_name, "s", "The V4L2 fd", - ":", SPA_PROP_INFO_type, "i-r", p->device_fd); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceFd), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 fd"), + SPA_PROP_INFO_type, &SPA_POD_Int(p->device_fd), + 0); break; default: return 0; @@ -209,9 +214,10 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_device, "S", p->device, sizeof(p->device), - ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), - ":", SPA_PROP_deviceFd, "i-r", p->device_fd); + SPA_PROP_device, &SPA_POD_Stringv(p->device), + SPA_PROP_deviceName, &SPA_POD_Stringv(p->device_name), + SPA_PROP_deviceFd, &SPA_POD_Int(p->device_fd), + 0); break; default: return 0; @@ -250,7 +256,7 @@ static int impl_node_set_param(struct spa_node *node, return 0; } spa_pod_object_parse(param, - ":", SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL); + SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL); break; } default: @@ -395,28 +401,31 @@ static int port_get_format(struct spa_node *node, return 0; spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_Format); - - spa_pod_builder_add(builder, - ":", SPA_FORMAT_mediaType, "I", port->current_format.media_type, - ":", SPA_FORMAT_mediaSubtype, "I", port->current_format.media_subtype, 0); + spa_pod_builder_props(builder, + SPA_FORMAT_mediaType, &SPA_POD_Id(port->current_format.media_type), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(port->current_format.media_subtype), + 0); switch (port->current_format.media_subtype) { case SPA_MEDIA_SUBTYPE_raw: - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_format, "I", port->current_format.info.raw.format, - ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.raw.size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.raw.framerate, 0); + spa_pod_builder_props(builder, + SPA_FORMAT_VIDEO_format, &SPA_POD_Id(port->current_format.info.raw.format), + SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.raw.size), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.raw.framerate), + 0); break; case SPA_MEDIA_SUBTYPE_mjpg: case SPA_MEDIA_SUBTYPE_jpeg: - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.mjpg.size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.mjpg.framerate, 0); + spa_pod_builder_props(builder, + SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.mjpg.size), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.mjpg.framerate), + 0); break; case SPA_MEDIA_SUBTYPE_h264: - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.h264.size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.h264.framerate, 0); + spa_pod_builder_props(builder, + SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.h264.size), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.h264.framerate), + 0); break; default: return -EIO; @@ -467,8 +476,10 @@ static int impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -491,12 +502,12 @@ static int impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", MAX_BUFFERS, - SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", port->fmt.fmt.pix.sizeimage, - ":", SPA_PARAM_BUFFERS_stride, "i", port->fmt.fmt.pix.bytesperline, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(MAX_BUFFERS, 2, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(port->fmt.fmt.pix.sizeimage), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->fmt.fmt.pix.bytesperline), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -504,8 +515,9 @@ static int impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -516,20 +528,23 @@ static int impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Clock, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Clock), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_clock)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; @@ -813,20 +828,19 @@ static int process_control(struct impl *this, struct port *port, struct spa_pod_ switch (c->type) { case SPA_CONTROL_Properties: { - struct spa_pod *pod; + struct spa_pod_prop *prop; struct spa_pod_object *obj = (struct spa_pod_object *) &c->value; - SPA_POD_OBJECT_FOREACH(obj, pod) { - struct spa_pod_prop *prop = (struct spa_pod_prop *)pod; + SPA_POD_OBJECT_FOREACH(obj, prop) { struct v4l2_control c; uint32_t control_id; - if ((control_id = prop_to_control_id(prop->body.key)) == 0) + if ((control_id = prop_to_control_id(prop->key)) == 0) continue; memset (&c, 0, sizeof (c)); c.id = control_id; - c.value = SPA_POD_VALUE(struct spa_pod_float, &prop->body.value); + c.value = SPA_POD_VALUE(struct spa_pod_float, &prop->value); if (ioctl(port->fd, VIDIOC_S_CTRL, &c) < 0) spa_log_error(port->log, "VIDIOC_S_CTRL %m"); diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index f77accea5..ed8b716ed 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -403,24 +403,26 @@ enum_filter_format(uint32_t media_type, int32_t media_subtype, case SPA_MEDIA_TYPE_image: if (media_subtype == SPA_MEDIA_SUBTYPE_raw) { struct spa_pod_prop *p; - uint32_t n_values; + const struct spa_pod *val; + uint32_t n_values, choice; const uint32_t *values; if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_format))) return SPA_VIDEO_FORMAT_UNKNOWN; - if (p->body.value.type != SPA_TYPE_Enum) + val = spa_pod_get_values(&p->value, &n_values, &choice); + + if (val->type != SPA_TYPE_Id) return SPA_VIDEO_FORMAT_UNKNOWN; - values = SPA_POD_BODY_CONST(&p->body.value); - n_values = SPA_POD_PROP_N_VALUES(p); + values = SPA_POD_BODY(val); - if (p->body.flags & SPA_POD_PROP_FLAG_UNSET) { - if (index + 1 < n_values) - video_format = values[index + 1]; - } else { + if (choice == SPA_CHOICE_None) { if (index == 0) video_format = values[0]; + } else { + if (index + 1 < n_values) + video_format = values[index + 1]; } } else { if (index == 0) @@ -527,7 +529,7 @@ spa_v4l2_enum_format(struct impl *this, struct port *port = &this->out_ports[0]; int res, n_fractions; const struct format_info *info; - struct spa_pod_prop *prop; + struct spa_pod_choice *choice; uint32_t filter_media_type, filter_media_subtype, video_format; if ((res = spa_v4l2_open(this)) < 0) @@ -590,18 +592,19 @@ spa_v4l2_enum_format(struct impl *this, while (port->next_frmsize) { if (filter) { struct spa_pod_prop *p; + struct spa_pod *val; + uint32_t n_vals, choice; /* check if we have a fixed frame size */ if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size))) goto do_frmsize; - if (p->body.value.type != SPA_TYPE_Rectangle) { + val = spa_pod_get_values(&p->value, &n_vals, &choice); + if (val->type != SPA_TYPE_Rectangle) goto enum_end; - } - if (!(p->body.flags & SPA_POD_PROP_FLAG_UNSET)) { - const struct spa_rectangle *values = - SPA_POD_BODY_CONST(&p->body.value); + if (choice == SPA_CHOICE_None) { + const struct spa_rectangle *values = SPA_POD_BODY(val); if (port->frmsize.index > 0) goto next_fmtdesc; @@ -623,25 +626,27 @@ spa_v4l2_enum_format(struct impl *this, } if (filter) { struct spa_pod_prop *p; + struct spa_pod *val; const struct spa_rectangle step = { 1, 1 }, *values; - uint32_t range; - uint32_t i, n_values; + uint32_t choice, i, n_values; /* check if we have a fixed frame size */ if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size))) goto have_size; - range = p->body.flags & SPA_POD_PROP_RANGE_MASK; - values = SPA_POD_BODY_CONST(&p->body.value); - n_values = SPA_POD_PROP_N_VALUES(p); + val = spa_pod_get_values(&p->value, &n_values, &choice); + if (val->type != SPA_TYPE_Rectangle) + goto have_size; - if (range == SPA_POD_PROP_RANGE_MIN_MAX && n_values > 2) { + values = SPA_POD_BODY_CONST(val); + + if (choice == SPA_CHOICE_Range && n_values > 2) { if (filter_framesize(&port->frmsize, &values[1], &values[2], &step)) goto have_size; - } else if (range == SPA_POD_PROP_RANGE_STEP && n_values > 3) { + } else if (choice == SPA_CHOICE_Step && n_values > 3) { if (filter_framesize(&port->frmsize, &values[1], &values[2], &values[3])) goto have_size; - } else if (range == SPA_POD_PROP_RANGE_ENUM) { + } else if (choice == SPA_CHOICE_Enum) { for (i = 1; i < n_values; i++) { if (filter_framesize(&port->frmsize, &values[i], &values[i], &step)) goto have_size; @@ -675,23 +680,24 @@ spa_v4l2_enum_format(struct impl *this, } spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); - spa_pod_builder_add(builder, - ":", SPA_FORMAT_mediaType, "I", info->media_type, - ":", SPA_FORMAT_mediaSubtype, "I", info->media_subtype, 0); + spa_pod_builder_props(builder, + SPA_FORMAT_mediaType, &SPA_POD_Id(info->media_type), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(info->media_subtype), + 0); if (info->media_subtype == SPA_MEDIA_SUBTYPE_raw) { - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_format, "I", info->format, 0); + spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_format, 0); + spa_pod_builder_id(builder, info->format); } - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width, - port->frmsize.discrete.height), 0); + spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_size, 0); + spa_pod_builder_rectangle(builder, port->frmsize.discrete.width, port->frmsize.discrete.height); + + spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_framerate, 0); - prop = spa_pod_builder_deref(builder, - spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_framerate, - SPA_POD_PROP_RANGE_NONE | SPA_POD_PROP_FLAG_UNSET)); n_fractions = 0; + choice = spa_pod_builder_deref(builder, + spa_pod_builder_push_choice(builder, SPA_CHOICE_None, 0)); port->frmival.index = 0; while (true) { @@ -709,34 +715,44 @@ spa_v4l2_enum_format(struct impl *this, } if (filter) { struct spa_pod_prop *p; - uint32_t range; - uint32_t i, n_values; + struct spa_pod *val; + uint32_t i, n_values, choice; const struct spa_fraction step = { 1, 1 }, *values; if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_framerate))) goto have_framerate; - if (p->body.value.type != SPA_TYPE_Fraction) + val = spa_pod_get_values(&p->value, &n_values, &choice); + + if (val->type != SPA_TYPE_Fraction) goto enum_end; - range = p->body.flags & SPA_POD_PROP_RANGE_MASK; - values = SPA_POD_BODY_CONST(&p->body.value); - n_values = SPA_POD_PROP_N_VALUES(p); + values = SPA_POD_BODY(val); - if (!(p->body.flags & SPA_POD_PROP_FLAG_UNSET)) { + switch (choice) { + case SPA_CHOICE_None: if (filter_framerate(&port->frmival, &values[0], &values[0], &step)) goto have_framerate; - } else if (range == SPA_POD_PROP_RANGE_MIN_MAX && n_values > 2) { - if (filter_framerate(&port->frmival, &values[1], &values[2], &step)) + break; + + case SPA_CHOICE_Range: + if (n_values > 2 && filter_framerate(&port->frmival, &values[1], &values[2], &step)) goto have_framerate; - } else if (range == SPA_POD_PROP_RANGE_STEP && n_values > 3) { - if (filter_framerate(&port->frmival, &values[1], &values[2], &values[3])) + break; + + case SPA_CHOICE_Step: + if (n_values > 3 && filter_framerate(&port->frmival, &values[1], &values[2], &values[3])) goto have_framerate; - } else if (range == SPA_POD_PROP_RANGE_ENUM) { + break; + + case SPA_CHOICE_Enum: for (i = 1; i < n_values; i++) { if (filter_framerate(&port->frmival, &values[i], &values[i], &step)) goto have_framerate; } + break; + default: + break; } port->frmival.index++; continue; @@ -745,7 +761,7 @@ spa_v4l2_enum_format(struct impl *this, have_framerate: if (port->frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) { - prop->body.flags |= SPA_POD_PROP_RANGE_ENUM; + choice->body.type = SPA_CHOICE_Enum; if (n_fractions == 0) spa_pod_builder_fraction(builder, port->frmival.discrete.denominator, @@ -766,9 +782,9 @@ spa_v4l2_enum_format(struct impl *this, port->frmival.stepwise.max.numerator); if (port->frmival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) { - prop->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX; + choice->body.type = SPA_CHOICE_Range; } else { - prop->body.flags |= SPA_POD_PROP_RANGE_STEP; + choice->body.type = SPA_CHOICE_Step; spa_pod_builder_fraction(builder, port->frmival.stepwise.step.denominator, port->frmival.stepwise.step.numerator); @@ -780,9 +796,9 @@ spa_v4l2_enum_format(struct impl *this, } n_fractions++; } - if (n_fractions <= 1) { - prop->body.flags &= ~(SPA_POD_PROP_RANGE_MASK | SPA_POD_PROP_FLAG_UNSET); - } + if (n_fractions <= 1) + choice->body.type = SPA_CHOICE_None; + spa_pod_builder_pop(builder); *result = spa_pod_builder_pop(builder); @@ -1052,35 +1068,38 @@ spa_v4l2_enum_controls(struct impl *this, case V4L2_CTRL_TYPE_INTEGER: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, - ":", SPA_PROP_INFO_id, "I", prop_id, - ":", SPA_PROP_INFO_type, "isu", queryctrl.default_value, - SPA_POD_PROP_STEP(queryctrl.minimum, - queryctrl.maximum, - queryctrl.step), - ":", SPA_PROP_INFO_name, "s", queryctrl.name); + SPA_PROP_INFO_id, &SPA_POD_Id(prop_id), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_STEP_Int( + queryctrl.default_value, + queryctrl.minimum, + queryctrl.maximum, + queryctrl.step), + SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name), + 0); break; case V4L2_CTRL_TYPE_BOOLEAN: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo, - ":", SPA_PROP_INFO_id, "I", prop_id, - ":", SPA_PROP_INFO_type, "b-u", queryctrl.default_value, - ":", SPA_PROP_INFO_name, "s", queryctrl.name); + SPA_PROP_INFO_id, &SPA_POD_Id(prop_id), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_Bool(queryctrl.default_value), + SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name), + 0); break; case V4L2_CTRL_TYPE_MENU: { struct v4l2_querymenu querymenu; spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo); - spa_pod_builder_add(&b, - ":", SPA_PROP_INFO_id, "I", prop_id, - ":", SPA_PROP_INFO_type, "i-u", queryctrl.default_value, - ":", SPA_PROP_INFO_name, "s", queryctrl.name, - NULL); + spa_pod_builder_props(&b, + SPA_PROP_INFO_id, &SPA_POD_Id(prop_id), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_ENUM_Int(1, queryctrl.default_value), + SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name), + 0); spa_zero(querymenu); querymenu.id = queryctrl.id; - spa_pod_builder_push_prop(&b, SPA_PROP_INFO_labels, 0); + spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0); spa_pod_builder_push_struct(&b); for (querymenu.index = queryctrl.minimum; querymenu.index <= queryctrl.maximum; @@ -1091,7 +1110,6 @@ spa_v4l2_enum_controls(struct impl *this, } } spa_pod_builder_pop(&b); - spa_pod_builder_pop(&b); param = spa_pod_builder_pop(&b); break; } diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index aeabc05c3..fde0e3369 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -132,7 +132,8 @@ static int impl_node_enum_params(struct spa_node *node, if (*index < SPA_N_ELEMENTS(list)) param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -145,19 +146,26 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_live, - ":", SPA_PROP_INFO_name, "s", "Configure live mode of the source", - ":", SPA_PROP_INFO_type, "b", p->live); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_live), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Configure live mode of the source"), + SPA_PROP_INFO_type, &SPA_POD_Bool(p->live), + 0); break; case 1: - param = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_patternType, - ":", SPA_PROP_INFO_name, "s", "The pattern", - ":", SPA_PROP_INFO_type, "i", p->pattern, - ":", SPA_PROP_INFO_labels, "[-i", - "i", PATTERN_SMPTE_SNOW, "s", "SMPTE snow", - "i", PATTERN_SNOW, "s", "Snow", "]"); + spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_PropInfo, id); + spa_pod_builder_props(&b, + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_patternType), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The pattern"), + SPA_PROP_INFO_type, &SPA_POD_Int(p->pattern), + 0); + spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, SPA_POD_PROP_FLAG_INFO), + spa_pod_builder_push_struct(&b); + spa_pod_builder_int(&b, PATTERN_SMPTE_SNOW); + spa_pod_builder_string(&b, "SMPTE snow"); + spa_pod_builder_int(&b, PATTERN_SNOW); + spa_pod_builder_string(&b, "Snow"); + spa_pod_builder_pop(&b); + param = spa_pod_builder_pop(&b); break; default: return 0; @@ -172,8 +180,9 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_live, "b", p->live, - ":", SPA_PROP_patternType, "i", p->pattern); + SPA_PROP_live, &SPA_POD_Bool(p->live), + SPA_PROP_patternType, &SPA_POD_Int(p->pattern), + 0); break; default: return 0; @@ -464,17 +473,21 @@ static int port_enum_formats(struct spa_node *node, case 0: *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_video, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "Ieu", SPA_VIDEO_FORMAT_RGB, - SPA_POD_PROP_ENUM(2, SPA_VIDEO_FORMAT_RGB, - SPA_VIDEO_FORMAT_UYVY), - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320, 240), - SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1, 1), - &SPA_RECTANGLE(INT32_MAX, INT32_MAX)), - ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), - SPA_POD_PROP_MIN_MAX(&SPA_FRACTION(0, 1), - &SPA_FRACTION(INT32_MAX, 1))); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_video), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_VIDEO_format, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_VIDEO_FORMAT_RGB, + SPA_VIDEO_FORMAT_RGB, + SPA_VIDEO_FORMAT_UYVY), + SPA_FORMAT_VIDEO_size, &SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(320, 240), + SPA_RECTANGLE(1, 1), + SPA_RECTANGLE(INT32_MAX, INT32_MAX)), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_CHOICE_RANGE_Fraction( + SPA_FRACTION(25,1), + SPA_FRACTION(0, 1), + SPA_FRACTION(INT32_MAX, 1)), + 0); break; default: return 0; @@ -516,8 +529,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Meta }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -547,12 +562,12 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", this->stride * raw_info->size.height, - ":", SPA_PARAM_BUFFERS_stride, "i", this->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(this->stride * raw_info->size.height), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(this->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; } case SPA_PARAM_Meta: @@ -563,8 +578,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 535c4bb95..b8255d707 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -125,8 +125,10 @@ static int impl_node_enum_params(struct spa_node *node, SPA_PARAM_Props }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -136,17 +138,18 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, - ":", SPA_PROP_INFO_name, "s", "The volume", - ":", SPA_PROP_INFO_type, "dr", p->volume, - SPA_POD_PROP_MIN_MAX(0.0, 10.0)); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_volume), + SPA_PROP_INFO_name, &SPA_POD_Stringc("The volume"), + SPA_PROP_INFO_type, &SPA_POD_CHOICE_RANGE_Float(p->volume, 0.0, 10.0), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_PropInfo, id, - ":", SPA_PROP_INFO_id, "I", SPA_PROP_mute, - ":", SPA_PROP_INFO_name, "s", "Mute", - ":", SPA_PROP_INFO_type, "b", p->mute); + SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_mute), + SPA_PROP_INFO_name, &SPA_POD_Stringc("Mute"), + SPA_PROP_INFO_type, &SPA_POD_Bool(p->mute), + 0); break; default: return 0; @@ -157,8 +160,9 @@ static int impl_node_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, id, - ":", SPA_PROP_volume, "d", p->volume, - ":", SPA_PROP_mute, "b", p->mute); + SPA_PROP_volume, &SPA_POD_Float(p->volume), + SPA_PROP_mute, &SPA_POD_Bool(p->mute), + 0); break; default: return 0; @@ -328,15 +332,15 @@ static int port_enum_formats(struct spa_node *node, case 0: *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32), - ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels,"iru", 2, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S32), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(2, 1, INT32_MAX), + 0); break; default: return 0; @@ -382,8 +386,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -410,21 +416,24 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * this->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * this->bpf, + 16 * this->bpf, + INT32_MAX / this->bpf), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: switch (*index) { case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -435,14 +444,16 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; default: return 0; diff --git a/spa/tests/meson.build b/spa/tests/meson.build index 0ff2eecc7..f67262494 100644 --- a/spa/tests/meson.build +++ b/spa/tests/meson.build @@ -52,10 +52,10 @@ executable('test-props2', 'test-props2.c', # include_directories : [spa_inc ], # dependencies : [], # install : false) -executable('test-props5', 'test-props5.c', - include_directories : [spa_inc ], - dependencies : [], - install : false) +#executable('test-props5', 'test-props5.c', +# include_directories : [spa_inc ], +# dependencies : [], +# install : false) executable('test-control', 'test-control.c', include_directories : [spa_inc ], dependencies : [dl_lib, pthread_lib, mathlib], diff --git a/spa/tests/test-control.c b/spa/tests/test-control.c index df8b2971b..e780766f9 100644 --- a/spa/tests/test-control.c +++ b/spa/tests/test-control.c @@ -199,13 +199,6 @@ static void update_props(struct data *data) spa_pod_builder_init(&b, data->ctrl, sizeof(data->ctrl)); -#if 1 - pod = spa_pod_builder_sequence(&b, 0, - ".", 0, SPA_CONTROL_Properties, - SPA_POD_OBJECT(SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_frequency, "d", ((sin(data->freq_accum) + 1.0) * 200.0) + 440.0, - ":", SPA_PROP_volume, "d", (sin(data->volume_accum) / 2.0) + 0.5)); -#endif #if 0 spa_pod_builder_push_sequence(&b, 0); spa_pod_builder_control_header(&b, 0, SPA_CONTROL_Properties); @@ -218,14 +211,14 @@ static void update_props(struct data *data) spa_pod_builder_pop(&b); spa_pod_builder_pop(&b); pod = spa_pod_builder_pop(&b); -#endif -#if 0 +#else spa_pod_builder_push_sequence(&b, 0); spa_pod_builder_control_header(&b, 0, SPA_CONTROL_Properties); spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_frequency, "d", ((sin(data->freq_accum) + 1.0) * 200.0) + 440.0, - ":", SPA_PROP_volume, "d", (sin(data->volume_accum) / 2.0) + 0.5); + SPA_PROP_frequency, &SPA_POD_Float(((sin(data->freq_accum) + 1.0) * 200.0) + 440.0), + SPA_PROP_volume, &SPA_POD_Float((sin(data->volume_accum) / 2.0) + 0.5), + 0); pod = spa_pod_builder_pop(&b); #endif @@ -311,8 +304,9 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_device, "s", device ? device : "hw:0", - ":", SPA_PROP_minLatency, "i", MIN_LATENCY); + SPA_PROP_device, &SPA_POD_Stringv(device ? device : "hw:0"), + SPA_PROP_minLatency, &SPA_POD_Int(MIN_LATENCY), + 0); spa_debug_pod(0, NULL, props); @@ -329,9 +323,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_frequency, "d", 600.0, - ":", SPA_PROP_volume, "d", 0.5, - ":", SPA_PROP_live, "b", false); + SPA_PROP_frequency, &SPA_POD_Float(600.0), + SPA_PROP_volume, &SPA_POD_Float(0.5), + SPA_PROP_live, &SPA_POD_Bool(false), + 0); if ((res = spa_node_set_param(data->source, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index 30e6bcb7a..6487a6729 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -258,8 +258,9 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_device, "s", device ? device : "hw:0", - ":", SPA_PROP_minLatency, "i", MIN_LATENCY); + SPA_PROP_device, &SPA_POD_Stringv(device ? device : "hw:0"), + SPA_PROP_minLatency, &SPA_POD_Int(MIN_LATENCY), + 0); spa_debug_pod(0, NULL, props); @@ -282,9 +283,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_frequency, "d", 600.0, - ":", SPA_PROP_volume, "d", 0.5, - ":", SPA_PROP_live, "b", false); + SPA_PROP_frequency, &SPA_POD_Float(600.0), + SPA_PROP_volume, &SPA_POD_Float(0.5), + SPA_PROP_live, &SPA_POD_Bool(false), + 0); if ((res = spa_node_set_param(data->source, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 3efe8af75..1998a10ed 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -320,8 +320,9 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_device, "s", device ? device : "hw:0", - ":", SPA_PROP_minLatency, "i", MIN_LATENCY); + SPA_PROP_device, &SPA_POD_Stringv(device ? device : "hw:0"), + SPA_PROP_minLatency, &SPA_POD_Int(MIN_LATENCY), + 0); if ((res = spa_node_set_param(data->sink, SPA_PARAM_Props, 0, props)) < 0) error(0, -res, "set_param props"); @@ -343,9 +344,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, SPA_PARAM_Props, - ":", SPA_PROP_frequency, "d", 600.0, - ":", SPA_PROP_volume, "d", 1.0, - ":", SPA_PROP_live, "b", false); + SPA_PROP_frequency, &SPA_POD_Float(600.0), + SPA_PROP_volume, &SPA_POD_Float(1.0), + SPA_PROP_live, &SPA_POD_Bool(false), + 0); if ((res = spa_node_set_param(data->source1, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); @@ -360,9 +362,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, SPA_PARAM_Props, - ":", SPA_PROP_frequency, "d", 440.0, - ":", SPA_PROP_volume, "d", 1.0, - ":", SPA_PROP_live, "b", false); + SPA_PROP_frequency, &SPA_POD_Float(440.0), + SPA_PROP_volume, &SPA_POD_Float(1.0), + SPA_PROP_live, &SPA_POD_Bool(false), + 0); if ((res = spa_node_set_param(data->source2, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); @@ -404,8 +407,8 @@ static int make_nodes(struct data *data, const char *device) SPA_IO_Buffers, &data->mix_sink_io[0], sizeof(data->mix_sink_io[0])); - data->ctrl_volume[0] = SPA_POD_DOUBLE_INIT(0.5); - data->ctrl_volume[1] = SPA_POD_DOUBLE_INIT(0.5); + data->ctrl_volume[0] = SPA_POD_Double(0.5); + data->ctrl_volume[1] = SPA_POD_Double(0.5); #if 0 if ((res = spa_node_port_set_io(data->mix, diff --git a/spa/tests/test-perf.c b/spa/tests/test-perf.c index debf97d9c..6a49d76ad 100644 --- a/spa/tests/test-perf.c +++ b/spa/tests/test-perf.c @@ -360,8 +360,9 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Format, 0, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_binary, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_binary), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + 0); if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, diff --git a/spa/tests/test-props.c b/spa/tests/test-props.c index ae8160220..08e06247e 100644 --- a/spa/tests/test-props.c +++ b/spa/tests/test-props.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -147,21 +148,38 @@ key: "" } ] + ( "Format", + ("video", "raw" ), + { + "format": ( "seu", "I420", ( "I420","YUY2" ) ), + "size": ( "Rru", (320, 242), ( (1,1), (MAX, MAX)) ), + "framerate": ( "Fru", (25, 1), ( (0,1), (MAX, 1)) ) + } + ) + + { "Type" : "Format", "Id" : 0, + "mediaType": "video", + "mediaSubtype": "raw", + "videoFormat": [ "enum", "I420", "YUY2" ], + "videoSize": [ "range", [320,242], [1,1], [MAX,MAX] ], + "videoFramerate": [ "range", [25,1], [0,1], [MAX,1] ] + } + spa_build(SPA_MEDIA_TYPE_VIDEO, SPA_MEDIA_SUBTYPE_RAW, SPA_FORMAT_VIDEO_format, SPA_PROP_TYPE_ID, video_format.I420 SPA_POD_PROP_FLAG_UNSET | - SPA_PROP_RANGE_ENUM, 2, + SPA_CHOICE_ENUM, 2, video_format.I420, video_format.YUY2, SPA_FORMAT_VIDEO_size, SPA_PROP_TYPE_RECTANGLE, 320, 240, SPA_POD_PROP_FLAG_UNSET | - SPA_PROP_RANGE_MIN_MAX, + SPA_CHOICE_RANGE, 1, 1, INT32_MAX, INT32_MAX, SPA_FORMAT_VIDEO_framerate, SPA_PROP_TYPE_FRACTION, 25, 1, - SPA_POD_PROP_FLAG_UNSET | SPA_PROP_RANGE_MIN_MAX, 0, 1, INT32_MAX, 1, 0); + SPA_POD_PROP_FLAG_UNSET | SPA_CHOICE_RANGE, 0, 1, INT32_MAX, 1, 0); #endif static void do_static_struct(void) @@ -170,17 +188,22 @@ static void do_static_struct(void) struct spa_pod_object fmt; struct { - struct spa_pod_enum media_type SPA_ALIGNED(8); - struct spa_pod_enum media_subtype SPA_ALIGNED(8); + struct spa_pod_prop prop_media_type SPA_ALIGNED(8); + uint32_t media_type; + + struct spa_pod_prop prop_media_subtype SPA_ALIGNED(8); + uint32_t media_subtype; struct spa_pod_prop prop_format SPA_ALIGNED(8); struct { + struct spa_pod_choice_body choice; uint32_t def_format; uint32_t enum_format[2]; } format_vals; struct spa_pod_prop prop_size SPA_ALIGNED(8); struct { + struct spa_pod_choice_body choice; struct spa_rectangle def_size; struct spa_rectangle min_size; struct spa_rectangle max_size; @@ -188,43 +211,46 @@ static void do_static_struct(void) struct spa_pod_prop prop_framerate SPA_ALIGNED(8); struct { + struct spa_pod_choice_body array; struct spa_fraction def_framerate; struct spa_fraction min_framerate; struct spa_fraction max_framerate; } framerate_vals; } props; } test_format = { - SPA_POD_OBJECT_INIT(sizeof(test_format.props) + sizeof(struct spa_pod_object_body), + SPA_POD_Object(sizeof(test_format.props) + sizeof(struct spa_pod_object_body), SPA_TYPE_OBJECT_Format, 0), { - SPA_POD_ENUM_INIT(SPA_MEDIA_TYPE_video), - SPA_POD_ENUM_INIT(SPA_MEDIA_SUBTYPE_raw), + SPA_POD_Prop(SPA_FORMAT_mediaType, 0, + sizeof(test_format.props.media_type), SPA_TYPE_Id), + SPA_MEDIA_TYPE_video, - SPA_POD_PROP_INIT(sizeof(test_format.props.format_vals) + - sizeof(struct spa_pod_prop_body), - SPA_FORMAT_VIDEO_format, - SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET, - sizeof(uint32_t), SPA_TYPE_Enum), + SPA_POD_Prop(SPA_FORMAT_mediaSubtype, 0, + sizeof(test_format.props.media_subtype), SPA_TYPE_Id), + SPA_MEDIA_SUBTYPE_raw, + + SPA_POD_Prop(SPA_FORMAT_VIDEO_format, 0, + sizeof(test_format.props.format_vals), SPA_TYPE_Choice), { + SPA_POD_CHOICE_BODY_INIT(SPA_CHOICE_Enum, 0, + sizeof(uint32_t), SPA_TYPE_Id), SPA_VIDEO_FORMAT_I420, { SPA_VIDEO_FORMAT_I420, SPA_VIDEO_FORMAT_YUY2 } }, - SPA_POD_PROP_INIT(sizeof(test_format.props.size_vals) + - sizeof(struct spa_pod_prop_body), - SPA_FORMAT_VIDEO_size, - SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET, - sizeof(struct spa_rectangle), SPA_TYPE_Rectangle), + SPA_POD_Prop(SPA_FORMAT_VIDEO_size, 0, + sizeof(test_format.props.size_vals), SPA_TYPE_Choice), { + SPA_POD_CHOICE_BODY_INIT(SPA_CHOICE_Range, 0, + sizeof(struct spa_rectangle), SPA_TYPE_Rectangle), SPA_RECTANGLE(320,243), SPA_RECTANGLE(1,1), SPA_RECTANGLE(INT32_MAX, INT32_MAX) }, - SPA_POD_PROP_INIT(sizeof(test_format.props.framerate_vals) + - sizeof(struct spa_pod_prop_body), - SPA_FORMAT_VIDEO_framerate, - SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET, - sizeof(struct spa_fraction), SPA_TYPE_Fraction), + SPA_POD_Prop(SPA_FORMAT_VIDEO_framerate, 0, + sizeof(test_format.props.framerate_vals), SPA_TYPE_Choice), { + SPA_POD_CHOICE_BODY_INIT(SPA_CHOICE_Range, 0, + sizeof(struct spa_fraction), SPA_TYPE_Fraction), SPA_FRACTION(25,1), SPA_FRACTION(0,1), SPA_FRACTION(INT32_MAX,1) } @@ -256,106 +282,170 @@ static void do_static_struct(void) } + +#define ITER 10000000 + int main(int argc, char *argv[]) { struct spa_pod_builder b = { NULL, }; uint8_t buffer[1024]; struct spa_pod_object *fmt; + int i; + struct timespec ts1, ts2; + fprintf(stderr, "build 1: "); + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (i = 0 ; i < ITER; i++) { spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Format, 0); - spa_pod_builder_enum(&b, SPA_MEDIA_TYPE_video); - spa_pod_builder_enum(&b, SPA_MEDIA_SUBTYPE_raw); + spa_pod_builder_prop(&b, SPA_FORMAT_mediaType, 0); + spa_pod_builder_id(&b, SPA_MEDIA_TYPE_video); + spa_pod_builder_prop(&b, SPA_FORMAT_mediaSubtype, 0); + spa_pod_builder_id(&b, SPA_MEDIA_SUBTYPE_raw); - spa_pod_builder_push_prop(&b, SPA_FORMAT_VIDEO_format, - SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET); - spa_pod_builder_enum(&b, SPA_VIDEO_FORMAT_I420); - spa_pod_builder_enum(&b, SPA_VIDEO_FORMAT_I420); - spa_pod_builder_enum(&b, SPA_VIDEO_FORMAT_YUY2); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_format, 0); + spa_pod_builder_push_choice(&b, SPA_CHOICE_Enum, 0); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_I420); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_I420); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_YUY2); spa_pod_builder_pop(&b); struct spa_rectangle size_min_max[] = { {1, 1}, {INT32_MAX, INT32_MAX} }; - spa_pod_builder_push_prop(&b, - SPA_FORMAT_VIDEO_size, - SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_size, 0); + spa_pod_builder_push_choice(&b, SPA_CHOICE_Range, 0); spa_pod_builder_rectangle(&b, 320, 240); spa_pod_builder_raw(&b, size_min_max, sizeof(size_min_max)); spa_pod_builder_pop(&b); struct spa_fraction rate_min_max[] = { {0, 1}, {INT32_MAX, 1} }; - spa_pod_builder_push_prop(&b, - SPA_FORMAT_VIDEO_framerate, - SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_framerate, 0); + spa_pod_builder_push_choice(&b, SPA_CHOICE_Range, 0); spa_pod_builder_fraction(&b, 25, 1); spa_pod_builder_raw(&b, rate_min_max, sizeof(rate_min_max)); spa_pod_builder_pop(&b); fmt = spa_pod_builder_pop(&b); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); - + fprintf(stderr, "build 2: "); + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (i = 0 ; i < ITER; i++) { spa_pod_builder_init(&b, buffer, sizeof(buffer)); - fmt = spa_pod_builder_object(&b, + fmt = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, 0, ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_video, ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "Ieu", SPA_VIDEO_FORMAT_I420, - 2, SPA_VIDEO_FORMAT_I420, - SPA_VIDEO_FORMAT_YUY2, - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320,241), - 2, &SPA_RECTANGLE(1,1), - &SPA_RECTANGLE(INT32_MAX,INT32_MAX), - ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), - 2, &SPA_FRACTION(0,1), - &SPA_FRACTION(INT32_MAX,1)); + ":", SPA_FORMAT_VIDEO_format, "?eI", 3, SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_YUY2, + ":", SPA_FORMAT_VIDEO_size, "?rR", 3, &SPA_RECTANGLE(320,241), + &SPA_RECTANGLE(1,1), + &SPA_RECTANGLE(INT32_MAX,INT32_MAX), + ":", SPA_FORMAT_VIDEO_framerate, "?rF", 3, &SPA_FRACTION(25,1), + &SPA_FRACTION(0,1), + &SPA_FRACTION(INT32_MAX,1)); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); + fprintf(stderr, "build 3: "); + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (i = 0 ; i < ITER; i++) { spa_pod_builder_init(&b, buffer, sizeof(buffer)); - /* - * ( "Format", - * ("video", "raw" ), - * { - * "format": ( "seu", "I420", ( "I420","YUY2" ) ), - * "size": ( "Rru", (320, 242), ( (1,1), (MAX, MAX)) ), - * "framerate": ( "Fru", (25, 1), ( (0,1), (MAX, 1)) ) - * } - * ) - * - * { "Type" : "Format", "Id" : 0, - * "mediaType": "video", - * "mediaSubtype": "raw", - * "videoFormat": [ "enum", "I420", "YUY2" ], - * "videoSize": [ "range", [320,242], [1,1], [MAX,MAX] ], - * "videoFramerate": [ "range", [25,1], [0,1], [MAX,1] ] - * } - * - */ fmt = spa_pod_builder_add(&b, "{", SPA_TYPE_OBJECT_Format, 0, ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_video, ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "Ieu", SPA_VIDEO_FORMAT_I420, - 2, SPA_VIDEO_FORMAT_I420, - SPA_VIDEO_FORMAT_YUY2, - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320,242), - 2, &SPA_RECTANGLE(1,1), - &SPA_RECTANGLE(INT32_MAX,INT32_MAX), - ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), - 2, &SPA_FRACTION(0,1), - &SPA_FRACTION(INT32_MAX,1), + ":", SPA_FORMAT_VIDEO_format, "P", &SPA_POD_CHOICE_ENUM_Id(3, + SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_YUY2), + ":", SPA_FORMAT_VIDEO_size, "P", &SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(320,242), + SPA_RECTANGLE(1,1), + SPA_RECTANGLE(INT32_MAX,INT32_MAX)), + ":", SPA_FORMAT_VIDEO_framerate, "P", &SPA_POD_CHOICE_RANGE_Fraction( + SPA_FRACTION(25,1), + SPA_FRACTION(0,1), + SPA_FRACTION(INT32_MAX,1)), "}", NULL); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); do_static_struct(); + fprintf(stderr, "build 4: "); + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (i = 0 ; i < ITER; i++) { + spa_pod_builder_init(&b, buffer, sizeof(buffer)); + spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Format, 0); + spa_pod_builder_prop(&b, SPA_FORMAT_mediaType, 0); + spa_pod_builder_id(&b, SPA_MEDIA_TYPE_video); + spa_pod_builder_prop(&b, SPA_FORMAT_mediaSubtype, 0); + spa_pod_builder_id(&b, SPA_MEDIA_SUBTYPE_raw); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_format, 0); + spa_pod_builder_primitive(&b, (struct spa_pod*)&SPA_POD_CHOICE_ENUM_Id(3, + SPA_VIDEO_FORMAT_I420, SPA_VIDEO_FORMAT_I420, SPA_VIDEO_FORMAT_YUY2)); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_size, 0); + spa_pod_builder_primitive(&b, (struct spa_pod*)&SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(320,242), + SPA_RECTANGLE(1,1), + SPA_RECTANGLE(INT32_MAX,INT32_MAX))); + spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_framerate, 0); + spa_pod_builder_primitive(&b, (struct spa_pod *)&SPA_POD_CHOICE_RANGE_Fraction( + SPA_FRACTION(25,1), + SPA_FRACTION(0,1), + SPA_FRACTION(INT32_MAX,1))); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + + fmt = spa_pod_builder_pop(&b); + + spa_debug_pod(0, NULL, &fmt->pod); + spa_debug_format(0, NULL, &fmt->pod); + + fprintf(stderr, "build 5: "); + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (i = 0 ; i < ITER; i++) { + spa_pod_builder_init(&b, buffer, sizeof(buffer)); + fmt = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_Format, 0, + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_video), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_VIDEO_format, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_YUY2), + SPA_FORMAT_VIDEO_size, &SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(320,242), + SPA_RECTANGLE(1,1), + SPA_RECTANGLE(INT32_MAX,INT32_MAX)), + SPA_FORMAT_VIDEO_framerate,&SPA_POD_CHOICE_RANGE_Fraction( + SPA_FRACTION(25,1), + SPA_FRACTION(0,1), + SPA_FRACTION(INT32_MAX,1)), + 0); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + + spa_debug_pod(0, NULL, &fmt->pod); + spa_debug_format(0, NULL, &fmt->pod); #if 0 printf("media type is enum %d\n", spa_type_is_a(SPA_TYPE__mediaType, SPA_TYPE_ENUM_BASE)); printf("media sybtype is enum %d\n", diff --git a/spa/tests/test-props2.c b/spa/tests/test-props2.c index e74c2ea13..a5a5bb479 100644 --- a/spa/tests/test-props2.c +++ b/spa/tests/test-props2.c @@ -46,24 +46,24 @@ int main(int argc, char *argv[]) spa_pod_builder_push_object(&b, 0, 0); uint32_t formats[] = { 1, 2 }; - spa_pod_builder_push_prop(&b, 1, SPA_POD_PROP_RANGE_ENUM); + spa_pod_builder_prop(&b, 1, 0); + spa_pod_builder_push_array(&b); spa_pod_builder_int(&b, 1); spa_pod_builder_int(&b, formats[0]); spa_pod_builder_int(&b, formats[1]); spa_pod_builder_pop(&b); - spa_pod_builder_push_prop(&b, 2, 0); + spa_pod_builder_prop(&b, 2, 0); spa_pod_builder_int(&b, 42); - spa_pod_builder_pop(&b); struct spa_rectangle sizes[] = { {0, 0}, {1024, 1024} }; - spa_pod_builder_push_prop(&b, - 3, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET); + spa_pod_builder_prop(&b, 3, 0); + spa_pod_builder_push_array(&b); spa_pod_builder_rectangle(&b, 320, 240); spa_pod_builder_raw(&b, sizes, sizeof(sizes)); spa_pod_builder_pop(&b); - spa_pod_builder_push_prop(&b, 4, SPA_POD_PROP_FLAG_READONLY); + spa_pod_builder_prop(&b, 4, SPA_POD_PROP_FLAG_READONLY); ref = spa_pod_builder_push_struct(&b); spa_pod_builder_int(&b, 4); spa_pod_builder_long(&b, 6000); @@ -78,14 +78,12 @@ int main(int argc, char *argv[]) spa_pod_builder_int(&b, 6); spa_pod_builder_pop(&b); spa_pod_builder_pop(&b); - spa_pod_builder_pop(&b); obj = spa_pod_builder_pop(&b); spa_debug_pod(0, NULL, obj); struct spa_pod_prop *p = spa_pod_find_prop(obj, 4); - printf("%d %d\n", p->body.key, p->body.flags); - spa_debug_pod(0, NULL, &p->body.value); + spa_debug_pod(0, NULL, &p->value); obj = spa_pod_builder_deref(&b, ref); diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index aa7bf3b42..4a67258de 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -237,8 +237,9 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_device, "s", device ? device : "hw:0", - ":", SPA_PROP_minLatency, "i", 64); + SPA_PROP_device, &SPA_POD_Stringv(device ? device : "hw:0"), + SPA_PROP_minLatency, &SPA_POD_Int(64), + 0); if ((res = spa_node_set_param(data->sink, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); @@ -253,7 +254,8 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_live, "b", false); + SPA_PROP_live, &SPA_POD_Bool(false), + 0); if ((res = spa_node_set_param(data->source, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index 83cf4aba5..ff8a5acba 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -289,7 +289,8 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_device, "s", device ? device : "/dev/video0"); + SPA_PROP_device, &SPA_POD_Stringv(device ? device : "/dev/video0"), + 0); if ((res = spa_node_set_param(data->source, SPA_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c index ed56b9e10..ab0cbd1b0 100644 --- a/src/examples/export-sink.c +++ b/src/examples/export-sink.c @@ -112,10 +112,13 @@ static void update_param(struct data *data) return; spa_pod_builder_init(&b, data->io_notify, data->io_notify_size); - spa_pod_builder_sequence(&b, 0, - ".", 0, SPA_CONTROL_Properties, - SPA_POD_OBJECT(SPA_TYPE_OBJECT_Props, 0, - ":", SPA_PROP_contrast, "f", (sin(data->param_accum) * 127.0) + 127.0)); + spa_pod_builder_push_sequence(&b, 0); + spa_pod_builder_control_header(&b, 0, SPA_CONTROL_Properties); + spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Props, 0); + spa_pod_builder_prop(&b, SPA_PROP_contrast, 0); + spa_pod_builder_float(&b, (sin(data->param_accum) * 127.0) + 127.0); + spa_pod_builder_pop(&b); + spa_pod_builder_pop(&b); data->param_accum += M_PI_M2 / 30.0; if (data->param_accum >= M_PI_M2) @@ -235,7 +238,8 @@ static int impl_port_enum_params(struct spa_node *node, if (*index < SPA_N_ELEMENTS(list)) param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -255,12 +259,12 @@ static int impl_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 2, - SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", d->stride * d->format.size.height, - ":", SPA_PARAM_BUFFERS_stride, "i", d->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 2, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(d->stride * d->format.size.height), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(d->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -268,14 +272,16 @@ static int impl_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; case 1: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_VideoDamage, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_region)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_VideoDamage), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_region)), + 0); break; default: return 0; @@ -287,14 +293,16 @@ static int impl_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Notify, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence) + 1024); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Notify), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence) + 1024), + 0); break; default: return 0; diff --git a/src/examples/export-source.c b/src/examples/export-source.c index 2f11523f6..8b5f893d2 100644 --- a/src/examples/export-source.c +++ b/src/examples/export-source.c @@ -33,17 +33,6 @@ #define BUFFER_SAMPLES 128 -#define DEFAULT_VOLUME 1.0 - -struct props { - double volume; -}; - -static void reset_props(struct props *props) -{ - props->volume = DEFAULT_VOLUME; -} - struct buffer { struct spa_buffer *buffer; struct spa_list link; @@ -52,8 +41,6 @@ struct buffer { }; struct data { - struct props props; - const char *path; struct pw_main_loop *loop; @@ -72,8 +59,8 @@ struct data { const struct spa_node_callbacks *callbacks; void *callbacks_data; struct spa_io_buffers *io; - - struct spa_pod_double *ctrl_volume; + struct spa_io_control *io_notify; + uint32_t io_notify_size; struct spa_audio_info_raw format; @@ -87,10 +74,20 @@ struct data { static void update_volume(struct data *data) { - if (data->ctrl_volume == NULL) + struct spa_pod_builder b = { 0, }; + + if (data->io_notify == NULL) return; - data->ctrl_volume->value = (sin(data->volume_accum) / 2.0) + 0.5; + spa_pod_builder_init(&b, data->io_notify, data->io_notify_size); + spa_pod_builder_push_sequence(&b, 0); + spa_pod_builder_control_header(&b, 0, SPA_CONTROL_Properties); + spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Props, 0); + spa_pod_builder_prop(&b, SPA_PROP_volume, 0); + spa_pod_builder_float(&b, (sin(data->volume_accum) / 2.0) + 0.5); + spa_pod_builder_pop(&b); + spa_pod_builder_pop(&b); + data->volume_accum += M_PI_M2 / 1000.0; if (data->volume_accum >= M_PI_M2) data->volume_accum -= M_PI_M2; @@ -137,19 +134,17 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, { struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); - if (id == SPA_IO_Buffers) + switch (id) { + case SPA_IO_Buffers: d->io = data; -#if 0 - else if (id == type.io_prop_volume) { - if (data && size >= sizeof(struct spa_pod_double)) - d->ctrl_volume = data; - else - d->ctrl_volume = NULL; - } -#endif - else + break; + case SPA_IO_Notify: + d->io_notify = data; + d->io_notify_size = size; + break; + default: return -ENOENT; - + } return 0; } @@ -182,18 +177,19 @@ static int port_enum_formats(struct spa_node *node, *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_F32), - ":", SPA_FORMAT_AUDIO_layout, "Ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, - SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", SPA_FORMAT_AUDIO_channels, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_CHOICE_ENUM_Id(3, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_channels, &SPA_POD_CHOICE_RANGE_Int(2, 1, INT32_MAX), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX), + 0); (*index)++; @@ -222,7 +218,8 @@ static int impl_port_enum_params(struct spa_node *node, if (*index < SPA_N_ELEMENTS(list)) param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -244,13 +241,12 @@ static int impl_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, 32), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", BUFFER_SAMPLES * sizeof(float), - SPA_POD_PROP_MIN_MAX(32, 4096), - ":", SPA_PARAM_BUFFERS_stride, "i", 0, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, 32), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int(BUFFER_SAMPLES * sizeof(float), 32, 4096), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(0), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -258,8 +254,9 @@ static int impl_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -270,32 +267,21 @@ static int impl_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); + break; + case 1: + param = spa_pod_builder_object(builder, + SPA_TYPE_OBJECT_ParamIO, id, + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Notify), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence) + 1024), + 0); break; default: return 0; } break; -#if 0 - else if (id == t->param_io.idPropsOut) { - struct props *p = &d->props; - - switch (*index) { - case 0: - param = spa_pod_builder_object(builder, - id, t->param_io.Prop, - ":", t->param_io.id, "I", d->type.io_prop_volume, - ":", t->param_io.size, "i", sizeof(struct spa_pod_double), - ":", t->param.propId, "I", d->type.prop_volume, - ":", t->param.propType, "dru", p->volume, - SPA_POD_PROP_MIN_MAX(0.0, 10.0)); - break; - default: - return 0; - } - } -#endif default: return -ENOENT; } @@ -554,7 +540,6 @@ int main(int argc, char *argv[]) data.path = argc > 1 ? argv[1] : NULL; spa_list_init(&data.empty); - reset_props(&data.props); pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data); diff --git a/src/examples/local-v4l2.c b/src/examples/local-v4l2.c index 435baf31b..63c282e15 100644 --- a/src/examples/local-v4l2.c +++ b/src/examples/local-v4l2.c @@ -20,7 +20,11 @@ #include #include -#include +#define WIDTH 640 +#define HEIGHT 480 +#define BPP 3 + +#include "sdl.h" #include #include @@ -31,10 +35,6 @@ #include #include -#define WIDTH 640 -#define HEIGHT 480 -#define BPP 3 - struct data { SDL_Renderer *renderer; SDL_Window *window; @@ -76,76 +76,6 @@ static void handle_events(struct data *data) } } -static struct { - Uint32 format; - uint32_t id; -} video_formats[] = { - { SDL_PIXELFORMAT_UNKNOWN, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX1LSB, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_UNKNOWN, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX1LSB, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX1MSB, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX4LSB, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX4MSB, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_INDEX8, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGB332, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGB444, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGB555, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_BGR555, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_ARGB4444, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGBA4444, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_ABGR4444, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_BGRA4444, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_ARGB1555, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGBA5551, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_ABGR1555, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_BGRA5551, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGB565, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_BGR565, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGB24, SPA_VIDEO_FORMAT_RGB,}, - { SDL_PIXELFORMAT_RGB888, SPA_VIDEO_FORMAT_RGB,}, - { SDL_PIXELFORMAT_RGBX8888, SPA_VIDEO_FORMAT_RGBx,}, - { SDL_PIXELFORMAT_BGR24, SPA_VIDEO_FORMAT_BGR,}, - { SDL_PIXELFORMAT_BGR888, SPA_VIDEO_FORMAT_BGR,}, - { SDL_PIXELFORMAT_BGRX8888, SPA_VIDEO_FORMAT_BGRx,}, - { SDL_PIXELFORMAT_ARGB2101010, SPA_VIDEO_FORMAT_UNKNOWN,}, - { SDL_PIXELFORMAT_RGBA8888, SPA_VIDEO_FORMAT_RGBA,}, - { SDL_PIXELFORMAT_ARGB8888, SPA_VIDEO_FORMAT_ARGB,}, - { SDL_PIXELFORMAT_BGRA8888, SPA_VIDEO_FORMAT_BGRA,}, - { SDL_PIXELFORMAT_ABGR8888, SPA_VIDEO_FORMAT_ABGR,}, - { SDL_PIXELFORMAT_YV12, SPA_VIDEO_FORMAT_YV12,}, - { SDL_PIXELFORMAT_IYUV, SPA_VIDEO_FORMAT_I420,}, - { SDL_PIXELFORMAT_YUY2, SPA_VIDEO_FORMAT_YUY2,}, - { SDL_PIXELFORMAT_UYVY, SPA_VIDEO_FORMAT_UYVY,}, - { SDL_PIXELFORMAT_YVYU, SPA_VIDEO_FORMAT_YVYU,}, -#if SDL_VERSION_ATLEAST(2,0,4) - { SDL_PIXELFORMAT_NV12, SPA_VIDEO_FORMAT_NV12,}, - { SDL_PIXELFORMAT_NV21, SPA_VIDEO_FORMAT_NV21,}, -#endif -}; - -static uint32_t sdl_format_to_id(struct data *data, Uint32 format) -{ - size_t i; - - for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) { - if (video_formats[i].format == format) - return video_formats[i].id; - } - return SPA_VIDEO_FORMAT_UNKNOWN; -} - -static Uint32 id_to_sdl_format(struct data *data, uint32_t id) -{ - size_t i; - - for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) { - if (video_formats[i].id == id) - return video_formats[i].format; - } - return SDL_PIXELFORMAT_UNKNOWN; -} - static int impl_send_command(struct spa_node *node, const struct spa_command *command) { return 0; @@ -218,50 +148,12 @@ static int port_enum_formats(struct spa_node *node, { struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); SDL_RendererInfo info; - uint32_t i, c; if (*index != 0) return 0; SDL_GetRendererInfo(d->renderer, &info); - - spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); - spa_pod_builder_push_prop(builder, SPA_FORMAT_mediaType, 0); - spa_pod_builder_enum(builder, SPA_MEDIA_TYPE_video); - spa_pod_builder_pop(builder); - - spa_pod_builder_push_prop(builder, SPA_FORMAT_mediaSubtype, 0); - spa_pod_builder_enum(builder, SPA_MEDIA_SUBTYPE_raw); - spa_pod_builder_pop(builder); - - spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_format, - SPA_POD_PROP_FLAG_UNSET | - SPA_POD_PROP_RANGE_ENUM); - for (i = 0, c = 0; i < info.num_texture_formats; i++) { - uint32_t id = sdl_format_to_id(d, info.texture_formats[i]); - if (id == 0) - continue; - if (c++ == 0) - spa_pod_builder_enum(builder, id); - spa_pod_builder_enum(builder, id); - } - for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) { - uint32_t id = video_formats[i].id; - if (id != SPA_VIDEO_FORMAT_UNKNOWN) - spa_pod_builder_enum(builder, id); - } - spa_pod_builder_pop(builder); - - spa_pod_builder_add(builder, - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT), - SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1,1), - &SPA_RECTANGLE(info.max_texture_width, - info.max_texture_height)), - ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), - SPA_POD_PROP_MIN_MAX(&SPA_FRACTION(0,1), - &SPA_FRACTION(30,1)), - NULL); - *result = spa_pod_builder_pop(builder); + *result = sdl_build_formats(&info, builder); (*index)++; @@ -287,12 +179,12 @@ static int impl_port_enum_params(struct spa_node *node, *result = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, 32), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", d->stride * d->format.size.height, - ":", SPA_PARAM_BUFFERS_stride, "i", d->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, 32), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_Int(d->stride * d->format.size.height), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(d->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -301,8 +193,9 @@ static int impl_port_enum_params(struct spa_node *node, *result = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: @@ -327,7 +220,7 @@ static int port_set_format(struct spa_node *node, enum spa_direction direction, spa_format_video_raw_parse(format, &d->format); - sdl_format = id_to_sdl_format(d, d->format.format); + sdl_format = id_to_sdl_format(d->format.format); if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) return -EINVAL; diff --git a/src/examples/sdl.h b/src/examples/sdl.h index 60aed590e..990458e7c 100644 --- a/src/examples/sdl.h +++ b/src/examples/sdl.h @@ -98,38 +98,37 @@ static struct spa_pod *sdl_build_formats(SDL_RendererInfo *info, struct spa_pod_ int i, c; spa_pod_builder_push_object(b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); - spa_pod_builder_push_prop(b, SPA_FORMAT_mediaType, 0); - spa_pod_builder_enum(b, SPA_MEDIA_TYPE_video); - spa_pod_builder_pop(b); - spa_pod_builder_push_prop(b, SPA_FORMAT_mediaSubtype, 0); - spa_pod_builder_enum(b, SPA_MEDIA_SUBTYPE_raw); - spa_pod_builder_pop(b); + spa_pod_builder_prop(b, SPA_FORMAT_mediaType, 0); + spa_pod_builder_id(b, SPA_MEDIA_TYPE_video); + spa_pod_builder_prop(b, SPA_FORMAT_mediaSubtype, 0); + spa_pod_builder_id(b, SPA_MEDIA_SUBTYPE_raw); - spa_pod_builder_push_prop(b, SPA_FORMAT_VIDEO_format, - SPA_POD_PROP_FLAG_UNSET | - SPA_POD_PROP_RANGE_ENUM); + spa_pod_builder_prop(b, SPA_FORMAT_VIDEO_format, 0); + spa_pod_builder_push_choice(b, SPA_CHOICE_Enum, 0); for (i = 0, c = 0; i < info->num_texture_formats; i++) { uint32_t id = sdl_format_to_id(info->texture_formats[i]); if (id == 0) continue; if (c++ == 0) - spa_pod_builder_enum(b, id); - spa_pod_builder_enum(b, id); + spa_pod_builder_id(b, id); + spa_pod_builder_id(b, id); } for (i = 0; i < SPA_N_ELEMENTS(sdl_video_formats); i++) { uint32_t id = sdl_video_formats[i].id; if (id != SPA_VIDEO_FORMAT_UNKNOWN) - spa_pod_builder_enum(b, id); + spa_pod_builder_id(b, id); } spa_pod_builder_pop(b); - spa_pod_builder_add(b, - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT), - SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1,1), - &SPA_RECTANGLE(info->max_texture_width, - info->max_texture_height)), - ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), - SPA_POD_PROP_MIN_MAX(&SPA_FRACTION(0,1), - &SPA_FRACTION(30,1)), - NULL); + spa_pod_builder_props(b, + SPA_FORMAT_VIDEO_size, &SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(WIDTH, HEIGHT), + SPA_RECTANGLE(1,1), + SPA_RECTANGLE(info->max_texture_width, + info->max_texture_height)), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_CHOICE_RANGE_Fraction( + SPA_FRACTION(25,1), + SPA_FRACTION(0,1), + SPA_FRACTION(30,1)), + 0); return spa_pod_builder_pop(b); } diff --git a/src/examples/video-play.c b/src/examples/video-play.c index f554bd795..4850b8e69 100644 --- a/src/examples/video-play.c +++ b/src/examples/video-play.c @@ -170,17 +170,18 @@ on_stream_format_changed(void *_data, const struct spa_pod *format) params[0] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 8, - SPA_POD_PROP_MIN_MAX(2, 16), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", data->stride * data->format.size.height, - ":", SPA_PARAM_BUFFERS_stride, "i", data->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(8, 2, 16), + 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), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); params[1] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); pw_stream_finish_format(stream, 0, params, 2); } diff --git a/src/examples/video-src.c b/src/examples/video-src.c index 331d2cf08..806db96f5 100644 --- a/src/examples/video-src.c +++ b/src/examples/video-src.c @@ -169,24 +169,27 @@ on_stream_format_changed(void *_data, const struct spa_pod *format) params[0] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 2, - SPA_POD_PROP_MIN_MAX(1, 32), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "i", data->stride * data->format.size.height, - ":", SPA_PARAM_BUFFERS_stride, "i", data->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(2, 1, 32), + 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), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); params[1] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); params[2] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - ":", SPA_PARAM_META_type, "I", SPA_META_VideoDamage, - ":", SPA_PARAM_META_size, "iru", sizeof(struct spa_meta_region) * 16, - SPA_POD_PROP_MIN_MAX(sizeof(struct spa_meta_region) * 1, - sizeof(struct spa_meta_region) * 16)); + 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), + 0); pw_stream_finish_format(stream, 0, params, 3); } @@ -224,13 +227,15 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo params[0] = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_video, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "I", SPA_VIDEO_FORMAT_RGB, - ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320, 240), - SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1, 1), - &SPA_RECTANGLE(4096, 4096)), - ":", SPA_FORMAT_VIDEO_framerate, "F", &SPA_FRACTION(25, 1)); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_video), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_VIDEO_format, &SPA_POD_Id(SPA_VIDEO_FORMAT_RGB), + SPA_FORMAT_VIDEO_size, &SPA_POD_CHOICE_RANGE_Rectangle( + SPA_RECTANGLE(320, 240), + SPA_RECTANGLE(1, 1), + SPA_RECTANGLE(4096, 4096)), + SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(SPA_FRACTION(25, 1)), + 0); pw_stream_add_listener(data->stream, &data->stream_listener, diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c index e2b8c3760..bd5e690ba 100644 --- a/src/gst/gstpipewireformat.c +++ b/src/gst/gstpipewireformat.c @@ -317,22 +317,22 @@ get_range_type (const GValue *val) GType type = G_VALUE_TYPE (val); if (type == GST_TYPE_LIST) - return SPA_POD_PROP_RANGE_ENUM; + return SPA_CHOICE_Enum; if (type == GST_TYPE_DOUBLE_RANGE || type == GST_TYPE_FRACTION_RANGE) - return SPA_POD_PROP_RANGE_MIN_MAX; + return SPA_CHOICE_Range; if (type == GST_TYPE_INT_RANGE) { if (gst_value_get_int_range_step (val) == 1) - return SPA_POD_PROP_RANGE_MIN_MAX; + return SPA_CHOICE_Range; else - return SPA_POD_PROP_RANGE_STEP; + return SPA_CHOICE_Step; } if (type == GST_TYPE_INT64_RANGE) { if (gst_value_get_int64_range_step (val) == 1) - return SPA_POD_PROP_RANGE_MIN_MAX; + return SPA_CHOICE_Range; else - return SPA_POD_PROP_RANGE_STEP; + return SPA_CHOICE_Step; } - return SPA_POD_PROP_RANGE_NONE; + return SPA_CHOICE_None; } static const uint32_t @@ -345,11 +345,11 @@ get_range_type2 (const GValue *v1, const GValue *v2) if (r1 == r2) return r1; - if (r1 == SPA_POD_PROP_RANGE_STEP || r2 == SPA_POD_PROP_RANGE_STEP) - return SPA_POD_PROP_RANGE_STEP; - if (r1 == SPA_POD_PROP_RANGE_MIN_MAX || r2 == SPA_POD_PROP_RANGE_MIN_MAX) - return SPA_POD_PROP_RANGE_MIN_MAX; - return SPA_POD_PROP_RANGE_MIN_MAX; + if (r1 == SPA_CHOICE_Step || r2 == SPA_CHOICE_Step) + return SPA_CHOICE_Step; + if (r1 == SPA_CHOICE_Range || r2 == SPA_CHOICE_Range) + return SPA_CHOICE_Range; + return SPA_CHOICE_Range; } static gboolean @@ -357,73 +357,73 @@ handle_video_fields (ConvertData *d) { const GValue *value, *value2; int i; - struct spa_pod_prop *prop; + struct spa_pod_choice *choice; value = gst_structure_get_value (d->cs, "format"); if (value) { const char *v; int idx; for (i = 0; (v = get_nth_string (value, i)); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_VIDEO_format, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_VIDEO_format, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } idx = gst_video_format_from_string (v); if (idx < SPA_N_ELEMENTS (video_format_map)) - spa_pod_builder_enum (&d->b, video_format_map[idx]); + spa_pod_builder_id (&d->b, video_format_map[idx]); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "width"); value2 = gst_structure_get_value (d->cs, "height"); if (value || value2) { struct spa_rectangle v; for (i = 0; get_nth_rectangle (value, value2, i, &v); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_VIDEO_size, - get_range_type2 (value, value2)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_VIDEO_size, 0); + spa_pod_builder_push_choice(&d->b, get_range_type2 (value, value2), 0); + } spa_pod_builder_rectangle (&d->b, v.width, v.height); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "framerate"); if (value) { struct spa_fraction v; for (i = 0; get_nth_fraction (value, i, &v); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_VIDEO_framerate, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_VIDEO_framerate, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } spa_pod_builder_fraction (&d->b, v.num, v.denom); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "max-framerate"); if (value) { struct spa_fraction v; for (i = 0; get_nth_fraction (value, i, &v); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_VIDEO_maxFramerate, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_VIDEO_maxFramerate, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } spa_pod_builder_fraction (&d->b, v.num, v.denom); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } return TRUE; } @@ -432,7 +432,7 @@ static gboolean handle_audio_fields (ConvertData *d) { const GValue *value; - struct spa_pod_prop *prop; + struct spa_pod_choice *choice; int i = 0; value = gst_structure_get_value (d->cs, "format"); @@ -440,18 +440,18 @@ handle_audio_fields (ConvertData *d) const char *v; int idx; for (i = 0; (v = get_nth_string (value, i)); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_AUDIO_format, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_AUDIO_format, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } idx = gst_audio_format_from_string (v); if (idx < SPA_N_ELEMENTS (audio_format_map)) - spa_pod_builder_enum (&d->b, audio_format_map[idx]); + spa_pod_builder_id (&d->b, audio_format_map[idx]); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "layout"); @@ -467,46 +467,46 @@ handle_audio_fields (ConvertData *d) else break; - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_AUDIO_layout, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_AUDIO_layout, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } - spa_pod_builder_enum (&d->b, layout); + spa_pod_builder_id (&d->b, layout); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "rate"); if (value) { int v; for (i = 0; get_nth_int (value, i, &v); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_AUDIO_rate, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_AUDIO_rate, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } spa_pod_builder_int (&d->b, v); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } value = gst_structure_get_value (d->cs, "channels"); if (value) { int v; for (i = 0; get_nth_int (value, i, &v); i++) { - if (i == 0) - spa_pod_builder_push_prop (&d->b, - SPA_FORMAT_AUDIO_channels, - get_range_type (value)); + if (i == 0) { + spa_pod_builder_prop (&d->b, SPA_FORMAT_AUDIO_channels, 0); + spa_pod_builder_push_choice(&d->b, get_range_type (value), 0); + } spa_pod_builder_int (&d->b, v); } - prop = spa_pod_builder_pop(&d->b); - if (i > 1) - prop->body.flags |= SPA_POD_PROP_FLAG_UNSET; + choice = spa_pod_builder_pop(&d->b); + if (i <= 1) + choice->body.type = SPA_CHOICE_None; } return TRUE; } @@ -536,13 +536,11 @@ convert_1 (ConvertData *d) spa_pod_builder_push_object (&d->b, SPA_TYPE_OBJECT_Format, d->id); - spa_pod_builder_push_prop (&d->b, SPA_FORMAT_mediaType, 0); - spa_pod_builder_enum(&d->b, d->type->media_type); - spa_pod_builder_pop (&d->b); + spa_pod_builder_prop (&d->b, SPA_FORMAT_mediaType, 0); + spa_pod_builder_id(&d->b, d->type->media_type); - spa_pod_builder_push_prop (&d->b, SPA_FORMAT_mediaSubtype, 0); - spa_pod_builder_enum(&d->b, d->type->media_subtype); - spa_pod_builder_pop (&d->b); + spa_pod_builder_prop (&d->b, SPA_FORMAT_mediaSubtype, 0); + spa_pod_builder_id(&d->b, d->type->media_subtype); if (d->type->media_type == SPA_MEDIA_TYPE_video) handle_video_fields (d); @@ -627,21 +625,23 @@ static void handle_id_prop (struct spa_pod_prop *prop, const char *key, id_to_string_func func, GstCaps *res) { const char * str; - uint32_t *id = SPA_POD_CONTENTS (struct spa_pod_prop, prop); - uint32_t i, n_items = SPA_POD_PROP_N_VALUES (prop); - uint32_t flags; + struct spa_pod *val; + uint32_t *id; + uint32_t i, n_items, choice; - flags = prop->body.flags; - if (!(flags & SPA_POD_PROP_FLAG_UNSET)) - flags &= ~SPA_POD_PROP_RANGE_MASK; + val = spa_pod_get_values(&prop->value, &n_items, &choice); + if (val->type != SPA_TYPE_Id) + return; - switch (flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: + id = SPA_POD_BODY(val); + + switch (choice) { + case SPA_CHOICE_None: if (!(str = func(id[0]))) return; gst_caps_set_simple (res, key, G_TYPE_STRING, rindex (str, ':') + 1, NULL); break; - case SPA_POD_PROP_RANGE_ENUM: + case SPA_CHOICE_Enum: { GValue list = { 0 }, v = { 0 }; @@ -666,34 +666,36 @@ handle_id_prop (struct spa_pod_prop *prop, const char *key, id_to_string_func fu static void handle_int_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res) { - uint32_t *val = SPA_POD_CONTENTS (struct spa_pod_prop, prop); - uint32_t i, n_items = SPA_POD_PROP_N_VALUES (prop); - uint32_t flags; + struct spa_pod *val; + uint32_t *ints; + uint32_t i, n_items, choice; - flags = prop->body.flags; - if (!(flags & SPA_POD_PROP_FLAG_UNSET)) - flags &= ~SPA_POD_PROP_RANGE_MASK; + val = spa_pod_get_values(&prop->value, &n_items, &choice); + if (val->type != SPA_TYPE_Int) + return; - switch (flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: - gst_caps_set_simple (res, key, G_TYPE_INT, val[0], NULL); + ints = SPA_POD_BODY(val); + + switch (choice) { + case SPA_CHOICE_None: + gst_caps_set_simple (res, key, G_TYPE_INT, ints[0], NULL); break; - case SPA_POD_PROP_RANGE_MIN_MAX: - case SPA_POD_PROP_RANGE_STEP: + case SPA_CHOICE_Range: + case SPA_CHOICE_Step: { if (n_items < 3) return; - gst_caps_set_simple (res, key, GST_TYPE_INT_RANGE, val[1], val[2], NULL); + gst_caps_set_simple (res, key, GST_TYPE_INT_RANGE, ints[1], ints[2], NULL); break; } - case SPA_POD_PROP_RANGE_ENUM: + case SPA_CHOICE_Enum: { GValue list = { 0 }, v = { 0 }; g_value_init (&list, GST_TYPE_LIST); for (i = 1; i < n_items; i++) { g_value_init (&v, G_TYPE_INT); - g_value_set_int (&v, val[i]); + g_value_set_int (&v, ints[i]); gst_value_list_append_and_take_value (&list, &v); } gst_caps_set_value (res, key, &list); @@ -708,21 +710,23 @@ handle_int_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res) static void handle_rect_prop (struct spa_pod_prop *prop, const char *width, const char *height, GstCaps *res) { - struct spa_rectangle *rect = SPA_POD_CONTENTS (struct spa_pod_prop, prop); - uint32_t i, n_items = SPA_POD_PROP_N_VALUES (prop); - uint32_t flags; + struct spa_pod *val; + struct spa_rectangle *rect; + uint32_t i, n_items, choice; - flags = prop->body.flags; - if (!(flags & SPA_POD_PROP_FLAG_UNSET)) - flags &= ~SPA_POD_PROP_RANGE_MASK; + val = spa_pod_get_values(&prop->value, &n_items, &choice); + if (val->type != SPA_TYPE_Rectangle) + return; - switch (flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: + rect = SPA_POD_BODY(val); + + switch (choice) { + case SPA_CHOICE_None: gst_caps_set_simple (res, width, G_TYPE_INT, rect[0].width, height, G_TYPE_INT, rect[0].height, NULL); break; - case SPA_POD_PROP_RANGE_MIN_MAX: - case SPA_POD_PROP_RANGE_STEP: + case SPA_CHOICE_Range: + case SPA_CHOICE_Step: { if (n_items < 3) return; @@ -730,7 +734,7 @@ handle_rect_prop (struct spa_pod_prop *prop, const char *width, const char *heig height, GST_TYPE_INT_RANGE, rect[1].height, rect[2].height, NULL); break; } - case SPA_POD_PROP_RANGE_ENUM: + case SPA_CHOICE_Enum: { GValue l1 = { 0 }, l2 = { 0 }, v1 = { 0 }, v2 = { 0 }; @@ -759,20 +763,22 @@ handle_rect_prop (struct spa_pod_prop *prop, const char *width, const char *heig static void handle_fraction_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res) { - struct spa_fraction *fract = SPA_POD_CONTENTS (struct spa_pod_prop, prop); - uint32_t i, n_items = SPA_POD_PROP_N_VALUES (prop); - uint32_t flags; + struct spa_pod *val; + struct spa_fraction *fract; + uint32_t i, n_items, choice; - flags = prop->body.flags; - if (!(flags & SPA_POD_PROP_FLAG_UNSET)) - flags &= ~SPA_POD_PROP_RANGE_MASK; + val = spa_pod_get_values(&prop->value, &n_items, &choice); + if (val->type != SPA_TYPE_Fraction) + return; - switch (flags & SPA_POD_PROP_RANGE_MASK) { - case SPA_POD_PROP_RANGE_NONE: + fract = SPA_POD_BODY(val); + + switch (choice) { + case SPA_CHOICE_None: gst_caps_set_simple (res, key, GST_TYPE_FRACTION, fract[0].num, fract[0].denom, NULL); break; - case SPA_POD_PROP_RANGE_MIN_MAX: - case SPA_POD_PROP_RANGE_STEP: + case SPA_CHOICE_Range: + case SPA_CHOICE_Step: { if (n_items < 3) return; @@ -780,7 +786,7 @@ handle_fraction_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res) fract[2].num, fract[2].denom, NULL); break; } - case SPA_POD_PROP_RANGE_ENUM: + case SPA_CHOICE_Enum: { GValue l1 = { 0 }, v1 = { 0 }; diff --git a/src/gst/gstpipewiresink.c b/src/gst/gstpipewiresink.c index da2852aa3..5096e42e4 100644 --- a/src/gst/gstpipewiresink.c +++ b/src/gst/gstpipewiresink.c @@ -232,25 +232,25 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink) spa_pod_builder_init (&b, buffer, sizeof (buffer)); spa_pod_builder_push_object (&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers); if (size == 0) - spa_pod_builder_add (&b, - ":", SPA_PARAM_BUFFERS_size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), NULL); + spa_pod_builder_props (&b, + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int(0, 0, INT32_MAX), 0); else - spa_pod_builder_add (&b, - ":", SPA_PARAM_BUFFERS_size, "iru", size, SPA_POD_PROP_MIN_MAX(size, INT32_MAX), NULL); + spa_pod_builder_props (&b, + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int(size, size, INT32_MAX), 0); - spa_pod_builder_add (&b, - ":", SPA_PARAM_BUFFERS_stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), - ":", SPA_PARAM_BUFFERS_buffers, "iru", min_buffers, - SPA_POD_PROP_MIN_MAX(min_buffers, + spa_pod_builder_props (&b, + SPA_PARAM_BUFFERS_stride, &SPA_POD_CHOICE_RANGE_Int(0, 0, INT32_MAX), + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(min_buffers, min_buffers, max_buffers ? max_buffers : INT32_MAX), - ":", SPA_PARAM_BUFFERS_align, "i", 16, - NULL); + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); port_params[0] = spa_pod_builder_pop (&b); port_params[1] = spa_pod_builder_object (&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof (struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Int(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof (struct spa_meta_header)), + 0); pw_thread_loop_lock (sink->main_loop); diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 75b9a376f..64b8fd61a 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -703,16 +703,18 @@ on_format_changed (void *data, spa_pod_builder_init (&b, buffer, sizeof (buffer)); params[0] = spa_pod_builder_object (&b, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 16, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_PARAM_BUFFERS_blocks, "iru", 0, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_PARAM_BUFFERS_size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), - ":", SPA_PARAM_BUFFERS_stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(16, 1, INT32_MAX), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_CHOICE_RANGE_Int(0, 1, INT32_MAX), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int(0, 0, INT32_MAX), + SPA_PARAM_BUFFERS_stride, &SPA_POD_CHOICE_RANGE_Int(0, 0, INT32_MAX), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); params[1] = spa_pod_builder_object (&b, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof (struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof (struct spa_meta_header)), + 0); GST_DEBUG_OBJECT (pwsrc, "doing finish format"); pw_stream_finish_format (pwsrc->stream, 0, params, 2); diff --git a/src/modules/module-client-node/protocol-native.c b/src/modules/module-client-node/protocol-native.c index 6a5e49bbb..9daf59a2e 100644 --- a/src/modules/module-client-node/protocol-native.c +++ b/src/modules/module-client-node/protocol-native.c @@ -37,7 +37,7 @@ client_node_marshal_done(void *object, int seq, int res) b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_DONE); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "i", res); @@ -136,7 +136,7 @@ static void client_node_marshal_set_active(void *object, bool active) b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_SET_ACTIVE); - spa_pod_builder_struct(b, "b", active); + spa_pod_builder_add_struct(b, "b", active); pw_protocol_native_end_proxy(proxy, b); } @@ -148,7 +148,7 @@ static void client_node_marshal_event_method(void *object, struct spa_event *eve b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_EVENT); - spa_pod_builder_struct(b, "P", event); + spa_pod_builder_add_struct(b, "P", event); pw_protocol_native_end_proxy(proxy, b); } @@ -160,7 +160,7 @@ static void client_node_marshal_destroy(void *object) b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_DESTROY); - spa_pod_builder_struct(b); + spa_pod_builder_add_struct(b); pw_protocol_native_end_proxy(proxy, b); } @@ -471,7 +471,7 @@ client_node_marshal_add_mem(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_ADD_MEM); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", mem_id, "I", type, "i", pw_protocol_native_add_resource_fd(resource, memfd), @@ -487,7 +487,7 @@ static void client_node_marshal_transport(void *object, uint32_t node_id, int re b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_TRANSPORT); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", node_id, "i", pw_protocol_native_add_resource_fd(resource, readfd), "i", pw_protocol_native_add_resource_fd(resource, writefd)); @@ -504,7 +504,7 @@ client_node_marshal_set_param(void *object, uint32_t seq, uint32_t id, uint32_t b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_SET_PARAM); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "I", id, "i", flags, @@ -520,7 +520,7 @@ static void client_node_marshal_event_event(void *object, const struct spa_event b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_EVENT); - spa_pod_builder_struct(b, "P", event); + spa_pod_builder_add_struct(b, "P", event); pw_protocol_native_end_resource(resource, b); } @@ -533,7 +533,7 @@ client_node_marshal_command(void *object, uint32_t seq, const struct spa_command b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_COMMAND); - spa_pod_builder_struct(b, "i", seq, "P", command); + spa_pod_builder_add_struct(b, "i", seq, "P", command); pw_protocol_native_end_resource(resource, b); } @@ -547,7 +547,7 @@ client_node_marshal_add_port(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_ADD_PORT); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "i", direction, "i", port_id); @@ -564,7 +564,7 @@ client_node_marshal_remove_port(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_REMOVE_PORT); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "i", direction, "i", port_id); @@ -586,7 +586,7 @@ client_node_marshal_port_set_param(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_PARAM); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "i", direction, "i", port_id, @@ -662,7 +662,7 @@ client_node_marshal_port_command(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_COMMAND); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", direction, "i", port_id, "P", command); @@ -686,7 +686,7 @@ client_node_marshal_port_set_io(void *object, b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_IO); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", seq, "i", direction, "i", port_id, @@ -710,7 +710,7 @@ client_node_marshal_set_io(void *object, struct spa_pod_builder *b; b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_SET_IO); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "I", id, "i", memid, "i", offset, diff --git a/src/modules/module-media-session/floatmix.c b/src/modules/module-media-session/floatmix.c index 9949a2c1e..dc8afd06f 100644 --- a/src/modules/module-media-session/floatmix.c +++ b/src/modules/module-media-session/floatmix.c @@ -329,13 +329,13 @@ static int port_enum_formats(struct spa_node *node, } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - ":", SPA_FORMAT_mediaType, "I", SPA_MEDIA_TYPE_audio, - ":", SPA_FORMAT_mediaSubtype, "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, - SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", SPA_FORMAT_AUDIO_channels, "iru", 1); + SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), + SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), + SPA_FORMAT_AUDIO_format, &SPA_POD_Id(SPA_AUDIO_FORMAT_F32), + SPA_FORMAT_AUDIO_layout, &SPA_POD_Id(SPA_AUDIO_LAYOUT_NON_INTERLEAVED), + SPA_FORMAT_AUDIO_rate, &SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX), + SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(1), + 0); } break; default: @@ -382,8 +382,10 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_IO }; if (*index < SPA_N_ELEMENTS(list)) - param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", list[*index]); + param = spa_pod_builder_object(&b, + SPA_TYPE_OBJECT_ParamList, id, + SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]), + 0); else return 0; break; @@ -410,13 +412,15 @@ impl_node_port_enum_params(struct spa_node *node, param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, - ":", SPA_PARAM_BUFFERS_buffers, "iru", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", SPA_PARAM_BUFFERS_blocks, "i", 1, - ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * this->stride, - SPA_POD_PROP_MIN_MAX(16 * this->stride, INT32_MAX / this->stride), - ":", SPA_PARAM_BUFFERS_stride, "i", this->stride, - ":", SPA_PARAM_BUFFERS_align, "i", 16); + SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS), + SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, &SPA_POD_CHOICE_RANGE_Int( + 1024 * this->stride, + 16 * this->stride, + INT32_MAX / this->stride), + SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(this->stride), + SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16), + 0); break; case SPA_PARAM_Meta: @@ -427,8 +431,9 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, - ":", SPA_PARAM_META_type, "I", SPA_META_Header, - ":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header)); + SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header), + SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)), + 0); break; default: return 0; @@ -440,20 +445,23 @@ impl_node_port_enum_params(struct spa_node *node, case 0: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)), + 0); break; case 1: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Range, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)), + 0); break; case 2: param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, id, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0); break; default: return 0; diff --git a/src/modules/module-protocol-native/protocol-native.c b/src/modules/module-protocol-native/protocol-native.c index 051898a6d..8889cebfd 100644 --- a/src/modules/module-protocol-native/protocol-native.c +++ b/src/modules/module-protocol-native/protocol-native.c @@ -37,7 +37,7 @@ static void core_marshal_hello(void *object) b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_HELLO); - spa_pod_builder_struct(b, "P", NULL); + spa_pod_builder_add_struct(b, "P", NULL); pw_protocol_native_end_proxy(proxy, b); } @@ -93,7 +93,7 @@ static void core_marshal_sync(void *object, uint32_t seq) b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_SYNC); - spa_pod_builder_struct(b, "i", seq); + spa_pod_builder_add_struct(b, "i", seq); pw_protocol_native_end_proxy(proxy, b); } @@ -105,7 +105,7 @@ static void core_marshal_get_registry(void *object, uint32_t version, uint32_t n b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_GET_REGISTRY); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", version, "i", new_id); @@ -153,7 +153,7 @@ core_marshal_destroy(void *object, uint32_t id) b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_DESTROY); - spa_pod_builder_struct(b, "i", id); + spa_pod_builder_add_struct(b, "i", id); pw_protocol_native_end_proxy(proxy, b); } @@ -276,7 +276,7 @@ static void core_marshal_done(void *object, uint32_t seq) b = pw_protocol_native_begin_resource(resource, PW_CORE_PROXY_EVENT_DONE); - spa_pod_builder_struct(b, "i", seq); + spa_pod_builder_add_struct(b, "i", seq); pw_protocol_native_end_resource(resource, b); } @@ -294,7 +294,7 @@ static void core_marshal_error(void *object, uint32_t id, int res, const char *e vsnprintf(buffer, sizeof(buffer), error, ap); va_end(ap); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", id, "i", res, "s", buffer); @@ -309,7 +309,7 @@ static void core_marshal_remove_id(void *object, uint32_t id) b = pw_protocol_native_begin_resource(resource, PW_CORE_PROXY_EVENT_REMOVE_ID); - spa_pod_builder_struct(b, "i", id); + spa_pod_builder_add_struct(b, "i", id); pw_protocol_native_end_resource(resource, b); } @@ -485,7 +485,7 @@ static void registry_marshal_global_remove(void *object, uint32_t id) b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_PROXY_EVENT_GLOBAL_REMOVE); - spa_pod_builder_struct(b, "i", id); + spa_pod_builder_add_struct(b, "i", id); pw_protocol_native_end_resource(resource, b); } @@ -704,7 +704,7 @@ static void node_marshal_param(void *object, uint32_t id, uint32_t index, uint32 b = pw_protocol_native_begin_resource(resource, PW_NODE_PROXY_EVENT_PARAM); - spa_pod_builder_struct(b, "I", id, "i", index, "i", next, "P", param); + spa_pod_builder_add_struct(b, "I", id, "i", index, "i", next, "P", param); pw_protocol_native_end_resource(resource, b); } @@ -736,7 +736,7 @@ static void node_marshal_enum_params(void *object, uint32_t id, uint32_t index, b = pw_protocol_native_begin_proxy(proxy, PW_NODE_PROXY_METHOD_ENUM_PARAMS); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "I", id, "i", index, "i", num, @@ -828,7 +828,7 @@ static void port_marshal_param(void *object, uint32_t id, uint32_t index, uint32 b = pw_protocol_native_begin_resource(resource, PW_PORT_PROXY_EVENT_PARAM); - spa_pod_builder_struct(b, "I", id, "i", index, "i", next, "P", param); + spa_pod_builder_add_struct(b, "I", id, "i", index, "i", next, "P", param); pw_protocol_native_end_resource(resource, b); } @@ -860,7 +860,7 @@ static void port_marshal_enum_params(void *object, uint32_t id, uint32_t index, b = pw_protocol_native_begin_proxy(proxy, PW_PORT_PROXY_METHOD_ENUM_PARAMS); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "I", id, "i", index, "i", num, @@ -1060,7 +1060,7 @@ static void registry_marshal_bind(void *object, uint32_t id, b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_PROXY_METHOD_BIND); - spa_pod_builder_struct(b, + spa_pod_builder_add_struct(b, "i", id, "I", type, "i", version, diff --git a/src/modules/spa/spa-monitor.c b/src/modules/spa/spa-monitor.c index 73a75826f..49addc6b1 100644 --- a/src/modules/spa/spa-monitor.c +++ b/src/modules/spa/spa-monitor.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -80,8 +81,11 @@ static struct monitor_item *add_item(struct pw_spa_monitor *this, ":", SPA_MONITOR_ITEM_name, "s", &name, ":", SPA_MONITOR_ITEM_class, "s", &klass, ":", SPA_MONITOR_ITEM_factory, "p", &factory, - ":", SPA_MONITOR_ITEM_info, "T", &info, NULL) < 0) + ":", SPA_MONITOR_ITEM_info, "T", &info, NULL) < 0) { + pw_log_warn("monitor %p: could not parse item", this); + spa_debug_pod(0, NULL, item); return NULL; + } pw_log_debug("monitor %p: add: \"%s\" (%s)", this, name, id); diff --git a/src/modules/spa/spa-node.c b/src/modules/spa/spa-node.c index dcb41c13b..5d8e6757e 100644 --- a/src/modules/spa/spa-node.c +++ b/src/modules/spa/spa-node.c @@ -181,29 +181,29 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie pw_log_info("configure prop %s", key); - switch(prop->body.value.type) { + switch(prop->value.type) { case SPA_TYPE_Bool: - SPA_POD_VALUE(struct spa_pod_bool, &prop->body.value) = + SPA_POD_VALUE(struct spa_pod_bool, &prop->value) = pw_properties_parse_bool(value); break; - case SPA_TYPE_Enum: - SPA_POD_VALUE(struct spa_pod_enum, &prop->body.value) = + case SPA_TYPE_Id: + SPA_POD_VALUE(struct spa_pod_id, &prop->value) = spa_debug_type_find_type(NULL, value); break; case SPA_TYPE_Int: - SPA_POD_VALUE(struct spa_pod_int, &prop->body.value) = + SPA_POD_VALUE(struct spa_pod_int, &prop->value) = pw_properties_parse_int(value); break; case SPA_TYPE_Long: - SPA_POD_VALUE(struct spa_pod_long, &prop->body.value) = + SPA_POD_VALUE(struct spa_pod_long, &prop->value) = pw_properties_parse_int64(value); break; case SPA_TYPE_Float: - SPA_POD_VALUE(struct spa_pod_float, &prop->body.value) = + SPA_POD_VALUE(struct spa_pod_float, &prop->value) = pw_properties_parse_float(value); break; case SPA_TYPE_Double: - SPA_POD_VALUE(struct spa_pod_double, &prop->body.value) = + SPA_POD_VALUE(struct spa_pod_double, &prop->value) = pw_properties_parse_double(value); break; case SPA_TYPE_String: diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 487d4de70..c045c69f4 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -406,7 +406,8 @@ static int impl_port_enum_params(struct spa_node *node, if (last_id == SPA_ID_INVALID){ *result = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_ParamList, id, - ":", SPA_PARAM_LIST_id, "I", new_id); + SPA_PARAM_LIST_id, &SPA_POD_Id(new_id), + 0); last_id = new_id; } else if (last_id != new_id) { @@ -631,10 +632,9 @@ static int process_notify(struct stream *impl, struct spa_pod_sequence *sequence if (impl->props.changed) { spa_pod_builder_control_header(&b, 0, SPA_CONTROL_Properties); spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_Props, 0); - spa_pod_builder_push_prop(&b, SPA_PROP_volume, 0); + spa_pod_builder_prop(&b, SPA_PROP_volume, 0); spa_pod_builder_float(&b, impl->props.volume); spa_pod_builder_pop(&b); - spa_pod_builder_pop(&b); impl->props.changed = false; } spa_pod_builder_pop(&b); @@ -1004,14 +1004,16 @@ static void add_controls(struct pw_stream *stream) add_param(stream, PARAM_TYPE_INIT, spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, SPA_PARAM_IO, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Notify, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence) + 1024)); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Notify), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence) + 1024), + 0)); add_param(stream, PARAM_TYPE_INIT, spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamIO, SPA_PARAM_IO, - ":", SPA_PARAM_IO_id, "I", SPA_IO_Control, - ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence))); + SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control), + SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)), + 0)); } int