Skip to content

Commit

Permalink
Fixing stuttering and standardizing the HAL functions on Ingenic T31
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 3, 2024
1 parent 5f40539 commit a489012
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 47 deletions.
114 changes: 70 additions & 44 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int t31_channel_create(char index, short width, short height, char framerate)
.dest = { .width = width, .height = height }, .pixFmt = T31_PIXFMT_NV12,
.scale = { .enable = (_t31_snr_dim.width != width || _t31_snr_dim.height != height)
? 1 : 0, .width = width, .height = height },
.fpsNum = framerate, .fpsDen = 1, .bufCount = 1, .phyOrExtChn = 0,
.fpsNum = framerate, .fpsDen = 1, .bufCount = width > 1920 ? 2 : 1, .phyOrExtChn = 0,
};

if (ret = t31_fs.fnCreateChannel(index, &channel))
Expand Down Expand Up @@ -162,6 +162,59 @@ int t31_config_load(char *path)
return t31_isp.fnLoadConfig(path);
}

int t31_pipeline_create(char mirror, char flip)
{
int ret;

if (ret = t31_isp.fnInit())
return ret;
{
const char *sensor = getenv("SENSOR");
for (char i = 0; i < sizeof(t31_sensors) / sizeof(*t31_sensors); i++) {
if (strcmp(t31_sensors[i].name, sensor)) continue;
memcpy(&_t31_isp_snr, &t31_sensors[i], sizeof(t31_isp_snr));
if (t31_sensors[i].mode == T31_ISP_COMM_I2C)
memcpy(&_t31_isp_snr.i2c.type, &t31_sensors[i].name, strlen(t31_sensors[i].name));
else if (t31_sensors[i].mode == T31_ISP_COMM_SPI)
memcpy(&_t31_isp_snr.spi.alias, &t31_sensors[i].name, strlen(t31_sensors[i].name));
_t31_snr_dim = t31_dims[i];
ret = 0;
break;
}
if (ret)
return EXIT_FAILURE;
}
if (ret = t31_isp.fnAddSensor(&_t31_isp_snr))
return ret;
if (ret = t31_isp.fnEnableSensor())
return ret;
if (ret = t31_isp.fnEnableTuning())
return ret;
if (ret = t31_isp.fnSetRunningMode(0))
return ret;
if (ret = t31_isp.fnSetAntiFlicker(T31_ISP_FLICK_50HZ))
return ret;
if (ret = t31_isp.fnSetFlip((mirror ? 1 : 0) | (flip ? 2 : 0)))
return ret;

if (ret = t31_osd.fnCreateGroup(_t31_osd_grp))
return ret;
if (ret = t31_osd.fnStartGroup(_t31_osd_grp))
return ret;

return EXIT_SUCCESS;
}

void t31_pipeline_destroy(void)
{
t31_osd.fnStopGroup(_t31_osd_grp);
t31_osd.fnDestroyGroup(_t31_osd_grp);

t31_isp.fnDisableSensor();
t31_isp.fnDeleteSensor(&_t31_isp_snr);
t31_isp.fnExit();
}

int t31_region_create(int *handle, hal_rect rect)
{
int ret;
Expand Down Expand Up @@ -380,9 +433,23 @@ void *t31_video_thread(void)

if (t31_venc_cb) {
hal_vidstream outStrm;
hal_vidpack outPack[1];
outStrm.count = 1;
hal_vidpack outPack[stream.count];
memset(outPack, 0, sizeof(outPack));
outStrm.count = stream.count;
outStrm.seq = stream.sequence;
for (int j = 0; j < stream.count; j++) {
t31_venc_pack *pack = &stream.packet[j];
if (!pack->length) continue;
outPack[j].offset = 0;
unsigned int remain = stream.length - pack->offset;
if (remain < pack->length) {
outPack[j].data = (unsigned char*)(stream.addr);
outPack[j].length = pack->length - remain;
} else {
outPack[j].data = (unsigned char*)(stream.addr + pack->offset);
outPack[j].length = pack->length;
}
}
outPack[0].data = (unsigned char*)(stream.addr);
outPack[0].offset = 0;
outPack[0].length = 0;
Expand All @@ -405,14 +472,7 @@ void *t31_video_thread(void)

void t31_system_deinit(void)
{
t31_osd.fnStopGroup(_t31_osd_grp);
t31_osd.fnDestroyGroup(_t31_osd_grp);

t31_sys.fnExit();

t31_isp.fnDisableSensor();
t31_isp.fnDeleteSensor(&_t31_isp_snr);
t31_isp.fnExit();
}

int t31_system_init(void)
Expand All @@ -427,42 +487,8 @@ int t31_system_init(void)
puts(version.version);
}

{
const char *sensor = getenv("SENSOR");
for (char i = 0; i < sizeof(t31_sensors) / sizeof(*t31_sensors); i++) {
if (strcmp(t31_sensors[i].name, sensor)) continue;
memcpy(&_t31_isp_snr, &t31_sensors[i], sizeof(t31_isp_snr));
if (t31_sensors[i].mode == T31_ISP_COMM_I2C)
memcpy(&_t31_isp_snr.i2c.type, &t31_sensors[i].name, strlen(t31_sensors[i].name));
else if (t31_sensors[i].mode == T31_ISP_COMM_SPI)
memcpy(&_t31_isp_snr.spi.alias, &t31_sensors[i].name, strlen(t31_sensors[i].name));
_t31_snr_dim = t31_dims[i];
ret = 0;
break;
}
if (ret)
return EXIT_FAILURE;
}

if (ret = t31_isp.fnInit())
return ret;
if (ret = t31_isp.fnAddSensor(&_t31_isp_snr))
return ret;
if (ret = t31_isp.fnEnableSensor())
return ret;

if (ret = t31_sys.fnInit())
return ret;

if (ret = t31_isp.fnEnableTuning())
return ret;
if (ret = t31_isp.fnSetRunningMode(0))
return ret;

if (ret = t31_osd.fnCreateGroup(_t31_osd_grp))
return ret;
if (ret = t31_osd.fnStartGroup(_t31_osd_grp))
return ret;

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions src/hal/inge/t31_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ int t31_channel_unbind(char index);

int t31_config_load(char *path);

int t31_pipeline_create(char mirror, char flip);
void t31_pipeline_destroy(void);

int t31_region_create(int *handle, hal_rect rect);
void t31_region_destroy(int *handle);
int t31_region_setbitmap(int *handle, hal_bitmap *bitmap);
Expand Down
22 changes: 21 additions & 1 deletion src/hal/inge/t31_isp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ typedef enum {
T31_ISP_COMM_SPI,
} t31_isp_comm;

typedef enum {
T31_ISP_FLICK_OFF,
T31_ISP_FLICK_50HZ,
T31_ISP_FLICK_60HZ
} t31_isp_flick;

typedef struct {
char type[20];
int addr;
Expand Down Expand Up @@ -99,6 +105,8 @@ typedef struct {
int (*fnExit)(void);
int (*fnInit)(void);
int (*fnLoadConfig)(char *path);
int (*fnSetAntiFlicker)(t31_isp_flick mode);
int (*fnSetFlip)(int mode);
int (*fnSetRunningMode)(int nightOn);

int (*fnAddSensor)(t31_isp_snr *sensor);
Expand Down Expand Up @@ -137,11 +145,23 @@ static int t31_isp_load(t31_isp_impl *isp_lib) {
return EXIT_FAILURE;
}

if (!(isp_lib->fnSetAntiFlicker = (int(*)(t31_isp_flick mode))
dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetAntiFlickerAttr"))) {
fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetAntiFlickerAttr!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnSetFlip = (int(*)(int mode))
dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetHVFLIP"))) {
fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetHVFLIP!\n");
return EXIT_FAILURE;
}

if (!(isp_lib->fnSetRunningMode = (int(*)(int nightOn))
dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetISPRunningMode"))) {
fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetISPRunningMode!\n");
return EXIT_FAILURE;
}
}

if (!(isp_lib->fnAddSensor = (int(*)(t31_isp_snr *sensor))
dlsym(isp_lib->handle, "IMP_ISP_AddSensor"))) {
Expand Down
7 changes: 5 additions & 2 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ int start_sdk() {
height, framerate); break;
case HAL_PLATFORM_I6F: ret = i6f_pipeline_create(0, width,
height, framerate); break;
case HAL_PLATFORM_T31: ret = t31_pipeline_create(
app_config.mirror, app_config.flip); break;
case HAL_PLATFORM_V3: ret = v3_pipeline_create(); break;
case HAL_PLATFORM_V4: ret = v4_pipeline_create(); break;
}
Expand Down Expand Up @@ -287,8 +289,8 @@ int start_sdk() {
if (app_config.mjpeg_enable) {
int index = take_next_free_channel(true);

if (ret = create_vpss_chn(index, app_config.mjpeg_width, app_config.mjpeg_height,
app_config.mjpeg_fps, 1)) {
if (ret = create_vpss_chn(index, app_config.mjpeg_width,
app_config.mjpeg_height, app_config.mjpeg_fps, 1)) {
fprintf(stderr,
"Creating channel %d failed with %#x!\n%s\n",
index, ret, errstr(ret));
Expand Down Expand Up @@ -389,6 +391,7 @@ int stop_sdk() {
case HAL_PLATFORM_I6: i6_pipeline_destroy(); break;
case HAL_PLATFORM_I6C: i6c_pipeline_destroy(); break;
case HAL_PLATFORM_I6F: i6f_pipeline_destroy(); break;
case HAL_PLATFORM_T31: t31_pipeline_destroy(); break;
case HAL_PLATFORM_V3: v3_pipeline_destroy(); break;
case HAL_PLATFORM_V4: v4_pipeline_destroy(); break;
}
Expand Down

0 comments on commit a489012

Please sign in to comment.