tests: add static caps example

Add example of how to define a static caps.
This commit is contained in:
Wim Taymans 2017-02-24 18:46:30 +01:00
parent 825cbbbdd6
commit e79a294816
2 changed files with 60 additions and 87 deletions

View file

@ -60,6 +60,61 @@ spa_build (SPA_MEDIA_TYPE_VIDEO, SPA_MEDIA_SUBTYPE_RAW,
0);
#endif
static const struct _test_format {
SpaFormat fmt;
struct {
SpaPODProp prop_format;
struct {
uint32_t def_format;
uint32_t enum_format[2];
} format_vals;
uint32_t pad;
SpaPODProp prop_size;
struct {
SpaRectangle def_size;
SpaRectangle min_size;
SpaRectangle max_size;
} size_vals;
SpaPODProp prop_framerate;
struct {
SpaFraction def_framerate;
SpaFraction min_framerate;
SpaFraction max_framerate;
} framerate_vals;
} props;
} test_format = {
{ SPA_MEDIA_TYPE_VIDEO,
SPA_MEDIA_SUBTYPE_RAW,
{ { sizeof (test_format.props) + sizeof (SpaPODObjectBody), SPA_POD_TYPE_OBJECT },
{ 0, 0 } },
}, {
{ { sizeof (test_format.props.format_vals) + sizeof (SpaPODPropBody),
SPA_POD_TYPE_PROP } ,
{ SPA_PROP_ID_VIDEO_FORMAT, SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET,
{ sizeof (uint32_t), SPA_POD_TYPE_INT } }, },
{ SPA_VIDEO_FORMAT_I420,
{ SPA_VIDEO_FORMAT_I420, SPA_VIDEO_FORMAT_YUY2 } }, 0,
{ { sizeof (test_format.props.size_vals) + sizeof (SpaPODPropBody),
SPA_POD_TYPE_PROP } ,
{ SPA_PROP_ID_VIDEO_SIZE, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET,
{ sizeof (SpaRectangle), SPA_POD_TYPE_RECTANGLE } }, },
{ { 320, 240 },
{ 1, 1 },
{ INT32_MAX, INT32_MAX } },
{ { sizeof (test_format.props.framerate_vals) + sizeof (SpaPODPropBody),
SPA_POD_TYPE_PROP } ,
{ SPA_PROP_ID_VIDEO_FRAMERATE, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET,
{ sizeof (SpaFraction), SPA_POD_TYPE_FRACTION } }, },
{ { 25, 1 },
{ 0, 1 },
{ INT32_MAX, 1 } },
}
};
int
main (int argc, char *argv[])
@ -128,10 +183,12 @@ main (int argc, char *argv[])
INT32_MAX, 1,
0);
printf ("%zd\n", o);
fmt = SPA_MEMBER (buffer, o, SpaFormat);
printf ("%d %d\n", fmt->media_type, fmt->media_subtype);
spa_debug_pod (&fmt->obj.pod);
spa_debug_format (fmt);
spa_debug_pod (&test_format.fmt.obj.pod);
spa_debug_format (&test_format.fmt);
return 0;
}

View file

@ -33,90 +33,6 @@
#include <lib/debug.h>
#include <lib/mapper.h>
static void
print_value (uint32_t size, uint32_t type, void *body, int prefix, uint32_t flags)
{
switch (type) {
case SPA_POD_TYPE_BOOL:
printf ("%-*sBool %d\n", prefix, "", *(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 %g\n", prefix, "", *(double *) body);
break;
case SPA_POD_TYPE_STRING:
printf ("%-*sString %s\n", prefix, "", (char *) body);
break;
case SPA_POD_TYPE_RECTANGLE:
{
SpaRectangle *r = body;
printf ("%-*sRectangle %dx%d\n", prefix, "", r->width, r->height);
break;
}
case SPA_POD_TYPE_FRACTION:
{
SpaFraction *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:
{
SpaPODArrayBody *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_value (b->child.size, b->child.type, p, prefix + 2, flags);
break;
}
case SPA_POD_TYPE_STRUCT:
{
SpaPOD *b = body, *p;
printf ("%-*sStruct: size %d\n", prefix, "", size);
SPA_POD_STRUCT_BODY_FOREACH (b, size, p)
print_value (p->size, p->type, SPA_POD_BODY (p), prefix + 2, flags);
break;
}
case SPA_POD_TYPE_OBJECT:
{
SpaPODObjectBody *b = body;
SpaPODProp *p;
void *alt;
int i;
printf ("%-*sObject: size %d\n", prefix, "", size);
SPA_POD_OBJECT_BODY_FOREACH (b, size, p) {
printf ("%-*sProp: key %d, flags %d\n", prefix + 2, "", p->body.key, p->body.flags);
if (p->body.flags & SPA_POD_PROP_FLAG_UNSET)
printf ("%-*sUnset (Default):\n", prefix + 4, "");
else
printf ("%-*sValue:\n", prefix + 4, "");
print_value (p->body.value.size, p->body.value.type, SPA_POD_BODY (&p->body.value), prefix + 6, p->body.flags);
i = 0;
SPA_POD_PROP_ALTERNATIVE_FOREACH (&p->body, p->pod.size, alt) {
if (i == 0)
printf ("%-*sAlternatives:\n", prefix + 4, "");
print_value (p->body.value.size, p->body.value.type, alt, prefix + 6, p->body.flags);
i++;
}
}
break;
}
}
}
int
main (int argc, char *argv[])
{
@ -172,7 +88,7 @@ main (int argc, char *argv[])
SpaPODProp *p = spa_pod_object_body_find_prop (SPA_POD_BODY (obj), obj->size, 4);
printf ("%d %d\n", p->body.key, p->body.flags);
print_value (p->body.value.size, p->body.value.type, SPA_POD_BODY (&p->body.value), 0, 0);
spa_debug_pod (&p->body.value);
return 0;
}