Skip to content

Commit

Permalink
(Continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 2, 2024
1 parent fb7493f commit 51e641d
Show file tree
Hide file tree
Showing 13 changed files with 946 additions and 76 deletions.
817 changes: 817 additions & 0 deletions src/hal/hisi/v3_hal.c

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions src/hal/hisi/v3_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include "v3_common.h"
#include "v3_aud.h"
#include "v3_config.h"
#include "v3_isp.h"
#include "v3_rgn.h"
#include "v3_snr.h"
#include "v3_sys.h"
#include "v3_vb.h"
#include "v3_venc.h"
#include "v3_vi.h"
#include "v3_vpss.h"

#include <fcntl.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <unistd.h>

extern char keepRunning;

extern hal_chnstate v3_state[V3_VENC_CHN_NUM];
extern int (*v3_venc_cb)(char, hal_vidstream*);

void v3_hal_deinit(void);
int v3_hal_init(void);

void v3_audio_deinit(void);
int v3_audio_init(void);

int v3_channel_bind(char index);
int v3_channel_create(char index, char mirror, char flip, char framerate);
int v3_channel_unbind(char index);

void *v3_image_thread(void);

int v3_pipeline_create(void);
void v3_pipeline_destroy(void);

int v3_region_create(char handle, hal_rect rect);
void v3_region_destroy(char handle);
int v3_region_setbitmap(int handle, hal_bitmap *bitmap);

void v3_sensor_deconfig(void);
int v3_sensor_config(void);
void v3_sensor_deinit(void);
int v3_sensor_init(char *name, char *obj);

int v3_video_create(char index, hal_vidconfig *config);
int v3_video_destroy(char index);
int v3_video_destroy_all(void);
int v3_video_snapshot_grab(char index, short width, short height,
char quality, hal_jpegdata *jpeg);
void *v3_video_thread(void);

int v3_system_calculate_block(short width, short height, v3_common_pixfmt pixFmt,
unsigned int alignWidth);
void v3_system_deinit(void);
int v3_system_init(char *snrConfig);
80 changes: 20 additions & 60 deletions src/hal/hisi/v3_isp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#include "v3_common.h"

extern int (*fnISP_AlgRegisterDehaze)(int);
extern int (*fnISP_AlgRegisterDrc)(int);
extern int (*fnISP_AlgRegisterLdci)(int);
extern int (*fnMPI_ISP_IrAutoRunOnce)(int, void*);

typedef struct {
int id;
char libName[20];
Expand All @@ -19,105 +14,78 @@ typedef struct {
} v3_isp_dev;

typedef struct {
void *handle, *handleDehaze, *handleDrc, *handleLdci, *handleIrAuto, *handleAwb, *handleAe;
void *handle, *handleAwb, *handleAe;

int (*fnExit)(int pipe);
int (*fnInit)(int pipe);
int (*fnMemInit)(int pipe);
int (*fnRun)(int pipe);
int (*fnExit)(int device);
int (*fnInit)(int device);
int (*fnMemInit)(int device);
int (*fnRun)(int device);

int (*fnSetDeviceConfig)(int pipe, v3_isp_dev *config);
int (*fnSetDeviceConfig)(int device, v3_isp_dev *config);

int (*fnRegisterAE)(int pipe, v3_isp_alg *library);
int (*fnRegisterAWB)(int pipe, v3_isp_alg *library);
int (*fnUnregisterAE)(int pipe, v3_isp_alg *library);
int (*fnUnregisterAWB)(int pipe, v3_isp_alg *library);
int (*fnRegisterAE)(int device, v3_isp_alg *library);
int (*fnRegisterAWB)(int device, v3_isp_alg *library);
int (*fnUnregisterAE)(int device, v3_isp_alg *library);
int (*fnUnregisterAWB)(int device, v3_isp_alg *library);
} v3_isp_impl;

static int v3_isp_load(v3_isp_impl *isp_lib) {
if (!(isp_lib->handle = dlopen("libisp.so", RTLD_LAZY | RTLD_GLOBAL)) ||
!(isp_lib->handleAe = dlopen("lib_hiae.so", RTLD_LAZY | RTLD_GLOBAL)) ||
!(isp_lib->handleAwb = dlopen("lib_hiawb.so", RTLD_LAZY | RTLD_GLOBAL)) ||
!(isp_lib->handleLdci = dlopen("lib_hildci.so", RTLD_LAZY | RTLD_GLOBAL))||
!(isp_lib->handleDehaze = dlopen("lib_hidehaze.so", RTLD_LAZY | RTLD_GLOBAL)) ||
!(isp_lib->handleDrc = dlopen("lib_hidrc.so", RTLD_LAZY | RTLD_GLOBAL))) {
!(isp_lib->handleAwb = dlopen("lib_hiawb.so", RTLD_LAZY | RTLD_GLOBAL))) {
fprintf(stderr, "[v3_isp] Failed to load library!\nError: %s\n", dlerror());
return EXIT_FAILURE;
}

if (!(fnISP_AlgRegisterDehaze = (int(*)(int))
dlsym(isp_lib->handleDehaze, "ISP_AlgRegisterDehaze"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol ISP_AlgRegisterDehaze!\n");
return EXIT_FAILURE;
}

if (!(fnISP_AlgRegisterDrc = (int(*)(int))
dlsym(isp_lib->handleDrc, "ISP_AlgRegisterDrc"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol ISP_AlgRegisterDrc!\n");
return EXIT_FAILURE;
}

if (!(fnISP_AlgRegisterLdci = (int(*)(int))
dlsym(isp_lib->handleLdci, "ISP_AlgRegisterLdci"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol ISP_AlgRegisterLdci!\n");
return EXIT_FAILURE;
}

if (!(fnMPI_ISP_IrAutoRunOnce = (int(*)(int, void*))
dlsym(isp_lib->handleIrAuto, "MPI_ISP_IrAutoRunOnce"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol MPI_ISP_IrAutoRunOnce!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnExit = (int(*)(int pipe))
if (!(isp_lib->fnExit = (int(*)(int device))
dlsym(isp_lib->handle, "HI_MPI_ISP_Exit"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Exit!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnInit = (int(*)(int pipe))
if (!(isp_lib->fnInit = (int(*)(int device))
dlsym(isp_lib->handle, "HI_MPI_ISP_Init"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Init!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnMemInit = (int(*)(int pipe))
if (!(isp_lib->fnMemInit = (int(*)(int device))
dlsym(isp_lib->handle, "HI_MPI_ISP_MemInit"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_MemInit!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnRun = (int(*)(int pipe))
if (!(isp_lib->fnRun = (int(*)(int device))
dlsym(isp_lib->handle, "HI_MPI_ISP_Run"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Run!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnSetDeviceConfig = (int(*)(int pipe, v3_isp_dev *config))
if (!(isp_lib->fnSetDeviceConfig = (int(*)(int device, v3_isp_dev *config))
dlsym(isp_lib->handle, "HI_MPI_ISP_SetPubAttr"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_SetPubAttr!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnRegisterAE = (int(*)(int pipe, v3_isp_alg *library))
if (!(isp_lib->fnRegisterAE = (int(*)(int device, v3_isp_alg *library))
dlsym(isp_lib->handleAe, "HI_MPI_AE_Register"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AE_Register!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnRegisterAWB = (int(*)(int pipe, v3_isp_alg *library))
if (!(isp_lib->fnRegisterAWB = (int(*)(int device, v3_isp_alg *library))
dlsym(isp_lib->handleAwb, "HI_MPI_AWB_Register"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AWB_Register!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnUnregisterAE = (int(*)(int pipe, v3_isp_alg *library))
if (!(isp_lib->fnUnregisterAE = (int(*)(int device, v3_isp_alg *library))
dlsym(isp_lib->handleAe, "HI_MPI_AE_UnRegister"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AE_UnRegister!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnUnregisterAWB = (int(*)(int pipe, v3_isp_alg *library))
if (!(isp_lib->fnUnregisterAWB = (int(*)(int device, v3_isp_alg *library))
dlsym(isp_lib->handleAwb, "HI_MPI_AWB_UnRegister"))) {
fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AWB_UnRegister!\n");
return EXIT_FAILURE;
Expand All @@ -131,14 +99,6 @@ static void v3_isp_unload(v3_isp_impl *isp_lib) {
isp_lib->handleAe = NULL;
if (isp_lib->handleAwb) dlclose(isp_lib->handleAwb);
isp_lib->handleAwb = NULL;
if (isp_lib->handleIrAuto) dlclose(isp_lib->handleIrAuto);
isp_lib->handleIrAuto = NULL;
if (isp_lib->handleLdci) dlclose(isp_lib->handleLdci);
isp_lib->handleLdci = NULL;
if (isp_lib->handleDrc) dlclose(isp_lib->handleDrc);
isp_lib->handleDrc = NULL;
if (isp_lib->handleDehaze) dlclose(isp_lib->handleDehaze);
isp_lib->handleDehaze = NULL;
if (isp_lib->handle) dlclose(isp_lib->handle);
isp_lib->handle = NULL;
memset(isp_lib, 0, sizeof(*isp_lib));
Expand Down
7 changes: 7 additions & 0 deletions src/hal/hisi/v3_snr.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,11 @@ typedef struct {
};
} v3_snr_dev;

typedef struct {
void *handle;

int (*fnRegisterCallback)(void);
int (*fnUnRegisterCallback)(void);
} v3_snr_drv_impl;

static const char v3_snr_endp[] = {"/dev/hi_mipi"};
10 changes: 0 additions & 10 deletions src/hal/hisi/v3_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ typedef enum {
V3_SYS_MOD_END
} v3_sys_mod;

typedef enum {
V3_SYS_OPER_VIOFF_VPSSOFF,
V3_SYS_OPER_VIOFF_VPSSON,
V3_SYS_OPER_VION_VPSSOFF,
V3_SYS_OPER_VION_VPSSON,
V3_SYS_OPER_VIPARA_VPSSOFF,
V3_SYS_OPER_VIPARA_VPSSPARA,
V3_SYS_OPER_END
} v3_sys_oper;

typedef struct {
v3_sys_mod module;
int device;
Expand Down
11 changes: 9 additions & 2 deletions src/hal/hisi/v3_venc.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ typedef struct {

int (*fnQuery)(int channel, v3_venc_stat* stats);

int (*fnStartReceiving)(int channel);
int (*fnStartReceivingEx)(int channel, int *count);
int (*fnStopReceiving)(int channel);
} v3_venc_impl;
Expand Down Expand Up @@ -453,9 +454,15 @@ static int v3_venc_load(v3_venc_impl *venc_lib) {
return EXIT_FAILURE;
}

if (!(venc_lib->fnStartReceiving = (int(*)(int channel))
dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvPic"))) {
fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvPic!\n");
return EXIT_FAILURE;
}

if (!(venc_lib->fnStartReceivingEx = (int(*)(int channel, int *count))
dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvFrame"))) {
fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvFrame!\n");
dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvPicEx"))) {
fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvPicEx!\n");
return EXIT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hal/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ void hal_identify(void) {
val |= (SCSYSID[i] & 0xFF) << i * 8;
}

plat = HAL_PLATFORM_V4;
sprintf(series, "%s%X",
((val >> 28) == 0x7) ? "GK" : "Hi", val);
if (series[6] == '0') {
Expand All @@ -138,6 +137,7 @@ void hal_identify(void) {
series[10] = series[9];
series[11] = '\0';
}
plat = HAL_PLATFORM_V4;
chnCount = V4_VENC_CHN_NUM;
chnState = (hal_chnstate*)v4_state;
isp_thread = v4_image_thread;
Expand Down
3 changes: 3 additions & 0 deletions src/hal/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ extern hal_chnstate *chnState;
extern hal_platform plat;
extern char series[16];

extern void *v3_video_thread(void);
extern hal_chnstate v3_state[V4_VENC_CHN_NUM];

extern void *v4_video_thread(void);
extern hal_chnstate v4_state[V4_VENC_CHN_NUM];

Expand Down
1 change: 1 addition & 0 deletions src/hal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef enum {
HAL_PLATFORM_I6C,
HAL_PLATFORM_I6F,
HAL_PLATFORM_T31,
HAL_PLATFORM_V3,
HAL_PLATFORM_V4
} hal_platform;

Expand Down
3 changes: 3 additions & 0 deletions src/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int jpeg_init() {
case HAL_PLATFORM_I6: ret = i6_video_create(jpeg_index, &config); break;
case HAL_PLATFORM_I6C: ret = i6c_video_create(jpeg_index, &config); break;
case HAL_PLATFORM_I6F: ret = i6f_video_create(jpeg_index, &config); break;
case HAL_PLATFORM_V3: ret = v3_video_create(jpeg_index, &config); break;
case HAL_PLATFORM_V4: ret = v4_video_create(jpeg_index, &config); break;
default:
pthread_mutex_unlock(&jpeg_mutex);
Expand Down Expand Up @@ -94,6 +95,8 @@ int jpeg_get(short width, short height, char quality, char grayscale,
quality, grayscale, jpeg); break;
case HAL_PLATFORM_I6F: ret = i6f_video_snapshot_grab(jpeg_index, width, height,
quality, grayscale, jpeg); break;
case HAL_PLATFORM_V3: ret = v3_video_snapshot_grab(jpeg_index, width, height,
quality, jpeg); break;
case HAL_PLATFORM_V4: ret = v4_video_snapshot_grab(jpeg_index, width, height,
quality, jpeg); break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Divinus for infinity6f\n"); break;
case HAL_PLATFORM_T31:
fprintf(stderr, "Divinus for ingenic t31\n"); break;
case HAL_PLATFORM_V3:
fprintf(stderr, "Divinus for hisi-gen3\n"); break;
case HAL_PLATFORM_V4:
fprintf(stderr, "Divinus for hisi-gen4\n"); break;
default:
Expand Down
5 changes: 5 additions & 0 deletions src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ void *region_thread(void)
t31_region_create(&osds[id].hand, rect);
t31_region_setbitmap(&osds[id].hand, &bitmap);
break;
case HAL_PLATFORM_V3:
v3_region_create(id, rect);
v3_region_setbitmap(id, &bitmap);
break;
case HAL_PLATFORM_V4:
v4_region_create(id, rect);
v4_region_setbitmap(id, &bitmap);
Expand All @@ -168,6 +172,7 @@ void *region_thread(void)
case HAL_PLATFORM_I6C: i6c_region_destroy(id); break;
case HAL_PLATFORM_I6F: i6f_region_destroy(id); break;
case HAL_PLATFORM_T31: t31_region_destroy(&osds[id].hand); break;
case HAL_PLATFORM_V3: v3_region_destroy(id); break;
case HAL_PLATFORM_V4: v4_region_destroy(id); break;
}
}
Expand Down
Loading

0 comments on commit 51e641d

Please sign in to comment.