ref: 40aa2fed03ea48fafe13ccf3e122b9d92c4fd2e9
parent: fc4cd8b597644da02cc1c166390d9805c94230ef
parent: e74f01ad471f8115601cf1f2acfec9c6d449fee9
author: Licai Guo <[email protected]>
date: Wed Mar 19 12:19:52 EDT 2014
Merge pull request #544 from ruil2/encoder_update use the same frame type EVideoFrameType in encoder internal
--- a/codec/encoder/core/inc/encoder.h
+++ b/codec/encoder/core/inc/encoder.h
@@ -81,9 +81,9 @@
/*!
* \brief initialize frame coding
*/
-void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType);
+void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType);
-EFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum);
+EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum);
/*!
* \brief Dump reconstruction for dependency layer
*/
--- a/codec/encoder/core/inc/extern.h
+++ b/codec/encoder/core/inc/extern.h
@@ -90,7 +90,7 @@
* \param h sWelsEncCtx*, encoder context
* \param pFbi FrameBSInfo*
* \param kpSrcPic Source picture
- * \return EFrameType (WELS_FRAME_TYPE_IDR/WELS_FRAME_TYPE_I/WELS_FRAME_TYPE_P)
+ * \return EFrameType (videoFrameTypeIDR/videoFrameTypeI/videoFrameTypeP)
*/
int32_t WelsEncoderEncodeExt (sWelsEncCtx*, SFrameBSInfo * pFbi, const SSourcePicture* kpSrcPic);
--- a/codec/encoder/core/inc/wels_common_basis.h
+++ b/codec/encoder/core/inc/wels_common_basis.h
@@ -137,17 +137,6 @@
#define IS_VCL_NAL_AVC_BASE(t) ( (t) == NAL_UNIT_CODED_SLICE || (t) == NAL_UNIT_CODED_SLICE_IDR )
#define IS_NEW_INTRODUCED_SVC_NAL(t) ( (t) == NAL_UNIT_PREFIX || (t) == NAL_UNIT_CODED_SLICE_EXT )
-/*
- * Frame types used in internal encoder (logic level based)
- */
-enum EFrameType {
-WELS_FRAME_TYPE_AUTO = 0x0000, /* Let encoder engine choose the proper type, RDO or scene change based */
-WELS_FRAME_TYPE_IDR = 0x0001, /* IDR, I frame with parameter sets */
-WELS_FRAME_TYPE_I = 0x0002, /* I Frame */
-WELS_FRAME_TYPE_P = 0x0003, /* P Frame */
-WELS_FRAME_TYPE_B = 0x0004, /* B Frame */
-WELS_FRAME_TYPE_SKIP = 0x0008
-};
/* Base SSlice Types
* Invalid in case of eSliceType exceeds 9,
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -213,7 +213,7 @@
/*!
* \brief initialize frame coding
*/
-void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType) {
+void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) {
// for bitstream writing
pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
pEncCtx->pOut->iNalIndex = 0; // reset NAL index
@@ -220,7 +220,7 @@
InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize);
- if (keFrameType == WELS_FRAME_TYPE_P) {
+ if (keFrameType == videoFrameTypeP) {
++pEncCtx->iFrameIndex;
if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification
@@ -237,7 +237,7 @@
pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
pEncCtx->eSliceType = P_SLICE;
pEncCtx->eNalPriority = NRI_PRI_HIGH;
- } else if (keFrameType == WELS_FRAME_TYPE_IDR) {
+ } else if (keFrameType == videoFrameTypeIDR) {
pEncCtx->iFrameNum = 0;
pEncCtx->iPOC = 0;
pEncCtx->bEncCurFrmAsIdrFlag = false;
@@ -252,7 +252,7 @@
// reset_ref_list
// rc_init_gop
- } else if (keFrameType == WELS_FRAME_TYPE_I) {
+ } else if (keFrameType == videoFrameTypeI) {
if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification
pEncCtx->iPOC += 2; // for POC type 0
else
@@ -279,9 +279,9 @@
#endif//FRAME_INFO_OUTPUT
}
-EFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) {
+EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) {
SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam;
- EFrameType iFrameType = WELS_FRAME_TYPE_AUTO;
+ EVideoFrameType iFrameType = videoFrameTypeInvalid;
bool bSceneChangeFlag = false;
// perform scene change detection
@@ -297,12 +297,12 @@
//bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum
//pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
- || pEncCtx->bEncCurFrmAsIdrFlag) ? WELS_FRAME_TYPE_IDR : WELS_FRAME_TYPE_P;
+ || pEncCtx->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
- if (WELS_FRAME_TYPE_P == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
+ if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
-- pEncCtx->iSkipFrameFlag;
- iFrameType = WELS_FRAME_TYPE_SKIP;
- } else if (WELS_FRAME_TYPE_IDR == iFrameType) {
+ iFrameType = videoFrameTypeSkip;
+ } else if (videoFrameTypeIDR == iFrameType) {
pEncCtx->iCodingIndex = 0;
}
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2538,7 +2538,7 @@
/*!
* \brief prefetch reference picture after WelsBuildRefList
*/
-static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EFrameType keFrameType) {
+static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) {
SSlice* pSliceBase = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0];
const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
int32_t iIdx = 0;
@@ -2545,7 +2545,7 @@
uint8_t uiRefIdx = -1;
assert (kiSliceCount > 0);
- if (keFrameType != WELS_FRAME_TYPE_IDR) {
+ if (keFrameType != videoFrameTypeIDR) {
assert (pCtx->iNumRef0 > 0);
pCtx->pRefPic = pCtx->pRefList0[0]; // always get item 0 due to reordering done
pCtx->pCurDqLayer->pRefPic = pCtx->pRefPic;
@@ -2859,7 +2859,7 @@
* \pParam pCtx sWelsEncCtx*, encoder context
* \pParam pFbi FrameBSInfo*
* \pParam pSrcPic Source Picture
- * \return EFrameType (WELS_FRAME_TYPE_IDR/WELS_FRAME_TYPE_I/WELS_FRAME_TYPE_P)
+ * \return EFrameType (videoFrameTypeIDR/videoFrameTypeI/videoFrameTypeP)
*/
int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSourcePicture* pSrcPic) {
SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0];
@@ -2880,7 +2880,7 @@
int32_t iNalLen[128] = {0};
int32_t iNalIdxInLayer = 0;
int32_t iCountNal = 0;
- EFrameType eFrameType = WELS_FRAME_TYPE_AUTO;
+ EVideoFrameType eFrameType = videoFrameTypeInvalid;
int32_t iCurWidth = 0;
int32_t iCurHeight = 0;
EWelsNalUnitType eNalType = NAL_UNIT_UNSPEC_0;
@@ -2903,12 +2903,12 @@
iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic);
if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
++ pCtx->iCodingIndex;
- pFbi->eOutputFrameType = WELS_FRAME_TYPE_SKIP;
+ pFbi->eOutputFrameType = videoFrameTypeSkip;
return ENC_RETURN_SUCCESS;
}
eFrameType = DecideFrameType (pCtx, iSpatialNum);
- if (eFrameType == WELS_FRAME_TYPE_SKIP) {
+ if (eFrameType == videoFrameTypeSkip) {
pFbi->eOutputFrameType = eFrameType;
return ENC_RETURN_SUCCESS;
}
@@ -2921,7 +2921,7 @@
pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
- if (eFrameType == WELS_FRAME_TYPE_IDR) {
+ if (eFrameType == videoFrameTypeIDR) {
++ pCtx->sPSOVector.uiIdrPicId;
//if ( pSvcParam->bEnableSSEI )
@@ -3006,9 +3006,9 @@
(pSvcParam->bPrefixNalAddingCtrl ||
(pSvcParam->iSpatialLayerNum > 1)));
- if (eFrameType == WELS_FRAME_TYPE_P) {
+ if (eFrameType == videoFrameTypeP) {
eNalType = bAvcBased ? NAL_UNIT_CODED_SLICE : NAL_UNIT_CODED_SLICE_EXT;
- } else if (eFrameType == WELS_FRAME_TYPE_IDR) {
+ } else if (eFrameType == videoFrameTypeIDR) {
eNalType = bAvcBased ? NAL_UNIT_CODED_SLICE_IDR : NAL_UNIT_CODED_SLICE_EXT;
}
if (iCurTid == 0 || pCtx->eSliceType == I_SLICE)
@@ -3037,7 +3037,7 @@
ForceCodingIDR (pCtx);
WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!\n",
pCtx->iNumRef0);
- pFbi->eOutputFrameType = WELS_FRAME_TYPE_IDR;
+ pFbi->eOutputFrameType = videoFrameTypeIDR;
pCtx->iEncoderError = ENC_RETURN_CORRECTED;
return ENC_RETURN_CORRECTED;
}
@@ -3338,7 +3338,7 @@
(iSpatialIdx == 0) ? "#AU" : " ",
pCtx->iPOC,
pCtx->iFrameNum,
- (uiFrameType == WELS_FRAME_TYPE_I || uiFrameType == WELS_FRAME_TYPE_IDR) ? "I" : "P",
+ (uiFrameType == videoFrameTypeI || uiFrameType == videoFrameTypeIDR) ? "I" : "P",
iCurTid,
iCurDid,
0,
@@ -3452,7 +3452,7 @@
}
if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag
- && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == WELS_FRAME_TYPE_IDR)) {
+ && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) {
pCtx->bLongTermRefFlag[d_idx][iCurTid] = true;
}
}
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -621,7 +621,7 @@
}
/*syntax for dec_ref_pic_marking()*/
- if (WELS_FRAME_TYPE_IDR == uiFrameType) {
+ if (videoFrameTypeIDR == uiFrameType) {
pRefPicMark->bNoOutputOfPriorPicsFlag = false;
pRefPicMark->bLongTermRefFlag = pCtx->pSvcParam->bEnableLongTermReference;
} else {
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -510,25 +510,8 @@
}
const int32_t kiEncoderReturn = EncodeFrameInternal(kpSrcPic, pBsInfo);
-
- switch (kiEncoderReturn) {
- case ENC_RETURN_MEMALLOCERR:
- WelsUninitEncoderExt (&m_pEncContext);
- return cmMallocMemeError;
- case ENC_RETURN_SUCCESS:
- case ENC_RETURN_CORRECTED:
- break;//continue processing
- case ENC_RETURN_UNSUPPORTED_PARA:
- return cmUnsupportedData;
- break;
- case ENC_RETURN_UNEXPECTED:
- return cmUnkonwReason;
- default:
- WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from WelsEncoderEncodeExt()!\n", kiEncoderReturn);
- return cmUnkonwReason;
- }
-
-
+ if(kiEncoderReturn != cmResultSuccess)
+ return kiEncoderReturn;
#ifdef REC_FRAME_COUNT
++ m_uiCountFrameNum;
WelsLog (m_pEncContext, WELS_LOG_INFO,
@@ -544,47 +527,23 @@
int CWelsH264SVCEncoder::EncodeFrameInternal(const SSourcePicture* pSrcPic, SFrameBSInfo* pBsInfo) {
if (!(pSrcPic && m_pEncContext && m_bInitialFlag) ){
- return videoFrameTypeInvalid;
+ return cmInitParaError;
}
- int32_t iFrameTypeReturned = 0;
- int32_t iFrameType = videoFrameTypeInvalid;
const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic);
if(kiEncoderReturn == ENC_RETURN_MEMALLOCERR) {
WelsUninitEncoderExt (&m_pEncContext);
- return videoFrameTypeInvalid;
+ return cmMallocMemeError;
}
else if((kiEncoderReturn != ENC_RETURN_SUCCESS)&&(kiEncoderReturn == ENC_RETURN_CORRECTED)){
WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from EncodeFrameInternal()!\n", kiEncoderReturn);
- return videoFrameTypeInvalid;
+ return cmUnkonwReason;
}
- iFrameTypeReturned = pBsInfo->eOutputFrameType;
- switch (iFrameTypeReturned) {
- case WELS_FRAME_TYPE_P:
- iFrameType = videoFrameTypeP;
- break;
- case WELS_FRAME_TYPE_IDR:
- iFrameType = videoFrameTypeIDR;
- break;
- case WELS_FRAME_TYPE_SKIP:
- iFrameType = videoFrameTypeSkip;
- break;
- case WELS_FRAME_TYPE_I:
- iFrameType = videoFrameTypeI;
- break;
- case WELS_FRAME_TYPE_AUTO:
- case WELS_FRAME_TYPE_B: // not support B pictures
- iFrameType = videoFrameTypeInvalid;
- break;
- default:
- break;
- }
- pBsInfo->eOutputFrameType = iFrameType;
///////////////////for test
#ifdef OUTPUT_BIT_STREAM
- if (iFrameType != videoFrameTypeInvalid && iFrameType != videoFrameTypeSkip) {
+ if (pBsInfo->eOutputFrameType != videoFrameTypeInvalid && pBsInfo->eOutputFrameType != videoFrameTypeSkip) {
SLayerBSInfo* pLayer = NULL;
int32_t i = 0, j = 0, iCurLayerBits = 0, total_bits = 0;
@@ -629,7 +588,7 @@
DumpSrcPicture (pSrcPicList[0]->pData[0]);
#endif // DUMP_SRC_PICTURE
- return kiEncoderReturn;
+ return cmResultSuccess;
}