-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |