v4l2: add support fot G_CTRL

Get the current values of the controls and add those to the Props.

Emit a Props param changed event when we update properties.
This commit is contained in:
Wim Taymans 2023-04-18 16:27:55 +02:00
parent 74b1b63c3d
commit b59766c3d1
2 changed files with 100 additions and 38 deletions

View file

@ -1139,10 +1139,9 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
spa_log_debug(this->log, "Control '%s' %d %d", queryctrl.name, prop_id, ctrl_id);
port->n_controls++;
switch (queryctrl.type) {
case V4L2_CTRL_TYPE_INTEGER:
port->controls[port->n_controls].type = SPA_TYPE_Int;
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
@ -1154,6 +1153,7 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
SPA_PROP_INFO_description, SPA_POD_String(queryctrl.name));
break;
case V4L2_CTRL_TYPE_BOOLEAN:
port->controls[port->n_controls].type = SPA_TYPE_Bool;
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
@ -1165,6 +1165,7 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
struct v4l2_querymenu querymenu;
struct spa_pod_builder_state state;
port->controls[port->n_controls].type = SPA_TYPE_Int;
spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo);
spa_pod_builder_add(&b,
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
@ -1205,6 +1206,9 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
goto next;
}
port->n_controls++;
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
goto next;
@ -1219,6 +1223,35 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
return res;
}
static int
spa_v4l2_update_controls(struct impl *this)
{
struct port *port = &this->out_ports[0];
struct spa_v4l2_device *dev = &port->dev;
int res;
uint32_t i;
if ((res = spa_v4l2_open(dev, this->props.device)) < 0)
return res;
for (i = 0; i < port->n_controls; i++) {
struct control *c = &port->controls[i];
struct v4l2_control control;
spa_zero(control);
control.id = c->ctrl_id;
if (xioctl(dev->fd, VIDIOC_G_CTRL, &control) < 0) {
res = -errno;
goto done;
}
c->value = control.value;
}
res = 0;
done:
spa_v4l2_close(dev);
return res;
}
static int
spa_v4l2_set_control(struct impl *this, uint32_t id,
const struct spa_pod_prop *prop)