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
378 return cmInitParaError;378 return cmInitParaError;
379 }379 }
380 if (kpSrcPic->iColorFormat != videoFormatI420) {380 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);
382 return cmInitParaError;383 return cmInitParaError;
383 }384 }
384 385
385 const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);386 const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
386 387
387 if (kiEncoderReturn != cmResultSuccess) {388 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);
389 return kiEncoderReturn;391 return kiEncoderReturn;
390 }392 }
391 393
@@ -644,11 +646,10 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 252 unmodified lines
644 pStatistics->iLastStatisticsFrameCount);646 pStatistics->iLastStatisticsFrameCount);
645 if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) {647 if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) {
646 if (kiTimeDiff >= m_pEncContext->iStatisticsLogInterval) {648 if (kiTimeDiff >= m_pEncContext->iStatisticsLogInterval) {
649 float fTimeDiffSec = kiTimeDiff / 1000.0;
647 pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -650 pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -
648 pStatistics->iLastStatisticsFrameCount) * 1000 /651 pStatistics->iLastStatisticsFrameCount) / fTimeDiffSec);
649 kiTimeDiff);652 pStatistics->uiBitRate = static_cast<unsigned int> ((pStatistics->iTotalEncodedBytes) * 8 / fTimeDiffSec);
650 pStatistics->uiBitRate = static_cast<unsigned int> ((pStatistics->iTotalEncodedBytes -
651 pStatistics->iLastStatisticsBytes) * 8 * 1000 / kiTimeDiff);
652 653
653 if (WELS_ABS (pStatistics->fLatestFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) {654 if (WELS_ABS (pStatistics->fLatestFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) {
654 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,655 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
@@ -669,26 +670,15 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 14 unmodified lines
669 // update variables670 // update variables
670 pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes;671 pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes;
671 pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;672 pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
672 673 m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
674 LogStatistics (kiCurrentFrameTs, iMaxDid);
675 pStatistics->iTotalEncodedBytes = 0;
673 //TODO: the following statistics will be calculated and added later676 //TODO: the following statistics will be calculated and added later
674 //pStatistics->uiLTRSentNum677 //pStatistics->uiLTRSentNum
675 678
676 }679 }
677 }680 }
678 }681 }
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 }
692 682
693}683}
694 684
@@ -727,7 +717,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 32 unmodified lines
727 int32_t iValue = * ((int32_t*)pOption);717 int32_t iValue = * ((int32_t*)pOption);
728 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,718 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
729 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL iValue = %d", iValue);719 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_IDR_INTERVAL iValue = %d", iValue);
730 if ( iValue <= -1 ) {720 if (iValue <= -1) {
731 iValue = 0;721 iValue = 0;
732 }722 }
733 if (iValue == (int32_t)m_pEncContext->pSvcParam->uiIntraPeriod) {723 if (iValue == (int32_t)m_pEncContext->pSvcParam->uiIntraPeriod) {
@@ -735,7 +725,8 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 1 unmodified line
735 }725 }
736 m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue;726 m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue;
737 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,727 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);
739 }730 }
740 break;731 break;
741 case ENCODER_OPTION_SVC_ENCODE_PARAM_BASE: { // SVC Encoding Parameter732 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