Showing the changes to codec/encoder/core/src/ratectl.cpp (1 of 85 files). Show all
Unified · Split
| @@ -57,11 +57,12 @@ FILE* fp_vgop = NULL; · 56 unmodified lines | ||
| 57 | 57 | #endif |
| 58 | 58 | #define _BITS_RANGE 0 |
| 59 | 59 | const int32_t g_kiQpToQstepTable[52] = { 63, 71, 79, 89, 100, 112, 126, 141, 159, 178, |
| 60 | − 200, 224, 252, 283, 317, 356, 400, 449, 504, 566, | |
| 61 | − 635, 713, 800, 898, 1008, 1131, 1270, 1425, 1600, 1796, | |
| 62 | − 2016, 2263, 2540, 2851, 3200, 3592, 4032, 4525, 5080, 5702, | |
| 63 | − 6400, 7184, 8063, 9051,10159,11404,12800,14368,16127,18102, | |
| 64 | − 20319,22807}; //WELS_ROUND(INT_MULTIPLY*pow (2.0, (iQP - 4.0) / 6.0)) | |
| 60 | + 200, 224, 252, 283, 317, 356, 400, 449, 504, 566, | |
| 61 | + 635, 713, 800, 898, 1008, 1131, 1270, 1425, 1600, 1796, | |
| 62 | + 2016, 2263, 2540, 2851, 3200, 3592, 4032, 4525, 5080, 5702, | |
| 63 | + 6400, 7184, 8063, 9051, 10159, 11404, 12800, 14368, 16127, 18102, | |
| 64 | + 20319, 22807 | |
| 65 | + }; //WELS_ROUND(INT_MULTIPLY*pow (2.0, (iQP - 4.0) / 6.0)) | |
| 65 | 66 | |
| 66 | 67 | void RcInitLayerMemory (SWelsSvcRc* pWelsSvcRc, CMemoryAlign* pMA, const int32_t kiMaxTl) { |
| 67 | 68 | const int32_t kiSliceNum = pWelsSvcRc->iSliceNum; |
| @@ -106,7 +107,7 @@ static inline int32_t RcConvertQp2QStep (int32_t iQP) { · 38 unmodified lines | ||
| 106 | 107 | return g_kiQpToQstepTable[iQP]; |
| 107 | 108 | } |
| 108 | 109 | static inline int32_t RcConvertQStep2Qp (int32_t iQpStep) { |
| 109 | − return WELS_ROUND((6 * log (iQpStep*1.0f/INT_MULTIPLY) / log (2.0) + 4.0)); | |
| 110 | + return WELS_ROUND ((6 * log (iQpStep * 1.0f / INT_MULTIPLY) / log (2.0) + 4.0)); | |
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 | void RcInitSequenceParameter (sWelsEncCtx* pEncCtx) { |
| @@ -135,10 +136,12 @@ void RcInitSequenceParameter (sWelsEncCtx* pEncCtx) { · 22 unmodified lines | ||
| 135 | 136 | |
| 136 | 137 | pWelsSvcRc->iSkipBufferRatio = SKIP_RATIO; |
| 137 | 138 | |
| 138 | − pWelsSvcRc->iQpRangeUpperInFrame = (QP_RANGE_UPPER_MODE1 * MAX_BITS_VARY_PERCENTAGE - ((QP_RANGE_UPPER_MODE1 - QP_RANGE_MODE0) * | |
| 139 | − pWelsSvcRc->iRcVaryRatio)) / MAX_BITS_VARY_PERCENTAGE; | |
| 140 | − pWelsSvcRc->iQpRangeLowerInFrame = (QP_RANGE_LOWER_MODE1 * MAX_BITS_VARY_PERCENTAGE - ((QP_RANGE_LOWER_MODE1 - QP_RANGE_MODE0) * | |
| 141 | − pWelsSvcRc->iRcVaryRatio)) / MAX_BITS_VARY_PERCENTAGE; | |
| 139 | + pWelsSvcRc->iQpRangeUpperInFrame = (QP_RANGE_UPPER_MODE1 * MAX_BITS_VARY_PERCENTAGE - (( | |
| 140 | + QP_RANGE_UPPER_MODE1 - QP_RANGE_MODE0) * | |
| 141 | + pWelsSvcRc->iRcVaryRatio)) / MAX_BITS_VARY_PERCENTAGE; | |
| 142 | + pWelsSvcRc->iQpRangeLowerInFrame = (QP_RANGE_LOWER_MODE1 * MAX_BITS_VARY_PERCENTAGE - (( | |
| 143 | + QP_RANGE_LOWER_MODE1 - QP_RANGE_MODE0) * | |
| 144 | + pWelsSvcRc->iRcVaryRatio)) / MAX_BITS_VARY_PERCENTAGE; | |
| 142 | 145 | |
| 143 | 146 | if (iMbWidth <= MB_WIDTH_THRESHOLD_90P) { |
| 144 | 147 | pWelsSvcRc->iSkipQpValue = SKIP_QP_90P; |
| @@ -223,8 +226,9 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) { · 78 unmodified lines | ||
| 223 | 226 | SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId]; |
| 224 | 227 | const int32_t kiGopSize = (1 << pDLayerParamInternal->iDecompositionStages); |
| 225 | 228 | const int32_t kiHighestTid = pDLayerParamInternal->iHighestTemporalId; |
| 226 | − int32_t input_iBitsPerFrame = WELS_ROUND(pDLayerParam->iSpatialBitrate * INT_MULTIPLY / pDLayerParamInternal->fInputFrameRate); | |
| 227 | − const int32_t kiGopBits = WELS_DIV_ROUND(input_iBitsPerFrame * kiGopSize, INT_MULTIPLY); | |
| 229 | + int32_t input_iBitsPerFrame = WELS_ROUND (pDLayerParam->iSpatialBitrate * INT_MULTIPLY / | |
| 230 | + pDLayerParamInternal->fInputFrameRate); | |
| 231 | + const int32_t kiGopBits = WELS_DIV_ROUND (input_iBitsPerFrame * kiGopSize, INT_MULTIPLY); | |
| 228 | 232 | int32_t i; |
| 229 | 233 | |
| 230 | 234 | pWelsSvcRc->iBitRate = pDLayerParam->iSpatialBitrate; |
| @@ -236,12 +240,14 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) { · 5 unmodified lines | ||
| 236 | 240 | |
| 237 | 241 | for (i = 0; i <= kiHighestTid; i++) { |
| 238 | 242 | const int64_t kdConstraitBits = kiGopBits * pTOverRc[i].iTlayerWeight; |
| 239 | − pTOverRc[i].iMinBitsTl = WELS_DIV_ROUND(kdConstraitBits * iMinBitsRatio, INT_MULTIPLY * MAX_BITS_VARY_PERCENTAGE * WEIGHT_MULTIPLY); | |
| 240 | − pTOverRc[i].iMaxBitsTl = WELS_DIV_ROUND(kdConstraitBits * iMaxBitsRatio, INT_MULTIPLY * MAX_BITS_VARY_PERCENTAGE * WEIGHT_MULTIPLY); | |
| 243 | + pTOverRc[i].iMinBitsTl = WELS_DIV_ROUND (kdConstraitBits * iMinBitsRatio, | |
| 244 | + INT_MULTIPLY * MAX_BITS_VARY_PERCENTAGE * WEIGHT_MULTIPLY); | |
| 245 | + pTOverRc[i].iMaxBitsTl = WELS_DIV_ROUND (kdConstraitBits * iMaxBitsRatio, | |
| 246 | + INT_MULTIPLY * MAX_BITS_VARY_PERCENTAGE * WEIGHT_MULTIPLY); | |
| 241 | 247 | } |
| 242 | 248 | //When bitrate is changed, pBuffer size should be updated |
| 243 | − pWelsSvcRc->iBufferSizeSkip = WELS_DIV_ROUND(pWelsSvcRc->iBitRate * pWelsSvcRc->iSkipBufferRatio, INT_MULTIPLY); | |
| 244 | − pWelsSvcRc->iBufferSizePadding = WELS_DIV_ROUND(pWelsSvcRc->iBitRate * PADDING_BUFFER_RATIO, INT_MULTIPLY); | |
| 249 | + pWelsSvcRc->iBufferSizeSkip = WELS_DIV_ROUND (pWelsSvcRc->iBitRate * pWelsSvcRc->iSkipBufferRatio, INT_MULTIPLY); | |
| 250 | + pWelsSvcRc->iBufferSizePadding = WELS_DIV_ROUND (pWelsSvcRc->iBitRate * PADDING_BUFFER_RATIO, INT_MULTIPLY); | |
| 245 | 251 | |
| 246 | 252 | //change remaining bits |
| 247 | 253 | if (pWelsSvcRc->iBitsPerFrame > REMAIN_BITS_TH) |
| @@ -256,7 +262,7 @@ void RcInitVGop (sWelsEncCtx* pEncCtx) { · 8 unmodified lines | ||
| 256 | 262 | SRCTemporal* pTOverRc = pWelsSvcRc->pTemporalOverRc; |
| 257 | 263 | const int32_t kiHighestTid = pEncCtx->pSvcParam->sDependencyLayers[kiDid].iHighestTemporalId; |
| 258 | 264 | |
| 259 | − pWelsSvcRc->iRemainingBits = WELS_DIV_ROUND(VGOP_SIZE * pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 265 | + pWelsSvcRc->iRemainingBits = WELS_DIV_ROUND (VGOP_SIZE * pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 260 | 266 | pWelsSvcRc->iRemainingWeights = pWelsSvcRc->iGopNumberInVGop * WEIGHT_MULTIPLY; |
| 261 | 267 | |
| 262 | 268 | pWelsSvcRc->iFrameCodedInVGop = 0; |
| @@ -427,7 +433,7 @@ void RcCalculateIdrQp (sWelsEncCtx* pEncCtx) { · 164 unmodified lines | ||
| 427 | 433 | pWelsSvcRc->iIntraMbCount; |
| 428 | 434 | } |
| 429 | 435 | pWelsSvcRc->iInitialQp = RcConvertQStep2Qp (pWelsSvcRc->iIntraComplexity / |
| 430 | − pWelsSvcRc->iTargetBits); | |
| 436 | + pWelsSvcRc->iTargetBits); | |
| 431 | 437 | pWelsSvcRc->iInitialQp = WELS_CLIP3 (pWelsSvcRc->iInitialQp, MIN_IDR_QP, MAX_IDR_QP); |
| 432 | 438 | pEncCtx->iGlobalQp = pWelsSvcRc->iInitialQp; |
| 433 | 439 | pWelsSvcRc->iQStep = RcConvertQp2QStep (pEncCtx->iGlobalQp); |
| @@ -465,17 +471,19 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) { · 31 unmodified lines | ||
| 465 | 471 | pWelsSvcRc->iLastCalculatedQScale = iLumaQp; |
| 466 | 472 | |
| 467 | 473 | if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) { |
| 468 | − iLumaQp = WELS_CLIP3 ((iLumaQp*INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp)/INT_MULTIPLY, GOM_MIN_QP_MODE, MAX_LOW_BR_QP); | |
| 474 | + iLumaQp = WELS_CLIP3 ((iLumaQp * INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp) / | |
| 475 | + INT_MULTIPLY, GOM_MIN_QP_MODE, MAX_LOW_BR_QP); | |
| 469 | 476 | } |
| 470 | 477 | |
| 471 | 478 | pEncCtx->iGlobalQp = iLumaQp; |
| 472 | 479 | |
| 473 | 480 | return; |
| 474 | 481 | } else { |
| 475 | − int64_t iCmplxRatio = WELS_DIV_ROUND64(pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity *INT_MULTIPLY, pTOverRc->iFrameCmplxMean); | |
| 482 | + int64_t iCmplxRatio = WELS_DIV_ROUND64 (pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity * INT_MULTIPLY, | |
| 483 | + pTOverRc->iFrameCmplxMean); | |
| 476 | 484 | iCmplxRatio = WELS_CLIP3 (iCmplxRatio, INT_MULTIPLY - FRAME_CMPLX_RATIO_RANGE, INT_MULTIPLY + FRAME_CMPLX_RATIO_RANGE); |
| 477 | 485 | |
| 478 | − pWelsSvcRc->iQStep = WELS_DIV_ROUND((pTOverRc->iLinearCmplx * iCmplxRatio), (pWelsSvcRc->iTargetBits * INT_MULTIPLY)); | |
| 486 | + pWelsSvcRc->iQStep = WELS_DIV_ROUND ((pTOverRc->iLinearCmplx * iCmplxRatio), (pWelsSvcRc->iTargetBits * INT_MULTIPLY)); | |
| 479 | 487 | iLumaQp = RcConvertQStep2Qp (pWelsSvcRc->iQStep); |
| 480 | 488 | |
| 481 | 489 | //limit QP |
| @@ -501,7 +509,8 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) { · 19 unmodified lines | ||
| 501 | 509 | #ifndef _NOT_USE_AQ_FOR_TEST_ |
| 502 | 510 | if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) { |
| 503 | 511 | |
| 504 | − iLumaQp = WELS_DIV_ROUND(iLumaQp*INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp,INT_MULTIPLY); | |
| 512 | + iLumaQp = WELS_DIV_ROUND (iLumaQp * INT_MULTIPLY - pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp, | |
| 513 | + INT_MULTIPLY); | |
| 505 | 514 | |
| 506 | 515 | if (pEncCtx->pSvcParam->iRCMode != RC_LOW_BW_MODE) |
| 507 | 516 | iLumaQp = WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp); |
| @@ -516,7 +525,7 @@ void RcInitSliceInformation (sWelsEncCtx* pEncCtx) { · 8 unmodified lines | ||
| 516 | 525 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 517 | 526 | SRCSlicing* pSOverRc = &pWelsSvcRc->pSlicingOverRc[0]; |
| 518 | 527 | const int32_t kiSliceNum = pWelsSvcRc->iSliceNum; |
| 519 | − const int32_t kiBitsPerMb = WELS_DIV_ROUND(pWelsSvcRc->iTargetBits * INT_MULTIPLY, pWelsSvcRc->iNumberMbFrame); | |
| 528 | + const int32_t kiBitsPerMb = WELS_DIV_ROUND (pWelsSvcRc->iTargetBits * INT_MULTIPLY, pWelsSvcRc->iNumberMbFrame); | |
| 520 | 529 | |
| 521 | 530 | for (int32_t i = 0; i < kiSliceNum; i++) { |
| 522 | 531 | pSOverRc->iStartMbSlice = |
| @@ -524,7 +533,7 @@ void RcInitSliceInformation (sWelsEncCtx* pEncCtx) { · 1 unmodified line | ||
| 524 | 533 | pSOverRc->iEndMbSlice += (pCurSliceCtx->pCountMbNumInSlice[i] - 1); |
| 525 | 534 | pSOverRc->iTotalQpSlice = 0; |
| 526 | 535 | pSOverRc->iTotalMbSlice = 0; |
| 527 | − pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND(kiBitsPerMb * pCurSliceCtx->pCountMbNumInSlice[i], INT_MULTIPLY); | |
| 536 | + pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurSliceCtx->pCountMbNumInSlice[i], INT_MULTIPLY); | |
| 528 | 537 | pSOverRc->iFrameBitsSlice = 0; |
| 529 | 538 | pSOverRc->iGomBitsSlice = 0; |
| 530 | 539 | ++ pSOverRc; |
| @@ -538,10 +547,10 @@ void RcDecideTargetBits (sWelsEncCtx* pEncCtx) { · 7 unmodified lines | ||
| 538 | 547 | pWelsSvcRc->iCurrentBitsLevel = BITS_NORMAL; |
| 539 | 548 | //allocate bits |
| 540 | 549 | if (pEncCtx->eSliceType == I_SLICE) { |
| 541 | − pWelsSvcRc->iTargetBits = WELS_DIV_ROUND(pWelsSvcRc->iBitsPerFrame * IDR_BITRATE_RATIO, INT_MULTIPLY); | |
| 550 | + pWelsSvcRc->iTargetBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame * IDR_BITRATE_RATIO, INT_MULTIPLY); | |
| 542 | 551 | } else { |
| 543 | − pWelsSvcRc->iTargetBits = (int32_t)((int64_t)pWelsSvcRc->iRemainingBits * pTOverRc->iTlayerWeight / | |
| 544 | − pWelsSvcRc->iRemainingWeights); | |
| 552 | + pWelsSvcRc->iTargetBits = (int32_t) ((int64_t)pWelsSvcRc->iRemainingBits * pTOverRc->iTlayerWeight / | |
| 553 | + pWelsSvcRc->iRemainingWeights); | |
| 545 | 554 | if ((pWelsSvcRc->iTargetBits <= 0) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) { |
| 546 | 555 | pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED; |
| 547 | 556 | } else if ((pWelsSvcRc->iTargetBits <= pTOverRc->iMinBitsTl) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) { |
| @@ -635,9 +644,10 @@ void RcGomTargetBits (sWelsEncCtx* pEncCtx, const int32_t kiSliceId) { · 87 unmodified lines | ||
| 635 | 644 | iSumSad += pWelsSvcRc_Base->pCurrentFrameGomSad[i]; |
| 636 | 645 | } |
| 637 | 646 | if (0 == iSumSad) |
| 638 | − iAllocateBits = WELS_DIV_ROUND(iLeftBits, (iLastGomIndex - kiComplexityIndex)); | |
| 647 | + iAllocateBits = WELS_DIV_ROUND (iLeftBits, (iLastGomIndex - kiComplexityIndex)); | |
| 639 | 648 | else |
| 640 | − iAllocateBits = WELS_DIV_ROUND((int64_t)iLeftBits * pWelsSvcRc_Base->pCurrentFrameGomSad[kiComplexityIndex + 1], iSumSad); | |
| 649 | + iAllocateBits = WELS_DIV_ROUND ((int64_t)iLeftBits * pWelsSvcRc_Base->pCurrentFrameGomSad[kiComplexityIndex + 1], | |
| 650 | + iSumSad); | |
| 641 | 651 | |
| 642 | 652 | } |
| 643 | 653 | pSOverRc->iGomTargetBits = iAllocateBits; |
| @@ -657,7 +667,7 @@ void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) { · 13 unmodified lines | ||
| 657 | 667 | pSOverRc->iCalculatedQpSlice += 2; |
| 658 | 668 | } else { |
| 659 | 669 | //globe decision |
| 660 | − iBitsRatio = 10000 * iLeftBits / (iTargetLeftBits+1); | |
| 670 | + iBitsRatio = 10000 * iLeftBits / (iTargetLeftBits + 1); | |
| 661 | 671 | if (iBitsRatio < 8409) //2^(-1.5/6)*10000 |
| 662 | 672 | pSOverRc->iCalculatedQpSlice += 2; |
| 663 | 673 | else if (iBitsRatio < 9439) //2^(-0.5/6)*10000 |
| @@ -680,11 +690,11 @@ void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) { · 16 unmodified lines | ||
| 680 | 690 | void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { |
| 681 | 691 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 682 | 692 | SRCTemporal* pTOverRc = pWelsSvcRc->pTemporalOverRc; |
| 683 | − const int32_t kiOutputBits = WELS_DIV_ROUND(pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 693 | + const int32_t kiOutputBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 684 | 694 | //condition 1: whole pBuffer fullness |
| 685 | 695 | pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits); |
| 686 | 696 | //condition 2: VGOP bits constraint |
| 687 | − const int32_t kiVGopBits = WELS_DIV_ROUND(pWelsSvcRc->iBitsPerFrame * VGOP_SIZE, INT_MULTIPLY); | |
| 697 | + const int32_t kiVGopBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame * VGOP_SIZE, INT_MULTIPLY); | |
| 688 | 698 | int32_t iVGopBitsPred = 0; |
| 689 | 699 | for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++) |
| 690 | 700 | iVGopBitsPred += pTOverRc[pWelsSvcRc->iTlOfFrames[i]].iMinBitsTl; |
| @@ -705,32 +715,32 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { · 14 unmodified lines | ||
| 705 | 715 | pWelsSvcRc->iBufferFullnessSkip = 0; |
| 706 | 716 | |
| 707 | 717 | if (pEncCtx->iSkipFrameFlag == 1) { |
| 708 | − pWelsSvcRc->iRemainingBits += WELS_DIV_ROUND(pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 718 | + pWelsSvcRc->iRemainingBits += WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 709 | 719 | pWelsSvcRc->iSkipFrameNum++; |
| 710 | 720 | pWelsSvcRc->iSkipFrameInVGop++; |
| 711 | 721 | } |
| 712 | 722 | } |
| 713 | 723 | |
| 714 | −void WelsRcFrameDelayJudge(void* pCtx) { | |
| 724 | +void WelsRcFrameDelayJudge (void* pCtx) { | |
| 715 | 725 | sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx; |
| 716 | 726 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 717 | 727 | SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId]; |
| 718 | 728 | SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId]; |
| 719 | 729 | |
| 720 | − int32_t iSentBits = WELS_ROUND(pDLayerParam->iSpatialBitrate / pDLayerParamInternal->fOutputFrameRate); | |
| 730 | + int32_t iSentBits = WELS_ROUND (pDLayerParam->iSpatialBitrate / pDLayerParamInternal->fOutputFrameRate); | |
| 721 | 731 | |
| 722 | 732 | pWelsSvcRc->bSkipFlag = false; |
| 723 | 733 | if (pWelsSvcRc->iBufferFullnessSkip > pWelsSvcRc->iBufferSizeSkip) { |
| 724 | 734 | pWelsSvcRc->bSkipFlag = true; |
| 725 | 735 | pWelsSvcRc->iBufferFullnessSkip -= iSentBits; |
| 726 | − pWelsSvcRc->iBufferFullnessSkip = WELS_MAX(pWelsSvcRc->iBufferFullnessSkip, 0); | |
| 736 | + pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0); | |
| 727 | 737 | } |
| 728 | 738 | } |
| 729 | 739 | |
| 730 | 740 | void RcVBufferCalculationPadding (sWelsEncCtx* pEncCtx) { |
| 731 | 741 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 732 | − const int32_t kiOutputBits = WELS_DIV_ROUND(pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 733 | − const int32_t kiBufferThreshold = WELS_DIV_ROUND(PADDING_THRESHOLD * (-pWelsSvcRc->iBufferSizePadding), INT_MULTIPLY); | |
| 742 | + const int32_t kiOutputBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame, INT_MULTIPLY); | |
| 743 | + const int32_t kiBufferThreshold = WELS_DIV_ROUND (PADDING_THRESHOLD * (-pWelsSvcRc->iBufferSizePadding), INT_MULTIPLY); | |
| 734 | 744 | |
| 735 | 745 | pWelsSvcRc->iBufferFullnessPadding += (pWelsSvcRc->iFrameDqBits - kiOutputBits); |
| 736 | 746 | |
| @@ -767,7 +777,7 @@ void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) { · 30 unmodified lines | ||
| 767 | 777 | ++ pSOverRc; |
| 768 | 778 | } |
| 769 | 779 | if (iTotalMb > 0) |
| 770 | − pWelsSvcRc->iAverageFrameQp = WELS_DIV_ROUND(INT_MULTIPLY * iTotalQp, iTotalMb * INT_MULTIPLY); | |
| 780 | + pWelsSvcRc->iAverageFrameQp = WELS_DIV_ROUND (INT_MULTIPLY * iTotalQp, iTotalMb * INT_MULTIPLY); | |
| 771 | 781 | else |
| 772 | 782 | pWelsSvcRc->iAverageFrameQp = pEncCtx->iGlobalQp; |
| 773 | 783 | } else { |
| @@ -779,11 +789,12 @@ void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) { · 5 unmodified lines | ||
| 779 | 789 | |
| 780 | 790 | void RcUpdateIntraComplexity (sWelsEncCtx* pEncCtx) { |
| 781 | 791 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 782 | − int32_t iAlpha = WELS_DIV_ROUND(INT_MULTIPLY, (1 + pWelsSvcRc->iIdrNum)); | |
| 783 | − if (iAlpha < (INT_MULTIPLY/4)) iAlpha = INT_MULTIPLY/4; | |
| 792 | + int32_t iAlpha = WELS_DIV_ROUND (INT_MULTIPLY, (1 + pWelsSvcRc->iIdrNum)); | |
| 793 | + if (iAlpha < (INT_MULTIPLY / 4)) iAlpha = INT_MULTIPLY / 4; | |
| 784 | 794 | |
| 785 | 795 | int64_t iIntraCmplx = pWelsSvcRc->iQStep * pWelsSvcRc->iFrameDqBits; |
| 786 | − pWelsSvcRc->iIntraComplexity = WELS_DIV_ROUND(((INT_MULTIPLY - iAlpha) * pWelsSvcRc->iIntraComplexity + iAlpha * iIntraCmplx), INT_MULTIPLY); | |
| 796 | + pWelsSvcRc->iIntraComplexity = WELS_DIV_ROUND (((INT_MULTIPLY - iAlpha) * pWelsSvcRc->iIntraComplexity + iAlpha * | |
| 797 | + iIntraCmplx), INT_MULTIPLY); | |
| 787 | 798 | pWelsSvcRc->iIntraMbCount = pWelsSvcRc->iNumberMbFrame; |
| 788 | 799 | |
| 789 | 800 | pWelsSvcRc->iIdrNum++; |
| @@ -799,14 +810,15 @@ void RcUpdateFrameComplexity (sWelsEncCtx* pEncCtx) { · 9 unmodified lines | ||
| 799 | 810 | if (0 == pTOverRc->iPFrameNum) { |
| 800 | 811 | pTOverRc->iLinearCmplx = ((int64_t)pWelsSvcRc->iFrameDqBits) * pWelsSvcRc->iQStep; |
| 801 | 812 | } else { |
| 802 | − pTOverRc->iLinearCmplx = WELS_DIV_ROUND64((LINEAR_MODEL_DECAY_FACTOR * (int64_t)pTOverRc->iLinearCmplx | |
| 803 | − + (INT_MULTIPLY - LINEAR_MODEL_DECAY_FACTOR) * (int64_t)(pWelsSvcRc->iFrameDqBits * pWelsSvcRc->iQStep)), INT_MULTIPLY); | |
| 813 | + pTOverRc->iLinearCmplx = WELS_DIV_ROUND64 ((LINEAR_MODEL_DECAY_FACTOR * (int64_t)pTOverRc->iLinearCmplx | |
| 814 | + + (INT_MULTIPLY - LINEAR_MODEL_DECAY_FACTOR) * (int64_t) (pWelsSvcRc->iFrameDqBits * pWelsSvcRc->iQStep)), | |
| 815 | + INT_MULTIPLY); | |
| 804 | 816 | } |
| 805 | − int32_t iAlpha = WELS_DIV_ROUND(INT_MULTIPLY, (1 + pTOverRc->iPFrameNum)); | |
| 817 | + int32_t iAlpha = WELS_DIV_ROUND (INT_MULTIPLY, (1 + pTOverRc->iPFrameNum)); | |
| 806 | 818 | if (iAlpha < SMOOTH_FACTOR_MIN_VALUE) |
| 807 | 819 | iAlpha = SMOOTH_FACTOR_MIN_VALUE; |
| 808 | − pTOverRc->iFrameCmplxMean = WELS_DIV_ROUND(((INT_MULTIPLY - iAlpha) * pTOverRc->iFrameCmplxMean + iAlpha * | |
| 809 | − pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity), INT_MULTIPLY); | |
| 820 | + pTOverRc->iFrameCmplxMean = WELS_DIV_ROUND (((INT_MULTIPLY - iAlpha) * pTOverRc->iFrameCmplxMean + iAlpha * | |
| 821 | + pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity), INT_MULTIPLY); | |
| 810 | 822 | |
| 811 | 823 | pTOverRc->iPFrameNum++; |
| 812 | 824 | if (pTOverRc->iPFrameNum > 255) |
| @@ -951,8 +963,8 @@ void WelsRcPictureInitDisable (void* pCtx) { · 138 unmodified lines | ||
| 951 | 963 | pEncCtx->iGlobalQp = RcCalculateCascadingQp (pEncCtx, kiQp); |
| 952 | 964 | |
| 953 | 965 | if (pEncCtx->pSvcParam->bEnableAdaptiveQuant && (pEncCtx->eSliceType == P_SLICE)) { |
| 954 | − pEncCtx->iGlobalQp = WELS_CLIP3 ( (pEncCtx->iGlobalQp *INT_MULTIPLY - | |
| 955 | − pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp)/INT_MULTIPLY, GOM_MIN_QP_MODE, GOM_MAX_QP_MODE); | |
| 966 | + pEncCtx->iGlobalQp = WELS_CLIP3 ((pEncCtx->iGlobalQp * INT_MULTIPLY - | |
| 967 | + pEncCtx->pVaa->sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp) / INT_MULTIPLY, GOM_MIN_QP_MODE, GOM_MAX_QP_MODE); | |
| 956 | 968 | } else { |
| 957 | 969 | pEncCtx->iGlobalQp = WELS_CLIP3 (pEncCtx->iGlobalQp, 0, 51); |
| 958 | 970 | } |