2023-02-08 18:12:00 +01:00
|
|
|
/* Simple Plugin API */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#ifndef SPA_DEBUG_FORMAT_H
|
|
|
|
|
#define SPA_DEBUG_FORMAT_H
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2025-07-12 21:00:38 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
2025-07-29 15:15:02 +02:00
|
|
|
#include <spa/pod/iter.h>
|
2025-05-27 09:06:08 +01:00
|
|
|
#include <spa/utils/string.h>
|
|
|
|
|
#include <spa/debug/context.h>
|
|
|
|
|
#include <spa/debug/types.h>
|
|
|
|
|
#include <spa/param/type-info.h>
|
|
|
|
|
#include <spa/param/format-utils.h>
|
|
|
|
|
|
2017-06-20 12:30:07 +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_FORMAT
|
|
|
|
|
#ifdef SPA_API_IMPL
|
|
|
|
|
#define SPA_API_DEBUG_FORMAT SPA_API_IMPL
|
|
|
|
|
#else
|
|
|
|
|
#define SPA_API_DEBUG_FORMAT static inline
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SPA_API_DEBUG_FORMAT int
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_debug_strbuf_format_value(struct spa_strbuf *buffer, const struct spa_type_info *info,
|
2018-08-14 13:05:10 +02:00
|
|
|
uint32_t type, void *body, uint32_t size)
|
|
|
|
|
{
|
2023-01-18 11:46:21 +01:00
|
|
|
|
2018-08-14 13:05:10 +02:00
|
|
|
switch (type) {
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bool:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%s", *(int32_t *) body ? "true" : "false");
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-09-05 16:41:07 +02:00
|
|
|
case SPA_TYPE_Id:
|
2018-08-14 13:05:10 +02:00
|
|
|
{
|
2025-07-12 21:00:38 +02:00
|
|
|
uint32_t value = *(uint32_t *) body;
|
|
|
|
|
const char *str = spa_debug_type_find_short_name(info, value);
|
2018-08-23 17:47:57 +02:00
|
|
|
char tmp[64];
|
2020-07-22 11:22:11 +02:00
|
|
|
if (str == NULL) {
|
2025-07-12 21:00:38 +02:00
|
|
|
snprintf(tmp, sizeof(tmp), "%" PRIu32, value);
|
2018-08-23 17:47:57 +02:00
|
|
|
str = tmp;
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%s", str);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Int:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%d", *(int32_t *) body);
|
2018-08-25 12:08:29 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Long:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%" PRIi64, *(int64_t *) body);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Float:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%f", *(float *) body);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Double:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%f", *(double *) body);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_String:
|
2025-07-22 13:14:17 +02:00
|
|
|
spa_strbuf_append(buffer, "%-*s", size, (char *) body);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Rectangle:
|
2018-08-14 13:05:10 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_rectangle *r = (struct spa_rectangle *)body;
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%" PRIu32 "x%" PRIu32, r->width, r->height);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Fraction:
|
2018-08-14 13:05:10 +02:00
|
|
|
{
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_fraction *f = (struct spa_fraction *)body;
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bitmap:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "Bitmap");
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_Bytes:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "Bytes");
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
2018-09-05 16:41:07 +02:00
|
|
|
case SPA_TYPE_Array:
|
|
|
|
|
{
|
|
|
|
|
void *p;
|
2019-01-08 11:53:36 +01:00
|
|
|
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
|
2018-09-05 16:41:07 +02:00
|
|
|
int i = 0;
|
2020-12-15 16:06:10 +01:00
|
|
|
info = info && info->values ? info->values : info;
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "< ");
|
2025-07-22 13:14:17 +02:00
|
|
|
if (b->child.size >= spa_pod_type_size(b->child.type)) {
|
|
|
|
|
SPA_POD_ARRAY_BODY_FOREACH(b, size, p) {
|
|
|
|
|
if (i++ > 0)
|
|
|
|
|
spa_strbuf_append(buffer, ", ");
|
|
|
|
|
spa_debug_strbuf_format_value(buffer, info, b->child.type, p, b->child.size);
|
|
|
|
|
}
|
2018-09-05 16:41:07 +02:00
|
|
|
}
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, " >");
|
2018-09-05 16:41:07 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-14 13:05:10 +02:00
|
|
|
default:
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(buffer, "INVALID type %d", type);
|
2018-08-14 13:05:10 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2025-07-15 14:51:24 +02:00
|
|
|
return 0;
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_FORMAT int
|
2023-01-18 11:46:21 +01:00
|
|
|
spa_debug_format_value(const struct spa_type_info *info,
|
|
|
|
|
uint32_t type, void *body, uint32_t size)
|
|
|
|
|
{
|
|
|
|
|
char buffer[1024];
|
2023-01-18 17:41:16 +01:00
|
|
|
struct spa_strbuf buf;
|
|
|
|
|
spa_strbuf_init(&buf, buffer, sizeof(buffer));
|
|
|
|
|
spa_debug_strbuf_format_value(&buf, info, type, body, size);
|
2023-01-18 11:46:21 +01:00
|
|
|
spa_debugn("%s", buffer);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_FORMAT int spa_debugc_format(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 *format)
|
2018-08-14 12:33:53 +02:00
|
|
|
{
|
2018-08-14 13:05:10 +02:00
|
|
|
const char *media_type;
|
|
|
|
|
const char *media_subtype;
|
2018-09-05 16:41:07 +02:00
|
|
|
struct spa_pod_prop *prop;
|
2018-08-14 13:05:10 +02:00
|
|
|
uint32_t mtype, mstype;
|
|
|
|
|
|
2018-08-30 12:01:52 +02:00
|
|
|
if (info == NULL)
|
|
|
|
|
info = spa_type_format;
|
|
|
|
|
|
2025-06-07 15:21:37 -04:00
|
|
|
if (format == NULL || format->type != SPA_TYPE_Object)
|
2018-08-14 13:05:10 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-08-29 18:08:52 +02:00
|
|
|
if (spa_format_parse(format, &mtype, &mstype) < 0)
|
2018-08-14 13:05:10 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
media_type = spa_debug_type_find_name(spa_type_media_type, mtype);
|
|
|
|
|
media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype);
|
|
|
|
|
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%*s %s/%s", indent, "",
|
2020-07-22 11:22:11 +02:00
|
|
|
media_type ? spa_debug_type_short_name(media_type) : "unknown",
|
|
|
|
|
media_subtype ? spa_debug_type_short_name(media_subtype) : "unknown");
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, prop) {
|
2018-08-14 13:05:10 +02:00
|
|
|
const char *key;
|
2018-08-23 17:47:57 +02:00
|
|
|
const struct spa_type_info *ti;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t i, type, size, n_vals, choice;
|
2018-09-05 16:41:07 +02:00
|
|
|
const struct spa_pod *val;
|
|
|
|
|
void *vals;
|
2023-01-18 11:46:21 +01:00
|
|
|
char buffer[1024];
|
2023-01-18 17:41:16 +01:00
|
|
|
struct spa_strbuf buf;
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
if (prop->key == SPA_FORMAT_mediaType ||
|
|
|
|
|
prop->key == SPA_FORMAT_mediaSubtype)
|
2018-08-14 13:05:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
val = spa_pod_get_values(&prop->value, &n_vals, &choice);
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
type = val->type;
|
|
|
|
|
size = val->size;
|
2018-08-29 18:08:52 +02:00
|
|
|
|
2025-10-31 11:39:41 +01:00
|
|
|
if (type < SPA_TYPE_None || type >= _SPA_TYPE_LAST || n_vals < 1)
|
2019-01-08 11:53:36 +01:00
|
|
|
continue;
|
|
|
|
|
|
2025-07-22 13:14:17 +02:00
|
|
|
vals = SPA_POD_BODY(val);
|
2018-09-05 16:41:07 +02:00
|
|
|
ti = spa_debug_type_find(info, prop->key);
|
2018-08-23 17:47:57 +02:00
|
|
|
key = ti ? ti->name : NULL;
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_init(&buf, buffer, sizeof(buffer));
|
|
|
|
|
spa_strbuf_append(&buf, "%*s %16s : (%s) ", indent, "",
|
2020-07-22 11:22:11 +02:00
|
|
|
key ? spa_debug_type_short_name(key) : "unknown",
|
|
|
|
|
spa_debug_type_short_name(spa_types[type].name));
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
if (choice == SPA_CHOICE_None) {
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_debug_strbuf_format_value(&buf, ti ? ti->values : NULL, type, vals, size);
|
2018-08-14 13:05:10 +02:00
|
|
|
} else {
|
|
|
|
|
const char *ssep, *esep, *sep;
|
|
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
switch (choice) {
|
|
|
|
|
case SPA_CHOICE_Range:
|
|
|
|
|
case SPA_CHOICE_Step:
|
2018-08-14 13:05:10 +02:00
|
|
|
ssep = "[ ";
|
|
|
|
|
sep = ", ";
|
|
|
|
|
esep = " ]";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-09-05 16:41:07 +02:00
|
|
|
case SPA_CHOICE_Enum:
|
|
|
|
|
case SPA_CHOICE_Flags:
|
2018-08-14 13:05:10 +02:00
|
|
|
ssep = "{ ";
|
|
|
|
|
sep = ", ";
|
|
|
|
|
esep = " }";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(&buf, "%s", ssep);
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
for (i = 1; i < n_vals; i++) {
|
2021-05-06 13:41:44 +10:00
|
|
|
vals = SPA_PTROFF(vals, size, void);
|
2018-09-05 16:41:07 +02:00
|
|
|
if (i > 1)
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(&buf, "%s", sep);
|
|
|
|
|
spa_debug_strbuf_format_value(&buf, ti ? ti->values : NULL, type, vals, size);
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_strbuf_append(&buf, "%s", esep);
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
2023-01-18 13:09:00 +01:00
|
|
|
spa_debugc(ctx, "%s", buffer);
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
2018-08-14 12:33:53 +02:00
|
|
|
}
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2024-11-21 11:50:12 +01:00
|
|
|
SPA_API_DEBUG_FORMAT int spa_debug_format(int indent,
|
2023-01-18 13:09:00 +01:00
|
|
|
const struct spa_type_info *info, const struct spa_pod *format)
|
|
|
|
|
{
|
|
|
|
|
return spa_debugc_format(NULL, indent, info, format);
|
|
|
|
|
}
|
2021-05-21 14:03:07 +10:00
|
|
|
/**
|
|
|
|
|
* \}
|
|
|
|
|
*/
|
|
|
|
|
|
2017-06-20 12:30:07 +02:00
|
|
|
#ifdef __cplusplus
|
2018-08-14 12:33:53 +02:00
|
|
|
} /* extern "C" */
|
2017-06-20 12:30:07 +02:00
|
|
|
#endif
|
|
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#endif /* SPA_DEBUG_FORMAT_H */
|