ref: 3e538617cdead5397f61af82dbb7b6eaafdff62c
parent: 78ae48c686376eb6f311807587a6c0d2ffaa27a9
parent: 881fc11c48bb229e344f89f948b011e2e38dc82b
author: ruil2 <ruil2@cisco.com>
date: Tue Feb 23 12:26:20 EST 2016
Merge pull request #2374 from sijchen/for_ts0 [Encoder] fix timestamp = 0 issue when rc mode is BITRATE mode
--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -235,7 +235,7 @@
bool bDependencyRecFlag[MAX_DEPENDENCY_LAYER];
bool bRecFlag;
#endif
-
+ int64_t uiLastTimestamp;
uint32_t GetNeededSpsNum() {
if (0 == sPSOVector.uiNeededSpsNum) {
sPSOVector.uiNeededSpsNum = ((SPS_LISTING & pSvcParam->eSpsPpsIdStrategy) ? (MAX_SPS_COUNT) : (1));
--- a/codec/encoder/core/inc/rc.h
+++ b/codec/encoder/core/inc/rc.h
@@ -272,5 +272,7 @@
void WelsRcInitFuncPointers (sWelsEncCtx* pEncCtx, RC_MODES iRcMode);
void WelsRcFreeMemory (sWelsEncCtx* pCtx);
+long long GetTimestampForRc(const long long uiTimeStamp, const long long uiLastTimeStamp, const float fFrameRate);
+
}
#endif //RC_H
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2582,7 +2582,7 @@
#endif//MEMORY_MONITOR
pCtx->iStatisticsLogInterval = STATISTICS_LOG_INTERVAL_MS;
-
+ pCtx->uiLastTimestamp = -1;
*ppCtx = pCtx;
WelsLog (pLogCtx, WELS_LOG_DEBUG, "WelsInitEncoderExt(), pCtx= 0x%p.", (void*)pCtx);
@@ -3716,7 +3716,7 @@
* \pParam pSrcPic Source Picture
* \return EFrameType (videoFrameTypeIDR/videoFrameTypeI/videoFrameTypeP)
*/
-int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSourcePicture* pSrcPic) {
+int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSourcePicture* pSrcPic ) {
if (pCtx == NULL) {
return ENC_RETURN_MEMALLOCERR;
}
@@ -3756,7 +3756,7 @@
pCtx->iEncoderError = ENC_RETURN_SUCCESS;
pCtx->bCurFrameMarkedAsSceneLtr = false;
pFbi->iLayerNum = 0; // for initialization
- pFbi->uiTimeStamp = pSrcPic->uiTimeStamp;
+ pFbi->uiTimeStamp = GetTimestampForRc(pSrcPic->uiTimeStamp, pCtx->uiLastTimestamp, pCtx->pSvcParam->sSpatialLayers[pCtx->pSvcParam->iSpatialLayerNum-1].fFrameRate);
for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) {
pFbi->sLayerInfo[iNalIdx].eFrameType = videoFrameTypeSkip;
}
@@ -3763,7 +3763,7 @@
// perform csc/denoise/downsample/padding, generate spatial layers
iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic);
if (pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus) {
- pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus (pCtx, iSpatialNum, pSrcPic->uiTimeStamp);
+ pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus (pCtx, iSpatialNum, pFbi->uiTimeStamp);
}
if (iSpatialNum < 1) {
@@ -3809,7 +3809,7 @@
pLayerBsInfo->eFrameType = eFrameType;
WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
"[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames",
- pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
+ pFbi->uiTimeStamp, pCtx->iContinualSkipFrames);
++ iSpatialIdx;
if (pSvcParam->bSimulcastAVC) {
if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip)
@@ -3830,13 +3830,13 @@
//loop each layer to check if have skip frame when RC and frame skip enable
if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType,
- (uint32_t)pSrcPic->uiTimeStamp);
+ (uint32_t)pFbi->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",
- pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
+ pFbi->uiTimeStamp, pCtx->iContinualSkipFrames);
++ iSpatialIdx;
if (pSvcParam->bSimulcastAVC)
continue;
@@ -3968,7 +3968,7 @@
eFrameType); //get reordering syntax used for writing slice header and transmit to encoder.
PrefetchReferencePicture (pCtx, eFrameType); // update reference picture for current pDq layer
- pCtx->pFuncList->pfRc.pfWelsRcPictureInit (pCtx, pSrcPic->uiTimeStamp);
+ pCtx->pFuncList->pfRc.pfWelsRcPictureInit (pCtx, pFbi->uiTimeStamp);
PreprocessSliceCoding (pCtx); // MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer()
//TODO Complexity Calculation here for screen content
@@ -4166,7 +4166,7 @@
}
if (NULL != pCtx->pFuncList->pfRc.pfWelsRcPostFrameSkipping
- && pCtx->pFuncList->pfRc.pfWelsRcPostFrameSkipping (pCtx, iCurDid, pSrcPic->uiTimeStamp)) {
+ && pCtx->pFuncList->pfRc.pfWelsRcPostFrameSkipping (pCtx, iCurDid, pFbi->uiTimeStamp)) {
StackBackEncoderStatus (pCtx, eFrameType);
ClearFrameBsInfo (pCtx, pFbi);
@@ -4182,7 +4182,7 @@
WelsRcPostFrameSkippedUpdate (pCtx, iCurDid);
WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO,
"[Rc] Frame timestamp = %lld, skip one frame due to post skip, continual skipped %d frames",
- pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
+ pFbi->uiTimeStamp, pCtx->iContinualSkipFrames);
pCtx->iEncoderError = ENC_RETURN_SUCCESS;
return ENC_RETURN_SUCCESS;
}
@@ -4200,7 +4200,7 @@
}
pCtx->pFuncList->pfRc.pfWelsRcPictureInfoUpdate (pCtx, iLayerSize);
- RcTraceFrameBits (pCtx, pSrcPic->uiTimeStamp);
+ RcTraceFrameBits (pCtx, pFbi->uiTimeStamp);
pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc[iDidIdx].iAverageFrameQp;
//update scc related
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -1544,4 +1544,11 @@
}
}
+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));
+ }
+ return uiTimeStamp;
+}
+
}//end of namespace
--- a/codec/encoder/plus/inc/welsEncoderExt.h
+++ b/codec/encoder/plus/inc/welsEncoderExt.h
@@ -100,7 +100,7 @@
int InitializeInternal (SWelsSvcCodingParam* argv);
void TraceParamInfo(SEncParamExt *pParam);
void LogStatistics (const int64_t kiCurrentFrameTs,int32_t iMaxDid);
- void UpdateStatistics(const int64_t kiCurrentFrameTs, SFrameBSInfo* pBsInfo, const int64_t kiCurrentFrameMs);
+ void UpdateStatistics(SFrameBSInfo* pBsInfo, const int64_t kiCurrentFrameMs);
sWelsEncCtx* m_pEncContext;
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -415,7 +415,7 @@
return cmUnknownReason;
}
- UpdateStatistics (pSrcPic->uiTimeStamp, pBsInfo, kiCurrentFrameMs);
+ UpdateStatistics (pBsInfo, kiCurrentFrameMs);
///////////////////for test
#ifdef OUTPUT_BIT_STREAM
@@ -566,9 +566,11 @@
}
}
-void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, SFrameBSInfo* pBsInfo,
+void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo,
const int64_t kiCurrentFrameMs) {
+ const int64_t kiCurrentFrameTs = m_pEncContext->uiLastTimestamp = pBsInfo->uiTimeStamp;
+
int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1;
SLayerBSInfo* pLayerInfo = &pBsInfo->sLayerInfo[0];
for (int32_t iDid = 0; iDid <= iMaxDid; iDid++) {
@@ -582,7 +584,7 @@
if ((pLayerInfo->uiLayerType == VIDEO_CODING_LAYER) && (pLayerInfo->uiSpatialId == iDid)) {
eFrameType = pLayerInfo->eFrameType;
for (int32_t iNalIdx = 0; iNalIdx < pLayerInfo->iNalCount; iNalIdx++) {
- kiCurrentFrameSize += pLayerInfo->pNalLengthInByte[iNalIdx];
+ kiCurrentFrameSize += pLayerInfo->pNalLengthInByte[iNalIdx];
}
}
}