Sensor orientation reporting
v2 cover Sensor orientation reporting
Hi,
Based on the limited feedback from last time I'm assuming people are generally happy with this so I've updated according to Jean-Francois Moine's comments and added documentation. Again this features only the minimum changes in libv4l to make some use of the info.
Add support to the SQ-905 driver to pass back to user space the sensor orientation information obtained from the camera during init. Modifies gspca and the videodev2.h header to create the necessary API.
---
linux/drivers/media/video/gspca/gspca.c +1 -0
@@ -1147,6 +1147,7 @@if (input->index !=0 )return -EINVAL ; input->type =V4L2_INPUT_TYPE_CAMERA ; + input->status = gspca_dev->cam.input_flags;strncpy (input->name, gspca_dev->sd_desc->name,sizeof input->name);return 0 ;
linux/drivers/media/video/gspca/gspca.h +1 -0
@@ -56,6 +56,7 @@* - cannot be > MAX_NURBS * - when 0 and bulk_size != 0 means * 1 URB and submit done by subdriver */ +u32 input_flags;/* value for ENUM_INPUT status flags */ };struct gspca_dev ;
linux/drivers/media/video/gspca/sq905.c +6 -0
@@ -360,6 +360,12 @@ gspca_dev->cam.nmodes =ARRAY_SIZE (sq905_mode);if (!(ident &SQ905_HIRES_MASK )) gspca_dev->cam.nmodes--; + +if (ident &SQ905_ORIENTATION_MASK ) + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP ; +else + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP | +V4L2_IN_ST_HFLIP ;return 0 ; }
linux/include/linux/videodev2.h +3 -0
@@ -737,6 +737,11 @@#define V4L2_IN_ST_NO_SIGNAL 0x00000002#define V4L2_IN_ST_NO_COLOR 0x00000004 +/* field 'status' - sensor orientation */ +/* If sensor is mounted upside down set both bits */ +#define V4L2_IN_ST_HFLIP 0x00000010/* Output is flipped horizontally
*/
+#define V4L2_IN_ST_VFLIP 0x00000020 /* Output is flipped vertically */
+
/* field 'status' - analog */
#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ #define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
PATCH v2 2/4 Specify SHELL in documentation Makefile
The Makefile for the V4L2 spec uses bash extensions but was using the default system shell, change it to explicitly request bash.
---
v4l2-spec/Makefile +1 -0
@@ -1,5 +1,6 @@ # Also update in v4l2.sgml! VERSION = 0.25 +SHELL=/bin/bash SGMLS = \ biblio.sgml \
PATCH v2 3/4 Document the orientation flags in ENUMINPUT
Add documentation for the flags that have been added to VIDIOC_ENUMINPUT to specify the sensor orientation.
---
v4l2-spec/vidioc-enuminput.sgml +18 -1
@@ -119,7 +119,7 @@ <entry><structfield>status</structfield></entry> <entry>This field provides status information about the input. See <xref linkend="input-status"> for flags. -<structfield>status</structfield> is only valid when this is the +With the exception of the sensor orientation bits <structfield>status</structfield> is only valid when this is the current input.</entry> </row> <row>
@@ -188,6 +188,23 @@ detect color modulation in the signal.</entry> </row> <row> + <entry spanname="hspan">Sensor Orientation</entry> + </row> + <row> + <entry><constant>V4L2_IN_ST_HFLIP</constant></entry> + <entry>0x00000010</entry> + <entry>The input is connected to a device that produces a signal +that is flipped horizontally and does not correct this before passing the +signal to userspace.</entry> + </row> + <row> + <entry><constant>V4L2_IN_ST_VFLIP</constant></entry> + <entry>0x00000020</entry> + <entry>The input is connected to a device that produces a signal +that is flipped vertically and does not correct this before passing the +signal to userspace. Note that a 180 degree rotation is the same as HFLIP | VFLIP</entry> + </row> + <row> <entry spanname="hspan">Analog Video</entry> </row> <row>
PATCH v2 4/4 Add support to libv4l to use orientation from VIDIOC_ENUMINPUT
Add check to libv4l of the sensor orientation as reported by VIDIOC_ENUMINPUT
---
v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c +13 -0
@@ -29,6 +29,11 @@#define MIN (a,b) (((a)<(b))?(a):(b))#define ARRAY_SIZE (x) ((int)sizeof(x)/(int)sizeof((x)[0])) +/* Workaround this potentially being missing from videodev2.h */ +#ifndef V4L2_IN_ST_VFLIP +#define V4L2_IN_ST_VFLIP 0x00000020/* Output is flipped vertically */ +#endif +/* Note for proper functioning of v4lconvert_enum_fmt the first entries in supported_src_pixfmts must match with the entries in supported_dst_pixfmts */ #define SUPPORTED_DST_PIXFMTS \
@@ -134,6 +139,7 @@int i, j;struct v4lconvert_data *data =calloc (1 ,sizeof (struct v4lconvert_data ));struct v4l2_capability cap; +struct v4l2_input input;if (!data)return NULL ;
@@ -161,6 +167,13 @@/* Check if this cam has any special flags */ data->flags =v4lconvert_get_flags (data->fd); +if ((syscall (SYS_ioctl, fd,VIDIOC_G_INPUT , &input.index) ==0 ) && + (syscall (SYS_ioctl, fd,VIDIOC_ENUMINPUT , &input) ==0 )) { +/* Don't yet support independent HFLIP and VFLIP so getting +* image the right way up is highest priority. */ +if (input.status &V4L2_IN_ST_VFLIP ) + data->flags |=V4LCONVERT_ROTATE_180 ; + }if (syscall (SYS_ioctl, fd,VIDIOC_QUERYCAP , &cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;
Re: [PATCH v2 4/4] Add support to libv4l to use orientation from VIDIOC_ENUMINPUT
Quoted 5 lines · Adam Baker
Add check to libv4l of the sensor orientation as reported by
VIDIOC_ENUMINPUTSigned-off-by Adam Baker<[email protected]>
Looks good, thanks. I'll apply this to my libv4l tree, as soon as its certain that the matching kernel changes will go in to the kernel without any API changes.
Thanks & Regards,
Hans
Quoted 40 lines
---
diff -ra647c2dfa989v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.cv4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c +13
-0@@ -29,6 +29,11 @@#define MIN (a,b) (((a)<(b))?(a):(b))#define ARRAY_SIZE (x) ((int)sizeof(x)/(int)sizeof((x)[0])) +/* Workaround this potentially being missing from videodev2.h */ +#ifndef V4L2_IN_ST_VFLIP +#define V4L2_IN_ST_VFLIP 0x00000020/* Output is flipped vertically */ +#endif +/* Note for proper functioning of v4lconvert_enum_fmt the first entries in supported_src_pixfmts must match with the entries in supported_dst_pixfmts */ #define SUPPORTED_DST_PIXFMTS \@@ -134,6 +139,7 @@int i, j;struct v4lconvert_data *data =calloc (1 ,sizeof (struct v4lconvert_data ));struct v4l2_capability cap; +struct v4l2_input input;if (!data)return NULL ;@@ -161,6 +167,13 @@/* Check if this cam has any special flags */ data->flags =v4lconvert_get_flags (data->fd); +if ((syscall (SYS_ioctl, fd,VIDIOC_G_INPUT ,&input.index) ==0 )&& + (syscall (SYS_ioctl, fd,VIDIOC_ENUMINPUT ,&input) ==0 )) { +/* Don't yet support independent HFLIP and VFLIP so getting +* image the right way up is highest priority. */ +if (input.status&V4L2_IN_ST_VFLIP ) + data->flags |=V4LCONVERT_ROTATE_180 ; + }if (syscall (SYS_ioctl, fd,VIDIOC_QUERYCAP ,&cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;
Re: [PATCH v2 4/4] Add support to libv4l to use orientation from VIDIOC_ENUMINPUT
Quoted 10 lines · On Mon, 30 Mar 2009 10:30:22 +0200 Hans de Goede <[email protected]> wrote:
Quoted 5 lines · Adam Baker
Add check to libv4l of the sensor orientation as reported by
VIDIOC_ENUMINPUTSigned-off-by Adam Baker<[email protected]>Looks good, thanks. I'll apply this to my libv4l tree, as soon as its certain that the matching kernel changes will go in to the kernel without any API changes.
kernel patches merged. As per your request, I'm letting the libv4l one for you to take care.
Cheers,
Mauro
Re: [PATCH v2 4/4] Add support to libv4l to use orientation from VIDIOC_ENUMINPUT
In reply to Adam BakerThanks,
I've applied this to my tree, it will be part of the next libv4l release.
Regards,
Hans
Quoted 45 lines · Adam Baker
Add check to libv4l of the sensor orientation as reported by
VIDIOC_ENUMINPUTSigned-off-by Adam Baker<[email protected]>---
diff -ra647c2dfa989v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.cv4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c +13
-0@@ -29,6 +29,11 @@#define MIN (a,b) (((a)<(b))?(a):(b))#define ARRAY_SIZE (x) ((int)sizeof(x)/(int)sizeof((x)[0])) +/* Workaround this potentially being missing from videodev2.h */ +#ifndef V4L2_IN_ST_VFLIP +#define V4L2_IN_ST_VFLIP 0x00000020/* Output is flipped vertically */ +#endif +/* Note for proper functioning of v4lconvert_enum_fmt the first entries in supported_src_pixfmts must match with the entries in supported_dst_pixfmts */ #define SUPPORTED_DST_PIXFMTS \@@ -134,6 +139,7 @@int i, j;struct v4lconvert_data *data =calloc (1 ,sizeof (struct v4lconvert_data ));struct v4l2_capability cap; +struct v4l2_input input;if (!data)return NULL ;@@ -161,6 +167,13 @@/* Check if this cam has any special flags */ data->flags =v4lconvert_get_flags (data->fd); +if ((syscall (SYS_ioctl, fd,VIDIOC_G_INPUT ,&input.index) ==0 )&& + (syscall (SYS_ioctl, fd,VIDIOC_ENUMINPUT ,&input) ==0 )) { +/* Don't yet support independent HFLIP and VFLIP so getting +* image the right way up is highest priority. */ +if (input.status&V4L2_IN_ST_VFLIP ) + data->flags |=V4LCONVERT_ROTATE_180 ; + }if (syscall (SYS_ioctl, fd,VIDIOC_QUERYCAP ,&cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;
Quoted 59 lines · On Monday 30 March 2009 00:17:10 Adam Baker wrote:
Add support to the SQ-905 driver to pass back to user space the sensor orientation information obtained from the camera during init. Modifies gspca and the
videodev2.hheader to create the necessary API.Signed-off-by Adam Baker <[email protected]>---
diff -rd8d701594f71linux/drivers/media/video/gspca/gspca.c
---a/linux/drivers/media/video/gspca/gspca.cSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/gspca.cSun Mar 29 23:00:08
2009 +0100 @@ -1147,6 +1147,7 @@linux/drivers/media/video/gspca/gspca.c +1
-0if (input->index !=0 )return -EINVAL ; input->type =V4L2_INPUT_TYPE_CAMERA ; + input->status = gspca_dev->cam.input_flags;strncpy (input->name, gspca_dev->sd_desc->name,sizeof input->name);return 0 ;diff -r
d8d701594f71linux/drivers/media/video/gspca/gspca.h
---a/linux/drivers/media/video/gspca/gspca.hSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/gspca.hSun Mar 29 23:00:08
2009 +0100 @@ -56,6 +56,7 @@linux/drivers/media/video/gspca/gspca.h +1
-0* - cannot be > MAX_NURBS * - when 0 and bulk_size != 0 means * 1 URB and submit done by subdriver */ +u32 input_flags;/* value for ENUM_INPUT status flags */ };struct gspca_dev ;diff -r
d8d701594f71linux/drivers/media/video/gspca/sq905.c
---a/linux/drivers/media/video/gspca/sq905.cSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/sq905.cSun Mar 29 23:00:08
2009 +0100 @@ -360,6 +360,12 @@linux/drivers/media/video/gspca/sq905.c +6
-0gspca_dev->cam.nmodes =ARRAY_SIZE (sq905_mode);if (!(ident &SQ905_HIRES_MASK )) gspca_dev->cam.nmodes--; + +if (ident &SQ905_ORIENTATION_MASK ) + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP ; +else + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP | +V4L2_IN_ST_HFLIP ;return 0 ; }diff -r
d8d701594f71linux/include/linux/videodev2.hlinux/include/linux/videodev2.h +3
-0@@ -737,6 +737,11 @@#define V4L2_IN_ST_NO_SIGNAL 0x00000002#define V4L2_IN_ST_NO_COLOR 0x00000004 +/* field 'status' - sensor orientation */ +/* If sensor is mounted upside down set both bits */ +#define V4L2_IN_ST_HFLIP 0x00000010/* Output is flipped horizontally */
+#defineV4L2_IN_ST_VFLIP0x00000020/* Output is flipped
vertically */ +
/* field 'status' - analog */
Quoted 2 lines
#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ #define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
Hi Adam,
I've only one small comment: the V4L2_IN_ST_H/VFLIP comments talk about 'Output' while these flags deal with an input. I know you mean the output from the sensor, but the point of view in this API is the application, and for the application it is an input.
Other than that I'm happy with it.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
Quoted 70 lines · Hans Verkuil
Quoted 59 lines · On Monday 30 March 2009 00:17:10 Adam Baker wrote:
Add support to the SQ-905 driver to pass back to user space the sensor orientation information obtained from the camera during init. Modifies gspca and the
videodev2.hheader to create the necessary API.Signed-off-by Adam Baker <[email protected]>---
diff -rd8d701594f71linux/drivers/media/video/gspca/gspca.c
---a/linux/drivers/media/video/gspca/gspca.cSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/gspca.cSun Mar 29 23:00:08
2009 +0100 @@ -1147,6 +1147,7 @@linux/drivers/media/video/gspca/gspca.c +1
-0if (input->index !=0 )return -EINVAL ; input->type =V4L2_INPUT_TYPE_CAMERA ; + input->status = gspca_dev->cam.input_flags;strncpy (input->name, gspca_dev->sd_desc->name,sizeof input->name);return 0 ;diff -r
d8d701594f71linux/drivers/media/video/gspca/gspca.h
---a/linux/drivers/media/video/gspca/gspca.hSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/gspca.hSun Mar 29 23:00:08
2009 +0100 @@ -56,6 +56,7 @@linux/drivers/media/video/gspca/gspca.h +1
-0* - cannot be > MAX_NURBS * - when 0 and bulk_size != 0 means * 1 URB and submit done by subdriver */ +u32 input_flags;/* value for ENUM_INPUT status flags */ };struct gspca_dev ;diff -r
d8d701594f71linux/drivers/media/video/gspca/sq905.c
---a/linux/drivers/media/video/gspca/sq905.cSun Mar 29 08:45:36 2009
+0200 +++b/linux/drivers/media/video/gspca/sq905.cSun Mar 29 23:00:08
2009 +0100 @@ -360,6 +360,12 @@linux/drivers/media/video/gspca/sq905.c +6
-0gspca_dev->cam.nmodes =ARRAY_SIZE (sq905_mode);if (!(ident &SQ905_HIRES_MASK )) gspca_dev->cam.nmodes--; + +if (ident &SQ905_ORIENTATION_MASK ) + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP ; +else + gspca_dev->cam.input_flags =V4L2_IN_ST_VFLIP | +V4L2_IN_ST_HFLIP ;return 0 ; }diff -r
d8d701594f71linux/include/linux/videodev2.hlinux/include/linux/videodev2.h +3
-0@@ -737,6 +737,11 @@#define V4L2_IN_ST_NO_SIGNAL 0x00000002#define V4L2_IN_ST_NO_COLOR 0x00000004 +/* field 'status' - sensor orientation */ +/* If sensor is mounted upside down set both bits */ +#define V4L2_IN_ST_HFLIP 0x00000010/* Output is flipped horizontally */
+#defineV4L2_IN_ST_VFLIP0x00000020/* Output is flipped
vertically */ +
/* field 'status' - analog */Quoted 2 lines
#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ #define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */Hi Adam,
I've only one small comment: the V4L2_IN_ST_H/VFLIP comments talk about 'Output' while these flags deal with an input. I know you mean the output from the sensor, but the point of view in this API is the application, and for the application it is an input.
Quoted 5 lines
Other than that I'm happy with it.
Regards,
Hans
Hmmm. These two comments?
Quoted 4 lines
Quoted 4 lines
+#define
V4L2_IN_ST_HFLIP0x00000010/* Output is flipped
horizontally */
+#defineV4L2_IN_ST_VFLIP0x00000020/* Output is flipped
vertically */ +
Perhaps one could change them to say /* Frames must be flipped ...
instead.
Theodore Kilgore