Loading...
Searching...
No Matches
tag-utils.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_PARAM_TAG_UTILS_H
#define SPA_PARAM_TAG_UTILS_H
#include <float.h>
#include <spa/utils/dict.h>
#include <spa/pod/builder.h>
#include <spa/pod/iter.h>
#include <spa/pod/parser.h>
#include <spa/pod/compare.h>
#include <spa/param/tag.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_TAG_UTILS
#ifdef SPA_API_IMPL
#define SPA_API_TAG_UTILS SPA_API_IMPL
#else
#define SPA_API_TAG_UTILS static inline
#endif
#endif
SPA_API_TAG_UTILS int
spa_tag_compare(const struct spa_pod *a, const struct spa_pod *b)
{
return spa_pod_memcmp(a, b);
}
SPA_API_TAG_UTILS int
spa_tag_parse(const struct spa_pod *tag, struct spa_tag_info *info, void **state)
{
int res;
const struct spa_pod_object *obj = (const struct spa_pod_object*)tag;
const struct spa_pod_prop *first, *start, *cur;
spa_zero(*info);
if ((res = spa_pod_parse_object(tag,
SPA_TYPE_OBJECT_ParamTag, NULL,
SPA_PARAM_TAG_direction, SPA_POD_Id(&info->direction))) < 0)
return res;
first = spa_pod_prop_first(&obj->body);
start = *state ? spa_pod_prop_next((struct spa_pod_prop*)*state) : first;
res = 0;
for (cur = start; spa_pod_prop_is_inside(&obj->body, obj->pod.size, cur);
cur = spa_pod_prop_next(cur)) {
if (cur->key == SPA_PARAM_TAG_info) {
info->info = &cur->value;
*state = (void*)cur;
return 1;
}
}
return 0;
}
SPA_API_TAG_UTILS int
spa_tag_info_parse(const struct spa_tag_info *info, struct spa_dict *dict, struct spa_dict_item *items)
{
struct spa_pod_parser prs;
uint32_t n, n_items;
const char *key, *value;
struct spa_pod_frame f[1];
spa_pod_parser_pod(&prs, info->info);
if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
spa_pod_parser_get_int(&prs, (int32_t*)&n_items) < 0)
return -EINVAL;
if (items == NULL) {
dict->n_items = n_items;
return 0;
}
n_items = SPA_MIN(dict->n_items, n_items);
for (n = 0; n < n_items; n++) {
if (spa_pod_parser_get(&prs,
SPA_POD_String(&key),
SPA_POD_String(&value),
NULL) < 0)
break;
if (key == NULL || value == NULL)
return -EINVAL;
items[n].key = key;
items[n].value = value;
}
dict->items = items;
spa_pod_parser_pop(&prs, &f[0]);
return 0;
}
SPA_API_TAG_UTILS void
spa_tag_build_start(struct spa_pod_builder *builder, struct spa_pod_frame *f,
uint32_t id, enum spa_direction direction)
{
spa_pod_builder_push_object(builder, f, SPA_TYPE_OBJECT_ParamTag, id);
spa_pod_builder_add(builder,
SPA_PARAM_TAG_direction, SPA_POD_Id(direction),
0);
}
SPA_API_TAG_UTILS void
spa_tag_build_add_info(struct spa_pod_builder *builder, const struct spa_pod *info)
{
spa_pod_builder_add(builder,
SPA_PARAM_TAG_info, SPA_POD_Pod(info),
0);
}
SPA_API_TAG_UTILS void
spa_tag_build_add_dict(struct spa_pod_builder *builder, const struct spa_dict *dict)
{
uint32_t i, n_items;
struct spa_pod_frame f;
n_items = dict ? dict->n_items : 0;
spa_pod_builder_prop(builder, SPA_PARAM_TAG_info, SPA_POD_PROP_FLAG_HINT_DICT);
spa_pod_builder_push_struct(builder, &f);
spa_pod_builder_int(builder, n_items);
for (i = 0; i < n_items; i++) {
spa_pod_builder_string(builder, dict->items[i].key);
spa_pod_builder_string(builder, dict->items[i].value);
}
spa_pod_builder_pop(builder, &f);
}
SPA_API_TAG_UTILS struct spa_pod *
spa_tag_build_end(struct spa_pod_builder *builder, struct spa_pod_frame *f)
{
return (struct spa_pod*)spa_pod_builder_pop(builder, f);
}
*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_PARAM_TAG_UTILS_H */
builder.h
spa/pod/builder.h
compare.h
spa/pod/compare.h
res
uint32_t int int res
Definition core.h:433
spa_tag_build_start
SPA_API_TAG_UTILS void spa_tag_build_start(struct spa_pod_builder *builder, struct spa_pod_frame *f, uint32_t id, enum spa_direction direction)
Definition tag-utils.h:112
spa_tag_build_add_info
SPA_API_TAG_UTILS void spa_tag_build_add_info(struct spa_pod_builder *builder, const struct spa_pod *info)
Definition tag-utils.h:122
spa_tag_build_add_dict
SPA_API_TAG_UTILS void spa_tag_build_add_dict(struct spa_pod_builder *builder, const struct spa_dict *dict)
Definition tag-utils.h:130
spa_tag_build_end
SPA_API_TAG_UTILS struct spa_pod * spa_tag_build_end(struct spa_pod_builder *builder, struct spa_pod_frame *f)
Definition tag-utils.h:148
SPA_API_TAG_UTILS
#define SPA_API_TAG_UTILS
Definition tag-utils.h:37
spa_tag_info_parse
SPA_API_TAG_UTILS int spa_tag_info_parse(const struct spa_tag_info *info, struct spa_dict *dict, struct spa_dict_item *items)
Definition tag-utils.h:77
spa_tag_parse
SPA_API_TAG_UTILS int spa_tag_parse(const struct spa_pod *tag, struct spa_tag_info *info, void **state)
Definition tag-utils.h:48
spa_tag_compare
SPA_API_TAG_UTILS int spa_tag_compare(const struct spa_pod *a, const struct spa_pod *b)
Definition tag-utils.h:42
SPA_PARAM_TAG_direction
@ SPA_PARAM_TAG_direction
direction, input/output (Id enum spa_direction)
Definition tag.h:27
SPA_PARAM_TAG_info
@ SPA_PARAM_TAG_info
Struct( Int: n_items (String: key ...
Definition tag.h:28
spa_pod_builder_pop
SPA_API_POD_BUILDER void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:213
spa_pod_builder_int
SPA_API_POD_BUILDER int spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val)
Definition builder.h:296
spa_pod_prop_first
SPA_API_POD_ITER struct spa_pod_prop * spa_pod_prop_first(const struct spa_pod_object_body *body)
Definition iter.h:51
SPA_POD_String
#define SPA_POD_String(val)
Definition vararg.h:102
spa_pod_parser_get_int
SPA_API_POD_PARSER int spa_pod_parser_get_int(struct spa_pod_parser *parser, int32_t *value)
Definition parser.h:236
spa_pod_parser_pop
SPA_API_POD_PARSER int spa_pod_parser_pop(struct spa_pod_parser *parser, struct spa_pod_frame *frame)
Definition parser.h:204
spa_pod_parser_pod
SPA_API_POD_PARSER void spa_pod_parser_pod(struct spa_pod_parser *parser, const struct spa_pod *pod)
Definition parser.h:60
spa_pod_builder_string
SPA_API_POD_BUILDER int spa_pod_builder_string(struct spa_pod_builder *builder, const char *str)
Definition builder.h:351
spa_pod_prop_is_inside
SPA_API_POD_ITER bool spa_pod_prop_is_inside(const struct spa_pod_object_body *body, uint32_t size, const struct spa_pod_prop *iter)
Definition iter.h:56
spa_pod_builder_push_struct
SPA_API_POD_BUILDER int spa_pod_builder_push_struct(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:462
spa_pod_builder_add
SPA_API_POD_BUILDER int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition builder.h:713
SPA_POD_Id
#define SPA_POD_Id(val)
Definition vararg.h:53
spa_pod_builder_push_object
SPA_API_POD_BUILDER int spa_pod_builder_push_object(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t type, uint32_t id)
Definition builder.h:475
spa_pod_parser_push_struct
SPA_API_POD_PARSER int spa_pod_parser_push_struct(struct spa_pod_parser *parser, struct spa_pod_frame *frame)
Definition parser.h:400
spa_pod_prop_next
SPA_API_POD_ITER struct spa_pod_prop * spa_pod_prop_next(const struct spa_pod_prop *iter)
Definition iter.h:65
spa_pod_parser_get
SPA_API_POD_PARSER int spa_pod_parser_get(struct spa_pod_parser *parser,...)
Definition parser.h:849
SPA_POD_PROP_FLAG_HINT_DICT
#define SPA_POD_PROP_FLAG_HINT_DICT
contains a dictionary struct as (Struct( Int : n_items,...
Definition pod.h:235
spa_pod_parse_object
#define spa_pod_parse_object(pod, type, id,...)
Definition parser.h:935
SPA_POD_Pod
#define SPA_POD_Pod(val)
Definition vararg.h:136
spa_pod_memcmp
SPA_API_POD_COMPARE int spa_pod_memcmp(const struct spa_pod *a, const struct spa_pod *b)
Definition compare.h:90
spa_pod_builder_prop
SPA_API_POD_BUILDER int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition builder.h:490
SPA_TYPE_OBJECT_ParamTag
@ SPA_TYPE_OBJECT_ParamTag
Definition type.h:97
SPA_MIN
#define SPA_MIN(a, b)
Definition defs.h:165
spa_zero
#define spa_zero(x)
Definition defs.h:512
spa_direction
spa_direction
Definition defs.h:106
iter.h
spa/pod/iter.h
parser.h
spa/pod/parser.h
spa_dict_item
Definition dict.h:41
spa_dict_item::key
const char * key
Definition dict.h:42
spa_dict_item::value
const char * value
Definition dict.h:43
spa_dict
Definition dict.h:51
spa_dict::items
const struct spa_dict_item * items
Definition dict.h:56
spa_dict::n_items
uint32_t n_items
Definition dict.h:55
spa_pod_builder
Definition builder.h:63
spa_pod_frame
Definition body.h:38
spa_pod_object
Definition pod.h:202
spa_pod_object::pod
struct spa_pod pod
Definition pod.h:203
spa_pod_object::body
struct spa_pod_object_body body
Definition pod.h:204
spa_pod_parser
Definition parser.h:44
spa_pod_prop
Definition pod.h:227
spa_pod_prop::key
uint32_t key
key of property, list of valid keys depends on the object type
Definition pod.h:228
spa_pod_prop::value
struct spa_pod value
Definition pod.h:249
spa_pod
Definition pod.h:57
spa_pod::size
uint32_t size
Definition pod.h:58
spa_tag_info
helper structure for managing tag objects
Definition tag.h:36
tag.h
spa/param/tag.h
dict.h
spa/utils/dict.h