Unify props, params and formats

Make enum_params and set_param to configure properties, format
and other parameters. This allows us to remove some duplicate
code and make the properties and parameters much more extensible.
Use the object id to mark the id of the parameter.
Remove the spa_format and spa_props.
We can now make the client-node easier by merging the various
format methods into the params.
Make the stream API more powerful now that we can pass params
around.
This commit is contained in:
Wim Taymans 2017-11-07 17:39:31 +01:00
parent b6ee67905d
commit f3bca48398
87 changed files with 3773 additions and 3580 deletions

View file

@ -138,18 +138,6 @@ int spa_debug_dump_mem(const void *mem, size_t size)
return SPA_RESULT_OK;
}
int spa_debug_props(const struct spa_props *props)
{
spa_debug_pod(&props->object.pod);
return SPA_RESULT_OK;
}
int spa_debug_param(const struct spa_param *param)
{
spa_debug_pod(&param->object.pod);
return SPA_RESULT_OK;
}
static const char *pod_type_names[] = {
[SPA_POD_TYPE_INVALID] = "invalid",
[SPA_POD_TYPE_NONE] = "none",
@ -248,7 +236,8 @@ print_pod_value(uint32_t size, uint32_t type, void *body, int prefix)
struct spa_pod_object_body *b = body;
struct spa_pod *p;
printf("%-*sObject: size %d, id %d, type %s\n", prefix, "", size, b->id,
printf("%-*sObject: size %d, id %s, type %s\n", prefix, "", size,
map ? spa_type_map_get_type(map, b->id) : "*no map*",
map ? spa_type_map_get_type(map, b->type) : "*no map*");
SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
print_pod_value(p->size, p->type, SPA_POD_BODY(p), prefix + 2);
@ -292,12 +281,6 @@ print_pod_value(uint32_t size, uint32_t type, void *body, int prefix)
}
}
int spa_debug_pod(const struct spa_pod *pod)
{
print_pod_value(pod->size, pod->type, SPA_POD_BODY(pod), 0);
return SPA_RESULT_OK;
}
static void
print_format_value(uint32_t size, uint32_t type, void *body)
{
@ -356,19 +339,20 @@ print_format_value(uint32_t size, uint32_t type, void *body)
}
}
int spa_debug_format(const struct spa_format *format)
static int spa_debug_format(const struct spa_pod_object *format)
{
int i;
const char *media_type;
const char *media_subtype;
struct spa_pod_prop *prop;
struct spa_pod *pod;
uint32_t mtype, mstype;
if (format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
mtype = format->body.media_type.value;
mstype = format->body.media_subtype.value;
if (spa_pod_object_parse(format, "I", &mtype,
"I", &mstype) < 0)
return SPA_RESULT_INVALID_ARGUMENTS;
media_type = spa_type_map_get_type(map, mtype);
media_subtype = spa_type_map_get_type(map, mstype);
@ -376,9 +360,15 @@ int spa_debug_format(const struct spa_format *format)
fprintf(stderr, "%-6s %s/%s\n", "", rindex(media_type, ':') + 1,
rindex(media_subtype, ':') + 1);
SPA_FORMAT_FOREACH(format, prop) {
SPA_POD_OBJECT_FOREACH(format, pod) {
struct spa_pod_prop *prop;
const char *key;
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;
@ -428,6 +418,19 @@ int spa_debug_format(const struct spa_format *format)
return SPA_RESULT_OK;
}
int spa_debug_pod(const struct spa_pod *pod, uint32_t flags)
{
int res = SPA_RESULT_OK;
if (flags & SPA_DEBUG_FLAG_FORMAT)
res = spa_debug_format((struct spa_pod_object*)pod);
else
print_pod_value(pod->size, pod->type, SPA_POD_BODY(pod), 0);
return res;
}
int spa_debug_dict(const struct spa_dict *dict)
{
unsigned int i;

View file

@ -37,10 +37,8 @@ void spa_debug_set_type_map(const struct spa_type_map *map);
int spa_debug_port_info(const struct spa_port_info *info);
int spa_debug_buffer(const struct spa_buffer *buffer);
int spa_debug_props(const struct spa_props *props);
int spa_debug_param(const struct spa_param *param);
int spa_debug_pod(const struct spa_pod *pod);
int spa_debug_format(const struct spa_format *format);
#define SPA_DEBUG_FLAG_FORMAT (1 << 0)
int spa_debug_pod(const struct spa_pod *pod, uint32_t flags);
int spa_debug_dump_mem(const void *data, size_t size);
int spa_debug_dict(const struct spa_dict *dict);

View file

@ -22,57 +22,44 @@
#include <stdio.h>
#include <string.h>
#include <spa/format-builder.h>
#include <spa/video/format-utils.h>
#include <lib/props.h>
int
spa_format_filter(const struct spa_format *format,
const struct spa_format *filter,
struct spa_pod_builder *result)
spa_pod_object_filter(const struct spa_pod_object *obj,
struct spa_pod_object *filter,
struct spa_pod_builder *result)
{
struct spa_pod_frame f;
int res;
if (format == NULL || result == NULL)
if (obj == NULL || result == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (filter == NULL) {
spa_pod_builder_raw_padded(result, format, SPA_POD_SIZE(format));
spa_pod_builder_raw_padded(result, obj, SPA_POD_SIZE(obj));
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;
spa_pod_builder_push_format(result, &f, filter->body.obj_body.type,
SPA_FORMAT_MEDIA_TYPE(filter),
SPA_FORMAT_MEDIA_SUBTYPE(filter));
spa_pod_builder_push_object(result, &f, obj->body.id, obj->body.type);
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_CONTENTS(struct spa_pod_object, obj),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, obj),
SPA_POD_CONTENTS(struct spa_pod_object, filter),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, filter));
spa_pod_builder_pop(result, &f);
return res;
}
int
spa_format_compare(const struct spa_format *format1,
const struct spa_format *format2)
spa_pod_object_compare(const struct spa_pod_object *obj1,
const struct spa_pod_object *obj2)
{
if (format1 == NULL || format2 == NULL)
if (obj1 == NULL || obj2 == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (SPA_FORMAT_MEDIA_TYPE(format1) != SPA_FORMAT_MEDIA_TYPE(format2) ||
SPA_FORMAT_MEDIA_SUBTYPE(format1) != SPA_FORMAT_MEDIA_SUBTYPE(format2))
return SPA_RESULT_INVALID_MEDIA_TYPE;
return spa_props_compare(SPA_POD_CONTENTS(struct spa_format, format1),
SPA_POD_CONTENTS_SIZE(struct spa_format, format1),
SPA_POD_CONTENTS(struct spa_format, format2),
SPA_POD_CONTENTS_SIZE(struct spa_format, format2));
return spa_props_compare(SPA_POD_CONTENTS(struct spa_pod_object, obj1),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, obj1),
SPA_POD_CONTENTS(struct spa_pod_object, obj2),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, obj2));
}

View file

@ -26,12 +26,12 @@ extern "C" {
#include <spa/props.h>
int spa_format_filter(const struct spa_format *format,
const struct spa_format *filter,
struct spa_pod_builder *result);
int spa_pod_object_filter(const struct spa_pod_object *obj,
const struct spa_pod_object *filter,
struct spa_pod_builder *result);
int spa_format_compare(const struct spa_format *format1,
const struct spa_format *format2);
int spa_pod_object_compare(const struct spa_pod_object *obj1,
const struct spa_pod_object *obj2);
#ifdef __cplusplus
} /* extern "C" */

View file

@ -23,6 +23,7 @@
#include <string.h>
#include <spa/props.h>
#include <spa/pod-builder.h>
static int compare_value(enum spa_pod_type type, const void *r1, const void *r2)
{

View file

@ -25,6 +25,7 @@ extern "C" {
#endif
#include <spa/props.h>
#include <spa/pod-builder.h>
int spa_props_filter(struct spa_pod_builder *b,
const struct spa_pod *props,