Skip to content

Commit

Permalink
(Continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 30, 2024
1 parent ebc117c commit a127be3
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/hal/plus/ak_vi.h
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));
}

0 comments on commit a127be3

Please sign in to comment.