C语言如何根据Makefile配置宏定义值进行编译预处理 #if defined(CFG_XXX_TYPE) && (CFG_XXX_TYPE == 1)

场景

开发中经常需要根据一些配置使用不同的代码块,比如根据配置决定是否用不同的代码实现某个接口,或者根据配置决定在内核态或者用户态使用不同的接口。

Makefile中定义

CFLAGS = \
	-DCFG_XXX_TYPE=1

注意这里不能定义成字符串比如 CFG_XXX_TYPE=“abc” 然后C语言中进行 CFG_XXX_TYPE == “CFG_XXX_TYPE”

C语言中使用

#if defined(CFG_XXX_TYPE) && (CFG_XXX_TYPE == 1)
    #define SET_DFT_LEN 10
    int a = 1;
#else
#ifndef CAMERA_DEFINE_H #define CAMERA_DEFINE_H #include "options.h" #include "stdint.h" // pl 出图的缓冲区个数 #define BUF_NUM_PROVIDE_TO_PL (6) #define MIN_IMAGE_WIDTH 256 #define MIN_IMAGE_HEIGHT 256 #if defined(CAM_ZYNQ_1200W) || defined(CAM_ZYNQ_1200W_1600w) #define CAM_IMG_HIGH 3072 #define CAM_IMG_WIDTH 4096 #define MAX_IMAGE_HEIGHT 3072 #define MAX_IMAGE_WIDTH 4096 #elif defined(CAM_ZYNQ_1000W) #define CAM_IMG_HIGH 2460 #define CAM_IMG_WIDTH 4096 #define MAX_IMAGE_HEIGHT 2460 //按64位的要求取整后为2432 #define MAX_IMAGE_WIDTH 4096 #elif defined(CAM_ZYNQ_230W) #define CAM_IMG_HIGH 1200 #define CAM_IMG_WIDTH 1920 #define MAX_IMAGE_HEIGHT 1200 #define MAX_IMAGE_WIDTH 1920 #elif defined(CAM_ZYNQ_200W) #define CAM_IMG_HIGH 1200 #define CAM_IMG_WIDTH 1600 #define MAX_IMAGE_HEIGHT 1200 #define MAX_IMAGE_WIDTH 1600 #elif defined(CAM_ZYNQ_4KLINE) #define CAM_IMG_HIGH 10240 #define CAM_IMG_WIDTH 4096 //Sensor本身最大宽4120,但受PL端JPG压缩模块对宽度64像素对齐限制,最大为4096 #define MAX_IMAGE_WIDTH 4096 #define MAX_IMAGE_HEIGHT 10240 #elif defined(CAM_ZYNQ_8KLINE) #ifdef PL_NEW_MULTI_BUF_AND_SLICE #define CAM_IMG_HIGH 16504 #define CAM_IMG_WIDTH 8192 #define MAX_IMAGE_WIDTH 8192 #define MAX_IMAGE_HEIGHT 16504 //1.2米的宽度<==>8192,2米的长度<==> 13653, 最终比理论需求大一些,留了余量 #else #define CAM_IMG_HIGH 10240 #define CAM_IMG_WIDTH 8192 //Sensor本身最大宽8240,但受PL端JPG压缩模块对宽度64像素对齐限制,最大为8192 #define MAX_IMAGE_WIDTH 8192 #define MAX_IMAGE_HEIGHT 10240 #endif #elif defined(CAM_ZYNQ_2000W) #define CAM_IMG_WIDTH 5440//Sensor本身最大宽5480,FPGA因像素对齐需要,舍弃了一部分 #define CAM_IMG_HIGH 3648 #define MAX_IMAGE_WIDTH 5480 #define MAX_IMAGE_HEIGHT 3648 #elif defined(CAM_ZYNQ_1800W) #define CAM_IMG_WIDTH 4480 #define CAM_IMG_HIGH 4096 #define MAX_IMAGE_WIDTH 4480 #define MAX_IMAGE_HEIGHT 4096 #elif defined(CAM_ZYNQ_1200W_V1) #define CAM_IMG_WIDTH 3968 // Sensor本身最大宽4000,FPGA因像素对齐需要,舍弃了一部分 #define CAM_IMG_HIGH 2944 #define MAX_IMAGE_WIDTH 4000 #define MAX_IMAGE_HEIGHT 2944 #else #error "please define camera type..." #endif typedef struct { uint32_t min_img_w; uint32_t max_img_w; uint32_t min_img_h; uint32_t max_img_h; uint32_t cam_img_w; uint32_t cam_img_h; }ImageConfig; uint32_t hal_get_min_img_width(); uint32_t hal_get_min_img_height(); uint32_t hal_get_max_img_width(); uint32_t hal_get_max_img_height(); uint32_t hal_get_cam_img_width(); uint32_t hal_get_cam_img_height(); #endif //CAMERA_DEFINE_H /***********************************/ //以下是源文件camera_define.c #include "camera_define.h" uint32_t hal_get_min_img_width() { return MIN_IMAGE_WIDTH; } uint32_t hal_get_min_img_height() { return MIN_IMAGE_HEIGHT; } uint32_t hal_get_max_img_width() { return MAX_IMAGE_WIDTH; } uint32_t hal_get_max_img_height() { return MAX_IMAGE_HEIGHT; } uint32_t hal_get_cam_img_width() { return CAM_IMG_WIDTH; } uint32_t hal_get_cam_img_height() { return CAM_IMG_HIGH; } void hal_get_img_config(ImageConfig *cfg) { cfg->cam_img_h = hal_get_cam_img_height(); cfg->cam_img_w = hal_get_cam_img_width(); cfg->max_img_h = hal_get_max_img_height(); cfg->max_img_w = hal_get_max_img_width(); cfg->min_img_h = hal_get_min_img_height(); cfg->min_img_w = hal_get_min_img_width(); }//////////是否满足将宏定义转移至hal层后,应用层调用接口获取到img的宽高信息,外部如果需要宽高信息则使用结构体变量赋
10-14
S32 mpp_video_set_attr(TP_STRM_ID_E strm_id, const TP_STREAM_ATTR_S* pAttr) { FLOW_MUTEX_LOCK(); #ifdef HDR_MODE_SUPPORT int ret = OK; /* 切换hdr需要关闭所有proc和cap重新配置参数 */ #ifdef AIISP_ENABLED // if (strm_id == STRM_ID_MAIN && (get_hdr_cfg() != pAttr->hdr || pAttr->strm_res.res_w != pre_res_w || is_need_reload_for_rotate == 1)) // { // if(pAttr->strm_res.res_w != pre_res_w) // { // pre_res_w = pAttr->strm_res.res_w; // } // is_need_reload_for_rotate = 0; // #else if (strm_id == STRM_ID_MAIN && get_hdr_cfg() != pAttr->hdr) { #endif ret = get_sensor_direction(); if(ret != HD_OK){ MPP_ERROR("vendor_isp_get_common ISPT_ITEM_SENSOR_DIRECTION, ret %d", ret); goto RET; } int isp_stream_is_inited = 0; int dla_stream_is_inited = 0; int isp_stream_is_started = 0; int dla_stream_is_started = 0; if(g_strm_param[0][STRM_ID_ISP].video_stream_inited == TRUE) { isp_stream_is_inited = 1; } if(g_strm_param[0][STRM_ID_DLA].video_stream_inited == TRUE) { dla_stream_is_inited = 1; } if(g_strm_param[0][STRM_ID_ISP].video_stream_started == TRUE) { isp_stream_is_started = 1; } if(g_strm_param[0][STRM_ID_DLA].video_stream_started == TRUE) { dla_stream_is_started = 1; } if(dla_stream_is_started) { __video_stream_stop(STRM_ID_DLA); } if(isp_stream_is_started) { __video_stream_stop(STRM_ID_ISP); } #ifdef MINOR_STREAM_THD_ENABLE __video_stream_stop(STRM_ID_MINOR_THD); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_THD); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_stop(STRM_ID_MINOR_SEC); #endif #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_SEC); } #endif __video_stream_stop(STRM_ID_JPEG); __video_stream_stop(STRM_ID_MINOR); __video_stream_stop(STRM_ID_MAIN); if(dla_stream_is_inited) { __video_stream_exit(STRM_ID_DLA); } if(isp_stream_is_inited) { __video_stream_exit(STRM_ID_ISP); } #ifdef MINOR_STREAM_THD_ENABLE __video_stream_exit(STRM_ID_MINOR_THD); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_exit(STRM_ID_MAIN_THD); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_exit(STRM_ID_MINOR_SEC); #endif #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_exit(STRM_ID_MAIN_SEC); } #endif __video_stream_exit(STRM_ID_JPEG); __video_stream_exit(STRM_ID_MINOR); __video_stream_exit(STRM_ID_MAIN); if(g_rotate_type != ROTATE_OFF && g_rotate_type != ROTATE_ANTICLOCKWISE_180) { TP_STREAM_ATTR_S attr_main = {0}; memcpy(&attr_main, pAttr, sizeof(TP_STREAM_ATTR_S)); attr_main.strm_res.res_w = ALIGN_FLOOR_16(attr_main.strm_res.res_w); attr_main.strm_res.res_h = ALIGN_FLOOR_16(attr_main.strm_res.res_h); __video_stream_init(STRM_ID_MAIN, &attr_main); } else { __video_stream_init(STRM_ID_MAIN, pAttr); } __video_stream_init(STRM_ID_MINOR, &g_video_attr[STRM_ID_MINOR]); __video_stream_init(STRM_ID_JPEG, &g_video_attr[STRM_ID_JPEG]); #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_init(STRM_ID_MAIN_SEC, &g_video_attr[STRM_ID_MAIN_SEC]); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_init(STRM_ID_MINOR_SEC, &g_video_attr[STRM_ID_MINOR_SEC]); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_init(STRM_ID_MAIN_THD, &g_video_attr[STRM_ID_MAIN_THD]); } #endif #ifdef MINOR_STREAM_THD_ENABLE __video_stream_init(STRM_ID_MINOR_THD, &g_video_attr[STRM_ID_MINOR_THD]); #endif if(isp_stream_is_inited) { __video_stream_init(STRM_ID_ISP, &g_video_attr[STRM_ID_ISP]); } if(dla_stream_is_inited) { __video_stream_init(STRM_ID_DLA, &g_video_attr[STRM_ID_DLA]); } __video_stream_start(STRM_ID_MAIN); __video_stream_start(STRM_ID_MINOR); __video_stream_start(STRM_ID_JPEG); #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_start(STRM_ID_MAIN_SEC); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_start(STRM_ID_MINOR_SEC); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_start(STRM_ID_MAIN_THD); } #endif #ifdef MINOR_STREAM_THD_ENABLE __video_stream_start(STRM_ID_MINOR_THD); #endif if(isp_stream_is_started) { __video_stream_start(STRM_ID_ISP); } if(dla_stream_is_started) { __video_stream_start(STRM_ID_DLA); } memcpy(&g_video_attr[strm_id], pAttr, sizeof(TP_STREAM_ATTR_S)); ret = set_sensor_direction(); if(ret != HD_OK){ MPP_ERROR("vendor_isp_set_common ISPT_ITEM_SENSOR_DIRECTION, ret %d", ret); goto RET; } } else #endif { __video_stream_stop(strm_id); __video_stream_exit(strm_id); if(g_rotate_type != ROTATE_OFF && g_rotate_type != ROTATE_ANTICLOCKWISE_180 && (strm_id == STRM_ID_MAIN || strm_id == STRM_ID_MINOR)) { TP_STREAM_ATTR_S attr = {0}; memcpy(&attr, pAttr, sizeof(TP_STREAM_ATTR_S)); attr.strm_res.res_w = ALIGN_FLOOR_16(attr.strm_res.res_w); attr.strm_res.res_h = ALIGN_FLOOR_16(attr.strm_res.res_h); __video_stream_init(strm_id, &attr); } else { __video_stream_init(strm_id, pAttr); } __video_stream_start(strm_id); memcpy(&g_video_attr[strm_id], pAttr, sizeof(TP_STREAM_ATTR_S)); if (STRM_ID_DLA == strm_id) { memcpy(&g_video_attr[STRM_ID_DLA_REC], pAttr + DLA_REC, sizeof(TP_STREAM_ATTR_S)); } goto RET; } RET: FLOW_MUTEX_UNLOCK(); return OK; } S32 sync_awb_cut_sensor(int cur_sen_id) { AWBT_STATUS cur_status = {0}; AWBT_STATUS to_status = {0}; ISPT_C_GAIN c_gain = {0}; IQT_NIGHT_MODE night_mode = {0}; night_mode.id = cur_sen_id; cur_status.id = cur_sen_id; to_status.id = cur_sen_id == 0 ? 1:0; vendor_isp_get_awb(AWBT_ITEM_STATUS, &cur_status); vendor_isp_get_awb(AWBT_ITEM_STATUS, &to_status); vendor_isp_get_iq(IQT_ITEM_NIGHT_MODE,&night_mode); if (night_mode.mode == 0) { if (abs(g_status_saved.status.cur_r_gain - cur_status.status.cur_r_gain) + abs(g_status_saved.status.cur_g_gain - cur_status.status.cur_g_gain) + abs(g_status_saved.status.cur_b_gain - cur_status.status.cur_b_gain) > THRE_AWB_SYNC) { c_gain.gain[0] = cur_status.status.cur_r_gain * g_sensor_awb_ratio_r_1_to_0 / SENSOR_AWB_RATIO_BASE; c_gain.gain[1] = cur_status.status.cur_g_gain; c_gain.gain[2] = cur_status.status.cur_b_gain * g_sensor_awb_ratio_b_1_to_0 / SENSOR_AWB_RATIO_BASE; } else /* use to_status itself */ { c_gain.gain[0] = to_status.status.cur_r_gain; c_gain.gain[1] = to_status.status.cur_g_gain; c_gain.gain[2] = to_status.status.cur_b_gain; } c_gain.id = cur_sen_id == 0 ? 1:0; vendor_isp_set_common(ISPT_ITEM_C_GAIN, &c_gain); } return 0; } S32 mpp_video_stream_restart(int sensor_id) { int ret = 0; if(sensor_id == 0) { ret = hd_videocap_stop(g_video_avdc_stream[1][0].cap_path); if (ret != HD_OK) { MPP_ERROR("hd_videocap_stop fail=%d\n", ret); return -1; } sync_awb_cut_sensor(1); g_cur_sensor_id = sensor_id; g_wait_i_frame_flag[STRM_ID_MAIN] = 1; g_wait_i_frame_flag[STRM_ID_MINOR] = 1; ret = hd_videocap_start(g_video_avdc_stream[0][0].cap_path); if (ret != HD_OK) { MPP_ERROR("hd_videocap_start fail=%d\n", ret); return -1; } } else if(sensor_id == 1) { ret = hd_videocap_stop(g_video_avdc_stream[0][0].cap_path); if (ret != HD_OK) { MPP_ERROR("hd_videocap_stop fail=%d\n", ret); return -1; } sync_awb_cut_sensor(0); g_cur_sensor_id = sensor_id; g_wait_i_frame_flag[STRM_ID_MAIN] = 1; g_wait_i_frame_flag[STRM_ID_MINOR] = 1; ret = hd_videocap_start(g_video_avdc_stream[1][0].cap_path); if (ret != HD_OK) { MPP_ERROR("hd_videocap_start fail=%d\n", ret); return -1; } } // HD_VIDEOCAP_OUT video_out_param = {0}; // //without setting dim for no scaling, using original sensor out size // video_out_param.pxlfmt = HD_VIDEO_PXLFMT_RAW10; // video_out_param.dir = HD_VIDEO_DIR_NONE; // video_out_param.frc = HD_VIDEO_FRC_RATIO(15,20); // ret = hd_videocap_set(g_video_avdc_stream[0][0].cap_path, HD_VIDEOCAP_PARAM_OUT, &video_out_param); // if (ret != HD_OK) { // MPP_ERROR("hd_videocap_set fail=%d\n", ret); // return -1; // } // hd_videocap_start(g_video_avdc_stream[0][0].cap_path); // video_out_param.pxlfmt = HD_VIDEO_PXLFMT_RAW10; // video_out_param.dir = HD_VIDEO_DIR_NONE; // video_out_param.frc = HD_VIDEO_FRC_RATIO(18,20); // ret = hd_videocap_set(g_video_avdc_stream[1][0].cap_path, HD_VIDEOCAP_PARAM_OUT, &video_out_param); // hd_videocap_start(g_video_avdc_stream[1][0].cap_path); return OK; } S32 mpp_video_restart(ROTATE_TYPE rotate_type, int mirror_type) { FLOW_MUTEX_LOCK(); g_rotate_type = rotate_type; g_mirror_type = mirror_type; U8 stream_type; if (g_strm_param[0][STRM_ID_ISP].video_stream_started == TRUE) { __video_stream_stop(STRM_ID_ISP); __video_stream_exit(STRM_ID_ISP); __video_stream_init(STRM_ID_ISP, &g_video_attr[STRM_ID_ISP]); __video_stream_start(STRM_ID_ISP); } else if (g_strm_param[0][STRM_ID_ISP].video_stream_inited == TRUE) { __video_stream_exit(STRM_ID_ISP); __video_stream_init(STRM_ID_ISP, &g_video_attr[STRM_ID_ISP]); } if (g_strm_param[0][STRM_ID_DLA].video_stream_started == TRUE) { __video_stream_stop(STRM_ID_DLA); __video_stream_exit(STRM_ID_DLA); __video_stream_init(STRM_ID_DLA, &g_video_attr[STRM_ID_DLA]); __video_stream_start(STRM_ID_DLA); } else if (g_strm_param[0][STRM_ID_DLA].video_stream_inited == TRUE) { __video_stream_exit(STRM_ID_DLA); __video_stream_init(STRM_ID_DLA, &g_video_attr[STRM_ID_DLA]); } if(rotate_type != ROTATE_OFF && rotate_type != ROTATE_ANTICLOCKWISE_180) { TP_STREAM_ATTR_S attr_main = {0}; TP_STREAM_ATTR_S attr_minor = {0}; #ifdef MAIN_STREAM_SEC_ENABLE TP_STREAM_ATTR_S attr_main_sec = {0}; #endif #ifdef MINOR_STREAM_SEC_ENABLE TP_STREAM_ATTR_S attr_minor_sec = {0}; #endif #ifdef MAIN_STREAM_THD_ENABLE TP_STREAM_ATTR_S attr_main_thd = {0}; #endif #ifdef MINOR_STREAM_THD_ENABLE TP_STREAM_ATTR_S attr_minor_thd = {0}; #endif memcpy(&attr_main, &g_video_attr[STRM_ID_MAIN], sizeof(TP_STREAM_ATTR_S)); memcpy(&attr_minor, &g_video_attr[STRM_ID_MINOR], sizeof(TP_STREAM_ATTR_S)); #ifdef MAIN_STREAM_SEC_ENABLE memcpy(&attr_main_sec, &g_video_attr[STRM_ID_MAIN_SEC], sizeof(TP_STREAM_ATTR_S)); #endif #ifdef MINOR_STREAM_SEC_ENABLE memcpy(&attr_minor_sec, &g_video_attr[STRM_ID_MINOR_SEC], sizeof(TP_STREAM_ATTR_S)); #endif #ifdef MAIN_STREAM_THD_ENABLE memcpy(&attr_main_thd, &g_video_attr[STRM_ID_MAIN_THD], sizeof(TP_STREAM_ATTR_S)); #endif #ifdef MINOR_STREAM_THD_ENABLE memcpy(&attr_minor_thd, &g_video_attr[STRM_ID_MINOR_THD], sizeof(TP_STREAM_ATTR_S)); #endif attr_main.strm_res.res_w = ALIGN_FLOOR_16(attr_main.strm_res.res_w); attr_main.strm_res.res_h = ALIGN_FLOOR_16(attr_main.strm_res.res_h); attr_minor.strm_res.res_w = ALIGN_FLOOR_16(attr_minor.strm_res.res_w); attr_minor.strm_res.res_h = ALIGN_FLOOR_16(attr_minor.strm_res.res_h); #ifdef MAIN_STREAM_SEC_ENABLE attr_main_sec.strm_res.res_w = ALIGN_FLOOR_16(attr_main_sec.strm_res.res_w); attr_main_sec.strm_res.res_h = ALIGN_FLOOR_16(attr_main_sec.strm_res.res_h); #endif #ifdef MINOR_STREAM_SEC_ENABLE attr_minor_sec.strm_res.res_w = ALIGN_FLOOR_16(attr_minor_sec.strm_res.res_w); attr_minor_sec.strm_res.res_h = ALIGN_FLOOR_16(attr_minor_sec.strm_res.res_h); #endif #ifdef MAIN_STREAM_THD_ENABLE attr_main_thd.strm_res.res_w = ALIGN_FLOOR_16(attr_main_thd.strm_res.res_w); attr_main_thd.strm_res.res_h = ALIGN_FLOOR_16(attr_main_thd.strm_res.res_h); #endif #ifdef MINOR_STREAM_THD_ENABLE attr_minor_thd.strm_res.res_w = ALIGN_FLOOR_16(attr_minor_thd.strm_res.res_w); attr_minor_thd.strm_res.res_h = ALIGN_FLOOR_16(attr_minor_thd.strm_res.res_h); #endif __video_stream_stop(STRM_ID_MAIN); __video_stream_exit(STRM_ID_MAIN); __video_stream_init(STRM_ID_MAIN, &attr_main); __video_stream_start(STRM_ID_MAIN); __video_stream_stop(STRM_ID_MINOR); __video_stream_exit(STRM_ID_MINOR); __video_stream_init(STRM_ID_MINOR, &attr_minor); __video_stream_start(STRM_ID_MINOR); #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_SEC); __video_stream_exit(STRM_ID_MAIN_SEC); __video_stream_init(STRM_ID_MAIN_SEC, &attr_main_sec); __video_stream_start(STRM_ID_MAIN_SEC); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_stop(STRM_ID_MINOR_SEC); __video_stream_exit(STRM_ID_MINOR_SEC); __video_stream_init(STRM_ID_MINOR_SEC, &attr_minor_sec); __video_stream_start(STRM_ID_MINOR_SEC); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_THD); __video_stream_exit(STRM_ID_MAIN_THD); __video_stream_init(STRM_ID_MAIN_THD, &attr_main_thd); __video_stream_start(STRM_ID_MAIN_THD); } #endif #ifdef MINOR_STREAM_THD_ENABLE __video_stream_stop(STRM_ID_MINOR_THD); __video_stream_exit(STRM_ID_MINOR_THD); __video_stream_init(STRM_ID_MINOR_THD, &attr_minor_thd); __video_stream_start(STRM_ID_MINOR_THD); #endif } else { __video_stream_stop(STRM_ID_MAIN); __video_stream_exit(STRM_ID_MAIN); __video_stream_init(STRM_ID_MAIN, &g_video_attr[STRM_ID_MAIN]); __video_stream_start(STRM_ID_MAIN); __video_stream_stop(STRM_ID_MINOR); __video_stream_exit(STRM_ID_MINOR); __video_stream_init(STRM_ID_MINOR, &g_video_attr[STRM_ID_MINOR]); __video_stream_start(STRM_ID_MINOR); #ifdef MAIN_STREAM_SEC_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_SEC); __video_stream_exit(STRM_ID_MAIN_SEC); __video_stream_init(STRM_ID_MAIN_SEC, &g_video_attr[STRM_ID_MAIN_SEC]); __video_stream_start(STRM_ID_MAIN_SEC); } #endif #ifdef MINOR_STREAM_SEC_ENABLE __video_stream_stop(STRM_ID_MINOR_SEC); __video_stream_exit(STRM_ID_MINOR_SEC); __video_stream_init(STRM_ID_MINOR_SEC, &g_video_attr[STRM_ID_MINOR_SEC]); __video_stream_start(STRM_ID_MINOR_SEC); #endif #ifdef MAIN_STREAM_THD_ENABLE #ifdef BINOCULOR_AVS if(get_factory_mode()) #endif { __video_stream_stop(STRM_ID_MAIN_THD); __video_stream_exit(STRM_ID_MAIN_THD); __video_stream_init(STRM_ID_MAIN_THD, &g_video_attr[STRM_ID_MAIN_THD]); __video_stream_start(STRM_ID_MAIN_THD); } #endif #ifdef MINOR_STREAM_THD_ENABLE __video_stream_stop(STRM_ID_MINOR_THD); __video_stream_exit(STRM_ID_MINOR_THD); __video_stream_init(STRM_ID_MINOR_THD, &g_video_attr[STRM_ID_MINOR_THD]); __video_stream_start(STRM_ID_MINOR_THD); #endif } stream_type = (U8)STRM_ID_MAIN; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); stream_type = (U8)STRM_ID_MINOR; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); #ifdef MAIN_STREAM_SEC_ENABLE // 预留:OSD 同步配置更新,当前除main、minor外暂不做处理(callback内部处理) stream_type = (U8)STRM_ID_MAIN_SEC; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); #endif #ifdef MINOR_STREAM_SEC_ENABLE // 预留:OSD 同步配置更新,当前除main、minor外暂不做处理(callback内部处理) stream_type = (U8)STRM_ID_MINOR_SEC; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); #endif #ifdef MAIN_STREAM_THD_ENABLE // 预留:OSD 同步配置更新,当前除main、minor外暂不做处理(callback内部处理) stream_type = (U8)STRM_ID_MAIN_THD; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); #endif #ifdef MINOR_STREAM_THD_ENABLE // 预留:OSD 同步配置更新,当前除main、minor外暂不做处理(callback内部处理) stream_type = (U8)STRM_ID_MINOR_THD; msg_send(AVTS_STREAM_RELOAD, &stream_type, sizeof(U8)); #endif __video_stream_stop(STRM_ID_JPEG); __video_stream_exit(STRM_ID_JPEG); __video_stream_init(STRM_ID_JPEG, &g_video_attr[STRM_ID_JPEG]); __video_stream_start(STRM_ID_JPEG); FLOW_MUTEX_UNLOCK(); return OK; } 这个函数怎么把aiisp的东西去掉
09-29
使用以下类似格式@cppcheck.checker def check_directive_comments(cfg, data): """ 检查 #else 和 #endif 指令是否有引用其匹配的开放指令条件的尾随注释。 """ # 用于跟踪活动预处理条件的栈 condition_stack = [] # 按行号跟踪指令 directive_lines = {} # 处理原始标记以识别预处理指令 line_num = 0 line_tokens = [] # 第一遍 - 按行收集标记并识别指令 for token in data.rawTokens: # 将标记添加到当前行 line_tokens.append(token) # 未到达行尾,继续遍历 if (token.next and (token.next.linenr == token.linenr)): continue line_num = token.linenr # 非预处理指令行,跳过 if line_tokens and line_tokens[0].str != '#': # 重置为新行 line_tokens = [] continue if len(line_tokens) <= 1: # 重置为新行 line_tokens = [] continue # 第 1 个字符为 '#',第 2 个字符为指令类型 directive_type = line_tokens[1].str # 处理 #if, #ifdef, #ifndef if directive_type in ['if', 'ifdef', 'ifndef']: if len(line_tokens) > 2: # 收集构成条件的所有标记 condition_tokens = line_tokens[2:] condition = ' '.join(t.str for t in condition_tokens if not (t.str.startswith('//') or t.str.startswith('/*'))) condition = condition.strip(' ') # 处理 #if defined(...) 情况,支持多个defined组合 if directive_type == 'if' and 'defined' in condition: condition = condition.replace(' ', '') condition = condition.replace('(', '') condition = condition.replace(')', '') condition = condition.replace('defined', '') # 处理 #ifdef 和 #ifndef elif directive_type in ['ifdef', 'ifndef'] and len(line_tokens) > 2: condition = line_tokens[2].str directive_lines[line_num] = {"type": directive_type, "condition": condition} condition_stack.append(condition) else: condition_stack.append("") # 处理 #else 和 #endif elif directive_type in ['else', 'endif']: if not condition_stack: # 重置为新行 line_tokens = [] break current_condition = condition_stack[-1] directive_lines[line_num] = {"type": directive_type, "condition": current_condition} if directive_type == 'endif': condition_stack.pop() # 检查行标记中是否有注释 has_comment = False for each in line_tokens: if each.str.startswith('//') or each.str.startswith('/*'): has_comment = True break if has_comment: # 重置为新行 line_tokens = [] continue # 找到要报告的指令标记 for idx, each in enumerate(line_tokens): if idx > 0 and line_tokens[idx - 1].str == '#' and each.str in ['else', 'endif']: directive_info = directive_lines[line_num] error_message = f"#{directive_info['type']} directive should have a comment, preferably referencing condition '{directive_info['condition']}'" error_key = (each.linenr, error_message) if error_key not in reported_errors: cppcheck.reportError( each, 'severity:warning', f"#{directive_info['type']} directive should have a comment, preferably referencing condition '{directive_info['condition']}'" ) reported_errors.add(error_key) break # 重置为新行 line_tokens = []
10-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值