|
|
|
@ -127,10 +127,10 @@ void RcInitSequenceParameter (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->dSkipBufferRatio = SKIP_RATIO;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iQpRangeUpperInFrame = QP_RANGE_UPPER_MODE1 - (int32_t) ((QP_RANGE_UPPER_MODE1 - QP_RANGE_MODE0) *
|
|
|
|
|
pWelsSvcRc->dRcVaryRatio + 0.5);
|
|
|
|
|
pWelsSvcRc->iQpRangeLowerInFrame = QP_RANGE_LOWER_MODE1 - (int32_t) ((QP_RANGE_LOWER_MODE1 - QP_RANGE_MODE0) *
|
|
|
|
|
pWelsSvcRc->dRcVaryRatio + 0.5);
|
|
|
|
|
pWelsSvcRc->iQpRangeUpperInFrame = QP_RANGE_UPPER_MODE1 - WELS_ROUND ((QP_RANGE_UPPER_MODE1 - QP_RANGE_MODE0) *
|
|
|
|
|
pWelsSvcRc->dRcVaryRatio);
|
|
|
|
|
pWelsSvcRc->iQpRangeLowerInFrame = QP_RANGE_LOWER_MODE1 - WELS_ROUND ((QP_RANGE_LOWER_MODE1 - QP_RANGE_MODE0) *
|
|
|
|
|
pWelsSvcRc->dRcVaryRatio);
|
|
|
|
|
|
|
|
|
|
if (iMbWidth <= MB_WIDTH_THRESHOLD_90P) {
|
|
|
|
|
pWelsSvcRc->iSkipQpValue = SKIP_QP_90P;
|
|
|
|
@ -149,17 +149,17 @@ void RcInitSequenceParameter (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
iGomRowMode0 = GOM_ROW_MODE0_720P;
|
|
|
|
|
iGomRowMode1 = GOM_ROW_MODE1_720P;
|
|
|
|
|
}
|
|
|
|
|
iGomRowMode0 = iGomRowMode1 + (int32_t) ((iGomRowMode0 - iGomRowMode1) * pWelsSvcRc->dRcVaryRatio + 0.5);
|
|
|
|
|
iGomRowMode0 = iGomRowMode1 + WELS_ROUND ((iGomRowMode0 - iGomRowMode1) * pWelsSvcRc->dRcVaryRatio);
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iNumberMbGom = iMbWidth * iGomRowMode0;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iMinQp = GOM_MIN_QP_MODE;
|
|
|
|
|
pWelsSvcRc->iMaxQp = GOM_MAX_QP_MODE;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iFrameDeltaQpUpper = LAST_FRAME_QP_RANGE_UPPER_MODE1 - (int32_t) ((LAST_FRAME_QP_RANGE_UPPER_MODE1 -
|
|
|
|
|
LAST_FRAME_QP_RANGE_UPPER_MODE0) * pWelsSvcRc->dRcVaryRatio + 0.5);
|
|
|
|
|
pWelsSvcRc->iFrameDeltaQpLower = LAST_FRAME_QP_RANGE_LOWER_MODE1 - (int32_t) ((LAST_FRAME_QP_RANGE_LOWER_MODE1 -
|
|
|
|
|
LAST_FRAME_QP_RANGE_LOWER_MODE0) * pWelsSvcRc->dRcVaryRatio + 0.5);
|
|
|
|
|
pWelsSvcRc->iFrameDeltaQpUpper = LAST_FRAME_QP_RANGE_UPPER_MODE1 - WELS_ROUND ((LAST_FRAME_QP_RANGE_UPPER_MODE1 -
|
|
|
|
|
LAST_FRAME_QP_RANGE_UPPER_MODE0) * pWelsSvcRc->dRcVaryRatio);
|
|
|
|
|
pWelsSvcRc->iFrameDeltaQpLower = LAST_FRAME_QP_RANGE_LOWER_MODE1 - WELS_ROUND ((LAST_FRAME_QP_RANGE_LOWER_MODE1 -
|
|
|
|
|
LAST_FRAME_QP_RANGE_LOWER_MODE0) * pWelsSvcRc->dRcVaryRatio);
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iSkipFrameNum = 0;
|
|
|
|
|
pWelsSvcRc->iGomSize = (pWelsSvcRc->iNumberMbFrame + pWelsSvcRc->iNumberMbGom - 1) / pWelsSvcRc->iNumberMbGom;
|
|
|
|
@ -213,7 +213,7 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
const int32_t kiGopSize = (1 << pDLayerParam->iDecompositionStages);
|
|
|
|
|
const int32_t kiHighestTid = pDLayerParam->iHighestTemporalId;
|
|
|
|
|
double input_dBitsPerFrame = pDLayerParam->iSpatialBitrate / pDLayerParam->fInputFrameRate;
|
|
|
|
|
const int32_t kiGopBits = (int32_t) (input_dBitsPerFrame * kiGopSize);
|
|
|
|
|
const int32_t kiGopBits = WELS_ROUND (input_dBitsPerFrame * kiGopSize);
|
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iBitRate = pDLayerParam->iSpatialBitrate;
|
|
|
|
@ -225,16 +225,16 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= kiHighestTid; i++) {
|
|
|
|
|
const double kdConstraitBits = kiGopBits * pTOverRc[i].dTlayerWeight;
|
|
|
|
|
pTOverRc[i].iMinBitsTl = (int32_t) (kdConstraitBits * dMinBitsRatio);
|
|
|
|
|
pTOverRc[i].iMaxBitsTl = (int32_t) (kdConstraitBits * dMaxBitsRatio);
|
|
|
|
|
pTOverRc[i].iMinBitsTl = WELS_ROUND (kdConstraitBits * dMinBitsRatio);
|
|
|
|
|
pTOverRc[i].iMaxBitsTl = WELS_ROUND (kdConstraitBits * dMaxBitsRatio);
|
|
|
|
|
}
|
|
|
|
|
//When bitrate is changed, pBuffer size should be updated
|
|
|
|
|
pWelsSvcRc->iBufferSizeSkip = (int32_t) (pWelsSvcRc->iBitRate * pWelsSvcRc->dSkipBufferRatio);
|
|
|
|
|
pWelsSvcRc->iBufferSizePadding = (int32_t) (pWelsSvcRc->iBitRate * PADDING_BUFFER_RATIO);
|
|
|
|
|
pWelsSvcRc->iBufferSizeSkip = WELS_ROUND (pWelsSvcRc->iBitRate * pWelsSvcRc->dSkipBufferRatio);
|
|
|
|
|
pWelsSvcRc->iBufferSizePadding = WELS_ROUND (pWelsSvcRc->iBitRate * PADDING_BUFFER_RATIO);
|
|
|
|
|
|
|
|
|
|
//change remaining bits
|
|
|
|
|
if (pWelsSvcRc->dBitsPerFrame > 0.1)
|
|
|
|
|
pWelsSvcRc->iRemainingBits = (int32_t) (pWelsSvcRc->iRemainingBits * input_dBitsPerFrame / pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
pWelsSvcRc->iRemainingBits = WELS_ROUND (pWelsSvcRc->iRemainingBits * input_dBitsPerFrame / pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
pWelsSvcRc->dBitsPerFrame = input_dBitsPerFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -245,7 +245,7 @@ void RcInitVGop (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
SRCTemporal* pTOverRc = pWelsSvcRc->pTemporalOverRc;
|
|
|
|
|
const int32_t kiHighestTid = pEncCtx->pSvcParam->sDependencyLayers[kiDid].iHighestTemporalId;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iRemainingBits = (int32_t) (VGOP_SIZE * pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
pWelsSvcRc->iRemainingBits = WELS_ROUND (VGOP_SIZE * pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
pWelsSvcRc->dRemainingWeights = pWelsSvcRc->iGopNumberInVGop;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iFrameCodedInVGop = 0;
|
|
|
|
@ -325,9 +325,9 @@ void RcTraceVGopBitrate (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
}
|
|
|
|
|
int32_t iFrameInVGop = pWelsSvcRc->iFrameCodedInVGop + pWelsSvcRc->iSkipFrameInVGop;
|
|
|
|
|
if (0 != iFrameInVGop)
|
|
|
|
|
iVGopBitrate = (int32_t) (iTotalBits / iFrameInVGop * pWelsSvcRc->fFrameRate);
|
|
|
|
|
iVGopBitrate = WELS_ROUND (iTotalBits / iFrameInVGop * pWelsSvcRc->fFrameRate);
|
|
|
|
|
#ifdef _TEST_TEMP_Rc_
|
|
|
|
|
fprintf (fp_vgop, "%d\n", (int32_t) ((double)iTotalBits / iFrameInVGop));
|
|
|
|
|
fprintf (fp_vgop, "%d\n", WELS_ROUND ((double)iTotalBits / iFrameInVGop));
|
|
|
|
|
#endif
|
|
|
|
|
WelsLog (pEncCtx, WELS_LOG_INFO, "[Rc] VGOPbitrate%d: %d \n", kiDid, iVGopBitrate);
|
|
|
|
|
if (iTotalBits > 0) {
|
|
|
|
@ -400,7 +400,7 @@ void RcInitIdrQp (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pWelsSvcRc->iInitialQp = dInitialQPArray[iBppIndex][i];
|
|
|
|
|
pWelsSvcRc->iInitialQp = (int32_t)WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP);
|
|
|
|
|
pWelsSvcRc->iInitialQp = WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP);
|
|
|
|
|
pEncCtx->iGlobalQp = pWelsSvcRc->iInitialQp;
|
|
|
|
|
pWelsSvcRc->dQStep = RcConvertQp2QStep (pEncCtx->iGlobalQp);
|
|
|
|
|
pWelsSvcRc->iLastCalculatedQScale = pEncCtx->iGlobalQp;
|
|
|
|
@ -410,11 +410,12 @@ void RcCalculateIdrQp (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
|
|
|
|
|
//obtain the idr qp using previous idr complexity
|
|
|
|
|
if (pWelsSvcRc->iNumberMbFrame != pWelsSvcRc->iIntraMbCount) {
|
|
|
|
|
pWelsSvcRc->iIntraComplexity = (int32_t) ((double)pWelsSvcRc->iIntraComplexity * pWelsSvcRc->iNumberMbFrame /
|
|
|
|
|
pWelsSvcRc->iIntraMbCount + 0.5);
|
|
|
|
|
pWelsSvcRc->iIntraComplexity = WELS_ROUND ((double)pWelsSvcRc->iIntraComplexity * pWelsSvcRc->iNumberMbFrame /
|
|
|
|
|
pWelsSvcRc->iIntraMbCount);
|
|
|
|
|
}
|
|
|
|
|
pWelsSvcRc->iInitialQp = (int32_t)RcConvertQStep2Qp ((double)pWelsSvcRc->iIntraComplexity / pWelsSvcRc->iTargetBits);
|
|
|
|
|
pWelsSvcRc->iInitialQp = (int32_t)WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP);
|
|
|
|
|
pWelsSvcRc->iInitialQp = WELS_ROUND (RcConvertQStep2Qp ((double)pWelsSvcRc->iIntraComplexity /
|
|
|
|
|
pWelsSvcRc->iTargetBits));
|
|
|
|
|
pWelsSvcRc->iInitialQp = WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP);
|
|
|
|
|
pEncCtx->iGlobalQp = pWelsSvcRc->iInitialQp;
|
|
|
|
|
pWelsSvcRc->dQStep = RcConvertQp2QStep (pEncCtx->iGlobalQp);
|
|
|
|
|
pWelsSvcRc->iLastCalculatedQScale = pEncCtx->iGlobalQp;
|
|
|
|
@ -451,7 +452,7 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
pWelsSvcRc->iLastCalculatedQScale = iLumaQp;
|
|
|
|
|
|
|
|
|
|
if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) {
|
|
|
|
|
iLumaQp = (int32_t) (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
|
|
|
|
|
iLumaQp = WELS_ROUND (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pEncCtx->iGlobalQp = iLumaQp;
|
|
|
|
@ -462,7 +463,7 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
dCmplxRatio = WELS_CLIP3 (dCmplxRatio, 1.0 - FRAME_CMPLX_RATIO_RANGE, 1.0 + FRAME_CMPLX_RATIO_RANGE);
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->dQStep = pTOverRc->dLinearCmplx * dCmplxRatio / pWelsSvcRc->iTargetBits;
|
|
|
|
|
iLumaQp = (int32_t) (RcConvertQStep2Qp (pWelsSvcRc->dQStep) + 0.5);
|
|
|
|
|
iLumaQp = WELS_ROUND (RcConvertQStep2Qp (pWelsSvcRc->dQStep));
|
|
|
|
|
|
|
|
|
|
//limit QP
|
|
|
|
|
int32_t iLastIdxCodecInVGop = pWelsSvcRc->iFrameCodedInVGop - 1;
|
|
|
|
@ -487,10 +488,10 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
#ifndef _NOT_USE_AQ_FOR_TEST_
|
|
|
|
|
if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) {
|
|
|
|
|
|
|
|
|
|
iLumaQp = (int32_t) (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
|
|
|
|
|
iLumaQp = WELS_ROUND (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
|
|
|
|
|
|
|
|
|
|
if (pEncCtx->pSvcParam->iRCMode != RC_LOW_BW_MODE)
|
|
|
|
|
iLumaQp = (int32_t)WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
|
|
|
|
|
iLumaQp = WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -510,7 +511,7 @@ void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
pSOverRc->iEndMbSlice += (pCurSliceCtx->pCountMbNumInSlice[i] - 1);
|
|
|
|
|
pSOverRc->iTotalQpSlice = 0;
|
|
|
|
|
pSOverRc->iTotalMbSlice = 0;
|
|
|
|
|
pSOverRc->iTargetBitsSlice = (int32_t) (kdBitsPerMb * pCurSliceCtx->pCountMbNumInSlice[i]);
|
|
|
|
|
pSOverRc->iTargetBitsSlice = WELS_ROUND (kdBitsPerMb * pCurSliceCtx->pCountMbNumInSlice[i]);
|
|
|
|
|
pSOverRc->iFrameBitsSlice = 0;
|
|
|
|
|
pSOverRc->iGomBitsSlice = 0;
|
|
|
|
|
++ pSOverRc;
|
|
|
|
@ -524,10 +525,10 @@ void RcDecideTargetBits (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
pWelsSvcRc->iCurrentBitsLevel = BITS_NORMAL;
|
|
|
|
|
//allocate bits
|
|
|
|
|
if (pEncCtx->eSliceType == I_SLICE) {
|
|
|
|
|
pWelsSvcRc->iTargetBits = (int32_t) (pWelsSvcRc->dBitsPerFrame * IDR_BITRATE_RATIO);
|
|
|
|
|
pWelsSvcRc->iTargetBits = WELS_ROUND (pWelsSvcRc->dBitsPerFrame * IDR_BITRATE_RATIO);
|
|
|
|
|
} else {
|
|
|
|
|
pWelsSvcRc->iTargetBits = (int32_t) (pWelsSvcRc->iRemainingBits * pTOverRc->dTlayerWeight /
|
|
|
|
|
pWelsSvcRc->dRemainingWeights);
|
|
|
|
|
pWelsSvcRc->iTargetBits = WELS_ROUND (pWelsSvcRc->iRemainingBits * pTOverRc->dTlayerWeight /
|
|
|
|
|
pWelsSvcRc->dRemainingWeights);
|
|
|
|
|
if ((pWelsSvcRc->iTargetBits <= 0) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) {
|
|
|
|
|
pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED;
|
|
|
|
|
} else if ((pWelsSvcRc->iTargetBits <= pTOverRc->iMinBitsTl) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) {
|
|
|
|
@ -625,7 +626,7 @@ void RcGomTargetBits (sWelsEncCtx* pEncCtx, const int32_t kiSliceId) {
|
|
|
|
|
dAllocateBits = (double)iLeftBits * pWelsSvcRc_Base->pCurrentFrameGomSad[kiComplexityIndex + 1] / iSumSad;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
pSOverRc->iGomTargetBits = int32_t (dAllocateBits + 0.5);
|
|
|
|
|
pSOverRc->iGomTargetBits = WELS_ROUND (dAllocateBits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -665,11 +666,11 @@ void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) {
|
|
|
|
|
void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
|
|
|
|
|
SRCTemporal* pTOverRc = pWelsSvcRc->pTemporalOverRc;
|
|
|
|
|
const int32_t kiOutputBits = (int32_t) (pWelsSvcRc->dBitsPerFrame + 0.5);
|
|
|
|
|
const int32_t kiOutputBits = WELS_ROUND (pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
//condition 1: whole pBuffer fullness
|
|
|
|
|
pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits);
|
|
|
|
|
//condition 2: VGOP bits constraint
|
|
|
|
|
const int32_t kiVGopBits = (int32_t) (pWelsSvcRc->dBitsPerFrame * VGOP_SIZE);
|
|
|
|
|
const int32_t kiVGopBits = WELS_ROUND (pWelsSvcRc->dBitsPerFrame * VGOP_SIZE);
|
|
|
|
|
int32_t iVGopBitsPred = 0;
|
|
|
|
|
for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++)
|
|
|
|
|
iVGopBitsPred += pTOverRc[pWelsSvcRc->iTlOfFrames[i]].iMinBitsTl;
|
|
|
|
@ -690,7 +691,7 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
pWelsSvcRc->iBufferFullnessSkip = 0;
|
|
|
|
|
|
|
|
|
|
if (pEncCtx->iSkipFrameFlag == 1) {
|
|
|
|
|
pWelsSvcRc->iRemainingBits += (int32_t) (pWelsSvcRc->dBitsPerFrame + 0.5);
|
|
|
|
|
pWelsSvcRc->iRemainingBits += WELS_ROUND (pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
pWelsSvcRc->iSkipFrameNum++;
|
|
|
|
|
pWelsSvcRc->iSkipFrameInVGop++;
|
|
|
|
|
}
|
|
|
|
@ -698,8 +699,8 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
|
|
|
|
|
void RcVBufferCalculationPadding (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
|
|
|
|
|
const int32_t kiOutputBits = (int32_t) (pWelsSvcRc->dBitsPerFrame + 0.5);
|
|
|
|
|
const int32_t kiBufferThreshold = (int32_t) (PADDING_THRESHOLD * (-pWelsSvcRc->iBufferSizePadding));
|
|
|
|
|
const int32_t kiOutputBits = WELS_ROUND (pWelsSvcRc->dBitsPerFrame);
|
|
|
|
|
const int32_t kiBufferThreshold = WELS_ROUND (PADDING_THRESHOLD * (-pWelsSvcRc->iBufferSizePadding));
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iBufferFullnessPadding += (pWelsSvcRc->iFrameDqBits - kiOutputBits);
|
|
|
|
|
|
|
|
|
@ -736,7 +737,7 @@ void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) {
|
|
|
|
|
++ pSOverRc;
|
|
|
|
|
}
|
|
|
|
|
if (iTotalMb > 0)
|
|
|
|
|
pWelsSvcRc->iAverageFrameQp = (int32_t) (1.0 * iTotalQp / iTotalMb + 0.5);
|
|
|
|
|
pWelsSvcRc->iAverageFrameQp = WELS_ROUND (1.0 * iTotalQp / iTotalMb);
|
|
|
|
|
else
|
|
|
|
|
pWelsSvcRc->iAverageFrameQp = pEncCtx->iGlobalQp;
|
|
|
|
|
} else {
|
|
|
|
@ -753,7 +754,7 @@ void RcUpdateIntraComplexity (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
|
|
|
|
|
double dIntraCmplx = pWelsSvcRc->dQStep * pWelsSvcRc->iFrameDqBits;
|
|
|
|
|
dIntraCmplx = (1.0 - iAlpha) * pWelsSvcRc->iIntraComplexity + iAlpha * dIntraCmplx;
|
|
|
|
|
pWelsSvcRc->iIntraComplexity = (int32_t) (dIntraCmplx + 0.5);
|
|
|
|
|
pWelsSvcRc->iIntraComplexity = WELS_ROUND (dIntraCmplx);
|
|
|
|
|
pWelsSvcRc->iIntraMbCount = pWelsSvcRc->iNumberMbFrame;
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iIdrNum++;
|
|
|
|
@ -775,8 +776,8 @@ void RcUpdateFrameComplexity (sWelsEncCtx* pEncCtx) {
|
|
|
|
|
double iAlpha = 1.0 / (1 + pTOverRc->iPFrameNum);
|
|
|
|
|
if (iAlpha < SMOOTH_FACTOR_MIN_VALUE)
|
|
|
|
|
iAlpha = SMOOTH_FACTOR_MIN_VALUE;
|
|
|
|
|
pTOverRc->iFrameCmplxMean = (int32_t) ((1.0 - iAlpha) * pTOverRc->iFrameCmplxMean + iAlpha *
|
|
|
|
|
pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity + 0.5);
|
|
|
|
|
pTOverRc->iFrameCmplxMean = WELS_ROUND ((1.0 - iAlpha) * pTOverRc->iFrameCmplxMean + iAlpha *
|
|
|
|
|
pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity);
|
|
|
|
|
|
|
|
|
|
pTOverRc->iPFrameNum++;
|
|
|
|
|
if (pTOverRc->iPFrameNum > 255)
|
|
|
|
@ -918,10 +919,10 @@ void WelsRcPictureInitDisable (void* pCtx) {
|
|
|
|
|
pEncCtx->iGlobalQp = RcCalculateCascadingQp (pEncCtx, kiQp);
|
|
|
|
|
|
|
|
|
|
if (pEncCtx->pSvcParam->bEnableAdaptiveQuant && (pEncCtx->eSliceType == P_SLICE)) {
|
|
|
|
|
pEncCtx->iGlobalQp = (int32_t)WELS_CLIP3 (pEncCtx->iGlobalQp -
|
|
|
|
|
pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp, GOM_MIN_QP_MODE, GOM_MAX_QP_MODE);
|
|
|
|
|
}else{
|
|
|
|
|
pEncCtx->iGlobalQp = WELS_CLIP3(pEncCtx->iGlobalQp, FIX_MIN_QP_MODE, FIX_MAX_QP_MODE);
|
|
|
|
|
pEncCtx->iGlobalQp = WELS_CLIP3 (WELS_ROUND (pEncCtx->iGlobalQp -
|
|
|
|
|
pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp), GOM_MIN_QP_MODE, GOM_MAX_QP_MODE);
|
|
|
|
|
} else {
|
|
|
|
|
pEncCtx->iGlobalQp = WELS_CLIP3 (pEncCtx->iGlobalQp, FIX_MIN_QP_MODE, FIX_MAX_QP_MODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pWelsSvcRc->iAverageFrameQp = pEncCtx->iGlobalQp;
|
|
|
|
@ -937,8 +938,8 @@ void WelsRcMbInitDisable (void* pCtx, SMB* pCurMb, SSlice* pSlice) {
|
|
|
|
|
if (pEncCtx->pSvcParam->bEnableAdaptiveQuant && (pEncCtx->eSliceType == P_SLICE)) {
|
|
|
|
|
iLumaQp = (int8_t)WELS_CLIP3 (iLumaQp +
|
|
|
|
|
pEncCtx->pVaa->sAdaptiveQuantParam.pMotionTextureIndexToDeltaQp[pCurMb->iMbXY], GOM_MIN_QP_MODE, 51);
|
|
|
|
|
}else{
|
|
|
|
|
iLumaQp = WELS_CLIP3(iLumaQp,FIX_MIN_QP_MODE,FIX_MAX_QP_MODE);
|
|
|
|
|
} else {
|
|
|
|
|
iLumaQp = WELS_CLIP3 (iLumaQp, FIX_MIN_QP_MODE, FIX_MAX_QP_MODE);
|
|
|
|
|
}
|
|
|
|
|
pCurMb->uiChromaQp = g_kuiChromaQpTable[iLumaQp];
|
|
|
|
|
pCurMb->uiLumaQp = iLumaQp;
|
|
|
|
|