ref: d3c8ade8d071c9ce305ccc8d3d7e0e0e40f45ff5
parent: 2dbb757d3009acdbf7acbaf0d211e7e6efb212f3
author: dong zhang <[email protected]>
date: Mon Oct 27 05:54:44 EDT 2014
fix Rc int32_t bitrate overflow
--- a/codec/common/inc/macros.h
+++ b/codec/common/inc/macros.h
@@ -116,6 +116,10 @@
#define WELS_ROUND(x) ((int32_t)(0.5+(x)))
#endif//WELS_ROUND
+#ifndef WELS_ROUND64
+#define WELS_ROUND64(x) ((int64_t)(0.5+(x)))
+#endif//WELS_ROUND
+
#ifndef WELS_DIV_ROUND
#define WELS_DIV_ROUND(x,y) ((int32_t)((y)==0?((x)/((y)+1)):(((y)/2+(x))/(y))))
#endif//WELS_DIV_ROUND
--- a/codec/encoder/core/inc/rc.h
+++ b/codec/encoder/core/inc/rc.h
@@ -159,7 +159,7 @@
int32_t iPreviousBitrate;
int32_t iPreviousGopSize;
double fFrameRate;
-int32_t iBitsPerFrame; // *INT_MULTIPLY
+int64_t iBitsPerFrame; // *INT_MULTIPLY
double dPreviousFps;
// bits allocation and status
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -230,7 +230,7 @@
SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
const int32_t kiGopSize = (1 << pDLayerParamInternal->iDecompositionStages);
const int32_t kiHighestTid = pDLayerParamInternal->iHighestTemporalId;
- int32_t input_iBitsPerFrame = WELS_ROUND (pDLayerParam->iSpatialBitrate * INT_MULTIPLY /
+ int64_t input_iBitsPerFrame = WELS_ROUND64 (((int64_t)pDLayerParam->iSpatialBitrate) * INT_MULTIPLY /
pDLayerParamInternal->fInputFrameRate);
const int32_t kiGopBits = WELS_DIV_ROUND (input_iBitsPerFrame * kiGopSize, INT_MULTIPLY);
int32_t i;
@@ -255,7 +255,7 @@
//change remaining bits
if (pWelsSvcRc->iBitsPerFrame > REMAIN_BITS_TH)
- pWelsSvcRc->iRemainingBits = pWelsSvcRc->iRemainingBits * input_iBitsPerFrame / pWelsSvcRc->iBitsPerFrame;
+ pWelsSvcRc->iRemainingBits = (int32_t) (pWelsSvcRc->iRemainingBits * input_iBitsPerFrame / pWelsSvcRc->iBitsPerFrame);
pWelsSvcRc->iBitsPerFrame = input_iBitsPerFrame;
}