Skip to content

Commit

Permalink
(Continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 16, 2024
1 parent 5e51f3c commit d0c1fc6
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _✔️ - supported, ↻ - in development, ✗ - unsupported, ⁿ/ₐ - not supp
_* At the moment, only text, 24-bit and 32-bit RGB overlays are handled, matricial formats and covers are to follow_

[^1]: CV181x[C/H], SG2000 and SG2002
[^2]: GM8135(S), GM8136(S) and GM8138(S)
[^2]: GM813[5/6/8](S)
[^3]: Hi3516AV100 and Hi3516DV100
[^4]: Hi3516CV100, Hi3518AV100, Hi3518CV100 and Hi3518EV100
[^5]: Hi3516CV200 and Hi3518EV20\[0/1\]
Expand All @@ -52,7 +52,7 @@ _* At the moment, only text, 24-bit and 32-bit RGB overlays are handled, matrici
[^9]: GK7202V300, GK7205V200/300 and GK7605V100
[^10]: Hi3516AV200 and Hi3519V101
[^11]: SSC323, SSC325(D/DE) and SSC327(D/DE/Q)
[^12]: SSC333/35/37(DE)
[^12]: SSC33[3/5/7](DE)
[^13]: SSC30K\[D/Q\], SSC336\[D/Q\], SSC338\[D/G/Q\] and SSC339G
[^14]: SSC377(D/DE/QE) or SSC378\[DE/QE\]
[^15]: SSC379G
Expand Down
3 changes: 3 additions & 0 deletions src/hal/plus/cvi_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "../types.h"

#define CVI_VI_PIPE_NUM 4
// Non-Sophgo chips support up to 4 channels
#define CVI_VPSS_CHN_NUM 3
#define CVI_VPSS_GRP_NUM 16

typedef enum {
CVI_BAYER_BG,
Expand Down
179 changes: 179 additions & 0 deletions src/hal/plus/cvi_rgn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#pragma once

#include "cvi_common.h"
#include "cvi_sys.h"

typedef enum {
CVI_RGN_BLK_8,
CVI_RGN_BLK_16,
CVI_RGN_BLK_END
} cvi_rgn_blk;

typedef enum {
CVI_RGN_COMPR_NONE,
CVI_RGN_COMPR_SW,
CVI_RGN_COMPR_HW,
CVI_RGN_COMPR_END
} cvi_rgn_compr;

typedef enum {
CVI_RGN_TYPE_OVERLAY,
CVI_RGN_TYPE_COVER,
CVI_RGN_TYPE_COVEREX,
CVI_RGN_TYPE_OVERLAYEX,
CVI_RGN_TYPE_MOSAIC,
CVI_RGN_TYPE_END
} cvi_rgn_type;

typedef struct {
cvi_common_pixfmt pixFmt;
cvi_common_dim size;
void *data;
} cvi_rgn_bmp;

typedef struct {
cvi_rgn_compr mode;
unsigned int estSize;
unsigned int realSize;
} cvi_rgn_cmpinfo;

typedef struct {
cvi_common_dim invColArea;
unsigned int lumThresh;
unsigned int highThanOn;
char invColOn;
} cvi_rgn_inv;

typedef struct {
cvi_common_pnt point;
// Accepts values from 0-7
unsigned int layer;
cvi_rgn_inv invert;
} cvi_rgn_ovlc;

typedef struct {
char solidOn;
unsigned int lineThick;
cvi_common_pnt point[4];
} cvi_rgn_qdr;

typedef struct {
int quadRangleOn;
union {
cvi_common_rect rect;
cvi_rgn_qdr quadR;
};
unsigned int color;
unsigned int layer;
int absOrRatioCoord;
} cvi_rgn_covc;

typedef struct {
int quadRangleOn;
union {
cvi_common_rect rect;
cvi_rgn_qdr quadR;
};
unsigned int color;
unsigned int layer;
} cvi_rgn_covxc;

typedef struct {
cvi_common_rect rect;
cvi_rgn_blk blkSize;
// Accepts values from 0-3
unsigned int layer;
} cvi_rgn_mosc;

typedef struct {
char show;
cvi_rgn_type type;
union {
cvi_rgn_ovlc overlay;
cvi_rgn_covc cover;
cvi_rgn_covxc coverex;
cvi_rgn_ovlc overlayex;
cvi_rgn_mosc mosaic;
};
} cvi_rgn_chn;

typedef struct {
cvi_common_pixfmt pixFmt;
unsigned int bgColor;
cvi_common_dim size;
unsigned int canvas;
cvi_rgn_cmpinfo compInfo;
} cvi_rgn_ovl;

typedef struct {
cvi_rgn_type type;
union {
cvi_rgn_ovl overlay;
cvi_rgn_ovl overlayex;
};
} cvi_rgn_cnf;

typedef struct {
void *handle;

int (*fnCreateRegion)(unsigned int handle, cvi_rgn_cnf *config);
int (*fnDestroyRegion)(unsigned int handle);
int (*fnGetRegionConfig)(unsigned int handle, cvi_rgn_cnf *config);
int (*fnSetRegionConfig)(unsigned int handle, cvi_rgn_cnf *config);

int (*fnAttachChannel)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config);
int (*fnDetachChannel)(unsigned int handle, cvi_sys_bind *dest);
int (*fnGetChannelConfig)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config);
int (*fnSetChannelConfig)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config);

int (*fnSetBitmap)(unsigned int handle, cvi_rgn_bmp *bitmap);
} cvi_rgn_impl;

static int cvi_rgn_load(cvi_rgn_impl *rgn_lib) {
if (!(rgn_lib->handle = dlopen("libvpu.so", RTLD_LAZY | RTLD_GLOBAL)))
HAL_ERROR("cvi_rgn", "Failed to load library!\nError: %s\n", dlerror());

if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned int handle, cvi_rgn_cnf *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_Create")))
return EXIT_FAILURE;

if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned int handle))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_Destroy")))
return EXIT_FAILURE;

if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned int handle, cvi_rgn_cnf *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_GetAttr")))
return EXIT_FAILURE;

if (!(rgn_lib->fnSetRegionConfig = (int(*)(unsigned int handle, cvi_rgn_cnf *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_SetAttr")))
return EXIT_FAILURE;

if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_AttachToChn")))
return EXIT_FAILURE;

if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned int handle, cvi_sys_bind *dest))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_DetachFromChn")))
return EXIT_FAILURE;

if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_GetDisplayAttr")))
return EXIT_FAILURE;

if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned int handle, cvi_sys_bind *dest, cvi_rgn_chn *config))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_SetDisplayAttr")))
return EXIT_FAILURE;

if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned int handle, cvi_rgn_bmp *bitmap))
hal_symbol_load("cvi_rgn", rgn_lib->handle, "CVI_RGN_SetBitMap")))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

static void cvi_rgn_unload(cvi_rgn_impl *rgn_lib) {
if (rgn_lib->handle) dlclose(rgn_lib->handle);
rgn_lib->handle = NULL;
memset(rgn_lib, 0, sizeof(*rgn_lib));
}
47 changes: 47 additions & 0 deletions src/hal/plus/cvi_vb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "cvi_common.h"

typedef struct {
unsigned int count;
struct {
unsigned long long blockSize;
unsigned int blockCnt;
// Accepts values from 0-2 (none, nocache, cached)
int rempVirt;
char heapName[32];
} comm[16];
} cvi_vb_pool;

typedef struct {
void *handle;

int (*fnConfigPool)(cvi_vb_pool *config);
int (*fnExit)(void);
int (*fnInit)(void);
} cvi_vb_impl;

static int cvi_vb_load(cvi_vb_impl *vb_lib) {
if (!(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)))
HAL_ERROR("cvi_vb", "Failed to load library!\nError: %s\n", dlerror());

if (!(vb_lib->fnConfigPool = (int(*)(cvi_vb_pool *config))
hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_SetConfig")))
return EXIT_FAILURE;

if (!(vb_lib->fnExit = (int(*)(void))
hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_Exit")))
return EXIT_FAILURE;

if (!(vb_lib->fnInit = (int(*)(void))
hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_Init")))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

static void cvi_vb_unload(cvi_vb_impl *vb_lib) {
if (vb_lib->handle) dlclose(vb_lib->handle);
vb_lib->handle = NULL;
memset(vb_lib, 0, sizeof(*vb_lib));
}
93 changes: 93 additions & 0 deletions src/hal/plus/cvi_vpss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#pragma once

#include "cvi_common.h"

typedef struct {
cvi_common_dim dest;
int reserved;
cvi_common_pixfmt pixFmt;
int srcFps;
int dstFps;
int mirror;
int flip;
// Accepts values from 0-8
unsigned int depth;
// Accepts values from 0-2 (none, auto, manual)
int aspectRatio;
char aspectBgOn;
unsigned int aspectBgCol;
cvi_common_rect aspectRect;
} cvi_vpss_chn;

typedef struct {
cvi_common_dim dest;
cvi_common_pixfmt pixFmt;
int srcFps;
int dstFps;
// Only used when VPSS mode is set to dual
unsigned char device;
} cvi_vpss_grp;

typedef struct {
void *handle;

int (*fnCreateGroup)(int group, cvi_vpss_grp *config);
int (*fnDestroyGroup)(int group);
int (*fnResetGroup)(int group);
int (*fnSetGroupConfig)(int channel, cvi_vpss_grp *config);
int (*fnStartGroup)(int group);
int (*fnStopGroup)(int group);

int (*fnDisableChannel)(int group, int channel);
int (*fnEnableChannel)(int group, int channel);
int (*fnSetChannelConfig)(int group, int channel, cvi_vpss_chn *config);
} cvi_vpss_impl;

static int cvi_vpss_load(cvi_vpss_impl *vpss_lib) {
if ( !(vpss_lib->handle = dlopen("libvpu.so", RTLD_LAZY | RTLD_GLOBAL)))
HAL_ERROR("cvi_vpss", "Failed to load library!\nError: %s\n", dlerror());

if (!(vpss_lib->fnCreateGroup = (int(*)(int group, cvi_vpss_grp *config))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_CreateGrp")))
return EXIT_FAILURE;

if (!(vpss_lib->fnDestroyGroup = (int(*)(int group))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_DestroyGrp")))
return EXIT_FAILURE;

if (!(vpss_lib->fnResetGroup = (int(*)(int group))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_ResetGrp")))
return EXIT_FAILURE;

if (!(vpss_lib->fnSetGroupConfig = (int(*)(int group, cvi_vpss_grp *config))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_SetGrpAttr")))
return EXIT_FAILURE;

if (!(vpss_lib->fnStartGroup = (int(*)(int group))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_StartGrp")))
return EXIT_FAILURE;

if (!(vpss_lib->fnStopGroup = (int(*)(int group))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_StopGrp")))
return EXIT_FAILURE;

if (!(vpss_lib->fnDisableChannel = (int(*)(int group, int channel))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_DisableChn")))
return EXIT_FAILURE;

if (!(vpss_lib->fnEnableChannel = (int(*)(int group, int channel))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_EnableChn")))
return EXIT_FAILURE;

if (!(vpss_lib->fnSetChannelConfig = (int(*)(int group, int channel, cvi_vpss_chn *config))
hal_symbol_load("cvi_vpss", vpss_lib->handle, "CVI_VPSS_SetChnAttr")))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

static void cvi_vpss_unload(cvi_vpss_impl *vpss_lib) {
if (vpss_lib->handle) dlclose(vpss_lib->handle);
vpss_lib->handle = NULL;
memset(vpss_lib, 0, sizeof(*vpss_lib));
}

0 comments on commit d0c1fc6

Please sign in to comment.