2023-02-08 18:12:00 +01:00
|
|
|
/* Simple Plugin API */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2018-08-14 12:33:53 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#ifndef SPA_DEBUG_POD_H
|
|
|
|
|
#define SPA_DEBUG_POD_H
|
2018-08-14 12:33:53 +02:00
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
2025-05-27 09:06:08 +01:00
|
|
|
#include <spa/debug/context.h>
|
|
|
|
|
#include <spa/debug/mem.h>
|
|
|
|
|
#include <spa/debug/types.h>
|
|
|
|
|
#include <spa/pod/pod.h>
|
|
|
|
|
#include <spa/pod/iter.h>
|
|
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \addtogroup spa_debug
|
|
|
|
|
* \{
|
|
|
|
|
*/
|
|
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
#ifndef SPA_API_DEBUG_POD
|
|
|
|
|
#ifdef SPA_API_IMPL
|
|
|
|
|
#define SPA_API_DEBUG_POD SPA_API_IMPL
|
|
|
|
|
#else
|
|
|
|
|
#define SPA_API_DEBUG_POD static inline
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SPA_API_DEBUG_POD int
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_debugc_pod_value(struct spa_debug_context *ctx, int indent, const struct spa_type_info *info,
|
2018-08-14 12:33:53 +02:00
|
|
|
uint32_t type, void *body, uint32_t size)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bool:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false");
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-09-05 16:41:07 +02:00
|
|
|
case SPA_TYPE_Id:
|
2025-07-12 21:00:38 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Id %-8" PRIu32 " (%s)", indent, "", *(uint32_t *) body,
|
|
|
|
|
spa_debug_type_find_name(info, *(uint32_t *) body));
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Int:
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Int %" PRId32, indent, "", *(int32_t *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Long:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Float:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Float %f", indent, "", *(float *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Double:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Double %f", indent, "", *(double *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_String:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "String \"%s\"", indent, "", (char *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Fd:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Fd %d", indent, "", *(int *) body);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Pointer:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body;
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Pointer %s %p", indent, "",
|
2018-08-30 12:01:52 +02:00
|
|
|
spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Rectangle:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_rectangle *r = (struct spa_rectangle *)body;
|
2025-01-04 16:32:45 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Rectangle %" PRIu32 "x%" PRIu32 "", indent, "", r->width, r->height);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Fraction:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_fraction *f = (struct spa_fraction *)body;
|
2025-01-04 16:32:45 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Fraction %" PRIu32 "/%" PRIu32 "", indent, "", f->num, f->denom);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bitmap:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Bitmap", indent, "");
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Array:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
|
2018-08-14 12:33:53 +02:00
|
|
|
void *p;
|
2018-09-05 16:41:07 +02:00
|
|
|
const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type);
|
2025-07-22 13:14:17 +02:00
|
|
|
uint32_t min_size = spa_pod_type_size(b->child.type);
|
2018-08-25 12:08:29 +02:00
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Array: child.size %" PRIu32 ", child.type %s", indent, "",
|
2018-08-25 12:08:29 +02:00
|
|
|
b->child.size, ti ? ti->name : "unknown");
|
|
|
|
|
|
2025-07-22 13:14:17 +02:00
|
|
|
if (b->child.size < min_size) {
|
|
|
|
|
spa_debugc(ctx, "%*s" " INVALID child.size < %" PRIu32, indent, "", min_size);
|
|
|
|
|
} else {
|
|
|
|
|
info = info && info->values ? info->values : info;
|
|
|
|
|
SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
|
|
|
|
|
spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size);
|
|
|
|
|
}
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-09-05 16:41:07 +02:00
|
|
|
case SPA_TYPE_Choice:
|
|
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body;
|
2018-09-05 16:41:07 +02:00
|
|
|
void *p;
|
|
|
|
|
const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type);
|
2025-07-22 13:14:17 +02:00
|
|
|
uint32_t min_size = spa_pod_type_size(b->child.type);
|
2018-09-05 16:41:07 +02:00
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Choice: type %s, flags %08" PRIx32 " %" PRIu32 " %" PRIu32, indent, "",
|
2018-09-05 16:41:07 +02:00
|
|
|
ti ? ti->name : "unknown", b->flags, size, b->child.size);
|
|
|
|
|
|
2025-07-22 13:14:17 +02:00
|
|
|
if (b->child.size < min_size) {
|
|
|
|
|
spa_debugc(ctx, "%*s" "INVALID child.size < %" PRIu32, indent, "", min_size);
|
|
|
|
|
} else {
|
|
|
|
|
SPA_POD_CHOICE_BODY_FOREACH(b, size, p)
|
|
|
|
|
spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size);
|
|
|
|
|
}
|
2018-09-05 16:41:07 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Struct:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod *b = (struct spa_pod *)body, *p;
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Struct: size %" PRIu32, indent, "", size);
|
2025-07-22 13:14:17 +02:00
|
|
|
SPA_POD_FOREACH(b, size, p) {
|
|
|
|
|
uint32_t min_size = spa_pod_type_size(p->type);
|
|
|
|
|
if (p->size < min_size) {
|
|
|
|
|
spa_debugc(ctx, "%*s" "INVALID child.size < %" PRIu32, indent, "", min_size);
|
|
|
|
|
} else {
|
|
|
|
|
spa_debugc_pod_value(ctx, indent + 2, info, p->type, SPA_POD_BODY(p), p->size);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Object:
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_object_body *b = (struct spa_pod_object_body *)body;
|
2018-09-05 16:41:07 +02:00
|
|
|
struct spa_pod_prop *p;
|
2018-08-28 18:16:41 +02:00
|
|
|
const struct spa_type_info *ti, *ii;
|
2018-08-14 12:33:53 +02:00
|
|
|
|
2018-08-27 15:03:11 +02:00
|
|
|
ti = spa_debug_type_find(info, b->type);
|
|
|
|
|
ii = ti ? spa_debug_type_find(ti->values, 0) : NULL;
|
|
|
|
|
ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL;
|
|
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Object: size %" PRIu32 ", type %s (%" PRIu32 "), id %s (%" PRIu32 ")",
|
|
|
|
|
indent, "", size, ti ? ti->name : "unknown", b->type, ii ? ii->name : "unknown", b->id);
|
2018-08-25 12:08:29 +02:00
|
|
|
|
|
|
|
|
info = ti ? ti->values : info;
|
|
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
SPA_POD_OBJECT_BODY_FOREACH(b, size, p) {
|
2025-07-09 18:19:25 +02:00
|
|
|
static const char custom_prefix[] = SPA_TYPE_INFO_PROPS_BASE "Custom:";
|
|
|
|
|
char custom_name[sizeof(custom_prefix) + 16];
|
|
|
|
|
const char *name = "unknown";
|
2025-07-22 13:14:17 +02:00
|
|
|
uint32_t min_size = spa_pod_type_size(p->value.type);
|
2025-07-09 18:19:25 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
ii = spa_debug_type_find(info, p->key);
|
2025-07-09 18:19:25 +02:00
|
|
|
if (ii) {
|
|
|
|
|
name = ii->name;
|
|
|
|
|
} else if (p->key >= SPA_PROP_START_CUSTOM) {
|
|
|
|
|
snprintf(custom_name, sizeof(custom_name),
|
|
|
|
|
"%s%" PRIu32, custom_prefix, p->key - SPA_PROP_START_CUSTOM);
|
|
|
|
|
name = custom_name;
|
|
|
|
|
}
|
2018-09-05 16:41:07 +02:00
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Prop: key %s (%" PRIu32 "), flags %08" PRIx32,
|
2025-07-09 18:19:25 +02:00
|
|
|
indent+2, "", name, p->key, p->flags);
|
2018-09-05 16:41:07 +02:00
|
|
|
|
2025-07-22 13:14:17 +02:00
|
|
|
if (p->value.size < min_size) {
|
|
|
|
|
spa_debugc(ctx, "%*s" "INVALID value.size < %" PRIu32, indent, "", min_size);
|
|
|
|
|
} else {
|
|
|
|
|
spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL,
|
|
|
|
|
p->value.type,
|
|
|
|
|
SPA_POD_CONTENTS(struct spa_pod_prop, p),
|
|
|
|
|
p->value.size);
|
|
|
|
|
}
|
2018-09-05 16:41:07 +02:00
|
|
|
}
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-28 18:16:41 +02:00
|
|
|
case SPA_TYPE_Sequence:
|
|
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body;
|
2018-08-28 18:16:41 +02:00
|
|
|
const struct spa_type_info *ti, *ii;
|
|
|
|
|
struct spa_pod_control *c;
|
|
|
|
|
|
|
|
|
|
ti = spa_debug_type_find(info, b->unit);
|
|
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Sequence: size %" PRIu32 ", unit %s", indent, "", size,
|
2018-08-28 18:16:41 +02:00
|
|
|
ti ? ti->name : "unknown");
|
|
|
|
|
|
|
|
|
|
SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) {
|
2025-07-22 13:14:17 +02:00
|
|
|
uint32_t min_size = spa_pod_type_size(c->value.type);
|
|
|
|
|
|
2018-08-30 12:01:52 +02:00
|
|
|
ii = spa_debug_type_find(spa_type_control, c->type);
|
2018-08-28 18:16:41 +02:00
|
|
|
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "Control: offset %" PRIu32 ", type %s", indent+2, "",
|
2018-08-28 18:16:41 +02:00
|
|
|
c->offset, ii ? ii->name : "unknown");
|
|
|
|
|
|
2025-07-22 13:14:17 +02:00
|
|
|
if (c->value.size < min_size) {
|
|
|
|
|
spa_debugc(ctx, "%*s" "INVALID value.size < %" PRIu32, indent, "", min_size);
|
|
|
|
|
} else {
|
|
|
|
|
spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL,
|
|
|
|
|
c->value.type,
|
|
|
|
|
SPA_POD_CONTENTS(struct spa_pod_control, c),
|
|
|
|
|
c->value.size);
|
|
|
|
|
}
|
2018-08-28 18:16:41 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bytes:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "Bytes", indent, "");
|
|
|
|
|
spa_debugc_mem(ctx, indent + 2, body, size);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_None:
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s" "None", indent, "");
|
|
|
|
|
spa_debugc_mem(ctx, indent + 2, body, size);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2025-07-09 18:16:08 +02:00
|
|
|
spa_debugc(ctx, "%*s" "unhandled POD type %" PRIu32, indent, "", type);
|
2018-08-14 12:33:53 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_POD int spa_debugc_pod(struct spa_debug_context *ctx, int indent,
|
2018-08-23 17:47:57 +02:00
|
|
|
const struct spa_type_info *info, const struct spa_pod *pod)
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2025-07-22 13:14:17 +02:00
|
|
|
if (pod->size < spa_pod_type_size(pod->type))
|
|
|
|
|
return -EINVAL;
|
2023-01-18 13:09:00 +01:00
|
|
|
return spa_debugc_pod_value(ctx, indent, info ? info : SPA_TYPE_ROOT,
|
2025-06-07 15:21:37 -04:00
|
|
|
pod->type, SPA_POD_BODY(pod), pod->size);
|
2018-08-14 12:33:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_POD int
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debug_pod_value(int indent, const struct spa_type_info *info,
|
|
|
|
|
uint32_t type, void *body, uint32_t size)
|
|
|
|
|
{
|
|
|
|
|
return spa_debugc_pod_value(NULL, indent, info, type, body, size);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_POD int spa_debug_pod(int indent,
|
2023-01-18 13:09:00 +01:00
|
|
|
const struct spa_type_info *info, const struct spa_pod *pod)
|
|
|
|
|
{
|
|
|
|
|
return spa_debugc_pod(NULL, indent, info, pod);
|
|
|
|
|
}
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
} /* extern "C" */
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#endif /* SPA_DEBUG_POD_H */
|