mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
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:
parent
74b1b63c3d
commit
b59766c3d1
2 changed files with 100 additions and 38 deletions
|
|
@ -63,7 +63,8 @@ struct buffer {
|
||||||
struct control {
|
struct control {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
uint32_t ctrl_id;
|
uint32_t ctrl_id;
|
||||||
double value;
|
uint32_t type;
|
||||||
|
int32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct port {
|
struct port {
|
||||||
|
|
@ -148,6 +149,37 @@ struct impl {
|
||||||
|
|
||||||
#include "v4l2-utils.c"
|
#include "v4l2-utils.c"
|
||||||
|
|
||||||
|
static const struct spa_dict_item info_items[] = {
|
||||||
|
{ SPA_KEY_DEVICE_API, "v4l2" },
|
||||||
|
{ SPA_KEY_MEDIA_CLASS, "Video/Source" },
|
||||||
|
{ SPA_KEY_MEDIA_ROLE, "Camera" },
|
||||||
|
{ SPA_KEY_NODE_DRIVER, "true" },
|
||||||
|
};
|
||||||
|
|
||||||
|
static void emit_node_info(struct impl *this, bool full)
|
||||||
|
{
|
||||||
|
uint64_t old = full ? this->info.change_mask : 0;
|
||||||
|
if (full)
|
||||||
|
this->info.change_mask = this->info_all;
|
||||||
|
if (this->info.change_mask) {
|
||||||
|
this->info.props = &SPA_DICT_INIT_ARRAY(info_items);
|
||||||
|
spa_node_emit_info(&this->hooks, &this->info);
|
||||||
|
this->info.change_mask = old;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
||||||
|
{
|
||||||
|
uint64_t old = full ? port->info.change_mask : 0;
|
||||||
|
if (full)
|
||||||
|
port->info.change_mask = port->info_all;
|
||||||
|
if (port->info.change_mask) {
|
||||||
|
spa_node_emit_port_info(&this->hooks,
|
||||||
|
SPA_DIRECTION_OUTPUT, 0, &port->info);
|
||||||
|
port->info.change_mask = old;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int port_get_format(struct port *port,
|
static int port_get_format(struct port *port,
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
const struct spa_pod *filter,
|
const struct spa_pod *filter,
|
||||||
|
|
@ -255,14 +287,40 @@ static int impl_node_enum_params(void *object, int seq,
|
||||||
case SPA_PARAM_Props:
|
case SPA_PARAM_Props:
|
||||||
{
|
{
|
||||||
struct props *p = &this->props;
|
struct props *p = &this->props;
|
||||||
|
struct spa_pod_frame f;
|
||||||
|
struct port *port = &this->out_ports[0];
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
if ((res = spa_v4l2_update_controls(this)) < 0) {
|
||||||
|
spa_log_error(this->log, "error: %s", spa_strerror(res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
switch (result.index) {
|
switch (result.index) {
|
||||||
case 0:
|
case 0:
|
||||||
param = spa_pod_builder_add_object(&b,
|
spa_pod_builder_push_object(&b, &f, SPA_TYPE_OBJECT_Props, id);
|
||||||
SPA_TYPE_OBJECT_Props, id,
|
spa_pod_builder_add(&b,
|
||||||
SPA_PROP_device, SPA_POD_String(p->device),
|
SPA_PROP_device, SPA_POD_String(p->device),
|
||||||
SPA_PROP_deviceName, SPA_POD_String(p->device_name),
|
SPA_PROP_deviceName, SPA_POD_String(p->device_name),
|
||||||
SPA_PROP_deviceFd, SPA_POD_Int(p->device_fd));
|
SPA_PROP_deviceFd, SPA_POD_Int(p->device_fd),
|
||||||
|
0);
|
||||||
|
for (i = 0; i < port->n_controls; i++) {
|
||||||
|
struct control *c = &port->controls[i];
|
||||||
|
|
||||||
|
spa_pod_builder_prop(&b, c->id, 0);
|
||||||
|
switch (c->type) {
|
||||||
|
case SPA_TYPE_Int:
|
||||||
|
spa_pod_builder_int(&b, c->value);
|
||||||
|
break;
|
||||||
|
case SPA_TYPE_Bool:
|
||||||
|
spa_pod_builder_bool(&b, c->value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
spa_pod_builder_int(&b, c->value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
param = spa_pod_builder_pop(&b, &f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -322,7 +380,9 @@ static int impl_node_set_param(void *object,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
|
||||||
|
this->params[NODE_Props].flags ^= SPA_PARAM_INFO_SERIAL;
|
||||||
|
emit_node_info(this, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -399,37 +459,6 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct spa_dict_item info_items[] = {
|
|
||||||
{ SPA_KEY_DEVICE_API, "v4l2" },
|
|
||||||
{ SPA_KEY_MEDIA_CLASS, "Video/Source" },
|
|
||||||
{ SPA_KEY_MEDIA_ROLE, "Camera" },
|
|
||||||
{ SPA_KEY_NODE_DRIVER, "true" },
|
|
||||||
};
|
|
||||||
|
|
||||||
static void emit_node_info(struct impl *this, bool full)
|
|
||||||
{
|
|
||||||
uint64_t old = full ? this->info.change_mask : 0;
|
|
||||||
if (full)
|
|
||||||
this->info.change_mask = this->info_all;
|
|
||||||
if (this->info.change_mask) {
|
|
||||||
this->info.props = &SPA_DICT_INIT_ARRAY(info_items);
|
|
||||||
spa_node_emit_info(&this->hooks, &this->info);
|
|
||||||
this->info.change_mask = old;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
|
||||||
{
|
|
||||||
uint64_t old = full ? port->info.change_mask : 0;
|
|
||||||
if (full)
|
|
||||||
port->info.change_mask = port->info_all;
|
|
||||||
if (port->info.change_mask) {
|
|
||||||
spa_node_emit_port_info(&this->hooks,
|
|
||||||
SPA_DIRECTION_OUTPUT, 0, &port->info);
|
|
||||||
port->info.change_mask = old;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
impl_node_add_listener(void *object,
|
impl_node_add_listener(void *object,
|
||||||
struct spa_hook *listener,
|
struct spa_hook *listener,
|
||||||
|
|
|
||||||
|
|
@ -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);
|
spa_log_debug(this->log, "Control '%s' %d %d", queryctrl.name, prop_id, ctrl_id);
|
||||||
|
|
||||||
port->n_controls++;
|
|
||||||
|
|
||||||
switch (queryctrl.type) {
|
switch (queryctrl.type) {
|
||||||
case V4L2_CTRL_TYPE_INTEGER:
|
case V4L2_CTRL_TYPE_INTEGER:
|
||||||
|
port->controls[port->n_controls].type = SPA_TYPE_Int;
|
||||||
param = spa_pod_builder_add_object(&b,
|
param = spa_pod_builder_add_object(&b,
|
||||||
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
|
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
|
||||||
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
|
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));
|
SPA_PROP_INFO_description, SPA_POD_String(queryctrl.name));
|
||||||
break;
|
break;
|
||||||
case V4L2_CTRL_TYPE_BOOLEAN:
|
case V4L2_CTRL_TYPE_BOOLEAN:
|
||||||
|
port->controls[port->n_controls].type = SPA_TYPE_Bool;
|
||||||
param = spa_pod_builder_add_object(&b,
|
param = spa_pod_builder_add_object(&b,
|
||||||
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
|
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
|
||||||
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
|
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 v4l2_querymenu querymenu;
|
||||||
struct spa_pod_builder_state state;
|
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_push_object(&b, &f[0], SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo);
|
||||||
spa_pod_builder_add(&b,
|
spa_pod_builder_add(&b,
|
||||||
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
|
SPA_PROP_INFO_id, SPA_POD_Id(prop_id),
|
||||||
|
|
@ -1205,6 +1206,9 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port->n_controls++;
|
||||||
|
|
||||||
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
|
|
@ -1219,6 +1223,35 @@ spa_v4l2_enum_controls(struct impl *this, int seq,
|
||||||
return res;
|
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
|
static int
|
||||||
spa_v4l2_set_control(struct impl *this, uint32_t id,
|
spa_v4l2_set_control(struct impl *this, uint32_t id,
|
||||||
const struct spa_pod_prop *prop)
|
const struct spa_pod_prop *prop)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue