/*
 * Copyright (C) Cvitek Co., Ltd. 2019-2020. All rights reserved.
 *
 * File Name: sample/common/sample_common_sensor.c
 * Description:
 *   Common sample code for sensor configure.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "cvi_mipi.h"
#include "cvi_sns_ctrl.h"
#include <linux/cvi_defines.h>
#include <linux/cvi_common.h>
#include "cvi_comm_isp.h"
#include "sample_comm.h"
#include "ini.h"

#define INI_FILE_PATH	"/mnt/data/sensor_cfg.ini"
#define INI_DEF_PATH	"/mnt/system/usr/bin/sensor_cfg.ini"
#define SNSCFGPATH_SIZE 100

static CVI_CHAR g_snsCfgPath[SNSCFGPATH_SIZE];

ISP_PUB_ATTR_S ISP_PUB_ATTR_SAMPLE = { { 0, 0, 1920, 1080 }, { 1920, 1080 }, 30, BAYER_RGGB, WDR_MODE_NONE, 0};

static SAMPLE_INI_CFG_S	stDefIniCfg = {
	.enSource  = VI_PIPE_FRAME_SOURCE_DEV,
	.devNum    = 1,
	.enSnsType[0] = SONY_IMX327_MIPI_2M_30FPS_12BIT,
	.enWDRMode[0] = WDR_MODE_NONE,
	.s32BusId[0]  = 3,
	.s32SnsI2cAddr[0] = -1,
	.s32SnsI2cAddr[1] = -1,
	.MipiDev[0]   = 0xFF,
	.MipiDev[1]   = 0xFF,
	.MipiDev[2]   = 0xFF,
	.u8UseMultiSns = 0,
};

// default is MIPI-CSI Bayer format sensor
VI_DEV_ATTR_S DEV_ATTR_SENSOR_BASE = {
	VI_MODE_MIPI,
	VI_WORK_MODE_1Multiplex,
	VI_SCAN_PROGRESSIVE,
	{-1, -1, -1, -1},
	VI_DATA_SEQ_YUYV,

	{
	/*port_vsync   port_vsync_neg     port_hsync        port_hsync_neg        */
	VI_VSYNC_PULSE, VI_VSYNC_NEG_LOW, VI_HSYNC_VALID_SINGNAL, VI_HSYNC_NEG_HIGH,
	VI_VSYNC_VALID_SIGNAL, VI_VSYNC_VALID_NEG_HIGH,

	/*hsync_hfb    hsync_act    hsync_hhb*/
	{0,            1920,        0,
	/*vsync0_vhb vsync0_act vsync0_hhb*/
	 0,            1080,        0,
	/*vsync1_vhb vsync1_act vsync1_hhb*/
	 0,            0,            0}
	},
	VI_DATA_TYPE_RGB,
	{1920, 1080},
	{
		WDR_MODE_NONE,
		1080,
		0
	},
	.enBayerFormat = BAYER_FORMAT_BG,
};

/******************************************************************************
 * If add new sensor , Modify the method as follows if need
 *1-----*snsr_type_name
 *2-----SAMPLE_COMM_SNS_GetSize
 *3-----SAMPLE_COMM_SNS_GetDevAttr
 *4-----SAMPLE_COMM_SNS_GetYuvBypassSts
 *5-----SAMPLE_COMM_SNS_GetIspAttrBySns
 *6-----SAMPLE_COMM_SNS_GetSnsObj
 ******************************************************************************/
/******************************************************************************
 * Structure : Configure sensor mode
 ******************************************************************************/
static const char *snsr_type_name[SAMPLE_SNS_TYPE_BUTT] = {
	/* ------ LINEAR BEGIN ------*/
	"BRIGATES_BG0808_MIPI_2M_30FPS_10BIT",
	"BYD_BF2253L_MIPI_1200P_30FPS_10BIT",
	"CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT",
	"GCORE_GC02M1_MIPI_2M_30FPS_10BIT",
	"GCORE_GC0312_MIPI_480P_20FPS_8BIT",
	"GCORE_GC0329_MIPI_480P_10FPS_8BIT",
	"GCORE_GC1054_MIPI_1M_30FPS_10BIT",
	"GCORE_GC1084_MIPI_1M_30FPS_10BIT",
	"GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT",
	"GCORE_GC2053_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2053_SLAVE_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2053_1L_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2083_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2093_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2093_MIPI_2M_60FPS_10BIT",
	"GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT",
	"GCORE_GC2145_MIPI_2M_12FPS_8BIT",
	"GCORE_GC4023_MIPI_4M_30FPS_10BIT",
	"GCORE_GC4653_MIPI_4M_30FPS_10BIT",
	"GCORE_GC4653_SLAVE_MIPI_4M_30FPS_10BIT",
	"IMGDS_MIS2008_MIPI_2M_1080P_30FPS_12BIT",
	"NEXTCHIP_N5_1M_2CH_25FPS_8BIT",
	"NEXTCHIP_N5_2M_25FPS_8BIT",
	"NEXTCHIP_N6_2M_4CH_25FPS_8BIT",
	"OV_OS02D10_MIPI_2M_30FPS_10BIT",
	"OV_OS02D10_SLAVE_MIPI_2M_30FPS_10BIT",
	"OV_OS02K10_SLAVE_MIPI_2M_30FPS_12BIT",
	"OV_OS04A10_MIPI_4M_1440P_30FPS_12BIT",
	"OV_OS04C10_MIPI_4M_30FPS_12BIT",
	"OV_OS04C10_MIPI_4M_1440P_30FPS_12BIT",
	"OV_OS04C10_SLAVE_MIPI_4M_30FPS_12BIT",
	"OV_OS08A20_MIPI_4M_30FPS_10BIT",
	"OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT",
	"OV_OS08A20_MIPI_5M_30FPS_10BIT",
	"OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT",
	"OV_OS08A20_MIPI_8M_30FPS_10BIT",
	"OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT",
	"OV_OV4689_MIPI_4M_30FPS_10BIT",
	"OV_OV5647_MIPI_2M_30FPS_10BIT",
	"OV_OV6211_MIPI_400P_120FPS_10BIT",
	"OV_OV7251_MIPI_480P_120FPS_10BIT",
	"PICO384_THERMAL_384X288",
	"PICO640_THERMAL_479P",
	"PIXELPLUS_PR2020_1M_25FPS_8BIT",
	"PIXELPLUS_PR2020_1M_30FPS_8BIT",
	"PIXELPLUS_PR2020_2M_25FPS_8BIT",
	"PIXELPLUS_PR2020_2M_30FPS_8BIT",
	"PIXELPLUS_PR2100_2M_25FPS_8BIT",
	"PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT",
	"PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT",
	"SMS_SC035GS_MIPI_480P_120FPS_12BIT",
	"SMS_SC035GS_1L_MIPI_480P_120FPS_10BIT",
	"SMS_SC035HGS_MIPI_480P_120FPS_12BIT",
	"SMS_SC035HGS_1L_MIPI_480P_120FPS_10BIT",
	"SMS_SC1336_1L_MIPI_1M_30FPS_10BIT",
	"SMS_SC1336_1L_MIPI_1M_60FPS_10BIT",
	"SMS_SC1346_1L_MIPI_1M_30FPS_10BIT",
	"SMS_SC1346_1L_MIPI_1M_60FPS_10BIT",
	"SMS_SC1346_1L_SLAVE_MIPI_1M_30FPS_10BIT",
	"SMS_SC1346_1L_SLAVE_MIPI_1M_60FPS_10BIT",
	"SMS_SC200AI_MIPI_2M_30FPS_10BIT",
	"SMS_SC301IOT_MIPI_3M_30FPS_10BIT",
	"SMS_SC401AI_MIPI_3M_30FPS_10BIT",
	"SMS_SC401AI_MIPI_4M_30FPS_10BIT",
	"SMS_SC500AI_MIPI_4M_30FPS_10BIT",
	"SMS_SC500AI_MIPI_5M_30FPS_10BIT",
	"SMS_SC501AI_2L_MIPI_5M_30FPS_10BIT",
	"SMS_SC531AI_2L_MIPI_5M_30FPS_10BIT",
	"SMS_SC850SL_MIPI_8M_30FPS_12BIT",
	"SMS_SC3332_MIPI_3M_30FPS_10BIT",
	"SMS_SC3335_MIPI_3M_30FPS_10BIT",
	"SMS_SC3335_SLAVE_MIPI_3M_30FPS_10BIT",
	"SMS_SC3336_MIPI_3M_30FPS_10BIT",
	"SMS_SC3336P_MIPI_3M_30FPS_10BIT",
	"SMS_SC2331_1L_MIPI_2M_30FPS_10BIT",
	"SMS_SC2331_1L_SLAVE_MIPI_2M_30FPS_10BIT",
	"SMS_SC2331_1L_SLAVE1_MIPI_2M_30FPS_10BIT",
	"SMS_SC2335_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336_SLAVE_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336_SLAVE1_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336_1L_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336P_MIPI_2M_30FPS_10BIT",
	"SMS_SC2336P_1L_MIPI_2M_30FPS_10BIT",
	"SMS_SC223A_1L_MIPI_2M_30FPS_10BIT",
	"SMS_SC4210_MIPI_4M_30FPS_12BIT",
	"SMS_SC4336_MIPI_4M_30FPS_10BIT",
	"SMS_SC4336P_MIPI_4M_30FPS_10BIT",
	"SMS_SC5336_2L_MIPI_5M_30FPS_10BIT",
	"SMS_SC8238_MIPI_8M_30FPS_10BIT",
	"SOI_F23_MIPI_2M_30FPS_10BIT",
	"SOI_F35_MIPI_2M_30FPS_10BIT",
	"SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT",
	"SOI_F37P_MIPI_2M_30FPS_10BIT",
	"SOI_H65_MIPI_1M_30FPS_10BIT",
	"SOI_K06_MIPI_4M_25FPS_10BIT",
	"SOI_Q03_MIPI_3M_30FPS_10BIT",
	"SOI_Q03P_MIPI_3M_30FPS_10BIT",
	"SONY_IMX290_MIPI_1M_30FPS_12BIT",
	"SONY_IMX290_MIPI_2M_60FPS_12BIT",
	"SONY_IMX307_MIPI_2M_30FPS_12BIT",
	"SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT",
	"SONY_IMX307_2L_MIPI_2M_30FPS_12BIT",
	"SONY_IMX307_SUBLVDS_2M_30FPS_12BIT",
	"SONY_IMX307_MIPI_2M_60FPS_12BIT",
	"SONY_IMX307_SUBLVDS_2M_60FPS_12BIT",
#ifdef FPGA_PORTING
	"SONY_IMX327_MIPI_1M_30FPS_10BIT",
#endif
	"SONY_IMX327_MIPI_2M_30FPS_12BIT",
	"SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT",
	"SONY_IMX327_2L_MIPI_2M_30FPS_12BIT",
	"SONY_IMX327_SUBLVDS_2M_30FPS_12BIT",
	"SONY_IMX327_MIPI_2M_60FPS_12BIT",
	"SONY_IMX334_MIPI_8M_30FPS_12BIT",
	"SONY_IMX335_MIPI_4M_30FPS_12BIT",
	"SONY_IMX335_MIPI_4M_1600P_30FPS_12BIT",
	"SONY_IMX335_2L_MIPI_4M_30FPS_10BIT",
	"SONY_IMX335_MIPI_5M_30FPS_12BIT",
	"SONY_IMX335_MIPI_2M_60FPS_10BIT",
	"SONY_IMX335_MIPI_4M_60FPS_10BIT",
	"SONY_IMX335_MIPI_5M_60FPS_10BIT",
	"SONY_IMX347_MIPI_4M_60FPS_12BIT",
	"SONY_IMX385_MIPI_2M_30FPS_12BIT",
	"TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT",
	"TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT",
	"TECHPOINT_TP2825_MIPI_2M_30FPS_8BIT",
	"TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT",
	"TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT",
	"TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT",
	"TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT",
	"VIVO_MCS369_2M_30FPS_12BIT",
	"VIVO_MCS369Q_4M_30FPS_12BIT",
	"VIVO_MM308M2_2M_25FPS_8BIT",
	"LONTIUM_LT6911_2M_60FPS_8BIT",
	/* ------ LINEAR END ------*/

	/* ------ WDR 2TO1 BEGIN ------*/
	"BRIGATES_BG0808_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1",
	"GCORE_GC2093_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"OV_OS04A10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1",
	"OV_OS04C10_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"OV_OS04C10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1",
	"OV_OS04C10_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_MIPI_5M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_MIPI_8M_30FPS_10BIT_WDR2TO1",
	"OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT_WDR2TO1",
	"SMS_SC1336_1L_MIPI_1M_30FPS_10BIT_WDR2TO1",
	"SMS_SC1336_1L_MIPI_1M_60FPS_10BIT_WDR2TO1",
	"SMS_SC1346_1L_MIPI_1M_30FPS_10BIT_WDR2TO1",
	"SMS_SC1346_1L_MIPI_1M_60FPS_10BIT_WDR2TO1",
	"SMS_SC200AI_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"SMS_SC500AI_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"SMS_SC500AI_MIPI_5M_30FPS_10BIT_WDR2TO1",
	"SMS_SC850SL_MIPI_8M_30FPS_10BIT_WDR2TO1",
	"SMS_SC4210_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"SMS_SC8238_MIPI_8M_15FPS_10BIT_WDR2TO1",
	"SOI_F35_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"SONY_IMX307_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX307_2L_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1",
#ifdef FPGA_PORTING
	"SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1",
#endif
	"SONY_IMX327_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX327_2L_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1",
	"SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1",
	"SONY_IMX335_MIPI_4M_30FPS_10BIT_WDR2TO1",
	"SONY_IMX335_MIPI_4M_1600P_30FPS_10BIT_WDR2TO1",
	"SONY_IMX335_MIPI_5M_30FPS_10BIT_WDR2TO1",
	/* ------ WDR 2TO1 END ------*/
};

CVI_CHAR *SAMPLE_COMM_SNS_GetSnsrTypeName(void)
{
	return (CVI_CHAR *)snsr_type_name;
}
/******************************************************************************
 * funciton : Get enSize by diffrent sensor
 * PIC_CIF:    352 * 288
 * PIC_D1_PAL:    720 * 576
 * PIC_D1_NTSC:    720 * 480
 * PIC_720P:    1280 * 720
 * PIC_1600x1200:
 * PIC_1080P:   1920 * 1080
 * PIC_1088:   1920 * 1088
 * PIC_1440P:   2560 * 1440
 * PIC_2304x1296:
 * PIC_2048x1536:
 * PIC_2592x1520:
 * PIC_2560x1600:
 * PIC_2592x1944:
 * PIC_2592x1536:
 * PIC_2688x1520:
 * PIC_2716x1524:
 * PIC_2880x1620:
 * PIC_3844x1124:
 * PIC_3840x2160:
 * PIC_3000x3000:
 * PIC_4000x3000:
 * PIC_4096x2160:
 * PIC_3840x8640:
 * PIC_7688x1124:
 * PIC_640x480:
 * PIC_479P:   632 * 479
 * PIC_400x400:
 * PIC_288P:   384 * 288
 ******************************************************************************/
CVI_S32 SAMPLE_COMM_SNS_GetSize(SAMPLE_SNS_TYPE_E enMode, PIC_SIZE_E *penSize)
{
	CVI_S32 s32Ret = CVI_SUCCESS;

	if (!penSize)
		return CVI_FAILURE;

	switch (enMode) {
	case GCORE_GC1054_MIPI_1M_30FPS_10BIT:
	case GCORE_GC1084_MIPI_1M_30FPS_10BIT:
	case GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT:
	case NEXTCHIP_N5_1M_2CH_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_30FPS_8BIT:
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_SLAVE_MIPI_1M_30FPS_10BIT:
	case SMS_SC1346_1L_SLAVE_MIPI_1M_60FPS_10BIT:
	case SOI_H65_MIPI_1M_30FPS_10BIT:
	case SONY_IMX290_MIPI_1M_30FPS_12BIT:
	case TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT:
#ifdef FPGA_PORTING
	case SONY_IMX327_MIPI_1M_30FPS_10BIT:
	case SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1:
#endif
		*penSize = PIC_720P;
		break;
	case GCORE_GC02M1_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
	case BYD_BF2253L_MIPI_1200P_30FPS_10BIT:
		*penSize = PIC_1600x1200;
		break;
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT:
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC2053_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_1L_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2083_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_60FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case NEXTCHIP_N5_2M_25FPS_8BIT:
	case NEXTCHIP_N6_2M_4CH_25FPS_8BIT:
	case OV_OS02D10_MIPI_2M_30FPS_10BIT:
	case OV_OS02D10_SLAVE_MIPI_2M_30FPS_10BIT:
	case OV_OS02K10_SLAVE_MIPI_2M_30FPS_12BIT:
	case OV_OV5647_MIPI_2M_30FPS_10BIT:
	case PIXELPLUS_PR2020_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_2M_30FPS_8BIT:
	case PIXELPLUS_PR2100_2M_25FPS_8BIT:
	case SMS_SC2331_1L_MIPI_2M_30FPS_10BIT:
	case SMS_SC2331_1L_SLAVE_MIPI_2M_30FPS_10BIT:
	case SMS_SC2331_1L_SLAVE1_MIPI_2M_30FPS_10BIT:
	case SMS_SC2335_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336_SLAVE_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336_SLAVE1_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336_1L_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336P_MIPI_2M_30FPS_10BIT:
	case SMS_SC2336P_1L_MIPI_2M_30FPS_10BIT:
	case SMS_SC223A_1L_MIPI_2M_30FPS_10BIT:
	case SMS_SC200AI_MIPI_2M_30FPS_10BIT:
	case SMS_SC200AI_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SOI_F23_MIPI_2M_30FPS_10BIT:
	case SOI_F35_MIPI_2M_30FPS_10BIT:
	case SOI_F35_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT:
	case SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SOI_F37P_MIPI_2M_30FPS_10BIT:
	case SONY_IMX290_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
	case SONY_IMX327_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_MIPI_2M_60FPS_12BIT:
	case SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_60FPS_10BIT:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2825_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT:
	case VIVO_MCS369_2M_30FPS_12BIT:
	case VIVO_MM308M2_2M_25FPS_8BIT:
	case IMGDS_MIS2008_MIPI_2M_1080P_30FPS_12BIT:
		*penSize = PIC_1080P;
		break;
	case LONTIUM_LT6911_2M_60FPS_8BIT:
		*penSize = PIC_CUSTOMIZE;
		break;
	case GCORE_GC4023_MIPI_4M_30FPS_10BIT:
	case GCORE_GC4653_MIPI_4M_30FPS_10BIT:
	case GCORE_GC4653_SLAVE_MIPI_4M_30FPS_10BIT:
	case OV_OS04A10_MIPI_4M_1440P_30FPS_12BIT:
	case OV_OS04A10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1:
	case OV_OS04C10_MIPI_4M_1440P_30FPS_12BIT:
	case OV_OS04C10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_MIPI_4M_30FPS_10BIT:
	case OV_OS08A20_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SMS_SC401AI_MIPI_4M_30FPS_10BIT:
	case SMS_SC500AI_MIPI_4M_30FPS_10BIT:
	case SMS_SC500AI_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SMS_SC4210_MIPI_4M_30FPS_12BIT:
	case SMS_SC4210_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SMS_SC4336_MIPI_4M_30FPS_10BIT:
	case SMS_SC4336P_MIPI_4M_30FPS_10BIT:
	case SOI_K06_MIPI_4M_25FPS_10BIT:
	case SONY_IMX335_MIPI_4M_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_2L_MIPI_4M_30FPS_10BIT:
	case SONY_IMX335_MIPI_4M_60FPS_10BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
	case VIVO_MCS369Q_4M_30FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1:
		*penSize = PIC_1440P;
		break;
	case SMS_SC401AI_MIPI_3M_30FPS_10BIT:
	case SMS_SC3332_MIPI_3M_30FPS_10BIT:
	case SMS_SC3335_MIPI_3M_30FPS_10BIT:
	case SMS_SC3335_SLAVE_MIPI_3M_30FPS_10BIT:
	case SMS_SC3336_MIPI_3M_30FPS_10BIT:
	case SMS_SC3336P_MIPI_3M_30FPS_10BIT:
	case SOI_Q03_MIPI_3M_30FPS_10BIT:
	case SOI_Q03P_MIPI_3M_30FPS_10BIT:
		*penSize = PIC_2304x1296;
		break;
	case SMS_SC301IOT_MIPI_3M_30FPS_10BIT:
		*penSize = PIC_2048x1536;
		break;
	case SONY_IMX335_MIPI_4M_1600P_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_10BIT_WDR2TO1:
		*penSize = PIC_2560x1600;
		break;
	case OV_OS08A20_MIPI_5M_30FPS_10BIT:
	case OV_OS08A20_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_5M_30FPS_12BIT:
	case SONY_IMX335_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_5M_60FPS_10BIT:
		*penSize = PIC_2592x1944;
		break;
	case OV_OS04C10_MIPI_4M_30FPS_12BIT:
	case OV_OS04C10_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OS04C10_SLAVE_MIPI_4M_30FPS_12BIT:
	case OV_OS04C10_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OV4689_MIPI_4M_30FPS_10BIT:
	case SONY_IMX347_MIPI_4M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX347_MIPI_4M_60FPS_12BIT:
		*penSize = PIC_2688x1520;
		break;
	case SMS_SC500AI_MIPI_5M_30FPS_10BIT:
	case SMS_SC500AI_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SMS_SC501AI_2L_MIPI_5M_30FPS_10BIT:
	case SMS_SC531AI_2L_MIPI_5M_30FPS_10BIT:
		*penSize = PIC_2880x1620;
		break;
	case SMS_SC5336_2L_MIPI_5M_30FPS_10BIT:
		// *penSize = PIC_2880x1618;
		*penSize = PIC_2880x1620;
		break;
	case OV_OS08A20_MIPI_8M_30FPS_10BIT:
	case OV_OS08A20_MIPI_8M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT_WDR2TO1:
	case SMS_SC850SL_MIPI_8M_30FPS_12BIT:
	case SMS_SC850SL_MIPI_8M_30FPS_10BIT_WDR2TO1:
	case SMS_SC8238_MIPI_8M_30FPS_10BIT:
	case SMS_SC8238_MIPI_8M_15FPS_10BIT_WDR2TO1:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1:
		*penSize = PIC_3840x2160;
		break;
	case OV_OV7251_MIPI_480P_120FPS_10BIT:
	case SMS_SC035GS_MIPI_480P_120FPS_12BIT:
	case SMS_SC035GS_1L_MIPI_480P_120FPS_10BIT:
	case SMS_SC035HGS_MIPI_480P_120FPS_12BIT:
	case SMS_SC035HGS_1L_MIPI_480P_120FPS_10BIT:
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
		*penSize = PIC_640x480;
		break;
	case PICO640_THERMAL_479P:
		*penSize = PIC_479P;
		break;
	case OV_OV6211_MIPI_400P_120FPS_10BIT:
		*penSize = PIC_400x400;
		break;
	case PICO384_THERMAL_384X288:
		*penSize = PIC_288P;
		break;
#ifdef ARCH_CV183X
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
		*penSize = PIC_3844x1124;
		break;
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
		*penSize = PIC_7688x1124;
		break;
#else
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
		*penSize = PIC_1080P;
		break;
#endif
	default:
		s32Ret = CVI_FAILURE;
		break;
	}
	return s32Ret;
}
/*
 * Brief: get picture size(w*h), according enPicSize
 */
CVI_S32 SAMPLE_COMM_SNS_GetPicSize(PIC_SIZE_E enPicSize, SIZE_S *pstSize)
{
	switch (enPicSize) {
	case PIC_CIF:   /* 352 * 288 */
		pstSize->u32Width  = 352;
		pstSize->u32Height = 288;
		break;

	case PIC_D1_PAL:   /* 720 * 576 */
		pstSize->u32Width  = 720;
		pstSize->u32Height = 576;
		break;

	case PIC_D1_NTSC:   /* 720 * 480 */
		pstSize->u32Width  = 720;
		pstSize->u32Height = 480;
		break;

	case PIC_720P:   /* 1280 * 720 */
		pstSize->u32Width  = 1280;
		pstSize->u32Height = 720;
		break;

	case PIC_1600x1200:
		pstSize->u32Width  = 1600;
		pstSize->u32Height = 1200;
		break;

	case PIC_1080P:  /* 1920 * 1080 */
		pstSize->u32Width  = 1920;
		pstSize->u32Height = 1080;
		break;

	case PIC_1088:  /* 1920 * 1088*/
		pstSize->u32Width  = 1920;
		pstSize->u32Height = 1088;
		break;

	case PIC_1440P:  /* 2560 * 1440 */
		pstSize->u32Width  = 2560;
		pstSize->u32Height = 1440;
		break;

	case PIC_2304x1296:  /* 2304 * 1296 */
		pstSize->u32Width  = 2304;
		pstSize->u32Height = 1296;
		break;

	case PIC_2048x1536:
		pstSize->u32Width  = 2048;
		pstSize->u32Height = 1536;
		break;

	case PIC_2592x1520:
		pstSize->u32Width  = 2592;
		pstSize->u32Height = 1520;
		break;

	case PIC_2560x1600:
		pstSize->u32Width  = 2560;
		pstSize->u32Height = 1600;
		break;

	case PIC_2592x1944:
		pstSize->u32Width  = 2592;
		pstSize->u32Height = 1944;
		break;

	case PIC_2592x1536:
		pstSize->u32Width  = 2592;
		pstSize->u32Height = 1536;
		break;

	case PIC_2688x1520:
		pstSize->u32Width  = 2688;
		pstSize->u32Height = 1520;
		break;

	case PIC_2716x1524:
		pstSize->u32Width  = 2716;
		pstSize->u32Height = 1524;
		break;

	case PIC_2880x1620:
		pstSize->u32Width  = 2880;
		pstSize->u32Height = 1620;
		break;
	case PIC_2880x1618:
		pstSize->u32Width  = 2880;
		pstSize->u32Height = 1618;
		break;
	case PIC_3844x1124:
		pstSize->u32Width  = 3844;
		pstSize->u32Height = 1124;
		break;

	case PIC_3840x2160:
		pstSize->u32Width  = 3840;
		pstSize->u32Height = 2160;
		break;

	case PIC_3000x3000:
		pstSize->u32Width  = 3000;
		pstSize->u32Height = 3000;
		break;

	case PIC_4000x3000:
		pstSize->u32Width  = 4000;
		pstSize->u32Height = 3000;
		break;

	case PIC_4096x2160:
		pstSize->u32Width  = 4096;
		pstSize->u32Height = 2160;
		break;

	case PIC_3840x8640:
		pstSize->u32Width = 3840;
		pstSize->u32Height = 8640;
		break;

	case PIC_7688x1124:
		pstSize->u32Width = 7688;
		pstSize->u32Height = 1124;
		break;

	case PIC_640x480:
		pstSize->u32Width = 640;
		pstSize->u32Height = 480;
		break;
	case PIC_479P:  /* 632 * 479 */
		pstSize->u32Width  = 632;
		pstSize->u32Height = 479;
		break;
	case PIC_400x400:
		pstSize->u32Width  = 400;
		pstSize->u32Height = 400;
		break;
	case PIC_288P:  /* 384 * 288 */
		pstSize->u32Width  = 384;
		pstSize->u32Height = 288;
		break;
	case PIC_CUSTOMIZE:  /* env * env */
	{
		uint8_t RW_Data[35];
		FILE *fp;
		int file_size;
		if(access("/kvmapp/kvm/width", F_OK) == 0){
			fp = fopen("/kvmapp/kvm/width", "r");
			fseek(fp, 0, SEEK_END);
			file_size = ftell(fp); 
			fseek(fp, 0, SEEK_SET);
			fread(RW_Data, sizeof(char), file_size, fp);
			fclose(fp);
			RW_Data[file_size] = 0;
			pstSize->u32Width = atoi((char*)RW_Data);
		} else {
			pstSize->u32Width = 1920;
		}
		if(access("/kvmapp/kvm/height", F_OK) == 0){
			fp = fopen("/kvmapp/kvm/height", "r");
			fseek(fp, 0, SEEK_END);
			file_size = ftell(fp); 
			fseek(fp, 0, SEEK_SET);
			fread(RW_Data, sizeof(char), file_size, fp);
			fclose(fp);
			RW_Data[file_size] = 0;
			pstSize->u32Height = atoi((char*)RW_Data);
		} else {
			pstSize->u32Height = 1080;
		}

		// if(getenv("KVM_CSI_HEIGHT") == NULL || getenv("KVM_CSI_WIDTH") == NULL){
		// 	pstSize->u32Width  = 1920;
		// 	pstSize->u32Height = 1080;
		// 	printf("KVM_CSI_H/W = NULL%d\n");
		// } else {
		// 	pstSize->u32Width  = atoi(getenv("KVM_CSI_HEIGHT"));
		// 	pstSize->u32Height = atoi(getenv("KVM_CSI_WIDTH"));
		// }
		
		printf("pstSize->u32Width = %d\n", pstSize->u32Width);
		printf("pstSize->u32Height = %d\n", pstSize->u32Height);
		break;
	}
		
	default:
		return CVI_FAILURE;
	}

	return CVI_SUCCESS;
}

/******************************************************************************
 * funciton : Get VI attr info by diffrent sensor
 ******************************************************************************/
CVI_S32 SAMPLE_COMM_SNS_GetDevAttr(SAMPLE_SNS_TYPE_E enSnsType, VI_DEV_ATTR_S *pstViDevAttr)
{
	PIC_SIZE_E enPicSize;
	SIZE_S stSize;

	memcpy(pstViDevAttr, &DEV_ATTR_SENSOR_BASE, sizeof(VI_DEV_ATTR_S));

	SAMPLE_COMM_SNS_GetSize(enSnsType, &enPicSize);
	SAMPLE_COMM_SNS_GetPicSize(enPicSize, &stSize);

	pstViDevAttr->stSize.u32Width = stSize.u32Width;
	pstViDevAttr->stSize.u32Height = stSize.u32Height;
	pstViDevAttr->stWDRAttr.u32CacheLine = stSize.u32Height;

	// WDR mode
	if (enSnsType >= SAMPLE_SNS_TYPE_LINEAR_BUTT)
		pstViDevAttr->stWDRAttr.enWDRMode = WDR_MODE_2To1_LINE;

	// set synthetic wdr mode
	switch (enSnsType) {
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
		pstViDevAttr->stWDRAttr.bSyntheticWDR = 1;
		break;
	default:
		pstViDevAttr->stWDRAttr.bSyntheticWDR = 0;
		break;
	}

	// YUV Sensor
	switch (enSnsType) {
	case NEXTCHIP_N5_1M_2CH_25FPS_8BIT:
	case NEXTCHIP_N5_2M_25FPS_8BIT:
	case NEXTCHIP_N6_2M_4CH_25FPS_8BIT:
	case PICO384_THERMAL_384X288:
	case PICO640_THERMAL_479P:
	case PIXELPLUS_PR2020_1M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_30FPS_8BIT:
	case PIXELPLUS_PR2020_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_2M_30FPS_8BIT:
	case PIXELPLUS_PR2100_2M_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
	case VIVO_MCS369_2M_30FPS_12BIT:
	case VIVO_MCS369Q_4M_30FPS_12BIT:
	case VIVO_MM308M2_2M_25FPS_8BIT:
		pstViDevAttr->enDataSeq = VI_DATA_SEQ_YUYV;
		pstViDevAttr->enInputDataType = VI_DATA_TYPE_YUV;
		pstViDevAttr->enIntfMode = VI_MODE_MIPI_YUV422;
		break;
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
		pstViDevAttr->enDataSeq = VI_DATA_SEQ_YUYV;
		pstViDevAttr->enInputDataType = VI_DATA_TYPE_YUV;
		pstViDevAttr->enIntfMode = VI_MODE_BT601;
		break;
	case TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT:
		pstViDevAttr->enDataSeq = VI_DATA_SEQ_UYVY;
		pstViDevAttr->enInputDataType = VI_DATA_TYPE_YUV;
		pstViDevAttr->enIntfMode = VI_MODE_MIPI_YUV422;
		break;
	default:
		break;
	};

	// BT601
	switch (enSnsType) {
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
		pstViDevAttr->enIntfMode = VI_MODE_BT601;
		break;
	default:
		break;
	};

	// BT656
	switch (enSnsType) {
	case NEXTCHIP_N5_1M_2CH_25FPS_8BIT:
	case NEXTCHIP_N5_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_30FPS_8BIT:
	case PIXELPLUS_PR2020_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_2M_30FPS_8BIT:
		pstViDevAttr->enIntfMode = VI_MODE_BT656;
		break;
	default:
		break;
	};

	// BT1120
	switch (enSnsType) {
	case VIVO_MCS369_2M_30FPS_12BIT:
	case VIVO_MCS369Q_4M_30FPS_12BIT:
	case VIVO_MM308M2_2M_25FPS_8BIT:
	case TECHPOINT_TP2825_MIPI_2M_30FPS_8BIT:
		pstViDevAttr->enDataSeq = VI_DATA_SEQ_YUYV;
		pstViDevAttr->enInputDataType = VI_DATA_TYPE_YUV;
		pstViDevAttr->enIntfMode = VI_MODE_BT1120_STANDARD;
		break;
	default:
		break;
	};

	// subLVDS
	switch (enSnsType) {
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
		pstViDevAttr->enIntfMode = VI_MODE_LVDS;
		break;
	default:
		break;
	};

	switch (enSnsType) {
	// Sony
	case SONY_IMX307_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
#ifdef FPGA_PORTING
	case SONY_IMX327_MIPI_1M_30FPS_10BIT:
	case SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1:
#endif
	case SONY_IMX327_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_MIPI_2M_60FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_4M_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_2L_MIPI_4M_30FPS_10BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_5M_30FPS_12BIT:
	case SONY_IMX335_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_60FPS_10BIT:
	case SONY_IMX335_MIPI_4M_60FPS_10BIT:
	case SONY_IMX335_MIPI_5M_60FPS_10BIT:
	case SONY_IMX347_MIPI_4M_60FPS_12BIT:
	case SONY_IMX347_MIPI_4M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT_WDR2TO1:
	// GalaxyCore
	case GCORE_GC02M1_MIPI_2M_30FPS_10BIT:
	case GCORE_GC1054_MIPI_1M_30FPS_10BIT:
	case GCORE_GC2053_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_1L_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2083_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_60FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC4023_MIPI_4M_30FPS_10BIT:
	// cvsens
	case CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1:
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_RG;
		break;
		// brigates
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT:
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SMS_SC4336_MIPI_4M_30FPS_10BIT:
	case SMS_SC4336P_MIPI_4M_30FPS_10BIT:
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_BG;
		break;
	case GCORE_GC1084_MIPI_1M_30FPS_10BIT:
	case GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT:
	case GCORE_GC4653_MIPI_4M_30FPS_10BIT:
	case GCORE_GC4653_SLAVE_MIPI_4M_30FPS_10BIT:
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_GR;
		break;
	case SOI_K06_MIPI_4M_25FPS_10BIT:
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_GB;
		break;
	case LONTIUM_LT6911_2M_60FPS_8BIT:
		pstViDevAttr->enDataSeq = VI_DATA_SEQ_UYVY;
		pstViDevAttr->enInputDataType = VI_DATA_TYPE_YUV;
		pstViDevAttr->enIntfMode = VI_MODE_MIPI_YUV422;
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_BG;
		break;
	default:
		pstViDevAttr->enBayerFormat = BAYER_FORMAT_BG;
		break;
	};

	// virtual channel for multi-ch
#ifndef ARCH_CV183X
	switch (enSnsType) {
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
		pstViDevAttr->enWorkMode = VI_WORK_MODE_2Multiplex;
		break;
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
		pstViDevAttr->enWorkMode = VI_WORK_MODE_4Multiplex;
		break;
	default:
		pstViDevAttr->enWorkMode = VI_WORK_MODE_1Multiplex;
		break;
	}
#endif

	return CVI_SUCCESS;
}

CVI_S32 SAMPLE_COMM_SNS_GetYuvBypassSts(SAMPLE_SNS_TYPE_E enSnsType)
{
	CVI_S32 s32Ret = 0;
	//Set YUV sensor need bypass isp
	switch (enSnsType) {
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
	case PICO640_THERMAL_479P:
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
	case TECHPOINT_TP2825_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT:
	case VIVO_MCS369Q_4M_30FPS_12BIT:
	case VIVO_MCS369_2M_30FPS_12BIT:
	case VIVO_MM308M2_2M_25FPS_8BIT:
	case NEXTCHIP_N5_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_30FPS_8BIT:
	case PIXELPLUS_PR2020_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_2M_30FPS_8BIT:
	case PIXELPLUS_PR2100_2M_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
		s32Ret = 1;
		break;
	default:
		break;
	}
	return s32Ret;
}
/******************************************************************************
 * funciton : Get ISP attr info by diffrent sensor
 ******************************************************************************/
CVI_S32 SAMPLE_COMM_SNS_GetIspAttrBySns(SAMPLE_SNS_TYPE_E enSnsType, ISP_PUB_ATTR_S *pstPubAttr)
{
	CVI_S32 s32Ret = CVI_SUCCESS;
	PIC_SIZE_E enPicSize;
	SIZE_S stSize;

	memcpy(pstPubAttr, &ISP_PUB_ATTR_SAMPLE, sizeof(ISP_PUB_ATTR_S));

	SAMPLE_COMM_SNS_GetSize(enSnsType, &enPicSize);
	SAMPLE_COMM_SNS_GetPicSize(enPicSize, &stSize);

	pstPubAttr->stSnsSize.u32Width = stSize.u32Width;
	pstPubAttr->stSnsSize.u32Height = stSize.u32Height;
	pstPubAttr->stWndRect.u32Width = stSize.u32Width;
	pstPubAttr->stWndRect.u32Height = stSize.u32Height;

	// WDR mode
	if (enSnsType >= SAMPLE_SNS_TYPE_LINEAR_BUTT)
		pstPubAttr->enWDRMode = WDR_MODE_2To1_LINE;

	// FPS
	switch (enSnsType) {
	case CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1:
		pstPubAttr->f32FrameRate = 15;
		break;
	case SMS_SC035GS_MIPI_480P_120FPS_12BIT:
	case SMS_SC035GS_1L_MIPI_480P_120FPS_10BIT:
	case SMS_SC035HGS_MIPI_480P_120FPS_12BIT:
	case SMS_SC035HGS_1L_MIPI_480P_120FPS_10BIT:
	case OV_OV6211_MIPI_400P_120FPS_10BIT:
	case OV_OV7251_MIPI_480P_120FPS_10BIT:
		pstPubAttr->f32FrameRate = 120;
		break;
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_SLAVE_MIPI_1M_60FPS_10BIT:
	case SONY_IMX307_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
	case SONY_IMX327_MIPI_2M_60FPS_12BIT:
	case SONY_IMX335_MIPI_2M_60FPS_10BIT:
	case SONY_IMX335_MIPI_4M_60FPS_10BIT:
	case SONY_IMX335_MIPI_5M_60FPS_10BIT:
	case SONY_IMX347_MIPI_4M_60FPS_12BIT:
	case GCORE_GC2093_MIPI_2M_60FPS_10BIT:
		pstPubAttr->f32FrameRate = 60;
		break;
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT:
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_SLAVE_MIPI_1M_30FPS_10BIT:
	case SMS_SC223A_1L_MIPI_2M_30FPS_10BIT:
	case SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX347_MIPI_4M_30FPS_12BIT_WDR2TO1:
	case OV_OV5647_MIPI_2M_30FPS_10BIT:
	case GCORE_GC1084_MIPI_1M_30FPS_10BIT:
	case GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT:
	case GCORE_GC2083_MIPI_2M_30FPS_10BIT:
	case BYD_BF2253L_MIPI_1200P_30FPS_10BIT:
		pstPubAttr->f32FrameRate = 30;
		break;
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
		pstPubAttr->f32FrameRate = 12;
		break;
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
		pstPubAttr->f32FrameRate = 20;
		break;
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
		pstPubAttr->f32FrameRate = 10;
		break;
#ifdef FPGA_PORTING
	case SONY_IMX327_MIPI_1M_30FPS_10BIT:
	case SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1:
		pstPubAttr->f32FrameRate = 10;
		break;
#endif
	case CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT:
	case TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT:
		pstPubAttr->f32FrameRate = 25;
		break;
	default:
		pstPubAttr->f32FrameRate = 25;
		break;
	}

	switch (enSnsType) {
	case SOI_K06_MIPI_4M_25FPS_10BIT:
		pstPubAttr->enBayer = BAYER_GBRG;
		break;
	case LONTIUM_LT6911_2M_60FPS_8BIT:
		pstPubAttr->enBayer = BAYER_BGGR;
		pstPubAttr->f32FrameRate = 60;
		break;
	// Sony
	case SONY_IMX307_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX307_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
#ifdef FPGA_PORTING
	case SONY_IMX327_MIPI_1M_30FPS_10BIT:
	case SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1:
#endif
	case SONY_IMX327_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX327_MIPI_2M_60FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_4M_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_2L_MIPI_4M_30FPS_10BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_5M_30FPS_12BIT:
	case SONY_IMX335_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_60FPS_10BIT:
	case SONY_IMX335_MIPI_4M_60FPS_10BIT:
	case SONY_IMX335_MIPI_5M_60FPS_10BIT:
	case SONY_IMX347_MIPI_4M_60FPS_12BIT:
	case SONY_IMX347_MIPI_4M_30FPS_12BIT_WDR2TO1:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT_WDR2TO1:
	// GalaxyCore
	case GCORE_GC02M1_MIPI_2M_30FPS_10BIT:
	case GCORE_GC1054_MIPI_1M_30FPS_10BIT:
	case GCORE_GC2053_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2053_1L_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2083_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_60FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case GCORE_GC4023_MIPI_4M_30FPS_10BIT:
	case IMGDS_MIS2008_MIPI_2M_1080P_30FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1:
		pstPubAttr->enBayer = BAYER_RGGB;
		break;
	case GCORE_GC1084_MIPI_1M_30FPS_10BIT:
	case GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT:
	case GCORE_GC4653_MIPI_4M_30FPS_10BIT:
	case GCORE_GC4653_SLAVE_MIPI_4M_30FPS_10BIT:
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
		// on licheervnano
		pstPubAttr->enBayer = BAYER_RGGB;
		//pstPubAttr->enBayer = BAYER_GRBG;
		break;
#ifdef ARCH_CV182X
	case SOI_F23_MIPI_2M_30FPS_10BIT:
		pstPubAttr->enBayer = BAYER_BGRGI;
	break;
#endif
	default:
		pstPubAttr->enBayer = BAYER_BGGR;
		break;
	};

	return s32Ret;
}

/******************************************************************************
 * funciton : Get sns_obj callback
 ******************************************************************************/
CVI_VOID *SAMPLE_COMM_SNS_GetSnsObj(SAMPLE_SNS_TYPE_E enSnsType)
{
	CVI_VOID *pSnsObj;

	switch (enSnsType) {
#if defined(SENSOR_BRIGATES_BG0808)
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT:
	case BRIGATES_BG0808_MIPI_2M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsBG0808_Obj;
		break;
#endif
#if defined(SENSOR_BYD_BF2253L)
	case BYD_BF2253L_MIPI_1200P_30FPS_10BIT:
		pSnsObj = &stSnsBF2253L_Obj;
		break;
#endif
#if defined(SENSOR_CVSENS_CV4001)
	case CVSENS_CV4001_MIPI_4M_1440P_25FPS_12BIT:
	case CVSENS_CV4001_MIPI_4M_1440P_15FPS_WDR2TO1:
		return &stSnsCV4001_Obj;
#endif
#if defined(SENSOR_GCORE_GC02M1)
	case GCORE_GC02M1_MIPI_2M_30FPS_10BIT:
		return &stSnsGc02m1_Obj;
#endif
#if defined(SENSOR_GCORE_GC0312)
	case GCORE_GC0312_MIPI_480P_20FPS_8BIT:
		return &stSnsGc0312_Obj;
#endif
#if defined(SENSOR_GCORE_GC0329)
	case GCORE_GC0329_MIPI_480P_10FPS_8BIT:
		return &stSnsGc0329_Obj;
#endif
#if defined(SENSOR_GCORE_GC1054)
	case GCORE_GC1054_MIPI_1M_30FPS_10BIT:
		return &stSnsGc1054_Obj;
#endif
#if defined(SENSOR_GCORE_GC1084)
	case GCORE_GC1084_MIPI_1M_30FPS_10BIT:
		return &stSnsGc1084_Obj;
#endif
#if defined(SENSOR_GCORE_GC1084_SLAVE)
	case GCORE_GC1084_SLAVE_MIPI_1M_30FPS_10BIT:
		return &stSnsGc1084_Slave_Obj;
#endif
#if defined(SENSOR_GCORE_GC2053)
	case GCORE_GC2053_MIPI_2M_30FPS_10BIT:
		return &stSnsGc2053_Obj;
#endif
#if defined(SENSOR_GCORE_GC2053_SLAVE)
	case GCORE_GC2053_SLAVE_MIPI_2M_30FPS_10BIT:
		return &stSnsGc2053_Slave_Obj;
#endif
#if defined(SENSOR_GCORE_GC2053_1L)
	case GCORE_GC2053_1L_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsGc2053_1l_Obj;
		break;
#endif
#if defined(SENSOR_GCORE_GC2083)
	case GCORE_GC2083_MIPI_2M_30FPS_10BIT:
		return &stSnsGc2083_Obj;
#endif
#if defined(SENSOR_GCORE_GC2093)
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_60FPS_10BIT:
	case GCORE_GC2093_MIPI_2M_30FPS_10BIT_WDR2TO1:
		return &stSnsGc2093_Obj;
#endif
#if defined(SENSOR_GCORE_GC2093_SLAVE)
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT:
	case GCORE_GC2093_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
		return &stSnsGc2093_Slave_Obj;
#endif
#if defined(SENSOR_GCORE_GC2145)
	case GCORE_GC2145_MIPI_2M_12FPS_8BIT:
		return &stSnsGc2145_Obj;
#endif
#if defined(SENSOR_GCORE_GC4023)
	case GCORE_GC4023_MIPI_4M_30FPS_10BIT:
		return &stSnsGc4023_Obj;
#endif
#if defined(SENSOR_GCORE_GC4653)
	case GCORE_GC4653_MIPI_4M_30FPS_10BIT:
		return &stSnsGc4653_Obj;
#endif
#if defined(SENSOR_GCORE_GC4653_SLAVE)
	case GCORE_GC4653_SLAVE_MIPI_4M_30FPS_10BIT:
		return &stSnsGc4653_Slave_Obj;
#endif
#if defined(SENSOR_ID_MIS2008)
	case IMGDS_MIS2008_MIPI_2M_1080P_30FPS_12BIT:
		pSnsObj = &stSnsMIS2008_Obj;
		break;
#endif
#if defined(SENSOR_NEXTCHIP_N5)
	case NEXTCHIP_N5_2M_25FPS_8BIT:
	case NEXTCHIP_N5_1M_2CH_25FPS_8BIT:
		pSnsObj = &stSnsN5_Obj;
		break;
#endif
#if defined(SENSOR_NEXTCHIP_N6)
	case NEXTCHIP_N6_2M_4CH_25FPS_8BIT:
		pSnsObj = &stSnsN6_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS02D10)
	case OV_OS02D10_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsOs02d10_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS02D10_SLAVE)
	case OV_OS02D10_SLAVE_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsOs02d10_Slave_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS02K10_SLAVE)
	case OV_OS02K10_SLAVE_MIPI_2M_30FPS_12BIT:
		pSnsObj = &stSnsOs02k10_Slave_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS04A10)
	case OV_OS04A10_MIPI_4M_1440P_30FPS_12BIT:
	case OV_OS04A10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsOs04a10_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS04C10)
	case OV_OS04C10_MIPI_4M_30FPS_12BIT:
	case OV_OS04C10_MIPI_4M_1440P_30FPS_12BIT:
	case OV_OS04C10_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OS04C10_MIPI_4M_1440P_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsOs04c10_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS04C10_SLAVE)
	case OV_OS04C10_SLAVE_MIPI_4M_30FPS_12BIT:
	case OV_OS04C10_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsOs04c10_Slave_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS08A20)
	case OV_OS08A20_MIPI_4M_30FPS_10BIT:
	case OV_OS08A20_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_MIPI_5M_30FPS_10BIT:
	case OV_OS08A20_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_MIPI_8M_30FPS_10BIT:
	case OV_OS08A20_MIPI_8M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsOs08a20_Obj;
		break;
#endif
#if defined(SENSOR_OV_OS08A20_SLAVE)
	case OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT:
	case OV_OS08A20_SLAVE_MIPI_8M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsOs08a20_Slave_Obj;
		break;
#endif
#if defined(SENSOR_OV_OV4689)
	case OV_OV4689_MIPI_4M_30FPS_10BIT:
		pSnsObj = &stSnsOv4689_Obj;
		break;
#endif
#if defined(SENSOR_OV_OV5647)
	case OV_OV5647_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsOv5647_Obj;
		break;
#endif
#if defined(SENSOR_OV_OV6211)
	case OV_OV6211_MIPI_400P_120FPS_10BIT:
		pSnsObj = &stSnsOv6211_Obj;
		break;
#endif
#if defined(SENSOR_OV_OV7251)
	case OV_OV7251_MIPI_480P_120FPS_10BIT:
		pSnsObj = &stSnsOv7251_Obj;
		break;
#endif
#if defined(SENSOR_PICO_384)
	case PICO384_THERMAL_384X288:
		pSnsObj = &stSnsPICO384_Obj;
		break;
#endif
#if defined(SENSOR_PICO_640)
	case PICO640_THERMAL_479P:
		pSnsObj = &stSnsPICO640_Obj;
		break;
#endif
#if defined(SENSOR_PIXELPLUS_PR2020)
	case PIXELPLUS_PR2020_1M_25FPS_8BIT:
	case PIXELPLUS_PR2020_1M_30FPS_8BIT:
	case PIXELPLUS_PR2020_2M_25FPS_8BIT:
	case PIXELPLUS_PR2020_2M_30FPS_8BIT:
		pSnsObj = &stSnsPR2020_Obj;
		break;
#endif
#if defined(SENSOR_PIXELPLUS_PR2100)
	case PIXELPLUS_PR2100_2M_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_2CH_25FPS_8BIT:
	case PIXELPLUS_PR2100_2M_4CH_25FPS_8BIT:
		pSnsObj = &stSnsPR2100_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC035GS)
	case SMS_SC035GS_MIPI_480P_120FPS_12BIT:
		pSnsObj = &stSnsSC035GS_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC035GS_1L)
	case SMS_SC035GS_1L_MIPI_480P_120FPS_10BIT:
		pSnsObj = &stSnsSC035GS_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC035HGS)
	case SMS_SC035HGS_MIPI_480P_120FPS_12BIT:
		pSnsObj = &stSnsSC035HGS_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC035HGS_1L)
	case SMS_SC035HGS_1L_MIPI_480P_120FPS_10BIT:
		pSnsObj = &stSnsSC035HGS_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC1336_1L)
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1336_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC1336_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC1346_1L)
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_30FPS_10BIT_WDR2TO1:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT:
	case SMS_SC1346_1L_MIPI_1M_60FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC1346_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC1346_1L_SLAVE)
	case SMS_SC1346_1L_SLAVE_MIPI_1M_30FPS_10BIT:
	case SMS_SC1346_1L_SLAVE_MIPI_1M_60FPS_10BIT:
		pSnsObj = &stSnsSC1346_1L_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC200AI)
	case SMS_SC200AI_MIPI_2M_30FPS_10BIT:
	case SMS_SC200AI_MIPI_2M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC200AI_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC301IOT)
	case SMS_SC301IOT_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC301IOT_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC401AI)
	case SMS_SC401AI_MIPI_4M_30FPS_10BIT:
	case SMS_SC401AI_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC401AI_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC500AI)
	case SMS_SC500AI_MIPI_5M_30FPS_10BIT:
	case SMS_SC500AI_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SMS_SC500AI_MIPI_4M_30FPS_10BIT:
	case SMS_SC500AI_MIPI_4M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC500AI_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC501AI_2L)
	case SMS_SC501AI_2L_MIPI_5M_30FPS_10BIT:
		pSnsObj = &stSnsSC501AI_2L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC531AI_2L)
	case SMS_SC531AI_2L_MIPI_5M_30FPS_10BIT:
		pSnsObj = &stSnsSC531AI_2L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC850SL)
	case SMS_SC850SL_MIPI_8M_30FPS_12BIT:
	case SMS_SC850SL_MIPI_8M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC850SL_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC3332)
	case SMS_SC3332_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC3332_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC3335)
	case SMS_SC3335_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC3335_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC3335_SLAVE)
	case SMS_SC3335_SLAVE_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC3335_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC3336)
	case SMS_SC3336_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC3336_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC3336P)
	case SMS_SC3336P_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsSC3336P_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2331_1L)
	case SMS_SC2331_1L_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2331_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2331_1L_SLAVE)
	case SMS_SC2331_1L_SLAVE_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2331_1L_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2331_1L_SLAVE1)
	case SMS_SC2331_1L_SLAVE1_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2331_1L_Slave1_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2335)
	case SMS_SC2335_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2335_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336)
	case SMS_SC2336_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336_SLAVE)
	case SMS_SC2336_SLAVE_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336_SLAVE1)
	case SMS_SC2336_SLAVE1_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336_Slave1_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336_1L)
	case SMS_SC2336_1L_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336P)
	case SMS_SC2336P_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336P_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC2336P_1L)
	case SMS_SC2336P_1L_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC2336P_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC223A_1L)
	case SMS_SC223A_1L_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsSC223A_1L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC4210)
	case SMS_SC4210_MIPI_4M_30FPS_12BIT:
	case SMS_SC4210_MIPI_4M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC4210_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC4336)
	case SMS_SC4336_MIPI_4M_30FPS_10BIT:
		pSnsObj = &stSnsSC4336_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC4336P)
	case SMS_SC4336P_MIPI_4M_30FPS_10BIT:
		pSnsObj = &stSnsSC4336P_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC5336_2L)
	case SMS_SC5336_2L_MIPI_5M_30FPS_10BIT:
		pSnsObj = &stSnsSC5336_2L_Obj;
		break;
#endif
#if defined(SENSOR_SMS_SC8238)
	case SMS_SC8238_MIPI_8M_30FPS_10BIT:
	case SMS_SC8238_MIPI_8M_15FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsSC8238_Obj;
		break;
#endif
#if defined(SENSOR_SOI_F23)
	case SOI_F23_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsF23_Obj;
		break;
#endif
#if defined(SENSOR_SOI_F35)
	case SOI_F35_MIPI_2M_30FPS_10BIT:
	case SOI_F35_MIPI_2M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsF35_Obj;
		break;
#endif
#if defined(SENSOR_SOI_F35_SLAVE)
	case SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT:
	case SOI_F35_SLAVE_MIPI_2M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsF35_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SOI_F37P)
	case SOI_F37P_MIPI_2M_30FPS_10BIT:
		pSnsObj = &stSnsF37P_Obj;
		break;
#endif
#if defined(SENSOR_SOI_H65)
	case SOI_H65_MIPI_1M_30FPS_10BIT:
		pSnsObj = &stSnsH65_Obj;
		break;
#endif
#if defined(SENSOR_SOI_K06)
	case SOI_K06_MIPI_4M_25FPS_10BIT:
		return &stSnsK06_Obj;
#endif
#if defined(SENSOR_SOI_Q03)
	case SOI_Q03_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsQ03_Obj;
		break;
#endif
#if defined(SENSOR_SOI_Q03P)
	case SOI_Q03P_MIPI_3M_30FPS_10BIT:
		pSnsObj = &stSnsQ03P_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX290_2L)
	case SONY_IMX290_MIPI_1M_30FPS_12BIT:
	case SONY_IMX290_MIPI_2M_60FPS_12BIT:
		pSnsObj = &stSnsImx290_2l_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX307)
	case SONY_IMX307_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_MIPI_2M_60FPS_12BIT:
	case SONY_IMX307_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx307_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX307_SLAVE)
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx307_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX307_2L)
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX307_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx307_2l_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX307_SUBLVDS)
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_60FPS_12BIT:
	case SONY_IMX307_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx307_Sublvds_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX327)
	case SONY_IMX327_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_MIPI_2M_60FPS_12BIT:
	case SONY_IMX327_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx327_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX327_SLAVE)
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_SLAVE_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx327_Slave_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX327_2L)
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT:
	case SONY_IMX327_2L_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx327_2l_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX327_FPGA) && defined(FPGA_PORTING)
	case SONY_IMX327_MIPI_1M_30FPS_10BIT:
	case SONY_IMX327_MIPI_1M_30FPS_10BIT_WDR2TO1:
		pSnsObj = &stSnsImx327_fpga_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX327_SUBLVDS)
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT:
	case SONY_IMX327_SUBLVDS_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx327_Sublvds_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX334)
	case SONY_IMX334_MIPI_8M_30FPS_12BIT:
	case SONY_IMX334_MIPI_8M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx334_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX335)
	case SONY_IMX335_MIPI_2M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_4M_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_2L_MIPI_4M_30FPS_10BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_12BIT:
	case SONY_IMX335_MIPI_4M_1600P_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_5M_30FPS_12BIT:
	case SONY_IMX335_MIPI_5M_30FPS_10BIT_WDR2TO1:
	case SONY_IMX335_MIPI_2M_60FPS_10BIT:
	case SONY_IMX335_MIPI_4M_60FPS_10BIT:
	case SONY_IMX335_MIPI_5M_60FPS_10BIT:
		pSnsObj = &stSnsImx335_Obj;
		break;
#endif
#if defined(SENSOR_SONY_IMX347)
	case SONY_IMX347_MIPI_4M_60FPS_12BIT:
	case SONY_IMX347_MIPI_4M_30FPS_12BIT_WDR2TO1:
		return &stSnsImx347_Obj;
#endif
#if defined(SENSOR_SONY_IMX385)
	case SONY_IMX385_MIPI_2M_30FPS_12BIT:
	case SONY_IMX385_MIPI_2M_30FPS_12BIT_WDR2TO1:
		pSnsObj = &stSnsImx385_Obj;
		break;
#endif
#if defined(SENSOR_TECHPOINT_TP2850)
	case TECHPOINT_TP2850_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2850_MIPI_4M_30FPS_8BIT:
		pSnsObj = &stSnsTP2850_Obj;
		break;
#endif
#if defined(SENSOR_TECHPOINT_TP2825)
	case TECHPOINT_TP2825_MIPI_2M_30FPS_8BIT:
		pSnsObj = &stSnsTP2825_Obj;
		break;
#endif
#if defined(SENSOR_TECHPOINT_TP2863)
	case TECHPOINT_TP2863_MIPI_1M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_30FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_1M_25FPS_8BIT:
	case TECHPOINT_TP2863_MIPI_2M_25FPS_8BIT:
		pSnsObj = &stSnsTP2863_Obj;
		break;
#endif
#if defined(SENSOR_VIVO_MCS369)
	case VIVO_MCS369_2M_30FPS_12BIT:
		pSnsObj = &stSnsMCS369_Obj;
		break;
#endif
#if defined(SENSOR_VIVO_MCS369Q)
	case VIVO_MCS369Q_4M_30FPS_12BIT:
		pSnsObj = &stSnsMCS369Q_Obj;
		break;
#endif
#if defined(SENSOR_VIVO_MM308M2)
	case VIVO_MM308M2_2M_25FPS_8BIT:
		pSnsObj = &stSnsMM308M2_Obj;
		break;
#endif
#if defined(SENSOR_LONTIUM_LT6911)
	case LONTIUM_LT6911_2M_60FPS_8BIT:
		pSnsObj = &stSnsLT6911_Obj;
		break;
#endif
	default:
		pSnsObj = CVI_NULL;
		break;
	}
	return pSnsObj;
}

/******************************************************************************
 * funciton : Get sns_cfg from sensor_cfg.ini
 ******************************************************************************/

/*=== Source section parser handler begin === */
static void parse_source_type(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	(CVI_VOID) param0;
	(CVI_VOID) param1;
	(CVI_VOID) param2;

	SAMPLE_PRT("source type =  %s\n", value);
	if (strcmp(value, "SOURCE_USER_FE") == 0) {
		cfg->enSource = VI_PIPE_FRAME_SOURCE_USER_FE;
	}
}

static void parse_source_devnum(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	int devno = atoi(value);

	(CVI_VOID) param0;
	(CVI_VOID) param1;
	(CVI_VOID) param2;

	SAMPLE_PRT("devNum =  %s\n", value);

	if (devno >= 1 && devno <= VI_MAX_DEV_NUM)
		cfg->devNum = devno;
	else
		cfg->devNum = 1;
}
/* === Source section parser handler end === */

/* === Sensor section parser handler begin === */
static int parse_lane_id(CVI_S16 *LaneId, const char *value)
{
	char buf[8];
	int offset = 0, idx = 0, k;

	for (k = 0; k < 30; k++) {
		/* find next ',' */
		if (value[k] == ',' || value[k] == '\0') {
			if (k == offset) {
				SAMPLE_PRT("lane_id parse error, is the format correct?\n");
				return -1;
			}
			memset(buf, 0, sizeof(buf));
			memcpy(buf, &value[offset], k - offset);
			buf[k-offset] = '\0';
			LaneId[idx++] = atoi(buf);
			offset = k + 1;
		}

		if (value[k] == '\0' || idx == 5)
			break;
	}

	if (k == 30) {
		SAMPLE_PRT("lane_id parse error, is the format correct?\n");
		return -1;
	}

	return 0;
}

static int parse_pn_swap(CVI_S8 *PNSwap, const char *value)
{
	char buf[8];
	int offset = 0, idx = 0, k;

	for (k = 0; k < 30; k++) {
		/* find next ',' */
		if (value[k] == ',' || value[k] == '\0') {
			if (k == offset) {
				SAMPLE_PRT("lane_id parse error, is the format correct?\n");
				return -1;
			}
			memset(buf, 0, sizeof(buf));
			memcpy(buf, &value[offset], k - offset);
			buf[k-offset] = '\0';
			PNSwap[idx++] = atoi(buf);
			offset = k + 1;
		}

		if (value[k] == '\0' || idx == 5)
			break;
	}

	if (k == 30) {
		SAMPLE_PRT("lane_id parse error, is the format correct?\n");
		return -1;
	}

	return 0;
}

static void parse_sensor_name(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
#define NAME_SIZE 20
	CVI_U32 index = param0;
	CVI_U32 i;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("sensor =  %s\n", value);
	char sensorNameEnv[NAME_SIZE];

	snprintf(sensorNameEnv, NAME_SIZE, "SENSORNAME%d", index);
	setenv(sensorNameEnv, value, 1);

	for (i = 0; i < SAMPLE_SNS_TYPE_BUTT; i++) {
		if (strcmp(value, snsr_type_name[i]) == 0) {
			cfg->enSnsType[index] = i;
			cfg->enWDRMode[index] = (i < SAMPLE_SNS_TYPE_LINEAR_BUTT) ?
				WDR_MODE_NONE : WDR_MODE_2To1_LINE;
			break;
		}
	}
	if (i == SAMPLE_SNS_TYPE_BUTT) {
		cfg->enSnsType[index] = SAMPLE_SNS_TYPE_BUTT;
		cfg->enWDRMode[index] = WDR_MODE_NONE;
		cfg->u8UseMultiSns = index;
		SAMPLE_PRT("ERROR: can not find sensor ini in /mnt/data/\n");
	}
}

static void parse_sensor_busid(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("bus_id =  %s\n", value);
	cfg->s32BusId[index] = atoi(value);
}

static void parse_sensor_i2caddr(SAMPLE_INI_CFG_S *cfg, const char *value,
					CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("sns_i2c_addr =  %s\n", value);
	cfg->s32SnsI2cAddr[index] = atoi(value);
}

static void parse_sensor_mipidev(SAMPLE_INI_CFG_S *cfg, const char *value,
					CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("mipi_dev =  %s\n", value);
	cfg->MipiDev[index] = atoi(value);
}

static void parse_sensor_laneid(SAMPLE_INI_CFG_S *cfg, const char *value,
					CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("Lane_id =  %s\n", value);
	parse_lane_id(cfg->as16LaneId[index], value);
}

static void parse_sensor_pnswap(SAMPLE_INI_CFG_S *cfg, const char *value,
					CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("pn_swap =  %s\n", value);
	parse_pn_swap(cfg->as8PNSwap[index], value);
}

static void parse_sensor_hwsync(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("hw_sync =  %s\n", value);
	cfg->u8HwSync[index] = atoi(value);
}

static void parse_sensor_mclken(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("mclk_en =  %s\n", value);
	cfg->stMclkAttr[index].bMclkEn = atoi(value);
}

static void parse_sensor_mclk(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("mclk =  %s\n", value);
	cfg->stMclkAttr[index].u8Mclk = atoi(value);
}

static void parse_sensor_orien(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("orien =  %s\n", value);
	cfg->u8Orien[index] = atoi(value);
}

static void parse_sensor_muxdev(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("muxdev =  %s\n", value);
	cfg->u8MuxDev[index] = atoi(value);
}

static void parse_sensor_attachdev(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("attach_dev =  %s\n", value);
	cfg->u8AttachDev[index] = atoi(value);
}

static void parse_sensor_switchgpio(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("switch_gpio =  %s\n", value);
	cfg->s16SwitchGpio[index] = atoi(value);
}

static void parse_sensor_switchpol(SAMPLE_INI_CFG_S *cfg, const char *value,
				CVI_U32 param0, CVI_U32 param1, CVI_U32 param2)
{
	CVI_U32 index = param0;

	(CVI_VOID) param1;
	(CVI_VOID) param2;
	SAMPLE_PRT("switch_pol =  %s\n", value);
	cfg->u8SwitchPol[index] = atoi(value);
}

 /* === Sensor section parser handler end === */
typedef CVI_VOID(*parser)(SAMPLE_INI_CFG_S *cfg, const char *value,
		CVI_U32 param0, CVI_U32 param1, CVI_U32 param2);

typedef struct _INI_HDLR_S {
	const char name[16];
	CVI_U32 param0;
	CVI_U32 param1;
	CVI_U32 param2;
	parser pfnJob;
} INI_HDLR_S;

typedef enum _INI_SOURCE_NAME_E {
	INI_SOURCE_TYPE = 0,
	INI_SOURCE_DEVNUM,
	INI_SOURCE_NUM,
} INI_SOURCE_NAME_E;

typedef enum _INI_SENSOR_NAME_E {
	INI_SENSOR_NAME = 0,
	INI_SENSOR_BUSID,
	INI_SENSOR_I2CADDR,
	INI_SENSOR_MIPIDEV,
	INI_SENSOR_LANEID,
	INI_SENSOR_PNSWAP,
	INI_SENSOR_HWSYNC,
	INI_SENSOR_MCLKEN,
	INI_SENSOR_MCLK,
	INI_SENSOR_ORIEN,
	INI_SENSOR_MUXDEV,
	INI_SENSOR_ATTACHDEV,
	INI_SENSOR_SWITCHGPIO,
	INI_SENSOR_SWITCHPOL,
	INI_SENSOR_NUM,
} INI_SENSOR_NAME_E;

const INI_HDLR_S stSectionSource[INI_SOURCE_NUM] = {
	[INI_SOURCE_TYPE] = {"type", 0, 0, 0, parse_source_type},
	[INI_SOURCE_DEVNUM] = {"dev_num", 0, 0, 0, parse_source_devnum},
};

const INI_HDLR_S stSectionSensor1[INI_SENSOR_NUM] = {
	[INI_SENSOR_NAME] = {"name", 0, 0, 0, parse_sensor_name},
	[INI_SENSOR_BUSID] = {"bus_id", 0, 0, 0, parse_sensor_busid},
	[INI_SENSOR_I2CADDR] = {"sns_i2c_addr", 0, 0, 0, parse_sensor_i2caddr},
	[INI_SENSOR_MIPIDEV] = {"mipi_dev", 0, 0, 0, parse_sensor_mipidev},
	[INI_SENSOR_LANEID] = {"lane_id", 0, 0, 0, parse_sensor_laneid},
	[INI_SENSOR_PNSWAP] = {"pn_swap", 0, 0, 0, parse_sensor_pnswap},
	[INI_SENSOR_HWSYNC] = {"hw_sync", 0, 0, 0, parse_sensor_hwsync},
	[INI_SENSOR_MCLKEN] = {"mclk_en", 0, 0, 0, parse_sensor_mclken},
	[INI_SENSOR_MCLK] = {"mclk", 0, 0, 0, parse_sensor_mclk},
	[INI_SENSOR_ORIEN] = {"orien", 0, 0, 0, parse_sensor_orien},
	[INI_SENSOR_MUXDEV] = {"mux_dev", 0, 0, 0, parse_sensor_muxdev},
	[INI_SENSOR_ATTACHDEV] = {"attach_dev", 0, 0, 0, parse_sensor_attachdev},
	[INI_SENSOR_SWITCHGPIO] = {"switch_gpio", 0, 0, 0, parse_sensor_switchgpio},
	[INI_SENSOR_SWITCHPOL] = {"switch_pol", 0, 0, 0, parse_sensor_switchpol},
};

const INI_HDLR_S stSectionSensor2[INI_SENSOR_NUM] = {
	[INI_SENSOR_NAME] = {"name", 1, 0, 0, parse_sensor_name},
	[INI_SENSOR_BUSID] = {"bus_id", 1, 0, 0, parse_sensor_busid},
	[INI_SENSOR_I2CADDR] = {"sns_i2c_addr", 1, 0, 0, parse_sensor_i2caddr},
	[INI_SENSOR_MIPIDEV] = {"mipi_dev", 1, 0, 0, parse_sensor_mipidev},
	[INI_SENSOR_LANEID] = {"lane_id", 1, 0, 0, parse_sensor_laneid},
	[INI_SENSOR_PNSWAP] = {"pn_swap", 1, 0, 0, parse_sensor_pnswap},
	[INI_SENSOR_HWSYNC] = {"hw_sync", 1, 0, 0, parse_sensor_hwsync},
	[INI_SENSOR_MCLKEN] = {"mclk_en", 1, 0, 0, parse_sensor_mclken},
	[INI_SENSOR_MCLK] = {"mclk", 1, 0, 0, parse_sensor_mclk},
	[INI_SENSOR_ORIEN] = {"orien", 1, 0, 0, parse_sensor_orien},
	[INI_SENSOR_MUXDEV] = {"mux_dev", 1, 0, 0, parse_sensor_muxdev},
	[INI_SENSOR_ATTACHDEV] = {"attach_dev", 1, 0, 0, parse_sensor_attachdev},
	[INI_SENSOR_SWITCHGPIO] = {"switch_gpio", 1, 0, 0, parse_sensor_switchgpio},
	[INI_SENSOR_SWITCHPOL] = {"switch_pol", 1, 0, 0, parse_sensor_switchpol},
};

const INI_HDLR_S stSectionSensor3[INI_SENSOR_NUM] = {
	[INI_SENSOR_NAME] = {"name", 2, 0, 0, parse_sensor_name},
	[INI_SENSOR_BUSID] = {"bus_id", 2, 0, 0, parse_sensor_busid},
	[INI_SENSOR_I2CADDR] = {"sns_i2c_addr", 2, 0, 0, parse_sensor_i2caddr},
	[INI_SENSOR_MIPIDEV] = {"mipi_dev", 2, 0, 0, parse_sensor_mipidev},
	[INI_SENSOR_LANEID] = {"lane_id", 2, 0, 0, parse_sensor_laneid},
	[INI_SENSOR_PNSWAP] = {"pn_swap", 2, 0, 0, parse_sensor_pnswap},
	[INI_SENSOR_HWSYNC] = {"hw_sync", 2, 0, 0, parse_sensor_hwsync},
	[INI_SENSOR_MCLKEN] = {"mclk_en", 2, 0, 0, parse_sensor_mclken},
	[INI_SENSOR_MCLK] = {"mclk", 2, 0, 0, parse_sensor_mclk},
	[INI_SENSOR_ORIEN] = {"orien", 2, 0, 0, parse_sensor_orien},
	[INI_SENSOR_MUXDEV] = {"mux_dev", 2, 0, 0, parse_sensor_muxdev},
	[INI_SENSOR_ATTACHDEV] = {"attach_dev", 2, 0, 0, parse_sensor_attachdev},
	[INI_SENSOR_SWITCHGPIO] = {"switch_gpio", 2, 0, 0, parse_sensor_switchgpio},
	[INI_SENSOR_SWITCHPOL] = {"switch_pol", 2, 0, 0, parse_sensor_switchpol},
};

CVI_S32 SAMPLE_COMM_SNS_SetIniPath(const CVI_CHAR *iniPath)
{
	int ret;

	if (iniPath == NULL) {
		SAMPLE_PRT("%s: null ptr\n", __func__);
		ret = CVI_FAILURE;
	} else if (strlen(iniPath) >= SNSCFGPATH_SIZE) {
		SAMPLE_PRT("%s: SNSCFGPATH_SIZE is too small\n", __func__);
		ret = CVI_FAILURE;
	} else {
		strncpy(g_snsCfgPath, iniPath, SNSCFGPATH_SIZE);
		ret = CVI_SUCCESS;
	}

	return ret;
}

static int parse_handler(void *user, const char *section, const char *name, const char *value)
{
	SAMPLE_INI_CFG_S *cfg = (SAMPLE_INI_CFG_S *)user;
	const INI_HDLR_S *hdler;
	int i, size;

	if (strcmp(section, "source") == 0) {
		hdler = stSectionSource;
		size = INI_SOURCE_NUM;
	} else if (strcmp(section, "sensor") == 0) {
		hdler = stSectionSensor1;
		size = INI_SENSOR_NUM;
	} else if (strcmp(section, "sensor2") == 0) {
		hdler = stSectionSensor2;
		size = INI_SENSOR_NUM;
	} else if (strcmp(section, "sensor3") == 0) {
		hdler = stSectionSensor3;
		size = INI_SENSOR_NUM;
	} else {
		/* unknown section/name */
		return 1;
	}
	for (i = 0; i < size; i++) {
		if (strcmp(name, hdler[i].name) == 0) {
			hdler[i].pfnJob(cfg, value, hdler[i].param0,
					hdler[i].param1, hdler[i].param2);
			break;
		}
	}

	return 1;
}

CVI_S32 SAMPLE_COMM_SNS_ParseIni(SAMPLE_INI_CFG_S *pstIniCfg)
{
	int ret;

	memcpy(pstIniCfg, &stDefIniCfg, sizeof(*pstIniCfg));
	if (g_snsCfgPath[0] != 0) {
		SAMPLE_PRT("Parse %s\n", g_snsCfgPath);
		ret = ini_parse(g_snsCfgPath, parse_handler, pstIniCfg);
		if (ret >= 0) {
			return CVI_SUCCESS;
		}
		if (ret != -1) {
			SAMPLE_PRT("Parse %s incomplete, use default cfg\n", INI_FILE_PATH);
			return CVI_FAILURE;
		}

		SAMPLE_PRT("%s Not Found\n", g_snsCfgPath);
	}
	SAMPLE_PRT("Parse %s\n", INI_FILE_PATH);
	ret = ini_parse(INI_FILE_PATH, parse_handler, pstIniCfg);
	if (ret >= 0) {
		return CVI_SUCCESS;
	}
	if (ret != -1) {
		SAMPLE_PRT("Parse %s incomplete, use default cfg\n", INI_FILE_PATH);
		return CVI_FAILURE;
	}
	SAMPLE_PRT("%s Not Found\n", INI_FILE_PATH);
	SAMPLE_PRT("Parse %s\n", INI_DEF_PATH);

	ret = ini_parse(INI_DEF_PATH, parse_handler, pstIniCfg);
	if (ret < 0) {
		if (ret == -1) {
			SAMPLE_PRT("%s not exist, use default cfg\n", INI_DEF_PATH);
		} else {
			SAMPLE_PRT("Parse %s incomplete, use default cfg\n", INI_DEF_PATH);
		}

		return CVI_FAILURE;
	}

	return CVI_SUCCESS;
}
