libv4l: Check a cam has the necessary controls before enabling autogain
authorHans de Goede <hdegoede@redhat.com>
Fri, 9 Oct 2009 07:45:17 +0000 (09:45 +0200)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 24 Feb 2010 00:44:39 +0000 (21:44 -0300)
Priority: normal

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
lib/libv4lconvert/control/libv4lcontrol.c

index f083e81..0040e5c 100644 (file)
@@ -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")))