Skip to content

Commit

Permalink
Fixes an issue loading a ISP config file, adds early support for Inge…
Browse files Browse the repository at this point in the history
…nic T series
  • Loading branch information
wberube committed May 24, 2024
1 parent 86034e5 commit ae85ecf
Show file tree
Hide file tree
Showing 13 changed files with 1,067 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ In spite of these design choices, Divinus boasts numerous features that cater to
| infinity6e[^6] || ✔️ | ✔️ || ✔️ |
| infinity6c[^7] || ✔️ | ✔️ || ✔️ |
| infinity6f[^8] || ✔️ | ✔️ || ✔️ |
| T2X series ||||||
| T3X series ||||||

_✔️ - supported, ↻ - in development, ✗ - unsupported, ⁿ/ₐ - not supported by hardware_

Expand Down
120 changes: 120 additions & 0 deletions src/hal/inge/tx_aud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#pragma once

#include "tx_common.h"

#define TX_AUD_CHN_NUM 2

typedef enum {
TX_AUD_BIT_16
} tx_aud_bit;

typedef enum {
TX_AUD_SND_MONO = 1,
TX_AUD_SND_STEREO = 2
} tx_aud_snd;

typedef struct {
// Accept industry standards from 8000 to 96000Hz
int rate;
tx_aud_bit bit;
tx_aud_snd mode;
unsigned int frmNum;
unsigned int packNumPerFrm;
unsigned int chnNum;
} tx_aud_cnf;

typedef struct {
tx_aud_bit bit;
tx_aud_snd mode;
unsigned int addr;
unsigned int phy;
unsigned long long timestamp;
unsigned int sequence;
unsigned int length;
} tx_aud_frm;

typedef struct {
void *handle;

int (*fnDisableDevice)(int device);
int (*fnEnableDevice)(int device);
int (*fnSetDeviceConfig)(int device, tx_aud_cnf *config);

int (*fnDisableChannel)(int device, int channel);
int (*fnEnableChannel)(int device, int channel);

int (*fnSetMute)(int device, int channel, int active);
int (*fnSetVolume)(int device, int channel, int *dbLevel);

int (*fnFreeFrame)(int device, int channel, tx_aud_frm *frame);
int (*fnGetFrame)(int device, int channel, tx_aud_frm *frame, int notBlocking);
} tx_aud_impl;

static int tx_aud_load(tx_aud_impl *aud_lib) {
if (!(aud_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) {
fprintf(stderr, "[tx_aud] Failed to load library!\nError: %s\n", dlerror());
return EXIT_FAILURE;
}

if (!(aud_lib->fnDisableDevice = (int(*)(int device))
dlsym(aud_lib->handle, "IMP_AI_Disable"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_Disable!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnEnableDevice = (int(*)(int device))
dlsym(aud_lib->handle, "IMP_AI_Enable"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_Enable!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, tx_aud_cnf *config))
dlsym(aud_lib->handle, "IMP_AI_SetPubAttr"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_SetPubAttr!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel))
dlsym(aud_lib->handle, "IMP_AI_DisableChn"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_DisableChn!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel))
dlsym(aud_lib->handle, "IMP_AI_EnableChn"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_EnableChn!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnSetMute = (int(*)(int device, int channel, int active))
dlsym(aud_lib->handle, "IMP_AI_SetVolMute"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_SetVolMute!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel))
dlsym(aud_lib->handle, "IMP_AI_SetVol"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_SetVol!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, tx_aud_frm *frame))
dlsym(aud_lib->handle, "IMP_AI_ReleaseFrame"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_ReleaseFrame!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, tx_aud_frm *frame, int notBlocking))
dlsym(aud_lib->handle, "IMP_AI_GetFrame"))) {
fprintf(stderr, "[tx_aud] Failed to acquire symbol IMP_AI_GetFrame!\n");
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

static void tx_aud_unload(tx_aud_impl *aud_lib) {
if (aud_lib->handle) dlclose(aud_lib->handle);
aud_lib->handle = NULL;
memset(aud_lib, 0, sizeof(*aud_lib));
}
74 changes: 74 additions & 0 deletions src/hal/inge/tx_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>

#include "../types.h"

#define TX_ERROR(x, ...) \
do { \
fprintf(stderr, "[tx_hal] \033[31m"); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
return EXIT_FAILURE; \
} while (0)

typedef enum {
TX_PIXFMT_YUV420P,
TX_PIXFMT_YUV422_YUYV,
TX_PIXFMT_YUV422_UYVY,
TX_PIXFMT_YUV422P,
TX_PIXFMT_YUV444P,
TX_PIXFMT_YUV410P,
TX_PIXFMT_YUV411P,
TX_PIXFMT_GRAY8,
TX_PIXFMT_MONOWHITE,
TX_PIXFMT_MONOBLACK,
TX_PIXFMT_NV12,
TX_PIXFMT_NV24,
TX_PIXFMT_RGB888,
TX_PIXFMT_BGR888,
TX_PIXFMT_ARGB8888,
TX_PIXFMT_RGBA8888,
TX_PIXFMT_ABGR8888,
TX_PIXFMT_BGRA8888,
TX_PIXFMT_RGB565BE,
TX_PIXFMT_RGB565LE,
// Following twos have their MSB set to 1
TX_PIXFMT_RGB555BE,
TX_PIXFMT_RGB555LE,
TX_PIXFMT_BGR565BE,
TX_PIXFMT_BGR565LE,
// Following twos have their MSB set to 1
TX_PIXFMT_BGR555BE,
TX_PIXFMT_BGR555LE,
TX_PIXFMT_0RGB8888,
TX_PIXFMT_RGB08888,
TX_PIXFMT_0BGR8888,
TX_PIXFMT_BGR08888,
TX_PIXFMT_BAYER_BGGR8,
TX_PIXFMT_BAYER_RGGB8,
TX_PIXFMT_BAYER_GBRG8,
TX_PIXFMT_BAYER_GRBG8,
TX_PIXFMT_RAW,
TX_PIXFMT_HSV888,
TX_PIXFMT_END
} tx_common_pixfmt;

typedef struct {
int width;
int height;
} tx_common_dim;

typedef struct {
int x;
int y;
} tx_common_pnt;

typedef struct {
tx_common_pnt p0;
tx_common_pnt p1;
} tx_common_rect;
115 changes: 115 additions & 0 deletions src/hal/inge/tx_fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#pragma once

#include "tx_common.h"

typedef struct {
int enable;
int left;
int top;
int width;
int height;
} tx_fs_crop;

typedef struct {
int enable;
int width;
int height;
} tx_fs_scale;

typedef struct {
tx_common_dim dest;
tx_common_pixfmt pixFmt;
tx_fs_crop crop;
tx_fs_scale scale;
int fpsNum;
int fpsDen;
int bufCount;
int phyOrExtChn;
tx_fs_crop frame;
} tx_fs_chn;

typedef struct {
int index;
int poolId;
unsigned int width;
unsigned int height;
tx_common_pixfmt pixFmt;
unsigned int size;
unsigned int phyAddr;
unsigned int virtAddr;
long long timestamp;
int rotateFlag;
unsigned int priv[0];
} tx_fs_frame;

typedef struct {
void *handle;

int (*fnCreateChannel)(int channel, tx_fs_chn *config);
int (*fnDestroyChannel)(int channel);
int (*fnDisableChannel)(int channel);
int (*fnEnableChannel)(int channel);
int (*fnSetChannelRotate)(int channel, char rotateMode, int width, int height);
int (*fnSetChannelSource)(int channel, int source);

int (*fnSnapshot)(int channel, tx_common_pixfmt pixFmt, int width, int height,
void *data, tx_fs_frame *info);
} tx_fs_impl;

static int tx_fs_load(tx_fs_impl *fs_lib) {
if (!(fs_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) {
fprintf(stderr, "[tx_fs] Failed to load library!\nError: %s\n", dlerror());
return EXIT_FAILURE;
}

if (!(fs_lib->fnCreateChannel = (int(*)(int channel, tx_fs_chn *config))
dlsym(fs_lib->handle, "IMP_FrameSource_CreateChn"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_CreateChn!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnDestroyChannel = (int(*)(int channel))
dlsym(fs_lib->handle, "IMP_FrameSource_DestroyChn"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_DestroyChn!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnDisableChannel = (int(*)(int channel))
dlsym(fs_lib->handle, "IMP_FrameSource_DisableChn"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_DisableChn!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnEnableChannel = (int(*)(int channel))
dlsym(fs_lib->handle, "IMP_FrameSource_EnableChn"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_EnableChn!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnSetChannelRotate = (int(*)(int channel, char rotateMode, int width, int height))
dlsym(fs_lib->handle, "IMP_FrameSource_SetChnRotate"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_SetChnRotate!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnSetChannelSource = (int(*)(int channel, int source))
dlsym(fs_lib->handle, "IMP_FrameSource_SetSource"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_SetSource!\n");
return EXIT_FAILURE;
}

if (!(fs_lib->fnSnapshot = (int(*)(int channel, tx_common_pixfmt pixFmt, int width, int height,
void *data, tx_fs_frame *info))
dlsym(fs_lib->handle, "IMP_FrameSource_SnapFrame"))) {
fprintf(stderr, "[tx_fs] Failed to acquire symbol IMP_FrameSource_SnapFrame!\n");
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

static void tx_fs_unload(tx_fs_impl *fs_lib) {
if (fs_lib->handle) dlclose(fs_lib->handle);
fs_lib->handle = NULL;
memset(fs_lib, 0, sizeof(*fs_lib));
}
41 changes: 41 additions & 0 deletions src/hal/inge/tx_hal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "tx_hal.h"

tx_aud_impl tx_aud;
tx_fs_impl tx_fs;
tx_isp_impl tx_isp;
tx_osd_impl tx_osd;
tx_sys_impl tx_sys;
tx_venc_impl tx_venc;

hal_chnstate tx_state[TX_VENC_CHN_NUM] = {0};
int (*tx_venc_cb)(char, hal_vidstream*);

void tx_hal_deinit(void)
{
tx_venc_unload(&tx_venc);
tx_osd_unload(&tx_osd);
tx_isp_unload(&tx_isp);
tx_fs_unload(&tx_fs);
tx_aud_unload(&tx_aud);
tx_sys_unload(&tx_sys);
}

int tx_hal_init(void)
{
int ret;

if (ret = tx_sys_load(&tx_sys))
return ret;
if (ret = tx_aud_load(&tx_aud))
return ret;
if (ret = tx_fs_load(&tx_fs))
return ret;
if (ret = tx_isp_load(&tx_isp))
return ret;
if (ret = tx_osd_load(&tx_osd))
return ret;
if (ret = tx_venc_load(&tx_venc))
return ret;

return EXIT_SUCCESS;
}
11 changes: 11 additions & 0 deletions src/hal/inge/tx_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "tx_common.h"
#include "tx_aud.h"
#include "tx_fs.h"
#include "tx_isp.h"
#include "tx_osd.h"
#include "tx_sys.h"
#include "tx_venc.h"

extern char keepRunning;
Loading

0 comments on commit ae85ecf

Please sign in to comment.