vencChn = 0;
PAYLOAD_TYPE_E enType = PT_H264;
SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR;
VB_SOURCE_E source = VB_SOURCE_COMMON;
VENC_GOP_MODE_E gopMode = CVI_H26X_GOP_MODE_DEFAULT;
CVI_S32 s32Ret;
VB_CONFIG_S stVbConf;
VENC_GOP_ATTR_S stGopAttr, *pstGopAttr = stGopAttr;
VENC_CHN_ATTR_S stVencChnAttr, *pstVencChnAttr = stVencChnAttr;
VENC_RC_PARAM_S stRcParam, *pstRcParam = stRcParam;
VENC_REF_PARAM_S stRefParam, *pstRefParam = stRefParam;
VENC_CU_PREDICTION_S stCuPrediction, *pstCuPrediction = stCuPrediction;
VENC_FRAMELOST_S stFL, *pstFL = stFL;
VENC_SUPERFRAME_CFG_S stsf, *pstsf = stsf;
VENC_CHN_PARAM_S stChnParam, *pstChnParam = stChnParam;
VENC_RECV_PIC_PARAM_S stRecvParam;
memset( stVbConf, 0, sizeof(VB_CONFIG_S));
stVbConf.u32MaxPoolCnt = 0;
if (initSystemAndVb( stVbConf, _Width, _Height) != CVI_SUCCESS)
assert("encoder init initSystemAndVb() failed" false);
if (setModParam(source) != CVI_SUCCESS)
assert("encoder init setModParam() failed" false);
if (setGopAttr(pstGopAttr, gopMode) != CVI_SUCCESS)
assert("encoder init setGopAttr() failed" false);
if (setChnAttr(pstVencChnAttr, pstGopAttr, _Width, _Height, _Fps, enType, enRcMode) != CVI_SUCCESS)
assert("encoder init setChnAttr() failed" false);
s32Ret = CVI_VENC_CreateChn(vencChn, pstVencChnAttr);
if (s32Ret != CVI_SUCCESS) {
ERR_COUT << "CVI_VENC_CreateChn failed: " << s32Ret << END_COUT;
assert("encoder init CVI_VENC_CreateChn() failed" false);
}
if (enType != PT_JPEG)
{
if (setRcParam(pstRcParam, enType, enRcMode) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setRcParam() failed" false);
}
if (setRefParam(pstRefParam) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setRefParam() failed" false);
}
if (setCuPrediction(pstCuPrediction) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setCuPrediction() failed" false);
}
if (setFrameLost(pstFL) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setFrameLost() failed" false);
}
if (setSuperFrame(pstsf) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setSuperFrame() failed" false);
}
if (enType != PT_MJPEG)
{
if (attachVbPoolIfSourceUser(enType) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init attachVbPoolIfSourceUser() failed" false);
}
}
}
if (enType == PT_H264)
{
if (setH264Entropy() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Entropy() failed" false);
}
if (setH264Trans() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Trans() failed" false);
}
if (setH264Vui() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Vui() failed" false);
}
if (setH264SliceSplit(_Height) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264SliceSplit() failed" false);
}
// if (setH264Dblk() != CVI_SUCCESS) {
// CVI_VENC_DestroyChn(vencChn);
// assert("encoder init setH264Dblk() failed" false);
// }
// if (setH264IntraPred() != CVI_SUCCESS) {
// CVI_VENC_DestroyChn(vencChn);
// assert("encoder init setH264IntraPred() failed" false);
// }
}
if (setChnParam(pstChnParam, _Width, _Height, _Fps) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setChnParam() failed" false);
}
/*
* 编码通道连续接收并编码的帧数。
* 范围:[-1,0)∪(0 ∞]
*/
stRecvParam.s32RecvPicNum = -1;
s32Ret = CVI_VENC_StartRecvFrame(vencChn, stRecvParam);
if (s32Ret != CVI_SUCCESS) {
ERR_COUT << "CVI_VENC_StartRecvFrame failed: " << s32Ret << END_COUT;
assert("encoder init CVI_VENC_StartRecvFrame() failed" false);
}
vencChn = 0;
PAYLOAD_TYPE_E enType = PT_H264;
SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR;
VB_SOURCE_E source = VB_SOURCE_COMMON;
VENC_GOP_MODE_E gopMode = CVI_H26X_GOP_MODE_DEFAULT;
CVI_S32 s32Ret;
VB_CONFIG_S stVbConf;
VENC_GOP_ATTR_S stGopAttr, *pstGopAttr = stGopAttr;
VENC_CHN_ATTR_S stVencChnAttr, *pstVencChnAttr = stVencChnAttr;
VENC_RC_PARAM_S stRcParam, *pstRcParam = stRcParam;
VENC_REF_PARAM_S stRefParam, *pstRefParam = stRefParam;
VENC_CU_PREDICTION_S stCuPrediction, *pstCuPrediction = stCuPrediction;
VENC_FRAMELOST_S stFL, *pstFL = stFL;
VENC_SUPERFRAME_CFG_S stsf, *pstsf = stsf;
VENC_CHN_PARAM_S stChnParam, *pstChnParam = stChnParam;
VENC_RECV_PIC_PARAM_S stRecvParam;
memset( stVbConf, 0, sizeof(VB_CONFIG_S));
stVbConf.u32MaxPoolCnt = 0;
if (initSystemAndVb( stVbConf, _Width, _Height) != CVI_SUCCESS)
assert("encoder init initSystemAndVb() failed" false);
if (setModParam(source) != CVI_SUCCESS)
assert("encoder init setModParam() failed" false);
if (setGopAttr(pstGopAttr, gopMode) != CVI_SUCCESS)
assert("encoder init setGopAttr() failed" false);
if (setChnAttr(pstVencChnAttr, pstGopAttr, _Width, _Height, _Fps, enType, enRcMode) != CVI_SUCCESS)
assert("encoder init setChnAttr() failed" false);
s32Ret = CVI_VENC_CreateChn(vencChn, pstVencChnAttr);
if (s32Ret != CVI_SUCCESS) {
ERR_COUT << "CVI_VENC_CreateChn failed: " << s32Ret << END_COUT;
assert("encoder init CVI_VENC_CreateChn() failed" false);
}
if (enType != PT_JPEG)
{
if (setRcParam(pstRcParam, enType, enRcMode) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setRcParam() failed" false);
}
if (setRefParam(pstRefParam) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setRefParam() failed" false);
}
if (setCuPrediction(pstCuPrediction) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setCuPrediction() failed" false);
}
if (setFrameLost(pstFL) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setFrameLost() failed" false);
}
if (setSuperFrame(pstsf) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setSuperFrame() failed" false);
}
if (enType != PT_MJPEG)
{
if (attachVbPoolIfSourceUser(enType) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init attachVbPoolIfSourceUser() failed" false);
}
}
}
if (enType == PT_H264)
{
if (setH264Entropy() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Entropy() failed" false);
}
if (setH264Trans() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Trans() failed" false);
}
if (setH264Vui() != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264Vui() failed" false);
}
if (setH264SliceSplit(_Height) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setH264SliceSplit() failed" false);
}
// if (setH264Dblk() != CVI_SUCCESS) {
// CVI_VENC_DestroyChn(vencChn);
// assert("encoder init setH264Dblk() failed" false);
// }
// if (setH264IntraPred() != CVI_SUCCESS) {
// CVI_VENC_DestroyChn(vencChn);
// assert("encoder init setH264IntraPred() failed" false);
// }
}
if (setChnParam(pstChnParam, _Width, _Height, _Fps) != CVI_SUCCESS) {
CVI_VENC_DestroyChn(vencChn);
assert("encoder init setChnParam() failed" false);
}
/*
* 编码通道连续接收并编码的帧数。
* 范围:[-1,0)∪(0 ∞]
*/
stRecvParam.s32RecvPicNum = -1;
s32Ret = CVI_VENC_StartRecvFrame(vencChn, stRecvParam);
if (s32Ret != CVI_SUCCESS) {
ERR_COUT << "CVI_VENC_StartRecvFrame failed: " << s32Ret << END_COUT;
assert("encoder init CVI_VENC_StartRecvFrame() failed" false);
}
举报