From 2559c7e713cdff44ffee959f6dd1f12838eac3a9 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Fri, 9 Oct 2009 09:45:17 +0200 Subject: [PATCH] libv4l: Check a cam has the necessary controls before enabling autogain Priority: normal Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- lib/libv4lconvert/control/libv4lcontrol.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/libv4lconvert/control/libv4lcontrol.c b/lib/libv4lconvert/control/libv4lcontrol.c index f083e81..0040e5c 100644 --- a/lib/libv4lconvert/control/libv4lcontrol.c +++ b/lib/libv4lconvert/control/libv4lcontrol.c @@ -412,16 +412,30 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion) } } - /* Check if a camera does not have hardware autogain, before enabling - software autogain, even if this is requested by flags. This is necessary - because some cameras share a USB-ID, but can have different sensors - with / without autogain (046d:0840 for example) */ - ctrl.id = V4L2_CID_AUTOGAIN; - rc = SYS_IOCTL(data->fd, VIDIOC_QUERYCTRL, &ctrl); - if ((data->flags & V4LCONTROL_WANTS_AUTOGAIN) && - (rc == -1 || (rc == 0 && (ctrl.flags & V4L2_CTRL_FLAG_DISABLED)))) + /* Check if a camera does not have hardware autogain and has the necessary + controls, before enabling sw autogain, even if this is requested by flags. + This is necessary because some cameras share a USB-ID, but can have + different sensors with / without autogain or the necessary controls. */ + while (data->flags & V4LCONTROL_WANTS_AUTOGAIN) { + ctrl.id = V4L2_CID_AUTOGAIN; + rc = SYS_IOCTL(data->fd, VIDIOC_QUERYCTRL, &ctrl); + if (rc == 0 && !(ctrl.flags & V4L2_CTRL_FLAG_DISABLED)) + break; + + ctrl.id = V4L2_CID_EXPOSURE; + rc = SYS_IOCTL(data->fd, VIDIOC_QUERYCTRL, &ctrl); + if (rc != 0 || (ctrl.flags & V4L2_CTRL_FLAG_DISABLED)) + break; + + ctrl.id = V4L2_CID_GAIN; + rc = SYS_IOCTL(data->fd, VIDIOC_QUERYCTRL, &ctrl); + if (rc != 0 || (ctrl.flags & V4L2_CTRL_FLAG_DISABLED)) + break; + data->controls |= 1 << V4LCONTROL_AUTOGAIN | 1 << V4LCONTROL_AUTOGAIN_TARGET; + break; + } /* Allow overriding through environment */ if ((s = getenv("LIBV4LCONTROL_CONTROLS"))) -- 2.7.4