diff --git a/src/hal/plus/ak_vi.h b/src/hal/plus/ak_vi.h new file mode 100644 index 0000000..595f9e1 --- /dev/null +++ b/src/hal/plus/ak_vi.h @@ -0,0 +1,82 @@ +#pragma once + +#include "ak_common.h" + +#define CVI_VI_CHN_NUM 2 + +typedef struct { + int x; + int y; + int width; + int height; +} ak_vi_crop; + +typedef struct { + int width; + int height; + int maxWidth; + int maxHeight; +} ak_vi_res; + +typedef struct { + ak_vi_crop capt; + ak_vi_res dest[CVI_VI_CHN_NUM]; +} ak_vi_cnf; + +typedef struct { + void *handle; + + int (*fnDisableDevice)(void *device); + void* (*fnEnableDevice)(int device); + int (*fnGetDeviceConfig)(void *device, ak_vi_cnf *config); + int (*fnSetDeviceConfig)(void *device, ak_vi_cnf *config); + int (*fnSetDeviceFlipMirror)(void *device, int flipOn, int mirrorOn); + int (*fnSetDeviceMode)(void *device, int nightOn); + int (*fnStartDevice)(void *device); + int (*fnStopDevice)(void *device); +} ak_vi_impl; + +static int ak_vi_load(ak_vi_impl *vi_lib) { + if (!(vi_lib->handle = dlopen("libplat_vi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("ak_vi", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(vi_lib->fnDisableDevice = (int(*)(void* device)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_venc_close"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnEnableDevice = (void*(*)(int device)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_open"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnGetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_get_channel_attr"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnSetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_set_channel_attr"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnSetDeviceFlipMirror = (int(*)(void *device, int flipOn, int mirrorOn)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_switch_mode"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnSetDeviceMode = (int(*)(void *device, int nightOn)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_switch_mode"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnStartDevice = (int(*)(void *device)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_on"))) + return EXIT_FAILURE; + + if (!(vi_lib->fnStopDevice = (int(*)(void *device)) + hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_off"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void ak_vi_unload(ak_vi_impl *vi_lib) { + if (vi_lib->handle) dlclose(vi_lib->handle); + vi_lib->handle = NULL; + memset(vi_lib, 0, sizeof(*vi_lib)); +} \ No newline at end of file