PipeWire: spa/debug/pod.h Source File

PipeWire 0.3.51

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