This commit is contained in:
Wim Taymans 2017-05-26 08:05:01 +02:00
parent d1a06ae247
commit 5b037661d9
154 changed files with 21017 additions and 23044 deletions

View file

@ -26,419 +26,414 @@
#include <spa/loop.h>
#include "debug.h"
int
spa_debug_port_info (const struct spa_port_info *info, const struct spa_type_map *map)
int spa_debug_port_info(const struct spa_port_info *info, const struct spa_type_map *map)
{
if (info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
fprintf (stderr, "struct spa_port_info %p:\n", info);
fprintf (stderr, " flags: \t%08x\n", info->flags);
fprintf(stderr, "struct spa_port_info %p:\n", info);
fprintf(stderr, " flags: \t%08x\n", info->flags);
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
int
spa_debug_buffer (const struct spa_buffer *buffer, const struct spa_type_map *map)
int spa_debug_buffer(const struct spa_buffer *buffer, const struct spa_type_map *map)
{
int i;
int i;
if (buffer == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (buffer == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
fprintf (stderr, "spa_buffer %p:\n", buffer);
fprintf (stderr, " id: %08X\n", buffer->id);
fprintf (stderr, " n_metas: %u (at %p)\n", buffer->n_metas, buffer->metas);
for (i = 0; i < buffer->n_metas; i++) {
struct spa_meta *m = &buffer->metas[i];
const char *type_name;
fprintf(stderr, "spa_buffer %p:\n", buffer);
fprintf(stderr, " id: %08X\n", buffer->id);
fprintf(stderr, " n_metas: %u (at %p)\n", buffer->n_metas, buffer->metas);
for (i = 0; i < buffer->n_metas; i++) {
struct spa_meta *m = &buffer->metas[i];
const char *type_name;
type_name = spa_type_map_get_type (map, m->type);
fprintf (stderr, " meta %d: type %d (%s), data %p, size %d:\n", i, m->type,
type_name, m->data, m->size);
type_name = spa_type_map_get_type(map, m->type);
fprintf(stderr, " meta %d: type %d (%s), data %p, size %d:\n", i, m->type,
type_name, m->data, m->size);
if (!strcmp (type_name, SPA_TYPE_META__Header)) {
struct spa_meta_header *h = m->data;
fprintf (stderr, " struct spa_meta_header:\n");
fprintf (stderr, " flags: %08x\n", h->flags);
fprintf (stderr, " seq: %u\n", h->seq);
fprintf (stderr, " pts: %"PRIi64"\n", h->pts);
fprintf (stderr, " dts_offset: %"PRIi64"\n", h->dts_offset);
}
else if (!strcmp (type_name, SPA_TYPE_META__Pointer)) {
struct spa_meta_pointer *h = m->data;
fprintf (stderr, " struct spa_meta_pointer:\n");
fprintf (stderr, " type: %s\n", spa_type_map_get_type (map, h->type));
fprintf (stderr, " ptr: %p\n", h->ptr);
}
else if (!strcmp (type_name, SPA_TYPE_META__VideoCrop)) {
struct spa_meta_video_crop *h = m->data;
fprintf (stderr, " struct spa_meta_video_crop:\n");
fprintf (stderr, " x: %d\n", h->x);
fprintf (stderr, " y: %d\n", h->y);
fprintf (stderr, " width: %d\n", h->width);
fprintf (stderr, " height: %d\n", h->height);
}
else if (!strcmp (type_name, SPA_TYPE_META__Ringbuffer)) {
struct spa_meta_ringbuffer *h = m->data;
fprintf (stderr, " struct spa_meta_ringbuffer:\n");
fprintf (stderr, " readindex: %d\n", h->ringbuffer.readindex);
fprintf (stderr, " writeindex: %d\n", h->ringbuffer.writeindex);
fprintf (stderr, " size: %d\n", h->ringbuffer.size);
fprintf (stderr, " mask: %d\n", h->ringbuffer.mask);
}
else if (!strcmp (type_name, SPA_TYPE_META__Shared)) {
struct spa_meta_shared *h = m->data;
fprintf (stderr, " struct spa_meta_shared:\n");
fprintf (stderr, " flags: %d\n", h->flags);
fprintf (stderr, " fd: %d\n", h->fd);
fprintf (stderr, " offset: %d\n", h->offset);
fprintf (stderr, " size: %d\n", h->size);
}
else {
fprintf (stderr, " Unknown:\n");
spa_debug_dump_mem (m->data, m->size);
}
}
fprintf (stderr, " n_datas: \t%u (at %p)\n", buffer->n_datas, buffer->datas);
for (i = 0; i < buffer->n_datas; i++) {
struct spa_data *d = &buffer->datas[i];
fprintf (stderr, " type: %d (%s)\n", d->type, spa_type_map_get_type (map, d->type));
fprintf (stderr, " flags: %d\n", d->flags);
fprintf (stderr, " data: %p\n", d->data);
fprintf (stderr, " fd: %d\n", d->fd);
fprintf (stderr, " offset: %d\n", d->mapoffset);
fprintf (stderr, " maxsize: %u\n", d->maxsize);
fprintf (stderr, " chunk: %p\n", d->chunk);
fprintf (stderr, " offset: %d\n", d->chunk->offset);
fprintf (stderr, " size: %u\n", d->chunk->size);
fprintf (stderr, " stride: %d\n", d->chunk->stride);
}
return SPA_RESULT_OK;
if (!strcmp(type_name, SPA_TYPE_META__Header)) {
struct spa_meta_header *h = m->data;
fprintf(stderr, " struct spa_meta_header:\n");
fprintf(stderr, " flags: %08x\n", h->flags);
fprintf(stderr, " seq: %u\n", h->seq);
fprintf(stderr, " pts: %" PRIi64 "\n", h->pts);
fprintf(stderr, " dts_offset: %" PRIi64 "\n", h->dts_offset);
} else if (!strcmp(type_name, SPA_TYPE_META__Pointer)) {
struct spa_meta_pointer *h = m->data;
fprintf(stderr, " struct spa_meta_pointer:\n");
fprintf(stderr, " type: %s\n",
spa_type_map_get_type(map, h->type));
fprintf(stderr, " ptr: %p\n", h->ptr);
} else if (!strcmp(type_name, SPA_TYPE_META__VideoCrop)) {
struct spa_meta_video_crop *h = m->data;
fprintf(stderr, " struct spa_meta_video_crop:\n");
fprintf(stderr, " x: %d\n", h->x);
fprintf(stderr, " y: %d\n", h->y);
fprintf(stderr, " width: %d\n", h->width);
fprintf(stderr, " height: %d\n", h->height);
} else if (!strcmp(type_name, SPA_TYPE_META__Ringbuffer)) {
struct spa_meta_ringbuffer *h = m->data;
fprintf(stderr, " struct spa_meta_ringbuffer:\n");
fprintf(stderr, " readindex: %d\n", h->ringbuffer.readindex);
fprintf(stderr, " writeindex: %d\n", h->ringbuffer.writeindex);
fprintf(stderr, " size: %d\n", h->ringbuffer.size);
fprintf(stderr, " mask: %d\n", h->ringbuffer.mask);
} else if (!strcmp(type_name, SPA_TYPE_META__Shared)) {
struct spa_meta_shared *h = m->data;
fprintf(stderr, " struct spa_meta_shared:\n");
fprintf(stderr, " flags: %d\n", h->flags);
fprintf(stderr, " fd: %d\n", h->fd);
fprintf(stderr, " offset: %d\n", h->offset);
fprintf(stderr, " size: %d\n", h->size);
} else {
fprintf(stderr, " Unknown:\n");
spa_debug_dump_mem(m->data, m->size);
}
}
fprintf(stderr, " n_datas: \t%u (at %p)\n", buffer->n_datas, buffer->datas);
for (i = 0; i < buffer->n_datas; i++) {
struct spa_data *d = &buffer->datas[i];
fprintf(stderr, " type: %d (%s)\n", d->type,
spa_type_map_get_type(map, d->type));
fprintf(stderr, " flags: %d\n", d->flags);
fprintf(stderr, " data: %p\n", d->data);
fprintf(stderr, " fd: %d\n", d->fd);
fprintf(stderr, " offset: %d\n", d->mapoffset);
fprintf(stderr, " maxsize: %u\n", d->maxsize);
fprintf(stderr, " chunk: %p\n", d->chunk);
fprintf(stderr, " offset: %d\n", d->chunk->offset);
fprintf(stderr, " size: %u\n", d->chunk->size);
fprintf(stderr, " stride: %d\n", d->chunk->stride);
}
return SPA_RESULT_OK;
}
int
spa_debug_dump_mem (const void *mem, size_t size)
int spa_debug_dump_mem(const void *mem, size_t size)
{
const uint8_t *t = mem;
int i;
const uint8_t *t = mem;
int i;
if (mem == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (mem == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < size; i++) {
if (i % 16 == 0)
printf ("%p: ", &t[i]);
printf ("%02x ", t[i]);
if (i % 16 == 15 || i == size - 1)
printf ("\n");
}
return SPA_RESULT_OK;
for (i = 0; i < size; i++) {
if (i % 16 == 0)
printf("%p: ", &t[i]);
printf("%02x ", t[i]);
if (i % 16 == 15 || i == size - 1)
printf("\n");
}
return SPA_RESULT_OK;
}
int
spa_debug_props (const struct spa_props *props, const struct spa_type_map *map)
int spa_debug_props(const struct spa_props *props, const struct spa_type_map *map)
{
spa_debug_pod (&props->object.pod, map);
return SPA_RESULT_OK;
spa_debug_pod(&props->object.pod, map);
return SPA_RESULT_OK;
}
int
spa_debug_param (const struct spa_param *param, const struct spa_type_map *map)
int spa_debug_param(const struct spa_param *param, const struct spa_type_map *map)
{
spa_debug_pod (&param->object.pod, map);
return SPA_RESULT_OK;
spa_debug_pod(&param->object.pod, map);
return SPA_RESULT_OK;
}
struct pod_type_name {
const char *name;
const char *CCName;
const char *name;
const char *CCName;
} pod_type_names[] = {
{ "invalid", "*Invalid*" },
{ "none", "None" },
{ "bool", "Bool" },
{ "id", "Id" },
{ "int", "Int" },
{ "long", "Long" },
{ "float", "Float" },
{ "double", "Double" },
{ "string", "String" },
{ "bytes", "Bytes" },
{ "pointer", "Pointer" },
{ "rectangle", "Rectangle" },
{ "fraction", "Fraction" },
{ "bitmask", "Bitmask" },
{ "array", "Array" },
{ "struct", "Struct" },
{ "object", "Object" },
{ "prop", "Prop" },
{ "invalid", "*Invalid*"},
{ "none", "None"},
{ "bool", "Bool"},
{ "id", "Id"},
{ "int", "Int"},
{ "long", "Long"},
{ "float", "Float"},
{ "double", "Double"},
{ "string", "String"},
{ "bytes", "Bytes"},
{ "pointer", "Pointer"},
{ "rectangle", "Rectangle"},
{ "fraction", "Fraction"},
{ "bitmask", "Bitmask"},
{ "array", "Array"},
{ "struct", "Struct"},
{ "object", "Object"},
{ "prop", "Prop"},
};
static void
print_pod_value (const struct spa_type_map *map, uint32_t size, uint32_t type, void *body, int prefix)
print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, void *body,
int prefix)
{
switch (type) {
case SPA_POD_TYPE_BOOL:
printf ("%-*sBool %d\n", prefix, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_ID:
printf ("%-*sId %d %s\n", prefix, "", *(int32_t *) body,
spa_type_map_get_type (map, *(int32_t*)body));
break;
case SPA_POD_TYPE_INT:
printf ("%-*sInt %d\n", prefix, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_LONG:
printf ("%-*sLong %"PRIi64"\n", prefix, "", *(int64_t *) body);
break;
case SPA_POD_TYPE_FLOAT:
printf ("%-*sFloat %f\n", prefix, "", *(float *) body);
break;
case SPA_POD_TYPE_DOUBLE:
printf ("%-*sDouble %f\n", prefix, "", *(double *) body);
break;
case SPA_POD_TYPE_STRING:
printf ("%-*sString \"%s\"\n", prefix, "", (char *) body);
break;
case SPA_POD_TYPE_POINTER:
{
struct spa_pod_pointer_body *b = body;
printf ("%-*sPointer %s %p\n", prefix, "",
spa_type_map_get_type (map, b->type), b->value);
break;
}
case SPA_POD_TYPE_RECTANGLE:
{
struct spa_rectangle *r = body;
printf ("%-*sRectangle %dx%d\n", prefix, "", r->width, r->height);
break;
}
case SPA_POD_TYPE_FRACTION:
{
struct spa_fraction *f = body;
printf ("%-*sFraction %d/%d\n", prefix, "", f->num, f->denom);
break;
}
case SPA_POD_TYPE_BITMASK:
printf ("%-*sBitmask\n", prefix, "");
break;
case SPA_POD_TYPE_ARRAY:
{
struct spa_pod_array_body *b = body;
void *p;
printf ("%-*sArray: child.size %d, child.type %d\n", prefix, "", b->child.size, b->child.type);
switch (type) {
case SPA_POD_TYPE_BOOL:
printf("%-*sBool %d\n", prefix, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_ID:
printf("%-*sId %d %s\n", prefix, "", *(int32_t *) body,
spa_type_map_get_type(map, *(int32_t *) body));
break;
case SPA_POD_TYPE_INT:
printf("%-*sInt %d\n", prefix, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_LONG:
printf("%-*sLong %" PRIi64 "\n", prefix, "", *(int64_t *) body);
break;
case SPA_POD_TYPE_FLOAT:
printf("%-*sFloat %f\n", prefix, "", *(float *) body);
break;
case SPA_POD_TYPE_DOUBLE:
printf("%-*sDouble %f\n", prefix, "", *(double *) body);
break;
case SPA_POD_TYPE_STRING:
printf("%-*sString \"%s\"\n", prefix, "", (char *) body);
break;
case SPA_POD_TYPE_POINTER:
{
struct spa_pod_pointer_body *b = body;
printf("%-*sPointer %s %p\n", prefix, "",
spa_type_map_get_type(map, b->type), b->value);
break;
}
case SPA_POD_TYPE_RECTANGLE:
{
struct spa_rectangle *r = body;
printf("%-*sRectangle %dx%d\n", prefix, "", r->width, r->height);
break;
}
case SPA_POD_TYPE_FRACTION:
{
struct spa_fraction *f = body;
printf("%-*sFraction %d/%d\n", prefix, "", f->num, f->denom);
break;
}
case SPA_POD_TYPE_BITMASK:
printf("%-*sBitmask\n", prefix, "");
break;
case SPA_POD_TYPE_ARRAY:
{
struct spa_pod_array_body *b = body;
void *p;
printf("%-*sArray: child.size %d, child.type %d\n", prefix, "",
b->child.size, b->child.type);
SPA_POD_ARRAY_BODY_FOREACH (b, size, p)
print_pod_value (map, b->child.size, b->child.type, p, prefix + 2);
break;
}
case SPA_POD_TYPE_STRUCT:
{
struct spa_pod *b = body, *p;
printf ("%-*sStruct: size %d\n", prefix, "", size);
SPA_POD_FOREACH (b, size, p)
print_pod_value (map, p->size, p->type, SPA_POD_BODY (p), prefix + 2);
break;
}
case SPA_POD_TYPE_OBJECT:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
print_pod_value(map, b->child.size, b->child.type, p, prefix + 2);
break;
}
case SPA_POD_TYPE_STRUCT:
{
struct spa_pod *b = body, *p;
printf("%-*sStruct: size %d\n", prefix, "", size);
SPA_POD_FOREACH(b, size, p)
print_pod_value(map, p->size, p->type, SPA_POD_BODY(p), prefix + 2);
break;
}
case SPA_POD_TYPE_OBJECT:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
printf ("%-*sObject: size %d, id %d, type %s\n", prefix, "", size, b->id,
spa_type_map_get_type (map, b->type));
SPA_POD_OBJECT_BODY_FOREACH (b, size, p)
print_pod_value (map, p->size, p->type, SPA_POD_BODY (p), prefix + 2);
break;
}
case SPA_POD_TYPE_PROP:
{
struct spa_pod_prop_body *b = body;
void *alt;
int i;
printf("%-*sObject: size %d, id %d, type %s\n", prefix, "", size, b->id,
spa_type_map_get_type(map, b->type));
SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
print_pod_value(map, p->size, p->type, SPA_POD_BODY(p), prefix + 2);
break;
}
case SPA_POD_TYPE_PROP:
{
struct spa_pod_prop_body *b = body;
void *alt;
int i;
printf ("%-*sProp: key %s, flags %d\n", prefix, "",
spa_type_map_get_type (map, b->key), b->flags);
if (b->flags & SPA_POD_PROP_FLAG_UNSET)
printf ("%-*sUnset (Default):\n", prefix + 2, "");
else
printf ("%-*sValue: size %u\n", prefix + 2, "", b->value.size);
print_pod_value (map, b->value.size, b->value.type, SPA_POD_BODY (&b->value), prefix + 4);
printf("%-*sProp: key %s, flags %d\n", prefix, "",
spa_type_map_get_type(map, b->key), b->flags);
if (b->flags & SPA_POD_PROP_FLAG_UNSET)
printf("%-*sUnset (Default):\n", prefix + 2, "");
else
printf("%-*sValue: size %u\n", prefix + 2, "", b->value.size);
print_pod_value(map, b->value.size, b->value.type, SPA_POD_BODY(&b->value),
prefix + 4);
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH (b, size, alt) {
if (i == 0)
printf ("%-*sAlternatives:\n", prefix + 2, "");
print_pod_value (map, b->value.size, b->value.type, alt, prefix + 4);
i++;
}
break;
}
case SPA_POD_TYPE_BYTES:
printf ("%-*sBytes\n", prefix, "");
spa_debug_dump_mem (body, size);
break;
case SPA_POD_TYPE_NONE:
printf ("%-*sNone\n", prefix, "");
spa_debug_dump_mem (body, size);
break;
default:
printf ("unhandled POD type %d\n", type);
break;
}
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
if (i == 0)
printf("%-*sAlternatives:\n", prefix + 2, "");
print_pod_value(map, b->value.size, b->value.type, alt, prefix + 4);
i++;
}
break;
}
case SPA_POD_TYPE_BYTES:
printf("%-*sBytes\n", prefix, "");
spa_debug_dump_mem(body, size);
break;
case SPA_POD_TYPE_NONE:
printf("%-*sNone\n", prefix, "");
spa_debug_dump_mem(body, size);
break;
default:
printf("unhandled POD type %d\n", type);
break;
}
}
int
spa_debug_pod (const struct spa_pod *pod, const struct spa_type_map *map)
int spa_debug_pod(const struct spa_pod *pod, const struct spa_type_map *map)
{
map = map ? map : spa_type_map_get_default ();
print_pod_value (map, pod->size, pod->type, SPA_POD_BODY (pod), 0);
return SPA_RESULT_OK;
map = map ? map : spa_type_map_get_default();
print_pod_value(map, pod->size, pod->type, SPA_POD_BODY(pod), 0);
return SPA_RESULT_OK;
}
static void
print_format_value (const struct spa_type_map *map, uint32_t size, uint32_t type, void *body)
print_format_value(const struct spa_type_map *map, uint32_t size, uint32_t type, void *body)
{
switch (type) {
case SPA_POD_TYPE_BOOL:
fprintf (stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_POD_TYPE_ID:
{
const char *str = spa_type_map_get_type (map, *(int32_t*)body);
if (str) {
const char *h = rindex (str, ':');
if (h)
str = h + 1;
} else {
str = "unknown";
}
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;
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_BITMASK:
fprintf (stderr, "Bitmask");
break;
case SPA_POD_TYPE_BYTES:
fprintf (stderr, "Bytes");
break;
default:
break;
}
switch (type) {
case SPA_POD_TYPE_BOOL:
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_POD_TYPE_ID:
{
const char *str = spa_type_map_get_type(map, *(int32_t *) body);
if (str) {
const char *h = rindex(str, ':');
if (h)
str = h + 1;
} else {
str = "unknown";
}
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;
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_BITMASK:
fprintf(stderr, "Bitmask");
break;
case SPA_POD_TYPE_BYTES:
fprintf(stderr, "Bytes");
break;
default:
break;
}
}
int
spa_debug_format (const struct spa_format *format, const struct spa_type_map *map)
int spa_debug_format(const struct spa_format *format, const struct spa_type_map *map)
{
int i;
const char *media_type;
const char *media_subtype;
struct spa_pod_prop *prop;
uint32_t mtype, mstype;
int i;
const char *media_type;
const char *media_subtype;
struct spa_pod_prop *prop;
uint32_t mtype, mstype;
if (format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
map = map ? map : spa_type_map_get_default ();
map = map ? map : spa_type_map_get_default();
mtype = format->body.media_type.value;
mstype = format->body.media_subtype.value;
mtype = format->body.media_type.value;
mstype = format->body.media_subtype.value;
media_type = spa_type_map_get_type (map, mtype);
media_subtype = spa_type_map_get_type (map, mstype);
media_type = spa_type_map_get_type(map, mtype);
media_subtype = spa_type_map_get_type(map, mstype);
fprintf (stderr, "%-6s %s/%s\n", "", rindex (media_type, ':')+1, rindex (media_subtype, ':')+1);
fprintf(stderr, "%-6s %s/%s\n", "", rindex(media_type, ':') + 1,
rindex(media_subtype, ':') + 1);
SPA_FORMAT_FOREACH (format, prop) {
const char *key;
SPA_FORMAT_FOREACH(format, prop) {
const char *key;
if ((prop->body.flags & SPA_POD_PROP_FLAG_UNSET) &&
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
continue;
if ((prop->body.flags & SPA_POD_PROP_FLAG_UNSET) &&
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
continue;
key = spa_type_map_get_type (map, prop->body.key);
key = spa_type_map_get_type(map, prop->body.key);
fprintf (stderr, " %20s : (%s) ", rindex (key, ':')+1, pod_type_names[prop->body.value.type].name);
fprintf(stderr, " %20s : (%s) ", rindex(key, ':') + 1,
pod_type_names[prop->body.value.type].name);
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
print_format_value (map, prop->body.value.size,
prop->body.value.type,
SPA_POD_BODY (&prop->body.value));
} else {
const char *ssep, *esep, *sep;
void *alt;
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
print_format_value(map, prop->body.value.size,
prop->body.value.type, SPA_POD_BODY(&prop->body.value));
} 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;
}
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);
fprintf(stderr, "%s", ssep);
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH (&prop->body, prop->pod.size, alt) {
if (i > 0)
fprintf (stderr, "%s", sep);
print_format_value (map, prop->body.value.size, prop->body.value.type, alt);
i++;
}
fprintf (stderr, "%s", esep);
}
fprintf (stderr, "\n");
}
return SPA_RESULT_OK;
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) {
if (i > 0)
fprintf(stderr, "%s", sep);
print_format_value(map, prop->body.value.size,
prop->body.value.type, alt);
i++;
}
fprintf(stderr, "%s", esep);
}
fprintf(stderr, "\n");
}
return SPA_RESULT_OK;
}
int
spa_debug_dict (const struct spa_dict *dict)
int spa_debug_dict(const struct spa_dict *dict)
{
unsigned int i;
unsigned int i;
if (dict == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (dict == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < dict->n_items; i++)
fprintf (stderr, " %s = \"%s\"\n", dict->items[i].key, dict->items[i].value);
for (i = 0; i < dict->n_items; i++)
fprintf(stderr, " %s = \"%s\"\n", dict->items[i].key,
dict->items[i].value);
return SPA_RESULT_OK;
return SPA_RESULT_OK;
}
@ -447,111 +442,107 @@ spa_debug_dict (const struct spa_dict *dict)
#define TRACE_BUFFER 4096
struct debug_log {
struct spa_log log;
struct spa_ringbuffer trace_rb;
uint8_t trace_data[TRACE_BUFFER];
struct spa_source *source;
struct spa_log log;
struct spa_ringbuffer trace_rb;
uint8_t trace_data[TRACE_BUFFER];
struct spa_source *source;
};
static void
do_logv (struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt,
va_list args)
do_logv(struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt,
va_list args)
{
struct debug_log *l = SPA_CONTAINER_OF (log, struct debug_log, log);
char text[512], location[1024];
static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
int size;
bool do_trace;
struct debug_log *l = SPA_CONTAINER_OF(log, struct debug_log, log);
char text[512], location[1024];
static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
int size;
bool do_trace;
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source)))
level++;
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source)))
level++;
vsnprintf (text, sizeof(text), fmt, args);
size = snprintf (location, sizeof(location), "[%s][%s:%i %s()] %s\n",
levels[level], strrchr (file, '/')+1, line, func, text);
vsnprintf(text, sizeof(text), fmt, args);
size = snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
levels[level], strrchr(file, '/') + 1, line, func, text);
if (SPA_UNLIKELY (do_trace)) {
uint32_t index;
uint64_t count = 1;
if (SPA_UNLIKELY(do_trace)) {
uint32_t index;
uint64_t count = 1;
spa_ringbuffer_get_write_index (&l->trace_rb, &index);
spa_ringbuffer_write_data (&l->trace_rb, l->trace_data,
index & l->trace_rb.mask,
location, size);
spa_ringbuffer_write_update (&l->trace_rb, index + size);
spa_ringbuffer_get_write_index(&l->trace_rb, &index);
spa_ringbuffer_write_data(&l->trace_rb, l->trace_data,
index & l->trace_rb.mask, location, size);
spa_ringbuffer_write_update(&l->trace_rb, index + size);
write (l->source->fd, &count, sizeof(uint64_t));
} else
fputs (location, stderr);
write(l->source->fd, &count, sizeof(uint64_t));
} else
fputs(location, stderr);
}
static void
do_log (struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt, ...)
do_log(struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
do_logv (log, level, file, line, func, fmt, args);
va_end (args);
va_list args;
va_start(args, fmt);
do_logv(log, level, file, line, func, fmt, args);
va_end(args);
}
static struct debug_log log = {
{ sizeof (struct spa_log),
NULL,
DEFAULT_LOG_LEVEL,
do_log,
do_logv,
},
{ 0, 0, TRACE_BUFFER, TRACE_BUFFER - 1 },
{sizeof(struct spa_log),
NULL,
DEFAULT_LOG_LEVEL,
do_log,
do_logv,
},
{0, 0, TRACE_BUFFER, TRACE_BUFFER - 1},
};
struct spa_log *
spa_log_get_default (void)
struct spa_log *spa_log_get_default(void)
{
return &log.log;
return &log.log;
}
static void
on_trace_event (struct spa_source *source)
static void on_trace_event(struct spa_source *source)
{
int32_t avail;
uint32_t index;
uint64_t count;
int32_t avail;
uint32_t index;
uint64_t count;
if (read (source->fd, &count, sizeof (uint64_t)) != sizeof (uint64_t))
fprintf (stderr, "failed to read event fd: %s", strerror (errno));
if (read(source->fd, &count, sizeof(uint64_t)) != sizeof(uint64_t))
fprintf(stderr, "failed to read event fd: %s", strerror(errno));
while ((avail = spa_ringbuffer_get_read_index (&log.trace_rb, &index)) > 0) {
uint32_t offset, first;
while ((avail = spa_ringbuffer_get_read_index(&log.trace_rb, &index)) > 0) {
uint32_t offset, first;
if (avail > log.trace_rb.size) {
index += avail - log.trace_rb.size;
avail = log.trace_rb.size;
}
offset = index & log.trace_rb.mask;
first = SPA_MIN (avail, log.trace_rb.size - offset);
if (avail > log.trace_rb.size) {
index += avail - log.trace_rb.size;
avail = log.trace_rb.size;
}
offset = index & log.trace_rb.mask;
first = SPA_MIN(avail, log.trace_rb.size - offset);
fwrite (log.trace_data + offset, first, 1, stderr);
if (SPA_UNLIKELY (avail > first)) {
fwrite (log.trace_data, avail - first, 1, stderr);
}
spa_ringbuffer_read_update (&log.trace_rb, index + avail);
}
fwrite(log.trace_data + offset, first, 1, stderr);
if (SPA_UNLIKELY(avail > first)) {
fwrite(log.trace_data, avail - first, 1, stderr);
}
spa_ringbuffer_read_update(&log.trace_rb, index + avail);
}
}
void
spa_log_default_set_trace_event (struct spa_source *source)
void spa_log_default_set_trace_event(struct spa_source *source)
{
log.source = source;
log.source->func = on_trace_event;
log.source->data = &log;
log.source = source;
log.source->func = on_trace_event;
log.source->data = &log;
}

View file

@ -33,22 +33,20 @@ extern "C" {
#include <spa/dict.h>
#include <spa/log.h>
int spa_debug_port_info (const struct spa_port_info *info, const struct spa_type_map *map);
int spa_debug_buffer (const struct spa_buffer *buffer, const struct spa_type_map *map);
int spa_debug_props (const struct spa_props *props, const struct spa_type_map *map);
int spa_debug_param (const struct spa_param *param, const struct spa_type_map *map);
int spa_debug_pod (const struct spa_pod *pod, const struct spa_type_map *map);
int spa_debug_format (const struct spa_format *format, const struct spa_type_map *map);
int spa_debug_dump_mem (const void *data, size_t size);
int spa_debug_dict (const struct spa_dict *dict);
int spa_debug_port_info(const struct spa_port_info *info, const struct spa_type_map *map);
int spa_debug_buffer(const struct spa_buffer *buffer, const struct spa_type_map *map);
int spa_debug_props(const struct spa_props *props, const struct spa_type_map *map);
int spa_debug_param(const struct spa_param *param, const struct spa_type_map *map);
int spa_debug_pod(const struct spa_pod *pod, const struct spa_type_map *map);
int spa_debug_format(const struct spa_format *format, const struct spa_type_map *map);
int spa_debug_dump_mem(const void *data, size_t size);
int spa_debug_dict(const struct spa_dict *dict);
struct spa_log* spa_log_get_default (void);
void spa_log_default_trace_purge (void);
struct spa_log *spa_log_get_default(void);
void spa_log_default_trace_purge(void);
#ifdef __cplusplus
} /* extern "C" */
} /* extern "C" */
#endif
#endif /* __SPA_LIBDEBUG_H__ */

View file

@ -28,34 +28,34 @@
#include <lib/mapper.h>
int
spa_format_filter (const struct spa_format *format,
const struct spa_format *filter,
struct spa_pod_builder *result)
spa_format_filter(const struct spa_format *format,
const struct spa_format *filter,
struct spa_pod_builder *result)
{
struct spa_pod_frame f;
int res;
struct spa_pod_frame f;
int res;
if (format == NULL || result == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (format == NULL || result == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (filter == NULL) {
spa_pod_builder_raw_padded (result, format, SPA_POD_SIZE (format));
return SPA_RESULT_OK;
}
if (filter == NULL) {
spa_pod_builder_raw_padded(result, format, SPA_POD_SIZE(format));
return SPA_RESULT_OK;
}
if (SPA_FORMAT_MEDIA_TYPE (filter) != SPA_FORMAT_MEDIA_TYPE (format) ||
SPA_FORMAT_MEDIA_SUBTYPE (filter) != SPA_FORMAT_MEDIA_SUBTYPE (format))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (SPA_FORMAT_MEDIA_TYPE(filter) != SPA_FORMAT_MEDIA_TYPE(format) ||
SPA_FORMAT_MEDIA_SUBTYPE(filter) != SPA_FORMAT_MEDIA_SUBTYPE(format))
return SPA_RESULT_INVALID_MEDIA_TYPE;
spa_pod_builder_push_format (result, &f, filter->body.obj_body.type,
SPA_FORMAT_MEDIA_TYPE (filter),
SPA_FORMAT_MEDIA_SUBTYPE (filter));
res = spa_props_filter (result,
SPA_POD_CONTENTS (struct spa_format, format),
SPA_POD_CONTENTS_SIZE (struct spa_format, format),
SPA_POD_CONTENTS (struct spa_format, filter),
SPA_POD_CONTENTS_SIZE (struct spa_format, filter));
spa_pod_builder_pop (result, &f);
spa_pod_builder_push_format(result, &f, filter->body.obj_body.type,
SPA_FORMAT_MEDIA_TYPE(filter),
SPA_FORMAT_MEDIA_SUBTYPE(filter));
res = spa_props_filter(result,
SPA_POD_CONTENTS(struct spa_format, format),
SPA_POD_CONTENTS_SIZE(struct spa_format, format),
SPA_POD_CONTENTS(struct spa_format, filter),
SPA_POD_CONTENTS_SIZE(struct spa_format, filter));
spa_pod_builder_pop(result, &f);
return res;
return res;
}

View file

@ -28,68 +28,63 @@
#define MAX_TYPES 4096
struct type_map{
struct spa_type_map map;
char *types[MAX_TYPES];
unsigned int n_types;
struct type_map {
struct spa_type_map map;
char *types[MAX_TYPES];
unsigned int n_types;
};
static uint32_t
type_map_get_id (struct spa_type_map *map, const char *type)
static uint32_t type_map_get_id(struct spa_type_map *map, const char *type)
{
struct type_map *this = SPA_CONTAINER_OF (map, struct type_map, map);
unsigned int i = 0;
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
unsigned int i = 0;
if (type != NULL) {
for (i = 1; i <= this->n_types; i++) {
if (strcmp (this->types[i], type) == 0)
return i;
}
this->types[i] = (char *)type;
this->n_types++;
}
return i;
if (type != NULL) {
for (i = 1; i <= this->n_types; i++) {
if (strcmp(this->types[i], type) == 0)
return i;
}
this->types[i] = (char *) type;
this->n_types++;
}
return i;
}
static const char *
type_map_get_type (const struct spa_type_map *map, uint32_t id)
static const char *type_map_get_type(const struct spa_type_map *map, uint32_t id)
{
struct type_map *this = SPA_CONTAINER_OF (map, struct type_map, map);
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
if (id <= this->n_types)
return this->types[id];
if (id <= this->n_types)
return this->types[id];
return NULL;
return NULL;
}
static size_t
type_map_get_size (const struct spa_type_map *map)
static size_t type_map_get_size(const struct spa_type_map *map)
{
struct type_map *this = SPA_CONTAINER_OF (map, struct type_map, map);
return this->n_types;
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
return this->n_types;
}
static struct type_map default_type_map = {
{ sizeof (struct spa_type_map),
NULL,
type_map_get_id,
type_map_get_type,
type_map_get_size,
},
{ NULL, },
0
{sizeof(struct spa_type_map),
NULL,
type_map_get_id,
type_map_get_type,
type_map_get_size,
},
{NULL,},
0
};
static struct spa_type_map *default_map = &default_type_map.map;
struct spa_type_map *
spa_type_map_get_default (void)
struct spa_type_map *spa_type_map_get_default(void)
{
return default_map;
return default_map;
}
void
spa_type_map_set_default (struct spa_type_map *map)
void spa_type_map_set_default(struct spa_type_map *map)
{
default_map = map;
default_map = map;
}

View file

@ -26,11 +26,11 @@ extern "C" {
#include <spa/type-map.h>
void spa_type_map_set_default (struct spa_type_map *map);
struct spa_type_map * spa_type_map_get_default (void);
void spa_type_map_set_default(struct spa_type_map *map);
struct spa_type_map *spa_type_map_get_default(void);
#ifdef __cplusplus
} /* extern "C" */
} /* extern "C" */
#endif
#endif /* __SPA_LIBMAPPER_H__ */

View file

@ -24,288 +24,289 @@
#include <spa/props.h>
static int
compare_value (enum spa_pod_type type, const void *r1, const void *r2)
static int compare_value(enum spa_pod_type type, const void *r1, const void *r2)
{
switch (type) {
case SPA_POD_TYPE_INVALID:
return 0;
case SPA_POD_TYPE_BOOL:
case SPA_POD_TYPE_ID:
return *(int32_t*)r1 == *(uint32_t*)r2 ? 0 : 1;
case SPA_POD_TYPE_INT:
return *(int32_t*)r1 - *(int32_t*)r2;
case SPA_POD_TYPE_LONG:
return *(int64_t*)r1 - *(int64_t*)r2;
case SPA_POD_TYPE_FLOAT:
return *(float*)r1 - *(float*)r2;
case SPA_POD_TYPE_DOUBLE:
return *(double*)r1 - *(double*)r2;
case SPA_POD_TYPE_STRING:
return strcmp (r1, r2);
case SPA_POD_TYPE_RECTANGLE:
{
const struct spa_rectangle *rec1 = (struct spa_rectangle*)r1,
*rec2 = (struct spa_rectangle*)r2;
if (rec1->width == rec2->width && rec1->height == rec2->height)
return 0;
else if (rec1->width < rec2->width || rec1->height < rec2->height)
return -1;
else
return 1;
}
case SPA_POD_TYPE_FRACTION:
{
const struct spa_fraction *f1 = (struct spa_fraction*)r1,
*f2 = (struct spa_fraction*)r2;
uint64_t n1, n2;
n1 = ((int64_t) f1->num) * f2->denom;
n2 = ((int64_t) f2->num) * f1->denom;
if (n1 < n2)
return -1;
else if (n1 > n2)
return 1;
else
return 0;
}
default:
break;
}
return 0;
switch (type) {
case SPA_POD_TYPE_INVALID:
return 0;
case SPA_POD_TYPE_BOOL:
case SPA_POD_TYPE_ID:
return *(int32_t *) r1 == *(uint32_t *) r2 ? 0 : 1;
case SPA_POD_TYPE_INT:
return *(int32_t *) r1 - *(int32_t *) r2;
case SPA_POD_TYPE_LONG:
return *(int64_t *) r1 - *(int64_t *) r2;
case SPA_POD_TYPE_FLOAT:
return *(float *) r1 - *(float *) r2;
case SPA_POD_TYPE_DOUBLE:
return *(double *) r1 - *(double *) r2;
case SPA_POD_TYPE_STRING:
return strcmp(r1, r2);
case SPA_POD_TYPE_RECTANGLE:
{
const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1,
*rec2 = (struct spa_rectangle *) r2;
if (rec1->width == rec2->width && rec1->height == rec2->height)
return 0;
else if (rec1->width < rec2->width || rec1->height < rec2->height)
return -1;
else
return 1;
}
case SPA_POD_TYPE_FRACTION:
{
const struct spa_fraction *f1 = (struct spa_fraction *) r1,
*f2 = (struct spa_fraction *) r2;
uint64_t n1, n2;
n1 = ((int64_t) f1->num) * f2->denom;
n2 = ((int64_t) f2->num) * f1->denom;
if (n1 < n2)
return -1;
else if (n1 > n2)
return 1;
else
return 0;
}
default:
break;
}
return 0;
}
static void
fix_default (struct spa_pod_prop *prop)
static void fix_default(struct spa_pod_prop *prop)
{
void *val = SPA_MEMBER (prop, sizeof (struct spa_pod_prop), void),
*alt = SPA_MEMBER (val, prop->body.value.size, void);
int i, nalt = SPA_POD_PROP_N_VALUES (prop) - 1;
void *val = SPA_MEMBER(prop, sizeof(struct spa_pod_prop), void),
*alt = SPA_MEMBER(val, prop->body.value.size, void);
int i, nalt = SPA_POD_PROP_N_VALUES(prop) - 1;
switch (prop->body.flags & SPA_POD_PROP_RANGE_MASK) {
case SPA_POD_PROP_RANGE_NONE:
break;
case SPA_POD_PROP_RANGE_MIN_MAX:
case SPA_POD_PROP_RANGE_STEP:
if (compare_value (prop->body.value.type, val, alt) < 0)
memcpy (val, alt, prop->body.value.size);
alt = SPA_MEMBER (alt, prop->body.value.size, void);
if (compare_value (prop->body.value.type, val, alt) > 0)
memcpy (val, alt, prop->body.value.size);
break;
case SPA_POD_PROP_RANGE_ENUM:
{
void *best = NULL;
switch (prop->body.flags & SPA_POD_PROP_RANGE_MASK) {
case SPA_POD_PROP_RANGE_NONE:
break;
case SPA_POD_PROP_RANGE_MIN_MAX:
case SPA_POD_PROP_RANGE_STEP:
if (compare_value(prop->body.value.type, val, alt) < 0)
memcpy(val, alt, prop->body.value.size);
alt = SPA_MEMBER(alt, prop->body.value.size, void);
if (compare_value(prop->body.value.type, val, alt) > 0)
memcpy(val, alt, prop->body.value.size);
break;
case SPA_POD_PROP_RANGE_ENUM:
{
void *best = NULL;
for (i = 0; i < nalt; i++) {
if (compare_value (prop->body.value.type, val, alt) == 0) {
best = alt;
break;
}
if (best == NULL)
best = alt;
alt = SPA_MEMBER (alt, prop->body.value.size, void);
}
if (best)
memcpy (val, best, prop->body.value.size);
for (i = 0; i < nalt; i++) {
if (compare_value(prop->body.value.type, val, alt) == 0) {
best = alt;
break;
}
if (best == NULL)
best = alt;
alt = SPA_MEMBER(alt, prop->body.value.size, void);
}
if (best)
memcpy(val, best, prop->body.value.size);
if (nalt == 1) {
prop->body.flags &= ~SPA_POD_PROP_FLAG_UNSET;
prop->body.flags &= ~SPA_POD_PROP_RANGE_MASK;
prop->body.flags |= SPA_POD_PROP_RANGE_NONE;
}
break;
}
case SPA_POD_PROP_RANGE_FLAGS:
break;
}
if (nalt == 1) {
prop->body.flags &= ~SPA_POD_PROP_FLAG_UNSET;
prop->body.flags &= ~SPA_POD_PROP_RANGE_MASK;
prop->body.flags |= SPA_POD_PROP_RANGE_NONE;
}
break;
}
case SPA_POD_PROP_RANGE_FLAGS:
break;
}
}
static inline struct spa_pod_prop *
find_prop (const struct spa_pod *pod, uint32_t size, uint32_t key)
static inline struct spa_pod_prop *find_prop(const struct spa_pod *pod, uint32_t size, uint32_t key)
{
const struct spa_pod *res;
SPA_POD_FOREACH (pod, size, res) {
if (res->type == SPA_POD_TYPE_PROP && ((struct spa_pod_prop*)res)->body.key == key)
return (struct spa_pod_prop *)res;
}
return NULL;
const struct spa_pod *res;
SPA_POD_FOREACH(pod, size, res) {
if (res->type == SPA_POD_TYPE_PROP
&& ((struct spa_pod_prop *) res)->body.key == key)
return (struct spa_pod_prop *) res;
}
return NULL;
}
int
spa_props_filter (struct spa_pod_builder *b,
const struct spa_pod *props,
uint32_t props_size,
const struct spa_pod *filter,
uint32_t filter_size)
spa_props_filter(struct spa_pod_builder *b,
const struct spa_pod *props,
uint32_t props_size,
const struct spa_pod *filter,
uint32_t filter_size)
{
int j, k;
const struct spa_pod *pr;
int j, k;
const struct spa_pod *pr;
SPA_POD_FOREACH (props, props_size, pr) {
struct spa_pod_frame f;
struct spa_pod_prop *p1, *p2, *np;
int nalt1, nalt2;
void *alt1, *alt2, *a1, *a2;
uint32_t rt1, rt2;
SPA_POD_FOREACH(props, props_size, pr) {
struct spa_pod_frame f;
struct spa_pod_prop *p1, *p2, *np;
int nalt1, nalt2;
void *alt1, *alt2, *a1, *a2;
uint32_t rt1, rt2;
if (pr->type != SPA_POD_TYPE_PROP)
continue;
if (pr->type != SPA_POD_TYPE_PROP)
continue;
p1 = (struct spa_pod_prop *) pr;
p1 = (struct spa_pod_prop *) pr;
if (filter == NULL || (p2 = find_prop (filter, filter_size, p1->body.key)) == NULL) {
/* no filter, copy the complete property */
spa_pod_builder_raw_padded (b, p1, SPA_POD_SIZE (p1));
continue;
}
if (filter == NULL || (p2 = find_prop(filter, filter_size, p1->body.key)) == NULL) {
/* no filter, copy the complete property */
spa_pod_builder_raw_padded(b, p1, SPA_POD_SIZE(p1));
continue;
}
/* incompatible property types */
if (p1->body.value.type != p2->body.value.type)
return SPA_RESULT_INCOMPATIBLE_PROPS;
/* incompatible property types */
if (p1->body.value.type != p2->body.value.type)
return SPA_RESULT_INCOMPATIBLE_PROPS;
rt1 = p1->body.flags & SPA_POD_PROP_RANGE_MASK;
rt2 = p2->body.flags & SPA_POD_PROP_RANGE_MASK;
rt1 = p1->body.flags & SPA_POD_PROP_RANGE_MASK;
rt2 = p2->body.flags & SPA_POD_PROP_RANGE_MASK;
/* else we filter. start with copying the property */
spa_pod_builder_push_prop (b, &f, p1->body.key, 0),
np = SPA_POD_BUILDER_DEREF (b, f.ref, struct spa_pod_prop);
/* else we filter. start with copying the property */
spa_pod_builder_push_prop(b, &f, p1->body.key, 0),
np = SPA_POD_BUILDER_DEREF(b, f.ref, struct spa_pod_prop);
/* default value */
spa_pod_builder_raw (b, &p1->body.value, sizeof (p1->body.value) + p1->body.value.size);
/* default value */
spa_pod_builder_raw(b, &p1->body.value,
sizeof(p1->body.value) + p1->body.value.size);
alt1 = SPA_MEMBER (p1, sizeof (struct spa_pod_prop), void);
nalt1 = SPA_POD_PROP_N_VALUES (p1);
alt2 = SPA_MEMBER (p2, sizeof (struct spa_pod_prop), void);
nalt2 = SPA_POD_PROP_N_VALUES (p2);
alt1 = SPA_MEMBER(p1, sizeof(struct spa_pod_prop), void);
nalt1 = SPA_POD_PROP_N_VALUES(p1);
alt2 = SPA_MEMBER(p2, sizeof(struct spa_pod_prop), void);
nalt2 = SPA_POD_PROP_N_VALUES(p2);
if (p1->body.flags & SPA_POD_PROP_FLAG_UNSET) {
alt1 = SPA_MEMBER (alt1, p1->body.value.size, void);
nalt1--;
} else {
nalt1 = 1;
rt1 = SPA_POD_PROP_RANGE_NONE;
}
if (p1->body.flags & SPA_POD_PROP_FLAG_UNSET) {
alt1 = SPA_MEMBER(alt1, p1->body.value.size, void);
nalt1--;
} else {
nalt1 = 1;
rt1 = SPA_POD_PROP_RANGE_NONE;
}
if (p2->body.flags & SPA_POD_PROP_FLAG_UNSET) {
alt2 = SPA_MEMBER (alt2, p2->body.value.size, void);
nalt2--;
} else {
nalt2 = 1;
rt2 = SPA_POD_PROP_RANGE_NONE;
}
if (p2->body.flags & SPA_POD_PROP_FLAG_UNSET) {
alt2 = SPA_MEMBER(alt2, p2->body.value.size, void);
nalt2--;
} else {
nalt2 = 1;
rt2 = SPA_POD_PROP_RANGE_NONE;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_ENUM) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_ENUM)) {
int n_copied = 0;
/* copy all equal values */
for (j = 0, a1 = alt1; j < nalt1; j++, a1 += p1->body.value.size) {
for (k = 0, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) {
if (compare_value (p1->body.value.type, a1, a2) == 0) {
spa_pod_builder_raw (b, a1, p1->body.value.size);
n_copied++;
}
}
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_ENUM) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_ENUM)) {
int n_copied = 0;
/* copy all equal values */
for (j = 0, a1 = alt1; j < nalt1; j++, a1 += p1->body.value.size) {
for (k = 0, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) {
if (compare_value(p1->body.value.type, a1, a2) == 0) {
spa_pod_builder_raw(b, a1, p1->body.value.size);
n_copied++;
}
}
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)) {
int n_copied = 0;
/* copy all values inside the range */
for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 += p1->body.value.size) {
if (compare_value (p1->body.value.type, a1, a2) < 0)
continue;
if (compare_value (p1->body.value.type, a1, a2 + p2->body.value.size) > 0)
continue;
spa_pod_builder_raw (b, a1, p1->body.value.size);
n_copied++;
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)) {
int n_copied = 0;
/* copy all values inside the range */
for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 += p1->body.value.size) {
if (compare_value(p1->body.value.type, a1, a2) < 0)
continue;
if (compare_value(p1->body.value.type, a1, a2 + p2->body.value.size)
> 0)
continue;
spa_pod_builder_raw(b, a1, p1->body.value.size);
n_copied++;
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_STEP) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_STEP)) {
return SPA_RESULT_NOT_IMPLEMENTED;
}
if ((rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_STEP) ||
(rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_STEP)) {
return SPA_RESULT_NOT_IMPLEMENTED;
}
if ((rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_ENUM)) {
int n_copied = 0;
/* copy all values inside the range */
for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) {
if (compare_value (p1->body.value.type, a2, a1) < 0)
continue;
if (compare_value (p1->body.value.type, a2, a1 + p1->body.value.size) > 0)
continue;
spa_pod_builder_raw (b, a2, p2->body.value.size);
n_copied++;
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if ((rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_NONE) ||
(rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_ENUM)) {
int n_copied = 0;
/* copy all values inside the range */
for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 += p2->body.value.size) {
if (compare_value(p1->body.value.type, a2, a1) < 0)
continue;
if (compare_value(p1->body.value.type, a2, a1 + p1->body.value.size)
> 0)
continue;
spa_pod_builder_raw(b, a2, p2->body.value.size);
n_copied++;
}
if (n_copied == 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
np->body.flags |= SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET;
}
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) {
if (compare_value (p1->body.value.type, alt1, alt2) < 0)
spa_pod_builder_raw (b, alt2, p2->body.value.size);
else
spa_pod_builder_raw (b, alt1, p1->body.value.size);
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_MIN_MAX) {
if (compare_value(p1->body.value.type, alt1, alt2) < 0)
spa_pod_builder_raw(b, alt2, p2->body.value.size);
else
spa_pod_builder_raw(b, alt1, p1->body.value.size);
alt1 += p1->body.value.size;
alt2 += p2->body.value.size;
alt1 += p1->body.value.size;
alt2 += p2->body.value.size;
if (compare_value (p1->body.value.type, alt1, alt2) < 0)
spa_pod_builder_raw (b, alt1, p1->body.value.size);
else
spa_pod_builder_raw (b, alt2, p2->body.value.size);
if (compare_value(p1->body.value.type, alt1, alt2) < 0)
spa_pod_builder_raw(b, alt1, p1->body.value.size);
else
spa_pod_builder_raw(b, alt2, p2->body.value.size);
np->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET;
}
np->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET;
}
if (rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_NONE && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_MIN_MAX && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_ENUM && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_NONE)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_NONE)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_ENUM)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_ENUM)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_STEP && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_NONE)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_ENUM)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_NONE)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_MIN_MAX)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_STEP)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_ENUM)
return SPA_RESULT_NOT_IMPLEMENTED;
if (rt1 == SPA_POD_PROP_RANGE_FLAGS && rt2 == SPA_POD_PROP_RANGE_FLAGS)
return SPA_RESULT_NOT_IMPLEMENTED;
spa_pod_builder_pop (b, &f);
fix_default (np);
}
return SPA_RESULT_OK;
spa_pod_builder_pop(b, &f);
fix_default(np);
}
return SPA_RESULT_OK;
}

View file

@ -26,16 +26,14 @@ extern "C" {
#include <spa/props.h>
int
spa_props_filter (struct spa_pod_builder *b,
const struct spa_pod *props,
uint32_t props_size,
const struct spa_pod *filter,
uint32_t filter_size);
int spa_props_filter(struct spa_pod_builder *b,
const struct spa_pod *props,
uint32_t props_size,
const struct spa_pod *filter,
uint32_t filter_size);
#ifdef __cplusplus
} /* extern "C" */
} /* extern "C" */
#endif
#endif /* __SPA_LIBPROPS_H__ */