PipeWire: spa/pod/builder.h Source File

PipeWire 1.0.3

Loading...
Searching...
No Matches
builder.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_POD_BUILDER_H
6#define SPA_POD_BUILDER_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
21#include <stdarg.h>
22
23#include <spa/utils/hook.h>
24#include <spa/pod/iter.h>
25#include <spa/pod/vararg.h>
26
27struct spa_pod_builder_state {
28 uint32_t offset;
29#define SPA_POD_BUILDER_FLAG_BODY (1<<0)
30#define SPA_POD_BUILDER_FLAG_FIRST (1<<1)
31 uint32_t flags;
32 struct spa_pod_frame *frame;
33};
34
35 struct spa_pod_builder;
36
37 struct spa_pod_builder_callbacks {
38#define SPA_VERSION_POD_BUILDER_CALLBACKS 0
39 uint32_t version;
40
41 int (*overflow) (void *data, uint32_t size);
42};
43
44struct spa_pod_builder {
45 void *data;
46 uint32_t size;
47 uint32_t _padding;
48 struct spa_pod_builder_state state;
49 struct spa_callbacks callbacks;
50};
51
52#define SPA_POD_BUILDER_INIT(buffer,size) ((struct spa_pod_builder){ (buffer), (size), 0, {}, {} })
53
54 static inline void
55 spa_pod_builder_get_state(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
56{
57 *state = builder->state;
58}
59
60static inline void
61 spa_pod_builder_set_callbacks(struct spa_pod_builder *builder,
62 const struct spa_pod_builder_callbacks *callbacks, void *data)
63{
64 builder->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
65}
66
67static inline void
68 spa_pod_builder_reset(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
69{
70 struct spa_pod_frame *f;
71 uint32_t size = builder->state.offset - state->offset;
72 builder->state = *state;
73 for (f = builder->state.frame; f ; f = f->parent)
74 f->pod.size -= size;
75}
76
77static inline void spa_pod_builder_init(struct spa_pod_builder *builder, void *data, uint32_t size)
78{
79 *builder = SPA_POD_BUILDER_INIT(data, size);
80}
81
82static inline struct spa_pod *
83 spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
84{
85 uint32_t size = builder->size;
86 if (offset + 8 <= size) {
87 struct spa_pod *pod = SPA_PTROFF(builder->data, offset, struct spa_pod);
88 if (offset + SPA_POD_SIZE(pod) <= size)
89 return pod;
90 }
91 return NULL;
92}
93
94static inline struct spa_pod *
95 spa_pod_builder_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
96{
97 if (frame->offset + SPA_POD_SIZE(&frame->pod) <= builder->size)
98 return SPA_PTROFF(builder->data, frame->offset, struct spa_pod);
99 return NULL;
100}
101
102static inline void
103 spa_pod_builder_push(struct spa_pod_builder *builder,
104 struct spa_pod_frame *frame,
105 const struct spa_pod *pod,
106 uint32_t offset)
107{
108 frame->pod = *pod;
109 frame->offset = offset;
110 frame->parent = builder->state.frame;
111 frame->flags = builder->state.flags;
112 builder->state.frame = frame;
113
114 if (frame->pod.type == SPA_TYPE_Array || frame->pod.type == SPA_TYPE_Choice)
115 builder->state.flags = SPA_POD_BUILDER_FLAG_FIRST | SPA_POD_BUILDER_FLAG_BODY;
116}
117
118static inline int spa_pod_builder_raw(struct spa_pod_builder *builder, const void *data, uint32_t size)
119{
120 int res = 0;
121 struct spa_pod_frame *f;
122 uint32_t offset = builder->state.offset;
123
124 if (offset + size > builder->size) {
125 res = -ENOSPC;
126 if (offset <= builder->size)
127 spa_callbacks_call_res(&builder->callbacks,
128 struct spa_pod_builder_callbacks, res,
129 overflow, 0, offset + size);
130 }
131 if (res == 0 && data)
132 memcpy(SPA_PTROFF(builder->data, offset, void), data, size);
133
134 builder->state.offset += size;
135
136 for (f = builder->state.frame; f ; f = f->parent)
137 f->pod.size += size;
138
139 return res;
140}
141
142static inline int spa_pod_builder_pad(struct spa_pod_builder *builder, uint32_t size)
143{
144 uint64_t zeroes = 0;
145 size = SPA_ROUND_UP_N(size, 8) - size;
146 return size ? spa_pod_builder_raw(builder, &zeroes, size) : 0;
147}
148
149static inline int
150 spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
151{
152 int r, res = spa_pod_builder_raw(builder, data, size);
153 if ((r = spa_pod_builder_pad(builder, size)) < 0)
154 res = r;
155 return res;
156}
157
158static inline void *spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
159{
160 struct spa_pod *pod;
161
162 if (SPA_FLAG_IS_SET(builder->state.flags, SPA_POD_BUILDER_FLAG_FIRST)) {
163 const struct spa_pod p = { 0, SPA_TYPE_None };
164 spa_pod_builder_raw(builder, &p, sizeof(p));
165 }
166 if ((pod = (struct spa_pod*)spa_pod_builder_frame(builder, frame)) != NULL)
167 *pod = frame->pod;
168
169 builder->state.frame = frame->parent;
170 builder->state.flags = frame->flags;
171 spa_pod_builder_pad(builder, builder->state.offset);
172 return pod;
173}
174
175static inline int
176 spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p)
177{
178 const void *data;
179 uint32_t size;
180 int r, res;
181
182 if (builder->state.flags == SPA_POD_BUILDER_FLAG_BODY) {
183 data = SPA_POD_BODY_CONST(p);
184 size = SPA_POD_BODY_SIZE(p);
185 } else {
186 data = p;
187 size = SPA_POD_SIZE(p);
188 SPA_FLAG_CLEAR(builder->state.flags, SPA_POD_BUILDER_FLAG_FIRST);
189 }
190 res = spa_pod_builder_raw(builder, data, size);
191 if (builder->state.flags != SPA_POD_BUILDER_FLAG_BODY)
192 if ((r = spa_pod_builder_pad(builder, size)) < 0)
193 res = r;
194 return res;
195}
196
197#define SPA_POD_INIT(size,type) ((struct spa_pod) { (size), (type) })
198
199#define SPA_POD_INIT_None() SPA_POD_INIT(0, SPA_TYPE_None)
200
201static inline int spa_pod_builder_none(struct spa_pod_builder *builder)
202{
203 const struct spa_pod p = SPA_POD_INIT_None();
204 return spa_pod_builder_primitive(builder, &p);
205}
206
207static inline int spa_pod_builder_child(struct spa_pod_builder *builder, uint32_t size, uint32_t type)
208{
209 const struct spa_pod p = SPA_POD_INIT(size,type);
210 SPA_FLAG_CLEAR(builder->state.flags, SPA_POD_BUILDER_FLAG_FIRST);
211 return spa_pod_builder_raw(builder, &p, sizeof(p));
212}
213
214#define SPA_POD_INIT_Bool(val) ((struct spa_pod_bool){ { sizeof(uint32_t), SPA_TYPE_Bool }, (val) ? 1 : 0, 0 })
215
216static inline int spa_pod_builder_bool(struct spa_pod_builder *builder, bool val)
217{
218 const struct spa_pod_bool p = SPA_POD_INIT_Bool(val);
219 return spa_pod_builder_primitive(builder, &p.pod);
220}
221
222#define SPA_POD_INIT_Id(val) ((struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (val), 0 })
223
224static inline int spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val)
225{
226 const struct spa_pod_id p = SPA_POD_INIT_Id(val);
227 return spa_pod_builder_primitive(builder, &p.pod);
228}
229
230#define SPA_POD_INIT_Int(val) ((struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (val), 0 })
231
232static inline int spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val)
233{
234 const struct spa_pod_int p = SPA_POD_INIT_Int(val);
235 return spa_pod_builder_primitive(builder, &p.pod);
236}
237
238#define SPA_POD_INIT_Long(val) ((struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (val) })
239
240static inline int spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val)
241{
242 const struct spa_pod_long p = SPA_POD_INIT_Long(val);
243 return spa_pod_builder_primitive(builder, &p.pod);
244}
245
246#define SPA_POD_INIT_Float(val) ((struct spa_pod_float){ { sizeof(float), SPA_TYPE_Float }, (val), 0 })
247
248static inline int spa_pod_builder_float(struct spa_pod_builder *builder, float val)
249{
250 const struct spa_pod_float p = SPA_POD_INIT_Float(val);
251 return spa_pod_builder_primitive(builder, &p.pod);
252}
253
254#define SPA_POD_INIT_Double(val) ((struct spa_pod_double){ { sizeof(double), SPA_TYPE_Double }, (val) })
255
256 static inline int spa_pod_builder_double(struct spa_pod_builder *builder, double val)
257{
258 const struct spa_pod_double p = SPA_POD_INIT_Double(val);
259 return spa_pod_builder_primitive(builder, &p.pod);
260}
261
262#define SPA_POD_INIT_String(len) ((struct spa_pod_string){ { (len), SPA_TYPE_String } })
263
264static inline int
265 spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len)
266{
267 int r, res;
268 res = spa_pod_builder_raw(builder, str, len);
269 if ((r = spa_pod_builder_raw(builder, "", 1)) < 0)
270 res = r;
271 if ((r = spa_pod_builder_pad(builder, builder->state.offset)) < 0)
272 res = r;
273 return res;
274}
275
276static inline int
277 spa_pod_builder_string_len(struct spa_pod_builder *builder, const char *str, uint32_t len)
278{
279 const struct spa_pod_string p = SPA_POD_INIT_String(len+1);
280 int r, res = spa_pod_builder_raw(builder, &p, sizeof(p));
281 if ((r = spa_pod_builder_write_string(builder, str, len)) < 0)
282 res = r;
283 return res;
284}
285
286static inline int spa_pod_builder_string(struct spa_pod_builder *builder, const char *str)
287{
288 uint32_t len = str ? strlen(str) : 0;
289 return spa_pod_builder_string_len(builder, str ? str : "", len);
290}
291
292#define SPA_POD_INIT_Bytes(len) ((struct spa_pod_bytes){ { (len), SPA_TYPE_Bytes } })
293
294static inline int
295 spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len)
296{
297 const struct spa_pod_bytes p = SPA_POD_INIT_Bytes(len);
298 int r, res = spa_pod_builder_raw(builder, &p, sizeof(p));
299 if ((r = spa_pod_builder_raw_padded(builder, bytes, len)) < 0)
300 res = r;
301 return res;
302}
303static inline void *
304 spa_pod_builder_reserve_bytes(struct spa_pod_builder *builder, uint32_t len)
305{
306 uint32_t offset = builder->state.offset;
307 if (spa_pod_builder_bytes(builder, NULL, len) < 0)
308 return NULL;
309 return SPA_POD_BODY(spa_pod_builder_deref(builder, offset));
310}
311
312#define SPA_POD_INIT_Pointer(type,value) ((struct spa_pod_pointer){ { sizeof(struct spa_pod_pointer_body), SPA_TYPE_Pointer }, { (type), 0, (value) } })
313
314static inline int
315 spa_pod_builder_pointer(struct spa_pod_builder *builder, uint32_t type, const void *val)
316{
317 const struct spa_pod_pointer p = SPA_POD_INIT_Pointer(type, val);
318 return spa_pod_builder_primitive(builder, &p.pod);
319}
320
321#define SPA_POD_INIT_Fd(fd) ((struct spa_pod_fd){ { sizeof(int64_t), SPA_TYPE_Fd }, (fd) })
322
323static inline int spa_pod_builder_fd(struct spa_pod_builder *builder, int64_t fd)
324{
325 const struct spa_pod_fd p = SPA_POD_INIT_Fd(fd);
326 return spa_pod_builder_primitive(builder, &p.pod);
327}
328
329#define SPA_POD_INIT_Rectangle(val) ((struct spa_pod_rectangle){ { sizeof(struct spa_rectangle), SPA_TYPE_Rectangle }, (val) })
330
331static inline int
332 spa_pod_builder_rectangle(struct spa_pod_builder *builder, uint32_t width, uint32_t height)
333{
334 const struct spa_pod_rectangle p = SPA_POD_INIT_Rectangle(SPA_RECTANGLE(width, height));
335 return spa_pod_builder_primitive(builder, &p.pod);
336}
337
338#define SPA_POD_INIT_Fraction(val) ((struct spa_pod_fraction){ { sizeof(struct spa_fraction), SPA_TYPE_Fraction }, (val) })
339
340static inline int
341 spa_pod_builder_fraction(struct spa_pod_builder *builder, uint32_t num, uint32_t denom)
342{
343 const struct spa_pod_fraction p = SPA_POD_INIT_Fraction(SPA_FRACTION(num, denom));
344 return spa_pod_builder_primitive(builder, &p.pod);
345}
346
347static inline int
348 spa_pod_builder_push_array(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
349{
350 const struct spa_pod_array p =
351 { {sizeof(struct spa_pod_array_body) - sizeof(struct spa_pod), SPA_TYPE_Array},
352 {{0, 0}} };
353 uint32_t offset = builder->state.offset;
354 int res = spa_pod_builder_raw(builder, &p, sizeof(p) - sizeof(struct spa_pod));
355 spa_pod_builder_push(builder, frame, &p.pod, offset);
356 return res;
357}
358
359static inline int
360 spa_pod_builder_array(struct spa_pod_builder *builder,
361 uint32_t child_size, uint32_t child_type, uint32_t n_elems, const void *elems)
362{
363 const struct spa_pod_array p = {
364 {(uint32_t)(sizeof(struct spa_pod_array_body) + n_elems * child_size), SPA_TYPE_Array},
365 {{child_size, child_type}}
366 };
367 int r, res = spa_pod_builder_raw(builder, &p, sizeof(p));
368 if ((r = spa_pod_builder_raw_padded(builder, elems, child_size * n_elems)) < 0)
369 res = r;
370 return res;
371}
372
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) }})
375
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__ } })
380
381static inline int
382 spa_pod_builder_push_choice(struct spa_pod_builder *builder, struct spa_pod_frame *frame,
383 uint32_t type, uint32_t flags)
384{
385 const struct spa_pod_choice p =
386 { {sizeof(struct spa_pod_choice_body) - sizeof(struct spa_pod), SPA_TYPE_Choice},
387 { type, flags, {0, 0}} };
388 uint32_t offset = builder->state.offset;
389 int res = spa_pod_builder_raw(builder, &p, sizeof(p) - sizeof(struct spa_pod));
390 spa_pod_builder_push(builder, frame, &p.pod, offset);
391 return res;
392}
393
394#define SPA_POD_INIT_Struct(size) ((struct spa_pod_struct){ { (size), SPA_TYPE_Struct } })
395
396static inline int
397 spa_pod_builder_push_struct(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
398{
399 const struct spa_pod_struct p = SPA_POD_INIT_Struct(0);
400 uint32_t offset = builder->state.offset;
401 int res = spa_pod_builder_raw(builder, &p, sizeof(p));
402 spa_pod_builder_push(builder, frame, &p.pod, offset);
403 return res;
404}
405
406#define SPA_POD_INIT_Object(size,type,id,...) ((struct spa_pod_object){ { (size), SPA_TYPE_Object }, { (type), (id) }, ##__VA_ARGS__ })
407
408static inline int
409 spa_pod_builder_push_object(struct spa_pod_builder *builder, struct spa_pod_frame *frame,
410 uint32_t type, uint32_t id)
411{
412 const struct spa_pod_object p =
413 SPA_POD_INIT_Object(sizeof(struct spa_pod_object_body), type, id);
414 uint32_t offset = builder->state.offset;
415 int res = spa_pod_builder_raw(builder, &p, sizeof(p));
416 spa_pod_builder_push(builder, frame, &p.pod, offset);
417 return res;
418}
419
420#define SPA_POD_INIT_Prop(key,flags,size,type) \
421 ((struct spa_pod_prop){ (key), (flags), { (size), (type) } })
422
423static inline int
424 spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
425{
426 const struct { uint32_t key; uint32_t flags; } p = { key, flags };
427 return spa_pod_builder_raw(builder, &p, sizeof(p));
428}
429
430#define SPA_POD_INIT_Sequence(size,unit) \
431 ((struct spa_pod_sequence){ { (size), SPA_TYPE_Sequence}, {(unit), 0 } })
432
433static inline int
434 spa_pod_builder_push_sequence(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t unit)
435{
436 const struct spa_pod_sequence p =
437 SPA_POD_INIT_Sequence(sizeof(struct spa_pod_sequence_body), unit);
438 uint32_t offset = builder->state.offset;
439 int res = spa_pod_builder_raw(builder, &p, sizeof(p));
440 spa_pod_builder_push(builder, frame, &p.pod, offset);
441 return res;
442}
443
444static inline int
445 spa_pod_builder_control(struct spa_pod_builder *builder, uint32_t offset, uint32_t type)
446{
447 const struct { uint32_t offset; uint32_t type; } p = { offset, type };
448 return spa_pod_builder_raw(builder, &p, sizeof(p));
449}
450
451static inline uint32_t spa_choice_from_id(char id)
452{
453 switch (id) {
454 case 'r':
455 return SPA_CHOICE_Range;
456 case 's':
457 return SPA_CHOICE_Step;
458 case 'e':
459 return SPA_CHOICE_Enum;
460 case 'f':
461 return SPA_CHOICE_Flags;
462 case 'n':
463 default:
464 return SPA_CHOICE_None;
465 }
466}
467
468#define SPA_POD_BUILDER_COLLECT(builder,type,args) \
469do { \
470 switch (type) { \
471 case 'b': \
472 spa_pod_builder_bool(builder, !!va_arg(args, int)); \
473 break; \
474 case 'I': \
475 spa_pod_builder_id(builder, va_arg(args, uint32_t)); \
476 break; \
477 case 'i': \
478 spa_pod_builder_int(builder, va_arg(args, int)); \
479 break; \
480 case 'l': \
481 spa_pod_builder_long(builder, va_arg(args, int64_t)); \
482 break; \
483 case 'f': \
484 spa_pod_builder_float(builder, va_arg(args, double)); \
485 break; \
486 case 'd': \
487 spa_pod_builder_double(builder, va_arg(args, double)); \
488 break; \
489 case 's': \
490 { \
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); \
495 } \
496 else \
497 spa_pod_builder_none(builder); \
498 break; \
499 } \
500 case 'S': \
501 { \
502 char *strval = va_arg(args, char *); \
503 size_t len = va_arg(args, int); \
504 spa_pod_builder_string_len(builder, strval, len); \
505 break; \
506 } \
507 case 'y': \
508 { \
509 void *ptr = va_arg(args, void *); \
510 int len = va_arg(args, int); \
511 spa_pod_builder_bytes(builder, ptr, len); \
512 break; \
513 } \
514 case 'R': \
515 { \
516 struct spa_rectangle *rectval = \
517 va_arg(args, struct spa_rectangle *); \
518 spa_pod_builder_rectangle(builder, \
519 rectval->width, rectval->height); \
520 break; \
521 } \
522 case 'F': \
523 { \
524 struct spa_fraction *fracval = \
525 va_arg(args, struct spa_fraction *); \
526 spa_pod_builder_fraction(builder, fracval->num, fracval->denom);\
527 break; \
528 } \
529 case 'a': \
530 { \
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); \
537 break; \
538 } \
539 case 'p': \
540 { \
541 int t = va_arg(args, uint32_t); \
542 spa_pod_builder_pointer(builder, t, va_arg(args, void *)); \
543 break; \
544 } \
545 case 'h': \
546 spa_pod_builder_fd(builder, va_arg(args, int)); \
547 break; \
548 case 'P': \
549 case 'O': \
550 case 'T': \
551 case 'V': \
552 { \
553 struct spa_pod *pod = va_arg(args, struct spa_pod *); \
554 if (pod == NULL) \
555 spa_pod_builder_none(builder); \
556 else \
557 spa_pod_builder_primitive(builder, pod); \
558 break; \
559 } \
560 } \
561} while(false)
562
563static inline int
564 spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
565{
566 int res = 0;
567 struct spa_pod_frame *frame = builder->state.frame;
568 uint32_t ftype = frame ? frame->pod.type : (uint32_t)SPA_TYPE_None;
569
570 do {
571 const char *format;
572 int n_values = 1;
573 struct spa_pod_frame f;
574 bool choice;
575
576 switch (ftype) {
577 case SPA_TYPE_Object:
578 {
579 uint32_t key = va_arg(args, uint32_t);
580 if (key == 0)
581 goto exit;
582 spa_pod_builder_prop(builder, key, 0);
583 break;
584 }
585 case SPA_TYPE_Sequence:
586 {
587 uint32_t offset = va_arg(args, uint32_t);
588 uint32_t type = va_arg(args, uint32_t);
589 if (type == 0)
590 goto exit;
591 spa_pod_builder_control(builder, offset, type);
592 SPA_FALLTHROUGH
593 }
594 default:
595 break;
596 }
597 if ((format = va_arg(args, const char *)) == NULL)
598 break;
599
600 choice = *format == '?';
601 if (choice) {
602 uint32_t type = spa_choice_from_id(*++format);
603 if (*format != '\0')
604 format++;
605
606 spa_pod_builder_push_choice(builder, &f, type, 0);
607
608 n_values = va_arg(args, int);
609 }
610 while (n_values-- > 0)
611 SPA_POD_BUILDER_COLLECT(builder, *format, args);
612
613 if (choice)
614 spa_pod_builder_pop(builder, &f);
615 } while (true);
616
617 exit:
618 return res;
619}
620
621static inline int spa_pod_builder_add(struct spa_pod_builder *builder, ...)
622{
623 int res;
624 va_list args;
625
626 va_start(args, builder);
627 res = spa_pod_builder_addv(builder, args);
628 va_end(args);
629
630 return res;
631}
632
633#define spa_pod_builder_add_object(b,type,id,...) \
634({ \
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); \
640})
641
642#define spa_pod_builder_add_struct(b,...) \
643({ \
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); \
649})
650
651#define spa_pod_builder_add_sequence(b,unit,...) \
652({ \
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); \
658})
659
661static inline struct spa_pod *
662 spa_pod_copy(const struct spa_pod *pod)
663{
664 size_t size;
665 struct spa_pod *c;
666
667 size = SPA_POD_SIZE(pod);
668 if ((c = (struct spa_pod *) malloc(size)) == NULL)
669 return NULL;
670 return (struct spa_pod *) memcpy(c, pod, size);
671}
672
677#ifdef __cplusplus
678} /* extern "C" */
679#endif
680
681#endif /* SPA_POD_BUILDER_H */
SPA_CALLBACKS_INIT
#define SPA_CALLBACKS_INIT(_funcs, _data)
Initialize the set of functions funcs as a spa_callbacks, together with _data.
Definition hook.h:134
spa_callbacks_call_res
#define spa_callbacks_call_res(callbacks, type, res, method, vers,...)
Invoke method named method in the callbacks.
Definition hook.h:207
SPA_POD_INIT_Double
#define SPA_POD_INIT_Double(val)
Definition builder.h:272
spa_pod_builder_reserve_bytes
static void * spa_pod_builder_reserve_bytes(struct spa_pod_builder *builder, uint32_t len)
Definition builder.h:324
spa_pod_builder_prop
static int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition builder.h:450
SPA_POD_INIT_None
#define SPA_POD_INIT_None()
Definition builder.h:211
SPA_POD_INIT
#define SPA_POD_INIT(size, type)
Definition builder.h:208
spa_pod_builder_string
static int spa_pod_builder_string(struct spa_pod_builder *builder, const char *str)
Definition builder.h:305
spa_pod_builder_child
static int spa_pod_builder_child(struct spa_pod_builder *builder, uint32_t size, uint32_t type)
Definition builder.h:219
spa_pod_builder_fraction
static int spa_pod_builder_fraction(struct spa_pod_builder *builder, uint32_t num, uint32_t denom)
Definition builder.h:365
spa_pod_builder_rectangle
static int spa_pod_builder_rectangle(struct spa_pod_builder *builder, uint32_t width, uint32_t height)
Definition builder.h:355
spa_pod_builder_float
static int spa_pod_builder_float(struct spa_pod_builder *builder, float val)
Definition builder.h:265
SPA_POD_BODY_CONST
#define SPA_POD_BODY_CONST(pod)
Definition pod.h:41
SPA_POD_INIT_Object
#define SPA_POD_INIT_Object(size, type, id,...)
Definition builder.h:432
SPA_POD_BUILDER_FLAG_BODY
#define SPA_POD_BUILDER_FLAG_BODY
Definition builder.h:35
spa_pod_builder_push
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
spa_pod_builder_double
static int spa_pod_builder_double(struct spa_pod_builder *builder, double val)
Definition builder.h:274
spa_pod_builder_write_string
static int spa_pod_builder_write_string(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition builder.h:284
SPA_POD_INIT_Sequence
#define SPA_POD_INIT_Sequence(size, unit)
Definition builder.h:456
SPA_POD_INIT_Rectangle
#define SPA_POD_INIT_Rectangle(val)
Definition builder.h:352
spa_pod_builder_set_callbacks
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
SPA_POD_INIT_Bool
#define SPA_POD_INIT_Bool(val)
Definition builder.h:227
spa_pod_builder_id
static int spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val)
Definition builder.h:238
spa_pod_builder_add
static int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition builder.h:647
SPA_POD_INIT_String
#define SPA_POD_INIT_String(len)
Definition builder.h:281
spa_pod_builder_fd
static int spa_pod_builder_fd(struct spa_pod_builder *builder, int64_t fd)
Definition builder.h:345
SPA_POD_BODY
#define SPA_POD_BODY(pod)
Definition pod.h:39
spa_pod_builder_frame
static struct spa_pod * spa_pod_builder_frame(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:105
spa_pod_builder_reset
static void spa_pod_builder_reset(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition builder.h:78
spa_pod_builder_none
static int spa_pod_builder_none(struct spa_pod_builder *builder)
Definition builder.h:213
SPA_POD_INIT_Id
#define SPA_POD_INIT_Id(val)
Definition builder.h:236
spa_pod_builder_push_sequence
static int spa_pod_builder_push_sequence(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t unit)
Definition builder.h:460
spa_pod_builder_raw_padded
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:160
SPA_POD_BODY_SIZE
#define SPA_POD_BODY_SIZE(pod)
Definition pod.h:26
SPA_POD_BUILDER_INIT
#define SPA_POD_BUILDER_INIT(buffer, size)
Definition builder.h:62
spa_pod_builder_pop
static void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:168
spa_pod_builder_pad
static int spa_pod_builder_pad(struct spa_pod_builder *builder, uint32_t size)
Definition builder.h:152
spa_pod_builder_string_len
static int spa_pod_builder_string_len(struct spa_pod_builder *builder, const char *str, uint32_t len)
Definition builder.h:296
SPA_POD_INIT_Struct
#define SPA_POD_INIT_Struct(size)
Definition builder.h:419
spa_pod_builder_push_array
static int spa_pod_builder_push_array(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:372
spa_pod_builder_primitive
static int spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p)
Definition builder.h:186
spa_choice_from_id
static uint32_t spa_choice_from_id(char id)
Definition builder.h:477
spa_pod_builder_push_struct
static int spa_pod_builder_push_struct(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:422
spa_pod_builder_control
static int spa_pod_builder_control(struct spa_pod_builder *builder, uint32_t offset, uint32_t type)
Definition builder.h:471
spa_pod_builder_get_state
static void spa_pod_builder_get_state(struct spa_pod_builder *builder, struct spa_pod_builder_state *state)
Definition builder.h:65
spa_pod_builder_bool
static int spa_pod_builder_bool(struct spa_pod_builder *builder, bool val)
Definition builder.h:229
SPA_POD_BUILDER_COLLECT
#define SPA_POD_BUILDER_COLLECT(builder, type, args)
Definition builder.h:494
spa_pod_copy
static struct spa_pod * spa_pod_copy(const struct spa_pod *pod)
Copy a pod structure.
Definition builder.h:688
spa_pod_builder_raw
static int spa_pod_builder_raw(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:128
SPA_POD_INIT_Int
#define SPA_POD_INIT_Int(val)
Definition builder.h:245
spa_pod_builder_bytes
static int spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len)
Definition builder.h:315
spa_pod_builder_push_choice
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
spa_pod_builder_int
static int spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val)
Definition builder.h:247
spa_pod_builder_init
static void spa_pod_builder_init(struct spa_pod_builder *builder, void *data, uint32_t size)
Definition builder.h:87
spa_pod_builder_push_object
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
SPA_POD_INIT_Float
#define SPA_POD_INIT_Float(val)
Definition builder.h:263
spa_pod_builder_long
static int spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val)
Definition builder.h:256
SPA_POD_INIT_Bytes
#define SPA_POD_INIT_Bytes(len)
Definition builder.h:312
SPA_POD_INIT_Fd
#define SPA_POD_INIT_Fd(fd)
Definition builder.h:343
spa_pod_builder_array
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
SPA_POD_INIT_Long
#define SPA_POD_INIT_Long(val)
Definition builder.h:254
SPA_POD_INIT_Pointer
#define SPA_POD_INIT_Pointer(type, value)
Definition builder.h:333
SPA_POD_INIT_Fraction
#define SPA_POD_INIT_Fraction(val)
Definition builder.h:362
SPA_POD_BUILDER_FLAG_FIRST
#define SPA_POD_BUILDER_FLAG_FIRST
Definition builder.h:37
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition pod.h:30
spa_pod_builder_addv
static int spa_pod_builder_addv(struct spa_pod_builder *builder, va_list args)
Definition builder.h:590
spa_pod_builder_deref
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:93
spa_pod_builder_pointer
static int spa_pod_builder_pointer(struct spa_pod_builder *builder, uint32_t type, const void *val)
Definition builder.h:336
SPA_CHOICE_Step
@ SPA_CHOICE_Step
range with step: default, min, max, step
Definition pod.h:149
SPA_CHOICE_None
@ SPA_CHOICE_None
no choice, first value is current
Definition pod.h:147
SPA_CHOICE_Flags
@ SPA_CHOICE_Flags
flags: default, possible flags,...
Definition pod.h:151
SPA_CHOICE_Range
@ SPA_CHOICE_Range
range: default, min, max
Definition pod.h:148
SPA_CHOICE_Enum
@ SPA_CHOICE_Enum
list: default, alternative,...
Definition pod.h:150
SPA_TYPE_Object
@ SPA_TYPE_Object
Definition type.h:45
SPA_TYPE_None
@ SPA_TYPE_None
Definition type.h:31
SPA_TYPE_Sequence
@ SPA_TYPE_Sequence
Definition type.h:46
SPA_TYPE_Choice
@ SPA_TYPE_Choice
Definition type.h:49
SPA_TYPE_Array
@ SPA_TYPE_Array
Definition type.h:43
SPA_ROUND_UP_N
#define SPA_ROUND_UP_N(num, align)
Definition defs.h:324
SPA_FRACTION
#define SPA_FRACTION(num, denom)
Definition defs.h:122
SPA_FLAG_IS_SET
#define SPA_FLAG_IS_SET(field, flag)
Definition defs.h:76
SPA_FALLTHROUGH
#define SPA_FALLTHROUGH
SPA_FALLTHROUGH is an annotation to suppress compiler warnings about switch cases that fall through w...
Definition defs.h:70
SPA_FLAG_CLEAR
#define SPA_FLAG_CLEAR(field, flag)
Definition defs.h:80
SPA_PTROFF
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition defs.h:198
SPA_RECTANGLE
#define SPA_RECTANGLE(width, height)
Definition defs.h:101
hook.h
spa/utils/hook.h
iter.h
spa/pod/iter.h
spa_callbacks
Callbacks, contains the structure with functions and the data passed to the functions.
Definition hook.h:116
spa_pod_array_body
Definition pod.h:121
spa_pod_array
Definition pod.h:126
spa_pod_array::pod
struct spa_pod pod
Definition pod.h:127
spa_pod_bool
Definition pod.h:51
spa_pod_bool::pod
struct spa_pod pod
Definition pod.h:52
spa_pod_builder_callbacks
Definition builder.h:45
spa_pod_builder_callbacks::overflow
int(* overflow)(void *data, uint32_t size)
Definition builder.h:50
spa_pod_builder_callbacks::version
uint32_t version
Definition builder.h:48
spa_pod_builder_state
Definition builder.h:32
spa_pod_builder_state::flags
uint32_t flags
Definition builder.h:38
spa_pod_builder_state::offset
uint32_t offset
Definition builder.h:33
spa_pod_builder_state::frame
struct spa_pod_frame * frame
Definition builder.h:39
spa_pod_builder
Definition builder.h:53
spa_pod_builder::_padding
uint32_t _padding
Definition builder.h:56
spa_pod_builder::callbacks
struct spa_callbacks callbacks
Definition builder.h:58
spa_pod_builder::data
void * data
Definition builder.h:54
spa_pod_builder::state
struct spa_pod_builder_state state
Definition builder.h:57
spa_pod_builder::size
uint32_t size
Definition builder.h:55
spa_pod_bytes
Definition pod.h:90
spa_pod_choice_body
Definition pod.h:154
spa_pod_choice_body::type
uint32_t type
type of choice, one of enum spa_choice_type
Definition pod.h:155
spa_pod_choice_body::flags
uint32_t flags
extra flags
Definition pod.h:156
spa_pod_choice
Definition pod.h:162
spa_pod_choice::pod
struct spa_pod pod
Definition pod.h:163
spa_pod_double
Definition pod.h:80
spa_pod_double::pod
struct spa_pod pod
Definition pod.h:81
spa_pod_fd
Definition pod.h:199
spa_pod_fd::pod
struct spa_pod pod
Definition pod.h:200
spa_pod_float
Definition pod.h:74
spa_pod_float::pod
struct spa_pod pod
Definition pod.h:75
spa_pod_fraction
Definition pod.h:100
spa_pod_fraction::pod
struct spa_pod pod
Definition pod.h:101
spa_pod_frame
Definition iter.h:27
spa_pod_frame::pod
struct spa_pod pod
Definition iter.h:28
spa_pod_frame::offset
uint32_t offset
Definition iter.h:30
spa_pod_frame::parent
struct spa_pod_frame * parent
Definition iter.h:29
spa_pod_frame::flags
uint32_t flags
Definition iter.h:31
spa_pod_id
Definition pod.h:57
spa_pod_id::pod
struct spa_pod pod
Definition pod.h:58
spa_pod_int
Definition pod.h:63
spa_pod_int::pod
struct spa_pod pod
Definition pod.h:64
spa_pod_long
Definition pod.h:69
spa_pod_long::pod
struct spa_pod pod
Definition pod.h:70
spa_pod_object_body
Definition pod.h:177
spa_pod_object
Definition pod.h:183
spa_pod_object::pod
struct spa_pod pod
Definition pod.h:184
spa_pod_pointer
Definition pod.h:194
spa_pod_pointer::pod
struct spa_pod pod
Definition pod.h:195
spa_pod_rectangle
Definition pod.h:95
spa_pod_rectangle::pod
struct spa_pod pod
Definition pod.h:96
spa_pod_sequence_body
Definition pod.h:241
spa_pod_sequence
a sequence of timed controls
Definition pod.h:248
spa_pod_sequence::pod
struct spa_pod pod
Definition pod.h:249
spa_pod_string
Definition pod.h:85
spa_pod_struct
Definition pod.h:167
spa_pod_struct::pod
struct spa_pod pod
Definition pod.h:168
spa_pod
Definition pod.h:43
spa_pod::type
uint32_t type
Definition pod.h:45
spa_pod::size
uint32_t size
Definition pod.h:44
vararg.h
spa/pod/vararg.h