Loading...
Searching...
No Matches
pod.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_DEBUG_POD_H
#define SPA_DEBUG_POD_H
#include <inttypes.h>
#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>
#ifdef __cplusplus
extern "C" {
#endif
#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
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)
{
switch (type) {
case SPA_TYPE_Bool:
spa_debugc(ctx, "%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false");
break;
case SPA_TYPE_Id:
spa_debugc(ctx, "%*s" "Id %-8" PRIu32 " (%s)", indent, "", *(uint32_t *) body,
spa_debug_type_find_name(info, *(uint32_t *) body));
break;
case SPA_TYPE_Int:
spa_debugc(ctx, "%*s" "Int %" PRId32, indent, "", *(int32_t *) body);
break;
case SPA_TYPE_Long:
spa_debugc(ctx, "%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body);
break;
case SPA_TYPE_Float:
spa_debugc(ctx, "%*s" "Float %f", indent, "", *(float *) body);
break;
case SPA_TYPE_Double:
spa_debugc(ctx, "%*s" "Double %f", indent, "", *(double *) body);
break;
case SPA_TYPE_String:
spa_debugc(ctx, "%*s" "String \"%s\"", indent, "", (char *) body);
break;
case SPA_TYPE_Fd:
spa_debugc(ctx, "%*s" "Fd %d", indent, "", *(int *) body);
break;
case SPA_TYPE_Pointer:
{
struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body;
spa_debugc(ctx, "%*s" "Pointer %s %p", indent, "",
spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value);
break;
}
case SPA_TYPE_Rectangle:
{
struct spa_rectangle *r = (struct spa_rectangle *)body;
spa_debugc(ctx, "%*s" "Rectangle %" PRIu32 "x%" PRIu32 "", indent, "", r->width, r->height);
break;
}
case SPA_TYPE_Fraction:
{
struct spa_fraction *f = (struct spa_fraction *)body;
spa_debugc(ctx, "%*s" "Fraction %" PRIu32 "/%" PRIu32 "", indent, "", f->num, f->denom);
break;
}
case SPA_TYPE_Bitmap:
spa_debugc(ctx, "%*s" "Bitmap", indent, "");
break;
case SPA_TYPE_Array:
{
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
void *p;
const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type);
uint32_t min_size = spa_pod_type_size(b->child.type);
spa_debugc(ctx, "%*s" "Array: child.size %" PRIu32 ", child.type %s", indent, "",
b->child.size, ti ? ti->name : "unknown");
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);
}
break;
}
case SPA_TYPE_Choice:
{
struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body;
void *p;
const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type);
uint32_t min_size = spa_pod_type_size(b->child.type);
spa_debugc(ctx, "%*s" "Choice: type %s, flags %08" PRIx32 " %" PRIu32 " %" PRIu32, indent, "",
ti ? ti->name : "unknown", b->flags, size, b->child.size);
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);
}
break;
}
case SPA_TYPE_Struct:
{
struct spa_pod *b = (struct spa_pod *)body, *p;
spa_debugc(ctx, "%*s" "Struct: size %" PRIu32, indent, "", size);
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);
}
}
break;
}
case SPA_TYPE_Object:
{
struct spa_pod_object_body *b = (struct spa_pod_object_body *)body;
struct spa_pod_prop *p;
const struct spa_type_info *ti, *ii;
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;
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);
info = ti ? ti->values : info;
SPA_POD_OBJECT_BODY_FOREACH(b, size, p) {
static const char custom_prefix[] = SPA_TYPE_INFO_PROPS_BASE "Custom:";
char custom_name[sizeof(custom_prefix) + 16];
const char *name = "unknown";
uint32_t min_size = spa_pod_type_size(p->value.type);
ii = spa_debug_type_find(info, p->key);
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;
}
spa_debugc(ctx, "%*s" "Prop: key %s (%" PRIu32 "), flags %08" PRIx32,
indent+2, "", name, p->key, p->flags);
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);
}
}
break;
}
case SPA_TYPE_Sequence:
{
struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body;
const struct spa_type_info *ti, *ii;
struct spa_pod_control *c;
ti = spa_debug_type_find(info, b->unit);
spa_debugc(ctx, "%*s" "Sequence: size %" PRIu32 ", unit %s", indent, "", size,
ti ? ti->name : "unknown");
SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) {
uint32_t min_size = spa_pod_type_size(c->value.type);
ii = spa_debug_type_find(spa_type_control, c->type);
spa_debugc(ctx, "%*s" "Control: offset %" PRIu32 ", type %s", indent+2, "",
c->offset, ii ? ii->name : "unknown");
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);
}
}
break;
}
case SPA_TYPE_Bytes:
spa_debugc(ctx, "%*s" "Bytes", indent, "");
spa_debugc_mem(ctx, indent + 2, body, size);
break;
case SPA_TYPE_None:
spa_debugc(ctx, "%*s" "None", indent, "");
spa_debugc_mem(ctx, indent + 2, body, size);
break;
default:
spa_debugc(ctx, "%*s" "unhandled POD type %" PRIu32, indent, "", type);
break;
}
return 0;
}
SPA_API_DEBUG_POD int spa_debugc_pod(struct spa_debug_context *ctx, int indent,
const struct spa_type_info *info, const struct spa_pod *pod)
{
if (pod->size < spa_pod_type_size(pod->type))
return -EINVAL;
return spa_debugc_pod_value(ctx, indent, info ? info : SPA_TYPE_ROOT,
pod->type, SPA_POD_BODY(pod), pod->size);
}
SPA_API_DEBUG_POD int
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);
}
SPA_API_DEBUG_POD int spa_debug_pod(int indent,
const struct spa_type_info *info, const struct spa_pod *pod)
{
return spa_debugc_pod(NULL, indent, info, pod);
}
*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_DEBUG_POD_H */
r
uint32_t int int const char int r
Definition core.h:447
spa_type_control
static const struct spa_type_info spa_type_control[]
Definition type-info.h:32
spa_debugc_mem
SPA_API_DEBUG_MEM int spa_debugc_mem(struct spa_debug_context *ctx, int indent, const void *data, size_t size)
Definition mem.h:36
SPA_API_DEBUG_POD
#define SPA_API_DEBUG_POD
Definition pod.h:36
spa_debugc
#define spa_debugc(_c, _fmt,...)
Definition context.h:50
spa_debug_type_find
SPA_API_DEBUG_TYPES const struct spa_type_info * spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
Definition types.h:37
spa_debug_pod_value
SPA_API_DEBUG_POD int spa_debug_pod_value(int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size)
Definition pod.h:242
spa_debug_pod
SPA_API_DEBUG_POD int spa_debug_pod(int indent, const struct spa_type_info *info, const struct spa_pod *pod)
Definition pod.h:248
spa_debugc_pod
SPA_API_DEBUG_POD 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:232
spa_debugc_pod_value
SPA_API_DEBUG_POD 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:41
spa_debug_type_find_name
SPA_API_DEBUG_TYPES const char * spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
Definition types.h:61
SPA_TYPE_INFO_PROPS_BASE
#define SPA_TYPE_INFO_PROPS_BASE
Definition props-types.h:30
SPA_PROP_START_CUSTOM
@ SPA_PROP_START_CUSTOM
Definition props.h:124
SPA_POD_OBJECT_BODY_FOREACH
#define SPA_POD_OBJECT_BODY_FOREACH(body, size, iter)
Definition iter.h:113
SPA_POD_CHOICE_BODY_FOREACH
#define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter)
Definition iter.h:97
SPA_POD_BODY
#define SPA_POD_BODY(pod)
Definition pod.h:44
spa_pod_type_size
SPA_API_POD_BODY uint32_t spa_pod_type_size(uint32_t type)
Definition body.h:45
SPA_POD_FOREACH
#define SPA_POD_FOREACH(pod, size, iter)
Definition iter.h:105
SPA_POD_CONTENTS
#define SPA_POD_CONTENTS(type, pod)
Definition pod.h:40
SPA_POD_SEQUENCE_BODY_FOREACH
#define SPA_POD_SEQUENCE_BODY_FOREACH(body, size, iter)
Definition iter.h:121
SPA_POD_ARRAY_BODY_FOREACH
#define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter)
Definition iter.h:89
spa_type_choice
static const struct spa_type_info spa_type_choice[]
Definition enum-types.h:41
SPA_TYPE_ROOT
#define SPA_TYPE_ROOT
Definition type-info.h:34
SPA_TYPE_Int
@ SPA_TYPE_Int
Definition type.h:45
SPA_TYPE_Rectangle
@ SPA_TYPE_Rectangle
Definition type.h:51
SPA_TYPE_Long
@ SPA_TYPE_Long
Definition type.h:46
SPA_TYPE_Bool
@ SPA_TYPE_Bool
Definition type.h:43
SPA_TYPE_Bytes
@ SPA_TYPE_Bytes
Definition type.h:50
SPA_TYPE_Bitmap
@ SPA_TYPE_Bitmap
Definition type.h:53
SPA_TYPE_Object
@ SPA_TYPE_Object
Definition type.h:56
SPA_TYPE_Float
@ SPA_TYPE_Float
Definition type.h:47
SPA_TYPE_Fraction
@ SPA_TYPE_Fraction
Definition type.h:52
SPA_TYPE_None
@ SPA_TYPE_None
Definition type.h:42
SPA_TYPE_Sequence
@ SPA_TYPE_Sequence
Definition type.h:57
SPA_TYPE_Double
@ SPA_TYPE_Double
Definition type.h:48
SPA_TYPE_Id
@ SPA_TYPE_Id
Definition type.h:44
SPA_TYPE_Choice
@ SPA_TYPE_Choice
Definition type.h:60
SPA_TYPE_Pointer
@ SPA_TYPE_Pointer
Definition type.h:58
SPA_TYPE_Array
@ SPA_TYPE_Array
Definition type.h:54
SPA_TYPE_String
@ SPA_TYPE_String
Definition type.h:49
SPA_TYPE_Fd
@ SPA_TYPE_Fd
Definition type.h:59
SPA_TYPE_Struct
@ SPA_TYPE_Struct
Definition type.h:55
iter.h
spa/pod/iter.h
pod.h
spa/pod/pod.h
context.h
spa/debug/context.h
mem.h
spa/debug/mem.h
spa_debug_context
Definition context.h:46
spa_fraction
Definition defs.h:137
spa_fraction::num
uint32_t num
Definition defs.h:138
spa_fraction::denom
uint32_t denom
Definition defs.h:139
spa_pod_array_body
Definition pod.h:135
spa_pod_array_body::child
struct spa_pod child
Definition pod.h:136
spa_pod_choice_body
Definition pod.h:168
spa_pod_choice_body::child
struct spa_pod child
Definition pod.h:171
spa_pod_choice_body::type
uint32_t type
type of choice, one of enum spa_choice_type
Definition pod.h:169
spa_pod_choice_body::flags
uint32_t flags
extra flags
Definition pod.h:170
spa_pod_control
Definition pod.h:257
spa_pod_control::value
struct spa_pod value
control value, depends on type
Definition pod.h:260
spa_pod_control::type
uint32_t type
type of control, enum spa_control_type
Definition pod.h:259
spa_pod_control::offset
uint32_t offset
media offset
Definition pod.h:258
spa_pod_object_body
Definition pod.h:196
spa_pod_object_body::type
uint32_t type
one of enum spa_type
Definition pod.h:197
spa_pod_object_body::id
uint32_t id
id of the object, depends on the object type
Definition pod.h:198
spa_pod_pointer_body
Definition pod.h:207
spa_pod_pointer_body::value
const void * value
Definition pod.h:210
spa_pod_pointer_body::type
uint32_t type
pointer id, one of enum spa_type
Definition pod.h:208
spa_pod_prop
Definition pod.h:227
spa_pod_prop::key
uint32_t key
key of property, list of valid keys depends on the object type
Definition pod.h:228
spa_pod_prop::flags
uint32_t flags
flags for property
Definition pod.h:248
spa_pod_prop::value
struct spa_pod value
Definition pod.h:249
spa_pod_sequence_body
Definition pod.h:264
spa_pod_sequence_body::unit
uint32_t unit
Definition pod.h:265
spa_pod
Definition pod.h:57
spa_pod::type
uint32_t type
Definition pod.h:59
spa_pod::size
uint32_t size
Definition pod.h:58
spa_rectangle
Definition defs.h:116
spa_type_info
Definition type.h:156
spa_type_info::values
const struct spa_type_info * values
Definition type.h:160
types.h
spa/debug/types.h