using function pointer to make different branch for different rc

This commit is contained in:
ruil2 2014-12-22 12:00:39 +08:00
parent c1752e2818
commit e3bf63db59
6 changed files with 7719 additions and 7688 deletions

View File

@ -252,6 +252,10 @@ typedef void (*PWelsRCPictureDelayJudgeFunc) (void* pCtx, EVideoFrameType eFram
typedef void (*PWelsRCPictureInfoUpdateFunc) (void* pCtx, int32_t iLayerSize); typedef void (*PWelsRCPictureInfoUpdateFunc) (void* pCtx, int32_t iLayerSize);
typedef void (*PWelsRCMBInfoUpdateFunc) (void* pCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* pSlice); typedef void (*PWelsRCMBInfoUpdateFunc) (void* pCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* pSlice);
typedef void (*PWelsRCMBInitFunc) (void* pCtx, SMB* pCurMb, SSlice* pSlice); typedef void (*PWelsRCMBInitFunc) (void* pCtx, SMB* pCurMb, SSlice* pSlice);
typedef bool (*PWelsCheckFrameSkipBasedMaxbrFunc) (void* pCtx, int32_t iSpatialNum, EVideoFrameType eFrameType,
const uint32_t uiTimeStamp);
typedef void (*PWelsUpdateBufferWhenFrameSkippedFunc)(void* pCtx, int32_t iSpatialNum);
typedef void (*PWelsUpdateMaxBrCheckWindowStatusFunc)(void* pCtx, int32_t iSpatialNum, const long long uiTimeStamp);
typedef struct WelsRcFunc_s { typedef struct WelsRcFunc_s {
PWelsRCPictureInitFunc pfWelsRcPictureInit; PWelsRCPictureInitFunc pfWelsRcPictureInit;
@ -259,6 +263,9 @@ PWelsRCPictureDelayJudgeFunc pfWelsRcPicDelayJudge;
PWelsRCPictureInfoUpdateFunc pfWelsRcPictureInfoUpdate; PWelsRCPictureInfoUpdateFunc pfWelsRcPictureInfoUpdate;
PWelsRCMBInitFunc pfWelsRcMbInit; PWelsRCMBInitFunc pfWelsRcMbInit;
PWelsRCMBInfoUpdateFunc pfWelsRcMbInfoUpdate; PWelsRCMBInfoUpdateFunc pfWelsRcMbInfoUpdate;
PWelsCheckFrameSkipBasedMaxbrFunc pfWelsCheckSkipBasedMaxbr;
PWelsUpdateBufferWhenFrameSkippedFunc pfWelsUpdateBufferWhenSkip;
PWelsUpdateMaxBrCheckWindowStatusFunc pfWelsUpdateMaxBrWindowStatus;
} SWelsRcFunc; } SWelsRcFunc;
bool CheckFrameSkipBasedMaxbr (void* pCtx, int32_t iSpatialNum, EVideoFrameType eFrameType, bool CheckFrameSkipBasedMaxbr (void* pCtx, int32_t iSpatialNum, EVideoFrameType eFrameType,

View File

@ -3101,8 +3101,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
// perform csc/denoise/downsample/padding, generate spatial layers // perform csc/denoise/downsample/padding, generate spatial layers
iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic); iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic);
if (pCtx->pSvcParam->bEnableFrameSkip) { if (pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus) {
UpdateMaxBrCheckWindowStatus (pCtx, iSpatialNum, pSrcPic->uiTimeStamp); pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus (pCtx, iSpatialNum, pSrcPic->uiTimeStamp);
} }
if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate) if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
@ -3115,7 +3115,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
eFrameType = DecideFrameType (pCtx, iSpatialNum); eFrameType = DecideFrameType (pCtx, iSpatialNum);
if (eFrameType == videoFrameTypeSkip) { if (eFrameType == videoFrameTypeSkip) {
UpdateBufferWhenFrameSkipped (pCtx, iSpatialNum); if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip)
pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iSpatialNum);
pFbi->eFrameType = eFrameType; pFbi->eFrameType = eFrameType;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "[Rc] Frame timestamp = %lld, skip one frame, continual skipped %d frames", WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "[Rc] Frame timestamp = %lld, skip one frame, continual skipped %d frames",
pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames); pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
@ -3123,11 +3124,15 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
} }
//loop each layer to check if have skip frame when RC and frame skip enable //loop each layer to check if have skip frame when RC and frame skip enable
if (CheckFrameSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType, (uint32_t)pSrcPic->uiTimeStamp)) { if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
pFbi->eFrameType = videoFrameTypeSkip; bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType,
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "[Rc] Frame timestamp = %lld, skip one frame, continual skipped %d frames", (uint32_t)pSrcPic->uiTimeStamp);
pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames); if (bSkip) {
return ENC_RETURN_SUCCESS; pFbi->eFrameType = videoFrameTypeSkip;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "[Rc] Frame timestamp = %lld, skip one frame, continual skipped %d frames",
pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
return ENC_RETURN_SUCCESS;
}
} }
pCtx->iContinualSkipFrames = 0; pCtx->iContinualSkipFrames = 0;

View File

@ -1296,6 +1296,9 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) {
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateDisable; pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateDisable;
pRcf->pfWelsRcMbInit = WelsRcMbInitDisable; pRcf->pfWelsRcMbInit = WelsRcMbInitDisable;
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable; pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;
pRcf->pfWelsCheckSkipBasedMaxbr = NULL;
pRcf->pfWelsUpdateBufferWhenSkip = NULL;
pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
break; break;
case RC_BUFFERBASED_MODE: case RC_BUFFERBASED_MODE:
pRcf->pfWelsRcPictureInit = WelRcPictureInitBufferBasedQp; pRcf->pfWelsRcPictureInit = WelRcPictureInitBufferBasedQp;
@ -1303,6 +1306,10 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) {
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateDisable; pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateDisable;
pRcf->pfWelsRcMbInit = WelsRcMbInitDisable; pRcf->pfWelsRcMbInit = WelsRcMbInitDisable;
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable; pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;
pRcf->pfWelsCheckSkipBasedMaxbr = NULL;
pRcf->pfWelsUpdateBufferWhenSkip = NULL;
pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
break; break;
case RC_BITRATE_MODE: case RC_BITRATE_MODE:
if (pEncCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { if (pEncCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
@ -1311,6 +1318,10 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) {
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc; pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc;
pRcf->pfWelsRcMbInit = WelsRcMbInitScc; pRcf->pfWelsRcMbInit = WelsRcMbInitScc;
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable; pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;
pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
pRcf->pfWelsUpdateBufferWhenSkip = NULL;
pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
InitRcModuleScc (pEncCtx); InitRcModuleScc (pEncCtx);
} else { } else {
@ -1319,6 +1330,10 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) {
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom; pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom;
pRcf->pfWelsRcMbInit = WelsRcMbInitGom; pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom; pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
pRcf->pfWelsUpdateBufferWhenSkip = UpdateBufferWhenFrameSkipped;
pRcf->pfWelsUpdateMaxBrWindowStatus = UpdateMaxBrCheckWindowStatus;
} }
break; break;
case RC_QUALITY_MODE: case RC_QUALITY_MODE:
@ -1328,6 +1343,10 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) {
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom; pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom;
pRcf->pfWelsRcMbInit = WelsRcMbInitGom; pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom; pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
pRcf->pfWelsUpdateBufferWhenSkip = UpdateBufferWhenFrameSkipped;
pRcf->pfWelsUpdateMaxBrWindowStatus = UpdateMaxBrCheckWindowStatus;
break; break;
} }