diff --git a/codec/common/inc/macros.h b/codec/common/inc/macros.h index 56778779..ed3f3d64 100644 --- 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 diff --git a/codec/encoder/core/inc/rc.h b/codec/encoder/core/inc/rc.h index 2dcd6b8d..1dd35fa8 100644 --- a/codec/encoder/core/inc/rc.h +++ b/codec/encoder/core/inc/rc.h @@ -159,7 +159,7 @@ int32_t iBitRate; int32_t iPreviousBitrate; int32_t iPreviousGopSize; double fFrameRate; -int32_t iBitsPerFrame; // *INT_MULTIPLY +int64_t iBitsPerFrame; // *INT_MULTIPLY double dPreviousFps; // bits allocation and status diff --git a/codec/encoder/core/src/ratectl.cpp b/codec/encoder/core/src/ratectl.cpp index 6d8e7314..ebc95ea6 100644 --- a/codec/encoder/core/src/ratectl.cpp +++ b/codec/encoder/core/src/ratectl.cpp @@ -230,7 +230,7 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) { 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 @@ void RcUpdateBitrateFps (sWelsEncCtx* pEncCtx) { //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; }