/******************************************************************************
Some simple Hisilicon Hi35xx system functions.
Copyright (C), 2010-2011, Hisilicon Tech. Co., Ltd.
******************************************************************************
Modification: 2011-2 Created
******************************************************************************/
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* End of #ifdef __cplusplus */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include <signal.h>
#include "sample_comm.h"
/* g_s32VBSource: 0 to module common vb, 1 to private vb, 2 to user vb
And don't forget to set the value of VBSource file "load35xx" */
HI_S32 g_s32VBSource = 0;
VB_POOL g_ahVbPool[VB_MAX_POOLS] = {[0 ... (VB_MAX_POOLS-1)] = VB_INVALID_POOLID};
#define PRINTF_VDEC_CHN_STATE(Chn, stChnStat) \
do{\
printf(" chn:%2d, bStart:%2d, DecodeFrames:%4d, LeftPics:%3d, LeftBytes:%10d, LeftFrames:%4d, RecvFrames:%6d\n",\
Chn,\
stChnStat.bStartRecvStream,\
stChnStat.u32DecodeStreamFrames,\
stChnStat.u32LeftPics,\
stChnStat.u32LeftStreamBytes,\
stChnStat.u32LeftStreamFrames,\
stChnStat.u32RecvStreamFrames);\
}while(0)
HI_VOID SAMPLE_COMM_VDEC_Sysconf(VB_CONF_S *pstVbConf, SIZE_S *pstSize)
{
memset(pstVbConf, 0, sizeof(VB_CONF_S));
pstVbConf->u32MaxPoolCnt = 1;
pstVbConf->astCommPool[0].u32BlkSize = (pstSize->u32Width * pstSize->u32Height * 4) >> 1;
pstVbConf->astCommPool[0].u32BlkCnt = 3;
}
HI_VOID SAMPLE_COMM_VDEC_ModCommPoolConf(VB_CONF_S *pstModVbConf,
PAYLOAD_TYPE_E enType, SIZE_S *pstSize, HI_S32 s32ChnNum, HI_BOOL bCompress)
{
HI_S32 PicSize, PmvSize;
memset(pstModVbConf, 0, sizeof(VB_CONF_S));
pstModVbConf->u32MaxPoolCnt = 2;
VB_PIC_BLK_SIZE(pstSize->u32Width, pstSize->u32Height, enType, PicSize);
/***********vdec compressed vb needs header****************/
pstModVbConf->astCommPool[0].u32BlkSize = PicSize;
pstModVbConf->astCommPool[0].u32BlkCnt = 5*s32ChnNum;
/* NOTICE:
1. if the VDEC channel is H264 channel and support to decode B frame, then you should allocate PmvBuffer
2. if the VDEC channel is MPEG4 channel, then you should allocate PmvBuffer.
*/
if(PT_H265 == enType)
{
VB_PMV_BLK_SIZE(pstSize->u32Width, pstSize->u32Height, enType, PmvSize);
pstModVbConf->astCommPool[1].u32BlkSize = PmvSize;
pstModVbConf->astCommPool[1].u32BlkCnt = 5*s32ChnNum;
}
}
HI_VOID SAMPLE_COMM_VDEC_ChnAttr(HI_S32 s32ChnNum,
VDEC_CHN_ATTR_S *pstVdecChnAttr, PAYLOAD_TYPE_E enType, SIZE_S *pstSize)
{
HI_S32 i;
for(i=0; i<s32ChnNum; i++)
{
pstVdecChnAttr[i].enType = enType;
pstVdecChnAttr[i].u32BufSize = 3 * pstSize->u32Width * pstSize->u32Height;
pstVdecChnAttr[i].u32Priority = 5;
pstVdecChnAttr[i].u32PicWidth = pstSize->u32Width;
pstVdecChnAttr[i].u32PicHeight = pstSize->u32Height;
if (PT_H264 == enType || PT_MP4VIDEO == enType)
{
pstVdecChnAttr[i].stVdecVideoAttr.enMode=VIDEO_MODE_FRAME;
pstVdecChnAttr[i].stVdecVideoAttr.u32RefFrameNum = 2;
pstVdecChnAttr[i].stVdecVideoAttr.bTemporalMvpEnable = 0;
}
else if (PT_JPEG == enType || PT_MJPEG == enType)
{
pstVdecChnAttr[i].stVdecJpegAttr.enMode = VIDEO_MODE_FRAME;
pstVdecChnAttr[i].stVdecJpegAttr.enJpegFormat = JPG_COLOR_FMT_YCBCR420;
}
else if(PT_H265 == enType)
{
pstVdecChnAttr[i].stVdecVideoAttr.enMode=VIDEO_MODE_STREAM;
pstVdecChnAttr[i].stVdecVideoAttr.u32RefFrameNum = 2;
pstVdecChnAttr[i].stVdecVideoAttr.bTemporalMvpEnable = 1;
}
}
}
HI_VOID SAMPLE_COMM_VDEC_VpssGrpAttr(HI_S32 s32ChnNum, VPSS_GRP_ATTR_S *pstVpssGrpAttr, SIZE_S *pstSize)
{
HI_S32 i;
for(i=0; i<s32ChnNum; i++)
{
pstVpssGrpAttr->enDieMode = VPSS_DIE_MODE_NODIE;
pstVpssGrpAttr->bIeEn = HI_FALSE;
pstVpssGrpAttr->bDciEn = HI_TRUE;
pstVpssGrpAttr->bNrEn = HI_TRUE;
pstVpssGrpAttr->bHistEn = HI_FALSE;
pstVpssGrpAttr->bEsEn = HI_FALSE;
pstVpssGrpAttr->enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
pstVpssGrpAttr->u32MaxW = ALIGN_UP(pstSize->u32Width, 16);
pstVpssGrpAttr->u32MaxH = ALIGN_UP(pstSize->u32Height, 16);
}
}
HI_VOID SAMPLE_COMM_VDEC_VoAttr(HI_S32 s32ChnNum, VO_DEV VoDev ,VO_PUB_ATTR_S *pstVoPubAttr, VO_VIDEO_LAYER_ATTR_S *pstVoLayerAttr)
{
HI_S32 u32Width, u32Height;
/*********** set the pub attr of VO ****************/
if (0 == VoDev)
{
pstVoPubAttr->enIntfSync = VO_OUTPUT_720P50;
pstVoPubAttr->enIntfType = VO_INTF_BT1120 | VO_INTF_VGA;
}
else if (1 == VoDev)
{
pstVoPubAttr->enIntfSync = VO_OUTPUT_720P50;
pstVoPubAttr->enIntfType = VO_INTF_VGA;
}
else if (VoDev>=2 && VoDev <=3)
{
pstVoPubAttr->enIntfSync = VO_OUTPUT_PAL;
pstVoPubAttr->enIntfType = VO_INTF_CVBS;
}
pstVoPubAttr->u32BgColor = VO_BKGRD_BLUE;
/***************** set the layer attr of VO *******************/
if(pstVoPubAttr->enIntfSync == VO_OUTPUT_720P50)
{
u32Width = 1280;
u32Height = 720;
}
else if (pstVoPubAttr->enIntfSync == VO_OUTPUT_PAL)
{
u32Width = 720;
u32Height = 576;
}
pstVoLayerAttr->stDispRect.s32X = 0;
pstVoLayerAttr->stDispRect.s32Y = 0;
pstVoLayerAttr->stDispRect.u32Width = u32Width;
pstVoLayerAttr->stDispRect.u32Height = u32Height;
pstVoLayerAttr->stImageSize.u32Width = u32Width;
pstVoLayerAttr->stImageSize.u32Height = u32Height;
pstVoLayerAttr->bDoubleFrame = HI_FALSE;
pstVoLayerAttr->bClusterMode = HI_FALSE;
pstVoLayerAttr->u32DispFrmRt = 30;
pstVoLayerAttr->enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
}
HI_VOID SAMPLE_COMM_VDEC_ThreadParam(HI_S32 s32ChnNum, VdecThreadParam *pstVdecSend,
VDEC_CHN_ATTR_S *pstVdecChnAttr, char *pStreamFileName)
{
int i;
for(i=0; i<s32ChnNum; i++)
{
sprintf(pstVdecSend[i].cFileName, pStreamFileName, i);
pstVdecSend[i].s32MilliSec = 0;
pstVdecSend[i].s32ChnId = i;
pstVdecSend[i].s32IntervalTime = 1;
pstVdecSend[i].u64PtsInit = 0;
pstVdecSend[i].u64PtsIncrease = 0;
pstVdecSend[i].eCtrlSinal = VDEC_CTRL_START;
pstVdecSend[i].bLoopSend = HI_TRUE;
pstVdecSend[i].bManuSend = HI_FALSE;
pstVdecSend[i].enType = pstVdecChnAttr[i].enType;
pstVdecSend[i].s32MinBufSize = (pstVdecChnAttr[i].u32PicWidth * pstVdecChnAttr[i].u32PicHeight * 3)>>1;
if (PT_H264 == pstVdecChnAttr[i].enType || PT_MP4VIDEO == pstVdecChnAttr[i].enType)
{
pstVdecSend[i].s32StreamMode = pstVdecChnAttr[i].stVdecVideoAttr.enMode;
}
else
{
pstVdecSend[i].s32StreamMode = VIDEO_MODE_FRAME;
}
}
}
HI_VOID Sample_COMM_SetCrop(HI_S32 VpssGrp)
{
VPSS_CROP_INFO_S stCropInfo;
memset(&stCropInfo, 0, sizeof(VPSS_CROP_INFO_S));
stCropInfo.bEnable = HI_TRUE;
stCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR;
stCropInfo.stCropRect.s32X = 160;
stCropInfo.stCropRect.s32Y= 160;
评论2