diff --git a/package/mediactl_lib/src/media_ctl.c b/package/mediactl_lib/src/media_ctl.c index bda9704..ac7609b 100644 --- a/package/mediactl_lib/src/media_ctl.c +++ b/package/mediactl_lib/src/media_ctl.c @@ -88,8 +88,17 @@ int *virtual_addr[MEMORY_TEST_BLOCK_NUM]= {0}; bool DualCamera_Sync = TRUE; bool Sensor1_Sync = FALSE; bool Awb_Sync_Init = TRUE; - - +int f2k_anti_flicker_enable = 1; +int r2k_anti_flicker_enable = 1; +AE_ANTI_FLICKER_PARAM_T f2k_anti_flicker_param; +AE_ANTI_FLICKER_PARAM_T r2k_anti_flicker_param; +int f2k_base_et_line = 0; +int r2k_base_et_line = 0; +unsigned int f2k_itc_ttl_v = 0x0; +unsigned int r2k_itc_ttl_v = 0x0; + +unsigned int ISPRegRead(unsigned int addr); +unsigned int ISPRegWrite(unsigned int addr, unsigned int value); struct share_memory_alloc_align_args allocAlignMem[MEMORY_TEST_BLOCK_NUM] = {0}; // @@ -724,6 +733,29 @@ static int isp_awb_sync_init() return 0; } +int base_et_lint_calc(enum isp_pipeline pipeline) +{ + if(pipeline == ISP_F2K_PIPELINE) + { + f2k_anti_flicker_param.nItcTtlV = ISPRegRead(0x92650404) + 1; + f2k_anti_flicker_param.nMaxExposure = ISPRegRead(0x92650484); + f2k_anti_flicker_param.nMinExposure = ISPRegRead(0x9265048C); + f2k_anti_flicker_param.nMaxGain = ISPRegRead(0x92650490); + f2k_anti_flicker_param.nMinGain = ISPRegRead(0x92650498); + f2k_anti_flicker_param.nBaseEtLine = 29.97 * f2k_anti_flicker_param.nItcTtlV / 100; + } + else if(pipeline == ISP_R2K_PIPELINE) + { + r2k_anti_flicker_param.nItcTtlV = ISPRegRead(0x92660404) + 1; + r2k_anti_flicker_param.nMaxExposure = ISPRegRead(0x92660484); + r2k_anti_flicker_param.nMinExposure = ISPRegRead(0x9266048C); + r2k_anti_flicker_param.nMaxGain = ISPRegRead(0x92660490); + r2k_anti_flicker_param.nMinGain = ISPRegRead(0x92660498); + r2k_anti_flicker_param.nBaseEtLine = 29.97 * r2k_anti_flicker_param.nItcTtlV / 100; + } + return 0; +} + /** * @brief * @@ -996,14 +1028,40 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) return 0; } #else + +int mediactl_anti_flicker_init(int scl) +{ + if(scl == 0) + { + f2k_anti_flicker_enable = 0; + r2k_anti_flicker_enable = 0; + } + else if (scl == 1) + { + f2k_anti_flicker_enable = 1; + r2k_anti_flicker_enable = 0; + } + else if (scl == 2) + { + f2k_anti_flicker_enable = 0; + r2k_anti_flicker_enable = 1; + } + else if (scl == 3) + { + f2k_anti_flicker_enable = 1; + r2k_anti_flicker_enable = 1; + } + return 0; +} + int mediactl_all_set_ae(enum isp_pipeline_e pipeline) { int ret; struct k510isp_ae_stats ae_stats; struct media_entity *pipe; - if(ISP_F2K_PIPELINE == pipeline) { + pipe = v4l_isp.f2k; ret = v4l2_subdev_open(pipe); if (ret < 0) @@ -1023,13 +1081,19 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) // no change static int expl = 0, agco = 0; + AE_ANTI_FLICKER_CORRECTION_T anti_flicker_corr_param; if (expl == ae_stats.ae_expl && agco == ae_stats.ae_agco) { return ret; } else { expl = ae_stats.ae_expl; agco = ae_stats.ae_agco; + anti_flicker_correction(pipeline, ae_stats.ae_agco, ae_stats.ae_expl, &anti_flicker_corr_param); + } + if(f2k_anti_flicker_enable == 0) + { + anti_flicker_corr_param.nCorrExposure = ae_stats.ae_expl; + anti_flicker_corr_param.nCorrGain = ae_stats.ae_agco; } - struct media_entity *sensor0 = v4l_isp.sensor0; if( ae_stats.ae_wren == 1) { @@ -1039,7 +1103,7 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) struct v4l2_control control_s; control_s.id = V4L2_CID_EXPOSURE; - control_s.value = ae_stats.ae_expl ; + control_s.value = anti_flicker_corr_param.nCorrExposure; ret = ioctl(sensor0->fd,VIDIOC_S_CTRL,&control_s); if (ret < 0) { @@ -1050,7 +1114,7 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) } control_s.id = V4L2_CID_GAIN; - control_s.value = ae_stats.ae_agco; + control_s.value = anti_flicker_corr_param.nCorrGain; ret = ioctl(sensor0->fd,VIDIOC_S_CTRL,&control_s); if (ret < 0) { @@ -1058,13 +1122,14 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) ret); v4l2_subdev_close(sensor0); return ret; - } + } v4l2_subdev_close(sensor0); } } if(ISP_R2K_PIPELINE == pipeline) { + pipe = v4l_isp.r2k; ret = v4l2_subdev_open(pipe); if (ret < 0) @@ -1083,11 +1148,18 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) v4l2_subdev_close(pipe); static int expl = 0, agco = 0; + AE_ANTI_FLICKER_CORRECTION_T anti_flicker_corr_param; if (expl == ae_stats.ae_expl && agco == ae_stats.ae_agco) { return ret; } else { expl = ae_stats.ae_expl; agco = ae_stats.ae_agco; + anti_flicker_correction(pipeline, ae_stats.ae_agco, ae_stats.ae_expl, &anti_flicker_corr_param); + } + if(r2k_anti_flicker_enable == 0) + { + anti_flicker_corr_param.nCorrExposure = ae_stats.ae_expl; + anti_flicker_corr_param.nCorrGain = ae_stats.ae_agco; } struct media_entity *sensor1 = v4l_isp.sensor1; @@ -1099,7 +1171,7 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) struct v4l2_control control_s; control_s.id = V4L2_CID_EXPOSURE; - control_s.value = ae_stats.ae_expl; + control_s.value = anti_flicker_corr_param.nCorrExposure; ret = ioctl(sensor1->fd,VIDIOC_S_CTRL,&control_s); if (ret < 0) { @@ -1110,7 +1182,7 @@ int mediactl_all_set_ae(enum isp_pipeline_e pipeline) } control_s.id = V4L2_CID_GAIN; - control_s.value = ae_stats.ae_agco; + control_s.value = anti_flicker_corr_param.nCorrGain; ret = ioctl(sensor1->fd,VIDIOC_S_CTRL,&control_s); if (ret < 0) { @@ -1569,6 +1641,7 @@ int mediactl_init(char *video_cfg_file,struct video_info *dev_info) printf("%s:error: unable to f2k cfg video %d\n",__func__,ret); return -1; } + base_et_lint_calc(ISP_F2K_PIPELINE); } if( v4l_isp.isp_pipeline[ISP_R2K].pipeline_en == 1 ) @@ -1577,7 +1650,8 @@ int mediactl_init(char *video_cfg_file,struct video_info *dev_info) if (ret < 0) { printf("%s:error: unable to r2k cfg video %d\n",__func__,ret); return -1; - } + } + base_et_lint_calc(ISP_R2K_PIPELINE); } // printf("%s:total_size.width(0x%x),total_size.height(0x%x)\n",__func__,vi_cfg.vi_pipe_cfg[0].total_size.width,vi_cfg.vi_pipe_cfg[0].total_size.height); @@ -2011,5 +2085,82 @@ unsigned int ISPRegWrite(unsigned int addr, unsigned int value) return 1; } +int anti_flicker_correction(enum isp_pipeline pipeline,int gain, int exp, AE_ANTI_FLICKER_CORRECTION_T * anti_flicker_corr_param) +{ + AE_ANTI_FLICKER_PARAM_T * anti_flicker_param_scl; + if(pipeline == ISP_F2K_PIPELINE) + { + anti_flicker_param_scl = &f2k_anti_flicker_param; + } + else if(pipeline == ISP_R2K_PIPELINE) + { + anti_flicker_param_scl = &r2k_anti_flicker_param; + } + + /* ae stat */ + int min_exp = anti_flicker_param_scl->nMinExposure; + int max_exp = anti_flicker_param_scl->nMaxExposure; + int min_gain = anti_flicker_param_scl->nMinGain; + int max_gain = anti_flicker_param_scl->nMaxGain; + int base_et_line = anti_flicker_param_scl->nBaseEtLine; + int multiple = max_exp / base_et_line; + int cur_et_lines = exp; + int cur_gain = gain; + int cur_ev = cur_et_lines * cur_gain; + int new_gain = 0; + int new_et_lines = 0; + int et_rate = 9999; + int correct_mutiple_sel = 0; + + if(cur_et_lines <= base_et_line) + { + goto keep_value; + } + + for(int mp = 0; mp <= multiple; mp++) + { + int delta = abs(cur_et_lines - mp * base_et_line); + if (delta <= et_rate) + { + correct_mutiple_sel = mp; + et_rate = delta; + } + } + + if((correct_mutiple_sel < 1) || \ + (cur_gain <= 256) || \ + ((cur_et_lines >= max_exp)&&(cur_gain >= max_gain))) + { + goto keep_value; + } + + new_et_lines = (correct_mutiple_sel) * base_et_line; + new_gain = cur_gain * cur_et_lines / new_et_lines; + + if((new_gain <= max_gain + 8) && \ + (new_gain > max_gain) + ) + { + new_gain = max_gain; + goto correct_value; + } + else if(new_gain <= max_gain) + { + goto correct_value; + } + else + { + goto keep_value; + } + +correct_value: + anti_flicker_corr_param->nCorrExposure = new_et_lines; + anti_flicker_corr_param->nCorrGain = new_gain + 1; + return 0; +keep_value: + anti_flicker_corr_param->nCorrExposure = exp; + anti_flicker_corr_param->nCorrGain = gain; + return 0; +} \ No newline at end of file diff --git a/package/mediactl_lib/src/media_ctl.h b/package/mediactl_lib/src/media_ctl.h index 1a51e47..23d3dd0 100644 --- a/package/mediactl_lib/src/media_ctl.h +++ b/package/mediactl_lib/src/media_ctl.h @@ -78,12 +78,27 @@ struct video_info unsigned int video_out_format[4]; }; +typedef struct { + int nMaxExposure; + int nMinExposure; + int nMaxGain; + int nMinGain; + int nItcTtlV; + int nBaseEtLine; +} AE_ANTI_FLICKER_PARAM_T; + +typedef struct { + int nCorrExposure; + int nCorrGain; +} AE_ANTI_FLICKER_CORRECTION_T; + int mediactl_init(char *video_cfg_file,struct video_info *dev_info); void mediactl_exit(void); int mediactl_set_ae(enum isp_pipeline_e pipeline); int mediactl_set_ae_single(enum isp_pipeline_e pipeline); int mediactl_set_ae_sync(enum isp_pipeline_e pipeline); int mediactl_set_awb_sync(enum isp_pipeline_e pipeline); +int mediactl_anti_flicker_init(int scl); unsigned int mediactl_get_isp_modules(enum isp_pipeline_e pipeline,enum isp_modules module); #ifdef __cplusplus diff --git a/package/mediactl_lib/src/v4l2_demo/media_ctl.h b/package/mediactl_lib/src/v4l2_demo/media_ctl.h index 3e7c69c..22878f8 100644 --- a/package/mediactl_lib/src/v4l2_demo/media_ctl.h +++ b/package/mediactl_lib/src/v4l2_demo/media_ctl.h @@ -1,26 +1,26 @@ -/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __MEDIACTL_H__ #define __MEDIACTL_H__ @@ -29,6 +29,8 @@ extern "C"{ #endif + + enum isp_pipeline_e { ISP_F2K_PIPELINE, @@ -76,9 +78,28 @@ struct video_info unsigned int video_out_format[4]; }; +typedef struct { + int nMaxExposure; + int nMinExposure; + int nMaxGain; + int nMinGain; + int nItcTtlV; + int nBaseEtLine; +} AE_ANTI_FLICKER_PARAM_T; + +typedef struct { + int nCorrExposure; + int nCorrGain; +} AE_ANTI_FLICKER_CORRECTION_T; + int mediactl_init(char *video_cfg_file,struct video_info *dev_info); void mediactl_exit(void); int mediactl_set_ae(enum isp_pipeline_e pipeline); +int mediactl_set_ae_single(enum isp_pipeline_e pipeline); +int mediactl_set_ae_sync(enum isp_pipeline_e pipeline); +int mediactl_set_awb_sync(enum isp_pipeline_e pipeline); +int mediactl_anti_flicker_init(int scl); + unsigned int mediactl_get_isp_modules(enum isp_pipeline_e pipeline,enum isp_modules module); #ifdef __cplusplus } diff --git a/package/mediactl_lib/src/v4l2_demo/v4l2-demo.c b/package/mediactl_lib/src/v4l2_demo/v4l2-demo.c index 8b9ff23..2c9bef0 100644 --- a/package/mediactl_lib/src/v4l2_demo/v4l2-demo.c +++ b/package/mediactl_lib/src/v4l2_demo/v4l2-demo.c @@ -1,26 +1,26 @@ -/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -343,17 +343,19 @@ static void usage(FILE *fp, int argc, char **argv) "-h | --help Print this message\n" "-f | --video_cfg_file video_cfg_filename [%s]\n" "-v | --verbose Verbose output\n" + "-a | --anti-flicker-enable, 50Hz, default 0: all disable, 1: f2k enable, 2: r2k enable, 3: all enable\n" "", argv[0],video_cfg_file); } -static const char short_options[] = "hf:v";// 短选项 :表示带参数 +static const char short_options[] = "hf:va:";// 短选项 :表示带参数 static const struct option //长选项 long_options[] = { { "video_cfg_file", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, + { "anti-flicker-enable", required_argument, NULL, 'a' }, { 0, 0, 0, 0 } }; /** @@ -766,7 +768,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu case 'v': verbose = 1; break; - + case 'a': + mediactl_anti_flicker_init(atoi(optarg)); // anti flicker 0: disable, 1: f2k enable, 2: r2k enable, 3: all enable + break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); diff --git a/package/mediactl_lib/src/v4l2_drm/media_ctl.h b/package/mediactl_lib/src/v4l2_drm/media_ctl.h index 96257c5..22878f8 100644 --- a/package/mediactl_lib/src/v4l2_drm/media_ctl.h +++ b/package/mediactl_lib/src/v4l2_drm/media_ctl.h @@ -1,28 +1,27 @@ -/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #ifndef __MEDIACTL_H__ #define __MEDIACTL_H__ @@ -30,6 +29,8 @@ extern "C"{ #endif + + enum isp_pipeline_e { ISP_F2K_PIPELINE, @@ -77,9 +78,28 @@ struct video_info unsigned int video_out_format[4]; }; +typedef struct { + int nMaxExposure; + int nMinExposure; + int nMaxGain; + int nMinGain; + int nItcTtlV; + int nBaseEtLine; +} AE_ANTI_FLICKER_PARAM_T; + +typedef struct { + int nCorrExposure; + int nCorrGain; +} AE_ANTI_FLICKER_CORRECTION_T; + int mediactl_init(char *video_cfg_file,struct video_info *dev_info); void mediactl_exit(void); int mediactl_set_ae(enum isp_pipeline_e pipeline); +int mediactl_set_ae_single(enum isp_pipeline_e pipeline); +int mediactl_set_ae_sync(enum isp_pipeline_e pipeline); +int mediactl_set_awb_sync(enum isp_pipeline_e pipeline); +int mediactl_anti_flicker_init(int scl); + unsigned int mediactl_get_isp_modules(enum isp_pipeline_e pipeline,enum isp_modules module); #ifdef __cplusplus } diff --git a/package/mediactl_lib/src/v4l2_drm/v4l2_drm.cc b/package/mediactl_lib/src/v4l2_drm/v4l2_drm.cc index 23e9762..636e2d6 100644 --- a/package/mediactl_lib/src/v4l2_drm/v4l2_drm.cc +++ b/package/mediactl_lib/src/v4l2_drm/v4l2_drm.cc @@ -488,11 +488,12 @@ static void usage(FILE *fp, int argc, char **argv) "-v | --verbose Verbose output\n" "-s | --single[(0|1),[,width*height[,x*y]]] display sensor (0|1)\n" "-d | --double[width*height,x*y,width*height,x*y] display double sensor\n" + "-a | --anti-flicker-enable, 50Hz, default 0: all disable, 1: f2k enable, 2: r2k enable, 3: all enable\n" "", argv[0], video_cfg_file); } -static const char short_options[] = "f:e:hvs::d::";// 短选项 :表示带参数 +static const char short_options[] = "f:e:hvs::d::a:";// 短选项 :表示带参数 static const struct option //长选项 long_options[] = { @@ -502,6 +503,7 @@ long_options[] = { { "verbose", no_argument, NULL, 'v' }, { "single", optional_argument, NULL, 's' }, { "double", optional_argument, NULL, 'd' }, + { "anti-flicker-enable", required_argument, NULL, 'a' }, { 0, 0, 0, 0 } }; @@ -821,7 +823,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu case 'v': verbose = 1; break; - + case 'a': + mediactl_anti_flicker_init(atoi(optarg)); // anti flicker 0: disable, 1: f2k enable, 2: r2k enable, 3: all enable + break; case 's': parse_count = sscanf(optarg ? : "", "%u,%u%*[*x]%u,%u%*[*x]%u", &sensor_index, &video_in_cfg[0].width_force, &video_in_cfg[0].height_force, &video_in_cfg[0].offset_x_force, &video_in_cfg[0].offset_y_force); diff --git a/package/mediactl_lib/src/v4l2_drm_isptool/v4l2_drm_isptool.c b/package/mediactl_lib/src/v4l2_drm_isptool/v4l2_drm_isptool.c index a23aa3a..ad422d0 100644 --- a/package/mediactl_lib/src/v4l2_drm_isptool/v4l2_drm_isptool.c +++ b/package/mediactl_lib/src/v4l2_drm_isptool/v4l2_drm_isptool.c @@ -759,17 +759,19 @@ static void usage(FILE *fp, int argc, char **argv) "-e | --ae config 0 close all, 1 open f-2k ae, 2 open r-2k ae, 3 open all\n" "-h | --help Print this message\n" "-v | --verbose Verbose output\n" + "-a | --anti-flicker-enable, 50Hz, default 0: all disable, 1: f2k enable, 2: r2k enable, 3: all enable\n" "", argv[0], video_cfg_file); } -static const char short_options[] = "f:hv";// 短选项 :表示带参数 +static const char short_options[] = "f:hva:";// 短选项 :表示带参数 static const struct option //长选项 long_options[] = { { "device_cfg name", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, + { "anti-flicker-enable", required_argument, NULL, 'a' }, { 0, 0, 0, 0 } }; @@ -1063,7 +1065,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu case 'v': verbose = 1; break; - + case 'a': + mediactl_anti_flicker_init(atoi(optarg)); // anti flicker 0: disable, 1: f2k enable, 2: r2k enable, 3: all enable + break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); diff --git a/package/mediactl_lib/src/v4l2_test/media_ctl.h b/package/mediactl_lib/src/v4l2_test/media_ctl.h index 3e7c69c..22878f8 100644 --- a/package/mediactl_lib/src/v4l2_test/media_ctl.h +++ b/package/mediactl_lib/src/v4l2_test/media_ctl.h @@ -1,26 +1,26 @@ -/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __MEDIACTL_H__ #define __MEDIACTL_H__ @@ -29,6 +29,8 @@ extern "C"{ #endif + + enum isp_pipeline_e { ISP_F2K_PIPELINE, @@ -76,9 +78,28 @@ struct video_info unsigned int video_out_format[4]; }; +typedef struct { + int nMaxExposure; + int nMinExposure; + int nMaxGain; + int nMinGain; + int nItcTtlV; + int nBaseEtLine; +} AE_ANTI_FLICKER_PARAM_T; + +typedef struct { + int nCorrExposure; + int nCorrGain; +} AE_ANTI_FLICKER_CORRECTION_T; + int mediactl_init(char *video_cfg_file,struct video_info *dev_info); void mediactl_exit(void); int mediactl_set_ae(enum isp_pipeline_e pipeline); +int mediactl_set_ae_single(enum isp_pipeline_e pipeline); +int mediactl_set_ae_sync(enum isp_pipeline_e pipeline); +int mediactl_set_awb_sync(enum isp_pipeline_e pipeline); +int mediactl_anti_flicker_init(int scl); + unsigned int mediactl_get_isp_modules(enum isp_pipeline_e pipeline,enum isp_modules module); #ifdef __cplusplus } diff --git a/package/mediactl_lib/src/v4l2_test/v4l2_test.c b/package/mediactl_lib/src/v4l2_test/v4l2_test.c index ff969ee..7a80e02 100644 --- a/package/mediactl_lib/src/v4l2_test/v4l2_test.c +++ b/package/mediactl_lib/src/v4l2_test/v4l2_test.c @@ -1,26 +1,26 @@ -/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* Copyright (c) 2022, Canaan Bright Sight Co., Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* v4l2_test */ #include @@ -621,11 +621,12 @@ static void usage(FILE *fp, int argc, char **argv) "-c | --count Number of frames to grab [%i]\n" "-v | --verbose Verbose output\n" "-O | --output file Output file full path[%s]\n" + "-a | --anti-flicker-enable, 50Hz, default 0: all disable, 1: f2k enable, 2: r2k enable, 3: all enable\n" "", argv[0], dev_name, frame_count, video_name); } -static const char short_options[] = "d:hmruofc:vO:";// 短选项 :表示带参数 +static const char short_options[] = "d:hmruofc:vO:a:";// 短选项 :表示带参数 static const struct option //长选项 long_options[] = { @@ -639,6 +640,7 @@ long_options[] = { { "count", required_argument, NULL, 'c' }, { "verbose", no_argument, NULL, 'v' }, { "ouput file", required_argument, NULL, 'O' }, + { "anti-flicker-enable", required_argument, NULL, 'a' }, { 0, 0, 0, 0 } }; @@ -717,6 +719,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu case 'O': video_name = optarg; break; + case 'a': + mediactl_anti_flicker_init(atoi(optarg)); // anti flicker 0: disable, 1: f2k enable, 2: r2k enable, 3: all enable + break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); @@ -771,4 +776,4 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu mediactl_exit(); fprintf(stderr, "\n"); return 0; -} +}