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