From 21deaddc4820fc2e3ac0eb514bad875c847220ca Mon Sep 17 00:00:00 2001 From: lyao2 Date: Thu, 3 Jul 2014 15:01:48 +0800 Subject: [PATCH] refactor code to eliminate potential div by 0 --- codec/encoder/core/src/ratectl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codec/encoder/core/src/ratectl.cpp b/codec/encoder/core/src/ratectl.cpp index 92bc7de9..8db036f8 100644 --- a/codec/encoder/core/src/ratectl.cpp +++ b/codec/encoder/core/src/ratectl.cpp @@ -694,12 +694,11 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) { //condition 1: whole pBuffer fullness pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits); //condition 2: VGOP bits constraint - const int32_t kiVGopBits = WELS_DIV_ROUND (pWelsSvcRc->iBitsPerFrame * VGOP_SIZE, INT_MULTIPLY); int32_t iVGopBitsPred = 0; for (int32_t i = pWelsSvcRc->iFrameCodedInVGop + 1; i < VGOP_SIZE; i++) iVGopBitsPred += pTOverRc[pWelsSvcRc->iTlOfFrames[i]].iMinBitsTl; iVGopBitsPred -= pWelsSvcRc->iRemainingBits; - double dIncPercent = iVGopBitsPred * 100.0 / kiVGopBits - (double)VGOP_BITS_PERCENTAGE_DIFF; + double dIncPercent = iVGopBitsPred * 100.0 * INT_MULTIPLY / (pWelsSvcRc->iBitsPerFrame * VGOP_SIZE) - (double)VGOP_BITS_PERCENTAGE_DIFF; if ((pWelsSvcRc->iBufferFullnessSkip > pWelsSvcRc->iBufferSizeSkip && pWelsSvcRc->iAverageFrameQp > pWelsSvcRc->iSkipQpValue)