mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
Add new pod parser and builder
Add a new pod builder and parser that is less verbose and a little more powerful.
This commit is contained in:
parent
3e49aec61b
commit
24d80e5c00
54 changed files with 3616 additions and 2817 deletions
|
|
@ -1,26 +1,32 @@
|
|||
executable('test-mixer', 'test-mixer.c',
|
||||
include_directories : [spa_inc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
executable('test-ringbuffer', 'test-ringbuffer.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
executable('test-graph', 'test-graph.c',
|
||||
include_directories : [spa_inc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
executable('test-graph2', 'test-graph2.c',
|
||||
include_directories : [spa_inc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
executable('test-perf', 'test-perf.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
executable('stress-ringbuffer', 'stress-ringbuffer.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
if sdl_dep.found()
|
||||
executable('test-v4l2', 'test-v4l2.c',
|
||||
|
|
@ -44,3 +50,13 @@ executable('test-props3', 'test-props3.c',
|
|||
dependencies : [],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
#executable('test-props4', 'test-props4.c',
|
||||
# include_directories : [spa_inc, spa_libinc ],
|
||||
# dependencies : [],
|
||||
# link_with : spalib,
|
||||
# install : false)
|
||||
executable('test-props5', 'test-props5.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@
|
|||
#include <spa/graph.h>
|
||||
#include <spa/graph-scheduler1.h>
|
||||
|
||||
#include <spa/lib/debug.h>
|
||||
|
||||
static SPA_TYPE_MAP_IMPL(default_map, 4096);
|
||||
static SPA_LOG_IMPL(default_log);
|
||||
|
||||
|
|
@ -281,7 +283,6 @@ static int make_nodes(struct data *data, const char *device)
|
|||
int res;
|
||||
struct spa_props *props;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[128];
|
||||
|
||||
if ((res = make_node(data, &data->sink,
|
||||
|
|
@ -292,12 +293,12 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_node_set_callbacks(data->sink, &sink_callbacks, data);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_device, 0, SPA_POD_TYPE_STRING, 1,
|
||||
device ? device : "hw:0"),
|
||||
SPA_POD_PROP(&f[1], data->type.props_min_latency, 0, SPA_POD_TYPE_INT, 1,
|
||||
MIN_LATENCY));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_device, "s", device ? device : "hw:0",
|
||||
":", data->type.props_min_latency, "i", MIN_LATENCY);
|
||||
|
||||
spa_debug_pod(&props->object.pod);
|
||||
|
||||
if ((res = spa_node_set_props(data->sink, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -316,14 +317,11 @@ static int make_nodes(struct data *data, const char *device)
|
|||
}
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_freq, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
600.0),
|
||||
SPA_POD_PROP(&f[1], data->type.props_volume, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
0.5),
|
||||
SPA_POD_PROP(&f[1], data->type.props_live, 0, SPA_POD_TYPE_BOOL, 1,
|
||||
false));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_freq, "d", 600.0,
|
||||
":", data->type.props_volume, "d", 0.5,
|
||||
":", data->type.props_live, "b", false);
|
||||
|
||||
if ((res = spa_node_set_props(data->source, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -370,22 +368,16 @@ static int negotiate_formats(struct data *data)
|
|||
struct spa_format *format, *filter;
|
||||
uint32_t state = 0;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_format(&b, &f[0], data->type.format,
|
||||
data->type.media_type.audio,
|
||||
data->type.media_subtype.raw,
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.format, 0, SPA_POD_TYPE_ID, 1,
|
||||
data->type.audio_format.S16),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.layout, 0, SPA_POD_TYPE_INT, 1,
|
||||
SPA_AUDIO_LAYOUT_INTERLEAVED),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.rate, 0, SPA_POD_TYPE_INT, 1,
|
||||
44100),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.channels, 0, SPA_POD_TYPE_INT, 1,
|
||||
2));
|
||||
filter = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
|
||||
filter = spa_pod_builder_format(&b,
|
||||
data->type.format,
|
||||
data->type.media_type.audio, data->type.media_subtype.raw,
|
||||
":", data->type.format_audio.format, "I", data->type.audio_format.S16,
|
||||
":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", data->type.format_audio.rate, "i", 44100,
|
||||
":", data->type.format_audio.channels, "i", 2);
|
||||
|
||||
if ((res =
|
||||
spa_node_port_enum_formats(data->sink, SPA_DIRECTION_INPUT, 0, &format, filter,
|
||||
|
|
@ -527,7 +519,6 @@ int main(int argc, char *argv[])
|
|||
int res;
|
||||
const char *str;
|
||||
|
||||
|
||||
spa_graph_init(&data.graph);
|
||||
spa_graph_data_init(&data.graph_data, &data.graph);
|
||||
spa_graph_set_callbacks(&data.graph, &spa_graph_impl_default, &data.graph_data);
|
||||
|
|
@ -540,6 +531,8 @@ int main(int argc, char *argv[])
|
|||
data.data_loop.remove_source = do_remove_source;
|
||||
data.data_loop.invoke = do_invoke;
|
||||
|
||||
spa_debug_set_type_map(data.map);
|
||||
|
||||
if ((str = getenv("SPA_DEBUG")))
|
||||
data.log->level = atoi(str);
|
||||
|
||||
|
|
|
|||
|
|
@ -325,7 +325,6 @@ static int make_nodes(struct data *data, const char *device)
|
|||
int res;
|
||||
struct spa_props *props;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[128];
|
||||
|
||||
if ((res = make_node(data, &data->sink,
|
||||
|
|
@ -336,12 +335,10 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_node_set_callbacks(data->sink, &sink_callbacks, data);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_device, 0, SPA_POD_TYPE_STRING, 1,
|
||||
device ? device : "hw:0"),
|
||||
SPA_POD_PROP(&f[1], data->type.props_min_latency, 0, SPA_POD_TYPE_INT, 1,
|
||||
MIN_LATENCY));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_device, "s", device ? device : "hw:0",
|
||||
":", data->type.props_min_latency, "i", MIN_LATENCY);
|
||||
|
||||
if ((res = spa_node_set_props(data->sink, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -361,14 +358,11 @@ static int make_nodes(struct data *data, const char *device)
|
|||
}
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_freq, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
600.0),
|
||||
SPA_POD_PROP(&f[1], data->type.props_volume, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
0.5),
|
||||
SPA_POD_PROP(&f[1], data->type.props_live, 0, SPA_POD_TYPE_BOOL, 1,
|
||||
false));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_freq, "d", 600.0,
|
||||
":", data->type.props_volume, "d", 0.5,
|
||||
":", data->type.props_live, "b", false);
|
||||
|
||||
if ((res = spa_node_set_props(data->source1, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -381,14 +375,11 @@ static int make_nodes(struct data *data, const char *device)
|
|||
}
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_freq, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
440.0),
|
||||
SPA_POD_PROP(&f[1], data->type.props_volume, 0, SPA_POD_TYPE_DOUBLE, 1,
|
||||
0.5),
|
||||
SPA_POD_PROP(&f[1], data->type.props_live, 0, SPA_POD_TYPE_BOOL, 1,
|
||||
false));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_freq, "d", 440.0,
|
||||
":", data->type.props_volume, "d", 0.5,
|
||||
":", data->type.props_live, "b", false);
|
||||
|
||||
if ((res = spa_node_set_props(data->source2, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -459,22 +450,16 @@ static int negotiate_formats(struct data *data)
|
|||
struct spa_format *format, *filter;
|
||||
uint32_t state = 0;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_format(&b, &f[0], data->type.format,
|
||||
data->type.media_type.audio,
|
||||
data->type.media_subtype.raw,
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.format, 0, SPA_POD_TYPE_ID, 1,
|
||||
data->type.audio_format.S16),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.layout, 0, SPA_POD_TYPE_INT, 1,
|
||||
SPA_AUDIO_LAYOUT_INTERLEAVED),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.rate, 0, SPA_POD_TYPE_INT, 1,
|
||||
44100),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.channels, 0, SPA_POD_TYPE_INT, 1,
|
||||
2));
|
||||
filter = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
|
||||
filter = spa_pod_builder_format(&b,
|
||||
data->type.format,
|
||||
data->type.media_type.audio, data->type.media_subtype.raw,
|
||||
":", data->type.format_audio.format, "I", data->type.audio_format.S16,
|
||||
":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", data->type.format_audio.rate, "i", 44100,
|
||||
":", data->type.format_audio.channels, "i", 2);
|
||||
|
||||
if ((res =
|
||||
spa_node_port_enum_formats(data->sink, SPA_DIRECTION_INPUT, 0, &format, filter,
|
||||
|
|
|
|||
|
|
@ -387,13 +387,12 @@ static int negotiate_formats(struct data *data)
|
|||
int res;
|
||||
struct spa_format *format;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_format(&b, &f[0], data->type.format,
|
||||
data->type.media_type.binary, data->type.media_subtype.raw, 0);
|
||||
format = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
|
||||
format = spa_pod_builder_format(&b,
|
||||
data->type.format,
|
||||
data->type.media_type.binary, data->type.media_subtype.raw);
|
||||
|
||||
if ((res = spa_node_port_set_format(data->sink, SPA_DIRECTION_INPUT, 0, 0, format)) < 0)
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -230,8 +230,8 @@ static void do_static_struct(struct spa_type_map *map)
|
|||
sizeof(struct spa_rectangle), SPA_POD_TYPE_RECTANGLE),
|
||||
|
||||
{
|
||||
{ 320, 243},
|
||||
{ 1, 1}, { INT32_MAX, INT32_MAX}
|
||||
SPA_RECTANGLE(320,243),
|
||||
SPA_RECTANGLE(1,1), SPA_RECTANGLE(INT32_MAX, INT32_MAX)
|
||||
},
|
||||
SPA_POD_PROP_INIT(sizeof(test_format.props.framerate_vals) +
|
||||
sizeof(struct spa_pod_prop_body),
|
||||
|
|
@ -239,8 +239,8 @@ static void do_static_struct(struct spa_type_map *map)
|
|||
SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET,
|
||||
sizeof(struct spa_fraction), SPA_POD_TYPE_FRACTION),
|
||||
{
|
||||
{ 25, 1},
|
||||
{ 0, 1}, { INT32_MAX, 1}
|
||||
SPA_FRACTION(25,1),
|
||||
SPA_FRACTION(0,1), SPA_FRACTION(INT32_MAX,1)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -249,24 +249,23 @@ static void do_static_struct(struct spa_type_map *map)
|
|||
spa_debug_format(&test_format.fmt);
|
||||
|
||||
{
|
||||
uint32_t format = 0, match;
|
||||
struct spa_fraction frac = { 0, 0 };
|
||||
uint32_t format = -1;
|
||||
int res;
|
||||
struct spa_fraction frac = { -1, -1 };
|
||||
|
||||
match = spa_pod_contents_query(&test_format.fmt.pod, sizeof(struct spa_format),
|
||||
type.format_video.format, SPA_POD_TYPE_ID, &format,
|
||||
type.format_video.framerate, SPA_POD_TYPE_FRACTION,
|
||||
&frac, 0);
|
||||
res = spa_format_parse(&test_format.fmt,
|
||||
":",type.format_video.format, "I", &format,
|
||||
":",type.format_video.framerate, "F", &frac, NULL);
|
||||
|
||||
printf("%d %d %d %d\n", match, format, frac.num, frac.denom);
|
||||
printf("%d format %d num %d denom %d\n", res, format, frac.num, frac.denom);
|
||||
|
||||
spa_format_fixate(&test_format.fmt);
|
||||
|
||||
match = spa_pod_contents_query(&test_format.fmt.pod, sizeof(struct spa_format),
|
||||
type.format_video.format, SPA_POD_TYPE_ID, &format,
|
||||
type.format_video.framerate, SPA_POD_TYPE_FRACTION,
|
||||
&frac, 0);
|
||||
res = spa_format_parse(&test_format.fmt,
|
||||
":",type.format_video.format, "I", &format,
|
||||
":",type.format_video.framerate, "F", &frac, NULL);
|
||||
|
||||
printf("%d %d %d %d\n", match, format, frac.num, frac.denom);
|
||||
printf("%d format %d num %d denom %d\n", res, format, frac.num, frac.denom);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -274,7 +273,7 @@ static void do_static_struct(struct spa_type_map *map)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct spa_pod_builder b = { NULL, };
|
||||
struct spa_pod_frame frame[4];
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[1024];
|
||||
struct spa_format *fmt;
|
||||
struct spa_type_map *map = &default_map.map;
|
||||
|
|
@ -284,105 +283,82 @@ int main(int argc, char *argv[])
|
|||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
fmt = SPA_MEMBER(buffer, spa_pod_builder_push_format(&b, &frame[0], type.format,
|
||||
fmt = SPA_MEMBER(buffer, spa_pod_builder_push_format(&b, &f[0], type.format,
|
||||
type.media_type.video,
|
||||
type.media_subtype.raw),
|
||||
struct spa_format);
|
||||
spa_pod_builder_push_prop(&b, &frame[1], type.format_video.format,
|
||||
spa_pod_builder_push_prop(&b, &f[1], type.format_video.format,
|
||||
SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET);
|
||||
spa_pod_builder_id(&b, type.video_format.I420);
|
||||
spa_pod_builder_id(&b, type.video_format.I420);
|
||||
spa_pod_builder_id(&b, type.video_format.YUY2);
|
||||
spa_pod_builder_pop(&b, &frame[1]);
|
||||
spa_pod_builder_pop(&b, &f[1]);
|
||||
|
||||
struct spa_rectangle size_min_max[] = { {1, 1}, {INT32_MAX, INT32_MAX} };
|
||||
spa_pod_builder_push_prop(&b, &frame[1],
|
||||
spa_pod_builder_push_prop(&b, &f[1],
|
||||
type.format_video.size,
|
||||
SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET);
|
||||
spa_pod_builder_rectangle(&b, 320, 240);
|
||||
spa_pod_builder_raw(&b, size_min_max, sizeof(size_min_max));
|
||||
spa_pod_builder_pop(&b, &frame[1]);
|
||||
spa_pod_builder_pop(&b, &f[1]);
|
||||
|
||||
struct spa_fraction rate_min_max[] = { {0, 1}, {INT32_MAX, 1} };
|
||||
spa_pod_builder_push_prop(&b, &frame[1],
|
||||
spa_pod_builder_push_prop(&b, &f[1],
|
||||
type.format_video.framerate,
|
||||
SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET);
|
||||
spa_pod_builder_fraction(&b, 25, 1);
|
||||
spa_pod_builder_raw(&b, rate_min_max, sizeof(rate_min_max));
|
||||
spa_pod_builder_pop(&b, &frame[1]);
|
||||
spa_pod_builder_pop(&b, &f[1]);
|
||||
|
||||
spa_pod_builder_pop(&b, &frame[0]);
|
||||
spa_pod_builder_pop(&b, &f[0]);
|
||||
|
||||
spa_debug_pod(&fmt->pod);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
spa_pod_builder_format(&b, &frame[0], type.format,
|
||||
type.media_type.video,
|
||||
type.media_subtype.raw,
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.format,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_ENUM,
|
||||
SPA_POD_TYPE_ID, 3,
|
||||
type.video_format.I420,
|
||||
type.video_format.I420,
|
||||
type.video_format.YUY2,
|
||||
-SPA_POD_TYPE_PROP, &frame[1],
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.size,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
SPA_POD_TYPE_RECTANGLE, 3,
|
||||
320, 241,
|
||||
1, 1,
|
||||
INT32_MAX, INT32_MAX,
|
||||
-SPA_POD_TYPE_PROP, &frame[1],
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.framerate,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
SPA_POD_TYPE_FRACTION, 3,
|
||||
25, 1,
|
||||
0, 1,
|
||||
INT32_MAX, 1,
|
||||
-SPA_POD_TYPE_PROP, &frame[1]);
|
||||
fmt = spa_pod_builder_format(&b,
|
||||
type.format,
|
||||
type.media_type.video, type.media_subtype.raw,
|
||||
":", type.format_video.format, "Ieu", type.video_format.I420,
|
||||
2, type.video_format.I420,
|
||||
type.video_format.YUY2,
|
||||
":", type.format_video.size, "Rru", &SPA_RECTANGLE(320,241),
|
||||
2, &SPA_RECTANGLE(1,1),
|
||||
&SPA_RECTANGLE(INT32_MAX,INT32_MAX),
|
||||
":", type.format_video.framerate, "Fru", &SPA_FRACTION(25,1),
|
||||
2, &SPA_FRACTION(0,1),
|
||||
&SPA_FRACTION(INT32_MAX,1));
|
||||
|
||||
fmt = SPA_MEMBER(buffer, frame[0].ref, struct spa_format);
|
||||
spa_debug_pod(&fmt->pod);
|
||||
spa_debug_format(fmt);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
spa_pod_builder_add(&b,
|
||||
SPA_POD_TYPE_OBJECT, &frame[0], 0, type.format,
|
||||
SPA_POD_TYPE_ID, type.media_type.video,
|
||||
SPA_POD_TYPE_ID, type.media_subtype.raw,
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.format,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_ENUM,
|
||||
SPA_POD_TYPE_ID, 3,
|
||||
type.video_format.I420,
|
||||
type.video_format.I420,
|
||||
type.video_format.YUY2,
|
||||
-SPA_POD_TYPE_PROP, &frame[1],
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.size,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
SPA_POD_TYPE_RECTANGLE, 3,
|
||||
320, 242,
|
||||
1, 1,
|
||||
INT32_MAX, INT32_MAX,
|
||||
-SPA_POD_TYPE_PROP, &frame[1],
|
||||
SPA_POD_TYPE_PROP, &frame[1],
|
||||
type.format_video.framerate,
|
||||
SPA_POD_PROP_FLAG_UNSET | SPA_POD_PROP_RANGE_MIN_MAX,
|
||||
SPA_POD_TYPE_FRACTION, 3,
|
||||
25, 1,
|
||||
0, 1,
|
||||
INT32_MAX, 1,
|
||||
-SPA_POD_TYPE_PROP, &frame[1],
|
||||
-SPA_POD_TYPE_OBJECT, &frame[0],
|
||||
0);
|
||||
/*
|
||||
* ( "Format",
|
||||
* ("video", "raw" ),
|
||||
* {
|
||||
* "format": ( "seu", "I420", ( "I420","YUY2" ) ),
|
||||
* "size": ( "Rru", (320, 242), ( (1,1), (MAX, MAX)) ),
|
||||
* "framerate": ( "Fru", (25, 1), ( (0,1), (MAX, 1)) )
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
fmt = spa_pod_builder_add(&b,
|
||||
"<", 0, type.format,
|
||||
"I", type.media_type.video,
|
||||
"I", type.media_subtype.raw,
|
||||
":", type.format_video.format, "Ieu", type.video_format.I420,
|
||||
2, type.video_format.I420,
|
||||
type.video_format.YUY2,
|
||||
":", type.format_video.size, "Rru", &SPA_RECTANGLE(320,242),
|
||||
2, &SPA_RECTANGLE(1,1),
|
||||
&SPA_RECTANGLE(INT32_MAX,INT32_MAX),
|
||||
":", type.format_video.framerate, "Fru", &SPA_FRACTION(25,1),
|
||||
2, &SPA_FRACTION(0,1),
|
||||
&SPA_FRACTION(INT32_MAX,1),
|
||||
">", NULL);
|
||||
|
||||
fmt = SPA_MEMBER(buffer, frame[0].ref, struct spa_format);
|
||||
spa_debug_pod(&fmt->pod);
|
||||
spa_debug_format(fmt);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <spa/pod.h>
|
||||
#include <spa/pod-builder.h>
|
||||
#include <spa/pod-iter.h>
|
||||
#include <spa/pod-parser.h>
|
||||
|
||||
#include <spa/type-map-impl.h>
|
||||
#include <spa/log-impl.h>
|
||||
|
|
@ -42,7 +42,7 @@ int main(int argc, char *argv[])
|
|||
struct spa_pod_frame frame[4];
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod *obj;
|
||||
struct spa_pod_iter i;
|
||||
struct spa_pod_parser prs;
|
||||
struct spa_type_map *map = &default_map.map;
|
||||
|
||||
spa_debug_set_type_map(map);
|
||||
|
|
@ -105,14 +105,17 @@ int main(int argc, char *argv[])
|
|||
struct spa_rectangle vr;
|
||||
struct spa_fraction vfr;
|
||||
struct spa_pod_array *va;
|
||||
spa_pod_iter_pod(&i, obj);
|
||||
spa_pod_iter_get(&i, SPA_POD_TYPE_INT, &vi,
|
||||
SPA_POD_TYPE_LONG, &vl,
|
||||
SPA_POD_TYPE_FLOAT, &vf,
|
||||
SPA_POD_TYPE_DOUBLE, &vd,
|
||||
SPA_POD_TYPE_STRING, &vs,
|
||||
SPA_POD_TYPE_RECTANGLE, &vr,
|
||||
SPA_POD_TYPE_FRACTION, &vfr, SPA_POD_TYPE_ARRAY, &va, 0);
|
||||
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);
|
||||
|
||||
printf("%u %lu %f %g %s %ux%u %u/%u\n", vi, vl, vf, vd, vs, vr.width, vr.height, vfr.num,
|
||||
vfr.denom);
|
||||
|
|
|
|||
|
|
@ -22,558 +22,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <spa/type-map.h>
|
||||
#include <spa/type-map-impl.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/video/format-utils.h>
|
||||
#include <spa/format-builder.h>
|
||||
|
||||
#include <lib/debug.h>
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* JSON based format description
|
||||
|
||||
[ <type>,
|
||||
[ <media-type>, <media-subtype> ],
|
||||
{
|
||||
<key> : <property>,
|
||||
...
|
||||
}
|
||||
]
|
||||
|
||||
<property> = [ <flags>, <default>, [ <alternatives>,... ]]
|
||||
| <value>
|
||||
|
||||
|
||||
<flags> = "123.."
|
||||
|
||||
1: s = string : "value"
|
||||
i = int : <number>
|
||||
l = long : <number>
|
||||
f = float : <float>
|
||||
d = double : <double>
|
||||
b = bool : true | false
|
||||
R = rectangle : [ <width>, <height> ]
|
||||
F = fraction : [ <num>, <denom> ]
|
||||
|
||||
2: - = default (only default value present)
|
||||
e = enum : [ <value>, ... ]
|
||||
f = flags : [ <number> ]
|
||||
r = min/max : [ <min>, <max> ]
|
||||
s = min/max/step : [ <min>, <max>, <step> ]
|
||||
|
||||
3: u = unset : value is unset, choose from options or default
|
||||
o = optional : value does not need to be set
|
||||
r = readonly : value is read only
|
||||
d = deprecated : value is deprecated
|
||||
|
||||
[ "Format",
|
||||
[ "video", "raw"],
|
||||
{
|
||||
"format" : [ "se", "I420", [ "I420", "YUY2" ] ],
|
||||
"size" : [ "Rru", [320, 240], [[ 640, 480], [1024,786]]],
|
||||
"framerate" : [ "Fsu", [25, 1], [[ 0, 1], [65536,1]]]"
|
||||
}
|
||||
]
|
||||
|
||||
[ "Format",
|
||||
[ "audio", "raw"],
|
||||
{
|
||||
"format" : [ "se", "S16LE", [ "F32LE", "S16LE" ] ],
|
||||
"rate" : [ "iru", 44100, [8000, 96000]],
|
||||
"channels" : [ "iru", 1, [1, 4096]]"
|
||||
"interleaved" : [ "beo", true ]"
|
||||
}
|
||||
]
|
||||
*/
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define STRUCT 0
|
||||
#define BARE 1
|
||||
#define STRING 2
|
||||
#define UTF8 3
|
||||
#define ESC 4
|
||||
|
||||
struct spa_json_iter {
|
||||
const char *start;
|
||||
const char *cur;
|
||||
const char *end;
|
||||
int state;
|
||||
int depth;
|
||||
};
|
||||
|
||||
struct spa_json_chunk {
|
||||
const char *value;
|
||||
int len;
|
||||
};
|
||||
|
||||
static inline int
|
||||
spa_json_chunk_extract(struct spa_json_chunk *chunk, const char *template, ...);
|
||||
|
||||
enum spa_json_type {
|
||||
SPA_JSON_TYPE_ANY = '-',
|
||||
SPA_JSON_TYPE_CHUNK = 'c',
|
||||
SPA_JSON_TYPE_INT = 'i',
|
||||
SPA_JSON_TYPE_LONG = 'l',
|
||||
SPA_JSON_TYPE_FLOAT = 'f',
|
||||
SPA_JSON_TYPE_DOUBLE = 'd',
|
||||
SPA_JSON_TYPE_STRING = 's',
|
||||
SPA_JSON_TYPE_BOOL = 'b',
|
||||
SPA_JSON_TYPE_RECTANGLE = 'R',
|
||||
SPA_JSON_TYPE_FRACTION = 'F',
|
||||
SPA_JSON_TYPE_OBJECT = 'o',
|
||||
SPA_JSON_TYPE_ARRAY = 'a'
|
||||
};
|
||||
|
||||
static inline bool spa_json_chunk_is_type(struct spa_json_chunk *chunk,
|
||||
enum spa_json_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_JSON_TYPE_ANY:
|
||||
case SPA_JSON_TYPE_CHUNK:
|
||||
return true;
|
||||
case SPA_JSON_TYPE_INT:
|
||||
case SPA_JSON_TYPE_LONG:
|
||||
case SPA_JSON_TYPE_FLOAT:
|
||||
case SPA_JSON_TYPE_DOUBLE:
|
||||
return (chunk->value[0] >= '0' && chunk->value[0] <= '9') ||
|
||||
chunk->value[0] == '-' ;
|
||||
case SPA_JSON_TYPE_STRING:
|
||||
return chunk->value[0] == '\"';
|
||||
case SPA_JSON_TYPE_BOOL:
|
||||
return chunk->value[0] == 't' || chunk->value[0] == 'f';
|
||||
case SPA_JSON_TYPE_RECTANGLE:
|
||||
case SPA_JSON_TYPE_FRACTION:
|
||||
case SPA_JSON_TYPE_ARRAY:
|
||||
return chunk->value[0] == '[';
|
||||
case SPA_JSON_TYPE_OBJECT:
|
||||
return chunk->value[0] == '{';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline int spa_json_chunk_to_int(struct spa_json_chunk *chunk) {
|
||||
return atoi(chunk->value);
|
||||
}
|
||||
static inline int64_t spa_json_chunk_to_long(struct spa_json_chunk *chunk) {
|
||||
return atol(chunk->value);
|
||||
}
|
||||
static inline int64_t spa_json_chunk_to_float(struct spa_json_chunk *chunk) {
|
||||
return strtof(chunk->value, NULL);
|
||||
}
|
||||
static inline int64_t spa_json_chunk_to_double(struct spa_json_chunk *chunk) {
|
||||
return strtod(chunk->value, NULL);
|
||||
}
|
||||
static inline bool spa_json_chunk_to_bool(struct spa_json_chunk *chunk) {
|
||||
return chunk->value[0] == 't';
|
||||
}
|
||||
static inline int spa_json_chunk_to_rectangle(struct spa_json_chunk *chunk,
|
||||
struct spa_rectangle *rect) {
|
||||
return spa_json_chunk_extract(chunk, "[ #pi, #pi ]", &rect->width, &rect->height);
|
||||
}
|
||||
static inline int spa_json_chunk_to_fraction(struct spa_json_chunk *chunk,
|
||||
struct spa_fraction *frac) {
|
||||
return spa_json_chunk_extract(chunk, "[ #pi, #pi ]", &frac->num, &frac->denom);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_json_iter_init (struct spa_json_iter *iter, const char *data, size_t size)
|
||||
{
|
||||
iter->start = iter->cur = data;
|
||||
iter->end = size == -1 ? NULL : data + size;
|
||||
iter->state = STRUCT;
|
||||
iter->depth = 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_json_iter_chunk(struct spa_json_iter *iter, struct spa_json_chunk *chunk)
|
||||
{
|
||||
if (!spa_json_chunk_is_type(chunk, SPA_JSON_TYPE_OBJECT) &&
|
||||
!spa_json_chunk_is_type(chunk, SPA_JSON_TYPE_ARRAY))
|
||||
return false;
|
||||
|
||||
spa_json_iter_init (iter, chunk->value, -1);
|
||||
iter->cur++;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_json_iter_next_chunk(struct spa_json_iter *iter, struct spa_json_chunk *chunk)
|
||||
{
|
||||
int utf8_remain = 0;
|
||||
|
||||
for (;iter->end == NULL || iter->cur < iter->end; iter->cur++) {
|
||||
unsigned char cur = (unsigned char) *iter->cur;
|
||||
again:
|
||||
switch (iter->state) {
|
||||
case STRUCT:
|
||||
switch (cur) {
|
||||
case '\t': case ' ': case '\r': case '\n': case ':': case ',':
|
||||
continue;
|
||||
case '"':
|
||||
chunk->value = iter->cur;
|
||||
iter->state = STRING;
|
||||
continue;
|
||||
case '[': case '{':
|
||||
chunk->value = iter->cur;
|
||||
if (++iter->depth > 1)
|
||||
continue;
|
||||
iter->cur++;
|
||||
return chunk->len = 1;
|
||||
case '}': case ']':
|
||||
if (iter->depth == 0)
|
||||
return 0;
|
||||
--iter->depth;
|
||||
continue;
|
||||
case '-': case 'a' ... 'z': case 'A' ... 'Z': case '0' ... '9': case '#':
|
||||
chunk->value = iter->cur;
|
||||
iter->state = BARE;
|
||||
continue;
|
||||
case '\0':
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
case BARE:
|
||||
switch (cur) {
|
||||
case '\t': case ' ': case '\r': case '\n': case ':': case ',':
|
||||
case ']': case '}':
|
||||
iter->state = STRUCT;
|
||||
if (iter->depth > 0)
|
||||
goto again;
|
||||
return chunk->len = iter->cur - chunk->value;
|
||||
default:
|
||||
if (cur >= 32 && cur <= 126)
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
case STRING:
|
||||
switch (cur) {
|
||||
case '\\':
|
||||
iter->state = ESC;
|
||||
continue;
|
||||
case '"':
|
||||
iter->state = STRUCT;
|
||||
if (iter->depth > 0)
|
||||
continue;
|
||||
iter->cur++;
|
||||
return chunk->len = iter->cur - chunk->value;
|
||||
case 240 ... 247:
|
||||
utf8_remain++;
|
||||
case 224 ... 239:
|
||||
utf8_remain++;
|
||||
case 192 ... 223:
|
||||
utf8_remain++;
|
||||
iter->state = UTF8;
|
||||
continue;
|
||||
default:
|
||||
if (cur >= 32 && cur <= 126)
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
case UTF8:
|
||||
switch (cur) {
|
||||
case 128 ... 191:
|
||||
if (--utf8_remain == 0)
|
||||
iter->state = STRING;
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
case ESC:
|
||||
switch (cur) {
|
||||
case '"': case '\\': case '/': case 'b': case 'f': case 'n': case 'r':
|
||||
case 't': case 'u':
|
||||
iter->state = STRING;
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return iter->depth == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_json_chunk_print(struct spa_json_chunk *chunk, int prefix)
|
||||
{
|
||||
struct spa_json_iter iter;
|
||||
if (spa_json_iter_chunk(&iter, chunk)) {
|
||||
struct spa_json_chunk chunk2 = { NULL, };
|
||||
|
||||
printf ("%-*s%c\n", prefix, "", chunk->value[0]);
|
||||
while (spa_json_iter_next_chunk(&iter, &chunk2) > 0)
|
||||
spa_json_chunk_print(&chunk2, prefix + 2);
|
||||
printf ("%-*s%c\n", prefix, "", iter.cur[0]);
|
||||
} else {
|
||||
printf ("%-*s%.*s\n", prefix, "", chunk->len, chunk->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline int spa_json_iter_find_key(struct spa_json_iter *iter, const char *key)
|
||||
{
|
||||
struct spa_json_chunk ch = { NULL, };
|
||||
int res;
|
||||
|
||||
iter->cur = iter->start + 1;
|
||||
iter->depth = 0;
|
||||
iter->state = STRUCT;
|
||||
|
||||
while (true) {
|
||||
/* read key */
|
||||
if ((res = spa_json_iter_next_chunk(iter, &ch)) <= 0)
|
||||
return res;
|
||||
|
||||
if (spa_json_chunk_is_type(&ch, SPA_JSON_TYPE_STRING) &&
|
||||
strncmp(key, ch.value, ch.len) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum spa_json_prop_range {
|
||||
SPA_JSON_PROP_RANGE_NONE = '-',
|
||||
SPA_JSON_PROP_RANGE_MIN_MAX = 'r',
|
||||
SPA_JSON_PROP_RANGE_STEP = 's',
|
||||
SPA_JSON_PROP_RANGE_ENUM = 'e',
|
||||
SPA_JSON_PROP_RANGE_FLAGS = 'f'
|
||||
};
|
||||
|
||||
enum spa_json_prop_flags {
|
||||
SPA_JSON_PROP_FLAG_UNSET = (1 << 0),
|
||||
SPA_JSON_PROP_FLAG_OPTIONAL = (1 << 1),
|
||||
SPA_JSON_PROP_FLAG_READONLY = (1 << 2),
|
||||
SPA_JSON_PROP_FLAG_DEPRECATED = (1 << 3),
|
||||
};
|
||||
|
||||
struct spa_json_prop {
|
||||
enum spa_json_type type;
|
||||
enum spa_json_prop_range range;
|
||||
enum spa_json_prop_flags flags;
|
||||
struct spa_json_chunk value;
|
||||
struct spa_json_chunk alternatives;
|
||||
};
|
||||
|
||||
static inline int
|
||||
spa_json_chunk_parse_prop(struct spa_json_chunk *chunk, char type,
|
||||
struct spa_json_prop *prop)
|
||||
{
|
||||
if (spa_json_chunk_is_type(chunk, SPA_JSON_TYPE_ARRAY)) {
|
||||
struct spa_json_chunk flags;
|
||||
int res;
|
||||
char ch;
|
||||
|
||||
/* [<flags>, <default>, [<alternatives>,...]] */
|
||||
if ((res = spa_json_chunk_extract(chunk,
|
||||
"[ #&cs, #&c-, #&ca ]",
|
||||
&flags, &prop->value, &prop->alternatives)) < 3) {
|
||||
printf("can't parse prop chunk %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* skip \" */
|
||||
flags.value++;
|
||||
prop->type = *flags.value++;
|
||||
if (type != SPA_JSON_TYPE_ANY && type != SPA_JSON_TYPE_CHUNK && prop->type != type) {
|
||||
printf("prop chunk of wrong type %d %d\n", prop->type, type);
|
||||
return -1;
|
||||
}
|
||||
prop->range = *flags.value++;
|
||||
/* flags */
|
||||
prop->flags = 0;
|
||||
while ((ch = *flags.value++) != '\"') {
|
||||
switch (ch) {
|
||||
case 'u':
|
||||
prop->flags |= SPA_JSON_PROP_FLAG_UNSET;
|
||||
break;
|
||||
case 'o':
|
||||
prop->flags |= SPA_JSON_PROP_FLAG_OPTIONAL;
|
||||
break;
|
||||
case 'r':
|
||||
prop->flags |= SPA_JSON_PROP_FLAG_READONLY;
|
||||
break;
|
||||
case 'd':
|
||||
prop->flags |= SPA_JSON_PROP_FLAG_DEPRECATED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* <value> */
|
||||
prop->type = type;
|
||||
prop->range = SPA_JSON_PROP_RANGE_NONE;
|
||||
prop->flags = 0;
|
||||
prop->value = *chunk;
|
||||
prop->alternatives = *chunk;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* #[*]<asign>
|
||||
*
|
||||
* * = skip assignment
|
||||
* <asign> is:
|
||||
* &<type> -> pointer to type
|
||||
* p<type> -> property, fixed value store in pointer to type
|
||||
* P<type> -> property, stored in pointer to struct spa_json_prop
|
||||
*
|
||||
* <type>
|
||||
* - -> any
|
||||
* c<type> -> store as chunk if of type
|
||||
* s -> string
|
||||
* i -> int
|
||||
* l -> long
|
||||
* f -> float
|
||||
* d -> double
|
||||
* b -> bool
|
||||
* R -> rectangle
|
||||
* F -> fraction
|
||||
* a -> array
|
||||
* o -> object
|
||||
*/
|
||||
static inline int
|
||||
spa_json_chunk_extract(struct spa_json_chunk *chunk,
|
||||
const char *template, ...)
|
||||
{
|
||||
struct spa_json_iter templ[16], it[16];
|
||||
struct spa_json_chunk tch = { NULL, }, ch = { NULL, };
|
||||
struct spa_json_prop prop;
|
||||
const char *match;
|
||||
int collected = 0, res, level = 0;
|
||||
va_list args;
|
||||
bool store;
|
||||
|
||||
va_start(args, template);
|
||||
|
||||
spa_json_iter_init(&it[0], chunk->value, chunk->len);
|
||||
spa_json_iter_init (&templ[0], template, -1);
|
||||
|
||||
while (true) {
|
||||
res = spa_json_iter_next_chunk(&templ[level], &tch);
|
||||
if (res == 0) {
|
||||
if (--level == 0)
|
||||
break;
|
||||
continue;
|
||||
} else if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
switch (tch.value[0]) {
|
||||
case '[': case '{':
|
||||
if (spa_json_iter_next_chunk(&it[level], &ch) <= 0 ||
|
||||
ch.value[0] != tch.value[0])
|
||||
return -1;
|
||||
if (++level == 16)
|
||||
return -2;
|
||||
spa_json_iter_chunk(&it[level], &ch);
|
||||
spa_json_iter_chunk(&templ[level], &tch);
|
||||
break;
|
||||
case '"':
|
||||
case '-': case '0' ... '9':
|
||||
case 't': case 'f':
|
||||
case 'n':
|
||||
if (templ[level].start[0] == '{') {
|
||||
if (spa_json_iter_find_key(&it[level], tch.value) <= 0)
|
||||
continue;
|
||||
} else if (spa_json_iter_next_chunk(&it[level], &ch) <= 0 ||
|
||||
ch.len != tch.len ||
|
||||
strncmp(ch.value, tch.value, ch.len) != 0)
|
||||
return -1;
|
||||
break;
|
||||
case '#':
|
||||
match = tch.value + 1;
|
||||
if (spa_json_iter_next_chunk(&it[level], &ch) <= 0)
|
||||
return -1;
|
||||
|
||||
store = (match[0] != '*');
|
||||
if (!store)
|
||||
match++;
|
||||
|
||||
switch (match[0]) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
if (spa_json_chunk_parse_prop(&ch, match[1], &prop) < 0)
|
||||
goto skip;
|
||||
|
||||
if (match[0] == 'P') {
|
||||
if (store)
|
||||
*va_arg(args, struct spa_json_prop *) = prop;
|
||||
collected++;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (prop.flags & SPA_JSON_PROP_FLAG_UNSET)
|
||||
goto skip;
|
||||
|
||||
ch = prop.value;
|
||||
}
|
||||
/* fallthrough */
|
||||
case '&':
|
||||
if (!spa_json_chunk_is_type(&ch, match[1] == SPA_JSON_TYPE_CHUNK ?
|
||||
match[2] : match[1])) {
|
||||
skip:
|
||||
if (store)
|
||||
va_arg(args, void *);
|
||||
break;
|
||||
}
|
||||
if (!store)
|
||||
break;
|
||||
|
||||
collected++;
|
||||
|
||||
switch (match[1]) {
|
||||
case SPA_JSON_TYPE_CHUNK:
|
||||
*va_arg(args, struct spa_json_chunk *) = ch;
|
||||
break;
|
||||
case SPA_JSON_TYPE_INT:
|
||||
*va_arg(args, int *) = spa_json_chunk_to_int(&ch);
|
||||
break;
|
||||
case SPA_JSON_TYPE_LONG:
|
||||
*va_arg(args, int64_t *) = spa_json_chunk_to_long(&ch);
|
||||
break;
|
||||
case SPA_JSON_TYPE_FLOAT:
|
||||
*va_arg(args, float *) = spa_json_chunk_to_float(&ch);
|
||||
break;
|
||||
case SPA_JSON_TYPE_DOUBLE:
|
||||
*va_arg(args, double *) = spa_json_chunk_to_double(&ch);
|
||||
break;
|
||||
case SPA_JSON_TYPE_BOOL:
|
||||
*va_arg(args, bool *) = spa_json_chunk_to_bool(&ch);
|
||||
break;
|
||||
case SPA_JSON_TYPE_RECTANGLE:
|
||||
spa_json_chunk_to_rectangle(&ch,
|
||||
va_arg(args, struct spa_rectangle *));
|
||||
break;
|
||||
case SPA_JSON_TYPE_FRACTION:
|
||||
spa_json_chunk_to_fraction(&ch,
|
||||
va_arg(args, struct spa_fraction *));
|
||||
break;
|
||||
default:
|
||||
printf("ignoring invalid #p type %c\n", match[1]);
|
||||
va_arg(args, void *);
|
||||
collected--;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("ignoring unknown match type %c\n", *match);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("invalid char %c\n", tch.value[0]);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return collected;
|
||||
}
|
||||
#include <spa/json.h>
|
||||
#include <spa/json-builder.h>
|
||||
|
||||
static int
|
||||
spa_json_iter_array(struct spa_json_iter *iter,
|
||||
|
|
@ -749,7 +201,7 @@ static int test_extract3(const char *fmt)
|
|||
struct spa_json_chunk chunk;
|
||||
struct spa_json_chunk media_type;
|
||||
struct spa_json_chunk media_subtype;
|
||||
struct spa_json_chunk format;
|
||||
struct spa_json_chunk format = { "*unset*", 7 };
|
||||
int rate = -1, res;
|
||||
struct spa_json_prop channels;
|
||||
|
||||
|
|
@ -781,6 +233,35 @@ static int test_extract3(const char *fmt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int test_builder()
|
||||
{
|
||||
struct spa_json_builder builder = { NULL, 0, };
|
||||
int res;
|
||||
|
||||
again:
|
||||
res = spa_json_builder_printf(&builder,
|
||||
"[ \"Format\", "
|
||||
" [ \"audio\", \"raw\"], "
|
||||
" { "
|
||||
" \"format\": [ \"seu\", \"S16LE\", [ \"F32LE\", \"S16LE\" ]], "
|
||||
" \"rate\": %d, "
|
||||
" \"channels\": %d "
|
||||
" }"
|
||||
"]", 48000, 2);
|
||||
if (res < 0) {
|
||||
printf("needed %d bytes\n", builder.offset);
|
||||
builder.data = alloca(builder.offset);
|
||||
builder.size = builder.offset;
|
||||
builder.offset = 0;
|
||||
goto again;
|
||||
}
|
||||
printf("have %zd bytes\n", strlen(builder.data));
|
||||
|
||||
test_extract3(builder.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct spa_json_iter iter;
|
||||
|
|
@ -816,5 +297,7 @@ int main(int argc, char *argv[])
|
|||
" }"
|
||||
"]");
|
||||
|
||||
test_builder();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
861
spa/tests/test-props4.c
Normal file
861
spa/tests/test-props4.c
Normal file
|
|
@ -0,0 +1,861 @@
|
|||
/* Spa
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <lib/debug.h>
|
||||
#include <spa/pod-iter.h>
|
||||
|
||||
#if 0
|
||||
/*
|
||||
( "Format",
|
||||
( "video", "raw" ),
|
||||
{
|
||||
"format": ( "seu", "I420", ( "I420", "YUY2" ) ),
|
||||
"size": ( "Rru", R(320, 242), ( R(1,1), R(MAX, MAX)) ),
|
||||
"framerate": ( "Fru", F(25, 1), ( F(0,1), F(MAX, 1)) )
|
||||
}
|
||||
)
|
||||
|
||||
( struct
|
||||
{ object
|
||||
[ array
|
||||
|
||||
1: s = string : "value"
|
||||
i = int : <number>
|
||||
l = long : <number>
|
||||
f = float : <float>
|
||||
d = double : <float>
|
||||
b = bool : true | false
|
||||
R = rectangle : [ <width>, <height> ]
|
||||
F = fraction : [ <num>, <denom> ]
|
||||
|
||||
2: - = default (only default value present)
|
||||
e = enum : [ <value>, ... ]
|
||||
f = flags : [ <number> ]
|
||||
m = min/max : [ <min>, <max> ]
|
||||
s = min/max/step : [ <min>, <max>, <step> ]
|
||||
|
||||
3: u = unset : value is unset, choose from options or default
|
||||
o = optional : value does not need to be set
|
||||
r = readonly : value is read only
|
||||
d = deprecated : value is deprecated
|
||||
*/
|
||||
#endif
|
||||
|
||||
#define SPA_POD_MAX_LEVEL 16
|
||||
|
||||
struct spa_pod_maker {
|
||||
struct spa_pod_builder b;
|
||||
struct spa_pod_frame frame[SPA_POD_MAX_LEVEL];
|
||||
int depth;
|
||||
};
|
||||
|
||||
static inline void spa_pod_maker_init(struct spa_pod_maker *maker,
|
||||
char *data, int size)
|
||||
{
|
||||
spa_pod_builder_init(&maker->b, data, size);
|
||||
maker->depth = 0;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
char *pat;
|
||||
int len;
|
||||
int64_t val;
|
||||
} spa_constants[] = {
|
||||
{ "#I_MAX#", strlen("#I_MAX#"), INT32_MAX },
|
||||
{ "#I_MIN#", strlen("#I_MIN#"), INT32_MIN },
|
||||
{ "#L_MAX#", strlen("#L_MAX#"), INT64_MAX },
|
||||
{ "#L_MIN#", strlen("#L_MIN#"), INT64_MIN }
|
||||
};
|
||||
|
||||
static inline int64_t spa_parse_int(const char *str, char **endptr)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (*str != '#')
|
||||
return strtoll(str, endptr, 10);
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(spa_constants); i++) {
|
||||
if (strncmp(str, spa_constants[i].pat, spa_constants[i].len) == 0) {
|
||||
*endptr = (char *) (str + spa_constants[i].len);
|
||||
return spa_constants[i].val;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int spa_parse_string(const char *str, char **endptr)
|
||||
{
|
||||
int len;
|
||||
for (*endptr = (char *)str+1; **endptr != '\"' && **endptr != '\0'; (*endptr)++);
|
||||
len = (*endptr)++ - (str + 1);
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
spa_pod_maker_build(struct spa_pod_maker *maker,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
const char *start, *strval;
|
||||
int64_t intval;
|
||||
double doubleval;
|
||||
char last;
|
||||
struct spa_rectangle *rectval;
|
||||
struct spa_fraction *fracval;
|
||||
int len;
|
||||
|
||||
va_start(args, format);
|
||||
while (*format != '\0') {
|
||||
switch (*format) {
|
||||
case '[':
|
||||
spa_pod_builder_push_struct(&maker->b, &maker->frame[maker->depth++]);
|
||||
break;
|
||||
case '(':
|
||||
spa_pod_builder_push_array(&maker->b, &maker->frame[maker->depth++]);
|
||||
break;
|
||||
case '{':
|
||||
spa_pod_builder_push_map(&maker->b, &maker->frame[maker->depth++]);
|
||||
break;
|
||||
case ']': case '}': case ')':
|
||||
spa_pod_builder_pop(&maker->b, &maker->frame[--maker->depth]);
|
||||
break;
|
||||
case '\"':
|
||||
start = format + 1;
|
||||
if ((len = spa_parse_string(format, (char **) &format)) < 0)
|
||||
return NULL;
|
||||
format += strspn(format, " \t\r\n");
|
||||
if (*format == ':')
|
||||
spa_pod_builder_key_len(&maker->b, start, len);
|
||||
else
|
||||
spa_pod_builder_string_len(&maker->b, start, len);
|
||||
continue;
|
||||
case '@':
|
||||
case '%':
|
||||
last = *format;
|
||||
format++;
|
||||
switch (*format) {
|
||||
case 's':
|
||||
strval = va_arg(args, char *);
|
||||
spa_pod_builder_string_len(&maker->b, strval, strlen(strval));
|
||||
break;
|
||||
case 'i':
|
||||
spa_pod_builder_int(&maker->b, va_arg(args, int));
|
||||
break;
|
||||
case 'I':
|
||||
spa_pod_builder_id(&maker->b, va_arg(args, int));
|
||||
break;
|
||||
case 'l':
|
||||
spa_pod_builder_long(&maker->b, va_arg(args, int64_t));
|
||||
break;
|
||||
case 'f':
|
||||
spa_pod_builder_float(&maker->b, va_arg(args, double));
|
||||
break;
|
||||
case 'd':
|
||||
spa_pod_builder_double(&maker->b, va_arg(args, double));
|
||||
break;
|
||||
case 'b':
|
||||
spa_pod_builder_bool(&maker->b, va_arg(args, int));
|
||||
break;
|
||||
case 'z':
|
||||
{
|
||||
void *ptr = va_arg(args, void *);
|
||||
int len = va_arg(args, int);
|
||||
spa_pod_builder_bytes(&maker->b, ptr, len);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
spa_pod_builder_pointer(&maker->b, 0, va_arg(args, void *));
|
||||
break;
|
||||
case 'h':
|
||||
spa_pod_builder_fd(&maker->b, va_arg(args, int));
|
||||
break;
|
||||
case 'a':
|
||||
{
|
||||
int child_size = va_arg(args, int);
|
||||
int child_type = va_arg(args, int);
|
||||
int n_elems = va_arg(args, int);
|
||||
void *elems = va_arg(args, void *);
|
||||
spa_pod_builder_array(&maker->b, child_size, child_type, n_elems, elems);
|
||||
break;
|
||||
}
|
||||
case 'P':
|
||||
spa_pod_builder_primitive(&maker->b, va_arg(args, struct spa_pod *));
|
||||
break;
|
||||
case 'R':
|
||||
rectval = va_arg(args, struct spa_rectangle *);
|
||||
spa_pod_builder_rectangle(&maker->b, rectval->width, rectval->height);
|
||||
break;
|
||||
case 'F':
|
||||
fracval = va_arg(args, struct spa_fraction *);
|
||||
spa_pod_builder_fraction(&maker->b, fracval->num, fracval->denom);
|
||||
break;
|
||||
}
|
||||
if (last == '@') {
|
||||
format = va_arg(args, const char *);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '0' ... '9': case '-': case '+': case '#':
|
||||
start = format;
|
||||
intval = spa_parse_int(start, (char **) &format);
|
||||
if (*format == '.') {
|
||||
doubleval = strtod(start, (char **) &format);
|
||||
if (*format == 'f')
|
||||
spa_pod_builder_float(&maker->b, doubleval);
|
||||
else
|
||||
spa_pod_builder_double(&maker->b, doubleval);
|
||||
continue;
|
||||
}
|
||||
switch (*format) {
|
||||
case 'x':
|
||||
spa_pod_builder_rectangle(&maker->b, intval,
|
||||
spa_parse_int(format+1, (char **) &format));
|
||||
break;
|
||||
case '/':
|
||||
spa_pod_builder_fraction(&maker->b, intval,
|
||||
spa_parse_int(format+1, (char **) &format));
|
||||
break;
|
||||
case 'l':
|
||||
spa_pod_builder_long(&maker->b, intval);
|
||||
format++;
|
||||
break;
|
||||
default:
|
||||
spa_pod_builder_int(&maker->b, intval);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
format++;
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return SPA_POD_BUILDER_DEREF(&maker->b, maker->frame[maker->depth].ref, void);
|
||||
}
|
||||
|
||||
static inline int spa_pod_id_to_type(char id)
|
||||
{
|
||||
switch (id) {
|
||||
case 'n':
|
||||
return SPA_POD_TYPE_NONE;
|
||||
case 'b':
|
||||
return SPA_POD_TYPE_BOOL;
|
||||
case 'I':
|
||||
return SPA_POD_TYPE_ID;
|
||||
case 'i':
|
||||
return SPA_POD_TYPE_INT;
|
||||
case 'l':
|
||||
return SPA_POD_TYPE_LONG;
|
||||
case 'f':
|
||||
return SPA_POD_TYPE_FLOAT;
|
||||
case 'd':
|
||||
return SPA_POD_TYPE_DOUBLE;
|
||||
case 's':
|
||||
return SPA_POD_TYPE_STRING;
|
||||
case 'k':
|
||||
return SPA_POD_TYPE_KEY;
|
||||
case 'z':
|
||||
return SPA_POD_TYPE_BYTES;
|
||||
case 'R':
|
||||
return SPA_POD_TYPE_RECTANGLE;
|
||||
case 'F':
|
||||
return SPA_POD_TYPE_FRACTION;
|
||||
case 'B':
|
||||
return SPA_POD_TYPE_BITMASK;
|
||||
case 'A':
|
||||
return SPA_POD_TYPE_ARRAY;
|
||||
case 'S':
|
||||
return SPA_POD_TYPE_STRUCT;
|
||||
case 'O':
|
||||
return SPA_POD_TYPE_OBJECT;
|
||||
case 'M':
|
||||
return SPA_POD_TYPE_MAP;
|
||||
case 'p':
|
||||
return SPA_POD_TYPE_POINTER;
|
||||
case 'h':
|
||||
return SPA_POD_TYPE_FD;
|
||||
case 'V': case 'v':
|
||||
return SPA_POD_TYPE_PROP;
|
||||
case 'P':
|
||||
return SPA_POD_TYPE_POD;
|
||||
default:
|
||||
return SPA_POD_TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
enum spa_pod_prop_range {
|
||||
SPA_POD_PROP2_RANGE_NONE = '-',
|
||||
SPA_POD_PROP2_RANGE_MIN_MAX = 'r',
|
||||
SPA_POD_PROP2_RANGE_STEP = 's',
|
||||
SPA_POD_PROP2_RANGE_ENUM = 'e',
|
||||
SPA_POD_PROP2_RANGE_FLAGS = 'f'
|
||||
};
|
||||
|
||||
enum spa_pod_prop_flags {
|
||||
SPA_POD_PROP2_FLAG_UNSET = (1 << 0),
|
||||
SPA_POD_PROP2_FLAG_OPTIONAL = (1 << 1),
|
||||
SPA_POD_PROP2_FLAG_READONLY = (1 << 2),
|
||||
SPA_POD_PROP2_FLAG_DEPRECATED = (1 << 3),
|
||||
};
|
||||
|
||||
struct spa_pod_prop2 {
|
||||
enum spa_pod_type type;
|
||||
enum spa_pod_prop_range range;
|
||||
enum spa_pod_prop_flags flags;
|
||||
struct spa_pod *value;
|
||||
struct spa_pod *alternatives;
|
||||
};
|
||||
|
||||
static inline int spa_pod_match(struct spa_pod *pod, const char *templ, ...);
|
||||
|
||||
|
||||
static inline int
|
||||
spa_pod_parse_prop(struct spa_pod *pod, enum spa_pod_type type, struct spa_pod_prop2 *prop)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (SPA_POD_TYPE(pod) == SPA_POD_TYPE_STRUCT) {
|
||||
const char *flags;
|
||||
char ch;
|
||||
|
||||
if ((res = spa_pod_match(pod,
|
||||
"[ %s, %P, %P ]",
|
||||
&flags,
|
||||
&prop->value,
|
||||
&prop->alternatives)) < 0) {
|
||||
printf("can't parse prop chunk %d\n", res);
|
||||
return res;
|
||||
}
|
||||
prop->type = spa_pod_id_to_type(*flags++);
|
||||
if (type != SPA_POD_TYPE_POD && type != SPA_POD_TYPE(prop->value)) {
|
||||
printf("prop chunk of wrong type %d != %d\n", SPA_POD_TYPE(prop->value), type);
|
||||
return -1;
|
||||
}
|
||||
prop->range = *flags++;
|
||||
/* flags */
|
||||
prop->flags = 0;
|
||||
while ((ch = *flags++) != '\0') {
|
||||
switch (ch) {
|
||||
case 'u':
|
||||
prop->flags |= SPA_POD_PROP2_FLAG_UNSET;
|
||||
break;
|
||||
case 'o':
|
||||
prop->flags |= SPA_POD_PROP2_FLAG_OPTIONAL;
|
||||
break;
|
||||
case 'r':
|
||||
prop->flags |= SPA_POD_PROP2_FLAG_READONLY;
|
||||
break;
|
||||
case 'd':
|
||||
prop->flags |= SPA_POD_PROP2_FLAG_DEPRECATED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* a single value */
|
||||
if (type != SPA_POD_TYPE_POD && type != SPA_POD_TYPE(pod)) {
|
||||
printf("prop chunk of wrong type %d != %d\n", SPA_POD_TYPE(prop->value), type);
|
||||
return -1;
|
||||
}
|
||||
prop->type = SPA_POD_TYPE(pod);
|
||||
prop->range = SPA_POD_PROP2_RANGE_NONE;
|
||||
prop->flags = 0;
|
||||
prop->value = pod;
|
||||
prop->alternatives = pod;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_pod_match(struct spa_pod *pod,
|
||||
const char *templ, ...)
|
||||
{
|
||||
struct spa_pod_iter it[SPA_POD_MAX_LEVEL];
|
||||
int depth = 0, collected = 0;
|
||||
va_list args;
|
||||
const char *start;
|
||||
int64_t intval, int2val;
|
||||
double doubleval;
|
||||
char last;
|
||||
struct spa_rectangle *rectval;
|
||||
struct spa_fraction *fracval;
|
||||
int type, len;
|
||||
struct spa_pod *current = pod;
|
||||
struct spa_pod_prop2 prop;
|
||||
bool store, maybe;
|
||||
|
||||
va_start(args, templ);
|
||||
while (*templ != '\0') {
|
||||
switch (*templ) {
|
||||
case '[':
|
||||
depth++;
|
||||
if (current == NULL ||
|
||||
!spa_pod_iter_struct(&it[depth], current, SPA_POD_SIZE(current)))
|
||||
goto done;
|
||||
break;
|
||||
case '(':
|
||||
break;
|
||||
case '{':
|
||||
depth++;
|
||||
if (current == NULL ||
|
||||
!spa_pod_iter_map(&it[depth], current, SPA_POD_SIZE(current)))
|
||||
goto done;
|
||||
break;
|
||||
case ']': case '}': case ')':
|
||||
if (depth == 0)
|
||||
return -1;
|
||||
if (--depth == 0)
|
||||
goto done;
|
||||
break;
|
||||
case '\"':
|
||||
start = templ + 1;
|
||||
if ((len = spa_parse_string(templ, (char **) &templ)) < 0)
|
||||
return -1;
|
||||
templ += strspn(templ, " \t\r\n");
|
||||
if (*templ == ':') {
|
||||
if (SPA_POD_TYPE(it[depth].data) != SPA_POD_TYPE_MAP)
|
||||
return -1;
|
||||
it[depth].offset = sizeof(struct spa_pod_map);
|
||||
/* move to key */
|
||||
while (spa_pod_iter_has_next(&it[depth])) {
|
||||
current = spa_pod_iter_next(&it[depth]);
|
||||
if (SPA_POD_TYPE(current) == SPA_POD_TYPE_KEY &&
|
||||
strncmp(SPA_POD_CONTENTS_CONST(struct spa_pod_key, current),
|
||||
start, len) == 0)
|
||||
break;
|
||||
current = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (current == NULL || SPA_POD_TYPE(current) != SPA_POD_TYPE_STRING ||
|
||||
strncmp(SPA_POD_CONTENTS_CONST(struct spa_pod_string, current),
|
||||
start, len) != 0)
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case '@':
|
||||
case '%':
|
||||
last = *templ;
|
||||
if (*++templ == '\0')
|
||||
return -1;
|
||||
|
||||
store = *templ != '*';
|
||||
if (!store)
|
||||
if (*++templ == '\0')
|
||||
return -1;
|
||||
|
||||
maybe = *templ == '?';
|
||||
if (maybe)
|
||||
if (*++templ == '\0')
|
||||
return -1;
|
||||
|
||||
if (*templ == 'V' || *templ == 'v') {
|
||||
char t = *templ;
|
||||
templ++;
|
||||
type = spa_pod_id_to_type(*templ);
|
||||
|
||||
if (current == NULL)
|
||||
goto no_current;
|
||||
|
||||
if (spa_pod_parse_prop(current, type, &prop) < 0)
|
||||
return -1;
|
||||
|
||||
if (t == 'v') {
|
||||
if (prop.flags & SPA_POD_PROP2_FLAG_UNSET) {
|
||||
if (store)
|
||||
va_arg(args, void *);
|
||||
goto skip;
|
||||
}
|
||||
else
|
||||
current = prop.value;
|
||||
}
|
||||
else {
|
||||
collected++;
|
||||
*va_arg(args, struct spa_pod_prop2 *) = prop;
|
||||
goto skip;
|
||||
}
|
||||
}
|
||||
|
||||
no_current:
|
||||
type = spa_pod_id_to_type(*templ);
|
||||
if (current == NULL || (type != SPA_POD_TYPE_POD && type != SPA_POD_TYPE(current))) {
|
||||
if (!maybe)
|
||||
return -1;
|
||||
if (store)
|
||||
va_arg(args, void *);
|
||||
goto skip;
|
||||
}
|
||||
if (!store)
|
||||
goto skip;
|
||||
|
||||
collected++;
|
||||
|
||||
switch (*templ) {
|
||||
case 'n': case 'A': case 'S': case 'O': case 'M': case 'P':
|
||||
*va_arg(args, struct spa_pod **) = current;
|
||||
break;
|
||||
case 'b':
|
||||
case 'i':
|
||||
case 'I':
|
||||
*va_arg(args, int32_t *) = SPA_POD_VALUE(struct spa_pod_int, current);
|
||||
break;
|
||||
case 'l':
|
||||
*va_arg(args, int64_t *) = SPA_POD_VALUE(struct spa_pod_long, current);
|
||||
break;
|
||||
case 'f':
|
||||
*va_arg(args, float *) = SPA_POD_VALUE(struct spa_pod_float, current);
|
||||
break;
|
||||
case 'd':
|
||||
*va_arg(args, double *) = SPA_POD_VALUE(struct spa_pod_double, current);
|
||||
break;
|
||||
case 's':
|
||||
case 'k':
|
||||
*va_arg(args, char **) = SPA_POD_CONTENTS(struct spa_pod_string, current);
|
||||
break;
|
||||
case 'z':
|
||||
*va_arg(args, void **) = SPA_POD_CONTENTS(struct spa_pod_bytes, current);
|
||||
*va_arg(args, uint32_t *) = SPA_POD_BODY_SIZE(current);
|
||||
break;
|
||||
case 'R':
|
||||
*va_arg(args, struct spa_rectangle *) =
|
||||
SPA_POD_VALUE(struct spa_pod_rectangle, current);
|
||||
break;
|
||||
case 'F':
|
||||
*va_arg(args, struct spa_fraction *) =
|
||||
SPA_POD_VALUE(struct spa_pod_fraction, current);
|
||||
break;
|
||||
case 'p':
|
||||
{
|
||||
struct spa_pod_pointer_body *b = SPA_POD_BODY(current);
|
||||
*va_arg(args, void **) = b->value;
|
||||
break;
|
||||
}
|
||||
case 'h':
|
||||
*va_arg(args, int *) = SPA_POD_VALUE(struct spa_pod_fd, current);
|
||||
break;
|
||||
default:
|
||||
va_arg(args, void *);
|
||||
break;
|
||||
}
|
||||
|
||||
skip:
|
||||
if (last == '@') {
|
||||
templ = va_arg(args, void *);
|
||||
goto next;
|
||||
}
|
||||
break;
|
||||
case '0' ... '9': case '-': case '+': case '#':
|
||||
start = templ;
|
||||
intval = spa_parse_int(start, (char **) &templ);
|
||||
if (*templ == '.') {
|
||||
doubleval = strtod(start, (char **) &templ);
|
||||
if (*templ == 'f') {
|
||||
if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_FLOAT ||
|
||||
doubleval != SPA_POD_VALUE(struct spa_pod_float, current))
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
else if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_DOUBLE ||
|
||||
doubleval != SPA_POD_VALUE(struct spa_pod_double, current))
|
||||
goto done;
|
||||
goto next;
|
||||
}
|
||||
switch (*templ) {
|
||||
case 'x':
|
||||
if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_RECTANGLE)
|
||||
goto done;
|
||||
|
||||
rectval = &SPA_POD_VALUE(struct spa_pod_rectangle, current);
|
||||
int2val = spa_parse_int(templ+1, (char **) &templ);
|
||||
if (rectval->width != intval || rectval->height != int2val)
|
||||
goto done;
|
||||
goto next;
|
||||
case '/':
|
||||
if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_FRACTION)
|
||||
goto done;
|
||||
|
||||
fracval = &SPA_POD_VALUE(struct spa_pod_fraction, current);
|
||||
int2val = spa_parse_int(templ+1, (char **) &templ);
|
||||
if (fracval->num != intval || fracval->denom != int2val)
|
||||
goto done;
|
||||
goto next;
|
||||
case 'l':
|
||||
if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_LONG ||
|
||||
SPA_POD_VALUE(struct spa_pod_long, current) != intval)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
if (current == NULL ||
|
||||
SPA_POD_TYPE(current) != SPA_POD_TYPE_INT ||
|
||||
SPA_POD_VALUE(struct spa_pod_int, current) != intval)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ' ': case '\n': case '\t': case '\r': case ',':
|
||||
templ++;
|
||||
continue;
|
||||
}
|
||||
templ++;
|
||||
|
||||
next:
|
||||
if (spa_pod_iter_has_next(&it[depth]))
|
||||
current = spa_pod_iter_next(&it[depth]);
|
||||
else
|
||||
current = NULL;
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
done:
|
||||
return collected;
|
||||
}
|
||||
|
||||
static int test_match(const char *fmt)
|
||||
{
|
||||
const char *media_type, *media_subtype, *format;
|
||||
int rate = -1, res;
|
||||
struct spa_pod_prop2 channels;
|
||||
struct spa_pod *pod;
|
||||
struct spa_pod_maker m = { 0, };
|
||||
char buffer[4096];
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
pod = spa_pod_maker_build(&m, fmt);
|
||||
spa_debug_pod(pod);
|
||||
|
||||
res = spa_pod_match(pod,
|
||||
"[ \"Format\", "
|
||||
" [ @s",&media_type," @s",&media_subtype," ], "
|
||||
" { "
|
||||
" \"rate\": @vi", &rate,
|
||||
" \"format\": @vs", &format,
|
||||
" \"channels\": @VP", &channels,
|
||||
" \"foo\": @?VP", &channels,
|
||||
" } "
|
||||
"]");
|
||||
|
||||
printf("collected %d\n", res);
|
||||
printf("media type %s\n", media_type);
|
||||
printf("media subtype %s\n", media_subtype);
|
||||
printf("media rate %d\n", rate);
|
||||
printf("media format %s\n", format);
|
||||
printf("media channels: %d %c %04x\n",channels.type, channels.range, channels.flags);
|
||||
spa_debug_pod(channels.value);
|
||||
spa_debug_pod(channels.alternatives);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct spa_pod_maker m = { 0, };
|
||||
char buffer[4096];
|
||||
struct spa_pod *fmt;
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
fmt = spa_pod_maker_build(&m,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", \"raw\" ], "
|
||||
" { "
|
||||
" \"format\": [ \"eu\", \"I420\", [ \"I420\",\"YUY2\" ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ 1x1, #I_MAX#x#I_MAX# ] ], "
|
||||
" \"framerate\": [ \"ru\", 25/1, [ 0/1, #I_MAX#/1 ] ] "
|
||||
" } "
|
||||
"] ");
|
||||
spa_debug_pod(fmt);
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
fmt = spa_pod_maker_build(&m,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", %s ], "
|
||||
" { "
|
||||
" \"format\": [ \"eu\", \"I420\", [ %s, \"YUY2\" ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ %R, #I_MAX#x#I_MAX# ] ], "
|
||||
" \"framerate\": [ \"ru\", %F, [ 0/1, #I_MAX#/1 ] ] "
|
||||
" } "
|
||||
"] ",
|
||||
"raw",
|
||||
"I420",
|
||||
&(struct spa_rectangle){ 1, 1 },
|
||||
&(struct spa_fraction){ 25, 1 }
|
||||
);
|
||||
spa_debug_pod(fmt);
|
||||
|
||||
{
|
||||
const char *format = "S16";
|
||||
int rate = 44100, channels = 2;
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
fmt = spa_pod_maker_build(&m,
|
||||
"[ \"Format\", "
|
||||
" [\"audio\", \"raw\" ], "
|
||||
" { "
|
||||
" \"format\": [@s", format, "] "
|
||||
" \"rate\": [@i", rate, "] "
|
||||
" \"channels\": [@i", channels, "] "
|
||||
" \"rect\": [@R", &SPA_RECTANGLE(32, 22), "] "
|
||||
" } "
|
||||
"] ");
|
||||
spa_debug_pod(fmt);
|
||||
}
|
||||
|
||||
{
|
||||
const char *format = "S16";
|
||||
int rate = 44100, channels = 2;
|
||||
struct spa_rectangle rects[3] = { { 1, 1 }, { 2, 2}, {3, 3}};
|
||||
struct spa_pod_int pod = SPA_POD_INT_INIT(12);
|
||||
uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
spa_pod_maker_build(&m,
|
||||
"[ \"Format\", "
|
||||
" [\"audio\", \"raw\" ], ");
|
||||
fmt = spa_pod_maker_build(&m,
|
||||
" { "
|
||||
" \"format\": [ %s ] "
|
||||
" \"rate\": [ %i, ( 44100, 48000, 96000 ) ]"
|
||||
" \"foo\": %i, ( 1.1, 2.2, 3.2 )"
|
||||
" \"baz\": ( 1.1f, 2.2f, 3.2f )"
|
||||
" \"bar\": ( 1x1, 2x2, 3x2 )"
|
||||
" \"faz\": ( 1/1, 2/2, 3/2 )"
|
||||
" \"wha\": %a, "
|
||||
" \"fuz\": %P, "
|
||||
// " \"fur\": ( (1, 2), (7, 8), (7, 5) ) "
|
||||
// " \"fur\": ( [1, 2], [7, 8], [7, 5] ) "
|
||||
" \"buz\": %z, "
|
||||
" \"boo\": %p, "
|
||||
" \"foz\": %h, "
|
||||
" } "
|
||||
"] ", format, rate, channels,
|
||||
sizeof(struct spa_rectangle), SPA_POD_TYPE_RECTANGLE, 3, rects,
|
||||
&pod,
|
||||
bytes, sizeof(bytes),
|
||||
fmt,
|
||||
STDOUT_FILENO);
|
||||
spa_debug_pod(fmt);
|
||||
}
|
||||
|
||||
spa_pod_maker_init(&m, buffer, sizeof(buffer));
|
||||
fmt = spa_pod_maker_build(&m,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", %s ], "
|
||||
" { "
|
||||
" \"format\": [ \"eu\", \"I420\", [ %s, \"YUY2\" ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ %R, #I_MAX#x#I_MAX# ] ], "
|
||||
" \"framerate\": [ \"ru\", %F, [ 0/1, #I_MAX#/1 ] ] "
|
||||
" } "
|
||||
"] ",
|
||||
"raw",
|
||||
"I420",
|
||||
&(struct spa_rectangle){ 1, 1 },
|
||||
&(struct spa_fraction){ 25, 1 }
|
||||
);
|
||||
spa_debug_pod(fmt);
|
||||
|
||||
{
|
||||
const char *subtype = NULL, *format = NULL;
|
||||
struct spa_pod *pod = NULL;
|
||||
struct spa_rectangle rect = { 0, 0 };
|
||||
struct spa_fraction frac = { 0, 0 };
|
||||
int res;
|
||||
|
||||
res = spa_pod_match(fmt,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", %s ], "
|
||||
" { "
|
||||
" \"format\": [ %*s, %*s, [ %s, %*s ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ %R, %P ] ], "
|
||||
" \"framerate\": [ %*P, %F, %*S ] "
|
||||
" } "
|
||||
"] ",
|
||||
&subtype,
|
||||
&format,
|
||||
&rect,
|
||||
&pod,
|
||||
&frac);
|
||||
|
||||
printf("collected %d\n", res);
|
||||
printf("media type %s\n", subtype);
|
||||
printf("media format %s\n", format);
|
||||
printf("media size %dx%d\n", rect.width, rect.height);
|
||||
printf("media size pod\n");
|
||||
spa_debug_pod(pod);
|
||||
printf("media framerate %d/%d\n", frac.num, frac.denom);
|
||||
|
||||
res = spa_pod_match(fmt,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", @s", &subtype, " ], "
|
||||
" { "
|
||||
" \"format\": [ %*s, %*s, [ @s", &format, ", %*s ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ @R",&rect,", @P",&pod," ] ], "
|
||||
" \"framerate\": [ %*P, @F",&frac,", %*S ] "
|
||||
" } "
|
||||
"] ");
|
||||
|
||||
printf("collected %d\n", res);
|
||||
printf("media type %s\n", subtype);
|
||||
printf("media format %s\n", format);
|
||||
printf("media size %dx%d\n", rect.width, rect.height);
|
||||
printf("media size pod\n");
|
||||
spa_debug_pod(pod);
|
||||
printf("media framerate %d/%d\n", frac.num, frac.denom);
|
||||
|
||||
res = spa_pod_match(fmt,
|
||||
"[ \"Format\", "
|
||||
" [\"video\", @s", &subtype, " ], "
|
||||
" { "
|
||||
" \"format\": [ %*s, %*s, [ @s", &format, ", %*s ] ], "
|
||||
" \"size\": [ \"ru\", 320x242, [ @R",&rect,", @P",&pod," ] ], "
|
||||
" \"framerate\": [ %*P, @F",&frac,", %*S ] "
|
||||
" } "
|
||||
"] ");
|
||||
|
||||
}
|
||||
|
||||
test_match("[ \"Format\", "
|
||||
" [\"audio\", \"raw\" ], "
|
||||
" { "
|
||||
" \"format\": [ \"se\", \"S16\", [ \"S16\", \"F32\" ] ], "
|
||||
" \"rate\": [ \"iru\", 44100, [ 1, 192000 ] ], "
|
||||
" \"channels\": [ \"ir\", 2, [ 1, #I_MAX# ]] "
|
||||
" } "
|
||||
"] ");
|
||||
|
||||
test_match(
|
||||
"[ \"Format\", "
|
||||
" [ \"audio\", \"raw\"], "
|
||||
" { "
|
||||
" \"format\": \"S16LE\", "
|
||||
" \"rate\": 44100, "
|
||||
" \"channels\": 2 "
|
||||
" }"
|
||||
"]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
92
spa/tests/test-props5.c
Normal file
92
spa/tests/test-props5.c
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/* Spa
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <lib/debug.h>
|
||||
|
||||
#include <spa/pod-parser.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[4096];
|
||||
struct spa_pod_builder b = { 0, };
|
||||
struct spa_pod_parser prs;
|
||||
struct spa_pod *fmt, *pod = NULL, *pod2 = NULL;
|
||||
uint32_t format = 1, video = 2, raw = 3;
|
||||
uint32_t size = 4, framerate = 5, I420 = 6, YUY2 = 7;
|
||||
uint32_t media_type = -1, media_subtype = -1;
|
||||
uint32_t fmt_value = -1;
|
||||
int res;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
fmt = spa_pod_builder_add(&b,
|
||||
"<",0,format,
|
||||
" [ i", video, "i",raw,"]"
|
||||
" :", format, "ieu", I420,
|
||||
2, I420, YUY2,
|
||||
" :", size, "Rru", &SPA_RECTANGLE(320,240),
|
||||
2, &SPA_RECTANGLE(1,1),
|
||||
&SPA_RECTANGLE(INT32_MAX, INT32_MAX),
|
||||
" :", framerate, "Fru", &SPA_FRACTION(25,1),
|
||||
2, &SPA_FRACTION(0,1),
|
||||
&SPA_FRACTION(INT32_MAX, 1),
|
||||
">", NULL);
|
||||
spa_debug_pod(fmt);
|
||||
|
||||
spa_pod_parser_pod(&prs, fmt);
|
||||
res = spa_pod_parser_get(&prs,
|
||||
"<"
|
||||
" [ i",&media_type,"*i"/*,&media_subtype,*/" ]"
|
||||
" :", framerate, "V", &pod,
|
||||
" :", 10, "?V", &pod2,
|
||||
" :", format, "?i", &fmt_value,
|
||||
">", NULL);
|
||||
|
||||
printf("res :%d\n", res);
|
||||
printf("media-type:%d media-subtype:%d\n", media_type, media_subtype);
|
||||
printf("framerate:\n");
|
||||
if (pod)
|
||||
spa_debug_pod(pod);
|
||||
printf("format: %d\n", fmt_value);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
pod = spa_pod_builder_add(&b,
|
||||
"<",0,format,
|
||||
" P", NULL,
|
||||
" [ i", 44, "i",45,"]"
|
||||
">", NULL);
|
||||
spa_debug_pod(pod);
|
||||
|
||||
spa_pod_parser_pod(&prs, pod);
|
||||
res = spa_pod_parser_get(&prs,
|
||||
"<"
|
||||
" ?[ i",&media_type,"i",&media_subtype," ]"
|
||||
" [ i", &video, "i",&raw,"]"
|
||||
">", NULL);
|
||||
printf("res :%d\n", res);
|
||||
printf("video:%d raw:%d\n", video, raw);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -277,7 +277,6 @@ static int make_nodes(struct data *data, const char *device)
|
|||
int res;
|
||||
struct spa_props *props;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[128];
|
||||
|
||||
if ((res = make_node(data, &data->sink,
|
||||
|
|
@ -288,12 +287,10 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_node_set_callbacks(data->sink, &sink_callbacks, data);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_device, 0, SPA_POD_TYPE_STRING, 1,
|
||||
device ? device : "hw:0"),
|
||||
SPA_POD_PROP(&f[1], data->type.props_min_latency, 0, SPA_POD_TYPE_INT, 1,
|
||||
64));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_device, "s", device ? device : "hw:0",
|
||||
":", data->type.props_min_latency, "i", 64);
|
||||
|
||||
if ((res = spa_node_set_props(data->sink, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -306,10 +303,9 @@ static int make_nodes(struct data *data, const char *device)
|
|||
}
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_live, 0, SPA_POD_TYPE_BOOL, 1,
|
||||
false));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_live, "b", false);
|
||||
|
||||
if ((res = spa_node_set_props(data->source, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -322,22 +318,16 @@ static int negotiate_formats(struct data *data)
|
|||
struct spa_format *format, *filter;
|
||||
uint32_t state = 0;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_format(&b, &f[0], data->type.format,
|
||||
data->type.media_type.audio,
|
||||
data->type.media_subtype.raw,
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.format, 0, SPA_POD_TYPE_ID, 1,
|
||||
data->type.audio_format.S16),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.layout, 0, SPA_POD_TYPE_INT, 1,
|
||||
SPA_AUDIO_LAYOUT_INTERLEAVED),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.rate, 0, SPA_POD_TYPE_INT, 1,
|
||||
44100),
|
||||
SPA_POD_PROP(&f[1], data->type.format_audio.channels, 0, SPA_POD_TYPE_INT, 1,
|
||||
2));
|
||||
filter = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
|
||||
filter = spa_pod_builder_format(&b,
|
||||
data->type.format,
|
||||
data->type.media_type.audio, data->type.media_subtype.raw,
|
||||
":", data->type.format_audio.format, "I", data->type.audio_format.S16,
|
||||
":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", data->type.format_audio.rate, "i", 44100,
|
||||
":", data->type.format_audio.channels, "i", 2);
|
||||
|
||||
if ((res =
|
||||
spa_node_port_enum_formats(data->sink, SPA_DIRECTION_INPUT, 0, &format, filter,
|
||||
|
|
|
|||
|
|
@ -299,7 +299,6 @@ static int make_nodes(struct data *data, const char *device)
|
|||
int res;
|
||||
struct spa_props *props;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
|
||||
if ((res =
|
||||
|
|
@ -312,10 +311,9 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_node_set_callbacks(data->source, &source_callbacks, data);
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
spa_pod_builder_props(&b, &f[0], data->type.props,
|
||||
SPA_POD_PROP(&f[1], data->type.props_device, 0, SPA_POD_TYPE_STRING, 1,
|
||||
device ? device : "/dev/video0"));
|
||||
props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
|
||||
props = spa_pod_builder_props(&b,
|
||||
data->type.props,
|
||||
":", data->type.props_device, "s", device ? device : "/dev/video0");
|
||||
|
||||
if ((res = spa_node_set_props(data->source, props)) < 0)
|
||||
printf("got set_props error %d\n", res);
|
||||
|
|
@ -389,7 +387,6 @@ static int negotiate_formats(struct data *data)
|
|||
int res;
|
||||
const struct spa_port_info *info;
|
||||
struct spa_format *format;
|
||||
struct spa_pod_frame f[2];
|
||||
uint8_t buffer[256];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
|
||||
|
|
@ -407,17 +404,12 @@ static int negotiate_formats(struct data *data)
|
|||
return res;
|
||||
#else
|
||||
|
||||
spa_pod_builder_format(&b, &f[0], data->type.format,
|
||||
data->type.media_type.video, data->type.media_subtype.raw,
|
||||
SPA_POD_PROP(&f[1], data->type.format_video.format, 0,
|
||||
SPA_POD_TYPE_ID, 1,
|
||||
data->type.video_format.YUY2),
|
||||
SPA_POD_PROP(&f[1], data->type.format_video.size, 0,
|
||||
SPA_POD_TYPE_RECTANGLE, 1,
|
||||
320, 240),
|
||||
SPA_POD_PROP(&f[1], data->type.format_video.framerate, 0,
|
||||
SPA_POD_TYPE_FRACTION, 1, 25, 1));
|
||||
format = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
|
||||
format = spa_pod_builder_format(&b,
|
||||
data->type.format,
|
||||
data->type.media_type.video, data->type.media_subtype.raw,
|
||||
":", data->type.format_video.format, "I", data->type.video_format.YUY2,
|
||||
":", data->type.format_video.size, "R", &SPA_RECTANGLE(320, 240),
|
||||
":", data->type.format_video.framerate, "F", &SPA_FRACTION(25,1));
|
||||
#endif
|
||||
|
||||
if ((res = spa_node_port_set_format(data->source, SPA_DIRECTION_OUTPUT, 0, 0, format)) < 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue