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