Showing the changes to codec/encoder/core/src/ratectl.cpp (1 of 3 files). Show all
Unified · Split
| @@ -575,6 +575,8 @@ void RcInitGomParameters (sWelsEncCtx* pEncCtx) { · 574 unmodified lines | ||
| 575 | 575 | const int32_t kiGlobalQp = pEncCtx->iGlobalQp; |
| 576 | 576 | |
| 577 | 577 | pWelsSvcRc->iAverageFrameQp = 0; |
| 578 | + pWelsSvcRc->iMinFrameQp = 51;; | |
| 579 | + pWelsSvcRc->iMaxFrameQp = 0; | |
| 578 | 580 | for (int32_t i = 0; i < kiSliceNum; ++i) { |
| 579 | 581 | pSOverRc->iComplexityIndexSlice = 0; |
| 580 | 582 | pSOverRc->iCalculatedQpSlice = kiGlobalQp; |
| @@ -699,6 +701,7 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { · 118 unmodified lines | ||
| 699 | 701 | const int32_t kiOutputBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); |
| 700 | 702 | //condition 1: whole pBuffer fullness |
| 701 | 703 | pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits); |
| 704 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip); | |
| 702 | 705 | //condition 2: VGOP bits constraint |
| 703 | 706 | int32_t iVGopBitsPred = 0; |
| 704 | 707 | for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++) |
| @@ -712,14 +715,13 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { · 7 unmodified lines | ||
| 712 | 715 | || (dIncPercent > pWelsSvcRc->iRcVaryPercentage)) { |
| 713 | 716 | pEncCtx->iSkipFrameFlag = 1; |
| 714 | 717 | pWelsSvcRc->iBufferFullnessSkip = pWelsSvcRc->iBufferFullnessSkip - kiOutputBits; |
| 715 | − WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "skip one frame"); | |
| 718 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip); | |
| 716 | 719 | } |
| 717 | 720 | |
| 718 | − if (pWelsSvcRc->iBufferFullnessSkip < 0) | |
| 719 | − pWelsSvcRc->iBufferFullnessSkip = 0; | |
| 721 | + pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0); | |
| 720 | 722 | |
| 721 | 723 | if (pEncCtx->iSkipFrameFlag == 1) { |
| 722 | − pWelsSvcRc->iRemainingBits += WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 724 | + pWelsSvcRc->iRemainingBits += kiOutputBits; | |
| 723 | 725 | pWelsSvcRc->iSkipFrameNum++; |
| 724 | 726 | pWelsSvcRc->iSkipFrameInVGop++; |
| 725 | 727 | } |
| @@ -739,6 +741,7 @@ void WelsRcFrameDelayJudge (void* pCtx, EVideoFrameType eFrameType, long long ui · 13 unmodified lines | ||
| 739 | 741 | pWelsSvcRc->iSkipFrameNum++; |
| 740 | 742 | pWelsSvcRc->iSkipFrameInVGop++; |
| 741 | 743 | pWelsSvcRc->iBufferFullnessSkip -= iSentBits; |
| 744 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,"[Rc] bits in buffer = %3d",pWelsSvcRc->iBufferFullnessSkip); | |
| 742 | 745 | pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0); |
| 743 | 746 | } |
| 744 | 747 | } |
| @@ -759,14 +762,17 @@ void RcVBufferCalculationPadding (sWelsEncCtx* pEncCtx) { · 14 unmodified lines | ||
| 759 | 762 | } |
| 760 | 763 | |
| 761 | 764 | |
| 762 | −void RcTraceFrameBits (sWelsEncCtx* pEncCtx) { | |
| 765 | +void RcTraceFrameBits (void* pCtx, long long uiTimeStamp) { | |
| 766 | + sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx; | |
| 763 | 767 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 764 | 768 | |
| 765 | 769 | WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, |
| 766 | − "[Rc] encoding_qp%d, qp = %3d, index = %8d, iTid = %1d, used = %8d, target = %8d, remaingbits = %8d", | |
| 767 | − pEncCtx->uiDependencyId, pWelsSvcRc->iAverageFrameQp, pEncCtx->iFrameIndex, pEncCtx->uiTemporalId, | |
| 768 | − pWelsSvcRc->iFrameDqBits, | |
| 769 | − pWelsSvcRc->iTargetBits, pWelsSvcRc->iRemainingBits); | |
| 770 | + "[Rc] Frame timestamp = %8d, Frame type =%d, encoding_qp%d, average qp = %3d, max qp = %3d, min qp = %3d, index = %8d,\ | |
| 771 | + iTid = %1d, used = %8d, bitsperframe = %8d, target = %8d, remaingbits = %8d, skipbuffersize = %8d", | |
| 772 | + (uint32_t)uiTimeStamp,pEncCtx->eSliceType, pEncCtx->uiDependencyId, pWelsSvcRc->iAverageFrameQp,pWelsSvcRc->iMaxFrameQp,pWelsSvcRc->iMinFrameQp, | |
| 773 | + pEncCtx->iFrameIndex, pEncCtx->uiTemporalId, pWelsSvcRc->iFrameDqBits,WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY), | |
| 774 | + pWelsSvcRc->iTargetBits, pWelsSvcRc->iRemainingBits, pWelsSvcRc->iBufferSizeSkip); | |
| 775 | + | |
| 770 | 776 | } |
| 771 | 777 | |
| 772 | 778 | void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) { |
| @@ -891,8 +897,6 @@ void WelsRcPictureInfoUpdateGom (void* pCtx, int32_t iLayerSize) { · 118 unmodified lines | ||
| 891 | 897 | } |
| 892 | 898 | pWelsSvcRc->iRemainingBits -= pWelsSvcRc->iFrameDqBits; |
| 893 | 899 | |
| 894 | − RcTraceFrameBits (pEncCtx); | |
| 895 | − | |
| 896 | 900 | if (pEncCtx->pSvcParam->bEnableFrameSkip /*&& |
| 897 | 901 | pEncCtx->uiDependencyId == pEncCtx->pSvcParam->iSpatialLayerNum - 1*/) { |
| 898 | 902 | RcVBufferCalculationSkip (pEncCtx); |
| @@ -945,13 +949,15 @@ void WelsRcMbInfoUpdateGom (void* pCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* · 46 unmodified lines | ||
| 945 | 949 | SRCSlicing* pSOverRc = &pWelsSvcRc->pSlicingOverRc[iSliceId]; |
| 946 | 950 | const int32_t kiComplexityIndex = pSOverRc->iComplexityIndexSlice; |
| 947 | 951 | |
| 948 | − int32_t cur_mb_bits = BsGetBitsPos (bs) - pSOverRc->iBsPosSlice; | |
| 949 | − pSOverRc->iFrameBitsSlice += cur_mb_bits; | |
| 950 | − pSOverRc->iGomBitsSlice += cur_mb_bits; | |
| 952 | + int32_t iCurMbBits = BsGetBitsPos (bs) - pSOverRc->iBsPosSlice; | |
| 953 | + pSOverRc->iFrameBitsSlice += iCurMbBits; | |
| 954 | + pSOverRc->iGomBitsSlice += iCurMbBits; | |
| 951 | 955 | |
| 952 | 956 | pWelsSvcRc->pGomCost[kiComplexityIndex] += iCostLuma; |
| 953 | 957 | |
| 954 | − if (cur_mb_bits > 0) { | |
| 958 | + pWelsSvcRc->iMinFrameQp = WELS_MIN(pWelsSvcRc->iMinFrameQp,pCurMb->uiLumaQp); | |
| 959 | + pWelsSvcRc->iMaxFrameQp = WELS_MAX(pWelsSvcRc->iMaxFrameQp,pCurMb->uiLumaQp); | |
| 960 | + if (iCurMbBits > 0) { | |
| 955 | 961 | pSOverRc->iTotalQpSlice += pCurMb->uiLumaQp; |
| 956 | 962 | pSOverRc->iTotalMbSlice++; |
| 957 | 963 | } |