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

@ -37,6 +37,7 @@
#include <spa/support/loop.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/node/utils.h>
#include <spa/param/param.h>
#include <spa/param/props.h>
#include <spa/param/audio/format-utils.h>
@ -371,10 +372,10 @@ static int negotiate_formats(struct data *data)
spa_debug_pod(0, NULL, filter);
spa_log_debug(&default_log.log, "enum_params");
if ((res = spa_node_port_enum_params(data->sink,
if ((res = spa_node_port_enum_params_sync(data->sink,
SPA_DIRECTION_INPUT, 0,
SPA_PARAM_EnumFormat, &state,
filter, &format, &b)) <= 0)
filter, &format, &b)) != 1)
return -EBADF;
spa_log_debug(&default_log.log, "sink set_param");

View file

@ -38,12 +38,15 @@
#include <spa/support/loop.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/node/utils.h>
#include <spa/param/param.h>
#include <spa/param/props.h>
#include <spa/param/video/format-utils.h>
#include <spa/debug/pod.h>
static SPA_LOG_IMPL(default_log);
#define PATH "build/spa/plugins/"
#define MAX_BUFFERS 8
@ -58,7 +61,8 @@ struct buffer {
struct data {
struct spa_log *log;
struct spa_loop data_loop;
struct spa_loop *loop;
struct spa_loop_control *control;
struct spa_support support[4];
uint32_t n_support;
@ -87,9 +91,8 @@ struct data {
unsigned int n_buffers;
};
static int make_node(struct data *data, struct spa_node **node, const char *lib, const char *name)
static int load_handle(struct data *data, struct spa_handle **handle, const char *lib, const char *name)
{
struct spa_handle *handle;
int res;
void *hnd;
spa_handle_factory_enum_func_t enum_func;
@ -106,7 +109,6 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
@ -116,23 +118,35 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if (strcmp(factory->name, name))
continue;
handle = calloc(1, spa_handle_factory_get_size(factory, NULL));
if ((res =
spa_handle_factory_init(factory, handle, NULL, data->support,
data->n_support)) < 0) {
*handle = calloc(1, spa_handle_factory_get_size(factory, NULL));
if ((res = spa_handle_factory_init(factory, *handle,
NULL, data->support,
data->n_support)) < 0) {
printf("can't make factory instance: %d\n", res);
return res;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
printf("can't get interface %d\n", res);
return res;
}
*node = iface;
return 0;
}
return -EBADF;
}
static int make_node(struct data *data, struct spa_node **node, const char *lib, const char *name)
{
struct spa_handle *handle = NULL;
void *iface;
int res;
if ((res = load_handle(data, &handle, lib, name)) < 0)
return res;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
printf("can't get interface %d\n", res);
return res;
}
*node = iface;
return 0;
}
static void handle_events(struct data *data)
{
SDL_Event event;
@ -159,10 +173,8 @@ static int on_source_ready(void *_data, int status)
handle_events(data);
if ((res = spa_node_process(data->source)) < 0)
printf("got process error %d\n", res);
if (io->buffer_id > MAX_BUFFERS)
if (io->status != SPA_STATUS_HAVE_BUFFER ||
io->buffer_id > MAX_BUFFERS)
return -EINVAL;
b = &data->buffers[io->buffer_id];
@ -221,6 +233,10 @@ static int on_source_ready(void *_data, int status)
}
io->status = SPA_STATUS_NEED_BUFFER;
if ((res = spa_node_process(data->source)) < 0)
printf("got process error %d\n", res);
return 0;
}
@ -229,49 +245,29 @@ static const struct spa_node_callbacks source_callbacks = {
.ready = on_source_ready
};
static int do_add_source(struct spa_loop *loop, struct spa_source *source)
{
struct data *data = SPA_CONTAINER_OF(loop, struct data, data_loop);
data->sources[data->n_sources] = *source;
data->n_sources++;
data->rebuild_fds = true;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return 0;
}
static void do_remove_source(struct spa_source *source)
{
}
static int
do_invoke(struct spa_loop *loop,
spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, bool block, void *user_data)
{
return func(loop, false, seq, data, size, user_data);
}
static int make_nodes(struct data *data, const char *device)
{
int res;
struct spa_pod *props;
struct spa_pod_builder b = { 0 };
uint8_t buffer[256];
uint32_t index;
if ((res =
make_node(data, &data->source, "build/spa/plugins/v4l2/libspa-v4l2.so",
"v4l2-source")) < 0) {
make_node(data, &data->source, PATH "v4l2/libspa-v4l2.so", "v4l2-source")) < 0) {
printf("can't create v4l2-source: %d\n", res);
return res;
}
spa_node_set_callbacks(data->source, &source_callbacks, data);
index = 0;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_enum_params_sync(data->source, SPA_PARAM_Props,
&index, NULL, &props, &b)) == 1) {
spa_debug_pod(0, NULL, props);
}
spa_pod_builder_init(&b, buffer, sizeof(buffer));
props = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Props, 0,
@ -422,52 +418,14 @@ static void *loop(void *user_data)
struct data *data = user_data;
printf("enter thread\n");
spa_loop_control_enter(data->control);
while (data->running) {
int r;
unsigned int i;
/* rebuild */
if (data->rebuild_fds) {
for (i = 0; i < data->n_sources; i++) {
struct spa_source *p = &data->sources[i];
data->fds[i].fd = p->fd;
data->fds[i].events = p->mask;
}
data->n_fds = data->n_sources;
data->rebuild_fds = false;
}
r = poll((struct pollfd *) data->fds, data->n_fds, -1);
if (r < 0) {
if (errno == EINTR)
continue;
break;
}
if (r == 0) {
fprintf(stderr, "select timeout");
break;
}
/* after */
for (i = 0; i < data->n_sources; i++) {
struct spa_source *p = &data->sources[i];
p->rmask = 0;
if (data->fds[i].revents & POLLIN)
p->rmask |= SPA_IO_IN;
if (data->fds[i].revents & POLLOUT)
p->rmask |= SPA_IO_OUT;
if (data->fds[i].revents & POLLHUP)
p->rmask |= SPA_IO_HUP;
if (data->fds[i].revents & POLLERR)
p->rmask |= SPA_IO_ERR;
}
for (i = 0; i < data->n_sources; i++) {
struct spa_source *p = &data->sources[i];
if (p->rmask)
p->func(p);
}
spa_loop_control_iterate(data->control, -1);
}
printf("leave thread\n");
spa_loop_control_leave(data->control);
return NULL;
}
@ -507,6 +465,22 @@ int main(int argc, char *argv[])
struct data data = { 0 };
int res;
const char *str;
struct spa_handle *handle = NULL;
void *iface;
if ((res = load_handle(&data, &handle, PATH "support/libspa-support.so", "loop")) < 0)
return res;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Loop, &iface)) < 0) {
printf("can't get interface %d\n", res);
return res;
}
data.loop = iface;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_LoopControl, &iface)) < 0) {
printf("can't get interface %d\n", res);
return res;
}
data.control = iface;
data.use_buffer = true;
@ -515,15 +489,9 @@ int main(int argc, char *argv[])
if ((str = getenv("SPA_DEBUG")))
data.log->level = atoi(str);
data.data_loop.version = SPA_VERSION_LOOP;
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;
data.data_loop.remove_source = do_remove_source;
data.data_loop.invoke = do_invoke;
data.support[0] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Log, data.log);
data.support[1] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_MainLoop, &data.data_loop);
data.support[2] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_DataLoop, &data.data_loop);
data.support[1] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_MainLoop, data.loop);
data.support[2] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_DataLoop, data.loop);
data.n_support = 3;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {

View file

@ -32,6 +32,7 @@ extern "C" {
struct spa_node;
#include <spa/utils/defs.h>
#include <spa/utils/result.h>
#include <spa/utils/type.h>
#include <spa/support/plugin.h>
@ -97,14 +98,6 @@ struct spa_node_callbacks {
#define SPA_VERSION_NODE_CALLBACKS 0
uint32_t version; /**< version of this structure */
/** Emited as a reply to a sync method with \a seq.
*
* Will be called from the main thread. */
int (*done) (void *data, uint32_t seq);
/** an asynchronous error occured */
int (*error) (void *data, int res, const char *message);
/** Emited when info changes */
int (*info) (void *data, const struct spa_node_info *info);
@ -156,6 +149,12 @@ struct spa_node_callbacks {
#define SPA_NODE_PARAM_FLAG_NEAREST (1 << 2) /* allow set fields to be rounded to the
* nearest allowed field value. */
/** the result of enum_param. */
struct spa_result_node_enum_params {
uint32_t next; /**< next index of iteration */
struct spa_pod *param; /**< the result param */
};
/**
* A spa_node is a component that can consume and produce buffers.
*/
@ -182,13 +181,46 @@ struct spa_node {
/**
* Perform a sync operation.
*
* Calling this method will emit the done event or -EIO when
* no callbacks are installed.
* This method will complete when all previous methods on the node
* are completed.
*
* Because all methods are serialized in the node, this can be used
* to wait for completion of all previous method calls.
*
* If this function returns an async result, use spa_node_wait() to
* install a hook to receive the completion notification.
*
* \return 0 on success
* -EINVAL when node is NULL
* an async result
*/
int (*sync) (struct spa_node *node, uint32_t seq);
int (*sync) (struct spa_node *node);
/**
* Wait for an async function to complete and signal the result
* callback with result parameters.
*
* When a function returns an sync result, pass the async result
* to this function to create a hook that will be called when
* the operation completes.
*
* The generic completion callback can have an optional result.
* Depending on the method, this result will be NULL or point to
* a structure with extra return values. See the documentation
* of the function to see what result structure will be passed.
*
* The hook is automatically removed after the hook is called.
*
* \param node a spa_node
* \param res an async return value to wait for
* \param pending a spa_pending structure
* \param func a result callback
* \param data data passed to \a func
* \return 0 on success
* -EINVAL when node is NULL
*/
int (*wait) (struct spa_node *node, int res, struct spa_pending *pending,
spa_result_func_t func, void *data);
/**
* Enumerate the parameters of a node.
@ -202,23 +234,26 @@ struct spa_node {
*
* \param node a \ref spa_node
* \param id the param id to enumerate
* \param index the index of enumeration, pass 0 for the first item and the
* index is updated to retrieve the next item.
* \param start the index of enumeration, pass 0 for the first item
* \param num the number of parameters to enumerate
* \param filter and optional filter to use
* \param param result param or NULL
* \param builder builder for the param object.
* \return 1 on success and \a param contains the result
* 0 when there are no more parameters to enumerate
* \param func the callback with the result. The result will be
* of type struct spa_result_node_enum_params. The next field
* can be used to continue the enumeration.
* \param data first argument to \a func
*
* \return the return value of \a func or 0 when no more
* items can be iterated.
* -EINVAL when invalid arguments are given
* -ENOENT the parameter \a id is unknown
* -ENOTSUP when there are no parameters
* implemented on \a node
*/
int (*enum_params) (struct spa_node *node,
uint32_t id, uint32_t *index,
uint32_t id, uint32_t start, uint32_t max,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder);
spa_result_func_t func, void *data);
/**
* Set the configurable parameter in \a node.
*
@ -318,22 +353,25 @@ struct spa_node {
* \param direction an spa_direction
* \param port_id the port to query
* \param id the parameter id to query
* \param index an index state variable, 0 to get the first item
* \param start the first index to query, 0 to get the first item
* \param num the maximum number of params to query
* \param filter a parameter filter or NULL for no filter
* \param param result parameter
* \param builder a builder for the result parameter object
* \return 1 on success
* \param func the callback with the result. The result will be
* of type struct spa_result_node_enum_params. The next field
* can be used to continue the enumeration.
* \param data first argument to \a func
*
* \return the return value of \a func or 0 when no more
* items can be iterated.
* 0 when no more parameters exists
* -EINVAL when invalid parameters are given
* -ENOENT when \a id is unknown
*/
int (*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 **param,
struct spa_pod_builder *builder);
spa_result_func_t func, void *data);
/**
* Set a parameter on \a port_id of \a node.
*
@ -497,7 +535,8 @@ struct spa_node {
};
#define spa_node_set_callbacks(n,...) (n)->set_callbacks((n),__VA_ARGS__)
#define spa_node_sync(n,...) (n)->sync((n),__VA_ARGS__)
#define spa_node_sync(n) (n)->sync((n))
#define spa_node_wait(n,...) (n)->wait((n),__VA_ARGS__)
#define spa_node_enum_params(n,...) (n)->enum_params((n),__VA_ARGS__)
#define spa_node_set_param(n,...) (n)->set_param((n),__VA_ARGS__)
#define spa_node_set_io(n,...) (n)->set_io((n),__VA_ARGS__)

View file

@ -0,0 +1,95 @@
/* Simple Plugin API
*
* Copyright © 2019 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_NODE_UTILS_H
#define SPA_NODE_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/node/node.h>
struct spa_result_node_enum_params_data {
struct spa_pod_builder *builder;
struct spa_result_node_enum_params data;
};
static inline int spa_result_func_node_enum_params(void *data,
int seq, int res, const void *result)
{
struct spa_result_node_enum_params_data *d =
(struct spa_result_node_enum_params_data *)data;
const struct spa_result_node_enum_params *r =
(const struct spa_result_node_enum_params *)result;
if (res == 1) {
uint32_t offset = d->builder->state.offset;
spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
d->data.next = r->next;
d->data.param = SPA_MEMBER(d->builder->data, offset, struct spa_pod);
}
return res;
}
static inline int spa_node_enum_params_sync(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct spa_result_node_enum_params_data data = { builder, };
int res;
if ((res = spa_node_enum_params(node, id, *index, 1,
filter, spa_result_func_node_enum_params, &data)) != 1)
return res;
*index = data.data.next;
*param = data.data.param;
return res;
}
static inline int spa_node_port_enum_params_sync(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 **param,
struct spa_pod_builder *builder)
{
struct spa_result_node_enum_params_data data = { builder, };
int res;
if ((res = spa_node_port_enum_params(node, direction, port_id, id, *index, 1,
filter, spa_result_func_node_enum_params, &data)) != 1)
return res;
*index = data.data.next;
*param = data.data.param;
return res;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_NODE_UTILS_H */

View file

@ -629,6 +629,19 @@ static inline int spa_pod_builder_add(struct spa_pod_builder *builder, ...)
spa_pod_builder_pop(b, &f); \
})
/** Copy a pod structure */
static inline struct spa_pod *
spa_pod_copy(const struct spa_pod *pod)
{
size_t size;
struct spa_pod *c;
size = SPA_POD_SIZE(pod);
if ((c = (struct spa_pod *) malloc(size)) == NULL)
return NULL;
return (struct spa_pod *) memcpy(c, pod, size);
}
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -36,6 +36,7 @@ struct spa_source;
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#include <spa/utils/result.h>
enum spa_io {
SPA_IO_IN = (1 << 0),

View file

@ -36,18 +36,6 @@ extern "C" {
#include <stddef.h>
#include <stdio.h>
#define SPA_ASYNC_BIT (1 << 30)
#define SPA_ASYNC_MASK (3 << 30)
#define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1)
#define SPA_RESULT_IS_OK(res) ((res) >= 0)
#define SPA_RESULT_IS_ERROR(res) ((res) < 0)
#define SPA_RESULT_IS_ASYNC(res) (((res) & SPA_ASYNC_MASK) == SPA_ASYNC_BIT)
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | ((seq) & SPA_ASYNC_SEQ_MASK))
#define SPA_FLAG_MASK(field,mask,flag) (((field) & (mask)) == (flag))
#define SPA_FLAG_CHECK(field,flag) SPA_FLAG_MASK(field,flag,flag)
#define SPA_FLAG_SET(field,flag) ((field) |= (flag))

View file

@ -0,0 +1,61 @@
/* Simple Plugin API
*
* Copyright © 2018 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_UTILS_RESULT_H
#define SPA_UTILS_RESULT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/list.h>
#define SPA_ASYNC_BIT (1 << 30)
#define SPA_ASYNC_MASK (3 << 30)
#define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1)
#define SPA_RESULT_IS_OK(res) ((res) >= 0)
#define SPA_RESULT_IS_ERROR(res) ((res) < 0)
#define SPA_RESULT_IS_ASYNC(res) (((res) & SPA_ASYNC_MASK) == SPA_ASYNC_BIT)
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq))
typedef int (*spa_result_func_t) (void *data, int seq, int res, const void *result);
struct spa_pending {
struct spa_list link;
int seq;
int res;
spa_result_func_t func;
void *data;
void (*removed) (struct spa_pending *pending);
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_UTILS_RESULT_H */

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)

View file

@ -32,6 +32,7 @@
#include <spa/support/log-impl.h>
#include <spa/support/loop.h>
#include <spa/node/node.h>
#include <spa/node/utils.h>
#include <spa/pod/parser.h>
#include <spa/param/param.h>
#include <spa/param/format.h>
@ -63,9 +64,9 @@ inspect_node_params(struct data *data, struct spa_node *node)
uint32_t id;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_enum_params(node,
if ((res = spa_node_enum_params_sync(node,
SPA_PARAM_List, &idx1,
NULL, &param, &b)) <= 0) {
NULL, &param, &b)) != 1) {
if (res != 0)
error(0, -res, "enum_params");
break;
@ -78,9 +79,9 @@ inspect_node_params(struct data *data, struct spa_node *node)
printf("enumerating: %s:\n", spa_debug_type_find_name(spa_type_param, id));
for (idx2 = 0;;) {
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_enum_params(node,
if ((res = spa_node_enum_params_sync(node,
id, &idx2,
NULL, &param, &b)) <= 0) {
NULL, &param, &b)) != 1) {
if (res != 0)
error(0, -res, "enum_params %d", id);
break;
@ -104,10 +105,10 @@ inspect_port_params(struct data *data, struct spa_node *node,
uint32_t id;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_port_enum_params(node,
if ((res = spa_node_port_enum_params_sync(node,
direction, port_id,
SPA_PARAM_List, &idx1,
NULL, &param, &b)) <= 0) {
NULL, &param, &b)) != 1) {
if (res != 0)
error(0, -res, "port_enum_params");
break;
@ -119,10 +120,10 @@ inspect_port_params(struct data *data, struct spa_node *node,
printf("enumerating: %s:\n", spa_debug_type_find_name(spa_type_param, id));
for (idx2 = 0;;) {
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_port_enum_params(node,
if ((res = spa_node_port_enum_params_sync(node,
direction, port_id,
id, &idx2,
NULL, &param, &b)) <= 0) {
NULL, &param, &b)) != 1) {
if (res != 0)
error(0, -res, "port_enum_params");
break;