use the same frame type EVideoFrameType in encoder internal

This commit is contained in:
ruil2 2014-03-19 16:11:06 +08:00
parent fc4cd8b597
commit e74f01ad47
7 changed files with 33 additions and 85 deletions

View File

@ -81,9 +81,9 @@ int32_t InitFunctionPointers (SWelsFuncPtrList* pFuncList, SWelsSvcCodingParam*
/*!
* \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
*/

View File

@ -90,7 +90,7 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx);
* \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);

View File

@ -137,17 +137,6 @@ extern const EVclType g_keTypeMap[32][2];
#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,

View File

@ -213,14 +213,14 @@ int32_t InitFunctionPointers (SWelsFuncPtrList* pFuncList, SWelsSvcCodingParam*
/*!
* \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
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 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType) {
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 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType) {
// 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 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EFrameType keFrameType) {
#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 @@ EFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) {
//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;
}

View File

@ -2538,14 +2538,14 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx) {
/*!
* \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;
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 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
* \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 WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
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 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
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 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
if (eFrameType == WELS_FRAME_TYPE_IDR) {
if (eFrameType == videoFrameTypeIDR) {
++ pCtx->sPSOVector.uiIdrPicId;
//if ( pSvcParam->bEnableSSEI )
@ -3006,9 +3006,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
(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 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
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 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
(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 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
}
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;
}
}

View File

@ -621,7 +621,7 @@ void WelsUpdateRefSyntax (sWelsEncCtx* pCtx, const int32_t iPOC, const int32_t u
}
/*syntax for dec_ref_pic_marking()*/
if (WELS_FRAME_TYPE_IDR == uiFrameType) {
if (videoFrameTypeIDR == uiFrameType) {
pRefPicMark->bNoOutputOfPriorPicsFlag = false;
pRefPicMark->bLongTermRefFlag = pCtx->pSvcParam->bEnableLongTermReference;
} else {

View File

@ -510,25 +510,8 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn
}
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::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn
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 @@ int CWelsH264SVCEncoder::EncodeFrameInternal(const SSourcePicture* pSrcPic, SFr
DumpSrcPicture (pSrcPicList[0]->pData[0]);
#endif // DUMP_SRC_PICTURE
return kiEncoderReturn;
return cmResultSuccess;
}