From 24192cc235ae186a4f3b907f6aebc1ac3a6a9252 Mon Sep 17 00:00:00 2001 From: Sijia Chen Date: Thu, 30 Oct 2014 18:31:50 +0800 Subject: [PATCH] add validation of slice parameters instead of assert --- .../encoder/core/inc/svc_enc_slice_segment.h | 4 +- codec/encoder/core/src/encoder_ext.cpp | 37 ++++++++++++++----- .../core/src/svc_enc_slice_segment.cpp | 24 ++++++++---- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/codec/encoder/core/inc/svc_enc_slice_segment.h b/codec/encoder/core/inc/svc_enc_slice_segment.h index 6b725098..95c24b5f 100644 --- a/codec/encoder/core/inc/svc_enc_slice_segment.h +++ b/codec/encoder/core/inc/svc_enc_slice_segment.h @@ -196,8 +196,8 @@ bool CheckFixedSliceNumMultiSliceSetting (const int32_t kiMbNumInFrame, SSliceA bool CheckRasterMultiSliceSetting (const int32_t kiMbNumInFrame, SSliceArgument* pSliceArg); bool CheckRowMbMultiSliceSetting (const int32_t kiMbWidth, SSliceArgument* pSliceArg); -void GomValidCheckSliceNum (const int32_t kiMbWidth, const int32_t kiMbHeight, uint32_t* pSliceNum); -void GomValidCheckSliceMbNum (const int32_t kiMbWidth, const int32_t kiMbHeight, SSliceArgument* pSliceArg); +bool GomValidCheckSliceNum (const int32_t kiMbWidth, const int32_t kiMbHeight, uint32_t* pSliceNum); +bool GomValidCheckSliceMbNum (const int32_t kiMbWidth, const int32_t kiMbHeight, SSliceArgument* pSliceArg); //end of checking valid para int32_t DynamicAdjustSlicePEncCtxAll (SSliceCtx* pSliceCtx, diff --git a/codec/encoder/core/src/encoder_ext.cpp b/codec/encoder/core/src/encoder_ext.cpp index 3f6f58df..72b1e923 100644 --- a/codec/encoder/core/src/encoder_ext.cpp +++ b/codec/encoder/core/src/encoder_ext.cpp @@ -307,11 +307,20 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa break; } if (pCodingParam->iRCMode != RC_OFF_MODE) { // multiple slices verify with gom - //check uiSliceNum - GomValidCheckSliceNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum); + //check uiSliceNum and set uiSliceMbNum with current uiSliceNum + if (!GomValidCheckSliceNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum)) { + WelsLog (pLogCtx, WELS_LOG_WARNING, + "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to %d!", + pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum); + } + if (pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum <= 1 || + !GomValidCheckSliceMbNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceCfg.sSliceArgument)) { + WelsLog (pLogCtx, WELS_LOG_ERROR, + "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum (%d) combination under RC on! Consider setting single slice with this resolution!", + pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum); + return ENC_RETURN_UNSUPPORTED_PARA; + } assert (pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum > 1); - //set uiSliceMbNum with current uiSliceNum - GomValidCheckSliceMbNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceCfg.sSliceArgument); } else if (!CheckFixedSliceNumMultiSliceSetting (iMbNumInFrame, &pSpatialLayer->sSliceCfg.sSliceArgument)) { // verify interleave mode settings //check uiSliceMbNum with current uiSliceNum @@ -1858,11 +1867,19 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar break; } if (pCodingParam->iRCMode != RC_OFF_MODE) { // multiple slices verify with gom - //check uiSliceNum - GomValidCheckSliceNum (kiMbWidth, kiMbHeight, &pDlp->sSliceCfg.sSliceArgument.uiSliceNum); - assert (pDlp->sSliceCfg.sSliceArgument.uiSliceNum > 1); - //set uiSliceMbNum with current uiSliceNum - GomValidCheckSliceMbNum (kiMbWidth, kiMbHeight, &pDlp->sSliceCfg.sSliceArgument); + //check uiSliceNum and set uiSliceMbNum with current uiSliceNum + if (!GomValidCheckSliceNum (kiMbWidth, kiMbHeight, &pDlp->sSliceCfg.sSliceArgument.uiSliceNum)) { + WelsLog (pLogCtx, WELS_LOG_WARNING, + "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to %d!", + pDlp->sSliceCfg.sSliceArgument.uiSliceNum); + } + if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum <= 1 || + !GomValidCheckSliceMbNum (kiMbWidth, kiMbHeight, &pDlp->sSliceCfg.sSliceArgument)) { + WelsLog (pLogCtx, WELS_LOG_ERROR, + "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum (%d) combination under RC on! Consider setting single slice with this resolution!", + pDlp->sSliceCfg.sSliceArgument.uiSliceNum); + return ENC_RETURN_INVALIDINPUT; + } } else if (!CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame, &pDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings //check uiSliceMbNum with current uiSliceNum @@ -1894,7 +1911,7 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar 2; // Disable loop filter on slice boundaries since that's not allowed with multithreading *pMaxSliceCount = iMaxSliceCount; - return 0; + return ENC_RETURN_SUCCESS; } /*! diff --git a/codec/encoder/core/src/svc_enc_slice_segment.cpp b/codec/encoder/core/src/svc_enc_slice_segment.cpp index 35cb2c30..18254a98 100644 --- a/codec/encoder/core/src/svc_enc_slice_segment.cpp +++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp @@ -218,7 +218,7 @@ bool CheckRasterMultiSliceSetting (const int32_t kiMbNumInFrame, SSliceArgument* // GOM based RC related for uiSliceNum decision, only used at SM_FIXEDSLCNUM_SLICE -void GomValidCheckSliceNum (const int32_t kiMbWidth, const int32_t kiMbHeight, uint32_t* pSliceNum) { +bool GomValidCheckSliceNum (const int32_t kiMbWidth, const int32_t kiMbHeight, uint32_t* pSliceNum) { const int32_t kiCountNumMb = kiMbWidth * kiMbHeight; int32_t iSliceNum = *pSliceNum; int32_t iGomSize; @@ -246,15 +246,16 @@ void GomValidCheckSliceNum (const int32_t kiMbWidth, const int32_t kiMbHeight, u break; } - if (0 == iSliceNum) - iSliceNum = 1; - - *pSliceNum = iSliceNum; + if (*pSliceNum != iSliceNum) { + *pSliceNum = (0 != iSliceNum) ? iSliceNum : 1; + return false; + } + return true; } // GOM based RC related for uiSliceMbNum decision, only used at SM_FIXEDSLCNUM_SLICE -void GomValidCheckSliceMbNum (const int32_t kiMbWidth, const int32_t kiMbHeight, SSliceArgument* pSliceArg) { +bool GomValidCheckSliceMbNum (const int32_t kiMbWidth, const int32_t kiMbHeight, SSliceArgument* pSliceArg) { uint32_t* pSlicesAssignList = & (pSliceArg->uiSliceMbNum[0]); const uint32_t kuiSliceNum = pSliceArg->uiSliceNum; const int32_t kiMbNumInFrame = kiMbWidth * kiMbHeight; @@ -292,16 +293,23 @@ void GomValidCheckSliceMbNum (const int32_t kiMbWidth, const int32_t kiMbHeight, else if (iNumMbAssigning > iMaximalMbNum) iNumMbAssigning = iMaximalMbNum; - assert (iNumMbAssigning > 0); + if (iNumMbAssigning <= 0) { + return false; + } iNumMbLeft -= iNumMbAssigning; - assert (iNumMbLeft > 0); + if (iNumMbLeft <= 0) { + return false; + } + pSlicesAssignList[uiSliceIdx] = iNumMbAssigning; ++ uiSliceIdx; iMaximalMbNum = iNumMbLeft - (kuiSliceNum - uiSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts } pSlicesAssignList[uiSliceIdx] = iNumMbLeft; + + return true; }