History

astyle all

huili2 committed 12 years ago

Commit dc3fae41 parent 101265385 files · +4906 −4701Browse files

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

Unified · Split

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

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