node: improve pending results

Make a special function for pending results to make it clear that it
is different from normal results. Don't pass result code to result
function, it is not useful because since the callback is called, all
must be fine.

The spa_pending is removed from the list right before the callback
and can thus be freed in the callback. Pass the spa_pending in
the pending callback so that extra data can be added that way.

Reuse spa_pending objects in link and nodes instead of allocating. We
always only have one pending operation and we can cancel any pending
previous operation by removing the pending.
This commit is contained in:
Wim Taymans 2019-02-21 12:14:25 +01:00
parent a3ca2df0fe
commit 98463b689b
33 changed files with 126 additions and 156 deletions

View file

@ -212,15 +212,15 @@ struct spa_node {
* 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 seq 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);
int (*wait) (struct spa_node *node, int seq, struct spa_pending *pending,
spa_pending_func_t func, void *data);
/**
* Enumerate the parameters of a node.

View file

@ -37,20 +37,17 @@ 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)
uint32_t count, 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;
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 1;
}
static inline int spa_node_enum_params_sync(struct spa_node *node,

View file

@ -43,15 +43,18 @@ extern "C" {
#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);
typedef int (*spa_result_func_t) (void *data, uint32_t count, const void *result);
struct spa_pending;
typedef int (*spa_pending_func_t) (struct spa_pending *pending, 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);
struct spa_list link; /**< link used internally */
int seq; /**< sequence number of pending result */
int res; /**< result code of operation */
spa_pending_func_t func; /**< callback function */
void *data; /**< extra user data */
};
#ifdef __cplusplus

View file

@ -159,7 +159,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -437,7 +437,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -155,7 +155,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -434,7 +434,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -359,7 +359,7 @@ spa_alsa_enum_format(struct state *state, uint32_t start, uint32_t num,
if ((res = spa_pod_filter(&b, &result.param, fmt, filter)) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
goto exit;
if (++count != num)

View file

@ -443,7 +443,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -715,7 +715,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -518,7 +518,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -806,7 +806,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -489,7 +489,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -208,7 +208,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -513,7 +513,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -450,7 +450,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -206,7 +206,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -510,7 +510,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -438,7 +438,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -238,7 +238,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -665,7 +665,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -232,7 +232,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -1050,7 +1050,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -261,7 +261,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -255,7 +255,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -147,7 +147,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -491,7 +491,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -157,7 +157,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -508,7 +508,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -146,8 +146,8 @@ 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)
static int impl_node_wait(struct spa_node *node, int seq, struct spa_pending *pending,
spa_pending_func_t func, void *data)
{
return -ENOTSUP;
}
@ -247,7 +247,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -574,7 +574,7 @@ static int impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -812,7 +812,7 @@ spa_v4l2_enum_format(struct impl *this,
result.param = spa_pod_builder_pop(&b, &f[0]);
result.next++;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
goto exit;
if (++count != num)
@ -1142,7 +1142,7 @@ spa_v4l2_enum_controls(struct impl *this,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
goto exit;
if (++count != num)

View file

@ -207,7 +207,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -591,7 +591,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)

View file

@ -183,7 +183,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)
@ -434,7 +434,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
if ((res = func(data, count, 1, &result)) != 0)
if ((res = func(data, count, &result)) != 0)
return res;
if (++count != num)