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