Add Camera Control Class to Support Night Mode Feature
cover Add Camera Control Class to Support Night Mode Feature
Hi, I'm sending this patch proposing to add a Camera Control Class to support Night Mode because there are a lot of cameras with that feature, and the implemented ones currently non stantard work arounds, like enabling it in certain resolutions or using another control class like WHITE_BALANCE.
Also, I couldn't find a Control class suitable for that, because the efects of this feature varies from camera to camera like reduce frame rate by 1/4, enabling IR LEDs, etc.
This Patch includes the implementation for ov7670 and if you agree I can send the patched for other cameras also.
Thank You,
Roberto
PATCH 1/2 v4l2-ctrls: Add V4L2_CID_NIGHT_MODE control to support night mode
From: Roberto Rodriguez Alcala <[email protected]>
--- drivers/media/video/v4l2-ctrls.c | 2 ++ include/linux/videodev2.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
drivers/media/video/v4l2-ctrls.c +2 -0
@@ -365,6 +365,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_PRIVACY :return "Privacy" ;case V4L2_CID_IRIS_ABSOLUTE :return "Iris, Absolute" ;case V4L2_CID_IRIS_RELATIVE :return "Iris, Relative" ; +case V4L2_CID_NIGHT_MODE :return "Night mode" ;/* FM Radio Modulator control */ /* Keep the order of the 'case's the same as in videodev2.h! */
@@ -418,6 +419,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_EXPOSURE_AUTO_PRIORITY :case V4L2_CID_FOCUS_AUTO :case V4L2_CID_PRIVACY : +case V4L2_CID_NIGHT_MODE :case V4L2_CID_AUDIO_LIMITER_ENABLED :case V4L2_CID_AUDIO_COMPRESSION_ENABLED :case V4L2_CID_PILOT_TONE_ENABLED :
include/linux/videodev2.h +2 -0
@@ -1300,6 +1300,8 @@ enum v4l2_exposure_auto_type {#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) +#define V4L2_CID_NIGHT_MODE (V4L2_CID_CAMERA_CLASS_BASE+19) +/* FM Modulator class control IDs */ #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)
Signature · 1 line
1.7.3.2
Re: [PATCH 1/2] [media] v4l2-ctrls: Add V4L2_CID_NIGHT_MODE control to support night mode
Quoted 14 lines · On Monday, January 10, 2011 23:18:26 Roberto Rodriguez Alcala wrote:
From: Roberto Rodriguez Alcala <[email protected]>
Signed-off-by Roberto Rodriguez Alcala <[email protected]>--- drivers/media/video/v4l2-ctrls.c | 2 ++ include/linux/videodev2.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)drivers/media/video/v4l2-ctrls.c +0
-0
drivers/media/video/v4l2-ctrls.c const char *v4l2_ctrl_get_name(u32 id) · line 368
Quoted 4 lines
drivers/media/video/v4l2-ctrls.c +1
-0@@ -365,6 +365,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_PRIVACY :return "Privacy" ;case V4L2_CID_IRIS_ABSOLUTE :return "Iris, Absolute" ;case V4L2_CID_IRIS_RELATIVE :return "Iris, Relative" ; +case V4L2_CID_NIGHT_MODE :return "Night mode" ;
"Night Mode" (capital 'M', like in all the other strings).
Quoted 17 lines
drivers/media/video/v4l2-ctrls.c +1
-0/* FM Radio Modulator control */ /* Keep the order of the 'case's the same as in videodev2.h! */ @@ -418,6 +419,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_EXPOSURE_AUTO_PRIORITY :case V4L2_CID_FOCUS_AUTO :case V4L2_CID_PRIVACY : +case V4L2_CID_NIGHT_MODE :case V4L2_CID_AUDIO_LIMITER_ENABLED :case V4L2_CID_AUDIO_COMPRESSION_ENABLED :case V4L2_CID_PILOT_TONE_ENABLED :include/linux/videodev2.h +0
-0
include/linux/videodev2.h enum v4l2_exposure_auto_type { · line 1307
Quoted 8 lines
include/linux/videodev2.h +2
-0@@ -1300,6 +1300,8 @@ enum v4l2_exposure_auto_type {#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) +#define V4L2_CID_NIGHT_MODE (V4L2_CID_CAMERA_CLASS_BASE+19) +/* FM Modulator class control IDs */ #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)
This control also needs to be documented in Documentation/DocBook/v4l/controls.xml.
However, reading up a bit on this I wonder whether this shouldn't be a 'Camera Mode' menu control since there can be a lot of different modes:
http://www.digital-photography-school.com/digital-camera-modes
Also, how does this relate to controls like EXPOSURE_AUTO? Will selecting manual exposure automatically turn off Night Mode? Or the inverse, will selecting Night Mode automatically turn on autoexposure?
How is this done in the ov7670?
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by Cisco
Re: [PATCH 1/2] [media] v4l2-ctrls: Add V4L2_CID_NIGHT_MODE control to support night mode
Hi,
Quoted 1 line · On Monday 10 January 2011 23:34:36 Hans Verkuil wrote:
On Monday, January 10, 2011 23:18:26 Roberto Rodriguez Alcala wrote:
[snip]
Quoted 19 lines
Quoted 12 lines
include/linux/videodev2.h +1
-0@@ -1300,6 +1300,8 @@ enum v4l2_exposure_auto_type {#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) +#define V4L2_CID_NIGHT_MODE (V4L2_CID_CAMERA_CLASS_BASE+19) +
Quoted 3 lines
/* FM Modulator class control IDs */
#defineV4L2_CID_FM_TX_CLASS_BASE(V4L2_CTRL_CLASS_FM_TX|0x900)
#defineV4L2_CID_FM_TX_CLASS(V4L2_CTRL_CLASS_FM_TX| 1)This control also needs to be documented in
Documentation/DocBook/v4l/controls.xml.
Quoted 8 lines
However, reading up a bit on this I wonder whether this shouldn't be a 'Camera Mode' menu control since there can be a lot of different modes:
http://www.digital-photography-school.com/digital-camera-modes
Also, how does this relate to controls like
EXPOSURE_AUTO? Will selecting manual exposure automatically turn off Night Mode? Or the inverse, will selecting Night Mode automatically turn on autoexposure?
I'm in favor of a Camera Mode menu control, but we need to define the semantics of modes properly, and especially how they relate to other controls. Modes tend to be high-level controls that are usually implemented in software, so they will definitely have an influence on many low-level controls.
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 1/2] [media] v4l2-ctrls: Add V4L2_CID_NIGHT_MODE control to support night mode
In reply to Roberto Rodriguez AlcalaQuoted 14 lines · Roberto Rodriguez Alcala
From: Roberto Rodriguez Alcala <[email protected]>
Signed-off-by Roberto Rodriguez Alcala <[email protected]>--- drivers/media/video/v4l2-ctrls.c | 2 ++ include/linux/videodev2.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)drivers/media/video/v4l2-ctrls.c +0
-0
drivers/media/video/v4l2-ctrls.c const char *v4l2_ctrl_get_name(u32 id) · line 368
Quoted 4 lines
drivers/media/video/v4l2-ctrls.c +1
-0@@ -365,6 +365,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_PRIVACY :return "Privacy" ;case V4L2_CID_IRIS_ABSOLUTE :return "Iris, Absolute" ;case V4L2_CID_IRIS_RELATIVE :return "Iris, Relative" ; +case V4L2_CID_NIGHT_MODE :return "Night mode" ;
After you have clarified questions, asked by Hans, if this patch is going to be accepted in more or less unchanged form, please, in the above line and...
Quoted 16 lines
drivers/media/video/v4l2-ctrls.c +1
-0/* FM Radio Modulator control */ /* Keep the order of the 'case's the same as in videodev2.h! */ @@ -418,6 +419,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_EXPOSURE_AUTO_PRIORITY :case V4L2_CID_FOCUS_AUTO :case V4L2_CID_PRIVACY : +case V4L2_CID_NIGHT_MODE :case V4L2_CID_AUDIO_LIMITER_ENABLED :case V4L2_CID_AUDIO_COMPRESSION_ENABLED :case V4L2_CID_PILOT_TONE_ENABLED :include/linux/videodev2.h +0
-0
include/linux/videodev2.h enum v4l2_exposure_auto_type { · line 1304
Quoted 5 lines
include/linux/videodev2.h +2
-0@@ -1300,6 +1300,8 @@ enum v4l2_exposure_auto_type {#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) +#define V4L2_CID_NIGHT_MODE (V4L2_CID_CAMERA_CLASS_BASE+19) +
in this one use TABs and not spaces for indentation, just like other lines do.
Quoted 5 lines
include/linux/videodev2.h +0
-0/* FM Modulator class control IDs */ #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)Signature · 1 line
1.7.3.2
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
PATCH 2/2 ov7670: Allow configuration of night mode
In reply to Roberto Rodriguez AlcalaFrom: Roberto Rodriguez Alcala <[email protected]>
--- drivers/media/video/ov7670.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
drivers/media/video/ov7670.c +36 -0
@@ -1255,6 +1255,36 @@ static int ov7670_s_gain(struct v4l2_subdev *sd, int value) }/* +* Get or Set Night Mode. +*/ +static int ov7670_g_nightmode (struct v4l2_subdev *sd,__s32 *value) +{ +int ret; +unsigned char com11; + + ret =ov7670_read (sd,REG_COM11 , &com11); + *value = (com11 &COM11_NIGHT ) !=0 ; +return ret; +} + +static int ov7670_s_nightmode (struct v4l2_subdev *sd,int value) +{ +int ret; +unsigned char com11; + + ret =ov7670_read (sd,REG_COM11 , &com11); +if (ret ==0 ) { +if (value) + com11 |=COM11_NIGHT ; +else + com11 &= ~COM11_NIGHT ; + ret =ov7670_write (sd,REG_COM11 , com11); + } +return ret; +} + + +/* * Tweak autogain. */ static int ov7670_g_autogain (struct v4l2_subdev *sd,__s32 *value)
@@ -1382,6 +1412,8 @@ static int ov7670_queryctrl(struct v4l2_subdev *sd,return v4l2_ctrl_query_fill (qc,0 ,65535 ,1 ,500 );case V4L2_CID_EXPOSURE_AUTO :return v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,0 ); +case V4L2_CID_NIGHT_MODE : +return v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,0 ); }return -EINVAL ; }
@@ -1409,6 +1441,8 @@ static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)return ov7670_g_exp (sd, &ctrl->value);case V4L2_CID_EXPOSURE_AUTO :return ov7670_g_autoexp (sd, &ctrl->value); +case V4L2_CID_NIGHT_MODE : +return ov7670_g_nightmode (sd, &ctrl->value); }return -EINVAL ; }
@@ -1437,6 +1471,8 @@ static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)case V4L2_CID_EXPOSURE_AUTO :return ov7670_s_autoexp (sd, (enum v4l2_exposure_auto_type ) ctrl->value); +case V4L2_CID_NIGHT_MODE : +return ov7670_s_nightmode (sd, ctrl->value); }return -EINVAL ; }
Signature · 1 line
1.7.3.2