Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disableAE cmd in encode_app #285

Merged
merged 10 commits into from
Aug 11, 2022
93 changes: 24 additions & 69 deletions package/encode_app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ typedef struct
long *shared_phyAddr;
void **shared_vAddr;
unsigned int *shared_size;
unsigned int *exp;
unsigned int *agc;
int *stride;
int *width;
int *height;
Expand Down Expand Up @@ -190,10 +188,9 @@ typedef struct
uint32_t *drop;
uint32_t *drop_en;
uint32_t *framerate_mod;
int *set_ae;
unsigned char *out_framerate;
int video_enabled;
int ae_enable;
uint32_t *ae_disable;
int setQos;

/* audio */
Expand Down Expand Up @@ -462,19 +459,6 @@ static void enqueue_buf(unsigned char index, int channel)
}
}

static void set_ae(char* dev_name, int ae_enable)
{
if((dev_name[10] >= '2') && (dev_name[10] <= '5') && (ae_enable & 0x1))
{
mediactl_set_ae(ISP_F2K_PIPELINE);
}
else if((dev_name[10] >= '6') && (dev_name[10] <= '9') && (ae_enable & 0x1))
{
mediactl_set_ae(ISP_R2K_PIPELINE);
}
return;
}

static void *v4l2_output(void *arg)
{
printf("%s\n", __FUNCTION__);
Expand Down Expand Up @@ -506,8 +490,6 @@ static void *v4l2_output(void *arg)
buf.memory = V4L2_MEMORY_USERPTR;

res = ioctl(pCtx->fd_v4l2[channel], VIDIOC_DQBUF, &buf);

set_ae(pCtx->dev_name[channel], pCtx->ae_enable);

if (res < 0 || errno == EINTR)
{
Expand Down Expand Up @@ -974,8 +956,6 @@ int free_context(void *arg)
free(pCtx->shared_phyAddr );
free(pCtx->shared_vAddr );
free(pCtx->shared_size );
free(pCtx->exp );
free(pCtx->agc );
free(pCtx->stride );
free(pCtx->width );
free(pCtx->height );
Expand All @@ -1000,7 +980,7 @@ int free_context(void *arg)
free(pCtx->drop );
free(pCtx->drop_en );
free(pCtx->out_framerate );
free(pCtx->set_ae );
free(pCtx->ae_disable );

return 0;
}
Expand Down Expand Up @@ -1241,17 +1221,6 @@ static int init_isp()

pCtx->fd_isp = isp_video(&ds1_info, sensor_type, lcd_type);

if(pCtx->exp[0] > 0)
{
printf("isp exp = %d\n", pCtx->exp[0]);
video_set_ae_dgain_cfg(pCtx->exp[0]);
}
if(pCtx->agc[0] > 0)
{
printf("isp agc = %d\n", pCtx->agc[0]);
video_set_ae_again_cfg(pCtx->agc[0]);
}

printf("%s>fd_isp: 0x%x\n", __FUNCTION__, pCtx->fd_isp);

sleep(1); //It seems ISP output is not stable at the beginning
Expand Down Expand Up @@ -1309,6 +1278,7 @@ int init_v4l2()
struct v4l2_format fmt;
int i;
int f2k=0, r2k=0;
int ae_disabled[2] = {0};

for(int j = 0; j < pCtx->ch_cnt; j++)
{
Expand All @@ -1324,6 +1294,23 @@ int init_v4l2()
sem_init(&pCtx->pSemGetData[i],0,0);
}

for(i = 0; i < pCtx->ch_cnt; i++)
{
if(pCtx->ae_disable[i])
{
if((pCtx->dev_name[i][10] >= '2') && (pCtx->dev_name[i][10] <= '5') && (!ae_disabled[0]))
{
mediactl_disable_ae(ISP_F2K_PIPELINE);
ae_disabled[0] = 1;
}
else if((pCtx->dev_name[i][10] >= '6') && (pCtx->dev_name[i][10] <= '9') && (!ae_disabled[1]))
{
mediactl_disable_ae(ISP_R2K_PIPELINE);
ae_disabled[1] = 1;
}
}
}

if(mediactl_init(REAL_CONF_FILENAME, &(pCtx->dev_info[0])) < 0)
{
printf("mediactl_init error!\n");
Expand Down Expand Up @@ -1905,8 +1892,6 @@ int alloc_context(void *arg)
pCtx->shared_phyAddr = (long*)malloc(sizeof(long) * pCtx->ch_cnt);
pCtx->shared_vAddr = (void**)malloc(sizeof(void*) * pCtx->ch_cnt);
pCtx->shared_size = (unsigned int*)malloc(sizeof(unsigned int) * pCtx->ch_cnt);
pCtx->exp = (unsigned int*)malloc(sizeof(unsigned int) * pCtx->ch_cnt);
pCtx->agc = (unsigned int*)malloc(sizeof(unsigned int) * pCtx->ch_cnt);
pCtx->stride = (int*)malloc(sizeof(int) * pCtx->ch_cnt);
pCtx->width = (int*)malloc(sizeof(int) * pCtx->ch_cnt);
pCtx->height = (int*)malloc(sizeof(int) * pCtx->ch_cnt);
Expand All @@ -1931,8 +1916,8 @@ int alloc_context(void *arg)
pCtx->drop = (uint32_t*)malloc(sizeof(uint32_t) * pCtx->ch_cnt);
pCtx->drop_en = (uint32_t*)malloc(sizeof(uint32_t) * pCtx->ch_cnt);
pCtx->framerate_mod = (uint32_t*)malloc(sizeof(uint32_t) * pCtx->ch_cnt);
pCtx->ae_disable = (uint32_t*)malloc(sizeof(uint32_t) * pCtx->ch_cnt);
pCtx->out_framerate = (unsigned char*)malloc(sizeof(unsigned char) * pCtx->ch_cnt);
pCtx->set_ae = (int*)malloc(sizeof(int) * pCtx->ch_cnt);

memset(pCtx->Cfg,0,sizeof(EncSettings));

Expand All @@ -1957,8 +1942,6 @@ int parse_cmd(int argc, char *argv[])
printf("-o: output file name or rtsp\n");
printf("-w: width\n");
printf("-h: height\n");
printf("-e: set sensor exposure rate\n");
printf("-ag: analog gain\n");
printf("-fps: sensor input framerate\n");
printf("-r: encoder output framrate\n");
printf("-inframes: input frames for input file\n");
Expand All @@ -1976,15 +1959,14 @@ int parse_cmd(int argc, char *argv[])
printf("-GDRMode: GDR mode 0:GDR_VERTICAL 1:GDR_HORIZONTAL\n");
printf("-enableLTR: enbale long term reference picture and specifies LTR refresh frequency in number of frames,0 to disable use refresh frequency\n");
printf("-roi: roi config file\n");
printf("-ae: enable ae\n");
printf("-disableAE: disable ae\n");
printf("-conf: v4l2 config file\n");
/* audio */
printf("-alsa: enable audio\n");
printf("-ac: audio channel count\n");
printf("-ar: audio sample rate\n");
printf("-af: auido sample format\n");
printf("-ad: audio device");
printf("-lossless: enable jpeg lossless encode");
// printf("-aof: audio output frames\n");
return 1;
}
Expand Down Expand Up @@ -2077,27 +2059,6 @@ int parse_cmd(int argc, char *argv[])
pCtx->Cfg[cur_ch].height = atoi(argv[i+1]);
printf("height %d\n", pCtx->Cfg[cur_ch].height);
}
else if(strcmp(argv[i], "-e") == 0)
{
pCtx->exp[cur_ch] = atoi(argv[i+1]);
printf("exp = %d\n", pCtx->exp[cur_ch]);
if(pCtx->exp[cur_ch] <= 0 || pCtx->exp[cur_ch] > 128)
{
printf("wrong exp = %d\n", pCtx->exp[cur_ch]);
return -1;
}
pCtx->exp[cur_ch] *= 8;
}
else if(strcmp(argv[i], "-ag") == 0)
{
pCtx->agc[cur_ch] = atoi(argv[i+1]);
printf("agc = %d\n", pCtx->agc[cur_ch]);
if(pCtx->agc[cur_ch] < 0 || pCtx->agc[cur_ch] > 232)
{
printf("wrong agc = %d\n", pCtx->agc[cur_ch]);
return -1;
}
}
else if(strcmp(argv[i], "-fps") == 0)
{
pCtx->framerate[cur_ch] = atoi(argv[i+1]);
Expand Down Expand Up @@ -2167,12 +2128,6 @@ int parse_cmd(int argc, char *argv[])
pCtx->Cfg[cur_ch].SliceQP = nqp;
printf("sliceqp %d\n", nqp);
}
else if (strcmp(argv[i],"-lossless") == 0 )
{
int lossless = atoi(argv[i+1]);
pCtx->Cfg[cur_ch].lossless = lossless;
printf("lossless %d\n", lossless);
}
else if (strcmp(argv[i],"-minqp") == 0 )
{
int nqp = atoi(argv[i+1]);
Expand Down Expand Up @@ -2240,9 +2195,9 @@ int parse_cmd(int argc, char *argv[])
printf("roi_parse_conf ok\n");
}
}
else if(strcmp(argv[i], "-ae") == 0)
else if(strcmp(argv[i], "-disableAE") == 0)
{
pCtx->ae_enable = atoi(argv[i+1]);
pCtx->ae_disable[cur_ch] = atoi(argv[i+1]);
}
else if(strcmp(argv[i], "-conf") == 0)
{
Expand Down