libv4l: Make v4l2_get_control report errors
authorHans de Goede <hdegoede@redhat.com>
Tue, 8 Jun 2010 08:01:20 +0000 (10:01 +0200)
committerHans de Goede <hdegoede@redhat.com>
Tue, 8 Jun 2010 08:01:20 +0000 (10:01 +0200)
And handle those errors at the places calling v4l2_get_control.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
lib/include/libv4l2.h
lib/libv4l1/libv4l1.c
lib/libv4l2/libv4l2.c

index 3ebc781..cc0ab4a 100644 (file)
@@ -81,8 +81,8 @@ LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length);
 LIBV4L_PUBLIC int v4l2_set_control(int fd, int cid, int value);
 
 /* This function returns a value of 0 - 65535, scaled to from the actual range
-   of the given v4l control id. when the cid does not exist, could not be
-   accessed for some reason, or some error occured 0 is returned. */
+   of the given v4l control id. When the cid does not exist, or could not be
+   accessed -1 is returned. */
 LIBV4L_PUBLIC int v4l2_get_control(int fd, int cid);
 
 
index 7f006bb..cb53899 100644 (file)
@@ -567,14 +567,15 @@ int v4l1_ioctl(int fd, unsigned long int request, ...)
 
        case VIDIOCGPICT: {
                struct video_picture *pic = arg;
+               int i;
 
-               /* If our v4l2 pixformat has no corresponding v4l1 palette, and the
-                  app has not touched the pixformat sofar, try setting a palette which
-                  does (and which we emulate when necessary) so that applications
-                  which just query the current format and then take whatever they get
-                  will work */
+               /* If our v4l2 pixformat has no corresponding v4l1 palette, and
+                  the app has not touched the pixformat sofar, try setting a
+                  palette which does (and which we emulate when necessary) so
+                  that applications which just query the current format and
+                  then take whatever they get will work */
                if (!(devices[index].flags & V4L1_PIX_FMT_TOUCHED) &&
-                               !pixelformat_to_palette(devices[index].v4l2_pixfmt))
+                   !pixelformat_to_palette(devices[index].v4l2_pixfmt))
                        v4l1_set_format(index, devices[index].width,
                                        devices[index].height,
                                        VIDEO_PALETTE_RGB24,
@@ -583,15 +584,24 @@ int v4l1_ioctl(int fd, unsigned long int request, ...)
 
                devices[index].flags |= V4L1_PIX_FMT_TOUCHED;
 
+               memset(pic, 0, sizeof(*pic));
                pic->depth = devices[index].depth;
                pic->palette = devices[index].v4l1_pal;
-               pic->hue = v4l2_get_control(devices[index].fd, V4L2_CID_HUE);
-               pic->colour = v4l2_get_control(devices[index].fd, V4L2_CID_SATURATION);
-               pic->contrast = v4l2_get_control(devices[index].fd, V4L2_CID_CONTRAST);
-               pic->whiteness = v4l2_get_control(devices[index].fd,
-                               V4L2_CID_WHITENESS);
-               pic->brightness = v4l2_get_control(devices[index].fd,
-                               V4L2_CID_BRIGHTNESS);
+               i = v4l2_get_control(devices[index].fd, V4L2_CID_HUE);
+               if (i >= 0)
+                       pic->hue = i;
+               i = v4l2_get_control(devices[index].fd, V4L2_CID_SATURATION);
+               if (i >= 0)
+                       pic->colour = i;
+               i = v4l2_get_control(devices[index].fd, V4L2_CID_CONTRAST);
+               if (i >= 0)
+                       pic->contrast = i;
+               i = v4l2_get_control(devices[index].fd, V4L2_CID_WHITENESS);
+               if (i >= 0)
+                       pic->whiteness = i;
+               i = v4l2_get_control(devices[index].fd, V4L2_CID_BRIGHTNESS);
+               if (i >= 0)
+                       pic->brightness = i;
 
                result = 0;
                break;
index 7c595bf..ab85ea7 100644 (file)
@@ -1418,13 +1418,15 @@ int v4l2_get_control(int fd, int cid)
        }
 
        if (v4lconvert_vidioc_queryctrl(devices[index].convert, &qctrl))
-               return 0;
+               return -1;
 
-       if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
-               return 0;
+       if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
+               errno = EINVAL;
+               return -1;
+       }
 
        if (v4lconvert_vidioc_g_ctrl(devices[index].convert, &ctrl))
-               return 0;
+               return -1;
 
        return ((ctrl.value - qctrl.minimum) * 65535 +
                        (qctrl.maximum - qctrl.minimum) / 2) /