History

add rc function

ruil2 committed 11 years ago

Commit 5b5cc841 parent 993caea5 files · +228 −96Browse files

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

Unified · Split

codec/encoder/core/src/ratectl.cpp+213−81
@@ -390,7 +390,8 @@ void RcInitIdrQp (sWelsEncCtx* pEncCtx) { · 389 unmodified lines
390390 SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
391391 SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
392392 if (pDLayerParamInternal->fOutputFrameRate > EPSN && pDLayerParam->iVideoWidth && pDLayerParam->iVideoHeight)
393− dBpp = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParamInternal->fOutputFrameRate * pDLayerParam->iVideoWidth *
393+ dBpp = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParamInternal->fOutputFrameRate *
394+ pDLayerParam->iVideoWidth *
394395 pDLayerParam->iVideoHeight);
395396 else
396397 dBpp = 0.1;
@@ -672,7 +673,8 @@ void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) { · 275 unmodified lines
672673
673674 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice,
674675 pEncCtx->iGlobalQp - pWelsSvcRc->iQpRangeLowerInFrame, pEncCtx->iGlobalQp + pWelsSvcRc->iQpRangeUpperInFrame);
675− if (! ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->pSvcParam->bEnableFrameSkip == false)))
676+ if (! (((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) || (pEncCtx->pSvcParam->iRCMode == RC_TIMESTAMP_MODE))
677+ && (pEncCtx->pSvcParam->bEnableFrameSkip == false)))
676678 pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
677679
678680 pSOverRc->iGomBitsSlice = 0;
@@ -705,12 +707,12 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { · 26 unmodified lines
705707 pEncCtx->iSkipFrameFlag = 1;
706708 }
707709 }
708−
709710 void WelsRcFrameDelayJudge (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, long long uiTimeStamp) {
710711 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
711712 SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
712713 SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
713−
714+ if (!pEncCtx->pSvcParam->bEnableFrameSkip)
715+ return;
714716 const int32_t iSentBits = WELS_ROUND (pDLayerParam->iSpatialBitrate / pDLayerParamInternal->fOutputFrameRate);
715717 const int32_t kiOutputMaxBits = WELS_DIV_ROUND (pWelsSvcRc->iMaxBitsPerFrame, INT_MULTIPLY);
716718
@@ -772,22 +774,22 @@ bool CheckFrameSkipBasedMaxbr (sWelsEncCtx* pEncCtx, int32_t iSpatialNum, EVideo · 55 unmodified lines
772774 const uint32_t uiTimeStamp) {
773775 SSpatialPicIndex* pSpatialIndexMap = &pEncCtx->sSpatialIndexMap[0];
774776 bool bSkipMustFlag = false;
775− if (pEncCtx->pSvcParam->bEnableFrameSkip) {
776− if ((RC_QUALITY_MODE == pEncCtx->pSvcParam->iRCMode) || (RC_BITRATE_MODE == pEncCtx->pSvcParam->iRCMode)|| (RC_TIMESTAMP_MODE == pEncCtx->pSvcParam->iRCMode)) {
777−
778− for (int32_t i = 0; i < iSpatialNum; i++) {
779− if (UNSPECIFIED_BIT_RATE == pEncCtx->pSvcParam->sSpatialLayers[i].iMaxSpatialBitrate) {
780− break;
781− }
782− pEncCtx->uiDependencyId = (uint8_t) (pSpatialIndexMap + i)->iDid;
783− pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, eFrameType, uiTimeStamp);
784− if (true == pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].bSkipFlag) {
785− bSkipMustFlag = true;
786− pEncCtx->iContinualSkipFrames++;
787− break;
788− }
789− }
777+ if (!pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge)
778+ return false;
779+ for (int32_t i = 0; i < iSpatialNum; i++) {
780+ if (UNSPECIFIED_BIT_RATE == pEncCtx->pSvcParam->sSpatialLayers[i].iMaxSpatialBitrate) {
781+ break;
790782 }
783+ pEncCtx->uiDependencyId = (uint8_t) (pSpatialIndexMap + i)->iDid;
784+
785+ pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, eFrameType, uiTimeStamp);
786+ if (true == pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].bSkipFlag) {
787+ bSkipMustFlag = true;
788+ pEncCtx->iContinualSkipFrames++;
789+ break;
790+ }
791+
792+
791793 }
792794 return bSkipMustFlag;
793795 }
@@ -815,7 +817,6 @@ void UpdateBufferWhenFrameSkipped (sWelsEncCtx* pEncCtx, int32_t iSpatialNum) { · 21 unmodified lines
815817 }
816818 pEncCtx->iContinualSkipFrames++;
817819 }
818−
819820 void UpdateMaxBrCheckWindowStatus (sWelsEncCtx* pEncCtx, int32_t iSpatialNum, const long long uiTimeStamp) {
820821 SSpatialPicIndex* pSpatialIndexMap = &pEncCtx->sSpatialIndexMap[0];
821822 if (pEncCtx->bCheckWindowStatusRefreshFlag) {
@@ -885,10 +886,9 @@ void RcTraceFrameBits (sWelsEncCtx* pEncCtx, long long uiTimeStamp) { · 63 unmodified lines
885886 pWelsSvcRc->iPredFrameBit = pWelsSvcRc->iFrameDqBits;
886887
887888 WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
888− "[Rc] Frame timestamp = %lld, Frame type =%d, dependency ID = %d, encoding_qp =%d, average qp = %3d, max qp = %3d, min qp = %3d, index = %8d,\
889+ "[Rc] Frame timestamp = %lld, Frame type =%d, encoding_qp = %d, average qp = %3d, max qp = %3d, min qp = %3d, index = %8d,\
889890 iTid = %1d, used = %8d, bitsperframe = %8d, target = %8d, remaingbits = %8d, skipbuffersize = %8d",
890− uiTimeStamp, pEncCtx->eSliceType, pEncCtx->uiDependencyId, pEncCtx->iGlobalQp, pWelsSvcRc->iAverageFrameQp,
891− pWelsSvcRc->iMaxFrameQp,
891+ uiTimeStamp, pEncCtx->eSliceType, pEncCtx->iGlobalQp, pWelsSvcRc->iAverageFrameQp, pWelsSvcRc->iMaxFrameQp,
892892 pWelsSvcRc->iMinFrameQp,
893893 pEncCtx->iFrameIndex, pEncCtx->uiTemporalId, pWelsSvcRc->iFrameDqBits, WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame,
894894 INT_MULTIPLY),
@@ -933,6 +933,8 @@ void RcUpdateIntraComplexity (sWelsEncCtx* pEncCtx) { · 38 unmodified lines
933933 pWelsSvcRc->iIdrNum++;
934934 if (pWelsSvcRc->iIdrNum > 255)
935935 pWelsSvcRc->iIdrNum = 255;
936+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "RcUpdateIntraComplexity iFrameDqBits = %d,iQStep= %d,iIntraCmplx = %d",
937+ pWelsSvcRc->iFrameDqBits, pWelsSvcRc->iQStep, pWelsSvcRc->iIntraComplexity);
936938 }
937939
938940 void RcUpdateFrameComplexity (sWelsEncCtx* pEncCtx) {
@@ -956,6 +958,9 @@ void RcUpdateFrameComplexity (sWelsEncCtx* pEncCtx) { · 17 unmodified lines
956958 pTOverRc->iPFrameNum++;
957959 if (pTOverRc->iPFrameNum > 255)
958960 pTOverRc->iPFrameNum = 255;
961+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
962+ "RcUpdateFrameComplexity iFrameDqBits = %d,iQStep= %d,pTOverRc->iLinearCmplx = %lld", pWelsSvcRc->iFrameDqBits,
963+ pWelsSvcRc->iQStep, pTOverRc->iLinearCmplx);
959964 }
960965
961966 int32_t RcCalculateCascadingQp (struct TagWelsEncCtx* pEncCtx, int32_t iQp) {
@@ -971,7 +976,7 @@ int32_t RcCalculateCascadingQp (struct TagWelsEncCtx* pEncCtx, int32_t iQp) { · 9 unmodified lines
971976 return iTemporalQp;
972977 }
973978
974−void WelsRcPictureInitGom (sWelsEncCtx* pEncCtx) {
979+void WelsRcPictureInitGom (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
975980 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
976981
977982 if (pEncCtx->eSliceType == I_SLICE) {
@@ -1001,8 +1006,6 @@ void WelsRcPictureInitGom (sWelsEncCtx* pEncCtx) { · 23 unmodified lines
10011006
10021007 }
10031008
1004−
1005−
10061009 void WelsRcPictureInfoUpdateGom (sWelsEncCtx* pEncCtx, int32_t iLayerSize) {
10071010 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
10081011 int32_t iCodedBits = (iLayerSize << 3);
@@ -1074,7 +1077,7 @@ void WelsRcMbInfoUpdateGom (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iCostLuma · 65 unmodified lines
10741077 }
10751078 }
10761079
1077−void WelsRcPictureInitDisable (sWelsEncCtx* pEncCtx) {
1080+void WelsRcPictureInitDisable (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
10781081 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
10791082 SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
10801083 const int32_t kiQp = pDLayerParam->iDLayerQp;
@@ -1114,7 +1117,7 @@ void WelsRcMbInitDisable (sWelsEncCtx* pEncCtx, SMB* pCurMb, SSlice* pSlice) { · 33 unmodified lines
11141117 void WelsRcMbInfoUpdateDisable (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* pSlice) {
11151118 }
11161119
1117−void WelRcPictureInitBufferBasedQp (sWelsEncCtx* pEncCtx) {
1120+void WelRcPictureInitBufferBasedQp (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
11181121 SVAAFrameInfo* pVaa = static_cast<SVAAFrameInfo*> (pEncCtx->pVaa);
11191122
11201123 int32_t iMinQp = MIN_SCREEN_QP;
@@ -1130,18 +1133,7 @@ void WelRcPictureInitBufferBasedQp (sWelsEncCtx* pEncCtx) { · 9 unmodified lines
11301133 pEncCtx->iGlobalQp += 2;
11311134 pEncCtx->iGlobalQp = WELS_CLIP3 (pEncCtx->iGlobalQp, iMinQp, MAX_SCREEN_QP);
11321135 }
1133−
1134−void InitRcModuleScc (sWelsEncCtx* pEncCtx) {
1135− SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
1136− pWelsSvcRc->iBaseQp = 30;
1137−
1138− pWelsSvcRc->iBufferFullnessSkip = 0;
1139− pWelsSvcRc->uiLastTimeStamp = 0;
1140−
1141− pWelsSvcRc->iCost2BitsIntra = INT_MULTIPLY;
1142− pWelsSvcRc->iAvgCost2Bits = INT_MULTIPLY;
1143−}
1144−void WelRcPictureInitScc (sWelsEncCtx* pEncCtx) {
1136+void WelRcPictureInitScc (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
11451137 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
11461138 SVAAFrameInfoExt* pVaa = static_cast<SVAAFrameInfoExt*> (pEncCtx->pVaa);
11471139 SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
@@ -1199,40 +1191,9 @@ void WelRcPictureInitScc (sWelsEncCtx* pEncCtx) { · 51 unmodified lines
11991191 }
12001192 pWelsSvcRc->iAverageFrameQp = pEncCtx->iGlobalQp;
12011193 WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, "WelRcPictureInitScc iLumaQp = %d\n", pEncCtx->iGlobalQp);
1202−
1203−}
1204−void WelsRcFrameDelayJudgeScc (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, long long uiTimeStamp) {
1205− SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[0];
1206− SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
1207−
1208− if (pDLayerConfig->iSpatialBitrate > pDLayerConfig->iMaxSpatialBitrate)
1209− pDLayerConfig->iSpatialBitrate = pDLayerConfig->iMaxSpatialBitrate;
1210−
1211− int32_t iBitRate = pDLayerConfig->iSpatialBitrate;
1212− int32_t iEncTimeInv = (pWelsSvcRc->uiLastTimeStamp == 0) ? 0 : (int32_t) (uiTimeStamp - pWelsSvcRc->uiLastTimeStamp);
1213− int32_t iSentBits = (int32_t) ((double)iBitRate * iEncTimeInv * (1.0E-3) + 0.5);
1214− iSentBits = WELS_MAX (iSentBits, 0);
1215−
1216− const int32_t iVbufferThRatio = (eFrameType == videoFrameTypeI
1217− || eFrameType == videoFrameTypeIDR) ? VIRTUAL_BUFFER_HIGH_TH : VIRTUAL_BUFFER_LOW_TH;
1218− const int32_t iVbufferTh = WELS_DIV_ROUND ((((int64_t)iBitRate) * iVbufferThRatio), INT_MULTIPLY);
1219−
1220− pWelsSvcRc->iBufferFullnessSkip -= iSentBits;
1221− pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (0, pWelsSvcRc->iBufferFullnessSkip);
1222−
1223− pWelsSvcRc->bSkipFlag = true;
1224− if (pWelsSvcRc->iBufferFullnessSkip < iVbufferTh) {
1225− pWelsSvcRc->bSkipFlag = false;
1226− }
1227− if (pWelsSvcRc->bSkipFlag) {
1228− pWelsSvcRc->iSkipFrameNum++;
1229− WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO,
1230− "SCC iSkipFrameNum = %d,buffer = %d,threadhold = %d,bitrate = %d,timestamp=%lld\n", pWelsSvcRc->iSkipFrameNum,
1231− pWelsSvcRc->iBufferFullnessSkip, iVbufferTh, iBitRate, uiTimeStamp);
1232− }
12331194 pWelsSvcRc->uiLastTimeStamp = uiTimeStamp;
1234−}
12351195
1196+}
12361197 void WelsRcDropFrameUpdate (sWelsEncCtx* pEncCtx, uint32_t iDropSize) {
12371198 SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[0];
12381199
@@ -1243,7 +1204,7 @@ void WelsRcDropFrameUpdate (sWelsEncCtx* pEncCtx, uint32_t iDropSize) { · 4 unmodified lines
12431204 }
12441205
12451206 void WelsRcPictureInfoUpdateScc (sWelsEncCtx* pEncCtx, int32_t iNalSize) {
1246− SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[0];
1207+ SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
12471208 int32_t iFrameBits = (iNalSize << 3);
12481209 pWelsSvcRc->iBufferFullnessSkip += iFrameBits;
12491210
@@ -1266,9 +1227,178 @@ void WelsRcMbInitScc (sWelsEncCtx* pEncCtx, SMB* pCurMb, SSlice* pSlice) { · 16 unmodified lines
12661227 pCurMb->uiChromaQp = g_kuiChromaQpTable[WELS_CLIP3 (pCurMb->uiLumaQp + pEncCtx->pPps->uiChromaQpIndexOffset, 0, 51)];
12671228 }
12681229
1230+void InitRcModuleTimeStamp (sWelsEncCtx* pEncCtx) {
1231+ SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
1232+ pWelsSvcRc->iBaseQp = 30;
1233+
1234+ pWelsSvcRc->iBufferFullnessSkip = 0;
1235+ pWelsSvcRc->uiLastTimeStamp = 0;
1236+
1237+ pWelsSvcRc->iCost2BitsIntra = INT_MULTIPLY;
1238+ pWelsSvcRc->iAvgCost2Bits = INT_MULTIPLY;
1239+ pWelsSvcRc->iSkipBufferRatio = SKIP_RATIO;
1240+}
1241+void WelsRcFrameDelayJudgeTimeStamp (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, long long uiTimeStamp) {
1242+ SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
1243+ SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
1244+
1245+ if (pDLayerConfig->iSpatialBitrate > pDLayerConfig->iMaxSpatialBitrate)
1246+ pDLayerConfig->iSpatialBitrate = pDLayerConfig->iMaxSpatialBitrate;
1247+
1248+ int32_t iBitRate = pDLayerConfig->iSpatialBitrate;
1249+ int32_t iEncTimeInv = (pWelsSvcRc->uiLastTimeStamp == 0) ? 0 : (int32_t) (uiTimeStamp - pWelsSvcRc->uiLastTimeStamp);
1250+ int32_t iSentBits = (int32_t) ((double)iBitRate * iEncTimeInv * (1.0E-3) + 0.5);
1251+ iSentBits = WELS_MAX (iSentBits, 0);
1252+
1253+ //When bitrate is changed, pBuffer size should be updated
1254+ pWelsSvcRc->iBufferSizeSkip = WELS_DIV_ROUND (pDLayerConfig->iSpatialBitrate * pWelsSvcRc->iSkipBufferRatio,
1255+ INT_MULTIPLY);
1256+ pWelsSvcRc->iBufferSizePadding = WELS_DIV_ROUND (pDLayerConfig->iSpatialBitrate * PADDING_BUFFER_RATIO, INT_MULTIPLY);
1257+
1258+ pWelsSvcRc->iBufferFullnessSkip -= iSentBits;
1259+ pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (0, pWelsSvcRc->iBufferFullnessSkip);
1260+
1261+ if (pEncCtx->pSvcParam->bEnableFrameSkip) {
1262+ pWelsSvcRc->bSkipFlag = true;
1263+ if (pWelsSvcRc->iBufferFullnessSkip < pWelsSvcRc->iBufferSizeSkip) {
1264+ pWelsSvcRc->bSkipFlag = false;
1265+ }
1266+ if (pWelsSvcRc->bSkipFlag) {
1267+ pWelsSvcRc->iSkipFrameNum++;
1268+ pWelsSvcRc->uiLastTimeStamp = uiTimeStamp;
1269+ }
1270+ }
1271+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
1272+ "WelsRcFrameDelayJudgeTimeStamp iSkipFrameNum = %d,buffer = %d,threadhold = %d,bitrate = %d,iSentBits = %d,lasttimestamp = %lld,timestamp=%lld\n",
1273+ pWelsSvcRc->iSkipFrameNum, pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferSizeSkip, iBitRate, iSentBits,
1274+ pWelsSvcRc->uiLastTimeStamp, uiTimeStamp);
1275+}
1276+void WelsRcPictureInitGomTimeStamp (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
1277+ SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
1278+ SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId];
1279+ int32_t iLumaQp = pWelsSvcRc->iLastCalculatedQScale;
1280+ //decide one frame bits allocated
1281+ if (pEncCtx->eSliceType == I_SLICE) {
1282+ if (0 == pWelsSvcRc->iIdrNum) { //iIdrNum == 0 means encoder has been initialed
1283+ RcInitRefreshParameter (pEncCtx);
1284+ double dBpp = 0.05;
1285+ if ((pDLayerParam->fFrameRate > EPSN) && (pDLayerParam->iVideoWidth && pDLayerParam->iVideoHeight))
1286+ dBpp = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParam->fFrameRate * pDLayerParam->iVideoWidth *
1287+ pDLayerParam->iVideoHeight);
1288+ pWelsSvcRc->iInitialQp = 50 - dBpp * 10 * 4;
1289+ pWelsSvcRc->iInitialQp = WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP);
1290+
1291+ iLumaQp = pWelsSvcRc->iInitialQp;
1292+ pWelsSvcRc->iTargetBits = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParam->fFrameRate) *
1293+ IDR_BITRATE_RATIO;
1294+
1295+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
1296+ "[Rc] First IDR iSpatialBitrate = %d,iBufferFullnessSkip = %d,iTargetBits= %d,dBpp = %f,initQp = %d",
1297+ pDLayerParam->iSpatialBitrate, pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iTargetBits, dBpp,
1298+ pWelsSvcRc->iInitialQp);
1299+
1300+ } else {
1301+
1302+ int32_t iMaxTh = pWelsSvcRc->iBufferSizeSkip - pWelsSvcRc->iBufferFullnessSkip;
1303+ int32_t iMinTh = iMaxTh / 2;
1304+ pWelsSvcRc->iTargetBits = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParam->fFrameRate) *
1305+ IDR_BITRATE_RATIO;
1306+ if (iMaxTh > 0) {
1307+ pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, iMinTh, iMaxTh);
1308+
1309+ pWelsSvcRc->iQStep = WELS_DIV_ROUND ((((int64_t)pWelsSvcRc->iIntraComplexity) *
1310+ pWelsSvcRc->iCost2BitsIntra), pWelsSvcRc->iTargetBits);
1311+ iLumaQp = RcConvertQStep2Qp (pWelsSvcRc->iQStep);
1312+
1313+ iLumaQp = WELS_CLIP3 (iLumaQp, pEncCtx->iGlobalQp - DELTA_QP_BGD_THD, pEncCtx->iGlobalQp + DELTA_QP_BGD_THD);
1314+
1315+ } else {
1316+ iLumaQp = pWelsSvcRc->iLastCalculatedQScale + DELTA_QP_BGD_THD;
1317+ }
1318+ iLumaQp = WELS_CLIP3 (iLumaQp, MIN_IDR_QP, MAX_IDR_QP);
1319+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
1320+ "[Rc]I iLumaQp = %d,iQStep = %d,iTargetBits = %d,iBufferFullnessSkip =%d,iMaxTh=%d,iMinTh = %d,iFrameComplexity= %d",
1321+ iLumaQp, pWelsSvcRc->iQStep, pWelsSvcRc->iTargetBits, pWelsSvcRc->iBufferFullnessSkip, iMaxTh, iMinTh,
1322+ pWelsSvcRc->iIntraComplexity);
1323+
1324+ }
1325+
1326+ } else {
1327+ int32_t iTl = pEncCtx->uiTemporalId;
1328+ SRCTemporal* pTOverRc = &pWelsSvcRc->pTemporalOverRc[iTl];
1329+ int32_t iMaxTh = pWelsSvcRc->iBufferSizeSkip - pWelsSvcRc->iBufferFullnessSkip;
1330+ int32_t iMinTh = iMaxTh / (iTl + 2);
1331+
1332+ SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
1333+ const int32_t kiGopSize = (1 << pDLayerParamInternal->iDecompositionStages);
1334+ int32_t iAverageFrameSize = (double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParam->fFrameRate);
1335+ const int32_t kiGopBits = iAverageFrameSize * kiGopSize;
1336+ int64_t iCmplxRatio = WELS_DIV_ROUND64 (pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity * INT_MULTIPLY,
1337+ pTOverRc->iFrameCmplxMean);
1338+ iCmplxRatio = WELS_CLIP3 (iCmplxRatio, INT_MULTIPLY - FRAME_CMPLX_RATIO_RANGE, INT_MULTIPLY + FRAME_CMPLX_RATIO_RANGE);
1339+
1340+
1341+ pWelsSvcRc->iTargetBits = WELS_DIV_ROUND (pTOverRc->iTlayerWeight * kiGopBits, INT_MULTIPLY * 10 * 2);
1342+ if (iMaxTh > 0) {
1343+ pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, iMinTh, iMaxTh);
1344+ if (0 == pTOverRc->iPFrameNum)
1345+ iLumaQp = pWelsSvcRc->iInitialQp;
1346+ else {
1347+
1348+ pWelsSvcRc->iQStep = WELS_DIV_ROUND ((pTOverRc->iLinearCmplx * iCmplxRatio), (pWelsSvcRc->iTargetBits * INT_MULTIPLY));
1349+ iLumaQp = RcConvertQStep2Qp (pWelsSvcRc->iQStep);
1350+ iLumaQp = WELS_CLIP3 (iLumaQp, pEncCtx->iGlobalQp - DELTA_QP_BGD_THD, pEncCtx->iGlobalQp + DELTA_QP_BGD_THD);
1351+ }
1352+ } else {
1353+ iLumaQp = pWelsSvcRc->iLastCalculatedQScale + DELTA_QP_BGD_THD;
1354+ }
1355+
1356+ iLumaQp = WELS_CLIP3 (iLumaQp, GOM_MIN_QP_MODE, GOM_MAX_QP_MODE);
1357+
1358+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
1359+ "[Rc]P iTl = %d,iLumaQp = %d,iQStep = %d,iTargetBits = %d,iBufferFullnessSkip =%d,iMaxTh=%d,iMinTh = %d,iFrameComplexity= %d,iCmplxRatio=%lld",
1360+ iTl, iLumaQp, pWelsSvcRc->iQStep, pWelsSvcRc->iTargetBits, pWelsSvcRc->iBufferFullnessSkip, iMaxTh, iMinTh,
1361+ pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity, iCmplxRatio);
1362+ }
1363+
1364+ pWelsSvcRc->iQStep = RcConvertQp2QStep (iLumaQp);
1365+ pWelsSvcRc->iLastCalculatedQScale = iLumaQp;
1366+ pEncCtx->iGlobalQp = iLumaQp;
1367+
1368+ RcInitSliceInformation (pEncCtx);
1369+ RcInitGomParameters (pEncCtx);
1370+ float fInstantFps = (uiTimeStamp - pWelsSvcRc->uiLastTimeStamp) > 0 ? (1000.0 / (uiTimeStamp -
1371+ pWelsSvcRc->uiLastTimeStamp)) : 0;
1372+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
1373+ "[Rc]pEncCtx->iGlobalQp= %d,uiTimeStamp = %lld,uiLastTimeStamp = %lld,InstantFps = %f,settingFps = %f",
1374+ pEncCtx->iGlobalQp, uiTimeStamp, pWelsSvcRc->uiLastTimeStamp,
1375+ fInstantFps, pDLayerParam->fFrameRate);
1376+ pWelsSvcRc->uiLastTimeStamp = uiTimeStamp;
1377+
1378+}
1379+
1380+void WelsRcPictureInfoUpdateGomTimeStamp (sWelsEncCtx* pEncCtx, int32_t iLayerSize) {
1381+ SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
1382+ int32_t iCodedBits = (iLayerSize << 3);
1383+
1384+ RcUpdatePictureQpBits (pEncCtx, iCodedBits);
1385+ if (pEncCtx->eSliceType == P_SLICE) {
1386+ RcUpdateFrameComplexity (pEncCtx);
1387+ } else {
1388+ RcUpdateIntraComplexity (pEncCtx);
1389+ }
1390+
1391+ pWelsSvcRc->iRemainingBits -= pWelsSvcRc->iFrameDqBits;
1392+ //condition 1: whole pBuffer fullness
1393+ pWelsSvcRc->iBufferFullnessSkip += pWelsSvcRc->iFrameDqBits;
1394+
1395+
1396+ if (pEncCtx->pSvcParam->iPaddingFlag)
1397+ RcVBufferCalculationPadding (pEncCtx);
1398+ pWelsSvcRc->iFrameCodedInVGop++;
1399+}
12691400 void WelsRcInitModule (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) {
12701401 SWelsRcFunc* pRcf = &pEncCtx->pFuncList->pfRc;
1271−
12721402 switch (iRcMode) {
12731403 case RC_OFF_MODE:
12741404 pRcf->pfWelsRcPictureInit = WelsRcPictureInitDisable;
@@ -1303,19 +1433,21 @@ void WelsRcInitModule (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) { · 28 unmodified lines
13031433 case RC_TIMESTAMP_MODE:
13041434 if (pEncCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
13051435 pRcf->pfWelsRcPictureInit = WelRcPictureInitScc;
1306− pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudgeScc;
13071436 pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateScc;
13081437 pRcf->pfWelsRcMbInit = WelsRcMbInitScc;
13091438 pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateDisable;
1310− pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
1311− pRcf->pfWelsUpdateBufferWhenSkip = NULL;
1312− pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
1313−
1314− InitRcModuleScc (pEncCtx);
13151439
13161440 } else {
1317− WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "to be done in the future");
1441+ pRcf->pfWelsRcPictureInit = WelsRcPictureInitGomTimeStamp;
1442+ pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGomTimeStamp;
1443+ pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
1444+ pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
13181445 }
1446+ pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudgeTimeStamp;
1447+ pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
1448+ pRcf->pfWelsUpdateBufferWhenSkip = NULL;
1449+ pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
1450+ InitRcModuleTimeStamp (pEncCtx);
13191451 break;
13201452 case RC_QUALITY_MODE:
13211453 default:

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