From 9b5902b94a19cfbdd056a5ce0f1c817552ad97e3 Mon Sep 17 00:00:00 2001 From: ruil2 Date: Wed, 27 Aug 2014 12:19:59 +0800 Subject: [PATCH] update the number of reference when ltr changes --- codec/encoder/core/inc/extern.h | 2 +- codec/encoder/core/src/encoder_ext.cpp | 42 +++++++++++++++++++++-- codec/encoder/plus/src/welsEncoderExt.cpp | 8 +---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/codec/encoder/core/inc/extern.h b/codec/encoder/core/inc/extern.h index 99a96529..b500eaf9 100644 --- a/codec/encoder/core/inc/extern.h +++ b/codec/encoder/core/inc/extern.h @@ -108,7 +108,7 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx); int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew); void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam); void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer); - +void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx*pCtx,SLTRConfig* pLTRValue); int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest); void FilterLTRMarkingFeedback (sWelsEncCtx* pCtx, SLTRMarkingFeedback* pLTRMarkingFeedback); diff --git a/codec/encoder/core/src/encoder_ext.cpp b/codec/encoder/core/src/encoder_ext.cpp index e8852453..17c8f485 100644 --- a/codec/encoder/core/src/encoder_ext.cpp +++ b/codec/encoder/core/src/encoder_ext.cpp @@ -480,6 +480,7 @@ void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, } } } + /*! * \brief acquire count number of layers and NALs based on configurable paramters dependency * \pParam pCtx sWelsEncCtx* @@ -1273,8 +1274,10 @@ void GetMvMvdRange (SWelsSvcCodingParam* pParam, int32_t& iMvRange, int32_t& iMv if (pParam->sSpatialLayers[iLayer].uiLevelIdc < iMinLevelIdc) iMinLevelIdc = pParam->sSpatialLayers[iLayer].uiLevelIdc; } - iMinMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMinVmv)>>2; - iMaxMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMaxVmv)>>2; + + iMinMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMinVmv) >> 2; + iMaxMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMaxVmv) >> 2; + iMvRange = WELS_MIN (WELS_ABS (iMinMv), iMaxMv); iMvRange = WELS_MIN (iMvRange, iFixMvRange); @@ -3797,6 +3800,41 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa return 0; } +void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx* pCtx, SLTRConfig* pLTRValue) { + SWelsSvcCodingParam sConfig; + int32_t iNumRefFrame = 1; + memcpy (&sConfig, pCtx->pSvcParam, sizeof (SWelsSvcCodingParam)); + sConfig.bEnableLongTermReference = pLTRValue->bEnableLongTermReference; + sConfig.iLTRRefNum = pLTRValue->iLTRRefNum; + int32_t uiGopSize = 1 << (sConfig.iTemporalLayerNum - 1); + if (sConfig.iUsageType == SCREEN_CONTENT_REAL_TIME) { + if (sConfig.bEnableLongTermReference) { + sConfig.iLTRRefNum = WELS_CLIP3 (sConfig.iLTRRefNum, 1, LONG_TERM_REF_NUM_SCREEN); + iNumRefFrame = WELS_MAX (1, WELS_LOG2 (uiGopSize)) + sConfig.iLTRRefNum; + } else { + sConfig.iLTRRefNum = 0; + iNumRefFrame = WELS_MAX (1, uiGopSize >> 1); + } + } else { + if (sConfig.bEnableLongTermReference) { + sConfig.iLTRRefNum = WELS_CLIP3 (sConfig.iLTRRefNum, 1, LONG_TERM_REF_NUM); + } else { + sConfig.iLTRRefNum = 0; + } + iNumRefFrame = ((uiGopSize >> 1) > 1) ? ((uiGopSize >> 1) + sConfig.iLTRRefNum) : (MIN_REF_PIC_COUNT + + sConfig.iLTRRefNum); + iNumRefFrame = WELS_CLIP3 (iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM); + + } + if (sConfig.iNumRefFrame < iNumRefFrame) + sConfig.iNumRefFrame = iNumRefFrame; + if (sConfig.iNumRefFrame > sConfig.iMaxNumRefFrame) + sConfig.iMaxNumRefFrame = sConfig.iNumRefFrame; + + WelsLog (pLogCtx, WELS_LOG_WARNING, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d", + sConfig.bEnableLongTermReference, sConfig.iLTRRefNum); + WelsEncoderParamAdjust (&pCtx, &sConfig); +} int32_t DynSliceRealloc (sWelsEncCtx* pCtx, SFrameBSInfo* pFrameBsInfo, SLayerBSInfo* pLayerBsInfo) { diff --git a/codec/encoder/plus/src/welsEncoderExt.cpp b/codec/encoder/plus/src/welsEncoderExt.cpp index 68b20e2c..4fe91305 100644 --- a/codec/encoder/plus/src/welsEncoderExt.cpp +++ b/codec/encoder/plus/src/welsEncoderExt.cpp @@ -825,13 +825,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { break; case ENCODER_OPTION_LTR: { SLTRConfig* pLTRValue = ((SLTRConfig*) (pOption)); - SWelsSvcCodingParam sConfig; - memcpy (&sConfig, m_pEncContext->pSvcParam, sizeof (SWelsSvcCodingParam)); - sConfig.bEnableLongTermReference = pLTRValue->bEnableLongTermReference; - sConfig.iLTRRefNum = pLTRValue->iLTRRefNum; - WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d", - sConfig.bEnableLongTermReference, sConfig.iLTRRefNum); - WelsEncoderParamAdjust (&m_pEncContext, &sConfig); + WelsEncoderApplyLTR (&m_pWelsTrace->m_sLogCtx, m_pEncContext, pLTRValue); } break; case ENCODER_OPTION_ENABLE_SSEI: {