+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 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 | #include <inttypes.h> |
| 9 | |
| 10 | #include <spa/debug/context.h> |
| 11 | #include <spa/debug/mem.h> |
| 12 | #include <spa/debug/types.h> |
| 13 | #include <spa/pod/pod.h> |
| 14 | #include <spa/pod/iter.h> |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | /** |
| 21 | * \addtogroup spa_debug |
| 22 | * \{ |
| 23 | */ |
| 24 | |
| 25 | #ifndef SPA_API_DEBUG_POD |
| 26 | #ifdef SPA_API_IMPL |
| 27 | #define SPA_API_DEBUG_POD SPA_API_IMPL |
| 28 | #else |
| 29 | #define SPA_API_DEBUG_POD static inline |
| 30 | #endif |
| 31 | #endif |
| 32 | |
| 33 | SPA_API_DEBUG_POD int |
| 34 | spa_debugc_pod_value(struct spa_debug_context *ctx, int indent, const struct spa_type_info *info, |
| 35 | uint32_t type, void *body, uint32_t size) |
| 36 | { |
| 37 | switch (type) { |
| 38 | case SPA_TYPE_Bool: |
| 39 | spa_debugc(ctx, "%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false"); |
| 40 | break; |
| 41 | case SPA_TYPE_Id: |
| 42 | spa_debugc(ctx, "%*s" "Id %-8" PRIu32 " (%s)", indent, "", *(uint32_t *) body, |
| 43 | spa_debug_type_find_name(info, *(uint32_t *) body)); |
| 44 | break; |
| 45 | case SPA_TYPE_Int: |
| 46 | spa_debugc(ctx, "%*s" "Int %" PRId32, indent, "", *(int32_t *) body); |
| 47 | break; |
| 48 | case SPA_TYPE_Long: |
| 49 | spa_debugc(ctx, "%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body); |
| 50 | break; |
| 51 | case SPA_TYPE_Float: |
| 52 | spa_debugc(ctx, "%*s" "Float %f", indent, "", *(float *) body); |
| 53 | break; |
| 54 | case SPA_TYPE_Double: |
| 55 | spa_debugc(ctx, "%*s" "Double %f", indent, "", *(double *) body); |
| 56 | break; |
| 57 | case SPA_TYPE_String: |
| 58 | spa_debugc(ctx, "%*s" "String \"%s\"", indent, "", (char *) body); |
| 59 | break; |
| 60 | case SPA_TYPE_Fd: |
| 61 | spa_debugc(ctx, "%*s" "Fd %d", indent, "", *(int *) body); |
| 62 | break; |
| 63 | case SPA_TYPE_Pointer: |
| 64 | { |
| 65 | struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body; |
| 66 | spa_debugc(ctx, "%*s" "Pointer %s %p", indent, "", |
| 67 | spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value); |
| 68 | break; |
| 69 | } |
| 70 | case SPA_TYPE_Rectangle: |
| 71 | { |
| 72 | struct spa_rectangle *r = (struct spa_rectangle *)body; |
| 73 | spa_debugc(ctx, "%*s" "Rectangle %" PRIu32 "x%" PRIu32 "", indent, "", r->width, r->height); |
| 74 | break; |
| 75 | } |
| 76 | case SPA_TYPE_Fraction: |
| 77 | { |
| 78 | struct spa_fraction *f = (struct spa_fraction *)body; |
| 79 | spa_debugc(ctx, "%*s" "Fraction %" PRIu32 "/%" PRIu32 "", indent, "", f->num, f->denom); |
| 80 | break; |
| 81 | } |
| 82 | case SPA_TYPE_Bitmap: |
| 83 | spa_debugc(ctx, "%*s" "Bitmap", indent, ""); |
| 84 | break; |
| 85 | case SPA_TYPE_Array: |
| 86 | { |
| 87 | struct spa_pod_array_body *b = (struct spa_pod_array_body *)body; |
| 88 | void *p; |
| 89 | const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type); |
| 90 | uint32_t min_size = spa_pod_type_size(b->child.type); |
| 91 | |
| 92 | spa_debugc(ctx, "%*s" "Array: child.size %" PRIu32 ", child.type %s", indent, "", |
| 93 | b->child.size, ti ? ti->name : "unknown"); |
| 94 | |
| 95 | if (b->child.size < min_size) { |
| 96 | spa_debugc(ctx, "%*s" " INVALID child.size < %" PRIu32, indent, "", min_size); |
| 97 | } else { |
| 98 | info = info && info->values ? info->values : info; |
| 99 | SPA_POD_ARRAY_BODY_FOREACH(b, size, p) |
| 100 | spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); |
| 101 | } |
| 102 | break; |
| 103 | } |
| 104 | case SPA_TYPE_Choice: |
| 105 | { |
| 106 | struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body; |
| 107 | void *p; |
| 108 | const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type); |
| 109 | uint32_t min_size = spa_pod_type_size(b->child.type); |
| 110 | |
| 111 | spa_debugc(ctx, "%*s" "Choice: type %s, flags %08" PRIx32 " %" PRIu32 " %" PRIu32, indent, "", |
| 112 | ti ? ti->name : "unknown", b->flags, size, b->child.size); |
| 113 | |
| 114 | if (b->child.size < min_size) { |
| 115 | spa_debugc(ctx, "%*s" "INVALID child.size < %" PRIu32, indent, "", min_size); |
| 116 | } else { |
| 117 | SPA_POD_CHOICE_BODY_FOREACH(b, size, p) |
| 118 | spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); |
| 119 | } |
| 120 | break; |
| 121 | } |
| 122 | case SPA_TYPE_Struct: |
| 123 | { |
| 124 | struct spa_pod *b = (struct spa_pod *)body, *p; |
| 125 | spa_debugc(ctx, "%*s" "Struct: size %" PRIu32, indent, "", size); |
| 126 | SPA_POD_FOREACH(b, size, p) { |
| 127 | uint32_t min_size = spa_pod_type_size(p->type); |
| 128 | if (p->size < min_size) { |
| 129 | spa_debugc(ctx, "%*s" "INVALID child.size < %" PRIu32, indent, "", min_size); |
| 130 | } else { |
| 131 | spa_debugc_pod_value(ctx, indent + 2, info, p->type, SPA_POD_BODY(p), p->size); |
| 132 | } |
| 133 | } |
| 134 | break; |
| 135 | } |
| 136 | case SPA_TYPE_Object: |
| 137 | { |
| 138 | struct spa_pod_object_body *b = (struct spa_pod_object_body *)body; |
| 139 | struct spa_pod_prop *p; |
| 140 | const struct spa_type_info *ti, *ii; |
| 141 | |
| 142 | ti = spa_debug_type_find(info, b->type); |
| 143 | ii = ti ? spa_debug_type_find(ti->values, 0) : NULL; |
| 144 | ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL; |
| 145 | |
| 146 | spa_debugc(ctx, "%*s" "Object: size %" PRIu32 ", type %s (%" PRIu32 "), id %s (%" PRIu32 ")", |
| 147 | indent, "", size, ti ? ti->name : "unknown", b->type, ii ? ii->name : "unknown", b->id); |
| 148 | |
| 149 | info = ti ? ti->values : info; |
| 150 | |
| 151 | SPA_POD_OBJECT_BODY_FOREACH(b, size, p) { |
| 152 | static const char custom_prefix[] = SPA_TYPE_INFO_PROPS_BASE "Custom:"; |
| 153 | char custom_name[sizeof(custom_prefix) + 16]; |
| 154 | const char *name = "unknown"; |
| 155 | uint32_t min_size = spa_pod_type_size(p->value.type); |
| 156 | |
| 157 | ii = spa_debug_type_find(info, p->key); |
| 158 | if (ii) { |
| 159 | name = ii->name; |
| 160 | } else if (p->key >= SPA_PROP_START_CUSTOM) { |
| 161 | snprintf(custom_name, sizeof(custom_name), |
| 162 | "%s%" PRIu32, custom_prefix, p->key - SPA_PROP_START_CUSTOM); |
| 163 | name = custom_name; |
| 164 | } |
| 165 | |
| 166 | spa_debugc(ctx, "%*s" "Prop: key %s (%" PRIu32 "), flags %08" PRIx32, |
| 167 | indent+2, "", name, p->key, p->flags); |
| 168 | |
| 169 | if (p->value.size < min_size) { |
| 170 | spa_debugc(ctx, "%*s" "INVALID value.size < %" PRIu32, indent, "", min_size); |
| 171 | } else { |
| 172 | spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL, |
| 173 | p->value.type, |
| 174 | SPA_POD_CONTENTS(struct spa_pod_prop, p), |
| 175 | p->value.size); |
| 176 | } |
| 177 | } |
| 178 | break; |
| 179 | } |
| 180 | case SPA_TYPE_Sequence: |
| 181 | { |
| 182 | struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body; |
| 183 | const struct spa_type_info *ti, *ii; |
| 184 | struct spa_pod_control *c; |
| 185 | |
| 186 | ti = spa_debug_type_find(info, b->unit); |
| 187 | |
| 188 | spa_debugc(ctx, "%*s" "Sequence: size %" PRIu32 ", unit %s", indent, "", size, |
| 189 | ti ? ti->name : "unknown"); |
| 190 | |
| 191 | SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) { |
| 192 | uint32_t min_size = spa_pod_type_size(c->value.type); |
| 193 | |
| 194 | ii = spa_debug_type_find(spa_type_control, c->type); |
| 195 | |
| 196 | spa_debugc(ctx, "%*s" "Control: offset %" PRIu32 ", type %s", indent+2, "", |
| 197 | c->offset, ii ? ii->name : "unknown"); |
| 198 | |
| 199 | if (c->value.size < min_size) { |
| 200 | spa_debugc(ctx, "%*s" "INVALID value.size < %" PRIu32, indent, "", min_size); |
| 201 | } else { |
| 202 | spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL, |
| 203 | c->value.type, |
| 204 | SPA_POD_CONTENTS(struct spa_pod_control, c), |
| 205 | c->value.size); |
| 206 | } |
| 207 | } |
| 208 | break; |
| 209 | } |
| 210 | case SPA_TYPE_Bytes: |
| 211 | spa_debugc(ctx, "%*s" "Bytes", indent, ""); |
| 212 | spa_debugc_mem(ctx, indent + 2, body, size); |
| 213 | break; |
| 214 | case SPA_TYPE_None: |
| 215 | spa_debugc(ctx, "%*s" "None", indent, ""); |
| 216 | spa_debugc_mem(ctx, indent + 2, body, size); |
| 217 | break; |
| 218 | default: |
| 219 | spa_debugc(ctx, "%*s" "unhandled POD type %" PRIu32, indent, "", type); |
| 220 | break; |
| 221 | } |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | SPA_API_DEBUG_POD int spa_debugc_pod(struct spa_debug_context *ctx, int indent, |
| 226 | const struct spa_type_info *info, const struct spa_pod *pod) |
| 227 | { |
| 228 | if (pod->size < spa_pod_type_size(pod->type)) |
| 229 | return -EINVAL; |
| 230 | return spa_debugc_pod_value(ctx, indent, info ? info : SPA_TYPE_ROOT, |
| 231 | pod->type, SPA_POD_BODY(pod), pod->size); |
| 232 | } |
| 233 | |
| 234 | SPA_API_DEBUG_POD int |
| 235 | spa_debug_pod_value(int indent, const struct spa_type_info *info, |
| 236 | uint32_t type, void *body, uint32_t size) |
| 237 | { |
| 238 | return spa_debugc_pod_value(NULL, indent, info, type, body, size); |
| 239 | } |
| 240 | |
| 241 | SPA_API_DEBUG_POD int spa_debug_pod(int indent, |
| 242 | const struct spa_type_info *info, const struct spa_pod *pod) |
| 243 | { |
| 244 | return spa_debugc_pod(NULL, indent, info, pod); |
| 245 | } |
| 246 | /** |
| 247 | * \} |
| 248 | */ |
| 249 | |
| 250 | |
| 251 | #ifdef __cplusplus |
| 252 | } /* extern "C" */ |
| 253 | #endif |
| 254 | |
| 255 | #endif /* SPA_DEBUG_POD_H */ |