Go to the documentation of this file.
25 #ifndef SPA_POD_BUILDER_H
26 #define SPA_POD_BUILDER_H
48 #define SPA_POD_BUILDER_FLAG_BODY (1<<0)
49 #define SPA_POD_BUILDER_FLAG_FIRST (1<<1)
57 #define SPA_VERSION_POD_BUILDER_CALLBACKS 0
71 #define SPA_POD_BUILDER_INIT(buffer,size) (struct spa_pod_builder){ buffer, size, 0, {}, {} }
76 *state = builder->
state;
91 builder->
state = *state;
105 if (offset + 8 <=
size) {
146 overflow, 0,
offset + size);
148 if (res == 0 &&
data)
214 #define SPA_POD_INIT(size,type) (struct spa_pod) { size, type }
216 #define SPA_POD_INIT_None() SPA_POD_INIT(0, SPA_TYPE_None)
231 #define SPA_POD_INIT_Bool(val) (struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, val ? 1 : 0, 0 }
239 #define SPA_POD_INIT_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (uint32_t)val, 0 }
247 #define SPA_POD_INIT_Int(val) (struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (int32_t)val, 0 }
255 #define SPA_POD_INIT_Long(val) (struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (int64_t)val }
263 #define SPA_POD_INIT_Float(val) (struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, val, 0 }
271 #define SPA_POD_INIT_Double(val) (struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, val }
279 #define SPA_POD_INIT_String(len) (struct spa_pod_string){ { len, SPA_TYPE_String } }
305 uint32_t len = str ? strlen(str) : 0;
309 #define SPA_POD_INIT_Bytes(len) (struct spa_pod_bytes){ { len, SPA_TYPE_Bytes } }
329 #define SPA_POD_INIT_Pointer(type,value) (struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { type, 0, value } }
338 #define SPA_POD_INIT_Fd(fd) (struct spa_pod_fd){ { sizeof(int64_t), SPA_TYPE_Fd }, fd }
346 #define SPA_POD_INIT_Rectangle(val) (struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, val }
355 #define SPA_POD_INIT_Fraction(val) (struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, val }
378 uint32_t child_size, uint32_t child_type, uint32_t n_elems,
const void *elems)
382 {{child_size, child_type}}
390 #define SPA_POD_INIT_CHOICE_BODY(type, flags, child_size, child_type) \
391 (struct spa_pod_choice_body) { type, flags, { child_size, child_type }}
393 #define SPA_POD_INIT_Choice(type, ctype, child_type, n_vals, ...) \
394 (struct { struct spa_pod_choice choice; ctype vals[n_vals];}) \
395 { { { n_vals * sizeof(ctype) + sizeof(struct spa_pod_choice_body), SPA_TYPE_Choice }, \
396 { type, 0, { sizeof(ctype), child_type } } }, { __VA_ARGS__ } }
400 uint32_t type, uint32_t flags)
411 #define SPA_POD_INIT_Struct(size) (struct spa_pod_struct){ { size, SPA_TYPE_Struct } }
423 #define SPA_POD_INIT_Object(size,type,id,...) (struct spa_pod_object){ { size, SPA_TYPE_Object }, { type, id }, ##__VA_ARGS__ }
427 uint32_t type, uint32_t
id)
437 #define SPA_POD_INIT_Prop(key,flags,size,type) \
438 (struct spa_pod_prop){ key, flags, { size, type } }
443 const struct { uint32_t key; uint32_t flags; } p = { key, flags };
447 #define SPA_POD_INIT_Sequence(size,unit) \
448 (struct spa_pod_sequence){ { size, SPA_TYPE_Sequence}, {unit, 0 } }
464 const struct { uint32_t offset; uint32_t type; } p = { offset, type };
485 #define SPA_POD_BUILDER_COLLECT(builder,type,args) \
489 spa_pod_builder_bool(builder, !!va_arg(args, int)); \
492 spa_pod_builder_id(builder, va_arg(args, uint32_t)); \
495 spa_pod_builder_int(builder, va_arg(args, int)); \
498 spa_pod_builder_long(builder, va_arg(args, int64_t)); \
501 spa_pod_builder_float(builder, va_arg(args, double)); \
504 spa_pod_builder_double(builder, va_arg(args, double)); \
508 char *strval = va_arg(args, char *); \
509 if (strval != NULL) { \
510 size_t len = strlen(strval); \
511 spa_pod_builder_string_len(builder, strval, len); \
514 spa_pod_builder_none(builder); \
519 char *strval = va_arg(args, char *); \
520 size_t len = va_arg(args, int); \
521 spa_pod_builder_string_len(builder, strval, len); \
526 void *ptr = va_arg(args, void *); \
527 int len = va_arg(args, int); \
528 spa_pod_builder_bytes(builder, ptr, len); \
533 struct spa_rectangle *rectval = \
534 va_arg(args, struct spa_rectangle *); \
535 spa_pod_builder_rectangle(builder, \
536 rectval->width, rectval->height); \
541 struct spa_fraction *fracval = \
542 va_arg(args, struct spa_fraction *); \
543 spa_pod_builder_fraction(builder, fracval->num, fracval->denom);\
548 int child_size = va_arg(args, int); \
549 int child_type = va_arg(args, int); \
550 int n_elems = va_arg(args, int); \
551 void *elems = va_arg(args, void *); \
552 spa_pod_builder_array(builder, child_size, \
553 child_type, n_elems, elems); \
558 int t = va_arg(args, uint32_t); \
559 spa_pod_builder_pointer(builder, t, va_arg(args, void *)); \
563 spa_pod_builder_fd(builder, va_arg(args, int)); \
570 struct spa_pod *pod = va_arg(args, struct spa_pod *); \
572 spa_pod_builder_none(builder); \
574 spa_pod_builder_primitive(builder, pod); \
596 uint32_t key = va_arg(args, uint32_t);
604 uint32_t
offset = va_arg(args, uint32_t);
605 uint32_t type = va_arg(args, uint32_t);
614 if ((format = va_arg(args,
const char *)) == NULL)
617 choice = *format ==
'?';
625 n_values = va_arg(args,
int);
627 while (n_values-- > 0)
643 va_start(args, builder);
650 #define spa_pod_builder_add_object(b,type,id,...) \
652 struct spa_pod_frame _f; \
653 spa_pod_builder_push_object(b, &_f, type, id); \
654 spa_pod_builder_add(b, ##__VA_ARGS__, 0); \
655 spa_pod_builder_pop(b, &_f); \
658 #define spa_pod_builder_add_struct(b,...) \
660 struct spa_pod_frame _f; \
661 spa_pod_builder_push_struct(b, &_f); \
662 spa_pod_builder_add(b, ##__VA_ARGS__, NULL); \
663 spa_pod_builder_pop(b, &_f); \
666 #define spa_pod_builder_add_sequence(b,unit,...) \
668 struct spa_pod_frame _f; \
669 spa_pod_builder_push_sequence(b, &_f, unit); \
670 spa_pod_builder_add(b, ##__VA_ARGS__, 0, 0); \
671 spa_pod_builder_pop(b, &_f); \
uint32_t spa_pod_builder_control(struct spa_pod_builder *builder, uint32_t offset, uint32_t type)
Definition: builder.h:462
int spa_pod_builder_string_len(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition: builder.h:294
void spa_pod_builder_set_callbacks(struct spa_pod_builder *builder, const struct spa_pod_builder_callbacks *callbacks, void *data)
Definition: builder.h:80
int spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
Definition: builder.h:581
@ SPA_TYPE_None
Definition: build-12683127/doc/spa/utils/type.h:45
Definition: pod/pod.h:175
void spa_pod_builder_reset(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition: builder.h:87
#define SPA_FLAG_CLEAR(field, flag)
Definition: defs.h:75
Definition: pod/pod.h:191
#define SPA_POD_INIT_Id(val)
Definition: builder.h:239
Definition: pod/pod.h:156
#define SPA_POD_INIT_Fraction(val)
Definition: builder.h:355
@ SPA_CHOICE_Range
range: default, min, max
Definition: pod/pod.h:142
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:399
int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:167
int spa_pod_builder_float(struct spa_pod_builder *builder, float val)
Definition: builder.h:265
#define SPA_POD_INIT_Float(val)
Definition: builder.h:263
struct spa_pod_builder_state state
Definition: builder.h:67
struct spa_pod pod
Definition: pod/pod.h:64
user data to add to an object
Definition: filter.c:75
#define SPA_FRACTION(num, denom)
Definition: defs.h:103
Definition: pod/pod.h:169
@ SPA_CHOICE_Enum
list: default, alternative,...
Definition: pod/pod.h:144
int spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val)
Definition: builder.h:241
int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition: builder.h:638
#define SPA_POD_INIT_Object(size, type, id,...)
Definition: builder.h:423
#define SPA_ROUND_UP_N(num, align)
Definition: defs.h:223
int spa_pod_builder_child(struct spa_pod_builder *builder, uint32_t size, uint32_t type)
Definition: builder.h:224
struct spa_pod pod
Definition: pod/pod.h:107
@ SPA_TYPE_Array
Definition: build-12683127/doc/spa/utils/type.h:57
#define SPA_POD_BODY_CONST(pod)
Definition: pod/pod.h:48
Definition: pod/pod.h:186
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:426
Definition: pod/pod.h:148
struct spa_pod pod
Definition: pod/pod.h:162
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:159
void * spa_pod_builder_reserve_bytes(struct spa_pod_builder *builder, uint32_t len)
Definition: builder.h:321
struct spa_pod pod
Definition: pod/pod.h:70
#define SPA_POD_BUILDER_INIT(buffer, size)
Definition: builder.h:71
int spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p)
Definition: builder.h:193
#define SPA_POD_INIT_Struct(size)
Definition: builder.h:411
void * data
Definition: builder.h:64
@ SPA_CHOICE_Flags
flags: default, possible flags,...
Definition: pod/pod.h:145
struct spa_pod pod
Definition: pod/pod.h:76
#define SPA_RECTANGLE(width, height)
Definition: defs.h:85
Definition: pod/pod.h:101
#define SPA_POD_INIT_Double(val)
Definition: builder.h:271
void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition: builder.h:175
struct spa_pod pod
Definition: pod/pod.h:128
int spa_pod_builder_rectangle(struct spa_pod_builder *builder, uint32_t width, uint32_t height)
Definition: builder.h:349
struct spa_pod_frame * parent
Definition: iter.h:44
struct spa_pod * spa_pod_copy(const struct spa_pod *pod)
Copy a pod structure.
Definition: builder.h:676
Definition: pod/pod.h:226
int spa_pod_builder_bool(struct spa_pod_builder *builder, bool val)
Definition: builder.h:233
int(* overflow)(void *data, uint32_t size)
Definition: builder.h:60
struct spa_pod_frame * frame
Definition: builder.h:51
#define SPA_POD_INIT_String(len)
Definition: builder.h:279
#define SPA_POD_INIT_Long(val)
Definition: builder.h:255
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:122
struct spa_pod pod
Definition: pod/pod.h:58
struct spa_pod pod
Definition: pod/pod.h:81
struct spa_pod * spa_pod_builder_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition: builder.h:114
int spa_pod_builder_raw(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:137
uint32_t spa_choice_from_id(char id)
Definition: builder.h:468
#define SPA_POD_BUILDER_FLAG_FIRST
Definition: builder.h:49
uint32_t offset
Definition: iter.h:45
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:377
Callbacks, contains the structure with functions and the data passed to the functions.
Definition: hook.h:130
struct spa_pod pod
Definition: pod/pod.h:102
#define SPA_POD_INIT_Fd(fd)
Definition: builder.h:338
struct spa_callbacks callbacks
Definition: builder.h:68
Definition: pod/pod.h:122
uint32_t version
Definition: builder.h:58
#define SPA_POD_BODY(pod)
Definition: pod/pod.h:47
struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition: builder.h:102
struct spa_pod pod
Definition: pod/pod.h:187
#define SPA_FLAG_IS_SET(field, flag)
Definition: defs.h:73
Definition: pod/pod.h:127
void spa_pod_builder_init(struct spa_pod_builder *builder, void *data, uint32_t size)
Definition: builder.h:96
uint32_t size
Definition: pod/pod.h:51
#define SPA_POD_INIT_Int(val)
Definition: builder.h:247
int spa_pod_builder_string(struct spa_pod_builder *builder, const char *str)
Definition: builder.h:303
#define SPA_POD_INIT_Sequence(size, unit)
Definition: builder.h:447
int spa_pod_builder_pad(struct spa_pod_builder *builder, uint32_t size)
Definition: builder.h:159
void spa_pod_builder_get_state(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition: builder.h:74
#define SPA_POD_BODY_SIZE(pod)
Definition: pod/pod.h:40
#define spa_callbacks_call_res(callbacks, type, res, method, vers,...)
Invoke method named method in the callbacks.
Definition: hook.h:185
@ SPA_TYPE_Object
Definition: build-12683127/doc/spa/utils/type.h:59
struct spa_pod pod
Definition: pod/pod.h:234
uint32_t _padding
Definition: builder.h:66
@ SPA_TYPE_Sequence
Definition: build-12683127/doc/spa/utils/type.h:60
int spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val)
Definition: builder.h:257
uint32_t type
type of choice, one of enum spa_choice_type
Definition: pod/pod.h:149
struct spa_pod pod
Definition: pod/pod.h:176
struct spa_pod pod
Definition: pod/pod.h:192
#define SPA_FALLTHROUGH
SPA_FALLTHROUGH is an annotation to suppress compiler warnings about switch cases that fall through w...
Definition: defs.h:69
int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition: builder.h:441
int spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val)
Definition: builder.h:249
a sequence of timed controls
Definition: pod/pod.h:233
int spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len)
Definition: builder.h:312
@ SPA_CHOICE_None
no choice, first value is current
Definition: pod/pod.h:141
uint32_t flags
Definition: iter.h:46
struct spa_pod pod
Definition: pod/pod.h:157
uint32_t type
Definition: pod/pod.h:52
uint32_t flags
Definition: builder.h:50
#define SPA_POD_INIT_Bool(val)
Definition: builder.h:231
int spa_pod_builder_push_array(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition: builder.h:365
@ SPA_CHOICE_Step
range with step: default, min, max, step
Definition: pod/pod.h:143
#define SPA_POD_INIT(size, type)
Definition: builder.h:214
int spa_pod_builder_fraction(struct spa_pod_builder *builder, uint32_t num, uint32_t denom)
Definition: builder.h:358
struct spa_pod pod
Definition: iter.h:43
#define SPA_POD_SIZE(pod)
Definition: pod/pod.h:42
#define SPA_POD_INIT_None()
Definition: builder.h:216
@ SPA_TYPE_Choice
Definition: build-12683127/doc/spa/utils/type.h:63
#define SPA_POD_BUILDER_FLAG_BODY
Definition: builder.h:48
int spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition: builder.h:282
Definition: pod/pod.h:161
uint32_t size
Definition: builder.h:65
int spa_pod_builder_push_sequence(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t unit)
Definition: builder.h:451
int spa_pod_builder_double(struct spa_pod_builder *builder, double val)
Definition: builder.h:273
struct spa_pod pod
Definition: pod/pod.h:87
#define SPA_POD_INIT_Bytes(len)
Definition: builder.h:309
#define SPA_POD_INIT_Pointer(type, value)
Definition: builder.h:329
uint32_t flags
extra flags
Definition: pod/pod.h:150
#define SPA_POD_BUILDER_COLLECT(builder, type, args)
Definition: builder.h:485
#define SPA_CALLBACKS_INIT(_funcs, _data)
Initialize the set of functions funcs as a spa_callbacks, together with _data.
Definition: hook.h:142
int spa_pod_builder_pointer(struct spa_pod_builder *builder, uint32_t type, const void *val)
Definition: builder.h:332
int spa_pod_builder_none(struct spa_pod_builder *builder)
Definition: builder.h:218
uint32_t offset
Definition: builder.h:47
int spa_pod_builder_push_struct(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition: builder.h:414
int spa_pod_builder_fd(struct spa_pod_builder *builder, int64_t fd)
Definition: builder.h:340
Definition: pod/pod.h:106
#define SPA_POD_INIT_Rectangle(val)
Definition: builder.h:346