v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
PATCH 1/1 v4l2: add fallback for systems without V4L2_CTRL_WHICH_CUR_VAL
From: James Hilliard <[email protected]>
Some older systems don't seem to have V4L2_CTRL_WHICH_CUR_VAL so add a fallback.
--- zbar/video/v4l2.c | 8 ++++++++ 1 file changed, 8 insertions(+)
zbar/video/v4l2.c +8 -0
@@ -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));
Signature · 1 line
2.7.4
Em Wed, 16 Jan 2019 13:23:10 +0800
[email protected] escreveu:
Quoted 4 lines
From: James Hilliard <[email protected]>
Some older systems don't seem to have
V4L2_CTRL_WHICH_CUR_VALso add a fallback.
Nice catch.
Quoted 24 lines
Signed-off-by James Hilliard <[email protected]>--- zbar/video/v4l2.c | 8 ++++++++ 1 file changed, 8 insertions(+)zbar/video/v4l2.c +4
-0@@ -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,
zbar/video/v4l2.c static int v4l2_g_control(zbar_video_t *vdo, · line 928
Quoted 10 lines
zbar/video/v4l2.c +4
-0memset (&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.
zbar/video/v4l2.c +10 -2
@@ -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));
Quoted 44 lines · Mauro Carvalho Chehab
Em Wed, 16 Jan 2019 13:23:10 +0800
[email protected] escreveu:Quoted 4 lines
From: James Hilliard <[email protected]>
Some older systems don't seem to have
V4L2_CTRL_WHICH_CUR_VALso add a fallback.Nice catch.
Quoted 33 lines
Signed-off-by James Hilliard <[email protected]>--- zbar/video/v4l2.c | 8 ++++++++ 1 file changed, 8 insertions(+)zbar/video/v4l2.c +8
-0@@ -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;
Quoted 4 lines
zbar/video/v4l2.c static int v4l2_g_control(zbar_video_t *vdo, · line 928
Quoted 1 line
zbar/video/v4l2.c +0
-0memset (&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.
Quoted 9 lines
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.
Quoted 6 lines
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.
Quoted 10 lines
Thanks,
Maurov4l2: add fallback for systems without
v4l2_ext_controlswhich fieldThe v4l2_ext_controls.which field was introduced on Kernel 4.4, in order to solve some ambiguities and make easier to handle controls.
Quoted 5 lines
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).
Quoted 34 lines
Reported-by James Hilliard <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>zbar/video/v4l2.c +10
-2@@ -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));
Em Wed, 16 Jan 2019 13:34:29 -0700
James Hilliard <[email protected]> escreveu:
Quoted 3 lines
Quoted 2 lines
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
Quoted 9 lines · Mauro Carvalho Chehab
Em Wed, 16 Jan 2019 13:34:29 -0700
James Hilliard <[email protected]> escreveu:Quoted 3 lines
Quoted 2 lines
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.
Quoted 4 lines
Thanks,
Mauro