From 8456a35b69fb53d3e3389318d2affe58e01e647a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Thu, 29 Aug 2024 18:12:14 -0400 Subject: [PATCH] Updated SDK components for CVITEK chips --- src/hal/plus/cvi_hal.c | 40 +++++++++++++++++++--------------------- src/hal/plus/cvi_hal.h | 2 -- src/hal/plus/cvi_isp.h | 3 ++- src/hal/plus/cvi_snr.h | 24 ++++++++++++------------ src/hal/plus/cvi_sys.h | 7 +++++-- src/hal/plus/cvi_vb.h | 2 +- src/hal/plus/cvi_venc.h | 20 ++++---------------- 7 files changed, 43 insertions(+), 55 deletions(-) diff --git a/src/hal/plus/cvi_hal.c b/src/hal/plus/cvi_hal.c index 6687271..f7eb5ca 100644 --- a/src/hal/plus/cvi_hal.c +++ b/src/hal/plus/cvi_hal.c @@ -226,17 +226,17 @@ int cvi_pipeline_create(void) { int ret; + cvi_vpss.fnDestroyGroup(_cvi_vpss_grp); + { cvi_sys_oper mode[4]; cvi_sys.fnGetViVpssMode((cvi_sys_oper**)&mode); - mode[_cvi_vi_dev] = CVI_SYS_OPER_VIOFF_VPSSON; + for (int i = 0; i < 4; i++) + mode[i] = CVI_SYS_OPER_VIOFF_VPSSOFF; if (ret = cvi_sys.fnSetViVpssMode((cvi_sys_oper**)&mode)) return ret; } - if (ret = cvi_sensor_config()) - return ret; - if (ret = cvi_vi.fnSetDeviceConfig(_cvi_vi_dev, &cvi_config.videv)) return ret; if (ret = cvi_vi.fnEnableDevice(_cvi_vi_dev)) @@ -288,13 +288,6 @@ int cvi_pipeline_create(void) if (ret = cvi_vi.fnEnableChannel(_cvi_vi_pipe, _cvi_vi_chn)) return ret; - { - cvi_snr_bus bus; - bus.i2c = 0; - if (ret = cvi_snr_drv.obj->pfnSetBusInfo(_cvi_vi_pipe, bus)) - return ret; - } - if (ret = cvi_snr_drv.obj->pfnRegisterCallback(_cvi_vi_pipe, &cvi_ae_lib, &cvi_awb_lib)) return ret; @@ -369,8 +362,6 @@ void cvi_pipeline_destroy(void) cvi_vi.fnDestroyPipe(_cvi_vi_pipe); cvi_vi.fnDisableDevice(_cvi_vi_dev); - - cvi_sensor_deconfig(); } int cvi_region_create(char handle, hal_rect rect, short opacity) @@ -456,7 +447,7 @@ int cvi_sensor_config(void) { cvi_isp.fnResetSensor(device, 1); cvi_isp.fnResetIntf(device, 1); - + cvi_isp.fnSetIntfConfig(_cvi_vi_pipe, &config); cvi_isp.fnSetSensorClock(device, 1); @@ -487,7 +478,8 @@ void cvi_sensor_deinit(void) int cvi_sensor_init(char *name, char *obj) { char path[128]; - char* dirs[] = {"%s", "./%s", "/usr/lib/sensors/%s"}; + char* dirs[] = {"%s", "./%s", "/usr/lib/sensors/%s", "/usr/lib/%s", + "/mnt/system/lib/%s", "/mnt/system/lib/libsns_full.so"}; char **dir = dirs; while (*dir) { @@ -883,17 +875,23 @@ int cvi_system_init(char *snrConfig) return ret; cvi_sys.fnExit(); - //cvi_vb.fnExit(); + cvi_vb.fnExit(); - /*{ + { cvi_vb_pool pool; - memset(&pool, 0, sizeof(pool)); + memset(&pool, 0, sizeof(pool)); + + pool.count = 2; + pool.comm[0].blockSize = 1920 * 1080 * 3; + pool.comm[0].blockCnt = 4; + pool.comm[1].blockSize = 1920 * 1080 * 3; + pool.comm[1].blockCnt = 4; if (ret = cvi_vb.fnConfigPool(&pool)) return ret; - }*/ - //if (ret = cvi_vb.fnInit()) - // return ret; + } + if (ret = cvi_vb.fnInit()) + return ret; if (ret = cvi_sys.fnInit()) return ret; diff --git a/src/hal/plus/cvi_hal.h b/src/hal/plus/cvi_hal.h index e7810da..81ff333 100644 --- a/src/hal/plus/cvi_hal.h +++ b/src/hal/plus/cvi_hal.h @@ -45,8 +45,6 @@ int cvi_region_create(char handle, hal_rect rect, short opacity); void cvi_region_destroy(char handle); int cvi_region_setbitmap(int handle, hal_bitmap *bitmap); -void cvi_sensor_deconfig(void); -int cvi_sensor_config(void); void cvi_sensor_deinit(void); int cvi_sensor_init(char *name, char *obj); diff --git a/src/hal/plus/cvi_isp.h b/src/hal/plus/cvi_isp.h index 4c34ebc..f22567f 100644 --- a/src/hal/plus/cvi_isp.h +++ b/src/hal/plus/cvi_isp.h @@ -51,7 +51,8 @@ static int cvi_isp_load(cvi_isp_impl *isp_lib) { if (!(isp_lib->handle = dlopen("libisp.so", RTLD_LAZY | RTLD_GLOBAL)) || !(isp_lib->handleAlgo = dlopen("libisp_algo.so", RTLD_LAZY | RTLD_GLOBAL)) || !(isp_lib->handleAe = dlopen("libae.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(isp_lib->handleAwb = dlopen("libawb.so", RTLD_LAZY | RTLD_GLOBAL))); + !(isp_lib->handleAwb = dlopen("libawb.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("cvi_isp", "Failed to load library!\nError: %s\n", dlerror()); if (!(isp_lib->fnExit = (int(*)(int pipe)) hal_symbol_load("cvi_isp", isp_lib->handle, "CVI_ISP_Exit"))) diff --git a/src/hal/plus/cvi_snr.h b/src/hal/plus/cvi_snr.h index 4406521..56a9f52 100644 --- a/src/hal/plus/cvi_snr.h +++ b/src/hal/plus/cvi_snr.h @@ -194,21 +194,21 @@ typedef struct { } cvi_snr_init; typedef struct { - int (*pfnRegisterCallback)(int pipe, cvi_isp_alg *aeLibrary, cvi_isp_alg *awbLibrary); - int (*pfnUnRegisterCallback)(int pipe, cvi_isp_alg *aeLibrary, cvi_isp_alg *awbLibrary); - int (*pfnSetBusInfo)(int pipe, cvi_snr_bus bus); + int (*pfnRegisterCallback)(int pipe, cvi_isp_alg *aeLibrary, cvi_isp_alg *awbLibrary); + int (*pfnUnRegisterCallback)(int pipe, cvi_isp_alg *aeLibrary, cvi_isp_alg *awbLibrary); + int (*pfnSetBusInfo)(int pipe, cvi_snr_bus bus); void (*pfnStandby)(int pipe); void (*pfnRestart)(int pipe); void (*pfnMirrorFlip)(int pipe, cvi_isp_dir mode); - int (*pfnWriteReg)(int pipe, int addr, int data); - int (*pfnReadReg)(int pipe, int addr); - int (*pfnSetInit)(int pipe, cvi_snr_init *config); - int (*pfnPatchRxAttr)(cvi_snr_init *config); + int (*pfnWriteReg)(int pipe, int addr, int data); + int (*pfnReadReg)(int pipe, int addr); + int (*pfnSetInit)(int pipe, cvi_snr_init *config); + int (*pfnPatchRxAttr)(cvi_snr_init *config); void (*pfnPatchI2cAddr)(int addr); - int (*pfnGetRxAttr)(int pipe, cvi_snr_dev *device); - int (*pfnExpSensorCb)(void *config); - int (*pfnExpAeCb)(void *config); - int (*pfnSnsProbe)(int pipe); + int (*pfnGetRxAttr)(int pipe, cvi_snr_dev *device); + int (*pfnExpSensorCb)(void *config); + int (*pfnExpAeCb)(void *config); + int (*pfnSnsProbe)(int pipe); } cvi_snr_obj; typedef struct { @@ -216,4 +216,4 @@ typedef struct { cvi_snr_obj *obj; } cvi_snr_drv_impl; -static const char cvi_snr_endp[] = {"/dev/cvi-mipi-tx"}; \ No newline at end of file +static const char cvi_snr_endp[] = {"/dev/cvi-mipi-rx"}; \ No newline at end of file diff --git a/src/hal/plus/cvi_sys.h b/src/hal/plus/cvi_sys.h index 0bd7579..5879341 100644 --- a/src/hal/plus/cvi_sys.h +++ b/src/hal/plus/cvi_sys.h @@ -64,7 +64,7 @@ typedef struct { } cvi_sys_ver; typedef struct { - void *handle; + void *handle, *handleAtomic; int (*fnExit)(void); int (*fnGetChipId)(unsigned int *chip); @@ -79,7 +79,8 @@ typedef struct { } cvi_sys_impl; static int cvi_sys_load(cvi_sys_impl *sys_lib) { - if (!(sys_lib->handle = dlopen("libsys.so", RTLD_LAZY | RTLD_GLOBAL))) + if (!(sys_lib->handleAtomic = dlopen("libatomic.so.1", RTLD_LAZY | RTLD_GLOBAL)) || + !(sys_lib->handle = dlopen("libsys.so", RTLD_LAZY | RTLD_GLOBAL))) HAL_ERROR("cvi_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(void)) @@ -120,5 +121,7 @@ static int cvi_sys_load(cvi_sys_impl *sys_lib) { static void cvi_sys_unload(cvi_sys_impl *sys_lib) { if (sys_lib->handle) dlclose(sys_lib->handle); sys_lib->handle = NULL; + if (sys_lib->handleAtomic) dlclose(sys_lib->handleAtomic); + sys_lib->handleAtomic = NULL; memset(sys_lib, 0, sizeof(*sys_lib)); } \ No newline at end of file diff --git a/src/hal/plus/cvi_vb.h b/src/hal/plus/cvi_vb.h index c187c08..5c25c88 100644 --- a/src/hal/plus/cvi_vb.h +++ b/src/hal/plus/cvi_vb.h @@ -5,7 +5,7 @@ typedef struct { unsigned int count; struct { - unsigned long long blockSize; + unsigned int blockSize; unsigned int blockCnt; // Accepts values from 0-2 (none, nocache, cached) int rempVirt; diff --git a/src/hal/plus/cvi_venc.h b/src/hal/plus/cvi_venc.h index 21eba79..f30b866 100644 --- a/src/hal/plus/cvi_venc.h +++ b/src/hal/plus/cvi_venc.h @@ -78,11 +78,11 @@ typedef enum { typedef struct { char rcnRefShareBufOn; + char singleBufLumaOn; } cvi_venc_attr_h264; typedef struct { char rcnRefShareBufOn; - char singleBufLumaOn; } cvi_venc_attr_h265; typedef struct { @@ -90,6 +90,7 @@ typedef struct { unsigned char numThumbs; cvi_common_dim sizeThumbs[2]; int multiReceiveOn; + int shit; } cvi_venc_attr_jpg; typedef struct { @@ -119,19 +120,6 @@ typedef struct { char variFpsOn; } cvi_venc_rate_h26xbr; -typedef struct { - unsigned int gop; - unsigned int statTime; - unsigned int srcFps; - unsigned int dstFps; - unsigned int maxBitrate; - unsigned int shortTermStatTime; - unsigned int longTermStatTime; - unsigned int longTermMaxBitrate; - unsigned int longTermMinBitrate; - char variFpsOn; -} cvi_venc_rate_h26xcvbr; - typedef struct { unsigned int gop; unsigned int srcFps; @@ -182,9 +170,9 @@ typedef struct { cvi_venc_rate_h26xbr h264Vbr; cvi_venc_rate_h26xbr h264Avbr; cvi_venc_rate_h26xbr h264Qvbr; - cvi_venc_rate_h26xcvbr h264Cvbr; cvi_venc_rate_h26xqp h264Qp; cvi_venc_rate_h264qpmap h264QpMap; + cvi_venc_rate_h26xbr h264Ubr; cvi_venc_rate_mjpgbr mjpgCbr; cvi_venc_rate_mjpgbr mjpgVbr; cvi_venc_rate_mjpgqp mjpgQp; @@ -192,9 +180,9 @@ typedef struct { cvi_venc_rate_h26xbr h265Vbr; cvi_venc_rate_h26xbr h265Avbr; cvi_venc_rate_h26xbr h265Qvbr; - cvi_venc_rate_h26xcvbr h265Cvbr; cvi_venc_rate_h26xqp h265Qp; cvi_venc_rate_h265qpmap h265QpMap; + cvi_venc_rate_h26xbr h265Ubr; }; } cvi_venc_rate;