ref: cd75541c8ffb5cd7e2f056b851fb8a255885a3bb
parent: 539818101f38563196f7be1ba6b153e6b33e3f52
parent: 0d5db3d986cd5048f9655fcd0b9c580feb6dd143
author: HaiboZhu <[email protected]>
date: Thu Dec 31 04:55:58 EST 2015
Merge pull request #2323 from ruil2/rc_timestamp resolve abnormal timestamp(rollback or jump case)
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -193,10 +193,10 @@
n = 0;
while (n <= kiHighestTid) {
pTOverRc[n].iTlayerWeight = iWeightArray[kiDecompositionStages][n];
- pTOverRc[n].iMinQp = pWelsSvcRc->iMinQp + (n<<1);
- pTOverRc[n].iMinQp = WELS_CLIP3(pTOverRc[n].iMinQp, 0, 51);
- pTOverRc[n].iMaxQp = pWelsSvcRc->iMaxQp + (n<<1);
- pTOverRc[n].iMaxQp = WELS_CLIP3(pTOverRc[n].iMaxQp, pTOverRc[n].iMinQp, 51);
+ pTOverRc[n].iMinQp = pWelsSvcRc->iMinQp + (n << 1);
+ pTOverRc[n].iMinQp = WELS_CLIP3 (pTOverRc[n].iMinQp, 0, 51);
+ pTOverRc[n].iMaxQp = pWelsSvcRc->iMaxQp + (n << 1);
+ pTOverRc[n].iMaxQp = WELS_CLIP3 (pTOverRc[n].iMaxQp, pTOverRc[n].iMinQp, 51);
++ n;
}
//Calculate the frame index for the current frame and its reference frame
@@ -660,7 +660,7 @@
int64_t iLeftBits = pSOverRc->iTargetBitsSlice - pSOverRc->iFrameBitsSlice;
int64_t iTargetLeftBits = iLeftBits + pSOverRc->iGomBitsSlice - pSOverRc->iGomTargetBits;
- if ((iLeftBits <= 0)||(iTargetLeftBits <=0)) {
+ if ((iLeftBits <= 0) || (iTargetLeftBits <= 0)) {
pSOverRc->iCalculatedQpSlice += 2;
} else {
//globe decision
@@ -1076,7 +1076,7 @@
const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
pSOverRc->iBsPosSlice = BsGetBitsPos (bs);
- if((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE)&&(pEncCtx->eSliceType == I_SLICE)){
+ if ((pEncCtx->pSvcParam->iRCMode == RC_BITRATE_MODE) && (pEncCtx->eSliceType == I_SLICE)) {
pCurMb->uiLumaQp = pEncCtx->iGlobalQp;
pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
return;
@@ -1288,6 +1288,10 @@
int32_t iBitRate = pDLayerConfig->iSpatialBitrate;
int32_t iEncTimeInv = (pWelsSvcRc->uiLastTimeStamp == 0) ? 0 : (int32_t) (uiTimeStamp - pWelsSvcRc->uiLastTimeStamp);
+ if ((iEncTimeInv < 0) || (iEncTimeInv > 1000)) {
+ pWelsSvcRc->uiLastTimeStamp = uiTimeStamp - 1000.0 / pDLayerConfig->fFrameRate;
+ iEncTimeInv = 1000.0 / pDLayerConfig->fFrameRate;
+ }
int32_t iSentBits = (int32_t) ((double)iBitRate * iEncTimeInv * (1.0E-3) + 0.5);
iSentBits = WELS_MAX (iSentBits, 0);