History

fix bitrate overflow issue when running for long time

ruil2 committed 8 years ago

Commit e1f73c61 parent b90f8fc1 file · +13 −22Browse files

Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/plus/src/welsEncoderExt.cpp+13−22
@@ -378,14 +378,16 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn · 377 unmodified lines
378378 return cmInitParaError;
379379 }
380380 if (kpSrcPic->iColorFormat != videoFormatI420) {
381− WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), wrong iColorFormat %d", kpSrcPic->iColorFormat);
381+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), wrong iColorFormat %d",
382+ kpSrcPic->iColorFormat);
382383 return cmInitParaError;
383384 }
384385
385386 const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
386387
387388 if (kiEncoderReturn != cmResultSuccess) {
388− WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), kiEncoderReturn %d", kiEncoderReturn);
389+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::EncodeFrame(), kiEncoderReturn %d",
390+ kiEncoderReturn);
389391 return kiEncoderReturn;
390392 }
391393
@@ -644,11 +646,10 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 252 unmodified lines
644646 pStatistics->iLastStatisticsFrameCount);
645647 if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) {
646648 if (kiTimeDiff >= m_pEncContext->iStatisticsLogInterval) {
649+ float fTimeDiffSec = kiTimeDiff / 1000.0;
647650 pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -
648− pStatistics->iLastStatisticsFrameCount) * 1000 /
649− kiTimeDiff);
650− pStatistics->uiBitRate = static_cast<unsigned int> ((pStatistics->iTotalEncodedBytes -
651− pStatistics->iLastStatisticsBytes) * 8 * 1000 / kiTimeDiff);
651+ pStatistics->iLastStatisticsFrameCount) / fTimeDiffSec);
652+ pStatistics->uiBitRate = static_cast<unsigned int> ((pStatistics->iTotalEncodedBytes) * 8 / fTimeDiffSec);
652653
653654 if (WELS_ABS (pStatistics->fLatestFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) {
654655 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
@@ -669,26 +670,15 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 14 unmodified lines
669670 // update variables
670671 pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes;
671672 pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
672−
673+ m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
674+ LogStatistics (kiCurrentFrameTs, iMaxDid);
675+ pStatistics->iTotalEncodedBytes = 0;
673676 //TODO: the following statistics will be calculated and added later
674677 //pStatistics->uiLTRSentNum
675678
676679 }
677680 }
678681 }
679− if (((m_pEncContext->iStatisticsLogInterval > 0) && (kiTimeDiff >= m_pEncContext->iStatisticsLogInterval))
680− || (0 == iMaxInputFrame % 300)) {
681−
682− if ((iMaxFrameRate > 0) && WELS_ABS (iMaxFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) {
683− WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
684− "Actual input framerate fAverageFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), start_Ts = %"
685− PRId64,
686− iMaxFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, m_pEncContext->uiStartTimestamp);
687− }
688−
689− LogStatistics (kiCurrentFrameTs, iMaxDid);
690− m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
691− }
692682
693683 }
694684
@@ -727,7 +717,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 32 unmodified lines
727717 int32_t iValue = * ((int32_t*)pOption);
728718 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
729719 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL iValue = %d", iValue);
730− if ( iValue <= -1 ) {
720+ if (iValue <= -1) {
731721 iValue = 0;
732722 }
733723 if (iValue == (int32_t)m_pEncContext->pSvcParam->uiIntraPeriod) {
@@ -735,7 +725,8 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 1 unmodified line
735725 }
736726 m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue;
737727 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
738− "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL uiIntraPeriod updated to %d", m_pEncContext->pSvcParam->uiIntraPeriod);
728+ "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL uiIntraPeriod updated to %d",
729+ m_pEncContext->pSvcParam->uiIntraPeriod);
739730 }
740731 break;
741732 case ENCODER_OPTION_SVC_ENCODE_PARAM_BASE: { // SVC Encoding Parameter

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t