Skip to content

Commit

Permalink
Missing ISP day/night mode that made Ingenic unusable without first call
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 2, 2024
1 parent 3fd20cf commit b20f240
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
52 changes: 33 additions & 19 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ int t31_channel_create(char index, short width, short height, char framerate)
return ret;
}

if (ret = t31_venc.fnCreateGroup(index))
return ret;

return EXIT_SUCCESS;
}

void t31_channel_destroy(char index)
{
t31_venc.fnDestroyGroup(index);

t31_fs.fnDestroyChannel(index);
}

int t31_channel_grayscale(char enable)
{
return t31_isp.fnSetRunningMode(enable & 1);
}

int t31_channel_unbind(char index)
{
int ret;
Expand Down Expand Up @@ -223,9 +223,18 @@ int t31_video_create(char index, hal_vidconfig *config)
t31_venc_prof profile;
t31_venc_ratemode ratemode;

switch (config->mode) {
case HAL_VIDMODE_CBR: ratemode = T31_VENC_RATEMODE_CBR; break;
case HAL_VIDMODE_VBR: ratemode = T31_VENC_RATEMODE_VBR; break;
case HAL_VIDMODE_QP: ratemode = T31_VENC_RATEMODE_QP; break;
case HAL_VIDMODE_AVBR: ratemode = T31_VENC_RATEMODE_AVBR; break;
default: T31_ERROR("Video encoder does not support this mode!");
}
switch (config->codec) {
case HAL_VIDCODEC_JPG:
case HAL_VIDCODEC_MJPG: profile = T31_VENC_PROF_MJPG; break;
case HAL_VIDCODEC_MJPG:
profile = T31_VENC_PROF_MJPG;
break;
case HAL_VIDCODEC_H265: profile = T31_VENC_PROF_H265_MAIN; break;
case HAL_VIDCODEC_H264:
switch (config->profile) {
Expand All @@ -235,38 +244,34 @@ int t31_video_create(char index, hal_vidconfig *config)
} break;
default: T31_ERROR("This codec is not supported by the hardware!");
}
switch (config->mode) {
case HAL_VIDMODE_CBR: ratemode = T31_VENC_RATEMODE_CBR; break;
case HAL_VIDMODE_VBR: ratemode = T31_VENC_RATEMODE_VBR; break;
case HAL_VIDMODE_QP: ratemode = T31_VENC_RATEMODE_QP; break;
case HAL_VIDMODE_AVBR: ratemode = T31_VENC_RATEMODE_AVBR; break;
default: T31_ERROR("Video encoder does not support this mode!");
}

memset(&channel, 0, sizeof(channel));
t31_venc.fnSetDefaults(&channel, profile, ratemode, config->width, config->height,
config->framerate, 1, config->gop, 2, -1, config->bitrate);

switch (channel.rate.mode) {
case T31_VENC_RATEMODE_CBR:
channel.rate.cbr = (t31_venc_rate_cbr){ .tgtBitrate = MAX(config->bitrate,
config->maxBitrate), .minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
channel.rate.cbr = (t31_venc_rate_cbr){ .tgtBitrate = MAX(config->bitrate, config->maxBitrate),
.initQual = -1, .minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
.options = T31_VENC_RCOPT_SCN_CHG_RES | T31_VENC_RCOPT_SC_PREVENTION,
.maxPicSize = config->width }; break;
case T31_VENC_RATEMODE_VBR:
channel.rate.vbr = (t31_venc_rate_vbr){ .maxBitrate = config->maxBitrate,
.minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
.initQual = -1, .minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
.options = T31_VENC_RCOPT_SCN_CHG_RES | T31_VENC_RCOPT_SC_PREVENTION,
.maxPicSize = config->width }; break;
case T31_VENC_RATEMODE_QP:
channel.rate.qpModeQual = config->maxQual; break;
case T31_VENC_RATEMODE_AVBR:
channel.rate.avbr = (t31_venc_rate_xvbr){ .maxBitrate = config->maxBitrate,
.minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
.initQual = -1, .minQual = 34, .maxQual = 51, .ipDelta = -1, .pbDelta = -1,
.options = T31_VENC_RCOPT_SCN_CHG_RES | T31_VENC_RCOPT_SC_PREVENTION,
.maxPicSize = config->width, .maxPsnr = 42 }; break;
}

if (ret = t31_venc.fnCreateGroup(index))
return ret;

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

Expand Down Expand Up @@ -296,6 +301,9 @@ int t31_video_destroy(char index)
if (ret = t31_venc.fnDestroyChannel(index))
return ret;

if (ret = t31_venc.fnDestroyGroup(index))
return ret;

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -414,6 +422,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();
Expand Down Expand Up @@ -454,18 +463,23 @@ int t31_system_init(void)

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;
}
1 change: 1 addition & 0 deletions src/hal/inge/t31_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ int t31_audio_init(void);
int t31_channel_bind(char index);
int t31_channel_create(char index, short width, short height, char framerate);
void t31_channel_destroy(char index);
int t31_channel_grayscale(char enable);
int t31_channel_unbind(char index);

int t31_region_create(int *handle, hal_rect rect);
Expand Down
16 changes: 15 additions & 1 deletion src/hal/inge/t31_isp.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ static t31_isp_snr t31_sensors[] = {

typedef struct {
void *handle;


int (*fnEnableTuning)(void);
int (*fnExit)(void);
int (*fnInit)(void);
int (*fnLoadConfig)(char *path);
int (*fnSetRunningMode)(int nightOn);

int (*fnAddSensor)(t31_isp_snr *sensor);
int (*fnDeleteSensor)(t31_isp_snr *sensor);
Expand All @@ -111,6 +113,12 @@ static int t31_isp_load(t31_isp_impl *isp_lib) {
return EXIT_FAILURE;
}

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

if (!(isp_lib->fnExit = (int(*)(void))
dlsym(isp_lib->handle, "IMP_ISP_Close"))) {
fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Close!\n");
Expand All @@ -129,6 +137,12 @@ static int t31_isp_load(t31_isp_impl *isp_lib) {
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"))) {
fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_AddSensor!\n");
Expand Down
2 changes: 1 addition & 1 deletion src/hal/inge/t31_venc.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ typedef struct {
t31_venc_rate_xvbr cvbr;
t31_venc_rate_xvbr avbr;
};
unsigned int fpsDen;
unsigned int fpsNum;
unsigned int fpsDen;
} t31_venc_rate;

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void set_grayscale(bool active) {
case HAL_PLATFORM_I6: i6_channel_grayscale(active); break;
case HAL_PLATFORM_I6C: i6c_channel_grayscale(active); break;
case HAL_PLATFORM_I6F: i6f_channel_grayscale(active); break;
case HAL_PLATFORM_T31: t31_channel_grayscale(active); break;
}
pthread_mutex_unlock(&mutex);
}
Expand Down Expand Up @@ -142,6 +143,7 @@ int disable_venc_chn(char index, char jpeg) {
case HAL_PLATFORM_I6: return i6_video_destroy(index);
case HAL_PLATFORM_I6C: return i6c_video_destroy(index, jpeg);
case HAL_PLATFORM_I6F: return i6f_video_destroy(index, jpeg);
case HAL_PLATFORM_T31: return t31_video_destroy(index);
case HAL_PLATFORM_V4: return v4_video_destroy(index);
}
return 0;
Expand All @@ -154,7 +156,7 @@ int start_sdk() {
case HAL_PLATFORM_I6: ret = i6_hal_init(); break;
case HAL_PLATFORM_I6C: ret = i6c_hal_init(); break;
case HAL_PLATFORM_I6F: ret = i6f_hal_init(); break;
case HAL_PLATFORM_T31: ret = t31_hal_init(); break;
case HAL_PLATFORM_T31: ret = t31_hal_init(); break;
case HAL_PLATFORM_V4: ret = v4_hal_init(); break;
}
if (ret) {
Expand Down

0 comments on commit b20f240

Please sign in to comment.