History

refine scc rc

ruil2 committed 12 years ago

Commit c618cb11 parent a3bdf4f6 files · +8468 −8470Browse files

Showing the changes to codec/encoder/core/src/ratectl.cpp (1 of 6 files). Show all

Unified · Split

codec/encoder/core/src/ratectl.cpp+18−19
@@ -49,13 +49,9 @@ · 48 unmodified lines
49 49
50namespace WelsEnc {50namespace 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 53#define VIRTUAL_BUFFER_LOW_TH 1.2
57#define VIRTUAL_BUFFER_LOW_TH 0.154#define VIRTUAL_BUFFER_HIGH_TH 1.8
58#define VIRTUAL_BUFFER_HIGH_TH 2.5
59 55
60//#define _TEST_TEMP_RC_56//#define _TEST_TEMP_RC_
61#ifdef _TEST_TEMP_RC_57#ifdef _TEST_TEMP_RC_
@@ -520,7 +516,7 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) { · 458 unmodified lines
520 iLumaQp = WELS_DIV_ROUND (iLumaQp * INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp,516 iLumaQp = WELS_DIV_ROUND (iLumaQp * INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp,
521 INT_MULTIPLY);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 iLumaQp = WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);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 pWelsSvcRc->iRemainingWeights);558 pWelsSvcRc->iRemainingWeights);
563 else //this case should be not hit. needs to more test case to verify this559 else //this case should be not hit. needs to more test case to verify this
564 pWelsSvcRc->iTargetBits = pWelsSvcRc->iRemainingBits;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 pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED;563 pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED;
567 }564 }
568 pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, pTOverRc->iMinBitsTl, pTOverRc->iMaxBitsTl);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 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice,687 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice,
691 pEncCtx->iGlobalQp - pWelsSvcRc->iQpRangeLowerInFrame, pEncCtx->iGlobalQp + pWelsSvcRc->iQpRangeUpperInFrame);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 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);690 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
694 691
695 pSOverRc->iGomBitsSlice = 0;692 pSOverRc->iGomBitsSlice = 0;
@@ -1028,11 +1025,8 @@ void InitRcModuleScc (void* pCtx) { · 332 unmodified lines
1028 pWelsSvcRc->iBufferFullnessSkip = 0;1025 pWelsSvcRc->iBufferFullnessSkip = 0;
1029 pWelsSvcRc->uiLastTimeStamp = 0;1026 pWelsSvcRc->uiLastTimeStamp = 0;
1030 1027
1031 SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[0];1028 pWelsSvcRc->dCost2BitsIntra = 1;
1032 double dResoRatio = (pDLayerConfig->iVideoWidth * pDLayerConfig->iVideoHeight / 1024.0) / 768.0 * 0.8;1029 pWelsSvcRc->dAvgCost2Bits = 1;
1033
1034 pWelsSvcRc->dCost2BitsIntra = COST2BITS_INIT * dResoRatio;
1035 pWelsSvcRc->dAvgCost2Bits = COST2BITS_INIT_P * dResoRatio;
1036}1030}
1037void WelRcPictureInitScc (void* pCtx) {1031void WelRcPictureInitScc (void* pCtx) {
1038 sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;1032 sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;
@@ -1049,13 +1043,13 @@ void WelRcPictureInitScc (void* pCtx) { · 10 unmodified lines
1049 int32_t iTargetBits = iBitRate * 2 - pWelsSvcRc->iBufferFullnessSkip;1043 int32_t iTargetBits = iBitRate * 2 - pWelsSvcRc->iBufferFullnessSkip;
1050 iTargetBits = WELS_MAX (1, iTargetBits);1044 iTargetBits = WELS_MAX (1, iTargetBits);
1051 double Qstep = iFrameCplx * pWelsSvcRc->dCost2BitsIntra / iTargetBits;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 pEncCtx->iGlobalQp = WELS_CLIP3 (iQp, MIN_IDR_QP, MAX_IDR_QP);1048 pEncCtx->iGlobalQp = WELS_CLIP3 (iQp, MIN_IDR_QP, MAX_IDR_QP);
1055 } else {1049 } else {
1056 int32_t iTargetBits = (int32_t) ((float)iBitRate / pDLayerConfig->fFrameRate); //iBitRate / 10;1050 int32_t iTargetBits = (int32_t) ((float)iBitRate / pDLayerConfig->fFrameRate); //iBitRate / 10;
1057 double Qstep = iFrameCplx * pWelsSvcRc->dAvgCost2Bits / iTargetBits;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 iDeltaQp = iQp - iBaseQp;1053 iDeltaQp = iQp - iBaseQp;
1060 if (pWelsSvcRc->iBufferFullnessSkip > iBitRate) {1054 if (pWelsSvcRc->iBufferFullnessSkip > iBitRate) {
1061 if (iDeltaQp > 0) {1055 if (iDeltaQp > 0) {
@@ -1108,7 +1102,7 @@ void WelsRcFrameDelayJudgeScc (void* pCtx, EVideoFrameType eFrameType, long long · 46 unmodified lines
1108 iSentBits = WELS_MAX (iSentBits, 0);1102 iSentBits = WELS_MAX (iSentBits, 0);
1109 1103
1110 const double dVbufferThRatio = (eFrameType == videoFrameTypeI1104 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 const int32_t iVbufferTh = (int32_t) (iBitRate * dVbufferThRatio + 0.5);1106 const int32_t iVbufferTh = (int32_t) (iBitRate * dVbufferThRatio + 0.5);
1113 1107
1114 pWelsSvcRc->iBufferFullnessSkip -= iSentBits;1108 pWelsSvcRc->iBufferFullnessSkip -= iSentBits;
@@ -1118,6 +1112,10 @@ void WelsRcFrameDelayJudgeScc (void* pCtx, EVideoFrameType eFrameType, long long · 3 unmodified lines
1118 if (pWelsSvcRc->iBufferFullnessSkip < iVbufferTh) {1112 if (pWelsSvcRc->iBufferFullnessSkip < iVbufferTh) {
1119 pWelsSvcRc->bSkipFlag = false;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 pWelsSvcRc->uiLastTimeStamp = uiTimeStamp;1119 pWelsSvcRc->uiLastTimeStamp = uiTimeStamp;
1122}1120}
1123 1121
@@ -1141,7 +1139,8 @@ void WelsRcPictureInfoUpdateScc (void* pCtx, int32_t iNalSize) { · 17 unmodified lines
1141 SVAAFrameInfoExt* pVaa = static_cast<SVAAFrameInfoExt*> (pEncCtx->pVaa);1139 SVAAFrameInfoExt* pVaa = static_cast<SVAAFrameInfoExt*> (pEncCtx->pVaa);
1142 1140
1143 double Qstep = RcConvertQp2QStep (pEncCtx->iGlobalQp);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 if (pEncCtx->eSliceType == P_SLICE) {1145 if (pEncCtx->eSliceType == P_SLICE) {
1147 pWelsSvcRc->dAvgCost2Bits = 0.95 * pWelsSvcRc->dAvgCost2Bits + 0.05 * dCost2Bits;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 pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc;1184 pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc;
1186 pRcf->pfWelsRcMbInit = WelsRcMbInitScc;1185 pRcf->pfWelsRcMbInit = WelsRcMbInitScc;
1187 pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;1186 pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;
1188 InitRcModuleScc(pEncCtx);1187 InitRcModuleScc (pEncCtx);
1189 1188
1190 } else {1189 } else {
1191 pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom;1190 pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t