5088
- 收藏
- 点赞
- 分享
- 举报
同时实现h264及抓拍功能,提示snap time out
使用海思DEMO可以抓拍也可以获取h264流,但放到我的应用里来h264可以获取,抓拍提示snap time out,快被虐哭了,请大家帮忙看看我的配置那里有问题。谢谢
HI_S32 SAMPLE_VENC_720P_CLASSIC(HI_VOID)
{
PAYLOAD_TYPE_E enPayLoad[3]= {PT_H264, PT_JPEG,PT_H264};
PIC_SIZE_E enSize[3] = {PIC_HD1080, PIC_VGA,PIC_QVGA};
HI_U32 u32Profile = 1; //main profile
VB_CONF_S stVbConf;
SAMPLE_VI_CONFIG_S stViConfig = {0};
VPSS_GRP VpssGrp;
VPSS_CHN VpssChn;
VPSS_GRP_ATTR_S stVpssGrpAttr;
VPSS_CHN_ATTR_S stVpssChnAttr;
VPSS_CHN_MODE_S stVpssChnMode;
VENC_CHN VencChn;
SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR;
HI_S32 s32ChnNum=0;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32BlkSize, u32BlkCnt;
SIZE_S stSize;
#define SYSID_3516CV200 0x01000000
#define SYSID_3518EV200 0x02000000
#define SYSID_3518EV201 0x03000000
unsigned int id = SYSID_3518EV200;
FILE *fp = popen("himm 0x20050ee0 < /dev/null", "r");
if(fp) {
char line[128];
while(fgets(line, sizeof(line), fp))
{
if(strstr(line, "0x20050ee0:"))
{
sscanf(line, "%*s %x", &id);
break;
}
}
pclose(fp);
printf("sysid 0x%08x\n", id);
}
/******************************************
step 1: init sys variable
******************************************/
memset(&stVbConf,0,sizeof(VB_CONF_S));
switch(SENSOR_TYPE)
{
case SONY_IMX122_DC_1080P_30FPS:
case APTINA_AR0230_HISPI_1080P_30FPS:
case APTINA_AR0230_DC_1080P_30FPS:
enSize[0] = PIC_HD1080;
enSize[1] = PIC_CIF;
s32ChnNum = 1;
u32BlkCnt = id==SYSID_3516CV200?8:4;
break;
case APTINA_9M034_DC_720P_30FPS:
case APTINA_AR0130_DC_720P_30FPS:
case SONY_IMX122_DC_720P_30FPS:
case OMNIVISION_OV9732_DC_720P_30FPS:
case OMNIVISION_OV9732_MIPI_720P_30FPS:
enSize[0] = PIC_HD720;
enSize[1] = PIC_CIF;
//enSize[2] = PIC_QVGA;
s32ChnNum = 1;//enSize[1] is ExtViChan for md
u32BlkCnt = 8;
break;
case APTINA_AR0130_DC_960P_30FPS:
enSize[0] = PIC_HD960;
s32ChnNum = 1;
u32BlkCnt = 8;
break;
default:
printf("not support this sensor\n");
break;
}
stVbConf.u32MaxPoolCnt = 128;
/*video buffer*/
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[0].u32BlkCnt = u32BlkCnt;
if(s32ChnNum >= 2)
{
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[1].u32BlkCnt =3;
}
if(s32ChnNum >= 3)
{
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[2], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[2].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[2].u32BlkCnt = 3;
}
/******************************************
step 2: mpp system init.
******************************************/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_1080P_CLASSIC_0;
}
/******************************************
step 3: start vi dev & chn to capture
******************************************/
stViConfig.enViMode = SENSOR_TYPE;
stViConfig.enRotate = isImageRotate() ? ROTATE_90 : ROTATE_NONE;
stViConfig.enNorm = getVideoStandard();
stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
stViConfig.enWDRMode = WDR_MODE_NONE;
s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("start vi failed!\n");
goto END_VENC_1080P_CLASSIC_1;
}
#ifdef SUPPORT_MD
VI_EXT_CHN_ATTR_S stExtChnAttr;
VI_CHN ViExtChn = 1;
HI_U32 u32ViDepth = 1;//4;
stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT;
stExtChnAttr.s32BindChn = 0;//ViChn;
stExtChnAttr.stDestSize.u32Width = 352;
stExtChnAttr.stDestSize.u32Height = 288;
stExtChnAttr.s32DstFrameRate = -1;
stExtChnAttr.s32SrcFrameRate = -1;
stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE;
s32Ret = HI_MPI_VI_SetExtChnAttr(ViExtChn, &stExtChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
s32Ret = HI_MPI_VI_EnableChn(ViExtChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_EnableChn fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
s32Ret = HI_MPI_VI_SetFrameDepth(ViExtChn,u32ViDepth);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
#endif
/******************************************
step 4: start vpss and vi bind vpss
******************************************/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_1;
}
if(s32ChnNum >= 1)
{
VpssGrp = 0;
stVpssGrpAttr.u32MaxW = stSize.u32Width;
stVpssGrpAttr.u32MaxH = stSize.u32Height;
stVpssGrpAttr.bIeEn = HI_FALSE;
stVpssGrpAttr.bNrEn = HI_TRUE;
stVpssGrpAttr.bHistEn = HI_FALSE;
stVpssGrpAttr.bDciEn = HI_FALSE;
stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Vpss failed!\n");
goto END_VENC_1080P_CLASSIC_2;
}
s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Vi bind Vpss failed!\n");
goto END_VENC_1080P_CLASSIC_3;
}
VpssChn = 0;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG;
memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
if(s32ChnNum >= 2)
{
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[1], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
VpssChn = 1;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
if(s32ChnNum >= 3)
{
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[2], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
VpssChn = 2;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
/******************************************
step 5: start stream venc
******************************************/
/*** HD720P **/
enRcMode = SAMPLE_RC_VBR;
/*** enSize[0] **/
if(s32ChnNum >= 1)
{
VpssGrp = 0;
VpssChn = 0;
VencChn = 0;
s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[0],\
gs_enNorm, enSize[0], enRcMode,u32Profile);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
}
/*** enSize[1] **/
if(s32ChnNum >= 1)
{
VpssChn = 1;
VencChn = 1;
/* modify by elvis */
// s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[1], \
gs_enNorm, enSize[1], enRcMode,u32Profile);
/*snap start*/
HI_S32 s32Ret;
VENC_CHN_ATTR_S stVencChnAttr;
VENC_ATTR_JPEG_S stJpegAttr;
/******************************************
step 1: Create Venc Channel
******************************************/
stVencChnAttr.stVeAttr.enType = PT_JPEG;
stJpegAttr.u32MaxPicWidth = pstSize->u32Width;
stJpegAttr.u32MaxPicHeight = pstSize->u32Height;
stJpegAttr.u32PicWidth = pstSize->u32Width;
stJpegAttr.u32PicHeight = pstSize->u32Height;
stJpegAttr.u32BufSize = (((pstSize->u32Width+15)>>4)<<4) * (((pstSize->u32Height+15)>>4)<<4);
stJpegAttr.bByFrame = HI_TRUE;/*get stream mode is field mode or frame mode*/
stJpegAttr.bSupportDCF = HI_FALSE;
memcpy(&stVencChnAttr.stVeAttr.stAttrJpeg, &stJpegAttr, sizeof(VENC_ATTR_JPEG_S));
/*snap end*/
s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
int ret = pthread_create(&snapVencPid, 0, snapPthreadProcess, VencChn);
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
HI_S32 snapPthreadProcess(HI_S32 VencChn)
{
printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
int i = 0;
char ch;
HI_S32 s32Ret;
printf("Test : VencChn = %d\n",VencChn);
while ((ch = (char)getchar()) != 'q')
{
s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
printf("!!!!!!!!!!!%s: sanp process failed!\n", __FUNCTION__);
printf("!!!!!!!!!!!%s: sanp process failed!\n", __FUNCTION__);
break;
}
printf("snap %d success!\n", i);
i++;
}
printf("please press ENTER to exit this sample\n");
getchar();
getchar();
}
/******************************************************************************
* funciton : snap process
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SnapProcess(VENC_CHN VencChn)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_CHN_STAT_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
printf("press any key to snap one pic\n");
getchar();
/******************************************
step 2: Start Recv Venc Pictures
******************************************/
stRecvParam.s32RecvPicNum = 1;
s32Ret = HI_MPI_VENC_StartRecvPicEx(VencChn,&stRecvParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StartRecvPic faild with%#x!\n", s32Ret);
return HI_FAILURE;
}
/******************************************
step 3: recv picture
******************************************/
s32VencFd = HI_MPI_VENC_GetFd(VencChn);
if (s32VencFd < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd faild with%#x!\n", s32VencFd);
return HI_FAILURE;
}
FD_ZERO(&read_fds);
FD_SET(s32VencFd, &read_fds);
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
s32Ret = select(s32VencFd+1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("snap select failed!\n");
return HI_FAILURE;
}
else if (0 == s32Ret)
{
SAMPLE_PRT("snap time out!\n");//按回车提示time out
return HI_FAILURE;
}
else
{
if (FD_ISSET(s32VencFd, &read_fds))
{
s32Ret = HI_MPI_VENC_Query(VencChn, &stStat);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_Query failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*******************************************************
suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
*******************************************************/
if(0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc memory failed!\n");
return HI_FAILURE;
}
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(VencChn, &stStream, -1);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
s32Ret = SAMPLE_COMM_VENC_SaveSnap(&stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
s32Ret = HI_MPI_VENC_ReleaseStream(VencChn, &stStream);
if (s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_ReleaseStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
free(stStream.pstPack);
stStream.pstPack = NULL;
}
}
/******************************************
step 4: stop recv picture
******************************************/
s32Ret = HI_MPI_VENC_StopRecvPic(VencChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_StopRecvPic failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_VENC_720P_CLASSIC(HI_VOID)
{
PAYLOAD_TYPE_E enPayLoad[3]= {PT_H264, PT_JPEG,PT_H264};
PIC_SIZE_E enSize[3] = {PIC_HD1080, PIC_VGA,PIC_QVGA};
HI_U32 u32Profile = 1; //main profile
VB_CONF_S stVbConf;
SAMPLE_VI_CONFIG_S stViConfig = {0};
VPSS_GRP VpssGrp;
VPSS_CHN VpssChn;
VPSS_GRP_ATTR_S stVpssGrpAttr;
VPSS_CHN_ATTR_S stVpssChnAttr;
VPSS_CHN_MODE_S stVpssChnMode;
VENC_CHN VencChn;
SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR;
HI_S32 s32ChnNum=0;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32BlkSize, u32BlkCnt;
SIZE_S stSize;
#define SYSID_3516CV200 0x01000000
#define SYSID_3518EV200 0x02000000
#define SYSID_3518EV201 0x03000000
unsigned int id = SYSID_3518EV200;
FILE *fp = popen("himm 0x20050ee0 < /dev/null", "r");
if(fp) {
char line[128];
while(fgets(line, sizeof(line), fp))
{
if(strstr(line, "0x20050ee0:"))
{
sscanf(line, "%*s %x", &id);
break;
}
}
pclose(fp);
printf("sysid 0x%08x\n", id);
}
/******************************************
step 1: init sys variable
******************************************/
memset(&stVbConf,0,sizeof(VB_CONF_S));
switch(SENSOR_TYPE)
{
case SONY_IMX122_DC_1080P_30FPS:
case APTINA_AR0230_HISPI_1080P_30FPS:
case APTINA_AR0230_DC_1080P_30FPS:
enSize[0] = PIC_HD1080;
enSize[1] = PIC_CIF;
s32ChnNum = 1;
u32BlkCnt = id==SYSID_3516CV200?8:4;
break;
case APTINA_9M034_DC_720P_30FPS:
case APTINA_AR0130_DC_720P_30FPS:
case SONY_IMX122_DC_720P_30FPS:
case OMNIVISION_OV9732_DC_720P_30FPS:
case OMNIVISION_OV9732_MIPI_720P_30FPS:
enSize[0] = PIC_HD720;
enSize[1] = PIC_CIF;
//enSize[2] = PIC_QVGA;
s32ChnNum = 1;//enSize[1] is ExtViChan for md
u32BlkCnt = 8;
break;
case APTINA_AR0130_DC_960P_30FPS:
enSize[0] = PIC_HD960;
s32ChnNum = 1;
u32BlkCnt = 8;
break;
default:
printf("not support this sensor\n");
break;
}
stVbConf.u32MaxPoolCnt = 128;
/*video buffer*/
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[0].u32BlkCnt = u32BlkCnt;
if(s32ChnNum >= 2)
{
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[1].u32BlkCnt =3;
}
if(s32ChnNum >= 3)
{
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
enSize[2], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[2].u32BlkSize = u32BlkSize;
stVbConf.astCommPool[2].u32BlkCnt = 3;
}
/******************************************
step 2: mpp system init.
******************************************/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_1080P_CLASSIC_0;
}
/******************************************
step 3: start vi dev & chn to capture
******************************************/
stViConfig.enViMode = SENSOR_TYPE;
stViConfig.enRotate = isImageRotate() ? ROTATE_90 : ROTATE_NONE;
stViConfig.enNorm = getVideoStandard();
stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
stViConfig.enWDRMode = WDR_MODE_NONE;
s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("start vi failed!\n");
goto END_VENC_1080P_CLASSIC_1;
}
#ifdef SUPPORT_MD
VI_EXT_CHN_ATTR_S stExtChnAttr;
VI_CHN ViExtChn = 1;
HI_U32 u32ViDepth = 1;//4;
stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT;
stExtChnAttr.s32BindChn = 0;//ViChn;
stExtChnAttr.stDestSize.u32Width = 352;
stExtChnAttr.stDestSize.u32Height = 288;
stExtChnAttr.s32DstFrameRate = -1;
stExtChnAttr.s32SrcFrameRate = -1;
stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE;
s32Ret = HI_MPI_VI_SetExtChnAttr(ViExtChn, &stExtChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
s32Ret = HI_MPI_VI_EnableChn(ViExtChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_EnableChn fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
s32Ret = HI_MPI_VI_SetFrameDepth(ViExtChn,u32ViDepth);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
goto END_VENC_1080P_CLASSIC_1;
}
#endif
/******************************************
step 4: start vpss and vi bind vpss
******************************************/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_1;
}
if(s32ChnNum >= 1)
{
VpssGrp = 0;
stVpssGrpAttr.u32MaxW = stSize.u32Width;
stVpssGrpAttr.u32MaxH = stSize.u32Height;
stVpssGrpAttr.bIeEn = HI_FALSE;
stVpssGrpAttr.bNrEn = HI_TRUE;
stVpssGrpAttr.bHistEn = HI_FALSE;
stVpssGrpAttr.bDciEn = HI_FALSE;
stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Vpss failed!\n");
goto END_VENC_1080P_CLASSIC_2;
}
s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Vi bind Vpss failed!\n");
goto END_VENC_1080P_CLASSIC_3;
}
VpssChn = 0;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG;
memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
if(s32ChnNum >= 2)
{
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[1], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
VpssChn = 1;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
if(s32ChnNum >= 3)
{
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[2], &stSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
VpssChn = 2;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stVpssChnMode.u32Width = stSize.u32Width;
stVpssChnMode.u32Height = stSize.u32Height;
stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Enable vpss chn failed!\n");
goto END_VENC_1080P_CLASSIC_4;
}
}
/******************************************
step 5: start stream venc
******************************************/
/*** HD720P **/
enRcMode = SAMPLE_RC_VBR;
/*** enSize[0] **/
if(s32ChnNum >= 1)
{
VpssGrp = 0;
VpssChn = 0;
VencChn = 0;
s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[0],\
gs_enNorm, enSize[0], enRcMode,u32Profile);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
}
/*** enSize[1] **/
if(s32ChnNum >= 1)
{
VpssChn = 1;
VencChn = 1;
/* modify by elvis */
// s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[1], \
gs_enNorm, enSize[1], enRcMode,u32Profile);
/*snap start*/
HI_S32 s32Ret;
VENC_CHN_ATTR_S stVencChnAttr;
VENC_ATTR_JPEG_S stJpegAttr;
/******************************************
step 1: Create Venc Channel
******************************************/
stVencChnAttr.stVeAttr.enType = PT_JPEG;
stJpegAttr.u32MaxPicWidth = pstSize->u32Width;
stJpegAttr.u32MaxPicHeight = pstSize->u32Height;
stJpegAttr.u32PicWidth = pstSize->u32Width;
stJpegAttr.u32PicHeight = pstSize->u32Height;
stJpegAttr.u32BufSize = (((pstSize->u32Width+15)>>4)<<4) * (((pstSize->u32Height+15)>>4)<<4);
stJpegAttr.bByFrame = HI_TRUE;/*get stream mode is field mode or frame mode*/
stJpegAttr.bSupportDCF = HI_FALSE;
memcpy(&stVencChnAttr.stVeAttr.stAttrJpeg, &stJpegAttr, sizeof(VENC_ATTR_JPEG_S));
/*snap end*/
s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
int ret = pthread_create(&snapVencPid, 0, snapPthreadProcess, VencChn);
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto END_VENC_1080P_CLASSIC_5;
}
HI_S32 snapPthreadProcess(HI_S32 VencChn)
{
printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
int i = 0;
char ch;
HI_S32 s32Ret;
printf("Test : VencChn = %d\n",VencChn);
while ((ch = (char)getchar()) != 'q')
{
s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
printf("!!!!!!!!!!!%s: sanp process failed!\n", __FUNCTION__);
printf("!!!!!!!!!!!%s: sanp process failed!\n", __FUNCTION__);
break;
}
printf("snap %d success!\n", i);
i++;
}
printf("please press ENTER to exit this sample\n");
getchar();
getchar();
}
/******************************************************************************
* funciton : snap process
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SnapProcess(VENC_CHN VencChn)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_CHN_STAT_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
printf("press any key to snap one pic\n");
getchar();
/******************************************
step 2: Start Recv Venc Pictures
******************************************/
stRecvParam.s32RecvPicNum = 1;
s32Ret = HI_MPI_VENC_StartRecvPicEx(VencChn,&stRecvParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StartRecvPic faild with%#x!\n", s32Ret);
return HI_FAILURE;
}
/******************************************
step 3: recv picture
******************************************/
s32VencFd = HI_MPI_VENC_GetFd(VencChn);
if (s32VencFd < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd faild with%#x!\n", s32VencFd);
return HI_FAILURE;
}
FD_ZERO(&read_fds);
FD_SET(s32VencFd, &read_fds);
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
s32Ret = select(s32VencFd+1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("snap select failed!\n");
return HI_FAILURE;
}
else if (0 == s32Ret)
{
SAMPLE_PRT("snap time out!\n");//按回车提示time out
return HI_FAILURE;
}
else
{
if (FD_ISSET(s32VencFd, &read_fds))
{
s32Ret = HI_MPI_VENC_Query(VencChn, &stStat);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_Query failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*******************************************************
suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
*******************************************************/
if(0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc memory failed!\n");
return HI_FAILURE;
}
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(VencChn, &stStream, -1);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
s32Ret = SAMPLE_COMM_VENC_SaveSnap(&stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
s32Ret = HI_MPI_VENC_ReleaseStream(VencChn, &stStream);
if (s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_ReleaseStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
free(stStream.pstPack);
stStream.pstPack = NULL;
}
}
/******************************************
step 4: stop recv picture
******************************************/
s32Ret = HI_MPI_VENC_StopRecvPic(VencChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_StopRecvPic failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
我来回答
回答1个
时间排序
认可量排序
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2020-04-08 18:19:13
-
02019-06-10 15:03:36
-
2016-06-02 19:13:11
-
2020-07-14 08:42:42
-
2017-10-17 15:02:52
-
2014-08-25 15:03:10
-
2015-05-26 19:26:57
-
12024-03-15 15:47:47
-
2018-11-04 08:24:34
-
2020-03-24 11:56:33
-
2015-05-26 20:38:27
-
392015-12-18 15:47:06
-
42014-09-30 11:20:02
-
2020-10-06 12:17:39
-
2014-10-25 08:36:59
-
2017-06-22 10:34:42
-
2015-10-14 11:24:00
-
2017-05-24 10:58:20
-
2016-03-15 20:35:37
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认