Remove dynamic types

Do not use dynamic types anymore. The reason is that it's difficult:

- to maintain a shared type database over a network.
- the extra overhead when translating between processes and for
  maintaining the translation tables.
- race conditions in translating in RT-threads, this is a problem
  because we want to make event streams.

We now have simple enums with types and extension points for all
types. This is also nicer to use in general.
We don't need the mapper anymore or pass strings around as types.
There is a parallel type info system to get more info about ids and
enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
Wim Taymans 2018-08-23 17:47:57 +02:00
parent e6977fa178
commit fca3e1d85d
162 changed files with 5200 additions and 7461 deletions

View file

@ -24,15 +24,14 @@
extern "C" {
#endif
#include <spa/support/type-map.h>
#include <spa/debug/debug-mem.h>
#include <spa/buffer/buffer-types.h>
#ifndef spa_debug
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
static inline int spa_debug_buffer(int indent,
struct spa_type_map *map, const struct spa_buffer *buffer)
static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer)
{
int i;
@ -43,25 +42,33 @@ static inline int spa_debug_buffer(int indent,
struct spa_meta *m = &buffer->metas[i];
const char *type_name;
type_name = spa_type_map_get_type(map, m->type);
type_name = spa_debug_type_find_name(spa_type_meta_type, m->type);
spa_debug("%*s" " meta %d: type %d (%s), data %p, size %d:", indent, "", i, m->type,
type_name, m->data, m->size);
if (!strcmp(type_name, SPA_TYPE_META__Header)) {
switch (m->type) {
case SPA_META_Header:
{
struct spa_meta_header *h = m->data;
spa_debug("%*s" " struct spa_meta_header:", indent, "");
spa_debug("%*s" " flags: %08x", indent, "", h->flags);
spa_debug("%*s" " seq: %u", indent, "", h->seq);
spa_debug("%*s" " pts: %" PRIi64, indent, "", h->pts);
spa_debug("%*s" " dts_offset: %" PRIi64, indent, "", h->dts_offset);
} else if (!strcmp(type_name, SPA_TYPE_META__VideoCrop)) {
break;
}
case SPA_META_VideoCrop:
{
struct spa_meta_video_crop *h = m->data;
spa_debug("%*s" " struct spa_meta_video_crop:", indent, "");
spa_debug("%*s" " x: %d", indent, "", h->x);
spa_debug("%*s" " y: %d", indent, "", h->y);
spa_debug("%*s" " width: %d", indent, "", h->width);
spa_debug("%*s" " height: %d", indent, "", h->height);
} else {
break;
}
case SPA_META_VideoDamage:
default:
spa_debug("%*s" " Unknown:", indent, "");
spa_debug_mem(5, m->data, m->size);
}
@ -70,7 +77,7 @@ static inline int spa_debug_buffer(int indent,
for (i = 0; i < buffer->n_datas; i++) {
struct spa_data *d = &buffer->datas[i];
spa_debug("%*s" " type: %d (%s)", indent, "", d->type,
spa_type_map_get_type(map, d->type));
spa_debug_type_find_name(spa_type_data_type, d->type));
spa_debug("%*s" " flags: %d", indent, "", d->flags);
spa_debug("%*s" " data: %p", indent, "", d->data);
spa_debug("%*s" " fd: %d", indent, "", d->fd);

View file

@ -24,11 +24,13 @@
extern "C" {
#endif
#include <spa/support/type-map.h>
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
#include <spa/param/format-types.h>
#include <spa/param/audio/format-types.h>
static inline int
spa_debug_format_value(struct spa_type_map *map,
spa_debug_format_value(const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
{
switch (type) {
@ -36,21 +38,21 @@ spa_debug_format_value(struct spa_type_map *map,
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_POD_TYPE_ID:
case SPA_POD_TYPE_INT:
{
const char *str = map ? spa_type_map_get_type(map, *(int32_t *) body) : NULL;
const char *str = spa_debug_type_find_name(info, *(int32_t *) body);
char tmp[64];
if (str) {
const char *h = rindex(str, ':');
if (h)
str = h + 1;
} else {
str = "unknown";
snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body);
str = tmp;
}
fprintf(stderr, "%s", str);
break;
}
case SPA_POD_TYPE_INT:
fprintf(stderr, "%" PRIi32, *(int32_t *) body);
break;
case SPA_POD_TYPE_LONG:
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
break;
@ -88,7 +90,7 @@ spa_debug_format_value(struct spa_type_map *map,
}
static inline int spa_debug_format(int indent,
struct spa_type_map *map, const struct spa_pod *format)
const struct spa_type_info *info, const struct spa_pod *format)
{
int i;
const char *media_type;
@ -121,19 +123,25 @@ static inline int spa_debug_format(int indent,
if (format == NULL || SPA_POD_TYPE(format) != SPA_POD_TYPE_OBJECT)
return -EINVAL;
if (spa_pod_object_parse(format, "I", &mtype,
"I", &mstype) < 0)
return -EINVAL;
media_type = spa_type_map_get_type(map, mtype);
media_subtype = spa_type_map_get_type(map, mstype);
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", "", rindex(media_type, ':') + 1,
rindex(media_subtype, ':') + 1);
fprintf(stderr, "%-6s %s/%s\n", "",
media_type ? rindex(media_type, ':') + 1 : "unknown",
media_subtype ? rindex(media_subtype, ':') + 1 : "unknown");
info = spa_type_format_get_ids(mtype, mstype);
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, pod) {
struct spa_pod_prop *prop;
const char *key;
const struct spa_type_info *ti;
if (pod->type != SPA_POD_TYPE_PROP)
continue;
@ -144,13 +152,15 @@ static inline int spa_debug_format(int indent,
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
continue;
key = spa_type_map_get_type(map, prop->body.key);
ti = spa_debug_type_find(info, prop->body.key);
key = ti ? ti->name : NULL;
fprintf(stderr, " %20s : (%s) ", rindex(key, ':') + 1,
fprintf(stderr, " %20s : (%s) ",
key ? rindex(key, ':') + 1 : "unknown",
pod_type_names[prop->body.value.type]);
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
spa_debug_format_value(map,
spa_debug_format_value(ti->values,
prop->body.value.type,
SPA_POD_BODY(&prop->body.value),
prop->body.value.size);
@ -180,7 +190,7 @@ static inline int spa_debug_format(int indent,
SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) {
if (i > 0)
fprintf(stderr, "%s", sep);
spa_debug_format_value(map,
spa_debug_format_value(ti->values,
prop->body.value.type,
alt,
prop->body.value.size);

View file

@ -24,8 +24,8 @@
extern "C" {
#endif
#include <spa/support/type-map.h>
#include <spa/debug/mem.h>
#include <spa/debug/types.h>
#include <spa/pod/pod.h>
#include <spa/pod/iter.h>
@ -34,7 +34,7 @@ extern "C" {
#endif
static inline int
spa_debug_pod_value(int indent, struct spa_type_map *map,
spa_debug_pod_value(int indent, const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
{
switch (type) {
@ -43,7 +43,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
break;
case SPA_POD_TYPE_ID:
spa_debug("%*s" "Id %d %s", indent, "", *(int32_t *) body,
spa_type_map_get_type(map, *(int32_t *) body));
spa_debug_type_find_name(info, *(int32_t *) body));
break;
case SPA_POD_TYPE_INT:
spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body);
@ -67,7 +67,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
{
struct spa_pod_pointer_body *b = body;
spa_debug("%*s" "Pointer %s %p", indent, "",
map ? spa_type_map_get_type(map, b->type) : "*no map*", b->value);
spa_debug_type_find_name(info, b->type), b->value);
break;
}
case SPA_POD_TYPE_RECTANGLE:
@ -93,7 +93,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
b->child.size, b->child.type);
SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, map, b->child.type, p, b->child.size);
spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
break;
}
case SPA_POD_TYPE_STRUCT:
@ -101,19 +101,20 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
struct spa_pod *b = body, *p;
spa_debug("%*s" "Struct: size %d", indent, "", size);
SPA_POD_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, map, p->type, SPA_POD_BODY(p), p->size);
spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size);
break;
}
case SPA_POD_TYPE_OBJECT:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
const struct spa_type_info *ti = spa_debug_type_find(info, b->type);
spa_debug("%*s" "Object: size %d, id %s, type %s", indent, "", size,
map ? spa_type_map_get_type(map, b->id) : "*no map*",
map ? spa_type_map_get_type(map, b->type) : "*no map*");
spa_debug_type_find_name(info, b->id), ti ? ti->name : "unknown");
SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, map, p->type, SPA_POD_BODY(p), p->size);
spa_debug_pod_value(indent + 2, ti ? ti->values : NULL,
p->type, SPA_POD_BODY(p), p->size);
break;
}
case SPA_POD_TYPE_PROP:
@ -123,12 +124,12 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
int i;
spa_debug("%*s" "Prop: key %s, flags %d", indent, "",
map ? spa_type_map_get_type(map, b->key) : "*no map*", b->flags);
spa_debug_type_find_name(info, b->key), b->flags);
if (b->flags & SPA_POD_PROP_FLAG_UNSET)
spa_debug("%*s" "Unset (Default):", indent + 2, "");
else
spa_debug("%*s" "Value: size %u", indent + 2, "", b->value.size);
spa_debug_pod_value(indent + 4, map, b->value.type, SPA_POD_BODY(&b->value),
spa_debug_pod_value(indent + 4, info, b->value.type, SPA_POD_BODY(&b->value),
b->value.size);
i = 0;
@ -143,7 +144,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
spa_debug("%*s" "Max: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size);
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
@ -157,7 +158,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
spa_debug("%*s" "Step: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size);
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
@ -166,7 +167,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
if (i == 0) {
spa_debug("%*s" "Enum:", indent + 2, "");
}
spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size);
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
@ -191,9 +192,9 @@ spa_debug_pod_value(int indent, struct spa_type_map *map,
}
static inline int spa_debug_pod(int indent,
struct spa_type_map *map, const struct spa_pod *pod)
const struct spa_type_info *info, const struct spa_pod *pod)
{
return spa_debug_pod_value(indent, map,
return spa_debug_pod_value(indent, info,
SPA_POD_TYPE(pod),
SPA_POD_BODY(pod),
SPA_POD_BODY_SIZE(pod));

View file

@ -0,0 +1,80 @@
/* Simple Plugin API
* Copyright (C) 2018 Wim Taymans <wim.taymans@gmail.com>
*
* 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.
*/
#ifndef __SPA_DEBUG_TYPES_H__
#define __SPA_DEBUG_TYPES_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/monitor/monitor-types.h>
#include <spa/node/node-types.h>
#include <spa/param/buffers.h>
#include <spa/param/buffers-types.h>
static const struct spa_type_info spa_debug_types[] =
{
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_monitor },
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_node },
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_param_buffers },
{ 0, NULL, },
};
static inline const struct spa_type_info *spa_debug_type_find(const struct spa_type_info *info, uint32_t id)
{
const struct spa_type_info *res;
while (info && info->name) {
if (info->id == SPA_ID_INVALID)
if ((res = spa_debug_type_find(info->values, id)))
return res;
if (info->id == id)
return info;
info++;
}
return NULL;
}
static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t id)
{
const struct spa_type_info *type;
if ((type = spa_debug_type_find(info, id)) == NULL)
return NULL;
return type->name;
}
static inline uint32_t spa_debug_type_find_id(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
uint32_t res;
if (strcmp(info->name, name) == 0)
return info->id;
if ((res = spa_debug_type_find_id(info->values, name)) != SPA_ID_INVALID)
return res;
info++;
}
return SPA_ID_INVALID;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_DEBUG_NODE_H__ */