* [RFC PATCH 1/3] [media] gspca - main: rename get_ctrl to get_ctrl_index
2012-04-20 15:19 ` [RFC PATCH 0/3] gspca: Implement VIDIOC_G_EXT_CTRLS and VIDIOC_S_EXT_CTRLS Antonio Ospite
@ 2012-04-20 15:19 ` Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 2/3] [media] gspca - main: factor out the logic to set and get controls Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls Antonio Ospite
2 siblings, 0 replies; 12+ messages in thread
From: Antonio Ospite @ 2012-04-20 15:19 UTC (permalink / raw)
To: linux-media; +Cc: Antonio Ospite, Jean-Francois Moine, Erik Andrén
This reflects better what the function does and is also in preparation
of a refactoring of setting and getting controls.
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---
drivers/media/video/gspca/gspca.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index ca5a2b1..bc9d037 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -1415,7 +1415,7 @@ out:
return ret;
}
-static int get_ctrl(struct gspca_dev *gspca_dev,
+static int get_ctrl_index(struct gspca_dev *gspca_dev,
int id)
{
const struct ctrl *ctrls;
@@ -1458,7 +1458,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
idx = i;
}
} else {
- idx = get_ctrl(gspca_dev, id);
+ idx = get_ctrl_index(gspca_dev, id);
}
if (idx < 0)
return -EINVAL;
@@ -1483,7 +1483,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct gspca_ctrl *gspca_ctrl;
int idx, ret;
- idx = get_ctrl(gspca_dev, ctrl->id);
+ idx = get_ctrl_index(gspca_dev, ctrl->id);
if (idx < 0)
return -EINVAL;
if (gspca_dev->ctrl_inac & (1 << idx))
@@ -1531,7 +1531,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
const struct ctrl *ctrls;
int idx, ret;
- idx = get_ctrl(gspca_dev, ctrl->id);
+ idx = get_ctrl_index(gspca_dev, ctrl->id);
if (idx < 0)
return -EINVAL;
ctrls = &gspca_dev->sd_desc->ctrls[idx];
--
1.7.10
^ permalink raw reply related [flat|nested] 12+ messages in thread* [RFC PATCH 2/3] [media] gspca - main: factor out the logic to set and get controls
2012-04-20 15:19 ` [RFC PATCH 0/3] gspca: Implement VIDIOC_G_EXT_CTRLS and VIDIOC_S_EXT_CTRLS Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 1/3] [media] gspca - main: rename get_ctrl to get_ctrl_index Antonio Ospite
@ 2012-04-20 15:19 ` Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls Antonio Ospite
2 siblings, 0 replies; 12+ messages in thread
From: Antonio Ospite @ 2012-04-20 15:19 UTC (permalink / raw)
To: linux-media; +Cc: Antonio Ospite, Jean-Francois Moine, Erik Andrén
Factor out the logic to set and get controls from vidioc_s_ctrl()
and vidioc_g_ctrl() so that the code can be reused in the coming
implementation of vidioc_s_ext_ctrls() and vidioc_g_ext_ctrls().
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---
drivers/media/video/gspca/gspca.c | 148 ++++++++++++++++++++-----------------
1 file changed, 80 insertions(+), 68 deletions(-)
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index bc9d037..ba1bda9 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -1432,6 +1432,84 @@ static int get_ctrl_index(struct gspca_dev *gspca_dev,
return -1;
}
+static int gspca_set_ctrl(struct gspca_dev *gspca_dev,
+ __u32 id, __s32 value)
+{
+ const struct ctrl *ctrls;
+ struct gspca_ctrl *gspca_ctrl;
+ int idx, ret;
+
+ idx = get_ctrl_index(gspca_dev, id);
+ if (idx < 0)
+ return -EINVAL;
+ if (gspca_dev->ctrl_inac & (1 << idx))
+ return -EINVAL;
+ ctrls = &gspca_dev->sd_desc->ctrls[idx];
+ if (gspca_dev->cam.ctrls != NULL) {
+ gspca_ctrl = &gspca_dev->cam.ctrls[idx];
+ if (value < gspca_ctrl->min
+ || value > gspca_ctrl->max)
+ return -ERANGE;
+ } else {
+ gspca_ctrl = NULL;
+ if (value < ctrls->qctrl.minimum
+ || value > ctrls->qctrl.maximum)
+ return -ERANGE;
+ }
+ PDEBUG(D_CONF, "set ctrl [%08x] = %d", id, value);
+ if (mutex_lock_interruptible(&gspca_dev->usb_lock))
+ return -ERESTARTSYS;
+ if (!gspca_dev->present) {
+ ret = -ENODEV;
+ goto out;
+ }
+ gspca_dev->usb_err = 0;
+ if (ctrls->set != NULL) {
+ ret = ctrls->set(gspca_dev, value);
+ goto out;
+ }
+ if (gspca_ctrl != NULL) {
+ gspca_ctrl->val = value;
+ if (ctrls->set_control != NULL
+ && gspca_dev->streaming)
+ ctrls->set_control(gspca_dev);
+ }
+ ret = gspca_dev->usb_err;
+out:
+ mutex_unlock(&gspca_dev->usb_lock);
+ return ret;
+}
+
+static int gspca_get_ctrl(struct gspca_dev *gspca_dev,
+ __u32 id, __s32 *value)
+{
+ const struct ctrl *ctrls;
+ int idx, ret;
+
+ idx = get_ctrl_index(gspca_dev, id);
+ if (idx < 0)
+ return -EINVAL;
+ ctrls = &gspca_dev->sd_desc->ctrls[idx];
+
+ if (mutex_lock_interruptible(&gspca_dev->usb_lock))
+ return -ERESTARTSYS;
+ if (!gspca_dev->present) {
+ ret = -ENODEV;
+ goto out;
+ }
+ gspca_dev->usb_err = 0;
+ if (ctrls->get != NULL) {
+ ret = ctrls->get(gspca_dev, value);
+ goto out;
+ }
+ if (gspca_dev->cam.ctrls != NULL)
+ *value = gspca_dev->cam.ctrls[idx].val;
+ ret = 0;
+out:
+ mutex_unlock(&gspca_dev->usb_lock);
+ return ret;
+}
+
static int vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *q_ctrl)
{
@@ -1479,80 +1557,14 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct gspca_dev *gspca_dev = priv;
- const struct ctrl *ctrls;
- struct gspca_ctrl *gspca_ctrl;
- int idx, ret;
-
- idx = get_ctrl_index(gspca_dev, ctrl->id);
- if (idx < 0)
- return -EINVAL;
- if (gspca_dev->ctrl_inac & (1 << idx))
- return -EINVAL;
- ctrls = &gspca_dev->sd_desc->ctrls[idx];
- if (gspca_dev->cam.ctrls != NULL) {
- gspca_ctrl = &gspca_dev->cam.ctrls[idx];
- if (ctrl->value < gspca_ctrl->min
- || ctrl->value > gspca_ctrl->max)
- return -ERANGE;
- } else {
- gspca_ctrl = NULL;
- if (ctrl->value < ctrls->qctrl.minimum
- || ctrl->value > ctrls->qctrl.maximum)
- return -ERANGE;
- }
- PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value);
- if (mutex_lock_interruptible(&gspca_dev->usb_lock))
- return -ERESTARTSYS;
- if (!gspca_dev->present) {
- ret = -ENODEV;
- goto out;
- }
- gspca_dev->usb_err = 0;
- if (ctrls->set != NULL) {
- ret = ctrls->set(gspca_dev, ctrl->value);
- goto out;
- }
- if (gspca_ctrl != NULL) {
- gspca_ctrl->val = ctrl->value;
- if (ctrls->set_control != NULL
- && gspca_dev->streaming)
- ctrls->set_control(gspca_dev);
- }
- ret = gspca_dev->usb_err;
-out:
- mutex_unlock(&gspca_dev->usb_lock);
- return ret;
+ return gspca_set_ctrl(gspca_dev, ctrl->id, ctrl->value);
}
static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct gspca_dev *gspca_dev = priv;
- const struct ctrl *ctrls;
- int idx, ret;
-
- idx = get_ctrl_index(gspca_dev, ctrl->id);
- if (idx < 0)
- return -EINVAL;
- ctrls = &gspca_dev->sd_desc->ctrls[idx];
-
- if (mutex_lock_interruptible(&gspca_dev->usb_lock))
- return -ERESTARTSYS;
- if (!gspca_dev->present) {
- ret = -ENODEV;
- goto out;
- }
- gspca_dev->usb_err = 0;
- if (ctrls->get != NULL) {
- ret = ctrls->get(gspca_dev, &ctrl->value);
- goto out;
- }
- if (gspca_dev->cam.ctrls != NULL)
- ctrl->value = gspca_dev->cam.ctrls[idx].val;
- ret = 0;
-out:
- mutex_unlock(&gspca_dev->usb_lock);
- return ret;
+ return gspca_get_ctrl(gspca_dev, ctrl->id, &ctrl->value);
}
static int vidioc_querymenu(struct file *file, void *priv,
--
1.7.10
^ permalink raw reply related [flat|nested] 12+ messages in thread* [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls
2012-04-20 15:19 ` [RFC PATCH 0/3] gspca: Implement VIDIOC_G_EXT_CTRLS and VIDIOC_S_EXT_CTRLS Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 1/3] [media] gspca - main: rename get_ctrl to get_ctrl_index Antonio Ospite
2012-04-20 15:19 ` [RFC PATCH 2/3] [media] gspca - main: factor out the logic to set and get controls Antonio Ospite
@ 2012-04-20 15:19 ` Antonio Ospite
2012-04-27 8:20 ` Hans Verkuil
2 siblings, 1 reply; 12+ messages in thread
From: Antonio Ospite @ 2012-04-20 15:19 UTC (permalink / raw)
To: linux-media; +Cc: Antonio Ospite, Jean-Francois Moine, Erik Andrén
This makes it possible for applications to handle controls with a class
different than V4L2_CTRL_CLASS_USER for gspca subdevices, like for
instance V4L2_CID_EXPOSURE_AUTO which some subdrivers use and which
can't be controlled right now.
See
http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/47010
for an example of a problem fixed by this change.
NOTE: gspca currently won't handle control types like
V4L2_CTRL_TYPE_INTEGER64 or V4L2_CTRL_TYPE_STRING, so just the
__s32 field 'value' of 'struct v4l2_ext_control' is handled for now.
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---
drivers/media/video/gspca/gspca.c | 42 +++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index ba1bda9..7906093 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -1567,6 +1567,46 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
return gspca_get_ctrl(gspca_dev, ctrl->id, &ctrl->value);
}
+static int vidioc_s_ext_ctrls(struct file *file, void *priv,
+ struct v4l2_ext_controls *ext_ctrls)
+{
+ struct gspca_dev *gspca_dev = priv;
+ int ret = 0;
+ int i;
+
+ for (i = 0; i < ext_ctrls->count; i++) {
+ struct v4l2_ext_control *ctrl;
+
+ ctrl = ext_ctrls->controls + i;
+ ret = gspca_set_ctrl(gspca_dev, ctrl->id, ctrl->value);
+ if (ret < 0) {
+ ext_ctrls->error_idx = i;
+ return ret;
+ }
+ }
+ return ret;
+}
+
+static int vidioc_g_ext_ctrls(struct file *file, void *priv,
+ struct v4l2_ext_controls *ext_ctrls)
+{
+ struct gspca_dev *gspca_dev = priv;
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < ext_ctrls->count; i++) {
+ struct v4l2_ext_control *ctrl;
+
+ ctrl = ext_ctrls->controls + i;
+ ret = gspca_get_ctrl(gspca_dev, ctrl->id, &ctrl->value);
+ if (ret < 0) {
+ ext_ctrls->error_idx = i;
+ return ret;
+ }
+ }
+ return ret;
+}
+
static int vidioc_querymenu(struct file *file, void *priv,
struct v4l2_querymenu *qmenu)
{
@@ -2260,6 +2300,8 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
.vidioc_queryctrl = vidioc_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
+ .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
+ .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
.vidioc_querymenu = vidioc_querymenu,
.vidioc_enum_input = vidioc_enum_input,
.vidioc_g_input = vidioc_g_input,
--
1.7.10
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls
2012-04-20 15:19 ` [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls Antonio Ospite
@ 2012-04-27 8:20 ` Hans Verkuil
2012-04-27 9:24 ` Jean-Francois Moine
0 siblings, 1 reply; 12+ messages in thread
From: Hans Verkuil @ 2012-04-27 8:20 UTC (permalink / raw)
To: Antonio Ospite; +Cc: linux-media, Jean-Francois Moine, Erik Andrén
Hi Antonio,
My apologies for the late review, I missed this the first time around.
Since I am the 'control guy' :-) I thought I should give my view on this.
And that is the real long-term approach to implementing extended controls
in gspca is to add support in gspca for the control framework (see
Documentation/video4linux/v4l2-controls.txt). That will probably simplify
control handling in gspca anyway. The main problem is how to do it in such
a manner that we can convert gspca drivers to the control framework one by
one.
I am inclined to NACK code that adds a driver-specific extended control
implementation instead of going to the control framework because I know
from painful personal experience that it is very hard to get it right.
I might have some time (no guarantees yet) to help with this. It would
certainly be interesting to add support for the control framework in the
gspca core. Hmm, perhaps that's a job for the weekend...
Regards,
Hans
On Friday, April 20, 2012 17:19:11 Antonio Ospite wrote:
> This makes it possible for applications to handle controls with a class
> different than V4L2_CTRL_CLASS_USER for gspca subdevices, like for
> instance V4L2_CID_EXPOSURE_AUTO which some subdrivers use and which
> can't be controlled right now.
>
> See
> http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/47010
> for an example of a problem fixed by this change.
>
> NOTE: gspca currently won't handle control types like
> V4L2_CTRL_TYPE_INTEGER64 or V4L2_CTRL_TYPE_STRING, so just the
> __s32 field 'value' of 'struct v4l2_ext_control' is handled for now.
>
> Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
> ---
> drivers/media/video/gspca/gspca.c | 42 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
> index ba1bda9..7906093 100644
> --- a/drivers/media/video/gspca/gspca.c
> +++ b/drivers/media/video/gspca/gspca.c
> @@ -1567,6 +1567,46 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
> return gspca_get_ctrl(gspca_dev, ctrl->id, &ctrl->value);
> }
>
> +static int vidioc_s_ext_ctrls(struct file *file, void *priv,
> + struct v4l2_ext_controls *ext_ctrls)
> +{
> + struct gspca_dev *gspca_dev = priv;
> + int ret = 0;
> + int i;
> +
> + for (i = 0; i < ext_ctrls->count; i++) {
> + struct v4l2_ext_control *ctrl;
> +
> + ctrl = ext_ctrls->controls + i;
> + ret = gspca_set_ctrl(gspca_dev, ctrl->id, ctrl->value);
> + if (ret < 0) {
> + ext_ctrls->error_idx = i;
> + return ret;
> + }
> + }
> + return ret;
> +}
> +
> +static int vidioc_g_ext_ctrls(struct file *file, void *priv,
> + struct v4l2_ext_controls *ext_ctrls)
> +{
> + struct gspca_dev *gspca_dev = priv;
> + int i;
> + int ret = 0;
> +
> + for (i = 0; i < ext_ctrls->count; i++) {
> + struct v4l2_ext_control *ctrl;
> +
> + ctrl = ext_ctrls->controls + i;
> + ret = gspca_get_ctrl(gspca_dev, ctrl->id, &ctrl->value);
> + if (ret < 0) {
> + ext_ctrls->error_idx = i;
> + return ret;
> + }
> + }
> + return ret;
> +}
> +
> static int vidioc_querymenu(struct file *file, void *priv,
> struct v4l2_querymenu *qmenu)
> {
> @@ -2260,6 +2300,8 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
> .vidioc_queryctrl = vidioc_queryctrl,
> .vidioc_g_ctrl = vidioc_g_ctrl,
> .vidioc_s_ctrl = vidioc_s_ctrl,
> + .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
> + .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
> .vidioc_querymenu = vidioc_querymenu,
> .vidioc_enum_input = vidioc_enum_input,
> .vidioc_g_input = vidioc_g_input,
>
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls
2012-04-27 8:20 ` Hans Verkuil
@ 2012-04-27 9:24 ` Jean-Francois Moine
2012-04-27 9:34 ` Hans Verkuil
2012-04-27 10:51 ` Hans de Goede
0 siblings, 2 replies; 12+ messages in thread
From: Jean-Francois Moine @ 2012-04-27 9:24 UTC (permalink / raw)
To: Hans Verkuil; +Cc: Antonio Ospite, linux-media, Erik Andrén
On Fri, 27 Apr 2012 10:20:23 +0200
Hans Verkuil <hverkuil@xs4all.nl> wrote:
> I might have some time (no guarantees yet) to help with this. It would
> certainly be interesting to add support for the control framework in the
> gspca core. Hmm, perhaps that's a job for the weekend...
Hi Hans,
I hope you will not do it! The way gspca treats the controls is static,
quick and very small. The controls in the subdrivers ask only for the
declaration of the controls and functions to send the values to the
webcams. Actually, not all subdrivers have been converted to the new
gspca control handling, but, when done, it will save more memory.
Best regards.
--
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls
2012-04-27 9:24 ` Jean-Francois Moine
@ 2012-04-27 9:34 ` Hans Verkuil
2012-04-27 10:51 ` Hans de Goede
1 sibling, 0 replies; 12+ messages in thread
From: Hans Verkuil @ 2012-04-27 9:34 UTC (permalink / raw)
To: Jean-Francois Moine; +Cc: Antonio Ospite, linux-media, Erik Andrén
On Friday, April 27, 2012 11:24:43 Jean-Francois Moine wrote:
> On Fri, 27 Apr 2012 10:20:23 +0200
> Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> > I might have some time (no guarantees yet) to help with this. It would
> > certainly be interesting to add support for the control framework in the
> > gspca core. Hmm, perhaps that's a job for the weekend...
>
> Hi Hans,
>
> I hope you will not do it! The way gspca treats the controls is static,
> quick and very small. The controls in the subdrivers ask only for the
> declaration of the controls and functions to send the values to the
> webcams. Actually, not all subdrivers have been converted to the new
> gspca control handling, but, when done, it will save more memory.
And that is exactly what the control framework also does for you. Drivers
only have to declare the controls and have a function to set their value.
Everything else is handled by the control framework. And you get support
for the extended control API for free and also support for control events,
plus any future changes/enhancements to how controls are done will be
automatically added. Not to mention that it ensures consistent and correct
behavior of the control API towards applications.
Note that the control code is already part of videodev.ko, so you have that
code in memory anyway. So why not use it?
Regards,
Hans
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH 3/3] [media] gspca - main: implement vidioc_g_ext_ctrls and vidioc_s_ext_ctrls
2012-04-27 9:24 ` Jean-Francois Moine
2012-04-27 9:34 ` Hans Verkuil
@ 2012-04-27 10:51 ` Hans de Goede
1 sibling, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2012-04-27 10:51 UTC (permalink / raw)
To: Jean-Francois Moine
Cc: Hans Verkuil, Antonio Ospite, linux-media, Erik Andrén
Hi,
On 04/27/2012 11:24 AM, Jean-Francois Moine wrote:
> On Fri, 27 Apr 2012 10:20:23 +0200
> Hans Verkuil<hverkuil@xs4all.nl> wrote:
>
>> I might have some time (no guarantees yet) to help with this. It would
>> certainly be interesting to add support for the control framework in the
>> gspca core. Hmm, perhaps that's a job for the weekend...
>
> Hi Hans,
>
> I hope you will not do it! The way gspca treats the controls is static,
> quick and very small. The controls in the subdrivers ask only for the
> declaration of the controls and functions to send the values to the
> webcams. Actually, not all subdrivers have been converted to the new
> gspca control handling, but, when done, it will save more memory.
Actually I've moving gspca over to the control framework on my to-do
list. This will allows us to remove hacks like we have in sonixb.c for
coarse exposure / fine exposure controls. More in general it will allow
(in an easy way) to have per sensor control min/max/step values.
But the most important reason for me to want to use the control framework
in gspca is to get support for control events. Which allow a control-panel
app to dynamically update its display when settings are changed to some
other way (ie another control app, or software autogain).
I do plan to do this in way so that we can do this one subdriver at a
time. I've no idea when I'll get around to doing the first driver
though :)
Regards,
Hans
^ permalink raw reply [flat|nested] 12+ messages in thread