Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 3 files). Show all
Unified · Split
| @@ -568,9 +568,12 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 567 unmodified lines | |||
| 568 | const int64_t kiCurrentFrameMs) { | 568 | const int64_t kiCurrentFrameMs) { |
| 569 | 569 | ||
| 570 | const int64_t kiCurrentFrameTs = m_pEncContext->uiLastTimestamp = pBsInfo->uiTimeStamp; | 570 | const int64_t kiCurrentFrameTs = m_pEncContext->uiLastTimestamp = pBsInfo->uiTimeStamp; |
| 571 | const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; | ||
| 571 | 572 | ||
| 572 | int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1; | 573 | int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1; |
| 573 | SLayerBSInfo* pLayerInfo = &pBsInfo->sLayerInfo[0]; | 574 | SLayerBSInfo* pLayerInfo = &pBsInfo->sLayerInfo[0]; |
| 575 | uint32_t iMaxInputFrame = 0; | ||
| 576 | float iMaxFrameRate = 0; | ||
| 574 | for (int32_t iDid = 0; iDid <= iMaxDid; iDid++) { | 577 | for (int32_t iDid = 0; iDid <= iMaxDid; iDid++) { |
| 575 | EVideoFrameType eFrameType = videoFrameTypeSkip; | 578 | EVideoFrameType eFrameType = videoFrameTypeSkip; |
| 576 | int32_t kiCurrentFrameSize = 0; | 579 | int32_t kiCurrentFrameSize = 0; |
| @@ -584,19 +587,20 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | |||
| 584 | } | 587 | } |
| 585 | } | 588 | } |
| 586 | SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics[iDid]); | 589 | SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics[iDid]); |
| 587 | 590 | SSpatialLayerInternal* pSpatialLayerInternalParam = & (m_pEncContext->pSvcParam->sDependencyLayers[iDid]); | |
| 588 | 591 | ||
| 589 | if ((0 != pStatistics->uiWidth && 0 != pStatistics->uiHeight) | 592 | if ((0 != pStatistics->uiWidth && 0 != pStatistics->uiHeight) |
| 590 | && (pStatistics->uiWidth != (unsigned int) m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualWidth | 593 | && (pStatistics->uiWidth != (unsigned int) pSpatialLayerInternalParam->iActualWidth |
| 591 | || pStatistics->uiHeight != (unsigned int) m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualHeight)) { | 594 | || pStatistics->uiHeight != (unsigned int) pSpatialLayerInternalParam->iActualHeight)) { |
| 592 | pStatistics->uiResolutionChangeTimes ++; | 595 | pStatistics->uiResolutionChangeTimes ++; |
| 593 | } | 596 | } |
| 594 | pStatistics->uiWidth = m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualWidth; | 597 | pStatistics->uiWidth = pSpatialLayerInternalParam->iActualWidth; |
| 595 | pStatistics->uiHeight = m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualHeight; | 598 | pStatistics->uiHeight = pSpatialLayerInternalParam->iActualHeight; |
| 596 | 599 | ||
| 597 | const bool kbCurrentFrameSkipped = (videoFrameTypeSkip == eFrameType); | 600 | const bool kbCurrentFrameSkipped = (videoFrameTypeSkip == eFrameType); |
| 598 | pStatistics->uiInputFrameCount ++; | 601 | pStatistics->uiInputFrameCount ++; |
| 599 | pStatistics->uiSkippedFrameCount += (kbCurrentFrameSkipped ? 1 : 0); | 602 | pStatistics->uiSkippedFrameCount += (kbCurrentFrameSkipped ? 1 : 0); |
| 603 | iMaxInputFrame = WELS_MAX (pStatistics->uiInputFrameCount, iMaxInputFrame); | ||
| 600 | int32_t iProcessedFrameCount = pStatistics->uiInputFrameCount - pStatistics->uiSkippedFrameCount; | 604 | int32_t iProcessedFrameCount = pStatistics->uiInputFrameCount - pStatistics->uiSkippedFrameCount; |
| 601 | if (!kbCurrentFrameSkipped && iProcessedFrameCount != 0) { | 605 | if (!kbCurrentFrameSkipped && iProcessedFrameCount != 0) { |
| 602 | pStatistics->fAverageFrameSpeedInMs += (kiCurrentFrameMs - pStatistics->fAverageFrameSpeedInMs) / iProcessedFrameCount; | 606 | pStatistics->fAverageFrameSpeedInMs += (kiCurrentFrameMs - pStatistics->fAverageFrameSpeedInMs) / iProcessedFrameCount; |
| @@ -610,6 +614,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | |||
| 610 | } else { | 614 | } else { |
| 611 | m_pEncContext->uiStartTimestamp = kiCurrentFrameTs; | 615 | m_pEncContext->uiStartTimestamp = kiCurrentFrameTs; |
| 612 | } | 616 | } |
| 617 | iMaxFrameRate = WELS_MAX (iMaxFrameRate, pStatistics->fAverageFrameRate); | ||
| 613 | //pStatistics->fLatestFrameRate = m_pEncContext->pWelsSvcRc->fLatestFrameRate; //TODO: finish the calculation in RC | 618 | //pStatistics->fLatestFrameRate = m_pEncContext->pWelsSvcRc->fLatestFrameRate; //TODO: finish the calculation in RC |
| 614 | //pStatistics->uiBitRate = m_pEncContext->pWelsSvcRc->iActualBitRate; //TODO: finish the calculation in RC | 619 | //pStatistics->uiBitRate = m_pEncContext->pWelsSvcRc->iActualBitRate; //TODO: finish the calculation in RC |
| 615 | pStatistics->uiAverageFrameQP = m_pEncContext->pWelsSvcRc[iDid].iAverageFrameQp; | 620 | pStatistics->uiAverageFrameQP = m_pEncContext->pWelsSvcRc[iDid].iAverageFrameQp; |
| @@ -626,8 +631,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 10 unmodified lines | |||
| 626 | const int32_t kiDeltaFrames = static_cast<int32_t> (pStatistics->uiInputFrameCount - | 631 | const int32_t kiDeltaFrames = static_cast<int32_t> (pStatistics->uiInputFrameCount - |
| 627 | pStatistics->iLastStatisticsFrameCount); | 632 | pStatistics->iLastStatisticsFrameCount); |
| 628 | if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) { | 633 | if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) { |
| 629 | const int64_t kiTimeDiff = kiCurrentFrameTs - pStatistics->iStatisticsTs; | 634 | if (kiTimeDiff > m_pEncContext->iStatisticsLogInterval) { |
| 630 | if (kiTimeDiff) { | ||
| 631 | pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount - | 635 | pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount - |
| 632 | pStatistics->iLastStatisticsFrameCount) * 1000 / | 636 | pStatistics->iLastStatisticsFrameCount) * 1000 / |
| 633 | kiTimeDiff); | 637 | kiTimeDiff); |
| @@ -639,7 +643,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 5 unmodified lines | |||
| 639 | "Actual input fLatestFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), cur_Ts = %" | 643 | "Actual input fLatestFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), cur_Ts = %" |
| 640 | PRId64 " start_Ts = %" PRId64, | 644 | PRId64 " start_Ts = %" PRId64, |
| 641 | pStatistics->fLatestFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, kiCurrentFrameTs, | 645 | pStatistics->fLatestFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, kiCurrentFrameTs, |
| 642 | static_cast<int64_t> (pStatistics->iStatisticsTs)); | 646 | static_cast<int64_t> (m_pEncContext->iLastStatisticsLogTs)); |
| 643 | } | 647 | } |
| 644 | 648 | ||
| 645 | if (m_pEncContext->pSvcParam->iRCMode == RC_QUALITY_MODE || m_pEncContext->pSvcParam->iRCMode == RC_BITRATE_MODE) { | 649 | if (m_pEncContext->pSvcParam->iRCMode == RC_QUALITY_MODE || m_pEncContext->pSvcParam->iRCMode == RC_BITRATE_MODE) { |
| @@ -653,7 +657,6 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | |||
| 653 | } | 657 | } |
| 654 | 658 | ||
| 655 | // update variables | 659 | // update variables |
| 656 | pStatistics->iStatisticsTs = kiCurrentFrameTs; | ||
| 657 | pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes; | 660 | pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes; |
| 658 | pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount; | 661 | pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount; |
| 659 | 662 | ||
| @@ -661,20 +664,18 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 1 unmodified line | |||
| 661 | //pStatistics->uiLTRSentNum | 664 | //pStatistics->uiLTRSentNum |
| 662 | } | 665 | } |
| 663 | } | 666 | } |
| 664 | if (m_pEncContext->iStatisticsLogInterval > 0) { | 667 | if (((m_pEncContext->iStatisticsLogInterval > 0) && (kiTimeDiff > m_pEncContext->iStatisticsLogInterval)) |
| 665 | SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics[0]); | 668 | || (0 == iMaxInputFrame % 300)) { |
| 666 | const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; | ||
| 667 | if ((kiTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { | ||
| 668 | if (WELS_ABS (pStatistics->fAverageFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) { | ||
| 669 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | ||
| 670 | "Actual input framerate fAverageFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), start_Ts = %" | ||
| 671 | PRId64, | ||
| 672 | pStatistics->fAverageFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, m_pEncContext->uiStartTimestamp); | ||
| 673 | } | ||
| 674 | 669 | ||
| 675 | LogStatistics (kiCurrentFrameTs, iMaxDid); | 670 | if ((iMaxFrameRate > 0) && WELS_ABS (iMaxFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) { |
| 676 | m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; | 671 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, |
| 672 | "Actual input framerate fAverageFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), start_Ts = %" | ||
| 673 | PRId64, | ||
| 674 | iMaxFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, m_pEncContext->uiStartTimestamp); | ||
| 677 | } | 675 | } |
| 676 | |||
| 677 | LogStatistics (kiCurrentFrameTs, iMaxDid); | ||
| 678 | m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; | ||
| 678 | } | 679 | } |
| 679 | 680 | ||
| 680 | } | 681 | } |