diff --git a/codec/encoder/plus/src/welsEncoderExt.cpp b/codec/encoder/plus/src/welsEncoderExt.cpp index 88be4006..b52949e6 100644 --- a/codec/encoder/plus/src/welsEncoderExt.cpp +++ b/codec/encoder/plus/src/welsEncoderExt.cpp @@ -642,10 +642,11 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid int64_t iTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; if ((iTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { if (iTimeDiff) { - pStatistics->fLatestFrameRate = static_cast ((pStatistics->uiInputFrameCount - m_pEncContext->iLastStatisticsFrameCount) * 1000 / - iTimeDiff); + pStatistics->fLatestFrameRate = static_cast ((pStatistics->uiInputFrameCount - + m_pEncContext->iLastStatisticsFrameCount) * 1000 / + iTimeDiff); pStatistics->uiBitRate = static_cast ((m_pEncContext->iTotalEncodedBits - - m_pEncContext->iLastStatisticsBits) * 1000 / iTimeDiff); + m_pEncContext->iLastStatisticsBits) * 1000 / iTimeDiff); } // update variables @@ -727,6 +728,30 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { m_pEncContext->pSvcParam->uiIntraPeriod = (uint32_t)iValue; } break; + case ENCODER_OPTION_SVC_ENCODE_PARAM_BASE: { // SVC Encoding Parameter + SEncParamBase sEncodingParam; + SWelsSvcCodingParam sConfig; + int32_t iTargetWidth = 0; + int32_t iTargetHeight = 0; + + memcpy (&sEncodingParam, pOption, sizeof (SEncParamBase)); // confirmed_safe_unsafe_usage + if (sConfig.ParamBaseTranscode (sEncodingParam)) { + return cmInitParaError; + } + /* New configuration available here */ + iTargetWidth = sConfig.iPicWidth; + iTargetHeight = sConfig.iPicHeight; + if (m_iMaxPicWidth != iTargetWidth + || m_iMaxPicHeight != iTargetHeight) { + m_iMaxPicWidth = iTargetWidth; + m_iMaxPicHeight = iTargetHeight; + } + if (WelsEncoderParamAdjust (&m_pEncContext, &sConfig)) { + return cmInitParaError; + } + } + break; + case ENCODER_OPTION_SVC_ENCODE_PARAM_EXT: { // SVC Encoding Parameter SEncParamExt sEncodingParam; SWelsSvcCodingParam sConfig; diff --git a/test/encoder/EncUT_EncoderExt.cpp b/test/encoder/EncUT_EncoderExt.cpp index d38b8989..083c978d 100644 --- a/test/encoder/EncUT_EncoderExt.cpp +++ b/test/encoder/EncUT_EncoderExt.cpp @@ -482,6 +482,37 @@ TEST_F (EncoderInterfaceTest, BasicInitializeTest) { EXPECT_EQ (iResult, static_cast (cmResultSuccess)); } +TEST_F (EncoderInterfaceTest, BaseParamSettingTest) { + SEncParamBase sEncParamBase; + GetValidEncParamBase (&sEncParamBase); + + int iResult = pPtrEnc->Initialize (&sEncParamBase); + EXPECT_EQ (iResult, static_cast (cmResultSuccess)); + if (iResult != cmResultSuccess) { + fprintf (stderr, "Unexpected ParamBase? \ + iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n", + sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight, + sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate); + } + + PrepareOneSrcFrame(); + + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); + EXPECT_EQ (iResult, static_cast (cmResultSuccess)); + EXPECT_EQ (sFbi.eFrameType, static_cast (videoFrameTypeIDR)); + + GetValidEncParamBase (&sEncParamBase); + iResult = pPtrEnc->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, &sEncParamBase); + + PrepareOneSrcFrame(); + + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); + EXPECT_EQ (iResult, static_cast (cmResultSuccess)); + + iResult = pPtrEnc->Uninitialize(); + EXPECT_EQ (iResult, static_cast (cmResultSuccess)); +} + TEST_F (EncoderInterfaceTest, BasicInitializeTestFalse) { int iResult; SEncParamBase sEncParamBase;