Merge pull request #1396 from lyao2/rc_trace2

add debug info for RC max bitrate control test
This commit is contained in:
ruil2 2014-09-29 17:09:28 +08:00
commit 6b1630cc90
3 changed files with 45 additions and 27 deletions

View File

@ -181,6 +181,8 @@ int32_t* pCurrentFrameGomSad;
int32_t* pGomCost; int32_t* pGomCost;
int32_t iAverageFrameQp; int32_t iAverageFrameQp;
int32_t iMinFrameQp;
int32_t iMaxFrameQp;
int32_t iNumberMbFrame; int32_t iNumberMbFrame;
int32_t iNumberMbGom; int32_t iNumberMbGom;
int32_t iSliceNum; int32_t iSliceNum;
@ -238,9 +240,9 @@ PWelsRCMBInitFunc pfWelsRcMbInit;
PWelsRCMBInfoUpdateFunc pfWelsRcMbInfoUpdate; PWelsRCMBInfoUpdateFunc pfWelsRcMbInfoUpdate;
} SWelsRcFunc; } SWelsRcFunc;
void RcTraceFrameBits (void* pEncCtx, long long uiTimeStamp);
void WelsRcInitModule (void* pCtx, RC_MODES iRcMode); void WelsRcInitModule (void* pCtx, RC_MODES iRcMode);
void WelsRcFreeMemory (void* pCtx); void WelsRcFreeMemory (void* pCtx);
} }
#endif //RC_H #endif //RC_H

View File

@ -167,6 +167,12 @@ int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) {
pSpatialLayer->iSpatialBitrate); pSpatialLayer->iSpatialBitrate);
return ENC_RETURN_INVALIDINPUT; return ENC_RETURN_INVALIDINPUT;
} }
if (pSpatialLayer->iMaxSpatialBitrate < pSpatialLayer->iSpatialBitrate * 1.1f) {
WelsLog (pLogCtx, WELS_LOG_WARNING,
"MaxSpatialBitrate (%d) should set be larger than 1.1 times of SpatialBitrate (%d)",
pSpatialLayer->iMaxSpatialBitrate, pSpatialLayer->iSpatialBitrate);
// pSpatialLayer->iSpatialBitrate = (int32_t) (pSpatialLayer->iMaxSpatialBitrate/1.1f);
}
} }
if (iTotalBitrate > pCfg->iTargetBitrate) { if (iTotalBitrate > pCfg->iTargetBitrate) {
WelsLog (pLogCtx, WELS_LOG_ERROR, WelsLog (pLogCtx, WELS_LOG_ERROR,
@ -3032,18 +3038,21 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate) if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
++ pCtx->iCodingIndex; ++ pCtx->iCodingIndex;
pFbi->eFrameType = videoFrameTypeSkip; pFbi->eFrameType = videoFrameTypeSkip;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] Frame timestamp = %8d, skip one frame",pSrcPic->uiTimeStamp);
return ENC_RETURN_SUCCESS; return ENC_RETURN_SUCCESS;
} }
eFrameType = DecideFrameType (pCtx, iSpatialNum); eFrameType = DecideFrameType (pCtx, iSpatialNum);
if (eFrameType == videoFrameTypeSkip) { if (eFrameType == videoFrameTypeSkip) {
pFbi->eFrameType = eFrameType; pFbi->eFrameType = eFrameType;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] Frame timestamp = %8d, skip one frame",pSrcPic->uiTimeStamp);
return ENC_RETURN_SUCCESS; return ENC_RETURN_SUCCESS;
} }
//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 (CheckFrameSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType, (uint32_t)pSrcPic->uiTimeStamp)) {
pFbi->eFrameType = videoFrameTypeSkip; pFbi->eFrameType = videoFrameTypeSkip;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] Frame timestamp = %8d, skip one frame",pSrcPic->uiTimeStamp);
return ENC_RETURN_SUCCESS; return ENC_RETURN_SUCCESS;
} }
@ -3427,6 +3436,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
} }
pCtx->pFuncList->pfRc.pfWelsRcPictureInfoUpdate (pCtx, iLayerSize); pCtx->pFuncList->pfRc.pfWelsRcPictureInfoUpdate (pCtx, iLayerSize);
RcTraceFrameBits (pCtx,pSrcPic->uiTimeStamp);
pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc->iAverageFrameQp; pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc->iAverageFrameQp;
//update scc related //update scc related

View File

@ -575,6 +575,8 @@ void RcInitGomParameters (sWelsEncCtx* pEncCtx) {
const int32_t kiGlobalQp = pEncCtx->iGlobalQp; const int32_t kiGlobalQp = pEncCtx->iGlobalQp;
pWelsSvcRc->iAverageFrameQp = 0; pWelsSvcRc->iAverageFrameQp = 0;
pWelsSvcRc->iMinFrameQp = 51;;
pWelsSvcRc->iMaxFrameQp = 0;
for (int32_t i = 0; i < kiSliceNum; ++i) { for (int32_t i = 0; i < kiSliceNum; ++i) {
pSOverRc->iComplexityIndexSlice = 0; pSOverRc->iComplexityIndexSlice = 0;
pSOverRc->iCalculatedQpSlice = kiGlobalQp; pSOverRc->iCalculatedQpSlice = kiGlobalQp;
@ -699,6 +701,7 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
const int32_t kiOutputBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); const int32_t kiOutputBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY);
//condition 1: whole pBuffer fullness //condition 1: whole pBuffer fullness
pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits); pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits);
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip);
//condition 2: VGOP bits constraint //condition 2: VGOP bits constraint
int32_t iVGopBitsPred = 0; int32_t iVGopBitsPred = 0;
for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++) for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++)
@ -712,14 +715,13 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|| (dIncPercent > pWelsSvcRc->iRcVaryPercentage)) { || (dIncPercent > pWelsSvcRc->iRcVaryPercentage)) {
pEncCtx->iSkipFrameFlag = 1; pEncCtx->iSkipFrameFlag = 1;
pWelsSvcRc->iBufferFullnessSkip = pWelsSvcRc->iBufferFullnessSkip - kiOutputBits; pWelsSvcRc->iBufferFullnessSkip = pWelsSvcRc->iBufferFullnessSkip - kiOutputBits;
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "skip one frame"); WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip);
} }
if (pWelsSvcRc->iBufferFullnessSkip < 0) pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0);
pWelsSvcRc->iBufferFullnessSkip = 0;
if (pEncCtx->iSkipFrameFlag == 1) { if (pEncCtx->iSkipFrameFlag == 1) {
pWelsSvcRc->iRemainingBits += WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); pWelsSvcRc->iRemainingBits += kiOutputBits;
pWelsSvcRc->iSkipFrameNum++; pWelsSvcRc->iSkipFrameNum++;
pWelsSvcRc->iSkipFrameInVGop++; pWelsSvcRc->iSkipFrameInVGop++;
} }
@ -739,6 +741,7 @@ void WelsRcFrameDelayJudge (void* pCtx, EVideoFrameType eFrameType, long long ui
pWelsSvcRc->iSkipFrameNum++; pWelsSvcRc->iSkipFrameNum++;
pWelsSvcRc->iSkipFrameInVGop++; pWelsSvcRc->iSkipFrameInVGop++;
pWelsSvcRc->iBufferFullnessSkip -= iSentBits; pWelsSvcRc->iBufferFullnessSkip -= iSentBits;
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip);
pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0); pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0);
} }
} }
@ -759,14 +762,17 @@ void RcVBufferCalculationPadding (sWelsEncCtx* pEncCtx) {
} }
void RcTraceFrameBits (sWelsEncCtx* pEncCtx) { void RcTraceFrameBits (void* pCtx, long long uiTimeStamp) {
sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
"[Rc] encoding_qp%d, qp = %3d, index = %8d, iTid = %1d, used = %8d, target = %8d, remaingbits = %8d", "[Rc] Frame timestamp = %8d, Frame type =%d, encoding_qp%d, average qp = %3d, max qp = %3d, min qp = %3d, index = %8d,\
pEncCtx->uiDependencyId, pWelsSvcRc->iAverageFrameQp, pEncCtx->iFrameIndex, pEncCtx->uiTemporalId, iTid = %1d, used = %8d, bitsperframe = %8d, target = %8d, remaingbits = %8d, skipbuffersize = %8d",
pWelsSvcRc->iFrameDqBits, (uint32_t)uiTimeStamp,pEncCtx->eSliceType, pEncCtx->uiDependencyId, pWelsSvcRc->iAverageFrameQp,pWelsSvcRc->iMaxFrameQp,pWelsSvcRc->iMinFrameQp,
pWelsSvcRc->iTargetBits, pWelsSvcRc->iRemainingBits); pEncCtx->iFrameIndex, pEncCtx->uiTemporalId, pWelsSvcRc->iFrameDqBits,WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY),
pWelsSvcRc->iTargetBits, pWelsSvcRc->iRemainingBits, pWelsSvcRc->iBufferSizeSkip);
} }
void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) { void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) {
@ -891,8 +897,6 @@ void WelsRcPictureInfoUpdateGom (void* pCtx, int32_t iLayerSize) {
} }
pWelsSvcRc->iRemainingBits -= pWelsSvcRc->iFrameDqBits; pWelsSvcRc->iRemainingBits -= pWelsSvcRc->iFrameDqBits;
RcTraceFrameBits (pEncCtx);
if (pEncCtx->pSvcParam->bEnableFrameSkip /*&& if (pEncCtx->pSvcParam->bEnableFrameSkip /*&&
pEncCtx->uiDependencyId == pEncCtx->pSvcParam->iSpatialLayerNum - 1*/) { pEncCtx->uiDependencyId == pEncCtx->pSvcParam->iSpatialLayerNum - 1*/) {
RcVBufferCalculationSkip (pEncCtx); RcVBufferCalculationSkip (pEncCtx);
@ -945,13 +949,15 @@ void WelsRcMbInfoUpdateGom (void* pCtx, SMB* pCurMb, int32_t iCostLuma, SSlice*
SRCSlicing* pSOverRc = &pWelsSvcRc->pSlicingOverRc[iSliceId]; SRCSlicing* pSOverRc = &pWelsSvcRc->pSlicingOverRc[iSliceId];
const int32_t kiComplexityIndex = pSOverRc->iComplexityIndexSlice; const int32_t kiComplexityIndex = pSOverRc->iComplexityIndexSlice;
int32_t cur_mb_bits = BsGetBitsPos (bs) - pSOverRc->iBsPosSlice; int32_t iCurMbBits = BsGetBitsPos (bs) - pSOverRc->iBsPosSlice;
pSOverRc->iFrameBitsSlice += cur_mb_bits; pSOverRc->iFrameBitsSlice += iCurMbBits;
pSOverRc->iGomBitsSlice += cur_mb_bits; pSOverRc->iGomBitsSlice += iCurMbBits;
pWelsSvcRc->pGomCost[kiComplexityIndex] += iCostLuma; pWelsSvcRc->pGomCost[kiComplexityIndex] += iCostLuma;
if (cur_mb_bits > 0) { pWelsSvcRc->iMinFrameQp = WELS_MIN(pWelsSvcRc->iMinFrameQp,pCurMb->uiLumaQp);
pWelsSvcRc->iMaxFrameQp = WELS_MAX(pWelsSvcRc->iMaxFrameQp,pCurMb->uiLumaQp);
if (iCurMbBits > 0) {
pSOverRc->iTotalQpSlice += pCurMb->uiLumaQp; pSOverRc->iTotalQpSlice += pCurMb->uiLumaQp;
pSOverRc->iTotalMbSlice++; pSOverRc->iTotalMbSlice++;
} }