2017-02-22 13:12:32 +01:00
|
|
|
/* Spa
|
|
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2017-02-22 13:12:32 +01:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2017-02-22 13:12:32 +01:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2017-02-22 13:12:32 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/support/log-impl.h>
|
|
|
|
|
#include <spa/pod/pod.h>
|
|
|
|
|
#include <spa/pod/builder.h>
|
|
|
|
|
#include <spa/pod/parser.h>
|
|
|
|
|
#include <spa/param/video/format.h>
|
2017-06-06 13:30:34 +02:00
|
|
|
|
2018-08-14 12:33:53 +02:00
|
|
|
#include <spa/debug/pod.h>
|
2018-08-23 17:47:57 +02:00
|
|
|
#include <spa/debug/types.h>
|
2017-02-22 13:12:32 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2017-02-22 13:12:32 +01:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_pod_builder b = { NULL, };
|
|
|
|
|
uint8_t buffer[1024];
|
2017-11-08 15:48:31 +01:00
|
|
|
uint32_t ref;
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_pod *obj;
|
2017-09-21 18:57:41 +02:00
|
|
|
struct spa_pod_parser prs;
|
2017-06-06 13:30:34 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
b.data = buffer;
|
|
|
|
|
b.size = 1024;
|
|
|
|
|
|
2017-11-08 15:48:31 +01:00
|
|
|
spa_pod_builder_push_object(&b, 0, 0);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
uint32_t formats[] = { 1, 2 };
|
2018-09-05 16:41:07 +02:00
|
|
|
spa_pod_builder_prop(&b, 1, 0);
|
|
|
|
|
spa_pod_builder_push_array(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_pod_builder_int(&b, 1);
|
|
|
|
|
spa_pod_builder_int(&b, formats[0]);
|
|
|
|
|
spa_pod_builder_int(&b, formats[1]);
|
2017-11-08 15:48:31 +01:00
|
|
|
spa_pod_builder_pop(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-09-05 16:41:07 +02:00
|
|
|
spa_pod_builder_prop(&b, 2, 0);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_pod_builder_int(&b, 42);
|
|
|
|
|
|
|
|
|
|
struct spa_rectangle sizes[] = { {0, 0}, {1024, 1024} };
|
2018-09-05 16:41:07 +02:00
|
|
|
spa_pod_builder_prop(&b, 3, 0);
|
|
|
|
|
spa_pod_builder_push_array(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_pod_builder_rectangle(&b, 320, 240);
|
|
|
|
|
spa_pod_builder_raw(&b, sizes, sizeof(sizes));
|
2017-11-08 15:48:31 +01:00
|
|
|
spa_pod_builder_pop(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-09-28 17:44:14 +02:00
|
|
|
spa_pod_builder_prop(&b, 4, 0);
|
2017-11-08 15:48:31 +01:00
|
|
|
ref = spa_pod_builder_push_struct(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_pod_builder_int(&b, 4);
|
|
|
|
|
spa_pod_builder_long(&b, 6000);
|
|
|
|
|
spa_pod_builder_float(&b, 4.0);
|
|
|
|
|
spa_pod_builder_double(&b, 3.14);
|
|
|
|
|
spa_pod_builder_string(&b, "test123");
|
|
|
|
|
spa_pod_builder_rectangle(&b, 320, 240);
|
|
|
|
|
spa_pod_builder_fraction(&b, 25, 1);
|
2017-11-08 15:48:31 +01:00
|
|
|
spa_pod_builder_push_array(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_pod_builder_int(&b, 4);
|
|
|
|
|
spa_pod_builder_int(&b, 5);
|
|
|
|
|
spa_pod_builder_int(&b, 6);
|
2017-11-08 15:48:31 +01:00
|
|
|
spa_pod_builder_pop(&b);
|
|
|
|
|
spa_pod_builder_pop(&b);
|
2017-11-13 11:50:50 +01:00
|
|
|
obj = spa_pod_builder_pop(&b);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-08-30 12:01:52 +02:00
|
|
|
spa_debug_pod(0, NULL, obj);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-13 17:57:38 +01:00
|
|
|
struct spa_pod_prop *p = spa_pod_find_prop(obj, 4);
|
2018-09-05 16:41:07 +02:00
|
|
|
spa_debug_pod(0, NULL, &p->value);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-08 15:48:31 +01:00
|
|
|
obj = spa_pod_builder_deref(&b, ref);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
int32_t vi, *pi;
|
|
|
|
|
int64_t vl;
|
|
|
|
|
float vf;
|
|
|
|
|
double vd;
|
|
|
|
|
char *vs;
|
|
|
|
|
struct spa_rectangle vr;
|
|
|
|
|
struct spa_fraction vfr;
|
|
|
|
|
struct spa_pod_array *va;
|
2017-09-21 18:57:41 +02:00
|
|
|
spa_pod_parser_pod(&prs, obj);
|
|
|
|
|
spa_pod_parser_get(&prs,
|
|
|
|
|
"["
|
|
|
|
|
"i", &vi,
|
|
|
|
|
"l", &vl,
|
|
|
|
|
"f", &vf,
|
|
|
|
|
"d", &vd,
|
|
|
|
|
"s", &vs,
|
|
|
|
|
"R", &vr,
|
|
|
|
|
"F", &vfr,
|
|
|
|
|
"P", &va, 0);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
printf("%u %lu %f %g %s %ux%u %u/%u\n", vi, vl, vf, vd, vs, vr.width, vr.height, vfr.num,
|
|
|
|
|
vfr.denom);
|
|
|
|
|
SPA_POD_ARRAY_BODY_FOREACH(&va->body, SPA_POD_BODY_SIZE(va), pi) {
|
|
|
|
|
printf("%d\n", *pi);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2017-02-22 13:12:32 +01:00
|
|
|
}
|