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

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