public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: james.hilliard1@gmail.com
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
Date: Wed, 16 Jan 2019 12:24:09 -0200	[thread overview]
Message-ID: <20190116122409.0968a154@coco.lan> (raw)
In-Reply-To: <1547616190-24085-1-git-send-email-james.hilliard1@gmail.com>

Em Wed, 16 Jan 2019 13:23:10 +0800
james.hilliard1@gmail.com escreveu:

> From: James Hilliard <james.hilliard1@gmail.com>
> 
> Some older systems don't seem to have V4L2_CTRL_WHICH_CUR_VAL so add a
> fallback.

Nice catch.

> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>  zbar/video/v4l2.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/zbar/video/v4l2.c b/zbar/video/v4l2.c
> index 0147cb1..b883ecc 100644
> --- a/zbar/video/v4l2.c
> +++ b/zbar/video/v4l2.c
> @@ -866,7 +866,11 @@ static int v4l2_s_control(zbar_video_t *vdo,
>  
>      memset(&ctrls, 0, sizeof(ctrls));
>      ctrls.count = 1;
> +#ifdef V4L2_CTRL_WHICH_CUR_VAL
>      ctrls.which = V4L2_CTRL_WHICH_CUR_VAL;
> +#else
> +    ctrls.ctrl_class = V4L2_CTRL_CLASS_USER;
> +#endif
>      ctrls.controls = &c;
>  
>      memset(&c, 0, sizeof(c));
> @@ -914,7 +918,11 @@ static int v4l2_g_control(zbar_video_t *vdo,
>  
>      memset(&ctrls, 0, sizeof(ctrls));
>      ctrls.count = 1;
> +#ifdef V4L2_CTRL_WHICH_CUR_VAL
>      ctrls.which = V4L2_CTRL_WHICH_CUR_VAL;
> +#else
> +    ctrls.ctrl_class = V4L2_CTRL_CLASS_USER;
> +#endif
>      ctrls.controls = &c;
>  
>      memset(&c, 0, sizeof(c));

Hmm... This won't work if the control doesn't belong to V4L2_CTRL_CLASS_USER. 
Depending on the device, it may have some controls on different classes.

So, it would be better to get the control class from its ID.

Also, there's still a risk that someone would build zbar against
a Kernel > 4.4, and run it with an older Kernel.

So, IMHO, the best is to also fill ctrls.which from the control
ID. There is a macro for such purpose.

As the Kernel keeps backward-compatibility, with this approach,
it should work with any Kernel, even if someone, for example, builds it
on 4.20 and tries to run on a 2.6.x Kernel.

See the enclosed patch. I tested it here with Kernel 4.20 and works
fine.

Thanks,
Mauro

v4l2: add fallback for systems without v4l2_ext_controls which field

The v4l2_ext_controls.which field was introduced on Kernel 4.4,
in order to solve some ambiguities and make easier to handle
controls.

Yet, there are several systems running older Kernels. As the
newer Linux Kernels are backward-compatible with the old way,
we can change the logic in a way that would allow someone to
build it against a kernel > 4.4, while letting it to keep running
with legacy Kernels.

Reported-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

diff --git a/zbar/video/v4l2.c b/zbar/video/v4l2.c
index 0147cb18d499..0d180947945f 100644
--- a/zbar/video/v4l2.c
+++ b/zbar/video/v4l2.c
@@ -866,7 +866,11 @@ static int v4l2_s_control(zbar_video_t *vdo,
 
     memset(&ctrls, 0, sizeof(ctrls));
     ctrls.count = 1;
-    ctrls.which = V4L2_CTRL_WHICH_CUR_VAL;
+#ifdef V4L2_CTRL_ID2WHICH
+    ctrls.which = V4L2_CTRL_ID2WHICH(p->id);
+#else
+    ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+#endif
     ctrls.controls = &c;
 
     memset(&c, 0, sizeof(c));
@@ -914,7 +918,11 @@ static int v4l2_g_control(zbar_video_t *vdo,
 
     memset(&ctrls, 0, sizeof(ctrls));
     ctrls.count = 1;
-    ctrls.which = V4L2_CTRL_WHICH_CUR_VAL;
+#ifdef V4L2_CTRL_ID2WHICH
+    ctrls.which = V4L2_CTRL_ID2WHICH(p->id);
+#else
+    ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+#endif
     ctrls.controls = &c;
 
     memset(&c, 0, sizeof(c));

  reply	other threads:[~2019-01-16 14:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16  5:23 [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL james.hilliard1
2019-01-16 14:24 ` Mauro Carvalho Chehab [this message]
2019-01-16 20:34   ` James Hilliard
2019-01-16 21:08     ` Mauro Carvalho Chehab
2019-01-16 21:42       ` James Hilliard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190116122409.0968a154@coco.lan \
    --to=mchehab+samsung@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox