refine RC
This commit is contained in:
parent
1d2b52e4cc
commit
4fc2b1f636
@ -85,7 +85,7 @@ int32_t InitFunctionPointers (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* _param,
|
||||
void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType,const int32_t kiDidx);
|
||||
void LoadBackFrameNum(sWelsEncCtx* pEncCtx,const int32_t kiDidx);
|
||||
|
||||
EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum,const int32_t kiDidx);
|
||||
EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum,const int32_t kiDidx, bool bSkipFrameFlag);
|
||||
void InitBitStream(sWelsEncCtx* pEncCtx);
|
||||
int32_t GetTemporalLevel (SSpatialLayerInternal* fDlp, const int32_t kiFrameNum, const int32_t kiGopSize);
|
||||
/*!
|
||||
|
@ -172,7 +172,6 @@ typedef struct TagWelsEncCtx {
|
||||
int32_t iCheckWindowInterval;
|
||||
int32_t iCheckWindowIntervalShift;
|
||||
bool bCheckWindowShiftResetFlag;
|
||||
int32_t iSkipFrameFlag; //_GOM_RC_
|
||||
int32_t iContinualSkipFrames;
|
||||
int32_t iGlobalQp; // global qp
|
||||
|
||||
|
@ -87,7 +87,6 @@ typedef struct TagDLayerParam {
|
||||
float fInputFrameRate; // input frame rate
|
||||
float fOutputFrameRate; // output frame rate
|
||||
// uint16_t uiIdrPicId; // IDR picture id: [0, 65535], this one is used for LTR
|
||||
int32_t iSkipFrameFlag; //_GOM_RC_
|
||||
int32_t iCodingIndex;
|
||||
int32_t iFrameIndex; // count how many frames elapsed during coding context currently
|
||||
bool bEncCurFrmAsIdrFlag;
|
||||
|
@ -237,12 +237,11 @@ float fLatestFrameRate; // TODO: to complete later
|
||||
} SWelsSvcRc;
|
||||
|
||||
typedef void (*PWelsRCPictureInitFunc) (sWelsEncCtx* pCtx,long long uiTimeStamp);
|
||||
typedef void (*PWelsRCPictureDelayJudgeFunc) (sWelsEncCtx* pCtx, EVideoFrameType eFrameType, long long uiTimeStamp,int32_t iDidIdx);
|
||||
typedef void (*PWelsRCPictureDelayJudgeFunc) (sWelsEncCtx* pCtx,long long uiTimeStamp,int32_t iDidIdx);
|
||||
typedef void (*PWelsRCPictureInfoUpdateFunc) (sWelsEncCtx* pCtx, int32_t iLayerSize);
|
||||
typedef void (*PWelsRCMBInfoUpdateFunc) (sWelsEncCtx* pCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* pSlice);
|
||||
typedef void (*PWelsRCMBInitFunc) (sWelsEncCtx* pCtx, SMB* pCurMb, SSlice* pSlice);
|
||||
typedef bool (*PWelsCheckFrameSkipBasedMaxbrFunc) (sWelsEncCtx* pCtx, int32_t iSpatialNum, EVideoFrameType eFrameType,
|
||||
const uint32_t uiTimeStamp);
|
||||
typedef void (*PWelsCheckFrameSkipBasedMaxbrFunc) (sWelsEncCtx* pCtx, const long long uiTimeStamp, int32_t iDidIdx);
|
||||
typedef void (*PWelsUpdateBufferWhenFrameSkippedFunc)(sWelsEncCtx* pCtx, int32_t iSpatialNum);
|
||||
typedef void (*PWelsUpdateMaxBrCheckWindowStatusFunc)(sWelsEncCtx* pCtx, int32_t iSpatialNum, const long long uiTimeStamp);
|
||||
typedef bool (*PWelsRCPostFrameSkippingFunc)(sWelsEncCtx* pCtx, const int32_t iDid, const long long uiTimeStamp);
|
||||
@ -260,8 +259,7 @@ PWelsUpdateMaxBrCheckWindowStatusFunc pfWelsUpdateMaxBrWindowStatus;
|
||||
PWelsRCPostFrameSkippingFunc pfWelsRcPostFrameSkipping;
|
||||
} SWelsRcFunc;
|
||||
|
||||
bool CheckFrameSkipBasedMaxbr (sWelsEncCtx* pCtx, int32_t iSpatialNum, EVideoFrameType eFrameType,
|
||||
const uint32_t uiTimeStamp);
|
||||
void CheckFrameSkipBasedMaxbr (sWelsEncCtx* pCtx,const long long uiTimeStamp, int32_t iDidIdx);
|
||||
void UpdateBufferWhenFrameSkipped(sWelsEncCtx* pCtx, int32_t iSpatialNum);
|
||||
void UpdateMaxBrCheckWindowStatus(sWelsEncCtx* pCtx, int32_t iSpatialNum, const long long uiTimeStamp);
|
||||
bool WelsRcPostFrameSkipping(sWelsEncCtx* pCtx, const int32_t iDid, const long long uiTimeStamp);
|
||||
@ -271,7 +269,8 @@ void RcTraceFrameBits (sWelsEncCtx* pEncCtx, long long uiTimeStamp);
|
||||
void WelsRcInitModule (sWelsEncCtx* pCtx, RC_MODES iRcMode);
|
||||
void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode);
|
||||
void WelsRcFreeMemory (sWelsEncCtx* pCtx);
|
||||
|
||||
bool WelsRcCheckFrameStatus (sWelsEncCtx* pEncCtx,long long uiTimeStamp,int32_t iSpatialNum);
|
||||
bool WelsUpdateSkipFrameStatus();
|
||||
long long GetTimestampForRc(const long long uiTimeStamp, const long long uiLastTimeStamp, const float fFrameRate);
|
||||
|
||||
}
|
||||
|
@ -330,12 +330,11 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType, c
|
||||
#endif//FRAME_INFO_OUTPUT
|
||||
}
|
||||
|
||||
EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum, const int32_t kiDidx) {
|
||||
EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum, const int32_t kiDidx, bool bSkipFrameFlag) {
|
||||
SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam;
|
||||
SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx];
|
||||
EVideoFrameType iFrameType = videoFrameTypeInvalid;
|
||||
bool bSceneChangeFlag = false;
|
||||
int32_t iSkipFrameFlag = pSvcParam->bSimulcastAVC?pParamInternal->iSkipFrameFlag:pEncCtx->iSkipFrameFlag;
|
||||
if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
|
||||
if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
|
||||
(kiSpatialNum < pSvcParam->iSpatialLayerNum)) {
|
||||
@ -365,8 +364,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum
|
||||
} else {
|
||||
iFrameType = videoFrameTypeP;
|
||||
}
|
||||
if (videoFrameTypeP == iFrameType && iSkipFrameFlag > 0) {
|
||||
pParamInternal->iSkipFrameFlag = 0;
|
||||
if (videoFrameTypeP == iFrameType && bSkipFrameFlag) {
|
||||
iFrameType = videoFrameTypeSkip;
|
||||
} else if (videoFrameTypeIDR == iFrameType) {
|
||||
pParamInternal->iCodingIndex = 0;
|
||||
@ -389,8 +387,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum
|
||||
iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
|
||||
|| pParamInternal->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
|
||||
|
||||
if (videoFrameTypeP == iFrameType && iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
|
||||
pParamInternal->iSkipFrameFlag = 0;
|
||||
if (videoFrameTypeP == iFrameType && bSkipFrameFlag) { // for frame skip, 1/5/2010
|
||||
iFrameType = videoFrameTypeSkip;
|
||||
} else if (videoFrameTypeIDR == iFrameType) {
|
||||
pParamInternal->iCodingIndex = 0;
|
||||
|
@ -1163,7 +1163,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p
|
||||
const int32_t kiMbW = (pDlayer->iVideoWidth + 0x0f) >> 4;
|
||||
const int32_t kiMbH = (pDlayer->iVideoHeight + 0x0f) >> 4;
|
||||
|
||||
pParamInternal->iSkipFrameFlag = 0;
|
||||
pParamInternal->iCodingIndex = 0;
|
||||
pParamInternal->iFrameIndex = 0;
|
||||
pParamInternal->iFrameNum = 0;
|
||||
@ -3144,7 +3143,6 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) {
|
||||
for (int32_t iDid = 0; iDid < pCtx->pSvcParam->iSpatialLayerNum; iDid++) {
|
||||
SSpatialLayerInternal* pParamInternal = &pCtx->pSvcParam->sDependencyLayers[iDid];
|
||||
pParamInternal->iCodingIndex = 0;
|
||||
pParamInternal->iSkipFrameFlag = 0;
|
||||
pParamInternal->iFrameIndex = 0;
|
||||
pParamInternal->iFrameNum = 0;
|
||||
pParamInternal->iPOC = 0;
|
||||
@ -3454,14 +3452,9 @@ EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsIn
|
||||
int32_t& iLayerNum, int32_t& iFrameSize, long long uiTimeStamp) {
|
||||
SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
|
||||
SSpatialPicIndex* pSpatialIndexMap = &pCtx->sSpatialIndexMap[0];
|
||||
if (!pSvcParam->bSimulcastAVC) {
|
||||
pCtx->iSkipFrameFlag = false;
|
||||
for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) {
|
||||
if (pCtx->pSvcParam->sDependencyLayers[ (pSpatialIndexMap + iDid)->iDid].iSkipFrameFlag)
|
||||
pCtx->iSkipFrameFlag = 1;
|
||||
}
|
||||
}
|
||||
EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid);
|
||||
|
||||
bool bSkipFrameFlag = WelsRcCheckFrameStatus (pCtx,uiTimeStamp,iSpatialNum);
|
||||
EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid, bSkipFrameFlag);
|
||||
|
||||
if (eFrameType == videoFrameTypeSkip) {
|
||||
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
@ -3475,27 +3468,12 @@ EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsIn
|
||||
else {
|
||||
if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) {
|
||||
for (int32_t i = 0; i < iSpatialNum; i++) {
|
||||
pCtx->pSvcParam->sDependencyLayers[i].iSkipFrameFlag = false;
|
||||
pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, (pSpatialIndexMap + i)->iDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
|
||||
bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType,
|
||||
(uint32_t)uiTimeStamp);
|
||||
if (bSkip) {
|
||||
eFrameType = videoFrameTypeSkip;
|
||||
pLayerBsInfo->eFrameType = videoFrameTypeSkip;
|
||||
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
"[Rc] Frame timestamp = %lld, skip one frame due to max_br, continual skipped %d frames",
|
||||
uiTimeStamp, pCtx->iContinualSkipFrames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eFrameType != videoFrameTypeSkip) {
|
||||
SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid];
|
||||
pCtx->iContinualSkipFrames = 0;
|
||||
iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iCurDid], pParamInternal->iCodingIndex,
|
||||
|
@ -523,7 +523,8 @@ void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
|
||||
pSOverRc->iEndMbSlice += (pSliceInLayer[i].iCountMbNumInSlice - 1);
|
||||
pSOverRc->iTotalQpSlice = 0;
|
||||
pSOverRc->iTotalMbSlice = 0;
|
||||
pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * pSliceInLayer[i].iCountMbNumInSlice, INT_MULTIPLY);
|
||||
pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * pSliceInLayer[i].iCountMbNumInSlice,
|
||||
INT_MULTIPLY);
|
||||
pSOverRc->iFrameBitsSlice = 0;
|
||||
pSOverRc->iGomBitsSlice = 0;
|
||||
}
|
||||
@ -684,7 +685,6 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|
||||
SRCTemporal* pTOverRc = pWelsSvcRc->pTemporalOverRc;
|
||||
const int32_t kiOutputBits = pWelsSvcRc->iBitsPerFrame;
|
||||
const int32_t kiOutputMaxBits = pWelsSvcRc->iMaxBitsPerFrame;
|
||||
SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
|
||||
//condition 1: whole pBuffer fullness
|
||||
pWelsSvcRc->iBufferFullnessSkip += (pWelsSvcRc->iFrameDqBits - kiOutputBits);
|
||||
pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW] += (pWelsSvcRc->iFrameDqBits - kiOutputMaxBits);
|
||||
@ -704,10 +704,10 @@ void RcVBufferCalculationSkip (sWelsEncCtx* pEncCtx) {
|
||||
if ((pWelsSvcRc->iBufferFullnessSkip > pWelsSvcRc->iBufferSizeSkip
|
||||
&& pWelsSvcRc->iAverageFrameQp > pWelsSvcRc->iSkipQpValue)
|
||||
|| (dIncPercent > pWelsSvcRc->iRcVaryPercentage)) {
|
||||
pDLayerParamInternal->iSkipFrameFlag = 1;
|
||||
pWelsSvcRc->bSkipFlag = true;
|
||||
}
|
||||
}
|
||||
void WelsRcFrameDelayJudge (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, long long uiTimeStamp,int32_t iDidIdx) {
|
||||
void CheckFrameSkipBasedMaxbr (sWelsEncCtx* pEncCtx, const long long uiTimeStamp, int32_t iDidIdx) {
|
||||
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[iDidIdx];
|
||||
SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[iDidIdx];
|
||||
//SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
|
||||
@ -768,60 +768,91 @@ void WelsRcFrameDelayJudge (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, lo
|
||||
}
|
||||
}
|
||||
|
||||
bool WelsRcCheckFrameStatus (sWelsEncCtx* pEncCtx, long long uiTimeStamp, int32_t iSpatialNum) {
|
||||
|
||||
//loop each layer to check if have skip frame when RC and frame skip enable (maxbr>0)
|
||||
bool CheckFrameSkipBasedMaxbr (sWelsEncCtx* pEncCtx, int32_t iSpatialNum, EVideoFrameType eFrameType,
|
||||
const uint32_t uiTimeStamp) {
|
||||
bool bSkipMustFlag = false;
|
||||
int32_t iDidIdx = pEncCtx->uiDependencyId;
|
||||
SSpatialPicIndex* pSpatialIndexMap = &pEncCtx->sSpatialIndexMap[0];
|
||||
if (!pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge)
|
||||
return false;
|
||||
if( pEncCtx->pSvcParam->bSimulcastAVC){
|
||||
if (UNSPECIFIED_BIT_RATE == pEncCtx->pSvcParam->sSpatialLayers[iDidIdx].iMaxSpatialBitrate)
|
||||
return false;
|
||||
|
||||
pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, eFrameType, uiTimeStamp,iDidIdx);
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
|
||||
pEncCtx->iContinualSkipFrames++;
|
||||
SSpatialPicIndex* pSpatialIndexMap = &pEncCtx->sSpatialIndexMap[0];
|
||||
|
||||
//simul_cast AVC control
|
||||
if (pEncCtx->pSvcParam->bSimulcastAVC) {
|
||||
//check target_br skip and update info
|
||||
int32_t iDidIdx = pSpatialIndexMap->iDid;
|
||||
if (pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge) {
|
||||
pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, uiTimeStamp, iDidIdx);
|
||||
}
|
||||
}else{
|
||||
for(int32_t i = 0;i<iSpatialNum;i++){
|
||||
iDidIdx = (pSpatialIndexMap + i)->iDid;
|
||||
if (UNSPECIFIED_BIT_RATE == pEncCtx->pSvcParam->sSpatialLayers[iDidIdx].iMaxSpatialBitrate)
|
||||
break;
|
||||
pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, eFrameType, uiTimeStamp,iDidIdx);
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
|
||||
pEncCtx->iContinualSkipFrames++;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
|
||||
break;
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
}
|
||||
//check max_br skip
|
||||
if (pEncCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
|
||||
if ((!bSkipMustFlag)&&(pEncCtx->pSvcParam->sSpatialLayers[iDidIdx].iMaxSpatialBitrate != UNSPECIFIED_BIT_RATE)) {
|
||||
pEncCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pEncCtx, uiTimeStamp, iDidIdx);
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bSkipMustFlag) {
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
|
||||
pEncCtx->iContinualSkipFrames++;
|
||||
return true;
|
||||
}
|
||||
} else { //SVC control
|
||||
for (int32_t i = 0; i < iSpatialNum; i++) {
|
||||
int32_t iDidIdx = (pSpatialIndexMap + i)->iDid;
|
||||
//check target_br skip and update info
|
||||
|
||||
if (pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge) {
|
||||
pEncCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pEncCtx, uiTimeStamp, iDidIdx);
|
||||
}
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
}
|
||||
//check max_br skip
|
||||
if (pEncCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
|
||||
if ((!bSkipMustFlag)&&(pEncCtx->pSvcParam->sSpatialLayers[iDidIdx].iMaxSpatialBitrate != UNSPECIFIED_BIT_RATE)) {
|
||||
pEncCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pEncCtx, uiTimeStamp, iDidIdx);
|
||||
if (true == pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag) {
|
||||
bSkipMustFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bSkipMustFlag) {
|
||||
pEncCtx->iContinualSkipFrames++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bSkipMustFlag) {
|
||||
for (int32_t i = 0; i < iSpatialNum; i++) {
|
||||
int32_t iDidIdx = (pSpatialIndexMap + i)->iDid;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
|
||||
pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return bSkipMustFlag;
|
||||
return false;
|
||||
}
|
||||
|
||||
void UpdateBufferWhenFrameSkipped (sWelsEncCtx* pEncCtx, int32_t iCurDid) {
|
||||
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[iCurDid];
|
||||
const int32_t kiOutputBits = pWelsSvcRc->iBitsPerFrame;
|
||||
const int32_t kiOutputMaxBits = pWelsSvcRc->iMaxBitsPerFrame;
|
||||
pWelsSvcRc->iBufferFullnessSkip = pWelsSvcRc->iBufferFullnessSkip - kiOutputBits;
|
||||
pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW] -= kiOutputMaxBits;
|
||||
pWelsSvcRc->iBufferMaxBRFullness[ODD_TIME_WINDOW] -= kiOutputMaxBits;
|
||||
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
"[Rc] bits in buffer = %" PRId64 ", bits in Max bitrate buffer = %" PRId64,
|
||||
pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW]);
|
||||
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[iCurDid];
|
||||
const int32_t kiOutputBits = pWelsSvcRc->iBitsPerFrame;
|
||||
const int32_t kiOutputMaxBits = pWelsSvcRc->iMaxBitsPerFrame;
|
||||
pWelsSvcRc->iBufferFullnessSkip = pWelsSvcRc->iBufferFullnessSkip - kiOutputBits;
|
||||
pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW] -= kiOutputMaxBits;
|
||||
pWelsSvcRc->iBufferMaxBRFullness[ODD_TIME_WINDOW] -= kiOutputMaxBits;
|
||||
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
"[Rc] bits in buffer = %" PRId64 ", bits in Max bitrate buffer = %" PRId64,
|
||||
pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW]);
|
||||
|
||||
pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0);
|
||||
pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0);
|
||||
|
||||
pWelsSvcRc->iRemainingBits += kiOutputBits;
|
||||
pWelsSvcRc->iSkipFrameNum++;
|
||||
pWelsSvcRc->iSkipFrameInVGop++;
|
||||
pWelsSvcRc->iRemainingBits += kiOutputBits;
|
||||
pWelsSvcRc->iSkipFrameNum++;
|
||||
pWelsSvcRc->iSkipFrameInVGop++;
|
||||
|
||||
pEncCtx->iContinualSkipFrames++;
|
||||
if ((pEncCtx->iContinualSkipFrames % 3) == 0) {
|
||||
@ -911,7 +942,7 @@ void RcVBufferCalculationPadding (sWelsEncCtx* pEncCtx) {
|
||||
|
||||
void RcTraceFrameBits (sWelsEncCtx* pEncCtx, long long uiTimeStamp) {
|
||||
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
|
||||
SSpatialLayerInternal *pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
|
||||
SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
|
||||
if (pWelsSvcRc->iPredFrameBit != 0)
|
||||
pWelsSvcRc->iPredFrameBit = (int32_t) (LAST_FRAME_PREDICT_WEIGHT * pWelsSvcRc->iFrameDqBits +
|
||||
(1 - LAST_FRAME_PREDICT_WEIGHT) * pWelsSvcRc->iPredFrameBit);
|
||||
@ -984,7 +1015,7 @@ void RcUpdateFrameComplexity (sWelsEncCtx* pEncCtx) {
|
||||
pTOverRc->iLinearCmplx = ((int64_t)pWelsSvcRc->iFrameDqBits) * iQStep;
|
||||
} else {
|
||||
pTOverRc->iLinearCmplx = WELS_DIV_ROUND64 ((LINEAR_MODEL_DECAY_FACTOR * (int64_t)pTOverRc->iLinearCmplx
|
||||
+ (INT_MULTIPLY - LINEAR_MODEL_DECAY_FACTOR) *((int64_t)pWelsSvcRc->iFrameDqBits * iQStep)),
|
||||
+ (INT_MULTIPLY - LINEAR_MODEL_DECAY_FACTOR) * ((int64_t)pWelsSvcRc->iFrameDqBits * iQStep)),
|
||||
INT_MULTIPLY);
|
||||
}
|
||||
int32_t iAlpha = WELS_DIV_ROUND (INT_MULTIPLY, (1 + pTOverRc->iPFrameNum));
|
||||
@ -1286,13 +1317,10 @@ void InitRcModuleTimeStamp (sWelsEncCtx* pEncCtx) {
|
||||
pWelsSvcRc->iAvgCost2Bits = 1;
|
||||
pWelsSvcRc->iSkipBufferRatio = SKIP_RATIO;
|
||||
}
|
||||
void WelsRcFrameDelayJudgeTimeStamp (sWelsEncCtx* pEncCtx, EVideoFrameType eFrameType, long long uiTimeStamp,int32_t iDidIdx) {
|
||||
void WelsRcFrameDelayJudgeTimeStamp (sWelsEncCtx* pEncCtx, long long uiTimeStamp, int32_t iDidIdx) {
|
||||
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[iDidIdx];
|
||||
SSpatialLayerConfig* pDLayerConfig = &pEncCtx->pSvcParam->sSpatialLayers[iDidIdx];
|
||||
|
||||
if (pDLayerConfig->iSpatialBitrate > pDLayerConfig->iMaxSpatialBitrate)
|
||||
pDLayerConfig->iSpatialBitrate = pDLayerConfig->iMaxSpatialBitrate;
|
||||
|
||||
int32_t iBitRate = pDLayerConfig->iSpatialBitrate;
|
||||
int32_t iEncTimeInv = (pWelsSvcRc->uiLastTimeStamp == 0) ? 0 : (int32_t) (uiTimeStamp - pWelsSvcRc->uiLastTimeStamp);
|
||||
if ((iEncTimeInv < 0) || (iEncTimeInv > 1000)) {
|
||||
@ -1302,11 +1330,6 @@ void WelsRcFrameDelayJudgeTimeStamp (sWelsEncCtx* pEncCtx, EVideoFrameType eFram
|
||||
int32_t iSentBits = (int32_t) ((double)iBitRate * iEncTimeInv * (1.0E-3) + 0.5);
|
||||
iSentBits = WELS_MAX (iSentBits, 0);
|
||||
|
||||
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
"WelsRcFrameDelayJudgeTimeStamp AiDidIdx = %d,iSkipFrameNum = %d,buffer = %" PRId64
|
||||
",threadhold = %d,bitrate = %d,iSentBits = %d,lasttimestamp = %lld,timestamp=%lld\n",iDidIdx,
|
||||
pWelsSvcRc->iSkipFrameNum, pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferSizeSkip, iBitRate, iSentBits,
|
||||
pWelsSvcRc->uiLastTimeStamp, uiTimeStamp);
|
||||
//When bitrate is changed, pBuffer size should be updated
|
||||
pWelsSvcRc->iBufferSizeSkip = WELS_DIV_ROUND (pDLayerConfig->iSpatialBitrate * pWelsSvcRc->iSkipBufferRatio,
|
||||
INT_MULTIPLY);
|
||||
@ -1327,7 +1350,7 @@ void WelsRcFrameDelayJudgeTimeStamp (sWelsEncCtx* pEncCtx, EVideoFrameType eFram
|
||||
}
|
||||
WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
|
||||
"WelsRcFrameDelayJudgeTimeStamp iDidIdx = %d,iSkipFrameNum = %d,buffer = %" PRId64
|
||||
",threadhold = %d,bitrate = %d,iSentBits = %d,lasttimestamp = %lld,timestamp=%lld\n",iDidIdx,
|
||||
",threadhold = %d,bitrate = %d,iSentBits = %d,lasttimestamp = %lld,timestamp=%lld\n", iDidIdx,
|
||||
pWelsSvcRc->iSkipFrameNum, pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferSizeSkip, iBitRate, iSentBits,
|
||||
pWelsSvcRc->uiLastTimeStamp, uiTimeStamp);
|
||||
}
|
||||
@ -1490,7 +1513,7 @@ void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) {
|
||||
break;
|
||||
case RC_BITRATE_MODE:
|
||||
pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom;
|
||||
pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudge;
|
||||
pRcf->pfWelsRcPicDelayJudge = NULL;
|
||||
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom;
|
||||
pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
|
||||
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
|
||||
@ -1501,7 +1524,7 @@ void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) {
|
||||
break;
|
||||
case RC_BITRATE_MODE_POST_SKIP:
|
||||
pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom;
|
||||
pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudge;
|
||||
pRcf->pfWelsRcPicDelayJudge = NULL;
|
||||
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom;
|
||||
pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
|
||||
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
|
||||
@ -1524,7 +1547,7 @@ void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) {
|
||||
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
|
||||
}
|
||||
pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudgeTimeStamp;
|
||||
pRcf->pfWelsCheckSkipBasedMaxbr = CheckFrameSkipBasedMaxbr;
|
||||
pRcf->pfWelsCheckSkipBasedMaxbr = NULL;
|
||||
pRcf->pfWelsUpdateBufferWhenSkip = NULL;
|
||||
pRcf->pfWelsUpdateMaxBrWindowStatus = NULL;
|
||||
pRcf->pfWelsRcPostFrameSkipping = NULL;
|
||||
@ -1533,7 +1556,7 @@ void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode) {
|
||||
case RC_QUALITY_MODE:
|
||||
default:
|
||||
pRcf->pfWelsRcPictureInit = WelsRcPictureInitGom;
|
||||
pRcf->pfWelsRcPicDelayJudge = WelsRcFrameDelayJudge;
|
||||
pRcf->pfWelsRcPicDelayJudge = NULL;
|
||||
pRcf->pfWelsRcPictureInfoUpdate = WelsRcPictureInfoUpdateGom;
|
||||
pRcf->pfWelsRcMbInit = WelsRcMbInitGom;
|
||||
pRcf->pfWelsRcMbInfoUpdate = WelsRcMbInfoUpdateGom;
|
||||
@ -1559,7 +1582,7 @@ void WelsRcFreeMemory (sWelsEncCtx* pEncCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
long long GetTimestampForRc(const long long uiTimeStamp, const long long uiLastTimeStamp, const float fFrameRate) {
|
||||
long long GetTimestampForRc (const long long uiTimeStamp, const long long uiLastTimeStamp, const float fFrameRate) {
|
||||
if ((uiLastTimeStamp >= uiTimeStamp) || ((uiTimeStamp == 0) && (uiLastTimeStamp != -1))) {
|
||||
return (uiLastTimeStamp + (int32_t) (1000.0 / fFrameRate));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user