Skip to content

Commit

Permalink
Mostly completed port for hisi-gen2 with the exception of the audio
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jul 14, 2024
1 parent c0d364c commit af0d555
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ In spite of these design choices, Divinus boasts numerous features that cater to
| SoC Family | Audio Stream | JPEG Snapshot | fMP4 Stream | RTSP Stream | On-Screen Display* |
|-------------------------|:------------:|:-------------:|:-----------:|:-----------:|:------------------:|
| GM813x || ✔️ | ✔️ | ✔️ ||
| Hi3516AV100[^1] || | | | |
| Hi3516CV200[^2] || | | | |
| Hi3516AV100[^1] || ✔️ | ✔️ | ✔️ | ✔️ |
| Hi3516CV200[^2] || ✔️ | ✔️ | ✔️ | ✔️ |
| Hi3516CV300[^3] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| Hi3516CV500[^4] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| Hi3516EV200[^5] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
Expand Down
10 changes: 6 additions & 4 deletions src/hal/hisi/v2_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ static enum ConfigError v2_parse_config_videv(
err = parse_int(
ini, section, "timingblank_vsyncvbbb", 0, INT_MAX,
&device->sync.timing.vsyncIntrlBack);
if (err != CONFIG_OK)
return err;
err = parse_int(ini, section, "datapath", 0, INT_MAX, &device->dataPath);
if (err != CONFIG_OK)
return err;
err = parse_int(ini, section, "inputdatatype", 0, INT_MAX, &device->rgbModeOn);
if (err != CONFIG_OK)
return err;
err = parse_int(ini, section, "datarev", 0, INT_MAX, &device->dataRevOn);
Expand All @@ -297,10 +303,6 @@ static enum ConfigError v2_parse_config_videv(
err = parse_int(ini, section, "devrect_h", 0, INT_MAX, &device->rect.height);
if (err != CONFIG_OK)
return err;

if (device->intf == V2_VI_INTF_MIPI || device->intf == V2_VI_INTF_LVDS)
device->rgbModeOn = 1;
else device->rgbModeOn = 0;

return CONFIG_OK;
}
Expand Down
47 changes: 11 additions & 36 deletions src/hal/hisi/v2_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ void v2_pipeline_destroy(void)
v2_vi.fnDisableChannel(_v2_vi_chn);

v2_vi.fnDisableDevice(_v2_vi_dev);

v2_sensor_deconfig();
}

int v2_region_create(char handle, hal_rect rect, short opacity)
Expand Down Expand Up @@ -411,7 +409,6 @@ int v2_sensor_config(void) {
int fd;
v2_snr_dev config;
memset(&config, 0, sizeof(config));
config.device = 0;
config.input = v2_config.input_mode;
if (config.input == V2_SNR_INPUT_MIPI)
memcpy(&config.mipi, &v2_config.mipi, sizeof(v2_snr_mipi));
Expand All @@ -420,44 +417,20 @@ int v2_sensor_config(void) {

if (!access(v2_snr_endp, F_OK))
fd = open(v2_snr_endp, O_RDWR);
else fd = open("/dev/mipi", O_RDWR);
else
HAL_ERROR("v2_snr", "Imaging device doesn't exist, "
"maybe a kernel module is missing?\n");
if (fd < 0)
HAL_ERROR("v2_snr", "Opening imaging device has failed!\n");

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_RST_MIPI, unsigned int), &config.device);

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_RST_SENS, unsigned int), &config.device);

if (ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_CONF_DEV, v2_snr_dev), &config))
HAL_ERROR("v2_snr", "Configuring imaging device has failed!\n");

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_UNRST_MIPI, unsigned int), &config.device);

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_UNRST_SENS, unsigned int), &config.device);

close(fd);

return EXIT_SUCCESS;
}

void v2_sensor_deconfig(void) {
int fd;
v2_snr_dev config;
config.device = 0;

if (!access(v2_snr_endp, F_OK))
fd = open(v2_snr_endp, O_RDWR);
else fd = open("/dev/mipi", O_RDWR);
if (fd < 0)
HAL_DANGER("v2_snr", "Opening imaging device has failed!\n");

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_RST_SENS, unsigned int), &config.device);

ioctl(fd, _IOW(V2_SNR_IOC_MAGIC, V2_SNR_CMD_RST_MIPI, unsigned int), &config.device);

close(fd);
}

void v2_sensor_deinit(void)
{
dlclose(v2_snr_drv.handle);
Expand Down Expand Up @@ -544,17 +517,17 @@ int v2_video_create(char index, hal_vidconfig *config)
channel.rate.h265Vbr = (v2_venc_rate_h26xvbr){ .gop = config->gop,
.statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate,
.maxBitrate = MAX(config->bitrate, config->maxBitrate), .maxQual = config->maxQual,
.minQual = config->minQual, .minIQual = config->minQual }; break;
.minQual = config->minQual }; break;
case HAL_VIDMODE_QP:
channel.rate.mode = V2_VENC_RATEMODE_H265QP;
channel.rate.h265Qp = (v2_venc_rate_h26xqp){ .gop = config->gop,
.srcFps = config->framerate, .dstFps = config->framerate, .interQual = config->maxQual,
.predQual = config->minQual, .bipredQual = config->minQual }; break;
.predQual = config->minQual }; break;
case HAL_VIDMODE_AVBR:
channel.rate.mode = V2_VENC_RATEMODE_H265AVBR;
channel.rate.h265Avbr = (v2_venc_rate_h26xavbr){ .gop = config->gop,
.statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate,
.bitrate = config->bitrate }; break;
.maxBitrate = config->bitrate }; break;
default:
HAL_ERROR("v2_venc", "H.265 encoder does not support this mode!");
}
Expand All @@ -572,17 +545,17 @@ int v2_video_create(char index, hal_vidconfig *config)
channel.rate.h264Vbr = (v2_venc_rate_h26xvbr){ .gop = config->gop,
.statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate,
.maxBitrate = MAX(config->bitrate, config->maxBitrate), .maxQual = config->maxQual,
.minQual = config->minQual, .minIQual = config->minQual }; break;
.minQual = config->minQual }; break;
case HAL_VIDMODE_QP:
channel.rate.mode = V2_VENC_RATEMODE_H264QP;
channel.rate.h264Qp = (v2_venc_rate_h26xqp){ .gop = config->gop,
.srcFps = config->framerate, .dstFps = config->framerate, .interQual = config->maxQual,
.predQual = config->minQual, .bipredQual = config->minQual }; break;
.predQual = config->minQual }; break;
case HAL_VIDMODE_AVBR:
channel.rate.mode = V2_VENC_RATEMODE_H264AVBR;
channel.rate.h264Avbr = (v2_venc_rate_h26xavbr){ .gop = config->gop,
.statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate,
.bitrate = config->bitrate }; break;
.maxBitrate = config->bitrate }; break;
default:
HAL_ERROR("v2_venc", "H.264 encoder does not support this mode!");
}
Expand All @@ -594,6 +567,8 @@ int v2_video_create(char index, hal_vidconfig *config)
attrib->byFrame = 1;
attrib->pic.width = config->width;
attrib->pic.height = config->height;
attrib->bFrameNum = 0;
attrib->refNum = 1;
attach:
if (ret = v2_venc.fnCreateChannel(index, &channel))
return ret;
Expand Down
9 changes: 1 addition & 8 deletions src/hal/hisi/v2_snr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
enum {
V2_SNR_CMD_CONF_DEV = 1,
V2_SNR_CMD_CONF_EDGE,
V2_SNR_CMD_CONF_MSB,
V2_SNR_CMD_CONF_CMV,
V2_SNR_CMD_RST_SENS,
V2_SNR_CMD_UNRST_SENS,
V2_SNR_CMD_RST_MIPI,
V2_SNR_CMD_UNRST_MIPI,
V2_SNR_CMD_CONF_CROP
V2_SNR_CMD_CONF_MSB
};

typedef enum {
Expand Down Expand Up @@ -66,7 +60,6 @@ typedef struct {
} v2_snr_mipi;

typedef struct {
unsigned int device;
v2_snr_input input;
union {
v2_snr_mipi mipi;
Expand Down
15 changes: 3 additions & 12 deletions src/hal/hisi/v2_venc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ typedef enum {
V2_VENC_CODEC_END
} v2_venc_codec;

typedef enum {
V2_VENC_GOPMODE_NORMALP,
V2_VENC_GOPMODE_DUALP,
V2_VENC_GOPMODE_SMARTP,
V2_VENC_GOPMODE_BIPREDB,
V2_VENC_GOPMODE_LOWDELAYB,
V2_VENC_GOPMODE_END
} v2_venc_gopmode;

typedef enum {
V2_VENC_NALU_H264_BSLICE,
V2_VENC_NALU_H264_PSLICE,
Expand Down Expand Up @@ -75,6 +66,8 @@ typedef struct {
unsigned int profile;
int byFrame;
v2_common_dim pic;
unsigned int bFrameNum;
unsigned int refNum;
} v2_venc_attr_h26x;

typedef struct {
Expand Down Expand Up @@ -119,15 +112,14 @@ typedef struct {
unsigned int maxBitrate;
unsigned int maxQual;
unsigned int minQual;
unsigned int minIQual;
} v2_venc_rate_h26xvbr;

typedef struct {
unsigned int gop;
unsigned int statTime;
unsigned int srcFps;
unsigned int dstFps;
unsigned int bitrate;
unsigned int maxBitrate;
} v2_venc_rate_h26xavbr;

typedef struct {
Expand All @@ -136,7 +128,6 @@ typedef struct {
unsigned int dstFps;
unsigned int interQual;
unsigned int predQual;
unsigned int bipredQual;
} v2_venc_rate_h26xqp;

typedef struct {
Expand Down
6 changes: 2 additions & 4 deletions src/hal/tools.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include "tools.h"

char *memstr(char *haystack, char *needle, int size, char needlesize)
{
char *memstr(char *haystack, char *needle, int size, char needlesize) {
for (char *p = haystack; p <= (haystack - needlesize + size); p++)
if (!memcmp(p, needle, needlesize)) return p;
return NULL;
}

unsigned int millis()
{
unsigned int millis() {
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
Expand Down

0 comments on commit af0d555

Please sign in to comment.