Showing the changes to codec/encoder/core/src/ratectl.cpp (1 of 6 files). Show all
Unified · Split
| @@ -49,13 +49,9 @@ · 48 unmodified lines | ||
| 49 | 49 | |
| 50 | 50 | namespace WelsEnc { |
| 51 | 51 | |
| 52 | −#define COST2BITS_INIT 0.33 | |
| 53 | −#define COMPRESS_RATIO_I_P 3 | |
| 54 | −#define COST2BITS_INIT_P (COST2BITS_INIT/COMPRESS_RATIO_I_P) | |
| 55 | 52 | |
| 56 | − | |
| 57 | −#define VIRTUAL_BUFFER_LOW_TH 0.1 | |
| 58 | −#define VIRTUAL_BUFFER_HIGH_TH 2.5 | |
| 53 | +#define VIRTUAL_BUFFER_LOW_TH 1.2 | |
| 54 | +#define VIRTUAL_BUFFER_HIGH_TH 1.8 | |
| 59 | 55 | |
| 60 | 56 | //#define _TEST_TEMP_RC_ |
| 61 | 57 | #ifdef _TEST_TEMP_RC_ |
| @@ -520,7 +516,7 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) { · 458 unmodified lines | ||
| 520 | 516 | iLumaQp = WELS_DIV_ROUND (iLumaQp * INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp, |
| 521 | 517 | INT_MULTIPLY); |
| 522 | 518 | |
| 523 | − if (!((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) | |
| 519 | + if (! ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) | |
| 524 | 520 | iLumaQp = WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp); |
| 525 | 521 | |
| 526 | 522 | } |
| @@ -562,7 +558,8 @@ void RcDecideTargetBits (sWelsEncCtx* pEncCtx) { · 35 unmodified lines | ||
| 562 | 558 | pWelsSvcRc->iRemainingWeights); |
| 563 | 559 | else //this case should be not hit. needs to more test case to verify this |
| 564 | 560 | pWelsSvcRc->iTargetBits = pWelsSvcRc->iRemainingBits; |
| 565 | − if ((pWelsSvcRc->iTargetBits <= 0) && ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) { | |
| 561 | + if ((pWelsSvcRc->iTargetBits <= 0) && ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) | |
| 562 | + && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) { | |
| 566 | 563 | pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED; |
| 567 | 564 | } |
| 568 | 565 | pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, pTOverRc->iMinBitsTl, pTOverRc->iMaxBitsTl); |
| @@ -689,7 +686,7 @@ void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) { · 120 unmodified lines | ||
| 689 | 686 | |
| 690 | 687 | pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, |
| 691 | 688 | pEncCtx->iGlobalQp - pWelsSvcRc->iQpRangeLowerInFrame, pEncCtx->iGlobalQp + pWelsSvcRc->iQpRangeUpperInFrame); |
| 692 | − if (!((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) | |
| 689 | + if (! ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false))) | |
| 693 | 690 | pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp); |
| 694 | 691 | |
| 695 | 692 | pSOverRc->iGomBitsSlice = 0; |
| @@ -1028,11 +1025,8 @@ void InitRcModuleScc (void* pCtx) { · 332 unmodified lines | ||
| 1028 | 1025 | pWelsSvcRc->iBufferFullnessSkip = 0; |
| 1029 | 1026 | pWelsSvcRc->uiLastTimeStamp = 0; |
| 1030 | 1027 | |
| 1031 | − SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[0]; | |
| 1032 | − double dResoRatio = (pDLayerConfig->iVideoWidth * pDLayerConfig->iVideoHeight / 1024.0) / 768.0 * 0.8; | |
| 1033 | − | |
| 1034 | − pWelsSvcRc->dCost2BitsIntra = COST2BITS_INIT * dResoRatio; | |
| 1035 | − pWelsSvcRc->dAvgCost2Bits = COST2BITS_INIT_P * dResoRatio; | |
| 1028 | + pWelsSvcRc->dCost2BitsIntra = 1; | |
| 1029 | + pWelsSvcRc->dAvgCost2Bits = 1; | |
| 1036 | 1030 | } |
| 1037 | 1031 | void WelRcPictureInitScc (void* pCtx) { |
| 1038 | 1032 | sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx; |
| @@ -1049,13 +1043,13 @@ void WelRcPictureInitScc (void* pCtx) { · 10 unmodified lines | ||
| 1049 | 1043 | int32_t iTargetBits = iBitRate * 2 - pWelsSvcRc->iBufferFullnessSkip; |
| 1050 | 1044 | iTargetBits = WELS_MAX (1, iTargetBits); |
| 1051 | 1045 | double Qstep = iFrameCplx * pWelsSvcRc->dCost2BitsIntra / iTargetBits; |
| 1052 | − int32_t iQp = RcConvertQStep2Qp ((int32_t)Qstep); | |
| 1046 | + int32_t iQp = RcConvertQStep2Qp ((int32_t) (Qstep * INT_MULTIPLY)); | |
| 1053 | 1047 | |
| 1054 | 1048 | pEncCtx->iGlobalQp = WELS_CLIP3 (iQp, MIN_IDR_QP, MAX_IDR_QP); |
| 1055 | 1049 | } else { |
| 1056 | 1050 | int32_t iTargetBits = (int32_t) ((float)iBitRate / pDLayerConfig->fFrameRate); //iBitRate / 10; |
| 1057 | 1051 | double Qstep = iFrameCplx * pWelsSvcRc->dAvgCost2Bits / iTargetBits; |
| 1058 | − int32_t iQp = RcConvertQStep2Qp ((int32_t)Qstep); | |
| 1052 | + int32_t iQp = RcConvertQStep2Qp ((int32_t) (Qstep * INT_MULTIPLY)); | |
| 1059 | 1053 | iDeltaQp = iQp - iBaseQp; |
| 1060 | 1054 | if (pWelsSvcRc->iBufferFullnessSkip > iBitRate) { |
| 1061 | 1055 | if (iDeltaQp > 0) { |
| @@ -1108,7 +1102,7 @@ void WelsRcFrameDelayJudgeScc (void* pCtx, EVideoFrameType eFrameType, long long · 46 unmodified lines | ||
| 1108 | 1102 | iSentBits = WELS_MAX (iSentBits, 0); |
| 1109 | 1103 | |
| 1110 | 1104 | const double dVbufferThRatio = (eFrameType == videoFrameTypeI |
| 1111 | − || eFrameType == videoFrameTypeIDR) ? VIRTUAL_BUFFER_LOW_TH : VIRTUAL_BUFFER_HIGH_TH; | |
| 1105 | + || eFrameType == videoFrameTypeIDR) ? VIRTUAL_BUFFER_HIGH_TH : VIRTUAL_BUFFER_LOW_TH; | |
| 1112 | 1106 | const int32_t iVbufferTh = (int32_t) (iBitRate * dVbufferThRatio + 0.5); |
| 1113 | 1107 | |
| 1114 | 1108 | pWelsSvcRc->iBufferFullnessSkip -= iSentBits; |
| @@ -1118,6 +1112,10 @@ void WelsRcFrameDelayJudgeScc (void* pCtx, EVideoFrameType eFrameType, long long · 3 unmodified lines | ||
| 1118 | 1112 | if (pWelsSvcRc->iBufferFullnessSkip < iVbufferTh) { |
| 1119 | 1113 | pWelsSvcRc->bSkipFlag = false; |
| 1120 | 1114 | } |
| 1115 | + if (pWelsSvcRc->bSkipFlag) { | |
| 1116 | + pWelsSvcRc->iSkipFrameNum++; | |
| 1117 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "SCC iSkipFrameNum = %d,buffer = %d,threadhold = %d,bitrate = %d,timestamp=%d\n", pWelsSvcRc->iSkipFrameNum,pWelsSvcRc->iBufferFullnessSkip,iVbufferTh,pWelsSvcRc->iSkipFrameNum,iBitRate,uiTimeStamp); | |
| 1118 | + } | |
| 1121 | 1119 | pWelsSvcRc->uiLastTimeStamp = uiTimeStamp; |
| 1122 | 1120 | } |
| 1123 | 1121 | |
| @@ -1141,7 +1139,8 @@ void WelsRcPictureInfoUpdateScc (void* pCtx, int32_t iNalSize) { · 17 unmodified lines | ||
| 1141 | 1139 | SVAAFrameInfoExt* pVaa = static_cast<SVAAFrameInfoExt*> (pEncCtx->pVaa); |
| 1142 | 1140 | |
| 1143 | 1141 | double Qstep = RcConvertQp2QStep (pEncCtx->iGlobalQp); |
| 1144 | − double dCost2Bits = (iFrameBits * Qstep) / (double) (pVaa->sComplexityScreenParam.iFrameComplexity + 1.0); | |
| 1142 | + double dCost2Bits = (iFrameBits * Qstep) / (double) (pVaa->sComplexityScreenParam.iFrameComplexity + 1.0) / | |
| 1143 | + INT_MULTIPLY; | |
| 1145 | 1144 | |
| 1146 | 1145 | if (pEncCtx->eSliceType == P_SLICE) { |
| 1147 | 1146 | pWelsSvcRc->dAvgCost2Bits = 0.95 * pWelsSvcRc->dAvgCost2Bits + 0.05 * dCost2Bits; |
| @@ -1185,7 +1184,7 @@ void WelsRcInitModule (void* pCtx, RC_MODES iRcMode) { · 37 unmodified lines | ||
| 1185 | 1184 | pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc; |
| 1186 | 1185 | pRcf->pfWelsRcMbInit = WelsRcMbInitScc; |
| 1187 | 1186 | pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable; |
| 1188 | − InitRcModuleScc(pEncCtx); | |
| 1187 | + InitRcModuleScc (pEncCtx); | |
| 1189 | 1188 | |
| 1190 | 1189 | } else { |
| 1191 | 1190 | pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom; |