linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
@ 2019-01-16  5:23 james.hilliard1
  2019-01-16 14:24 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 5+ messages in thread
From: james.hilliard1 @ 2019-01-16  5:23 UTC (permalink / raw)
  To: mchehab+samsung; +Cc: linux-media, James Hilliard

From: James Hilliard <james.hilliard1@gmail.com>

Some older systems don't seem to have V4L2_CTRL_WHICH_CUR_VAL so add a
fallback.

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));
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
  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
  2019-01-16 20:34   ` James Hilliard
  0 siblings, 1 reply; 5+ messages in thread
From: Mauro Carvalho Chehab @ 2019-01-16 14:24 UTC (permalink / raw)
  To: james.hilliard1; +Cc: linux-media

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));

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
  2019-01-16 14:24 ` Mauro Carvalho Chehab
@ 2019-01-16 20:34   ` James Hilliard
  2019-01-16 21:08     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 5+ messages in thread
From: James Hilliard @ 2019-01-16 20:34 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media

On Wed, Jan 16, 2019 at 7:24 AM Mauro Carvalho Chehab
<mchehab+samsung@kernel.org> wrote:
>
> 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.
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.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));

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
  2019-01-16 20:34   ` James Hilliard
@ 2019-01-16 21:08     ` Mauro Carvalho Chehab
  2019-01-16 21:42       ` James Hilliard
  0 siblings, 1 reply; 5+ messages in thread
From: Mauro Carvalho Chehab @ 2019-01-16 21:08 UTC (permalink / raw)
  To: James Hilliard; +Cc: linux-media

Em Wed, 16 Jan 2019 13:34:29 -0700
James Hilliard <james.hilliard1@gmail.com> escreveu:

> > 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.

Ok. Please let me know once you test it.


Thanks,
Mauro

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH zbar 1/1] v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
  2019-01-16 21:08     ` Mauro Carvalho Chehab
@ 2019-01-16 21:42       ` James Hilliard
  0 siblings, 0 replies; 5+ messages in thread
From: James Hilliard @ 2019-01-16 21:42 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media

On Wed, Jan 16, 2019 at 2:08 PM Mauro Carvalho Chehab
<mchehab+samsung@kernel.org> wrote:
>
> Em Wed, 16 Jan 2019 13:34:29 -0700
> James Hilliard <james.hilliard1@gmail.com> escreveu:
>
> > > 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.
>
> Ok. Please let me know once you test it.
Tested now, looks good to me.
>
>
> Thanks,
> Mauro

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-16 21:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-01-16 20:34   ` James Hilliard
2019-01-16 21:08     ` Mauro Carvalho Chehab
2019-01-16 21:42       ` James Hilliard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).