Hello Laurie,

On Wed, 5 Aug 2020 21:42:18 +0100
Laurence Tratt <[email protected]> wrote:

> Following Marcus's commit of video(1) changes, the attached patch
> crudely solves the "-c output is misleading for
> white_balance_temperature" because we conflate
> auto_white_balance_temperature and white_balance_temperature (which
> are two separate UVC controls) into one control in video(1).
> 
> With this patch we can tell people if white_balance_temperature is
> being automatically controlled or not:
> 
>   $ video white_balance_temperature=6500
>   white_balance_temperature: 4000 -> 6500
>   $ obj/video -c
>   brightness=128
>   contrast=32
>   saturation=64
>   hue=0
>   gamma=120
>   sharpness=2
>   white_balance_temperature=6500
>   $ obj/video -d
>   $ obj/video -c
>   brightness=128
>   contrast=32
>   saturation=64
>   hue=0
>   gamma=120
>   sharpness=2
>   white_balance_temperature=auto
> 
> This patch raises several questions:
> 
>   1) At the moment the only "auto" control we have is
>      white_balance_temperature. If we gain control of
> zoom/pan/exposure (etc), it might be worth breaking out the common
> "auto" functionality?

For now how about adding the according auto control id to our dev_ctrls
structure?  In a next step we could change
dev_set_ctrl_auto_white_balance() to become a generic function
dev_set_ctrl_auto() available for all auto controls.

>   2) Arguably the first command should look like:
>        $ video white_balance_temperature=6500
>        white_balance_temperature: auto -> 6500

I agree that feels more natural.  Added in the below diff.
 
>   3) The output of "video -dv" is very different to "video -c": I
> suspect the former should look more like the latter for consistency.

Lets look at this separately.

>   4) "video -dc" doesn't seem to reset auto_white_balance_temperature?

Agree that combination should work - Will check it later.

> 
> Laurie

Marcus


Index: video.c
===================================================================
RCS file: /cvs/xenocara/app/video/video.c,v
retrieving revision 1.33
diff -u -p -u -p -r1.33 video.c
--- video.c     5 Aug 2020 11:34:00 -0000       1.33
+++ video.c     8 Aug 2020 12:28:33 -0000
@@ -94,6 +94,7 @@ struct dev_ctrls {
        char            *name;
        int              supported;
        int              id;
+       int              id_auto;
        int              def;
        int              min;
        int              max;
@@ -101,24 +102,25 @@ struct dev_ctrls {
        int              cur;
 } ctrls[] = {
 #define CTRL_BRIGHTNESS        0
-       { "brightness", 0, V4L2_CID_BRIGHTNESS, 0, 0, 0, 0, 0 },
+       { "brightness", 0, V4L2_CID_BRIGHTNESS, 0, 0, 0, 0, 0, 0 },
 #define CTRL_CONTRAST  1
-       { "contrast",   0, V4L2_CID_CONTRAST,   0, 0, 0, 0, 0 },
+       { "contrast",   0, V4L2_CID_CONTRAST,   0, 0, 0, 0, 0, 0 },
 #define CTRL_SATURATION        2
-       { "saturation", 0, V4L2_CID_SATURATION, 0, 0, 0, 0, 0 },
+       { "saturation", 0, V4L2_CID_SATURATION, 0, 0, 0, 0, 0, 0 },
 #define CTRL_HUE       3
-       { "hue",        0, V4L2_CID_HUE,        0, 0, 0, 0, 0 },
+       { "hue",        0, V4L2_CID_HUE,        0, 0, 0, 0, 0, 0 },
 #define CTRL_GAIN      4
-       { "gain",       0, V4L2_CID_GAIN,       0, 0, 0, 0, 0 },
+       { "gain",       0, V4L2_CID_GAIN,       0, 0, 0, 0, 0, 0 },
 #define CTRL_GAMMA     5
-       { "gamma",      0, V4L2_CID_GAMMA,      0, 0, 0, 0, 0 },
+       { "gamma",      0, V4L2_CID_GAMMA,      0, 0, 0, 0, 0, 0 },
 #define CTRL_SHARPNESS 6
-       { "sharpness",  0, V4L2_CID_SHARPNESS,  0, 0, 0, 0, 0 },
+       { "sharpness",  0, V4L2_CID_SHARPNESS,  0, 0, 0, 0, 0, 0 },
 #define CTRL_WHITE_BALANCE_TEMPERATURE 7
        { "white_balance_temperature",
-                       0, V4L2_CID_WHITE_BALANCE_TEMPERATURE,  0, 0, 0, 0, 0 },
+                       0, V4L2_CID_WHITE_BALANCE_TEMPERATURE,
+                          V4L2_CID_AUTO_WHITE_BALANCE, 0, 0, 0, 0, 0 },
 #define CTRL_LAST       8
-       { NULL, 0, 0, 0, 0, 0, 0, 0 }
+       { NULL, 0, 0, 0, 0, 0, 0, 0, 0 }
 };
 
 /* frame dimensions */
@@ -218,6 +220,7 @@ int dev_init(struct video *);
 int dev_set_ctrl_abs(struct video *vid, int, int);
 void dev_set_ctrl_rel(struct video *, int, int);
 void dev_set_ctrl_auto_white_balance(struct video *, int, int);
+int dev_get_ctrl_auto(struct video *, int);
 void dev_reset_ctrls(struct video *);
 
 int parse_ctrl(struct video *, int, char **);
@@ -1102,6 +1105,24 @@ dev_set_ctrl_auto_white_balance(struct v
        }
 }
 
+int
+dev_get_ctrl_auto(struct video *vid, int ctrl)
+{
+       struct dev *d = &vid->dev;
+       struct v4l2_control control;
+
+       if (!ctrls[ctrl].id_auto)
+               return 0;
+
+       control.id = ctrls[ctrl].id_auto;
+       if (ioctl(d->fd, VIDIOC_G_CTRL, &control) != 0) {
+               warn("VIDIOC_G_CTRL");
+               return 0;
+       }
+
+       return (control.value);
+}
+
 void
 dev_reset_ctrls(struct video *vid)
 {
@@ -1195,7 +1216,12 @@ dev_dump_query_ctrls(struct video *vid)
                return;
 
        for (i = 0; i < CTRL_LAST; i++) {
-               if (ctrls[i].supported)
+               if (!ctrls[i].supported)
+                       continue;
+
+               if (dev_get_ctrl_auto(vid, i))
+                       fprintf(stderr, "%s=auto\n", ctrls[i].name);
+               else
                        fprintf(stderr, "%s=%d\n", ctrls[i].name, ctrls[i].cur);
        }
 }
@@ -1253,7 +1279,7 @@ dev_init(struct video *vid)
 int
 parse_ctrl(struct video *vid, int argc, char **argv)
 {
-       int i, val_old, val_new;
+       int i, val_old, auto_old, val_new;
        char *p;
        const char *errstr;
 
@@ -1296,9 +1322,17 @@ parse_ctrl(struct video *vid, int argc, 
                                return 0;
                        }
                        val_old = ctrls[i].cur;
-                       if (dev_set_ctrl_abs(vid, i, val_new) == 0)
-                               fprintf(stderr, "%s: %d -> %d\n",
-                                   ctrls[i].name, val_old, ctrls[i].cur);
+                       auto_old = dev_get_ctrl_auto(vid, i);
+                       if (dev_set_ctrl_abs(vid, i, val_new) == 0) {
+                               if (auto_old) {
+                                       fprintf(stderr, "%s: auto -> %d\n",
+                                           ctrls[i].name, ctrls[i].cur);
+                               } else {
+                                       fprintf(stderr, "%s: %d -> %d\n",
+                                           ctrls[i].name, val_old,
+                                           ctrls[i].cur);
+                               }
+                       }
                        break;
                }
                if (i == CTRL_LAST)

Reply via email to