PipeWire  0.3.33
debug/pod.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_DEBUG_POD_H
26 #define SPA_DEBUG_POD_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 #include <spa/debug/mem.h>
38 #include <spa/debug/types.h>
39 #include <spa/pod/pod.h>
40 #include <spa/pod/iter.h>
41 
42 #ifndef spa_debug
43 #define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
44 #endif
45 
46 /* static */ inline int
47 spa_debug_pod_value(int indent, const struct spa_type_info *info,
48  uint32_t type, void *body, uint32_t size)
49 {
50  switch (type) {
51  case SPA_TYPE_Bool:
52  spa_debug("%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false");
53  break;
54  case SPA_TYPE_Id:
55  spa_debug("%*s" "Id %-8d (%s)", indent, "", *(int32_t *) body,
56  spa_debug_type_find_name(info, *(int32_t *) body));
57  break;
58  case SPA_TYPE_Int:
59  spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body);
60  break;
61  case SPA_TYPE_Long:
62  spa_debug("%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body);
63  break;
64  case SPA_TYPE_Float:
65  spa_debug("%*s" "Float %f", indent, "", *(float *) body);
66  break;
67  case SPA_TYPE_Double:
68  spa_debug("%*s" "Double %f", indent, "", *(double *) body);
69  break;
70  case SPA_TYPE_String:
71  spa_debug("%*s" "String \"%s\"", indent, "", (char *) body);
72  break;
73  case SPA_TYPE_Fd:
74  spa_debug("%*s" "Fd %d", indent, "", *(int *) body);
75  break;
76  case SPA_TYPE_Pointer:
77  {
78  struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body;
79  spa_debug("%*s" "Pointer %s %p", indent, "",
81  break;
82  }
83  case SPA_TYPE_Rectangle:
84  {
85  struct spa_rectangle *r = (struct spa_rectangle *)body;
86  spa_debug("%*s" "Rectangle %dx%d", indent, "", r->width, r->height);
87  break;
88  }
89  case SPA_TYPE_Fraction:
90  {
91  struct spa_fraction *f = (struct spa_fraction *)body;
92  spa_debug("%*s" "Fraction %d/%d", indent, "", f->num, f->denom);
93  break;
94  }
95  case SPA_TYPE_Bitmap:
96  spa_debug("%*s" "Bitmap", indent, "");
97  break;
98  case SPA_TYPE_Array:
99  {
100  struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
101  void *p;
102  const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type);
103 
104  spa_debug("%*s" "Array: child.size %d, child.type %s", indent, "",
105  b->child.size, ti ? ti->name : "unknown");
106 
107  info = info && info->values ? info->values : info;
108  SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
109  spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
110  break;
111  }
112  case SPA_TYPE_Choice:
113  {
114  struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body;
115  void *p;
116  const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type);
117 
118  spa_debug("%*s" "Choice: type %s, flags %08x %d %d", indent, "",
119  ti ? ti->name : "unknown", b->flags, size, b->child.size);
120 
121  SPA_POD_CHOICE_BODY_FOREACH(b, size, p)
122  spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
123  break;
124  }
125  case SPA_TYPE_Struct:
126  {
127  struct spa_pod *b = (struct spa_pod *)body, *p;
128  spa_debug("%*s" "Struct: size %d", indent, "", size);
129  SPA_POD_FOREACH(b, size, p)
130  spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size);
131  break;
132  }
133  case SPA_TYPE_Object:
134  {
135  struct spa_pod_object_body *b = (struct spa_pod_object_body *)body;
136  struct spa_pod_prop *p;
137  const struct spa_type_info *ti, *ii;
138 
139  ti = spa_debug_type_find(info, b->type);
140  ii = ti ? spa_debug_type_find(ti->values, 0) : NULL;
141  ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL;
142 
143  spa_debug("%*s" "Object: size %d, type %s (%d), id %s (%d)", indent, "", size,
144  ti ? ti->name : "unknown", b->type, ii ? ii->name : "unknown", b->id);
145 
146  info = ti ? ti->values : info;
147 
148  SPA_POD_OBJECT_BODY_FOREACH(b, size, p) {
149  ii = spa_debug_type_find(info, p->key);
150 
151  spa_debug("%*s" "Prop: key %s (%d), flags %08x", indent+2, "",
152  ii ? ii->name : "unknown", p->key, p->flags);
153 
154  spa_debug_pod_value(indent + 4, ii ? ii->values : NULL,
155  p->value.type,
156  SPA_POD_CONTENTS(struct spa_pod_prop, p),
157  p->value.size);
158  }
159  break;
160  }
161  case SPA_TYPE_Sequence:
162  {
163  struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body;
164  const struct spa_type_info *ti, *ii;
165  struct spa_pod_control *c;
166 
167  ti = spa_debug_type_find(info, b->unit);
168 
169  spa_debug("%*s" "Sequence: size %d, unit %s", indent, "", size,
170  ti ? ti->name : "unknown");
171 
172  SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) {
174 
175  spa_debug("%*s" "Control: offset %d, type %s", indent+2, "",
176  c->offset, ii ? ii->name : "unknown");
177 
178  spa_debug_pod_value(indent + 4, ii ? ii->values : NULL,
179  c->value.type,
181  c->value.size);
182  }
183  break;
184  }
185  case SPA_TYPE_Bytes:
186  spa_debug("%*s" "Bytes", indent, "");
187  spa_debug_mem(indent + 2, body, size);
188  break;
189  case SPA_TYPE_None:
190  spa_debug("%*s" "None", indent, "");
191  spa_debug_mem(indent + 2, body, size);
192  break;
193  default:
194  spa_debug("%*s" "unhandled POD type %d", indent, "", type);
195  break;
196  }
197  return 0;
198 }
199 
200 /* static */ inline int spa_debug_pod(int indent,
201  const struct spa_type_info *info, const struct spa_pod *pod)
202 {
203  return spa_debug_pod_value(indent, info ? info : SPA_TYPE_ROOT,
204  SPA_POD_TYPE(pod),
205  SPA_POD_BODY(pod),
206  SPA_POD_BODY_SIZE(pod));
207 }
208 
214 #ifdef __cplusplus
215 } /* extern "C" */
216 #endif
217 
218 #endif /* SPA_DEBUG_POD_H */
SPA_TYPE_None
@ SPA_TYPE_None
Definition: build-12775836/doc/spa/utils/type.h:45
spa_rectangle::width
uint32_t width
Definition: defs.h:87
SPA_TYPE_Float
@ SPA_TYPE_Float
Definition: build-12775836/doc/spa/utils/type.h:50
SPA_POD_CHOICE_BODY_FOREACH
#define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter)
Definition: iter.h:102
SPA_TYPE_Long
@ SPA_TYPE_Long
Definition: build-12775836/doc/spa/utils/type.h:49
spa_pod_object_body::type
uint32_t type
one of enum spa_type
Definition: pod/pod.h:170
spa_type_control
const struct spa_type_info spa_type_control[]
Definition: control/type-info.h:45
spa_type_choice
const struct spa_type_info spa_type_choice[]
Definition: utils/type-info.h:69
types.h
SPA_TYPE_Id
@ SPA_TYPE_Id
Definition: build-12775836/doc/spa/utils/type.h:47
spa_type_info::type
uint32_t type
Definition: build-12775836/doc/spa/utils/type.h:138
spa_pod_sequence_body::unit
uint32_t unit
Definition: pod/pod.h:227
SPA_TYPE_Int
@ SPA_TYPE_Int
Definition: build-12775836/doc/spa/utils/type.h:48
spa_pod_pointer_body
Definition: pod/pod.h:180
spa_type_info
Definition: build-12775836/doc/spa/utils/type.h:137
spa_pod_object_body
Definition: pod/pod.h:169
spa_pod_prop
Definition: pod/pod.h:199
spa_pod_object_body::id
uint32_t id
id of the object, depends on the object type
Definition: pod/pod.h:171
spa_pod_control
Definition: pod/pod.h:219
spa_rectangle::height
uint32_t height
Definition: defs.h:88
spa_pod_choice_body::child
struct spa_pod child
Definition: pod/pod.h:151
spa_fraction
Definition: defs.h:104
SPA_TYPE_Array
@ SPA_TYPE_Array
Definition: build-12775836/doc/spa/utils/type.h:57
spa_debug
#define spa_debug(...)
Definition: debug/pod.h:43
SPA_POD_OBJECT_BODY_FOREACH
#define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter)
Definition: iter.h:118
SPA_POD_TYPE
#define SPA_POD_TYPE(pod)
Definition: pod/pod.h:41
SPA_TYPE_Rectangle
@ SPA_TYPE_Rectangle
Definition: build-12775836/doc/spa/utils/type.h:54
spa_pod_pointer_body::value
const void * value
Definition: pod/pod.h:183
spa_pod_choice_body
Definition: pod/pod.h:148
SPA_POD_ARRAY_BODY_FOREACH
#define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter)
Definition: iter.h:94
SPA_TYPE_Pointer
@ SPA_TYPE_Pointer
Definition: build-12775836/doc/spa/utils/type.h:61
spa_pod_sequence_body
Definition: pod/pod.h:226
spa_rectangle
Definition: defs.h:86
spa_type_info::name
const char * name
Definition: build-12775836/doc/spa/utils/type.h:140
spa_pod
Definition: pod/pod.h:50
SPA_TYPE_Fd
@ SPA_TYPE_Fd
Definition: build-12775836/doc/spa/utils/type.h:62
spa_handle_factory::info
const struct spa_dict * info
Extra information about the handles of this factory.
Definition: plugin.h:130
SPA_TYPE_String
@ SPA_TYPE_String
Definition: build-12775836/doc/spa/utils/type.h:52
SPA_TYPE_Bitmap
@ SPA_TYPE_Bitmap
Definition: build-12775836/doc/spa/utils/type.h:56
spa_pod_control::type
uint32_t type
type of control, enum spa_control_type
Definition: pod/pod.h:221
spa_debug_mem
int spa_debug_mem(int indent, const void *data, size_t size)
Definition: build-12775836/doc/spa/debug/mem.h:43
SPA_TYPE_Bool
@ SPA_TYPE_Bool
Definition: build-12775836/doc/spa/utils/type.h:46
spa_pod_array_body
Definition: pod/pod.h:122
spa_pod_pointer_body::type
uint32_t type
pointer id, one of enum spa_type
Definition: pod/pod.h:181
SPA_POD_SEQUENCE_BODY_FOREACH
#define SPA_POD_SEQUENCE_BODY_FOREACH(body, size, iter)
Definition: iter.h:126
SPA_POD_BODY
#define SPA_POD_BODY(pod)
Definition: pod/pod.h:47
spa_pod_prop::key
uint32_t key
key of property, list of valid keys depends on the object type
Definition: pod/pod.h:200
spa_pod::size
uint32_t size
Definition: pod/pod.h:51
SPA_TYPE_ROOT
#define SPA_TYPE_ROOT
Definition: utils/type-info.h:40
SPA_TYPE_Bytes
@ SPA_TYPE_Bytes
Definition: build-12775836/doc/spa/utils/type.h:53
SPA_TYPE_Double
@ SPA_TYPE_Double
Definition: build-12775836/doc/spa/utils/type.h:51
SPA_POD_BODY_SIZE
#define SPA_POD_BODY_SIZE(pod)
Definition: pod/pod.h:40
SPA_TYPE_Object
@ SPA_TYPE_Object
Definition: build-12775836/doc/spa/utils/type.h:59
SPA_TYPE_Sequence
@ SPA_TYPE_Sequence
Definition: build-12775836/doc/spa/utils/type.h:60
spa_type_info::values
const struct spa_type_info * values
Definition: build-12775836/doc/spa/utils/type.h:141
spa_pod_control::value
struct spa_pod value
control value, depends on type
Definition: pod/pod.h:222
spa_fraction::denom
uint32_t denom
Definition: defs.h:106
spa_pod_choice_body::type
uint32_t type
type of choice, one of enum spa_choice_type
Definition: pod/pod.h:149
SPA_TYPE_Fraction
@ SPA_TYPE_Fraction
Definition: build-12775836/doc/spa/utils/type.h:55
spa_pod::type
uint32_t type
Definition: pod/pod.h:52
spa_debug_type_find
const struct spa_type_info * spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
Definition: types.h:41
mem.h
spa_debug_pod_value
int spa_debug_pod_value(int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size)
Definition: debug/pod.h:47
spa_pod_prop::flags
uint32_t flags
flags for property
Definition: pod/pod.h:211
iter.h
SPA_TYPE_Choice
@ SPA_TYPE_Choice
Definition: build-12775836/doc/spa/utils/type.h:63
spa_debug_pod
int spa_debug_pod(int indent, const struct spa_type_info *info, const struct spa_pod *pod)
Definition: debug/pod.h:200
SPA_POD_CONTENTS
#define SPA_POD_CONTENTS(type, pod)
Definition: pod/pod.h:45
spa_pod_prop::value
struct spa_pod value
Definition: pod/pod.h:212
spa_fraction::num
uint32_t num
Definition: defs.h:105
spa_pod_choice_body::flags
uint32_t flags
extra flags
Definition: pod/pod.h:150
SPA_POD_FOREACH
#define SPA_POD_FOREACH(pod, size, iter)
Definition: iter.h:110
spa_pod_control::offset
uint32_t offset
media offset
Definition: pod/pod.h:220
pod.h
spa_pod_array_body::child
struct spa_pod child
Definition: pod/pod.h:123
SPA_TYPE_Struct
@ SPA_TYPE_Struct
Definition: build-12775836/doc/spa/utils/type.h:58
spa_debug_type_find_name
const char * spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
Definition: types.h:68