Skip to content

Commit

Permalink
(Continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 10, 2024
1 parent 233032d commit f348994
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 71 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ _* At the moment, only text, 24-bit and 32-bit RGB overlays are handled, matrici

### Roadmap

- [ ] Assorted WebUI to handle media reconfiguration and live preview
- [ ] Writing config changes
- [ ] Safe mode feature
- [ ] Additional WebUI functionalities
- [ ] Motion detection reimplementation
- [ ] Hardware support improvement (older SoCs, general usage chips)
- [ ] Alternative audio codecs
Expand Down
31 changes: 24 additions & 7 deletions src/hal/hisi/v1_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ int v1_pipeline_create(void)
if (ret = v1_vi.fnEnableChannel(_v1_vi_chn))
return ret;

if (ret = v1_snr_drv.fnInit())
return ret;
if (ret = v1_snr_drv.fnRegisterCallback())
return ret;

Expand All @@ -274,6 +272,7 @@ int v1_pipeline_create(void)
return ret;
if (ret = v1_isp.fnSetImageConfig(&v1_config.img))
return ret;
v1_config.tim.mode = V1_ISP_WIN_BOTH;
if (ret = v1_isp.fnSetInputTiming(&v1_config.tim))
return ret;

Expand Down Expand Up @@ -423,8 +422,6 @@ int v1_sensor_init(char *name, char *obj)
} if (!v1_snr_drv.handle)
HAL_ERROR("v1_snr", "Failed to load the sensor driver");

if (!(v1_snr_drv.fnInit = (int(*)(void))dlsym(v1_snr_drv.handle, "sensor_init")))
HAL_ERROR("v1_snr", "Failed to connect the init function");
if (!(v1_snr_drv.fnRegisterCallback = (int(*)(void))dlsym(v1_snr_drv.handle, "sensor_register_callback")))
HAL_ERROR("v1_snr", "Failed to connect the callback register function");
if (!(v1_snr_drv.fnUnRegisterCallback = (int(*)(void))dlsym(v1_snr_drv.handle, "sensor_unregister_callback")))
Expand All @@ -447,9 +444,10 @@ int v1_video_create(char index, hal_vidconfig *config)
channel.attrib.jpg.bufSize =
config->height * config->width * 2;
channel.attrib.jpg.byFrame = 1;
channel.attrib.jpg.fieldOrFrame = 0;
channel.attrib.jpg.priority = 0;
channel.attrib.jpg.pic.width = config->width;
channel.attrib.jpg.pic.height = config->height;
channel.attrib.jpg.dcfThumbs = 0;
goto attach;
} else if (config->codec == HAL_VIDCODEC_MJPG) {
channel.attrib.codec = V1_VENC_CODEC_MJPG;
Expand All @@ -458,6 +456,9 @@ int v1_video_create(char index, hal_vidconfig *config)
channel.attrib.mjpg.bufSize =
config->height * config->width * 2;
channel.attrib.mjpg.byFrame = 1;
channel.attrib.mjpg.mainStrmOn = index ? 0 : 1;
channel.attrib.mjpg.fieldOrFrame = 0;
channel.attrib.mjpg.priority = 0;
channel.attrib.mjpg.pic.width = config->width;
channel.attrib.mjpg.pic.height = config->height;
switch (config->mode) {
Expand Down Expand Up @@ -507,14 +508,24 @@ int v1_video_create(char index, hal_vidconfig *config)
attrib->bufSize = config->height * config->width * 2;
attrib->profile = config->profile;
attrib->byFrame = 1;
attrib->fieldOn = 0;
attrib->mainStrmOn = index ? 0 : 1;
attrib->priority = 0;
attrib->fieldOrFrame = 0;
attrib->pic.width = config->width;
attrib->pic.height = config->height;
attrib->bFrameNum = 0;
attrib->refNum = 1;
attach:
if (ret = v1_venc.fnCreateGroup(_v1_venc_dev))
return ret;

if (ret = v1_venc.fnCreateChannel(index, &channel))
return ret;

if (ret = v1_venc.fnRegisterChannel(_v1_venc_dev, index))
return ret;

if (config->codec != HAL_VIDCODEC_JPG &&
(ret = v1_venc.fnStartReceiving(index)))
return ret;
Expand Down Expand Up @@ -542,8 +553,14 @@ int v1_video_destroy(char index)
return ret;
}

if (ret = v1_venc.fnUnregisterChannel(index))
return ret;

if (ret = v1_venc.fnDestroyChannel(index))
return ret;

if (ret = v1_venc.fnDestroyGroup(_v1_venc_dev))
return ret;

if (ret = v1_vpss.fnDisableChannel(_v1_vpss_grp, index))
return ret;
Expand Down Expand Up @@ -809,8 +826,8 @@ int v1_system_init(char *snrConfig)
v1_config.vichn.capt.width : v1_config.videv.rect.width,
v1_config.vichn.capt.height ?
v1_config.vichn.capt.height : v1_config.videv.rect.height,
V1_PIXFMT_YUV420SP, alignWidth);
pool.comm[0].blockCnt = 4;
alignWidth);
pool.comm[0].blockCnt = 12;

if (ret = v1_vb.fnConfigPool(&pool))
return ret;
Expand Down
19 changes: 0 additions & 19 deletions src/hal/hisi/v1_snr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

#include "v1_common.h"

#include <asm/ioctl.h>
#include <fcntl.h>

#define V1_SNR_IOC_MAGIC 'm'
#define V1_SNR_LANE_NUM 8
#define V1_SNR_WDR_VC_NUM 4

enum {
V1_SNR_CMD_CONF_DEV = 1,
V1_SNR_CMD_CONF_EDGE,
V1_SNR_CMD_CONF_MSB
};

typedef enum {
V1_SNR_INPUT_MIPI,
V1_SNR_INPUT_SUBLVDS,
Expand Down Expand Up @@ -59,18 +49,9 @@ typedef struct {
short laneId[V1_SNR_LANE_NUM];
} v1_snr_mipi;

typedef struct {
v1_snr_input input;
union {
v1_snr_mipi mipi;
v1_snr_lvds lvds;
};
} v1_snr_dev;

typedef struct {
void *handle;

int (*fnInit)(void);
int (*fnRegisterCallback)(void);
int (*fnUnRegisterCallback)(void);
} v1_snr_drv_impl;
46 changes: 3 additions & 43 deletions src/hal/hisi/v1_vb.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,10 @@ static void v1_vb_unload(v1_vb_impl *vb_lib) {
memset(vb_lib, 0, sizeof(*vb_lib));
}

inline static unsigned int v1_buffer_calculate_vi(
unsigned int width, unsigned int height, v1_common_pixfmt pixFmt,
v1_common_compr compr, unsigned int alignWidth)
{
unsigned int bitWidth = 16;
unsigned int size = 0, stride = 0;
unsigned int cmpRatioLine = 1600, cmpRatioFrame = 2000;

if (!alignWidth)
alignWidth = 16;
else if (alignWidth > 64)
alignWidth = 64;
else
alignWidth = ALIGN_UP(alignWidth, 16);

if (compr == V1_COMPR_NONE) {
stride = ALIGN_UP(ALIGN_UP(width * bitWidth, 8) / 8,
alignWidth);
size = stride * height;
} else if (compr == V1_COMPR_LINE) {
unsigned int temp = ALIGN_UP(
(16 + width * bitWidth * 1000UL /
cmpRatioLine + 8192 + 127) / 128, 2);
stride = ALIGN_UP(temp * 16, alignWidth);
size = stride * height;
} else if (compr == V1_COMPR_FRAME) {
size = ALIGN_UP(height * width * bitWidth * 1000UL /
(cmpRatioFrame * 8), alignWidth);
}

return size;
}

inline static unsigned int v1_buffer_calculate_venc(short width, short height, v1_common_pixfmt pixFmt,
inline static unsigned int v1_buffer_calculate_venc(short width, short height,
unsigned int alignWidth)
{
unsigned int bufSize = CEILING_2_POWER(width, alignWidth) *
CEILING_2_POWER(height, alignWidth) *
(pixFmt == V1_PIXFMT_YUV422SP ? 2 : 1.5);
unsigned int headSize = 16 * height;
if (pixFmt == V1_PIXFMT_YUV422SP || pixFmt == V1_PIXFMT_RGB_BAYER)
headSize *= 2;
else if (pixFmt == V1_PIXFMT_YUV420SP)
headSize *= 3;
headSize >>= 1;
return bufSize + headSize;
CEILING_2_POWER(height, alignWidth) * 2;
return bufSize;
}
31 changes: 30 additions & 1 deletion src/hal/hisi/v1_venc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ typedef struct {
unsigned int bufSize;
unsigned int profile;
int byFrame;
int fieldOn;
int mainStrmOn;
unsigned int priority;
int fieldOrFrame;
v1_common_dim pic;
unsigned int bFrameNum;
unsigned int refNum;
Expand All @@ -56,15 +60,19 @@ typedef struct {
v1_common_dim maxPic;
unsigned int bufSize;
int byFrame;
int mainStrmOn;
int fieldOrFrame;
unsigned int priority;
v1_common_dim pic;
} v1_venc_attr_mjpg;

typedef struct {
v1_common_dim maxPic;
unsigned int bufSize;
int byFrame;
int fieldOrFrame;
unsigned int priority;
v1_common_dim pic;
int dcfThumbs;
} v1_venc_attr_jpg;

typedef struct {
Expand Down Expand Up @@ -231,6 +239,11 @@ typedef struct {
typedef struct {
void *handle;

int (*fnCreateGroup)(int group);
int (*fnDestroyGroup)(int group);
int (*fnRegisterChannel)(int group, int channel);
int (*fnUnregisterChannel)(int channel);

int (*fnCreateChannel)(int channel, v1_venc_chn *config);
int (*fnGetChannelConfig)(int channel, v1_venc_chn *config);
int (*fnDestroyChannel)(int channel);
Expand All @@ -257,6 +270,22 @@ static int v1_venc_load(v1_venc_impl *venc_lib) {
if (!(venc_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)))
HAL_ERROR("v1_venc", "Failed to load library!\nError: %s\n", dlerror());

if (!(venc_lib->fnCreateGroup = (int(*)(int group))
hal_symbol_load("v1_venc", venc_lib->handle, "HI_MPI_VENC_CreateGroup")))
return EXIT_FAILURE;

if (!(venc_lib->fnDestroyGroup = (int(*)(int group))
hal_symbol_load("v1_venc", venc_lib->handle, "HI_MPI_VENC_DestroyGroup")))
return EXIT_FAILURE;

if (!(venc_lib->fnRegisterChannel = (int(*)(int group, int channel))
hal_symbol_load("v1_venc", venc_lib->handle, "HI_MPI_VENC_RegisterChn")))
return EXIT_FAILURE;

if (!(venc_lib->fnUnregisterChannel = (int(*)(int channel))
hal_symbol_load("v1_venc", venc_lib->handle, "HI_MPI_VENC_UnRegisterChn")))
return EXIT_FAILURE;

if (!(venc_lib->fnCreateChannel = (int(*)(int channel, v1_venc_chn *config))
hal_symbol_load("v1_venc", venc_lib->handle, "HI_MPI_VENC_CreateChn")))
return EXIT_FAILURE;
Expand Down

0 comments on commit f348994

Please sign in to comment.