Type changes

Only allow properties inside objects, this makes it easier to
iterate the object, which is needed for efficiently processing
control streams.
Add a choice type to mark variable properties.
SPA_TYPE_Enum -> SPA_TYPE_Id to avoid confusion with choice enum
Make it easier to allocate and initialize properties on the stack
Make more efficient methods to make objects.
This commit is contained in:
Wim Taymans 2018-09-05 16:41:07 +02:00
parent 03fdabd155
commit cc842cbdc8
63 changed files with 2253 additions and 1880 deletions

View file

@ -37,7 +37,7 @@ spa_debug_format_value(const struct spa_type_info *info,
case SPA_TYPE_Bool:
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_TYPE_Enum:
case SPA_TYPE_Id:
{
const char *str = spa_debug_type_find_name(info, *(int32_t *) body);
char tmp[64];
@ -85,6 +85,20 @@ spa_debug_format_value(const struct spa_type_info *info,
case SPA_TYPE_Bytes:
fprintf(stderr, "Bytes");
break;
case SPA_TYPE_Array:
{
void *p;
struct spa_pod_array_body *b = body;
int i = 0;
fprintf(stderr, "< ");
SPA_POD_ARRAY_BODY_FOREACH(b, size, p) {
if (i++ > 0)
fprintf(stderr, ", ");
spa_debug_format_value(info, b->child.type, p, b->child.size);
}
fprintf(stderr, " >");
break;
}
default:
fprintf(stderr, "INVALID type %d", type);
break;
@ -98,12 +112,12 @@ static inline int spa_debug_format(int indent,
int i;
const char *media_type;
const char *media_subtype;
struct spa_pod *pod;
struct spa_pod_prop *prop;
uint32_t mtype, mstype;
const char *pod_type_names[] = {
[SPA_TYPE_None] = "none",
[SPA_TYPE_Bool] = "bool",
[SPA_TYPE_Enum] = "enum",
[SPA_TYPE_Id] = "id",
[SPA_TYPE_Int] = "int",
[SPA_TYPE_Long] = "long",
[SPA_TYPE_Float] = "float",
@ -118,7 +132,7 @@ static inline int spa_debug_format(int indent,
[SPA_TYPE_Object] = "object",
[SPA_TYPE_Pointer] = "pointer",
[SPA_TYPE_Fd] = "fd",
[SPA_TYPE_Prop] = "prop",
[SPA_TYPE_Choice] = "choice",
[SPA_TYPE_Pod] = "pod"
};
@ -138,50 +152,45 @@ static inline int spa_debug_format(int indent,
media_type ? rindex(media_type, ':') + 1 : "unknown",
media_subtype ? rindex(media_subtype, ':') + 1 : "unknown");
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, pod) {
struct spa_pod_prop *prop;
SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, prop) {
const char *key;
const struct spa_type_info *ti;
uint32_t type, size, n_vals, choice;
const struct spa_pod *val;
void *vals;
if (pod->type != SPA_TYPE_Prop)
if (prop->key == SPA_FORMAT_mediaType ||
prop->key == SPA_FORMAT_mediaSubtype)
continue;
prop = (struct spa_pod_prop *)pod;
val = spa_pod_get_values(&prop->value, &n_vals, &choice);
if ((prop->body.flags & SPA_POD_PROP_FLAG_UNSET) &&
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
continue;
type = val->type;
size = val->size;
vals = SPA_POD_BODY(val);
if (prop->body.key == SPA_FORMAT_mediaType ||
prop->body.key == SPA_FORMAT_mediaSubtype)
continue;
ti = spa_debug_type_find(info, prop->body.key);
ti = spa_debug_type_find(info, prop->key);
key = ti ? ti->name : NULL;
fprintf(stderr, "%*s %16s : (%s) ", indent, "",
key ? rindex(key, ':') + 1 : "unknown",
pod_type_names[prop->body.value.type]);
pod_type_names[type]);
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
spa_debug_format_value(ti->values,
prop->body.value.type,
SPA_POD_BODY(&prop->body.value),
prop->body.value.size);
if (choice == SPA_CHOICE_None) {
spa_debug_format_value(ti->values, type, vals, 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:
switch (choice) {
case SPA_CHOICE_Range:
case SPA_CHOICE_Step:
ssep = "[ ";
sep = ", ";
esep = " ]";
break;
default:
case SPA_POD_PROP_RANGE_ENUM:
case SPA_POD_PROP_RANGE_FLAGS:
case SPA_CHOICE_Enum:
case SPA_CHOICE_Flags:
ssep = "{ ";
sep = ", ";
esep = " }";
@ -190,15 +199,11 @@ static inline int spa_debug_format(int indent,
fprintf(stderr, "%s", ssep);
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) {
if (i > 0)
for (i = 1; i < n_vals; i++) {
vals = SPA_MEMBER(vals, size, void);
if (i > 1)
fprintf(stderr, "%s", sep);
spa_debug_format_value(ti->values,
prop->body.value.type,
alt,
prop->body.value.size);
i++;
spa_debug_format_value(ti->values, type, vals, size);
}
fprintf(stderr, "%s", esep);
}

View file

@ -33,6 +33,73 @@ extern "C" {
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
#endif
#if 0
static inline int
spa_debug_pod_prop(int indent, const struct spa_type_info *info, struct spa_pod_prop *prop)
{
void *alt;
int i;
const struct spa_type_info *ti = spa_debug_type_find(info, prop->key);
spa_debug("%*s" "Prop: key %s, flags %d", indent, "",
ti ? ti->name : "unknown", prop->flags);
info = ti ? ti->values : info;
if (prop->flags & SPA_POD_PROP_FLAG_UNSET)
spa_debug("%*s" "Unset (Default):", indent + 2, "");
else
spa_debug("%*s" "Value: size %u", indent + 2, "", prop->value.size);
spa_debug_pod_value(indent + 4, info, prop->value.type, SPA_POD_BODY(&prop->value),
prop->value.size);
i = 0;
switch (prop->flags & SPA_POD_PROP_RANGE_MASK) {
case SPA_POD_PROP_RANGE_NONE:
break;
case SPA_POD_PROP_RANGE_MIN_MAX:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0)
spa_debug("%*s" "Min: ", indent + 2, "");
else if (i == 1)
spa_debug("%*s" "Max: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_STEP:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0)
spa_debug("%*s" "Min: ", indent + 2, "");
else if (i == 1)
spa_debug("%*s" "Max: ", indent + 2, "");
else if (i == 2)
spa_debug("%*s" "Step: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_ENUM:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0) {
spa_debug("%*s" "Enum:", indent + 2, "");
}
spa_debug_pod_value(indent + 4, info, prop->value.type, alt, prop->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_FLAGS:
break;
}
break;
}
#endif
static inline int
spa_debug_pod_value(int indent, const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
@ -41,8 +108,8 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
case SPA_TYPE_Bool:
spa_debug("%*s" "Bool %d", indent, "", *(int32_t *) body);
break;
case SPA_TYPE_Enum:
spa_debug("%*s" "Enum %d (%s)", indent, "", *(int32_t *) body,
case SPA_TYPE_Id:
spa_debug("%*s" "Id %d (%s)", indent, "", *(int32_t *) body,
spa_debug_type_find_name(info, *(int32_t *) body));
break;
case SPA_TYPE_Int:
@ -89,17 +156,28 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
{
struct spa_pod_array_body *b = body;
void *p;
const struct spa_type_info *ti = spa_debug_type_find(info, b->child.type);
const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type);
spa_debug("%*s" "Array: child.size %d, child.type %s", indent, "",
b->child.size, ti ? ti->name : "unknown");
info = ti ? ti->values : info;
SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
break;
}
case SPA_TYPE_Choice:
{
struct spa_pod_choice_body *b = body;
void *p;
const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type);
spa_debug("%*s" "Choice: type %s, flags %08x %d %d", indent, "",
ti ? ti->name : "unknown", b->flags, size, b->child.size);
SPA_POD_CHOICE_BODY_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
break;
}
case SPA_TYPE_Struct:
{
struct spa_pod *b = body, *p;
@ -111,7 +189,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
case SPA_TYPE_Object:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
struct spa_pod_prop *p;
const struct spa_type_info *ti, *ii;
ti = spa_debug_type_find(info, b->type);
@ -123,9 +201,17 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
info = ti ? ti->values : info;
SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
spa_debug_pod_value(indent + 2, info,
p->type, SPA_POD_BODY(p), p->size);
SPA_POD_OBJECT_BODY_FOREACH(b, size, p) {
ii = spa_debug_type_find(info, p->key);
spa_debug("%*s" "Prop: key %s, flags %08x", indent+2, "",
ii ? ii->name : "unknown", p->flags);
spa_debug_pod_value(indent + 4, ii->values,
p->value.type,
SPA_POD_CONTENTS(struct spa_pod_prop, p),
p->value.size);
}
break;
}
case SPA_TYPE_Sequence:
@ -145,77 +231,13 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
spa_debug("%*s" "Control: offset %d, type %s", indent+2, "",
c->offset, ii ? ii->name : "unknown");
spa_debug_pod_value(indent + 2, info,
spa_debug_pod_value(indent + 4, ii->values,
c->value.type,
SPA_POD_CONTENTS(struct spa_pod_control, c),
c->value.size);
}
break;
}
case SPA_TYPE_Prop:
{
struct spa_pod_prop_body *b = body;
void *alt;
int i;
const struct spa_type_info *ti = spa_debug_type_find(info, b->key);
spa_debug("%*s" "Prop: key %s, flags %d", indent, "",
ti ? ti->name : "unknown", b->flags);
info = ti ? ti->values : info;
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, info, b->value.type, SPA_POD_BODY(&b->value),
b->value.size);
i = 0;
switch (b->flags & SPA_POD_PROP_RANGE_MASK) {
case SPA_POD_PROP_RANGE_NONE:
break;
case SPA_POD_PROP_RANGE_MIN_MAX:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0)
spa_debug("%*s" "Min: ", indent + 2, "");
else if (i == 1)
spa_debug("%*s" "Max: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_STEP:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0)
spa_debug("%*s" "Min: ", indent + 2, "");
else if (i == 1)
spa_debug("%*s" "Max: ", indent + 2, "");
else if (i == 2)
spa_debug("%*s" "Step: ", indent + 2, "");
else
break;
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_ENUM:
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0) {
spa_debug("%*s" "Enum:", indent + 2, "");
}
spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size);
i++;
}
break;
case SPA_POD_PROP_RANGE_FLAGS:
break;
}
break;
}
case SPA_TYPE_Bytes:
spa_debug("%*s" "Bytes", indent, "");
spa_debug_mem(indent + 2, body, size);