fix statistics: updating should be independent with log interval

This commit is contained in:
Sijia Chen 2015-01-27 10:12:51 +08:00
parent f404ce2e56
commit d557578be3
2 changed files with 28 additions and 19 deletions

View File

@ -432,7 +432,8 @@ typedef struct TagEncParamExt {
ECOMPLEXITY_MODE iComplexityMode; ECOMPLEXITY_MODE iComplexityMode;
unsigned int uiIntraPeriod; ///< period of Intra frame unsigned int uiIntraPeriod; ///< period of Intra frame
int iNumRefFrame; ///< number of reference frame used int iNumRefFrame; ///< number of reference frame used
EParameterSetStrategy eSpsPpsIdStrategy; ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional EParameterSetStrategy
eSpsPpsIdStrategy; ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional
bool bPrefixNalAddingCtrl; ///< false:not use Prefix NAL; true: use Prefix NAL bool bPrefixNalAddingCtrl; ///< false:not use Prefix NAL; true: use Prefix NAL
bool bEnableSSEI; ///< false:not use SSEI; true: use SSEI -- TODO: planning to remove the interface of SSEI bool bEnableSSEI; ///< false:not use SSEI; true: use SSEI -- TODO: planning to remove the interface of SSEI
bool bSimulcastAVC; ///< (when encoding more than 1 spatial layer) false: use SVC syntax for higher layers; true: use Simulcast AVC -- coming soon bool bSimulcastAVC; ///< (when encoding more than 1 spatial layer) false: use SVC syntax for higher layers; true: use Simulcast AVC -- coming soon
@ -631,6 +632,8 @@ typedef struct TagVideoEncoderStatistics {
unsigned int uiIDRReqNum; ///< number of IDR requests unsigned int uiIDRReqNum; ///< number of IDR requests
unsigned int uiIDRSentNum; ///< number of actual IDRs sent unsigned int uiIDRSentNum; ///< number of actual IDRs sent
unsigned int uiLTRSentNum; ///< number of LTR sent/marked unsigned int uiLTRSentNum; ///< number of LTR sent/marked
long long iStatisticsTs; ///< Timestamp of updating the statistics
} SEncoderStatistics; // in building, coming soon } SEncoderStatistics; // in building, coming soon
/** /**

View File

@ -583,24 +583,31 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid
pStatistics->uiLTRSentNum ++; pStatistics->uiLTRSentNum ++;
} }
m_pEncContext->iTotalEncodedBits += (kiCurrentFrameSize<<3); m_pEncContext->iTotalEncodedBits += (kiCurrentFrameSize << 3);
const int32_t kiDeltaFrames = static_cast<int32_t> (pStatistics->uiInputFrameCount -
m_pEncContext->iLastStatisticsFrameCount);
if (kiDeltaFrames > m_pEncContext->pSvcParam->fMaxFrameRate) {
const int64_t kiTimeDiff = kiCurrentFrameTs - pStatistics->iStatisticsTs;
if (kiTimeDiff) {
pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -
m_pEncContext->iLastStatisticsFrameCount) * 1000 /
kiTimeDiff);
pStatistics->uiBitRate = static_cast<unsigned int> ((m_pEncContext->iTotalEncodedBits -
m_pEncContext->iLastStatisticsBits) * 1000 / kiTimeDiff);
}
// update variables
pStatistics->iStatisticsTs = kiCurrentFrameTs;
m_pEncContext->iLastStatisticsBits = m_pEncContext->iTotalEncodedBits;
m_pEncContext->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
//TODO: the following statistics will be calculated and added later
//pStatistics->uiLTRSentNum
}
if (m_pEncContext->iStatisticsLogInterval > 0) { if (m_pEncContext->iStatisticsLogInterval > 0) {
int64_t iTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs;
if ((iTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { if ((kiTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) {
if (iTimeDiff) {
pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -
m_pEncContext->iLastStatisticsFrameCount) * 1000 /
iTimeDiff);
pStatistics->uiBitRate = static_cast<unsigned int> ((m_pEncContext->iTotalEncodedBits -
m_pEncContext->iLastStatisticsBits) * 1000 / iTimeDiff);
}
// update variables
m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
m_pEncContext->iLastStatisticsBits = m_pEncContext->iTotalEncodedBits;
m_pEncContext->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"EncoderStatistics: %dx%d, SpeedInMs: %f, fAverageFrameRate=%f, \ "EncoderStatistics: %dx%d, SpeedInMs: %f, fAverageFrameRate=%f, \
LastFrameRate=%f, LatestBitRate=%d, LastFrameQP=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, \ LastFrameRate=%f, LatestBitRate=%d, LastFrameQP=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, \
@ -610,8 +617,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid
pStatistics->fLatestFrameRate, pStatistics->uiBitRate, pStatistics->uiAverageFrameQP, pStatistics->fLatestFrameRate, pStatistics->uiBitRate, pStatistics->uiAverageFrameQP,
pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount, pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount,
pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRReqNum, pStatistics->uiIDRSentNum); pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRReqNum, pStatistics->uiIDRSentNum);
//TODO: the following statistics will be calculated and added later m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
//pStatistics->uiLTRSentNum
} }
} }