add complexity calculation in workflow

This commit is contained in:
ruil2
2014-04-17 17:33:44 +08:00
parent 2f8c539e60
commit 6b707ffb14
4 changed files with 114 additions and 60 deletions

View File

@@ -51,7 +51,7 @@
namespace WelsSVCEnc {
//trace
#define GOM_TRACE_FLAG 1
#define GOM_H_SCC 8
#define WELS_RC_DISABLE 0
#define WELS_RC_GOM 1

View File

@@ -127,6 +127,9 @@ class CWelsPreProcess {
int32_t AnalyzeSpatialPic (sWelsEncCtx* pEncCtx, const int32_t kiDIdx);
int32_t UpdateSpatialPictures(sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, const int8_t iCurTid, const int32_t d_idx);
int32_t GetRefCandidateLtrIndex(int32_t iRefIdx);
void AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
const int32_t kiDependencyId, const bool kbCalculateBGD);
private:
int32_t WelsPreprocessCreate();
int32_t WelsPreprocessDestroy();
@@ -144,8 +147,6 @@ class CWelsPreProcess {
bool bCalculateVar, bool bCalculateBGD);
void BackgroundDetection (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture, bool bDetectFlag);
void AdaptiveQuantCalculation (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture);
void AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
const int32_t kiDependencyId, const bool kbCalculateBGD);
void Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV,
int32_t iActualWidth, int32_t iPaddingWidth, int32_t iActualHeight, int32_t iPaddingHeight);
void SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArray, int32_t iRefPicType);

View File

@@ -3002,6 +3002,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
#ifdef LONG_TERM_REF_DUMP
dump_ref (pCtx);
#endif
if((pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)&&(pSvcParam->iRCMode != RC_OFF_MODE))
pCtx->pVpp->AnalyzePictureComplexity(pCtx,pCtx->pEncPic,((pCtx->eSliceType == P_SLICE)&&(pCtx->iNumRef0>0))?pCtx->pRefList0[0]:NULL,
iCurDid,pSvcParam->bEnableBackgroundDetection);
WelsUpdateRefSyntax (pCtx, pCtx->iPOC,
eFrameType); //get reordering syntax used for writing slice header and transmit to encoder.
PrefetchReferencePicture (pCtx, eFrameType); // update reference picture for current pDq layer

View File

@@ -242,14 +242,9 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD
AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
}
if(pSvcParam->iUsageType != SCREEN_CONTENT_REAL_TIME){
if (pSvcParam->iRCMode != RC_OFF_MODE) {
AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
}
WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);
}
}
return 0;
}
@@ -723,11 +718,66 @@ void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArra
void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
const int32_t kiDependencyId, const bool bCalculateBGD) {
SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
SVAAFrameInfo* pVaaInfo = pCtx->pVaa;
int32_t iComplexityAnalysisMode = 0;
if (pSvcParam->iRCMode == RC_OFF_MODE)
return;
if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
SComplexityAnalysisScreenParam* sComplexityAnalysisParam = &pVaaExt->sComplexityScreenParam;
SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
if (pCtx->eSliceType == P_SLICE)
iComplexityAnalysisMode = GOM_SAD;
else if (pCtx->eSliceType == I_SLICE)
iComplexityAnalysisMode = GOM_VAR;
else
return;
memset (pWelsSvcRc->pGomForegroundBlockNum, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
memset (pWelsSvcRc->pCurrentFrameGomSad, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
sComplexityAnalysisParam->iFrameComplexity = 0;
sComplexityAnalysisParam->pGomComplexity = pWelsSvcRc->pCurrentFrameGomSad;
sComplexityAnalysisParam->iGomNumInFrame = pWelsSvcRc->iGomSize;
sComplexityAnalysisParam->iIdrFlag = (pCtx->eSliceType == I_SLICE);
sComplexityAnalysisParam->iMbRowInGom = GOM_H_SCC;
sComplexityAnalysisParam->sScrollResult.bScrollDetectFlag = false;
sComplexityAnalysisParam->sScrollResult.iScrollMvX = 0;
sComplexityAnalysisParam->sScrollResult.iScrollMvY = 0;
const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN;
SPixMap sSrcPixMap;
SPixMap sRefPixMap;
memset (&sSrcPixMap, 0, sizeof (SPixMap));
memset (&sRefPixMap, 0, sizeof (SPixMap));
int32_t iRet = 0;
sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
if (pRefPicture != NULL) {
sRefPixMap.pPixel[0] = pRefPicture->pData[0];
sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
sRefPixMap.eFormat = VIDEO_FORMAT_I420;
}
iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
if (iRet == 0)
m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
} else {
SVAAFrameInfo* pVaaInfo = pCtx->pVaa;
SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam);
SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
int32_t iComplexityAnalysisMode = 0;
if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) {
iComplexityAnalysisMode = FRAME_SAD;
@@ -738,7 +788,6 @@ void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCu
} else {
return;
}
sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode;
sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo);
sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;
@@ -782,6 +831,7 @@ void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCu
m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
}
}
}
void CWelsPreProcess::InitPixMap (const SPicture* pPicture, SPixMap* pPixMap) {
@@ -1007,8 +1057,7 @@ ESceneChangeIdc CWelsPreProcess::DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPi
return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);
}
int32_t CWelsPreProcess::GetRefCandidateLtrIndex(int32_t iRefIdx)
{
int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) {
const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);