11389
- 收藏
- 点赞
- 分享
- 举报
关于hi3516a的错误:HI_MPI_VENC_SendFrame failed with 0xa0088003
1.使用MPI函数HI_MPI_VPSS_GetChnFrame从vpss获取帧,然后将帧通过HI_MPI_VENC_SendFrame函数发给venc编码,出现错误:HI_MPI_VENC_SendFrame failed with 0xa0088003。"参数范围不合法",可是我查看了一下,都是合法的值呀,有没有前辈遇到类似的情况?
以下是源码:
[code]
#include
#include
#include
#include
#include
#include
#include "sample_comm.h"
#define PRE_WIDTH 1920
#define PRE_HEIGHT 1080
#define RES_WIDTH 3840
#define RES_HEIGHT 2160
VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_NTSC;
PIC_SIZE_E g_enPicSize = PIC_HD1080;
VIDEO_FRAME_INFO_S g_stFrame;
static HI_CHAR* pUserPageAddr[2] = {HI_NULL,HI_NULL};
static HI_U32 u32Size = 0;
VIDEO_FRAME_INFO_S* g_stDestFrame;
VIDEO_FRAME_INFO_S* g_stVpssFrame;
static int VENC_SnapProcess(VENC_CHN VencChn)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_STREAM_S stStream;
VENC_CHN_STAT_S stStat;
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
printf("press any key to snap one pic\n");
getchar();
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;
}
#if 0
printf("g_stDestFrame->stVFrame.u32Width = %d\n",g_stDestFrame->stVFrame.u32Width);
printf("g_stDestFrame->stVFrame.u32Height = %d\n",g_stDestFrame->stVFrame.u32Height);
printf("g_stDestFrame->stVFrame.u32PhyAddr[0] = %#x\n",g_stDestFrame->stVFrame.u32PhyAddr[0]);
printf("g_stDestFrame->stVFrame.u32PhyAddr[1] = %#x\n",g_stDestFrame->stVFrame.u32PhyAddr[1]);
printf("g_stDestFrame->stVFrame.pVirAddr[0] = %#x\n",g_stDestFrame->stVFrame.pVirAddr[0]);
printf("g_stDestFrame->stVFrame.pVirAddr[1] = %#x\n",g_stDestFrame->stVFrame.pVirAddr[1]);
printf("g_stDestFrame->stVFrame.u32Stride[0] = %d\n",g_stDestFrame->stVFrame.u32Stride[0]);
printf("g_stDestFrame->stVFrame.u32Stride[1] = %d\n",g_stDestFrame->stVFrame.u32Stride[1]);
printf("g_stDestFrame->stVFrame.enPixelFormat = %d\n",g_stDestFrame->stVFrame.enPixelFormat);
printf("g_stDestFrame->stVFrame.u64pts = %d\n",g_stDestFrame->stVFrame.u64pts);
printf("g_stDestFrame->stVFrame.u32TimeRef = %d\n",g_stDestFrame->stVFrame.u32TimeRef);
#endif
printf("VencChn = %d\n",VencChn);
s32Ret = HI_MPI_VENC_SendFrame(VencChn,g_stVpssFrame,-1);
if(s32Ret != 0)
{
printf("HI_MPI_VENC_SendFrame failed with %#x!\n",s32Ret);
return -1;
}
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");
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;
}
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;
}
}
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;
}
static int VENC_SnapStart(VENC_CHN VencChn,SIZE_S* pstSize,int Width,int Height)
{
HI_S32 s32Ret;
VENC_CHN_ATTR_S stVencChnAttr;
VENC_ATTR_JPEG_S stJpegAttr;
stVencChnAttr.stVeAttr.enType = PT_JPEG;
stJpegAttr.u32MaxPicWidth = 3840;
stJpegAttr.u32MaxPicHeight = 2160;
stJpegAttr.u32PicWidth = 3840/*pstSize->u32Width*/;
stJpegAttr.u32PicHeight = 2160/*pstSize->u32Height*/;
stJpegAttr.u32BufSize = 3840*2160*2/*pstSize->u32Width * pstSize->u32Height * 2*/;
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));
printf("VencChn = %d\n",VencChn);
s32Ret = HI_MPI_VENC_CreateChn(VencChn, &stVencChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_CreateChn [%d] faild with %#x!\n", \
VencChn, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
int main(int argc,char *argv[])
{
VB_CONF_S stVbConf;
VB_BLK VbBlk = VB_INVALID_HANDLE;
VB_POOL hPool = VB_INVALID_POOLID;
SAMPLE_VI_CONFIG_S stViConfig = {0};
HI_U32 u32ViChnCnt = 2;
VPSS_GRP VpssGrp = 0;
VPSS_CHN VpssChn = 0;
VPSS_GRP_ATTR_S stVpssGrpAttr;
VPSS_CHN_ATTR_S stVpssChnAttr;
VPSS_CHN_MODE_S stVpssChnMode;
VPSS_EXT_CHN_ATTR_S stVpssExtChnAttr;
VENC_CHN VencChn;
HI_U32 u32BlkSize;
SIZE_S stSize;
ROTATE_E enRotate = ROTATE_NONE;
HI_S32 i = 0;
HI_S32 s32Ret = HI_SUCCESS;
char ch;
HI_S32 u32Depth = 4;
int width = 3840;
int height = 2160;
u32Size = width*height*3/2;
/* 1.初始化缓冲池 */
memset(&stVbConf, 0, sizeof(VB_CONF_S));
stVbConf.u32MaxPoolCnt = 128;
/*video buffer*/
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, \
g_enPicSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;//1920*1080*3/2
stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 8;
/* 2.初始化mpp系统*/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_JPEG_0;
}
/* 3.设置vi和开启vi通道*/
stViConfig.enViMode = SENSOR_TYPE;
stViConfig.enRotate = ROTATE_NONE;/*旋转角度为0*/
stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO;/*两种格式:PAL/NTSC/AUTO*/
stViConfig.enViChnSet = VI_CHN_SET_NORMAL;/*正常模式下/镜像*/
s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("start vi failed!\n");
goto END_VENC_JPEG_1;
}
/* 4.开启vpss,vi绑定vpss*/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm,g_enPicSize, &stSize);/*获取stSize*/
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_JPEG_1;
}
stVpssGrpAttr.u32MaxW = 1920;
stVpssGrpAttr.u32MaxH = 1080;
stVpssGrpAttr.bIeEn = HI_FALSE;
stVpssGrpAttr.bNrEn = HI_TRUE;
stVpssGrpAttr.bHistEn = HI_FALSE;
stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
stVpssGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT;
stVpssGrpAttr.bDciEn = HI_FALSE;
s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp,&stVpssGrpAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_CreateGrp failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
return -1;
}
#if 1
memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
stVpssChnAttr.bBorderEn = 0;
stVpssChnAttr.bFlip = 0;
stVpssChnAttr.bMirror = 0;
stVpssChnAttr.bSpEn = 0;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = SAMPLE_PIXEL_FORMAT;
stVpssChnMode.u32Width = 1920/*stSize.u32Width*/;
stVpssChnMode.u32Height = 1080/*stSize.u32Height*/;
stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
VPSS_CROP_INFO_S stVpssCropInfo;
stVpssCropInfo.bEnable = HI_TRUE;
stVpssCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR;
stVpssCropInfo.stCropRect.s32X = 0;
stVpssCropInfo.stCropRect.s32Y = 0;
stVpssCropInfo.stCropRect.u32Width = 1920;
stVpssCropInfo.stCropRect.u32Height = 1080;
s32Ret = HI_MPI_VPSS_SetGrpCrop(i, &stVpssCropInfo);
s32Ret = HI_MPI_VPSS_SetDepth(VpssGrp, VpssChn,u32Depth);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetDepth failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &stVpssChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_SetChnMode(VpssGrp, VpssChn,&stVpssChnMode);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp,VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnMode failed with %#x!\n", s32Ret);
return -1;
}
VencChn = 0;
s32Ret = VENC_SnapStart(VencChn,&stSize,4096,4096);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start snap failed!\n");
goto END_VENC_JPEG_5;
}
SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
int count = 0;
printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
while((ch = (char)getchar()) != 'q')
{
g_stVpssFrame = (VIDEO_FRAME_INFO_S*)malloc(sizeof(VIDEO_FRAME_INFO_S));
g_stDestFrame = (VIDEO_FRAME_INFO_S*)malloc(sizeof(VIDEO_FRAME_INFO_S));
memset(g_stVpssFrame,0,sizeof(g_stVpssFrame));
#if 0
hPool = HI_MPI_VB_CreatePool(u32Size,1,NULL);
if (hPool == VB_INVALID_POOLID)
{
SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n");
return -1;
}
#endif
s32Ret = HI_MPI_VPSS_GetChnFrame(VpssGrp,VpssChn,g_stVpssFrame,-1);
if (s32Ret == HI_SUCCESS)
{
#if 1
printf("g_stVpssFrame->stVFrame.u32Width = %d\n",g_stVpssFrame->stVFrame.u32Width);
printf("g_stVpssFrame->stVFrame.u32Height = %d\n",g_stVpssFrame->stVFrame.u32Height);
printf("g_stVpssFrame->stVFrame.u32PhyAddr[0] = %#x\n",g_stVpssFrame->stVFrame.u32PhyAddr[0]);
printf("g_stVpssFrame->stVFrame.u32PhyAddr[1] = %#x\n",g_stVpssFrame->stVFrame.u32PhyAddr[1]);
printf("g_stVpssFrame->stVFrame.pVirAddr[0] = %#x\n",g_stVpssFrame->stVFrame.pVirAddr[0]);
printf("g_stVpssFrame->stVFrame.pVirAddr[1] = %#x\n",g_stVpssFrame->stVFrame.pVirAddr[1]);
printf("g_stVpssFrame->stVFrame.u32Stride[0] = %d\n",g_stVpssFrame->stVFrame.u32Stride[0]);
printf("g_stVpssFrame->stVFrame.u32Stride[1] = %d\n",g_stVpssFrame->stVFrame.u32Stride[1]);
printf("g_stVpssFrame->stVFrame.enPixelFormat = %d\n",g_stVpssFrame->stVFrame.enPixelFormat);
printf("g_stVpssFrame->stVFrame.u64pts = %d\n",g_stVpssFrame->stVFrame.u64pts);
printf("g_stVpssFrame->stVFrame.u32TimeRef = %d\n",g_stVpssFrame->stVFrame.u32TimeRef);
#endif
memcpy(g_stDestFrame,g_stVpssFrame,sizeof(VIDEO_FRAME_INFO_S));
//reform_yuv(&g_stVpssFrame->stVFrame,g_stDestFrame,4);
HI_MPI_VPSS_ReleaseChnFrame(VpssGrp,VpssChn,g_stVpssFrame);
//vgs_main(&g_stVpssFrame->stVFrame,&g_stDestFrame->stVFrame,1920,1080);
}
else
{
SAMPLE_PRT("HI_MPI_VPSS_GetChnFrame failed with %#x\n", s32Ret);
return -1;
}
s32Ret = VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
printf("%s: snap process failed!\n", __FUNCTION__);
continue;
}
//HI_MPI_VPSS_ReleaseChnFrame(VpssGrp,VpssChn,g_stVpssFrame);
printf("snap %d success!\n",count);
count++;
free(g_stVpssFrame);
free(g_stDestFrame);
}
printf("please press ENTER to exit this sample\n");
getchar();
SAMPLE_COMM_VENC_StopGetStream();
#endif
#if 0
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
i = 0;
while ((ch = (char)getchar()) != 'q')
{
s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
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();
/******************************************
step 8: exit process
******************************************/
SAMPLE_COMM_VENC_StopGetStream();
#endif
END_VENC_JPEG_5:
VpssGrp = 0;
VpssChn = 0;
VencChn = 0;
SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
SAMPLE_COMM_VENC_Stop(VencChn);
END_VENC_JPEG_4: //vpss stop
VpssGrp = 0;
VpssChn = 0;
SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_JPEG_3: //vpss stop
SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_JPEG_2: //vpss stop
SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_JPEG_1: //vi stop
SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_JPEG_0: //system exit
SAMPLE_COMM_SYS_Exit();
HI_MPI_VB_DestroyPool(hPool);
hPool = VB_INVALID_POOLID;
return 0;
}
[/code]
以下是源码:
[code]
#include
#include
#include
#include
#include
#include
#include "sample_comm.h"
#define PRE_WIDTH 1920
#define PRE_HEIGHT 1080
#define RES_WIDTH 3840
#define RES_HEIGHT 2160
VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_NTSC;
PIC_SIZE_E g_enPicSize = PIC_HD1080;
VIDEO_FRAME_INFO_S g_stFrame;
static HI_CHAR* pUserPageAddr[2] = {HI_NULL,HI_NULL};
static HI_U32 u32Size = 0;
VIDEO_FRAME_INFO_S* g_stDestFrame;
VIDEO_FRAME_INFO_S* g_stVpssFrame;
static int VENC_SnapProcess(VENC_CHN VencChn)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_STREAM_S stStream;
VENC_CHN_STAT_S stStat;
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
printf("press any key to snap one pic\n");
getchar();
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;
}
#if 0
printf("g_stDestFrame->stVFrame.u32Width = %d\n",g_stDestFrame->stVFrame.u32Width);
printf("g_stDestFrame->stVFrame.u32Height = %d\n",g_stDestFrame->stVFrame.u32Height);
printf("g_stDestFrame->stVFrame.u32PhyAddr[0] = %#x\n",g_stDestFrame->stVFrame.u32PhyAddr[0]);
printf("g_stDestFrame->stVFrame.u32PhyAddr[1] = %#x\n",g_stDestFrame->stVFrame.u32PhyAddr[1]);
printf("g_stDestFrame->stVFrame.pVirAddr[0] = %#x\n",g_stDestFrame->stVFrame.pVirAddr[0]);
printf("g_stDestFrame->stVFrame.pVirAddr[1] = %#x\n",g_stDestFrame->stVFrame.pVirAddr[1]);
printf("g_stDestFrame->stVFrame.u32Stride[0] = %d\n",g_stDestFrame->stVFrame.u32Stride[0]);
printf("g_stDestFrame->stVFrame.u32Stride[1] = %d\n",g_stDestFrame->stVFrame.u32Stride[1]);
printf("g_stDestFrame->stVFrame.enPixelFormat = %d\n",g_stDestFrame->stVFrame.enPixelFormat);
printf("g_stDestFrame->stVFrame.u64pts = %d\n",g_stDestFrame->stVFrame.u64pts);
printf("g_stDestFrame->stVFrame.u32TimeRef = %d\n",g_stDestFrame->stVFrame.u32TimeRef);
#endif
printf("VencChn = %d\n",VencChn);
s32Ret = HI_MPI_VENC_SendFrame(VencChn,g_stVpssFrame,-1);
if(s32Ret != 0)
{
printf("HI_MPI_VENC_SendFrame failed with %#x!\n",s32Ret);
return -1;
}
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");
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;
}
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;
}
}
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;
}
static int VENC_SnapStart(VENC_CHN VencChn,SIZE_S* pstSize,int Width,int Height)
{
HI_S32 s32Ret;
VENC_CHN_ATTR_S stVencChnAttr;
VENC_ATTR_JPEG_S stJpegAttr;
stVencChnAttr.stVeAttr.enType = PT_JPEG;
stJpegAttr.u32MaxPicWidth = 3840;
stJpegAttr.u32MaxPicHeight = 2160;
stJpegAttr.u32PicWidth = 3840/*pstSize->u32Width*/;
stJpegAttr.u32PicHeight = 2160/*pstSize->u32Height*/;
stJpegAttr.u32BufSize = 3840*2160*2/*pstSize->u32Width * pstSize->u32Height * 2*/;
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));
printf("VencChn = %d\n",VencChn);
s32Ret = HI_MPI_VENC_CreateChn(VencChn, &stVencChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_CreateChn [%d] faild with %#x!\n", \
VencChn, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
int main(int argc,char *argv[])
{
VB_CONF_S stVbConf;
VB_BLK VbBlk = VB_INVALID_HANDLE;
VB_POOL hPool = VB_INVALID_POOLID;
SAMPLE_VI_CONFIG_S stViConfig = {0};
HI_U32 u32ViChnCnt = 2;
VPSS_GRP VpssGrp = 0;
VPSS_CHN VpssChn = 0;
VPSS_GRP_ATTR_S stVpssGrpAttr;
VPSS_CHN_ATTR_S stVpssChnAttr;
VPSS_CHN_MODE_S stVpssChnMode;
VPSS_EXT_CHN_ATTR_S stVpssExtChnAttr;
VENC_CHN VencChn;
HI_U32 u32BlkSize;
SIZE_S stSize;
ROTATE_E enRotate = ROTATE_NONE;
HI_S32 i = 0;
HI_S32 s32Ret = HI_SUCCESS;
char ch;
HI_S32 u32Depth = 4;
int width = 3840;
int height = 2160;
u32Size = width*height*3/2;
/* 1.初始化缓冲池 */
memset(&stVbConf, 0, sizeof(VB_CONF_S));
stVbConf.u32MaxPoolCnt = 128;
/*video buffer*/
u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, \
g_enPicSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;//1920*1080*3/2
stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 8;
/* 2.初始化mpp系统*/
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("system init failed with %d!\n", s32Ret);
goto END_VENC_JPEG_0;
}
/* 3.设置vi和开启vi通道*/
stViConfig.enViMode = SENSOR_TYPE;
stViConfig.enRotate = ROTATE_NONE;/*旋转角度为0*/
stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO;/*两种格式:PAL/NTSC/AUTO*/
stViConfig.enViChnSet = VI_CHN_SET_NORMAL;/*正常模式下/镜像*/
s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("start vi failed!\n");
goto END_VENC_JPEG_1;
}
/* 4.开启vpss,vi绑定vpss*/
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm,g_enPicSize, &stSize);/*获取stSize*/
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
goto END_VENC_JPEG_1;
}
stVpssGrpAttr.u32MaxW = 1920;
stVpssGrpAttr.u32MaxH = 1080;
stVpssGrpAttr.bIeEn = HI_FALSE;
stVpssGrpAttr.bNrEn = HI_TRUE;
stVpssGrpAttr.bHistEn = HI_FALSE;
stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
stVpssGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT;
stVpssGrpAttr.bDciEn = HI_FALSE;
s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp,&stVpssGrpAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_CreateGrp failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
return -1;
}
#if 1
memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
stVpssChnAttr.bBorderEn = 0;
stVpssChnAttr.bFlip = 0;
stVpssChnAttr.bMirror = 0;
stVpssChnAttr.bSpEn = 0;
stVpssChnAttr.s32SrcFrameRate = -1;
stVpssChnAttr.s32DstFrameRate = -1;
stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER;
stVpssChnMode.bDouble = HI_FALSE;
stVpssChnMode.enPixelFormat = SAMPLE_PIXEL_FORMAT;
stVpssChnMode.u32Width = 1920/*stSize.u32Width*/;
stVpssChnMode.u32Height = 1080/*stSize.u32Height*/;
stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
VPSS_CROP_INFO_S stVpssCropInfo;
stVpssCropInfo.bEnable = HI_TRUE;
stVpssCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR;
stVpssCropInfo.stCropRect.s32X = 0;
stVpssCropInfo.stCropRect.s32Y = 0;
stVpssCropInfo.stCropRect.u32Width = 1920;
stVpssCropInfo.stCropRect.u32Height = 1080;
s32Ret = HI_MPI_VPSS_SetGrpCrop(i, &stVpssCropInfo);
s32Ret = HI_MPI_VPSS_SetDepth(VpssGrp, VpssChn,u32Depth);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetDepth failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &stVpssChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x!\n", s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_SetChnMode(VpssGrp, VpssChn,&stVpssChnMode);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return -1;
}
s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp,VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnMode failed with %#x!\n", s32Ret);
return -1;
}
VencChn = 0;
s32Ret = VENC_SnapStart(VencChn,&stSize,4096,4096);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start snap failed!\n");
goto END_VENC_JPEG_5;
}
SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
int count = 0;
printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
while((ch = (char)getchar()) != 'q')
{
g_stVpssFrame = (VIDEO_FRAME_INFO_S*)malloc(sizeof(VIDEO_FRAME_INFO_S));
g_stDestFrame = (VIDEO_FRAME_INFO_S*)malloc(sizeof(VIDEO_FRAME_INFO_S));
memset(g_stVpssFrame,0,sizeof(g_stVpssFrame));
#if 0
hPool = HI_MPI_VB_CreatePool(u32Size,1,NULL);
if (hPool == VB_INVALID_POOLID)
{
SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n");
return -1;
}
#endif
s32Ret = HI_MPI_VPSS_GetChnFrame(VpssGrp,VpssChn,g_stVpssFrame,-1);
if (s32Ret == HI_SUCCESS)
{
#if 1
printf("g_stVpssFrame->stVFrame.u32Width = %d\n",g_stVpssFrame->stVFrame.u32Width);
printf("g_stVpssFrame->stVFrame.u32Height = %d\n",g_stVpssFrame->stVFrame.u32Height);
printf("g_stVpssFrame->stVFrame.u32PhyAddr[0] = %#x\n",g_stVpssFrame->stVFrame.u32PhyAddr[0]);
printf("g_stVpssFrame->stVFrame.u32PhyAddr[1] = %#x\n",g_stVpssFrame->stVFrame.u32PhyAddr[1]);
printf("g_stVpssFrame->stVFrame.pVirAddr[0] = %#x\n",g_stVpssFrame->stVFrame.pVirAddr[0]);
printf("g_stVpssFrame->stVFrame.pVirAddr[1] = %#x\n",g_stVpssFrame->stVFrame.pVirAddr[1]);
printf("g_stVpssFrame->stVFrame.u32Stride[0] = %d\n",g_stVpssFrame->stVFrame.u32Stride[0]);
printf("g_stVpssFrame->stVFrame.u32Stride[1] = %d\n",g_stVpssFrame->stVFrame.u32Stride[1]);
printf("g_stVpssFrame->stVFrame.enPixelFormat = %d\n",g_stVpssFrame->stVFrame.enPixelFormat);
printf("g_stVpssFrame->stVFrame.u64pts = %d\n",g_stVpssFrame->stVFrame.u64pts);
printf("g_stVpssFrame->stVFrame.u32TimeRef = %d\n",g_stVpssFrame->stVFrame.u32TimeRef);
#endif
memcpy(g_stDestFrame,g_stVpssFrame,sizeof(VIDEO_FRAME_INFO_S));
//reform_yuv(&g_stVpssFrame->stVFrame,g_stDestFrame,4);
HI_MPI_VPSS_ReleaseChnFrame(VpssGrp,VpssChn,g_stVpssFrame);
//vgs_main(&g_stVpssFrame->stVFrame,&g_stDestFrame->stVFrame,1920,1080);
}
else
{
SAMPLE_PRT("HI_MPI_VPSS_GetChnFrame failed with %#x\n", s32Ret);
return -1;
}
s32Ret = VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
printf("%s: snap process failed!\n", __FUNCTION__);
continue;
}
//HI_MPI_VPSS_ReleaseChnFrame(VpssGrp,VpssChn,g_stVpssFrame);
printf("snap %d success!\n",count);
count++;
free(g_stVpssFrame);
free(g_stDestFrame);
}
printf("please press ENTER to exit this sample\n");
getchar();
SAMPLE_COMM_VENC_StopGetStream();
#endif
#if 0
/******************************************
step 6: stream venc process -- get stream, then save it to file.
******************************************/
i = 0;
while ((ch = (char)getchar()) != 'q')
{
s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn);
if (HI_SUCCESS != s32Ret)
{
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();
/******************************************
step 8: exit process
******************************************/
SAMPLE_COMM_VENC_StopGetStream();
#endif
END_VENC_JPEG_5:
VpssGrp = 0;
VpssChn = 0;
VencChn = 0;
SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
SAMPLE_COMM_VENC_Stop(VencChn);
END_VENC_JPEG_4: //vpss stop
VpssGrp = 0;
VpssChn = 0;
SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_JPEG_3: //vpss stop
SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_JPEG_2: //vpss stop
SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_JPEG_1: //vi stop
SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_JPEG_0: //system exit
SAMPLE_COMM_SYS_Exit();
HI_MPI_VB_DestroyPool(hPool);
hPool = VB_INVALID_POOLID;
return 0;
}
[/code]
我来回答
回答8个
时间排序
认可量排序
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2020-03-17 18:14:42
-
2019-08-30 09:57:03
-
2020-07-23 17:45:58
-
2019-07-12 18:29:38
-
2020-08-06 12:57:35
-
2019-03-13 15:57:54
-
2022-11-02 20:17:05
-
2019-09-01 12:01:05
-
2018-11-19 08:53:29
-
2016-06-23 09:48:58
-
2020-04-07 11:51:15
-
2020-10-29 11:14:15
-
2017-08-10 21:02:27
-
2016-10-26 11:55:21
-
2016-09-10 09:35:34
-
2018-07-24 16:43:24
-
2018-09-21 08:56:19
-
2020-07-22 17:24:15
-
2016-11-18 13:41:42
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
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板子运行自己编码的程序
-
10求HI3519DV500_SDK_V2.0.1.1
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认