node: improve async handling

Remove the done and error callbacks. The error callback is in an
error message. The done callback is replace with spa_pending.

Make enum_params take a callback and data for the results. This allows
us to push the results one after another to the app and avoids ownership
issues of the passed data. We can then extend this to handle the async
case by doing a _wait call with a spa_pending+callback+data that will
be called when the _enum_params returns and async result.
Add a sync method.

All methods can now return SPA_RESULT_IS_ASYNC return values and you
can use spa_node_wait() to register a callback when they complete
with optional extra parameters. This makes it easier to sync and
handle the reply.

Make helper methods to simulate the sync enum_params behaviour for
sync nodes.

Let the transport generate the sequence number for pw_resource_sync()
and pw_proxy_sync(). That way we don't need to keep track of numbers
ourselves and we can match the reply to the request easily.
This commit is contained in:
Wim Taymans 2019-02-20 17:51:05 +01:00
parent b743518f78
commit 7b12212eeb
67 changed files with 1894 additions and 1209 deletions

View file

@ -49,22 +49,26 @@ static void reset_props(struct props *props)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct state *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -74,10 +78,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -86,7 +90,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -131,7 +135,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -150,12 +154,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -265,16 +275,8 @@ static void emit_port_info(struct state *this)
}
static int
impl_node_sync(struct spa_node *node, uint32_t seq)
impl_node_sync(struct spa_node *node)
{
struct state *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(this->callbacks && this->callbacks->done, -EIO);
this->callbacks->done(this->callbacks_data, seq);
return 0;
}
@ -312,25 +314,29 @@ static int impl_node_remove_port(struct spa_node *node, enum spa_direction direc
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct state *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -343,21 +349,21 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO, };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
return spa_alsa_enum_format(this, index, filter, result, builder);
return spa_alsa_enum_format(this, start, num, filter, func, data);
case SPA_PARAM_Format:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
@ -366,7 +372,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -385,7 +391,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -398,7 +404,7 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -426,12 +432,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct state *this)

View file

@ -49,25 +49,28 @@ static void reset_props(struct props *props)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct state *this;
struct spa_pod *param;
uint8_t buffer[1024];
struct spa_pod_builder b = { 0 };
struct props *p;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
p = &this->props;
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -77,16 +80,16 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props, };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_PropInfo:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -128,7 +131,7 @@ static int impl_node_enum_params(struct spa_node *node,
break;
case SPA_PARAM_Props:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -147,12 +150,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -310,24 +319,28 @@ static void recycle_buffer(struct state *this, uint32_t buffer_id)
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct state *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -339,21 +352,21 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Buffers,
SPA_PARAM_Meta };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
return spa_alsa_enum_format(this, index, filter, result, builder);
return spa_alsa_enum_format(this, start, num, filter, func, data);
case SPA_PARAM_Format:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
@ -362,7 +375,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -381,7 +394,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -394,7 +407,7 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -416,12 +429,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct state *this)

View file

@ -217,10 +217,9 @@ static void sanitize_map(snd_pcm_chmap_t* map)
}
int
spa_alsa_enum_format(struct state *state, uint32_t *index,
spa_alsa_enum_format(struct state *state, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
snd_pcm_t *hndl;
snd_pcm_hw_params_t *params;
@ -237,11 +236,15 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
int res;
bool opened;
struct spa_pod_frame f[2];
struct spa_result_node_enum_params result;
uint32_t count = 0;
opened = state->opened;
if ((err = spa_alsa_open(state)) < 0)
return err;
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -313,12 +316,11 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
uint32_t channel;
snd_pcm_chmap_t* map;
if (maps[*index] == NULL) {
res = 0;
if (maps[result.next] == NULL) {
snd_pcm_free_chmaps(maps);
goto exit;
goto enum_end;
}
map = &maps[*index]->map;
map = &maps[result.next]->map;
spa_log_debug(state->log, "map %d channels", map->channels);
sanitize_map(map);
@ -336,10 +338,8 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
snd_pcm_free_chmaps(maps);
}
else {
if (*index > 0) {
res = 0;
goto exit;
}
if (result.next > 0)
goto enum_end;
spa_pod_builder_push_choice(&b, &f[1], SPA_CHOICE_None, 0);
choice = (struct spa_pod_choice*)spa_pod_builder_frame(&b, &f[1]);
@ -354,13 +354,19 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
fmt = spa_pod_builder_pop(&b, &f[0]);
(*index)++;
result.next++;
if ((res = spa_pod_filter(builder, result, fmt, filter)) < 0)
if ((res = spa_pod_filter(&b, &result.param, fmt, filter)) < 0)
goto next;
res = 1;
if ((res = func(data, count, 1, &result)) != 0)
goto exit;
if (++count != num)
goto next;
enum_end:
res = 0;
exit:
if (!opened)
spa_alsa_close(state);

View file

@ -144,10 +144,9 @@ struct state {
int
spa_alsa_enum_format(struct state *state,
uint32_t *index,
uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder);
spa_result_func_t func, void *data);
int spa_alsa_set_format(struct state *state, struct spa_audio_info *info, uint32_t flags);

View file

@ -31,6 +31,7 @@
#include <spa/node/node.h>
#include <spa/buffer/alloc.h>
#include <spa/node/io.h>
#include <spa/node/utils.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/param.h>
#include <spa/pod/filter.h>
@ -145,11 +146,11 @@ static int debug_params(struct impl *this, struct spa_node *node,
state = 0;
while (true) {
spa_pod_builder_init(&b, buffer, sizeof(buffer));
res = spa_node_port_enum_params(node,
res = spa_node_port_enum_params_sync(node,
direction, port_id,
id, &state,
NULL, &param, &b);
if (res <= 0)
if (res != 1)
break;
spa_debug_pod(2, NULL, param);
@ -177,20 +178,20 @@ static int negotiate_link_format(struct impl *this, struct link *link)
state = 0;
filter = NULL;
if ((res = spa_node_port_enum_params(link->out_node,
if ((res = spa_node_port_enum_params_sync(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
SPA_PARAM_EnumFormat, &state,
filter, &format, &b)) <= 0) {
filter, &format, &b)) != 1) {
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
SPA_PARAM_EnumFormat, filter);
return -ENOTSUP;
}
filter = format;
state = 0;
if ((res = spa_node_port_enum_params(link->in_node,
if ((res = spa_node_port_enum_params_sync(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
SPA_PARAM_EnumFormat, &state,
filter, &format, &b)) <= 0) {
filter, &format, &b)) != 1) {
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
SPA_PARAM_EnumFormat, filter);
return -ENOTSUP;
@ -263,19 +264,19 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
return 0;
state = 0;
if ((res = spa_node_port_enum_params(link->in_node,
if ((res = spa_node_port_enum_params_sync(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
SPA_PARAM_Buffers, &state,
param, &param, &b)) <= 0) {
param, &param, &b)) != 1) {
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
SPA_PARAM_Buffers, param);
return -ENOTSUP;
}
state = 0;
if ((res = spa_node_port_enum_params(link->out_node,
if ((res = spa_node_port_enum_params_sync(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
SPA_PARAM_Buffers, &state,
param, &param, &b)) <= 0) {
param, &param, &b)) != 1) {
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
SPA_PARAM_Buffers, param);
return -ENOTSUP;
@ -384,28 +385,32 @@ static int setup_buffers(struct impl *this, enum spa_direction direction)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_EnumProfile:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamProfile, id,
@ -421,9 +426,10 @@ static int impl_node_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_Props:
switch (*index) {
switch (result.next) {
case 0:
return spa_node_enum_params(this->channelmix, id, index, filter, result, builder);
return spa_node_enum_params(this->channelmix,
id, start, num, filter, func, data);
default:
return 0;
}
@ -432,12 +438,18 @@ static int impl_node_enum_params(struct spa_node *node,
default:
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -633,28 +645,34 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_PropInfo:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(builder,
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
SPA_PROP_INFO_id, SPA_POD_Id(SPA_PROP_volume),
SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(1.0, 0.0, 10.0));
@ -665,21 +683,21 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(builder,
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Buffers),
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers)));
break;
case 1:
param = spa_pod_builder_add_object(builder,
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Range),
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_range)));
break;
case 2:
param = spa_pod_builder_add_object(builder,
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Control),
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_sequence)));
@ -690,14 +708,20 @@ impl_node_port_enum_params(struct spa_node *node,
break;
default:
return spa_node_port_enum_params(this->fmt[direction], direction, port_id,
id, index, filter, result, builder);
id, start, num, filter, func, data);
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int

View file

@ -432,22 +432,26 @@ static int setup_convert(struct impl *this,
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -457,10 +461,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -469,7 +473,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -493,7 +497,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -509,12 +513,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int apply_props(struct impl *this, const struct spa_pod *param)
@ -625,7 +635,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
@ -634,7 +644,7 @@ static int port_enum_formats(struct spa_node *node,
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0);
switch (*index) {
switch (index) {
case 0:
if (other->have_format) {
*param = spa_pod_builder_add_object(builder,
@ -663,21 +673,22 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port, *other;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -686,6 +697,8 @@ impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -698,23 +711,24 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
@ -726,7 +740,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
if (other->n_buffers > 0) {
@ -753,7 +767,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -766,7 +780,7 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -787,12 +801,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)

View file

@ -188,10 +188,9 @@ static int setup_convert(struct impl *this)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
@ -276,7 +275,7 @@ static int int32_cmp(const void *v1, const void *v2)
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
@ -287,7 +286,7 @@ static int port_enum_formats(struct spa_node *node,
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0);
spa_log_debug(this->log, NAME " %p: enum %p", this, other);
switch (*index) {
switch (index) {
case 0:
if (port->have_format) {
*param = spa_format_audio_raw_build(builder,
@ -360,22 +359,22 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port, *other;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -384,6 +383,8 @@ impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -396,23 +397,24 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
@ -425,7 +427,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
if (other->n_buffers > 0) {
@ -453,7 +455,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -466,7 +468,7 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -482,12 +484,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int calc_width(struct spa_audio_info *info)

View file

@ -169,17 +169,21 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -188,10 +192,10 @@ static int impl_node_enum_params(struct spa_node *node,
{
uint32_t list[] = { SPA_PARAM_Profile };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(builder,
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -199,12 +203,18 @@ static int impl_node_enum_params(struct spa_node *node,
default:
return 0;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -345,14 +355,14 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port = GET_PORT(this, direction, port_id);
switch (*index) {
switch (index) {
case 0:
if (PORT_IS_DSP(direction, port_id) || port->have_format) {
*param = spa_format_audio_raw_build(builder,
@ -392,27 +402,29 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -428,22 +440,22 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO, };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id, result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
@ -451,7 +463,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -469,7 +481,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -481,7 +493,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -496,12 +508,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)

View file

@ -157,10 +157,9 @@ static int setup_convert(struct impl *this,
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
@ -274,7 +273,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
@ -284,7 +283,7 @@ static int port_enum_formats(struct spa_node *node,
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0);
switch (*index) {
switch (index) {
case 0:
if (other->have_format) {
spa_pod_builder_push_object(builder, &f,
@ -320,21 +319,22 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port, *other;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -343,6 +343,8 @@ impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -355,22 +357,23 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
@ -381,7 +384,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
if (other->n_buffers > 0) {
@ -409,7 +412,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -421,7 +424,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -442,12 +445,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)

View file

@ -165,16 +165,22 @@ static int init_port(struct impl *this, enum spa_direction direction,
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -184,10 +190,10 @@ static int impl_node_enum_params(struct spa_node *node,
{
uint32_t list[] = { SPA_PARAM_Profile };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(builder,
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -195,12 +201,18 @@ static int impl_node_enum_params(struct spa_node *node,
default:
return 0;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -332,14 +344,14 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port = GET_PORT(this, direction, port_id);
switch (*index) {
switch (index) {
case 0:
if (direction == SPA_DIRECTION_OUTPUT || port->have_format) {
*param = spa_format_audio_raw_build(builder,
@ -384,21 +396,22 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -406,6 +419,8 @@ impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -420,22 +435,23 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
@ -443,7 +459,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -462,7 +478,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -474,7 +490,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -489,12 +505,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)

View file

@ -127,10 +127,9 @@ struct impl {
#define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p))
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
@ -278,13 +277,13 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
switch (*index) {
switch (index) {
case 0:
if (this->have_format) {
*param = spa_pod_builder_add_object(builder,
@ -315,22 +314,23 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -338,6 +338,8 @@ impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -350,22 +352,23 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO, };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->format.info.raw);
@ -373,7 +376,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -391,7 +394,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!port->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -403,7 +406,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -430,12 +433,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)

View file

@ -126,22 +126,26 @@ struct impl {
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS)
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -151,10 +155,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -164,7 +168,7 @@ static int impl_node_enum_params(struct spa_node *node,
struct props *p = &this->props;
struct spa_pod_frame f[2];
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -211,7 +215,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -229,12 +233,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
@ -505,11 +515,11 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int
port_enum_formats(struct impl *this,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
switch (*index) {
switch (index) {
case 0:
*param = spa_pod_builder_add_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
@ -532,26 +542,29 @@ port_enum_formats(struct impl *this,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -564,23 +577,24 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO, };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(this, direction, port_id, index, &param, &b)) <= 0)
if ((res = port_enum_formats(this, direction, port_id,
result.next, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
@ -589,7 +603,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -607,7 +621,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -619,7 +633,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -646,12 +660,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this)

View file

@ -146,22 +146,26 @@ static void reset_props(struct props *props)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -171,10 +175,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -183,7 +187,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -207,7 +211,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -223,12 +227,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -901,26 +911,30 @@ static int impl_node_remove_port(struct spa_node *node, enum spa_direction direc
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -932,16 +946,16 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Buffers,
SPA_PARAM_Meta };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if (*index > 0)
if (result.next > 0)
return 0;
switch (this->transport->codec) {
@ -987,7 +1001,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Format:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
@ -996,7 +1010,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -1015,7 +1029,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -1031,12 +1045,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this)

View file

@ -73,10 +73,9 @@ struct impl {
};
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
@ -163,22 +162,19 @@ impl_node_remove_port(struct spa_node *node,
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
//struct impl *this;
if (node == NULL || index == NULL)
return -EINVAL;
//this = SPA_CONTAINER_OF (node, struct impl, node);
if (!IS_VALID_PORT(this, direction, port_id))
return -EINVAL;
switch (*index) {
switch (index) {
case 0:
*param = NULL;
break;
@ -190,7 +186,7 @@ static int port_enum_formats(struct spa_node *node,
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -203,7 +199,7 @@ static int port_get_format(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (index > 0)
return 0;
*param = NULL;
@ -213,17 +209,20 @@ static int port_get_format(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -233,21 +232,23 @@ impl_node_port_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_EnumFormat,
SPA_PARAM_Format };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_get_format(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
@ -255,12 +256,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int port_set_format(struct spa_node *node,

View file

@ -76,10 +76,9 @@ struct impl {
};
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
@ -164,12 +163,12 @@ impl_node_remove_port(struct spa_node *node,
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
switch (*index) {
switch (index) {
case 0:
*param = NULL;
break;
@ -181,7 +180,7 @@ static int port_enum_formats(struct spa_node *node,
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -194,7 +193,7 @@ static int port_get_format(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (index > 0)
return 0;
*param = NULL;
@ -204,17 +203,20 @@ static int port_get_format(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -224,21 +226,23 @@ impl_node_port_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_EnumFormat,
SPA_PARAM_Format };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_get_format(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
@ -246,12 +250,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int port_set_format(struct spa_node *node,

View file

@ -38,6 +38,7 @@
#include <spa/support/log.h>
#include <spa/support/plugin.h>
#include <spa/utils/list.h>
#include <spa/utils/result.h>
#include <spa/utils/type.h>
#include <spa/utils/ringbuffer.h>

View file

@ -98,27 +98,32 @@ static void reset_props(struct impl *this, struct props *props)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_List:
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -126,7 +131,7 @@ static int impl_node_enum_params(struct spa_node *node,
SPA_PARAM_LIST_id, SPA_POD_Id(SPA_PARAM_Props));
break;
case SPA_PARAM_Props:
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -137,12 +142,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -368,7 +379,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -378,7 +389,7 @@ static int port_enum_formats(struct spa_node *node,
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -388,7 +399,7 @@ static int port_get_format(struct spa_node *node,
if (!this->have_format)
return -EIO;
if (*index > 0)
if (index > 0)
return 0;
*param = SPA_MEMBER(this->format_buffer, 0, struct spa_pod);
@ -398,23 +409,26 @@ static int port_get_format(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -426,24 +440,26 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Buffers,
SPA_PARAM_Meta };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_get_format(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Buffers:
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -455,7 +471,7 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
break;
case SPA_PARAM_Meta:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -470,12 +486,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this)

View file

@ -102,28 +102,32 @@ static void reset_props(struct impl *this, struct props *props)
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (id) {
case SPA_PARAM_List:
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -135,7 +139,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -148,12 +152,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -384,7 +394,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -394,7 +404,7 @@ static int port_enum_formats(struct spa_node *node,
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -403,7 +413,7 @@ static int port_get_format(struct spa_node *node,
if (!this->have_format)
return -EIO;
if (*index > 0)
if (index > 0)
return 0;
*param = SPA_MEMBER(this->format_buffer, 0, struct spa_pod);
@ -413,23 +423,26 @@ static int port_get_format(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -441,36 +454,41 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Buffers,
SPA_PARAM_Meta };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_get_format(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Buffers:
if (*index > 0)
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamBuffers, id,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(32, 2, 32),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(128),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
break;
default:
return 0;
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamBuffers, id,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(32, 2, 32),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(128),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
}
break;
case SPA_PARAM_Meta:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -485,12 +503,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this)

View file

@ -146,23 +146,33 @@ struct impl {
#include "v4l2-utils.c"
static int impl_node_wait(struct spa_node *node, int res, struct spa_pending *pending,
spa_result_func_t func, void *data)
{
return -ENOTSUP;
}
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -172,10 +182,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -184,7 +194,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -215,7 +225,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -232,12 +242,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_param(struct spa_node *node,
@ -387,7 +403,7 @@ static int impl_node_remove_port(struct spa_node *node,
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
@ -398,7 +414,7 @@ static int port_get_format(struct spa_node *node,
if (!port->have_format)
return -EIO;
if (*index > 0)
if (index > 0)
return 0;
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, SPA_PARAM_Format);
@ -440,10 +456,9 @@ static int port_get_format(struct spa_node *node,
static int impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
@ -451,11 +466,13 @@ static int impl_node_port_enum_params(struct spa_node *node,
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -463,6 +480,8 @@ static int impl_node_port_enum_params(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -476,28 +495,29 @@ static int impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_PropInfo:
return spa_v4l2_enum_controls(this, index, filter, result, builder);
return spa_v4l2_enum_controls(this, start, num, filter, func, data);
case SPA_PARAM_EnumFormat:
return spa_v4l2_enum_format(this, index, filter, result, builder);
return spa_v4l2_enum_format(this, start, num, filter, func, data);
case SPA_PARAM_Format:
if((res = port_get_format(node, direction, port_id, index, filter, &param, &b)) <= 0)
if((res = port_get_format(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -510,7 +530,7 @@ static int impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_Meta:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -522,7 +542,7 @@ static int impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -549,12 +569,18 @@ static int impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int port_set_format(struct spa_node *node,
@ -880,11 +906,12 @@ static int impl_node_process(struct spa_node *node)
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
.set_callbacks = impl_node_set_callbacks,
.wait = impl_node_wait,
.enum_params = impl_node_enum_params,
.set_param = impl_node_set_param,
.set_io = impl_node_set_io,
.send_command = impl_node_send_command,
.set_callbacks = impl_node_set_callbacks,
.add_port = impl_node_add_port,
.remove_port = impl_node_remove_port,
.port_enum_params = impl_node_port_enum_params,
@ -942,7 +969,9 @@ impl_init(const struct spa_handle_factory *factory,
spa_return_val_if_fail(handle != NULL, -EINVAL);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear, this = (struct impl *) handle;
handle->clear = impl_clear;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (support[i].type == SPA_TYPE_INTERFACE_Log)

View file

@ -521,10 +521,9 @@ filter_framerate(struct v4l2_frmivalenum *frmival,
static int
spa_v4l2_enum_format(struct impl *this,
uint32_t *index,
uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct port *port = &this->out_ports[0];
int res, n_fractions;
@ -532,12 +531,18 @@ spa_v4l2_enum_format(struct impl *this,
struct spa_pod_choice *choice;
uint32_t filter_media_type, filter_media_subtype, video_format;
struct spa_v4l2_device *dev = &port->dev;
uint8_t buffer[1024];
struct spa_pod_builder b = { 0 };
struct spa_pod_frame f[2];
struct spa_result_node_enum_params result;
uint32_t count = 0;
if ((res = spa_v4l2_open(dev, this->props.device)) < 0)
return res;
if (*index == 0) {
result.next = start;
if (result.next == 0) {
spa_zero(port->fmtdesc);
port->fmtdesc.index = 0;
port->fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@ -558,6 +563,7 @@ spa_v4l2_enum_format(struct impl *this,
port->next_fmtdesc = true;
}
next:
while (port->next_fmtdesc) {
if (filter) {
video_format = enum_filter_format(filter_media_type,
@ -681,25 +687,26 @@ spa_v4l2_enum_format(struct impl *this,
}
}
spa_pod_builder_push_object(builder, &f[0], SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
spa_pod_builder_add(builder,
spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
spa_pod_builder_add(&b,
SPA_FORMAT_mediaType, SPA_POD_Id(info->media_type),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(info->media_subtype),
0);
if (info->media_subtype == SPA_MEDIA_SUBTYPE_raw) {
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_format, 0);
spa_pod_builder_id(builder, info->format);
spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_format, 0);
spa_pod_builder_id(&b, info->format);
}
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_size, 0);
spa_pod_builder_rectangle(builder, port->frmsize.discrete.width, port->frmsize.discrete.height);
spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_size, 0);
spa_pod_builder_rectangle(&b, port->frmsize.discrete.width, port->frmsize.discrete.height);
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_framerate, 0);
spa_pod_builder_prop(&b, SPA_FORMAT_VIDEO_framerate, 0);
n_fractions = 0;
spa_pod_builder_push_choice(builder, &f[1], SPA_CHOICE_None, 0);
choice = (struct spa_pod_choice*)spa_pod_builder_frame(builder, &f[1]);
spa_pod_builder_push_choice(&b, &f[1], SPA_CHOICE_None, 0);
choice = (struct spa_pod_choice*)spa_pod_builder_frame(&b, &f[1]);
port->frmival.index = 0;
while (true) {
@ -765,21 +772,21 @@ spa_v4l2_enum_format(struct impl *this,
if (port->frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
choice->body.type = SPA_CHOICE_Enum;
if (n_fractions == 0)
spa_pod_builder_fraction(builder,
spa_pod_builder_fraction(&b,
port->frmival.discrete.denominator,
port->frmival.discrete.numerator);
spa_pod_builder_fraction(builder,
spa_pod_builder_fraction(&b,
port->frmival.discrete.denominator,
port->frmival.discrete.numerator);
port->frmival.index++;
} else if (port->frmival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS ||
port->frmival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
if (n_fractions == 0)
spa_pod_builder_fraction(builder, 25, 1);
spa_pod_builder_fraction(builder,
spa_pod_builder_fraction(&b, 25, 1);
spa_pod_builder_fraction(&b,
port->frmival.stepwise.min.denominator,
port->frmival.stepwise.min.numerator);
spa_pod_builder_fraction(builder,
spa_pod_builder_fraction(&b,
port->frmival.stepwise.max.denominator,
port->frmival.stepwise.max.numerator);
@ -787,7 +794,7 @@ spa_v4l2_enum_format(struct impl *this,
choice->body.type = SPA_CHOICE_Range;
} else {
choice->body.type = SPA_CHOICE_Step;
spa_pod_builder_fraction(builder,
spa_pod_builder_fraction(&b,
port->frmival.stepwise.step.denominator,
port->frmival.stepwise.step.numerator);
}
@ -801,21 +808,21 @@ spa_v4l2_enum_format(struct impl *this,
if (n_fractions <= 1)
choice->body.type = SPA_CHOICE_None;
spa_pod_builder_pop(builder, &f[1]);
*result = spa_pod_builder_pop(builder, &f[0]);
spa_pod_builder_pop(&b, &f[1]);
result.param = spa_pod_builder_pop(&b, &f[0]);
result.next++;
(*index)++;
if ((res = func(data, count, 1, &result)) != 0)
goto exit;
res = 1;
if (++count != num)
goto next;
enum_end:
res = 0;
exit:
spa_v4l2_close(dev);
return res;
enum_end:
res = 0;
goto exit;
}
static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format, bool try_only)
@ -999,10 +1006,9 @@ static uint32_t control_to_prop_id(struct impl *impl, uint32_t control_id)
static int
spa_v4l2_enum_controls(struct impl *this,
uint32_t *index,
uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct port *port = &this->out_ports[0];
struct spa_v4l2_device *dev = &port->dev;
@ -1014,19 +1020,23 @@ spa_v4l2_enum_controls(struct impl *this,
int res;
const unsigned next_fl = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
struct spa_pod_frame f[2];
struct spa_result_node_enum_params result;
uint32_t count = 0;
if ((res = spa_v4l2_open(dev, this->props.device)) < 0)
return res;
result.next = start;
next:
spa_zero(queryctrl);
if (*index == 0) {
*index |= next_fl;
if (result.next == 0) {
result.next |= next_fl;
port->n_controls = 0;
}
queryctrl.id = *index;
queryctrl.id = result.next;
spa_log_debug(this->log, "test control %08x", queryctrl.id);
if (query_ext_ctrl_ioctl(port, &queryctrl) != 0) {
@ -1034,12 +1044,12 @@ spa_v4l2_enum_controls(struct impl *this,
if (queryctrl.id != next_fl)
goto enum_end;
if (*index & next_fl)
*index = V4L2_CID_USER_BASE;
else if (*index >= V4L2_CID_USER_BASE && *index < V4L2_CID_LASTP1)
(*index)++;
else if (*index >= V4L2_CID_LASTP1)
*index = V4L2_CID_PRIVATE_BASE;
if (result.next & next_fl)
result.next = V4L2_CID_USER_BASE;
else if (result.next >= V4L2_CID_USER_BASE && result.next < V4L2_CID_LASTP1)
result.next++;
else if (result.next >= V4L2_CID_LASTP1)
result.next = V4L2_CID_PRIVATE_BASE;
else
goto enum_end;
goto next;
@ -1048,10 +1058,10 @@ spa_v4l2_enum_controls(struct impl *this,
spa_log_error(this->log, "VIDIOC_QUERYCTRL: %m");
return res;
}
if (*index & next_fl)
(*index) = queryctrl.id | next_fl;
if (result.next & next_fl)
result.next = queryctrl.id | next_fl;
else
(*index)++;
result.next++;
if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
goto next;
@ -1129,19 +1139,20 @@ spa_v4l2_enum_controls(struct impl *this,
goto next;
}
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
res = 1;
if ((res = func(data, count, 1, &result)) != 0)
goto exit;
if (++count != num)
goto next;
enum_end:
res = 0;
exit:
spa_v4l2_close(dev);
return res;
enum_end:
res = 0;
goto exit;
}
static int mmap_read(struct impl *this)

View file

@ -111,21 +111,26 @@ struct impl {
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS)
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -135,10 +140,10 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
@ -148,7 +153,7 @@ static int impl_node_enum_params(struct spa_node *node,
struct props *p = &this->props;
struct spa_pod_frame f[2];
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -181,7 +186,7 @@ static int impl_node_enum_params(struct spa_node *node,
{
struct props *p = &this->props;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -197,12 +202,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -448,12 +459,12 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
switch (*index) {
switch (index) {
case 0:
*param = spa_pod_builder_add_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
@ -480,26 +491,29 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -511,26 +525,27 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Buffers,
SPA_PARAM_Meta };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_video_raw_build(builder, id, &this->current_format.info.raw);
param = spa_format_video_raw_build(&b, id, &this->current_format.info.raw);
break;
case SPA_PARAM_Buffers:
@ -539,7 +554,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -555,7 +570,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (!this->have_format)
return -EIO;
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -571,12 +586,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this)

View file

@ -103,24 +103,28 @@ struct impl {
#define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p))
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
spa_result_func_t func, void *data)
{
struct impl *this;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct props *p;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
p = &this->props;
result.next = start;
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -130,16 +134,16 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t list[] = { SPA_PARAM_PropInfo,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_PropInfo:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
@ -159,7 +163,7 @@ static int impl_node_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_Props:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, id,
@ -174,12 +178,18 @@ static int impl_node_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -283,12 +293,12 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
uint32_t index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
switch (*index) {
switch (index) {
case 0:
*param = spa_pod_builder_add_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
@ -309,22 +319,23 @@ static int port_enum_formats(struct spa_node *node,
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter,
spa_result_func_t func, void *data)
{
struct impl *this;
struct port *port;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct spa_pod *param;
struct spa_result_node_enum_params result;
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
spa_return_val_if_fail(func != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -344,23 +355,24 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_Meta,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
if (result.next < SPA_N_ELEMENTS(list))
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, SPA_POD_Id(list[*index]));
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
else
return 0;
break;
}
case SPA_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, filter, &param, &b)) <= 0)
if ((res = port_enum_formats(node, direction, port_id,
result.next, filter, &param, &b)) <= 0)
return res;
break;
case SPA_PARAM_Format:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
@ -369,7 +381,7 @@ impl_node_port_enum_params(struct spa_node *node,
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
if (result.next > 0)
return 0;
param = spa_pod_builder_add_object(&b,
@ -384,7 +396,7 @@ impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
break;
case SPA_PARAM_Meta:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
@ -396,7 +408,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
break;
case SPA_PARAM_IO:
switch (*index) {
switch (result.next) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
@ -417,12 +429,18 @@ impl_node_port_enum_params(struct spa_node *node,
return -ENOENT;
}
(*index)++;
result.next++;
if (spa_pod_filter(builder, result, param, filter) < 0)
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
return 1;
if ((res = func(data, count, 1, &result)) != 0)
return res;
if (++count != num)
goto next;
return 0;
}
static int clear_buffers(struct impl *this, struct port *port)