2017-06-20 12:30:07 +02:00
|
|
|
/* Simple Plugin API
|
2018-08-14 12:33:53 +02:00
|
|
|
* Copyright (C) 2018 Wim Taymans <wim.taymans@gmail.com>
|
2017-06-20 12:30:07 +02:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
#ifndef __SPA_DEBUG_FORMAT_H__
|
|
|
|
|
#define __SPA_DEBUG_FORMAT_H__
|
2017-06-20 12:30:07 +02:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-08-14 13:05:10 +02:00
|
|
|
#include <spa/pod/parser.h>
|
2018-08-23 17:47:57 +02:00
|
|
|
#include <spa/debug/types.h>
|
|
|
|
|
#include <spa/param/format-types.h>
|
|
|
|
|
#include <spa/param/audio/format-types.h>
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2018-08-14 13:05:10 +02:00
|
|
|
static inline int
|
2018-08-23 17:47:57 +02:00
|
|
|
spa_debug_format_value(const struct spa_type_info *info,
|
2018-08-14 13:05:10 +02:00
|
|
|
uint32_t type, void *body, uint32_t size)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case SPA_POD_TYPE_BOOL:
|
|
|
|
|
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_ID:
|
2018-08-23 17:47:57 +02:00
|
|
|
case SPA_POD_TYPE_INT:
|
2018-08-14 13:05:10 +02:00
|
|
|
{
|
2018-08-23 17:47:57 +02:00
|
|
|
const char *str = spa_debug_type_find_name(info, *(int32_t *) body);
|
|
|
|
|
char tmp[64];
|
2018-08-14 13:05:10 +02:00
|
|
|
if (str) {
|
|
|
|
|
const char *h = rindex(str, ':');
|
|
|
|
|
if (h)
|
|
|
|
|
str = h + 1;
|
|
|
|
|
} else {
|
2018-08-23 17:47:57 +02:00
|
|
|
snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body);
|
|
|
|
|
str = tmp;
|
2018-08-14 13:05:10 +02:00
|
|
|
}
|
|
|
|
|
fprintf(stderr, "%s", str);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_POD_TYPE_LONG:
|
|
|
|
|
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_FLOAT:
|
|
|
|
|
fprintf(stderr, "%f", *(float *) body);
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_DOUBLE:
|
|
|
|
|
fprintf(stderr, "%g", *(double *) body);
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_STRING:
|
|
|
|
|
fprintf(stderr, "%s", (char *) body);
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_RECTANGLE:
|
|
|
|
|
{
|
|
|
|
|
struct spa_rectangle *r = body;
|
|
|
|
|
fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_POD_TYPE_FRACTION:
|
|
|
|
|
{
|
|
|
|
|
struct spa_fraction *f = body;
|
|
|
|
|
fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SPA_POD_TYPE_BITMAP:
|
|
|
|
|
fprintf(stderr, "Bitmap");
|
|
|
|
|
break;
|
|
|
|
|
case SPA_POD_TYPE_BYTES:
|
|
|
|
|
fprintf(stderr, "Bytes");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2017-06-20 12:30:07 +02:00
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
static inline int spa_debug_format(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
|
|
|
int i;
|
|
|
|
|
const char *media_type;
|
|
|
|
|
const char *media_subtype;
|
|
|
|
|
struct spa_pod *pod;
|
|
|
|
|
uint32_t mtype, mstype;
|
|
|
|
|
const char *pod_type_names[] = {
|
|
|
|
|
[SPA_POD_TYPE_INVALID] = "invalid",
|
|
|
|
|
[SPA_POD_TYPE_NONE] = "none",
|
|
|
|
|
[SPA_POD_TYPE_BOOL] = "bool",
|
|
|
|
|
[SPA_POD_TYPE_ID] = "id",
|
|
|
|
|
[SPA_POD_TYPE_INT] = "int",
|
|
|
|
|
[SPA_POD_TYPE_LONG] = "long",
|
|
|
|
|
[SPA_POD_TYPE_FLOAT] = "float",
|
|
|
|
|
[SPA_POD_TYPE_DOUBLE] = "double",
|
|
|
|
|
[SPA_POD_TYPE_STRING] = "string",
|
|
|
|
|
[SPA_POD_TYPE_BYTES] = "bytes",
|
|
|
|
|
[SPA_POD_TYPE_RECTANGLE] = "rectangle",
|
|
|
|
|
[SPA_POD_TYPE_FRACTION] = "fraction",
|
|
|
|
|
[SPA_POD_TYPE_BITMAP] = "bitmap",
|
|
|
|
|
[SPA_POD_TYPE_ARRAY] = "array",
|
|
|
|
|
[SPA_POD_TYPE_STRUCT] = "struct",
|
|
|
|
|
[SPA_POD_TYPE_OBJECT] = "object",
|
|
|
|
|
[SPA_POD_TYPE_POINTER] = "pointer",
|
|
|
|
|
[SPA_POD_TYPE_FD] = "fd",
|
|
|
|
|
[SPA_POD_TYPE_PROP] = "prop",
|
|
|
|
|
[SPA_POD_TYPE_POD] = "pod"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (format == NULL || SPA_POD_TYPE(format) != SPA_POD_TYPE_OBJECT)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
|
|
|
|
|
|
2018-08-14 13:05:10 +02:00
|
|
|
if (spa_pod_object_parse(format, "I", &mtype,
|
|
|
|
|
"I", &mstype) < 0)
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%-6s %s/%s\n", "",
|
|
|
|
|
media_type ? rindex(media_type, ':') + 1 : "unknown",
|
|
|
|
|
media_subtype ? rindex(media_subtype, ':') + 1 : "unknown");
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
info = spa_type_format_get_ids(mtype, mstype);
|
2018-08-14 13:05:10 +02:00
|
|
|
|
|
|
|
|
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, pod) {
|
|
|
|
|
struct spa_pod_prop *prop;
|
|
|
|
|
const char *key;
|
2018-08-23 17:47:57 +02:00
|
|
|
const struct spa_type_info *ti;
|
2018-08-14 13:05:10 +02:00
|
|
|
|
|
|
|
|
if (pod->type != SPA_POD_TYPE_PROP)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
prop = (struct spa_pod_prop *)pod;
|
|
|
|
|
|
|
|
|
|
if ((prop->body.flags & SPA_POD_PROP_FLAG_UNSET) &&
|
|
|
|
|
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
ti = spa_debug_type_find(info, prop->body.key);
|
|
|
|
|
key = ti ? ti->name : NULL;
|
2018-08-14 13:05:10 +02:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
fprintf(stderr, " %20s : (%s) ",
|
|
|
|
|
key ? rindex(key, ':') + 1 : "unknown",
|
2018-08-14 13:05:10 +02:00
|
|
|
pod_type_names[prop->body.value.type]);
|
|
|
|
|
|
|
|
|
|
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
|
2018-08-23 17:47:57 +02:00
|
|
|
spa_debug_format_value(ti->values,
|
2018-08-14 13:05:10 +02:00
|
|
|
prop->body.value.type,
|
|
|
|
|
SPA_POD_BODY(&prop->body.value),
|
|
|
|
|
prop->body.value.size);
|
|
|
|
|
} else {
|
|
|
|
|
const char *ssep, *esep, *sep;
|
|
|
|
|
void *alt;
|
|
|
|
|
|
|
|
|
|
switch (prop->body.flags & SPA_POD_PROP_RANGE_MASK) {
|
|
|
|
|
case SPA_POD_PROP_RANGE_MIN_MAX:
|
|
|
|
|
case SPA_POD_PROP_RANGE_STEP:
|
|
|
|
|
ssep = "[ ";
|
|
|
|
|
sep = ", ";
|
|
|
|
|
esep = " ]";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case SPA_POD_PROP_RANGE_ENUM:
|
|
|
|
|
case SPA_POD_PROP_RANGE_FLAGS:
|
|
|
|
|
ssep = "{ ";
|
|
|
|
|
sep = ", ";
|
|
|
|
|
esep = " }";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", ssep);
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) {
|
|
|
|
|
if (i > 0)
|
|
|
|
|
fprintf(stderr, "%s", sep);
|
2018-08-23 17:47:57 +02:00
|
|
|
spa_debug_format_value(ti->values,
|
2018-08-14 13:05:10 +02:00
|
|
|
prop->body.value.type,
|
|
|
|
|
alt,
|
|
|
|
|
prop->body.value.size);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "%s", esep);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2018-08-14 12:33:53 +02: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
|
|
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
#endif /* __SPA_DEBUG_FORMAT_H__ */
|