mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
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:
parent
b743518f78
commit
7b12212eeb
67 changed files with 1894 additions and 1209 deletions
|
|
@ -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, ¶m, &b)) <= 0)
|
||||
if((res = port_get_format(node, direction, port_id,
|
||||
result.next, filter, ¶m, &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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue