On Wed, Jan 16, 2019 at 7:24 AM Mauro Carvalho Chehab
<mchehab+sams...@kernel.org> wrote:
>
> Em Wed, 16 Jan 2019 13:23:10 +0800
> james.hillia...@gmail.com escreveu:
>
> > From: James Hilliard <james.hillia...@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.hillia...@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.
Yeah, I wasn't sure my fix was correct.
>
> 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.
I'll test it on the system I had which needed the fallback.
>
> 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.
I needed the fix for a 4.4.0 kernel(ubuntu 16.04).
>
> Reported-by: James Hilliard <james.hillia...@gmail.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+sams...@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));