pod: improve the vararg pod builder and parser

Automatically parse and build key/value when in objects without having
to prefix the key with ":"
Automatically build control/value when in sequence without the "."
prefix.
Remove the builder with key/pod, taking a reference to the stack built
temporary pods is not allowed in c++. We can use the varargs version
with the same convenient syntax.
Remove the parser "*" option, it is unused.
Improve spa_pod_builder_add_* and spa_pod_parser_get_* and make them
look similar.
This commit is contained in:
Wim Taymans 2019-01-16 11:05:12 +01:00
parent 79d68ace68
commit 80cfda89c1
59 changed files with 1833 additions and 2005 deletions

View file

@ -39,13 +39,16 @@ static inline int
spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info)
{
struct spa_pod *position = NULL;
struct spa_pod_parser prs;
int res;
res = spa_pod_object_parse(format,
":", SPA_FORMAT_AUDIO_format, "I", &info->format,
":", SPA_FORMAT_AUDIO_rate, "i", &info->rate,
":", SPA_FORMAT_AUDIO_channels, "i", &info->channels,
":", SPA_FORMAT_AUDIO_flags, "?i", &info->flags,
":", SPA_FORMAT_AUDIO_position, "?P", &position, NULL);
spa_pod_parser_pod(&prs, format);
res = spa_pod_parser_get_object(&prs,
SPA_TYPE_OBJECT_Format, NULL,
SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format),
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate),
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(&info->channels),
SPA_FORMAT_AUDIO_flags, SPA_POD_OPT_Int(&info->flags),
SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position));
if (position && position->type == SPA_TYPE_Array &&
SPA_POD_ARRAY_TYPE(position) == SPA_TYPE_Id) {
uint32_t *values = (uint32_t*)SPA_POD_ARRAY_VALUES(position);
@ -61,19 +64,13 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r
static inline struct spa_pod *
spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_raw *info)
{
const struct spa_pod_id media_type = SPA_POD_Id(SPA_MEDIA_TYPE_audio);
const struct spa_pod_id media_subtype = SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw);
const struct spa_pod_id format = SPA_POD_Id(info->format);
const struct spa_pod_int rate = SPA_POD_Int(info->rate);
const struct spa_pod_int channels = SPA_POD_Int(info->channels);
spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, id);
spa_pod_builder_props(builder,
SPA_FORMAT_mediaType, &media_type,
SPA_FORMAT_mediaSubtype, &media_subtype,
SPA_FORMAT_AUDIO_format, &format,
SPA_FORMAT_AUDIO_rate, &rate,
SPA_FORMAT_AUDIO_channels, &channels,
spa_pod_builder_add(builder,
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_rate, SPA_POD_Int(info->rate),
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(info->channels),
0);
if (!SPA_FLAG_CHECK(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED)) {
@ -81,7 +78,6 @@ spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct
spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id,
info->channels, info->position);
}
return (struct spa_pod*)spa_pod_builder_pop(builder);
}

View file

@ -36,9 +36,10 @@ extern "C" {
static inline int
spa_format_parse(const struct spa_pod *format, uint32_t *media_type, uint32_t *media_subtype)
{
return spa_pod_object_parse(format,
":", SPA_FORMAT_mediaType, "I", media_type,
":", SPA_FORMAT_mediaSubtype, "I", media_subtype, NULL);
return spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
SPA_FORMAT_mediaType, SPA_POD_Id(media_type),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(media_subtype));
}
#ifdef __cplusplus

View file

@ -38,63 +38,59 @@ static inline int
spa_format_video_raw_parse(const struct spa_pod *format,
struct spa_video_info_raw *info)
{
return spa_pod_object_parse(format,
":", SPA_FORMAT_VIDEO_format, "I", &info->format,
":", SPA_FORMAT_VIDEO_size, "R", &info->size,
":", SPA_FORMAT_VIDEO_framerate, "F", &info->framerate,
":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate,
":", SPA_FORMAT_VIDEO_views, "?i", &info->views,
":", SPA_FORMAT_VIDEO_interlaceMode, "?I", &info->interlace_mode,
":", SPA_FORMAT_VIDEO_pixelAspectRatio, "?F", &info->pixel_aspect_ratio,
":", SPA_FORMAT_VIDEO_multiviewMode, "?I", &info->multiview_mode,
":", SPA_FORMAT_VIDEO_multiviewFlags, "?I", &info->multiview_flags,
":", SPA_FORMAT_VIDEO_chromaSite, "?I", &info->chroma_site,
":", SPA_FORMAT_VIDEO_colorRange, "?I", &info->color_range,
":", SPA_FORMAT_VIDEO_colorMatrix, "?I", &info->color_matrix,
":", SPA_FORMAT_VIDEO_transferFunction, "?I", &info->transfer_function,
":", SPA_FORMAT_VIDEO_colorPrimaries, "?I", &info->color_primaries, NULL);
return spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
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),
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate),
SPA_FORMAT_VIDEO_views, SPA_POD_OPT_Int(&info->views),
SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_OPT_Id(&info->interlace_mode),
SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_POD_OPT_Fraction(&info->pixel_aspect_ratio),
SPA_FORMAT_VIDEO_multiviewMode, SPA_POD_OPT_Id(&info->multiview_mode),
SPA_FORMAT_VIDEO_multiviewFlags, SPA_POD_OPT_Id(&info->multiview_flags),
SPA_FORMAT_VIDEO_chromaSite, SPA_POD_OPT_Id(&info->chroma_site),
SPA_FORMAT_VIDEO_colorRange, SPA_POD_OPT_Id(&info->color_range),
SPA_FORMAT_VIDEO_colorMatrix, SPA_POD_OPT_Id(&info->color_matrix),
SPA_FORMAT_VIDEO_transferFunction, SPA_POD_OPT_Id(&info->transfer_function),
SPA_FORMAT_VIDEO_colorPrimaries, SPA_POD_OPT_Id(&info->color_primaries));
}
static inline struct spa_pod *
spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
struct spa_video_info_raw *info)
{
const struct spa_pod_id media_type = SPA_POD_Id(SPA_MEDIA_TYPE_video);
const struct spa_pod_id media_subtype = SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw);
const struct spa_pod_id format = SPA_POD_Id(info->format);
const struct spa_pod_rectangle size = SPA_POD_Rectangle(info->size);
const struct spa_pod_fraction framerate = SPA_POD_Fraction(info->framerate);
return (struct spa_pod *) spa_pod_builder_object(builder,
return (struct spa_pod *) spa_pod_builder_add_object(builder,
SPA_TYPE_OBJECT_Format, id,
SPA_FORMAT_mediaType, &media_type,
SPA_FORMAT_mediaSubtype, &media_subtype,
SPA_FORMAT_VIDEO_format, &format,
SPA_FORMAT_VIDEO_size, &size,
SPA_FORMAT_VIDEO_framerate, &framerate,
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_Id(info->format),
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&info->size),
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&info->framerate));
}
static inline int
spa_format_video_h264_parse(const struct spa_pod *format,
struct spa_video_info_h264 *info)
{
return spa_pod_object_parse(format,
":", SPA_FORMAT_VIDEO_size, "?R", &info->size,
":", SPA_FORMAT_VIDEO_framerate, "?F", &info->framerate,
":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate,
":", SPA_FORMAT_VIDEO_streamFormat, "?I", &info->stream_format,
":", SPA_FORMAT_VIDEO_alignment, "?I", &info->alignment, NULL);
return spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Rectangle(&info->size),
SPA_FORMAT_VIDEO_framerate, SPA_POD_OPT_Fraction(&info->framerate),
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate),
SPA_FORMAT_VIDEO_streamFormat, SPA_POD_OPT_Id(&info->stream_format),
SPA_FORMAT_VIDEO_alignment, SPA_POD_OPT_Id(&info->alignment));
}
static inline int
spa_format_video_mjpg_parse(const struct spa_pod *format,
struct spa_video_info_mjpg *info)
{
return spa_pod_object_parse(format,
":", SPA_FORMAT_VIDEO_size, "?R", &info->size,
":", SPA_FORMAT_VIDEO_framerate, "?F", &info->framerate,
":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate, NULL);
return spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Rectangle(&info->size),
SPA_FORMAT_VIDEO_framerate, SPA_POD_OPT_Fraction(&info->framerate),
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate));
}
#ifdef __cplusplus

View file

@ -40,8 +40,11 @@ struct spa_pod_frame {
struct spa_pod_builder_state {
uint32_t offset;
bool in_array;
bool first;
#define SPA_POD_BUILDER_FLAG_BODY (1<<0)
#define SPA_POD_BUILDER_FLAG_FIRST (1<<1)
#define SPA_POD_BUILDER_FLAG_OBJECT (1<<2)
#define SPA_POD_BUILDER_FLAG_SEQUENCE (1<<3)
uint32_t flags;
int depth;
};
@ -79,6 +82,12 @@ static inline void spa_pod_builder_init(struct spa_pod_builder *builder, void *d
*builder = SPA_POD_BUILDER_INIT(data, size);
}
static inline struct spa_pod_frame *
spa_pod_builder_top(struct spa_pod_builder *builder)
{
return builder->state.depth > 0 ? &builder->frame[builder->state.depth-1] : NULL;
}
static inline void *
spa_pod_builder_deref_checked(struct spa_pod_builder *builder, uint32_t ref, bool safe)
{
@ -100,6 +109,23 @@ spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t ref)
return spa_pod_builder_deref_checked(builder, ref, false);
}
static inline void
spa_pod_builder_update_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
{
switch (frame->pod.type) {
case SPA_TYPE_Array:
case SPA_TYPE_Choice:
builder->state.flags |= SPA_POD_BUILDER_FLAG_BODY;
break;
case SPA_TYPE_Object:
builder->state.flags |= SPA_POD_BUILDER_FLAG_OBJECT;
break;
case SPA_TYPE_Sequence:
builder->state.flags |= SPA_POD_BUILDER_FLAG_SEQUENCE;
break;
}
}
static inline uint32_t
spa_pod_builder_push(struct spa_pod_builder *builder,
const struct spa_pod *pod,
@ -108,8 +134,8 @@ spa_pod_builder_push(struct spa_pod_builder *builder,
struct spa_pod_frame *frame = &builder->frame[builder->state.depth++];
frame->pod = *pod;
frame->ref = ref;
builder->state.in_array = builder->state.first =
(pod->type == SPA_TYPE_Array || pod->type == SPA_TYPE_Choice);
builder->state.flags = SPA_POD_BUILDER_FLAG_FIRST;
spa_pod_builder_update_frame(builder, frame);
return ref;
}
@ -155,134 +181,102 @@ spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, ui
static inline void *spa_pod_builder_pop(struct spa_pod_builder *builder)
{
struct spa_pod_frame *frame, *top;
struct spa_pod_frame *frame;
struct spa_pod *pod;
frame = &builder->frame[--builder->state.depth];
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_Choice));
builder->state.flags = 0;
if ((frame = spa_pod_builder_top(builder)) != NULL)
spa_pod_builder_update_frame(builder, frame);
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 *head, *body;
uint32_t head_size, body_size, ref;
bool collect = p->type == SPA_TYPE_Collect;
const void *data;
uint32_t size, ref;
if (collect) {
struct spa_pod_collect *col = (struct spa_pod_collect *)p;
head = &col->child;
head_size = sizeof(struct spa_pod);
body = col->value;
if (builder->state.flags == SPA_POD_BUILDER_FLAG_BODY) {
data = SPA_POD_BODY_CONST(p);
size = SPA_POD_BODY_SIZE(p);
} else {
head = p;
head_size = SPA_POD_SIZE(p);
body = SPA_POD_BODY_CONST(p);
data = p;
size = SPA_POD_SIZE(p);
SPA_FLAG_UNSET(builder->state.flags, SPA_POD_BUILDER_FLAG_FIRST);
}
body_size = SPA_POD_BODY_SIZE(head);
ref = spa_pod_builder_raw(builder, data, size);
if (builder->state.flags != SPA_POD_BUILDER_FLAG_BODY)
spa_pod_builder_pad(builder, size);
if (builder->state.in_array && !builder->state.first) {
head = body;
head_size = body_size;
collect = false;
} else {
builder->state.first = false;
}
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, head_size);
return ref;
}
#define SPA_POD_INIT(size,type) (struct spa_pod) { size, type }
#define SPA_POD_None() SPA_POD_INIT(0, SPA_TYPE_None)
#define SPA_POD_INIT_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();
const struct spa_pod p = SPA_POD_INIT_None();
return spa_pod_builder_primitive(builder, &p);
}
#define SPA_POD_Bool(val) (struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, val ? 1 : 0, 0 }
#define SPA_POD_INIT_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(val);
const struct spa_pod_bool p = SPA_POD_INIT_Bool(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (uint32_t)val, 0 }
#define SPA_POD_INIT_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (uint32_t)val, 0 }
static inline uint32_t spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val)
{
const struct spa_pod_id p = SPA_POD_Id(val);
const struct spa_pod_id p = SPA_POD_INIT_Id(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Int(val) (struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (int32_t)val, 0 }
#define SPA_POD_INIT_Int(val) (struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (int32_t)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(val);
const struct spa_pod_int p = SPA_POD_INIT_Int(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Long(val) (struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (int64_t)val }
#define SPA_POD_INIT_Long(val) (struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (int64_t)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(val);
const struct spa_pod_long p = SPA_POD_INIT_Long(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Float(val) (struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, val }
#define SPA_POD_INIT_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(val);
const struct spa_pod_float p = SPA_POD_INIT_Float(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Double(val) (struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, val }
#define SPA_POD_INIT_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(val);
const struct spa_pod_double p = SPA_POD_INIT_Double(val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#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 } }
#define SPA_POD_INIT_String(len) (struct spa_pod_string){ { len, SPA_TYPE_String } }
static inline uint32_t
spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len)
@ -299,7 +293,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 = { { len + 1, SPA_TYPE_String } };
const struct spa_pod_string p = SPA_POD_INIT_String(len+1);
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;
@ -312,58 +306,53 @@ 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(len) (struct spa_pod_bytes){ { len, SPA_TYPE_Bytes } }
#define SPA_POD_INIT_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(len);
const struct spa_pod_bytes p = SPA_POD_INIT_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(type,value) (struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { type, value } }
#define SPA_POD_INIT_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(type, val);
const struct spa_pod_pointer p = SPA_POD_INIT_Pointer(type, val);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Fd(fd) (struct spa_pod_fd){ { sizeof(int), SPA_TYPE_Fd }, fd }
#define SPA_POD_INIT_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(fd);
const struct spa_pod_fd p = SPA_POD_INIT_Fd(fd);
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Rectangle(val) (struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, val }
#define SPA_POD_INIT_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(SPA_RECTANGLE(width, height));
const struct spa_pod_rectangle p = SPA_POD_INIT_Rectangle(SPA_RECTANGLE(width, height));
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Fraction(val) (struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, val }
#define SPA_POD_INIT_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(SPA_FRACTION(num, denom));
const struct spa_pod_fraction p = SPA_POD_INIT_Fraction(SPA_FRACTION(num, denom));
return spa_pod_builder_primitive(builder, &p.pod);
}
#define SPA_POD_Array(ctype, child_type, n_vals, ...) \
(struct { struct spa_pod_array array; ctype vals[n_vals];}) \
{ { { n_vals * sizeof(ctype) + sizeof(struct spa_pod_array_body), SPA_TYPE_Array }, \
{ { sizeof(ctype), child_type } } }, { __VA_ARGS__ } }
static inline uint32_t
spa_pod_builder_push_array(struct spa_pod_builder *builder)
{
@ -389,13 +378,13 @@ spa_pod_builder_array(struct spa_pod_builder *builder,
return ref;
}
#define SPA_POD_CHOICE_BODY_INIT(type, flags, child_size, child_type) \
#define SPA_POD_INIT_CHOICE_BODY(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, ...) \
#define SPA_POD_INIT_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__ } }
{ type, 0, { sizeof(ctype), child_type } } }, { __VA_ARGS__ } }
static inline uint32_t
spa_pod_builder_push_choice(struct spa_pod_builder *builder, uint32_t type, uint32_t flags)
@ -408,28 +397,28 @@ spa_pod_builder_push_choice(struct spa_pod_builder *builder, uint32_t type, uint
sizeof(p) - sizeof(struct spa_pod)));
}
#define SPA_POD_Struct(size) (struct spa_pod_struct){ { size, SPA_TYPE_Struct } }
#define SPA_POD_INIT_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);
const struct spa_pod_struct p = SPA_POD_INIT_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__ }
#define SPA_POD_INIT_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);
SPA_POD_INIT_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) \
#define SPA_POD_INIT_Prop(key,flags,size,type) \
(struct spa_pod_prop){ key, flags, { size, type } }
static inline uint32_t
@ -439,14 +428,14 @@ spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t fla
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__ }
#define SPA_POD_INIT_Sequence(size,unit) \
(struct spa_pod_sequence){ { size, SPA_TYPE_Sequence}, {unit, 0 } }
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(sizeof(struct spa_pod_sequence_body), unit);
SPA_POD_INIT_Sequence(sizeof(struct spa_pod_sequence_body), unit);
return spa_pod_builder_push(builder, &p.pod,
spa_pod_builder_raw(builder, &p, sizeof(p)));
}
@ -556,6 +545,9 @@ do { \
spa_pod_builder_fd(builder, va_arg(args, int)); \
break; \
case 'P': \
case 'O': \
case 'T': \
case 'V': \
{ \
struct spa_pod *pod = va_arg(args, struct spa_pod *); \
if (pod == NULL) \
@ -568,12 +560,30 @@ do { \
} while(false)
static inline void *
spa_pod_builder_addv(struct spa_pod_builder *builder,
const char *format, va_list args)
spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
{
while (format) {
const char *format = "";
void *top = NULL;
do {
int n_values = 1;
bool do_pop = false;
if (SPA_FLAG_CHECK(builder->state.flags, SPA_POD_BUILDER_FLAG_OBJECT)) {
uint32_t key = va_arg(args, uint32_t);
if (key == 0)
break;
if (key != SPA_ID_INVALID)
spa_pod_builder_prop(builder, key, 0);
}
else if (SPA_FLAG_CHECK(builder->state.flags, SPA_POD_BUILDER_FLAG_SEQUENCE)) {
uint32_t offset = va_arg(args, uint32_t);
uint32_t type = va_arg(args, uint32_t);
if (type == 0)
break;
if (type != SPA_ID_INVALID)
spa_pod_builder_control_header(builder, offset, type);
}
again:
switch (*format) {
case '{':
{
@ -594,13 +604,6 @@ spa_pod_builder_addv(struct spa_pod_builder *builder,
spa_pod_builder_push_sequence(builder, unit);
break;
}
case '.':
{
uint32_t offset = va_arg(args, uint32_t);
uint32_t type = va_arg(args, uint32_t);
spa_pod_builder_control_header(builder, offset, type);
break;
}
case '?':
{
uint32_t choice, flags = 0;
@ -616,165 +619,119 @@ spa_pod_builder_addv(struct spa_pod_builder *builder,
do_pop = true;
goto do_collect;
}
case ':':
{
uint32_t key;
key = va_arg(args, uint32_t);
spa_pod_builder_prop(builder, key, 0);
break;
}
case ']': case ')': case '>': case '}':
spa_pod_builder_pop(builder);
top = spa_pod_builder_pop(builder);
break;
case ' ': case '\n': case '\t': case '\r':
break;
case '\0':
format = va_arg(args, const char *);
if ((format = va_arg(args, const char *)) != NULL)
goto again;
continue;
default:
do_collect:
while (n_values-- > 0)
SPA_POD_BUILDER_COLLECT(builder, *format, args);
if (do_pop)
spa_pod_builder_pop(builder);
break;;
top = spa_pod_builder_pop(builder);
break;
}
if (*format != '\0')
format++;
}
return spa_pod_builder_deref_checked(builder, builder->frame[builder->state.depth].ref,true);
} while (format != NULL);
return top;
}
static inline void *spa_pod_builder_add(struct spa_pod_builder *builder, const char *format, ...)
static inline void *spa_pod_builder_add(struct spa_pod_builder *builder, ...)
{
void *res;
va_list args;
va_start(args, format);
res = spa_pod_builder_addv(builder, format, args);
va_start(args, builder);
res = spa_pod_builder_addv(builder, args);
va_end(args);
return res;
}
static inline void spa_pod_builder_prop_val(struct spa_pod_builder *builder,
uint32_t key, void *pod)
{
spa_pod_builder_prop(builder, key, 0);
spa_pod_builder_primitive(builder, (const struct spa_pod *) pod);
}
#define SPA_POD_Object(type,id,...) \
"{", type, id, ##__VA_ARGS__, SPA_ID_INVALID, "}"
static inline void spa_pod_builder_propsv(struct spa_pod_builder *builder,
uint32_t key, va_list args)
{
while (key) {
spa_pod_builder_prop_val(builder, key, va_arg(args, struct spa_pod *));
key = va_arg(args, uint32_t);
}
}
#define SPA_POD_Prop(key,...) \
key, ##__VA_ARGS__
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(...) \
#define SPA_POD_Struct(...) \
"[", ##__VA_ARGS__, "]"
#define SPA_POD_PROP(key,spec,value,...) \
":", key, spec, value, ##__VA_ARGS__
#define SPA_POD_Sequence(unit,...) \
"<", unit, ##__VA_ARGS__, 0, SPA_ID_INVALID, ">"
#define SPA_POD_SEQUENCE(unit,...) \
"<", unit, ##__VA_ARGS__, ">"
#define SPA_POD_CONTROL(offset,type,...) \
".", offset, type, ##__VA_ARGS__
#define SPA_POD_Control(offset,type,...) \
offset, type, ##__VA_ARGS__
#define spa_pod_builder_add_object(b,type,id,...) \
spa_pod_builder_add(b, SPA_POD_OBJECT(type,id,##__VA_ARGS__), NULL)
spa_pod_builder_add(b, SPA_POD_Object(type,id,##__VA_ARGS__), NULL)
#define spa_pod_builder_add_struct(b,...) \
spa_pod_builder_add(b, SPA_POD_STRUCT(__VA_ARGS__), NULL)
spa_pod_builder_add(b, SPA_POD_Struct(__VA_ARGS__), NULL)
#define spa_pod_builder_add_sequence(b,unit,...) \
spa_pod_builder_add(b, SPA_POD_SEQUENCE(unit,__VA_ARGS__), NULL)
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_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_Bool(val) "b", val
#define SPA_POD_CHOICE_Bool(def) "?eb", SPA_CHOICE_BOOL(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_Id(val) "I", val
#define SPA_POD_CHOICE_ENUM_Id(n_vals,...) "?eI", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#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_Int(val) "i", val
#define SPA_POD_CHOICE_ENUM_Int(n_vals,...) "?ei", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Int(def,min,max) "?ri", SPA_CHOICE_RANGE(def, min, max)
#define SPA_POD_CHOICE_STEP_Int(def,min,max,step) "?si", SPA_CHOICE_STEP(def, min, max, step)
#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_Long(val) "l", val
#define SPA_POD_CHOICE_ENUM_Long(n_vals,...) "?el", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Long(def,min,max) "?rl", SPA_CHOICE_RANGE(def, min, max)
#define SPA_POD_CHOICE_STEP_Long(def,min,max,step) "?sl", SPA_CHOICE_STEP(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_Float(val) "f", val
#define SPA_POD_CHOICE_ENUM_Float(n_vals,...) "?ef", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Float(def,min,max) "?rf", SPA_CHOICE_RANGE(def, min, max)
#define SPA_POD_CHOICE_STEP_Float(def,min,max,step) "?sf", SPA_CHOICE_STEP(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_Double(val) "d", val
#define SPA_POD_CHOICE_ENUM_Double(n_vals,...) "?ed", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Double(def,min,max) "?rd", SPA_CHOICE_RANGE(def, min, max)
#define SPA_POD_CHOICE_STEP_Double(def,min,max,step) "?sd", SPA_CHOICE_STEP(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))
#define SPA_POD_String(val) "s",val
#define SPA_POD_Stringn(val,len) "S",val,len
#define SPA_POD_Bytes(val,len) "z",val,len
#define SPA_POD_Rectangle(val) "R", val
#define SPA_POD_CHOICE_ENUM_Rectangle(n_vals,...) "?eR", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Rectangle(def,min,max) "?rR", SPA_CHOICE_RANGE((def),(min),(max))
#define SPA_POD_CHOICE_STEP_Rectangle(def,min,max,step) "?sR", SPA_CHOICE_STEP((def),(min),(max),(step))
#define SPA_POD_Fraction(val) "F", val
#define SPA_POD_CHOICE_ENUM_Fraction(n_vals,...) "?eF", SPA_CHOICE_ENUM(n_vals, __VA_ARGS__)
#define SPA_POD_CHOICE_RANGE_Fraction(def,min,max) "?rF", SPA_CHOICE_RANGE((def),(min),(max))
#define SPA_POD_CHOICE_STEP_Fraction(def,min,max,step) "?sF", SPA_CHOICE_STEP(def, min, max, step)
#define SPA_POD_Array(csize,ctype,n_vals,vals) "a", csize,ctype,n_vals,vals
#define SPA_POD_Pointer(type,val) "p", type,val
#define SPA_POD_Fd(val) "h", val
#define SPA_POD_Pod(val) "P", val
#define SPA_POD_PodObject(val) "O", val
#define SPA_POD_PodStruct(val) "T", val
#define SPA_POD_PodChoice(val) "V", val
#ifdef __cplusplus
} /* extern "C" */

View file

@ -36,6 +36,9 @@ extern "C" {
struct spa_pod_parser {
int depth;
#define SPA_POD_PARSER_FLAG_OBJECT (1<<0)
#define SPA_POD_PARSER_FLAG_STRUCT (1<<1)
uint32_t flags;
struct spa_pod_iter iter[SPA_POD_MAX_DEPTH];
};
@ -43,6 +46,7 @@ static inline void spa_pod_parser_init(struct spa_pod_parser *parser,
const void *data, uint32_t size, uint32_t offset)
{
parser->depth = 0;
parser->flags = 0;
spa_pod_iter_init(&parser->iter[0], data, size, offset);
}
@ -100,9 +104,9 @@ static inline bool spa_pod_parser_can_collect(struct spa_pod *pod, char type)
}
}
#define SPA_POD_PARSER_COLLECT(pod,type,args) \
#define SPA_POD_PARSER_COLLECT(pod,_type,args) \
do { \
switch (type) { \
switch (_type) { \
case 'b': \
*va_arg(args, int*) = SPA_POD_VALUE(struct spa_pod_bool, pod); \
break; \
@ -152,7 +156,8 @@ do { \
{ \
struct spa_pod_pointer_body *b = \
(struct spa_pod_pointer_body *) SPA_POD_BODY(pod); \
*(va_arg(args, const void **)) = b->value; \
*(va_arg(args, uint32_t *)) = b->type; \
*(va_arg(args, const void **)) = b->value; \
break; \
} \
case 'h': \
@ -171,13 +176,14 @@ do { \
} \
} while(false)
#define SPA_POD_PARSER_SKIP(type,args) \
#define SPA_POD_PARSER_SKIP(_type,args) \
do { \
switch (type) { \
switch (_type) { \
case 'S': \
va_arg(args, void*); \
va_arg(args, char*); \
va_arg(args, uint32_t); \
break; \
case 'p': \
case 'z': \
va_arg(args, void**); \
/* fallthrough */ \
@ -191,7 +197,6 @@ do { \
case 'R': \
case 'F': \
case 'B': \
case 'p': \
case 'h': \
case 'V': \
case 'P': \
@ -202,69 +207,85 @@ do { \
} \
} while(false)
static inline int spa_pod_parser_getv(struct spa_pod_parser *parser,
const char *format, va_list args)
static inline int spa_pod_parser_getv(struct spa_pod_parser *parser, va_list args)
{
struct spa_pod *pod = NULL, *current;
struct spa_pod_prop *prop = NULL;
bool required = true, suppress = false, skip = false;
bool required = true, skip = false;
struct spa_pod_iter *it = &parser->iter[parser->depth];
const char *format = "";
uint32_t *idp;
current = pod = spa_pod_iter_current(it);
while (format) {
do {
again:
switch (*format) {
case '{':
if (pod == NULL || SPA_POD_TYPE(pod) != SPA_TYPE_Object)
return -EINVAL;
break;
if (va_arg(args, uint32_t) != SPA_POD_OBJECT_TYPE(pod))
return -EINVAL;
if ((idp = va_arg(args, uint32_t*)) != NULL)
*idp = SPA_POD_OBJECT_ID(pod);
parser->flags = SPA_POD_PARSER_FLAG_OBJECT;
goto enter;
case '[':
if (pod == NULL || SPA_POD_TYPE(pod) != SPA_TYPE_Struct)
return -EINVAL;
parser->flags = SPA_POD_PARSER_FLAG_STRUCT;
enter:
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_struct));
goto read_pod;
case ']':
case '}':
if (current != NULL)
return -EINVAL;
if (--parser->depth < 0)
return -EINVAL;
/* fallthrough */
case '}':
it = &parser->iter[parser->depth];
if (SPA_POD_TYPE(it->data) == SPA_TYPE_Object)
parser->flags = SPA_POD_PARSER_FLAG_OBJECT;
else if (SPA_POD_TYPE(it->data) == SPA_TYPE_Struct)
parser->flags = SPA_POD_PARSER_FLAG_STRUCT;
else
parser->flags = 0;
current = spa_pod_iter_current(it);
spa_pod_iter_advance(it, current);
goto read_pod;
case '\0':
format = va_arg(args, char *);
if (parser->flags & SPA_POD_PARSER_FLAG_OBJECT) {
const struct spa_pod *obj = (const struct spa_pod *) it->data;
uint32_t key = va_arg(args, uint32_t);
if (key == 0) {
format = NULL;
continue;
}
if (key != SPA_ID_INVALID) {
prop = spa_pod_find_prop(obj, key);
if (prop != NULL)
pod = &prop->value;
else
pod = NULL;
it->offset = it->size;
current = NULL;
required = true;
}
}
if ((format = va_arg(args, char *)) != NULL)
goto again;
continue;
case ' ': case '\n': case '\t': case '\r':
break;
case '?':
required = false;
break;
case '*':
suppress = true;
break;
case ':':
{
uint32_t key = va_arg(args, uint32_t);
const struct spa_pod *obj = (const struct spa_pod *) parser->iter[parser->depth].data;
prop = spa_pod_find_prop(obj, key);
if (prop != NULL)
pod = &prop->value;
else
pod = NULL;
it->offset = it->size;
current = NULL;
required = true;
break;
}
case 'V':
pod = (struct spa_pod *) prop;
if (pod == NULL && required)
@ -280,9 +301,7 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser,
if (pod->type == SPA_TYPE_Choice)
pod = SPA_POD_CHOICE_CHILD(pod);
if (suppress)
suppress = false;
else if (skip)
if (skip)
SPA_POD_PARSER_SKIP(*format, args);
else
SPA_POD_PARSER_COLLECT(pod, *format, args);
@ -296,28 +315,56 @@ static inline int spa_pod_parser_getv(struct spa_pod_parser *parser,
break;
}
format++;
}
} while (format != NULL);
return 0;
}
static inline int spa_pod_parser_get(struct spa_pod_parser *parser,
const char *format, ...)
static inline int spa_pod_parser_get(struct spa_pod_parser *parser, ...)
{
int res;
va_list args;
va_start(args, format);
res = spa_pod_parser_getv(parser, format, args);
va_start(args, parser);
res = spa_pod_parser_getv(parser, args);
va_end(args);
return res;
}
#define spa_pod_object_parse(pod,...) \
#define SPA_POD_OPT_Bool(val) "?" SPA_POD_Bool(val)
#define SPA_POD_OPT_Id(val) "?" SPA_POD_Id(val)
#define SPA_POD_OPT_Int(val) "?" SPA_POD_Int(val)
#define SPA_POD_OPT_Long(val) "?" SPA_POD_Long(val)
#define SPA_POD_OPT_Float(val) "?" SPA_POD_Float(val)
#define SPA_POD_OPT_Double(val) "?" SPA_POD_Double(val)
#define SPA_POD_OPT_String(val) "?" SPA_POD_String(val)
#define SPA_POD_OPT_Stringn(val,len) "?" SPA_POD_Stringn(val,len)
#define SPA_POD_OPT_Bytes(val,len) "?" SPA_POD_Bytes(val,len)
#define SPA_POD_OPT_Rectangle(val) "?" SPA_POD_Rectangle(val)
#define SPA_POD_OPT_Fraction(val) "?" SPA_POD_Fraction(val)
#define SPA_POD_OPT_Pointer(type,val) "?" SPA_POD_Pointer(type,val)
#define SPA_POD_OPT_Fd(val) "?" SPA_POD_Fd(val)
#define SPA_POD_OPT_Pod(val) "?" SPA_POD_Pod(val)
#define spa_pod_parser_get_object(p,type,id,...) \
spa_pod_parser_get(p, SPA_POD_Object(type,id,##__VA_ARGS__), NULL)
#define spa_pod_parser_get_struct(p,...) \
spa_pod_parser_get(p, SPA_POD_Struct(__VA_ARGS__), NULL)
#define spa_pod_parse_object(pod,type,id,...) \
({ \
struct spa_pod_parser _p; \
spa_pod_parser_pod(&_p, pod); \
spa_pod_parser_get(&_p, "{", ##__VA_ARGS__, NULL); \
spa_pod_parser_get_object(&_p,type,id,##__VA_ARGS__); \
})
#define spa_pod_parse_struct(pod,...) \
({ \
struct spa_pod_parser _p; \
spa_pod_parser_pod(&_p, pod); \
spa_pod_parser_get_struct(&_p,##__VA_ARGS__); \
})
static inline int spa_pod_is_bool(struct spa_pod *pod)