5#ifndef SPA_POD_BUILDER_H
6#define SPA_POD_BUILDER_H
29#define SPA_POD_BUILDER_FLAG_BODY (1<<0)
30#define SPA_POD_BUILDER_FLAG_FIRST (1<<1)
38#define SPA_VERSION_POD_BUILDER_CALLBACKS 0
41 int (*
overflow) (
void *data, uint32_t size);
52#define SPA_POD_BUILDER_INIT(buffer,size) ((struct spa_pod_builder){ (buffer), (size), 0, {0}, {0} })
72 builder->
state = *state;
86 if (offset + 8 <=
size) {
129 overflow, 0,
offset + size);
131 if (res == 0 && data)
197#define SPA_POD_INIT(size,type) ((struct spa_pod) { (size), (type) })
199#define SPA_POD_INIT_None() SPA_POD_INIT(0, SPA_TYPE_None)
214#define SPA_POD_INIT_Bool(val) ((struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, (val) ? 1 : 0, 0 })
222#define SPA_POD_INIT_Id(val) ((struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (val), 0 })
230#define SPA_POD_INIT_Int(val) ((struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (val), 0 })
238#define SPA_POD_INIT_Long(val) ((struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (val) })
246#define SPA_POD_INIT_Float(val) ((struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, (val), 0 })
254#define SPA_POD_INIT_Double(val) ((struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, (val) })
262#define SPA_POD_INIT_String(len) ((struct spa_pod_string){ { (len), SPA_TYPE_String } })
288 uint32_t len = str ? strlen(str) : 0;
292#define SPA_POD_INIT_Bytes(len) ((struct spa_pod_bytes){ { (len), SPA_TYPE_Bytes } })
312#define SPA_POD_INIT_Pointer(type,value) ((struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { (type), 0, (value) } })
321#define SPA_POD_INIT_Fd(fd) ((struct spa_pod_fd){ { sizeof(int64_t), SPA_TYPE_Fd }, (fd) })
329#define SPA_POD_INIT_Rectangle(val) ((struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, (val) })
338#define SPA_POD_INIT_Fraction(val) ((struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, (val) })
361 uint32_t child_size, uint32_t child_type, uint32_t n_elems,
const void *elems)
365 {{child_size, child_type}}
373#define SPA_POD_INIT_CHOICE_BODY(type, flags, child_size, child_type) \
374 ((struct spa_pod_choice_body) { (type), (flags), { (child_size), (child_type) }})
376#define SPA_POD_INIT_Choice(type, ctype, child_type, n_vals, ...) \
377 ((struct { struct spa_pod_choice choice; ctype vals[(n_vals)];}) \
378 { { { (n_vals) * sizeof(ctype) + sizeof(struct spa_pod_choice_body), SPA_TYPE_Choice }, \
379 { (type), 0, { sizeof(ctype), (child_type) } } }, { __VA_ARGS__ } })
383 uint32_t type, uint32_t flags)
394#define SPA_POD_INIT_Struct(size) ((struct spa_pod_struct){ { (size), SPA_TYPE_Struct } })
406#define SPA_POD_INIT_Object(size,type,id,...) ((struct spa_pod_object){ { (size), SPA_TYPE_Object }, { (type), (id) }, ##__VA_ARGS__ })
410 uint32_t type, uint32_t
id)
420#define SPA_POD_INIT_Prop(key,flags,size,type) \
421 ((struct spa_pod_prop){ (key), (flags), { (size), (type) } })
426 const struct { uint32_t key; uint32_t flags; } p = { key, flags };
430#define SPA_POD_INIT_Sequence(size,unit) \
431 ((struct spa_pod_sequence){ { (size), SPA_TYPE_Sequence}, {(unit), 0 } })
447 const struct { uint32_t offset; uint32_t type; } p = { offset, type };
468#define SPA_POD_BUILDER_COLLECT(builder,type,args) \
472 spa_pod_builder_bool(builder, !!va_arg(args, int)); \
475 spa_pod_builder_id(builder, va_arg(args, uint32_t)); \
478 spa_pod_builder_int(builder, va_arg(args, int)); \
481 spa_pod_builder_long(builder, va_arg(args, int64_t)); \
484 spa_pod_builder_float(builder, (float)va_arg(args, double)); \
487 spa_pod_builder_double(builder, va_arg(args, double)); \
491 char *strval = va_arg(args, char *); \
492 if (strval != NULL) { \
493 size_t len = strlen(strval); \
494 spa_pod_builder_string_len(builder, strval, len); \
497 spa_pod_builder_none(builder); \
502 char *strval = va_arg(args, char *); \
503 size_t len = va_arg(args, int); \
504 spa_pod_builder_string_len(builder, strval, len); \
509 void *ptr = va_arg(args, void *); \
510 int len = va_arg(args, int); \
511 spa_pod_builder_bytes(builder, ptr, len); \
516 struct spa_rectangle *rectval = \
517 va_arg(args, struct spa_rectangle *); \
518 spa_pod_builder_rectangle(builder, \
519 rectval->width, rectval->height); \
524 struct spa_fraction *fracval = \
525 va_arg(args, struct spa_fraction *); \
526 spa_pod_builder_fraction(builder, fracval->num, fracval->denom);\
531 int child_size = va_arg(args, int); \
532 int child_type = va_arg(args, int); \
533 int n_elems = va_arg(args, int); \
534 void *elems = va_arg(args, void *); \
535 spa_pod_builder_array(builder, child_size, \
536 child_type, n_elems, elems); \
541 int t = va_arg(args, uint32_t); \
542 spa_pod_builder_pointer(builder, t, va_arg(args, void *)); \
546 spa_pod_builder_fd(builder, va_arg(args, int)); \
553 struct spa_pod *pod = va_arg(args, struct spa_pod *); \
555 spa_pod_builder_none(builder); \
557 spa_pod_builder_primitive(builder, pod); \
579 uint32_t key = va_arg(args, uint32_t);
587 uint32_t
offset = va_arg(args, uint32_t);
588 uint32_t type = va_arg(args, uint32_t);
597 if ((format = va_arg(args,
const char *)) == NULL)
600 choice = *format ==
'?';
608 n_values = va_arg(args,
int);
610 while (n_values-- > 0)
626 va_start(args, builder);
633#define spa_pod_builder_add_object(b,type,id,...) \
635 struct spa_pod_builder *_b = (b); \
636 struct spa_pod_frame _f; \
637 spa_pod_builder_push_object(_b, &_f, type, id); \
638 spa_pod_builder_add(_b, ##__VA_ARGS__, 0); \
639 spa_pod_builder_pop(_b, &_f); \
642#define spa_pod_builder_add_struct(b,...) \
644 struct spa_pod_builder *_b = (b); \
645 struct spa_pod_frame _f; \
646 spa_pod_builder_push_struct(_b, &_f); \
647 spa_pod_builder_add(_b, ##__VA_ARGS__, NULL); \
648 spa_pod_builder_pop(_b, &_f); \
651#define spa_pod_builder_add_sequence(b,unit,...) \
653 struct spa_pod_builder *_b = (b); \
654 struct spa_pod_frame _f; \
655 spa_pod_builder_push_sequence(_b, &_f, unit); \
656 spa_pod_builder_add(_b, ##__VA_ARGS__, 0, 0); \
657 spa_pod_builder_pop(_b, &_f); \
#define SPA_CALLBACKS_INIT(_funcs, _data)
Initialize the set of functions funcs as a spa_callbacks, together with _data.
Definition hook.h:134
#define spa_callbacks_call_res(callbacks, type, res, method, vers,...)
Invoke method named method in the callbacks.
Definition hook.h:207
#define SPA_POD_INIT_Double(val)
Definition builder.h:272
static void * spa_pod_builder_reserve_bytes(struct spa_pod_builder *builder, uint32_t len)
Definition builder.h:324
static int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition builder.h:450
#define SPA_POD_INIT_None()
Definition builder.h:211
#define SPA_POD_INIT(size, type)
Definition builder.h:208
static int spa_pod_builder_string(struct spa_pod_builder *builder, const char *str)
Definition builder.h:305
static int spa_pod_builder_child(struct spa_pod_builder *builder, uint32_t size, uint32_t type)
Definition builder.h:219
static int spa_pod_builder_fraction(struct spa_pod_builder *builder, uint32_t num, uint32_t denom)
Definition builder.h:365
static int spa_pod_builder_rectangle(struct spa_pod_builder *builder, uint32_t width, uint32_t height)
Definition builder.h:355
static int spa_pod_builder_float(struct spa_pod_builder *builder, float val)
Definition builder.h:265
#define SPA_POD_BODY_CONST(pod)
Definition pod.h:41
#define SPA_POD_INIT_Object(size, type, id,...)
Definition builder.h:432
#define SPA_POD_BUILDER_FLAG_BODY
Definition builder.h:35
static void spa_pod_builder_push(struct spa_pod_builder *builder, struct spa_pod_frame *frame, const struct spa_pod *pod, uint32_t offset)
Definition builder.h:113
static int spa_pod_builder_double(struct spa_pod_builder *builder, double val)
Definition builder.h:274
static int spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition builder.h:284
#define SPA_POD_INIT_Sequence(size, unit)
Definition builder.h:456
#define SPA_POD_INIT_Rectangle(val)
Definition builder.h:352
static void spa_pod_builder_set_callbacks(struct spa_pod_builder *builder, const struct spa_pod_builder_callbacks *callbacks, void *data)
Definition builder.h:71
#define SPA_POD_INIT_Bool(val)
Definition builder.h:227
static int spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val)
Definition builder.h:238
static int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition builder.h:647
#define SPA_POD_INIT_String(len)
Definition builder.h:281
static int spa_pod_builder_fd(struct spa_pod_builder *builder, int64_t fd)
Definition builder.h:345
#define SPA_POD_BODY(pod)
Definition pod.h:39
static struct spa_pod * spa_pod_builder_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:105
static void spa_pod_builder_reset(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition builder.h:78
static int spa_pod_builder_none(struct spa_pod_builder *builder)
Definition builder.h:213
#define SPA_POD_INIT_Id(val)
Definition builder.h:236
static int spa_pod_builder_push_sequence(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t unit)
Definition builder.h:460
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:160
#define SPA_POD_BODY_SIZE(pod)
Definition pod.h:26
#define SPA_POD_BUILDER_INIT(buffer, size)
Definition builder.h:62
static void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:168
static int spa_pod_builder_pad(struct spa_pod_builder *builder, uint32_t size)
Definition builder.h:152
static int spa_pod_builder_string_len(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition builder.h:296
#define SPA_POD_INIT_Struct(size)
Definition builder.h:419
static int spa_pod_builder_push_array(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:372
static int spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p)
Definition builder.h:186
static uint32_t spa_choice_from_id(char id)
Definition builder.h:477
static int spa_pod_builder_push_struct(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:422
static int spa_pod_builder_control(struct spa_pod_builder *builder, uint32_t offset, uint32_t type)
Definition builder.h:471
static void spa_pod_builder_get_state(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition builder.h:65
static int spa_pod_builder_bool(struct spa_pod_builder *builder, bool val)
Definition builder.h:229
#define SPA_POD_BUILDER_COLLECT(builder, type, args)
Definition builder.h:494
static struct spa_pod * spa_pod_copy(const struct spa_pod *pod)
Copy a pod structure.
Definition builder.h:688
static int spa_pod_builder_raw(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:128
#define SPA_POD_INIT_Int(val)
Definition builder.h:245
static int spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len)
Definition builder.h:315
static int spa_pod_builder_push_choice(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t type, uint32_t flags)
Definition builder.h:406
static int spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val)
Definition builder.h:247
static void spa_pod_builder_init(struct spa_pod_builder *builder, void *data, uint32_t size)
Definition builder.h:87
static 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:435
#define SPA_POD_INIT_Float(val)
Definition builder.h:263
static int spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val)
Definition builder.h:256
#define SPA_POD_INIT_Bytes(len)
Definition builder.h:312
#define SPA_POD_INIT_Fd(fd)
Definition builder.h:343
static int spa_pod_builder_array(struct spa_pod_builder *builder, uint32_t child_size, uint32_t child_type, uint32_t n_elems, const void *elems)
Definition builder.h:384
#define SPA_POD_INIT_Long(val)
Definition builder.h:254
#define SPA_POD_INIT_Pointer(type, value)
Definition builder.h:333
#define SPA_POD_INIT_Fraction(val)
Definition builder.h:362
#define SPA_POD_BUILDER_FLAG_FIRST
Definition builder.h:37
#define SPA_POD_SIZE(pod)
Definition pod.h:30
static int spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
Definition builder.h:590
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:93
static int spa_pod_builder_pointer(struct spa_pod_builder *builder, uint32_t type, const void *val)
Definition builder.h:336
@ SPA_CHOICE_Step
range with step: default, min, max, step
Definition pod.h:149
@ SPA_CHOICE_None
no choice, first value is current
Definition pod.h:147
@ SPA_CHOICE_Flags
flags: default, possible flags,...
Definition pod.h:151
@ SPA_CHOICE_Range
range: default, min, max
Definition pod.h:148
@ SPA_CHOICE_Enum
list: default, alternative,...
Definition pod.h:150
@ SPA_TYPE_Object
Definition type.h:45
@ SPA_TYPE_None
Definition type.h:31
@ SPA_TYPE_Sequence
Definition type.h:46
@ SPA_TYPE_Choice
Definition type.h:49
@ SPA_TYPE_Array
Definition type.h:43
#define SPA_ROUND_UP_N(num, align)
Definition defs.h:342
#define SPA_FRACTION(num, denom)
Definition defs.h:136
#define SPA_FLAG_IS_SET(field, flag)
Definition defs.h:90
#define SPA_FALLTHROUGH
SPA_FALLTHROUGH is an annotation to suppress compiler warnings about switch cases that fall through w...
Definition defs.h:84
#define SPA_FLAG_CLEAR(field, flag)
Definition defs.h:94
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition defs.h:222
#define SPA_RECTANGLE(width, height)
Definition defs.h:115
Callbacks, contains the structure with functions and the data passed to the functions.
Definition hook.h:116
struct spa_pod pod
Definition pod.h:127
struct spa_pod pod
Definition pod.h:52
int(* overflow)(void *data, uint32_t size)
Definition builder.h:50
uint32_t version
Definition builder.h:48
uint32_t flags
Definition builder.h:38
uint32_t offset
Definition builder.h:33
struct spa_pod_frame * frame
Definition builder.h:39
uint32_t _padding
Definition builder.h:56
struct spa_callbacks callbacks
Definition builder.h:58
void * data
Definition builder.h:54
struct spa_pod_builder_state state
Definition builder.h:57
uint32_t size
Definition builder.h:55
uint32_t type
type of choice, one of enum spa_choice_type
Definition pod.h:155
uint32_t flags
extra flags
Definition pod.h:156
struct spa_pod pod
Definition pod.h:163
struct spa_pod pod
Definition pod.h:81
struct spa_pod pod
Definition pod.h:200
struct spa_pod pod
Definition pod.h:75
struct spa_pod pod
Definition pod.h:101
struct spa_pod pod
Definition iter.h:28
uint32_t offset
Definition iter.h:30
struct spa_pod_frame * parent
Definition iter.h:29
uint32_t flags
Definition iter.h:31
struct spa_pod pod
Definition pod.h:58
struct spa_pod pod
Definition pod.h:64
struct spa_pod pod
Definition pod.h:70
struct spa_pod pod
Definition pod.h:184
struct spa_pod pod
Definition pod.h:195
struct spa_pod pod
Definition pod.h:96
a sequence of timed controls
Definition pod.h:248
struct spa_pod pod
Definition pod.h:249
struct spa_pod pod
Definition pod.h:168
uint32_t type
Definition pod.h:45
uint32_t size
Definition pod.h:44