shithub: openh264

Download patch

ref: 3bf0c41b67f7631e783e3ae43b44934eabb044c3
parent: 2ab706a24e1fb002bbd039d8a94e224a11b347f8
parent: 37f20f1c5e951782436d735db55ed99d08fd22ce
author: huili2 <huili2@cisco.com>
date: Mon Apr 7 20:25:25 EDT 2014

Merge pull request #641 from ruil2/enc_update

update pre-processing workflow for screen content

--- a/codec/encoder/core/inc/wels_preprocess.h
+++ b/codec/encoder/core/inc/wels_preprocess.h
@@ -188,11 +188,13 @@
   CWelsLib*        m_pEncLib;
   sWelsEncCtx*     m_pEncCtx;
   bool             m_bInitDone;
+  uint8_t          m_uiSpatialLayersInTemporal[MAX_DEPENDENCY_LAYER];
+  uint8_t          m_uiSpatialPicNum[MAX_DEPENDENCY_LAYER];
+public:
   /* For Downsampling & VAA I420 based source pictures */
   SPicture*        m_pSpatialPic[MAX_DEPENDENCY_LAYER][MAX_TEMPORAL_LEVEL + 1 +
       LONG_TERM_REF_NUM];	// need memory requirement with total number of (log2(uiGopSize)+1+1+long_term_ref_num)
-  uint8_t          m_uiSpatialLayersInTemporal[MAX_DEPENDENCY_LAYER];
-  uint8_t          m_uiSpatialPicNum[MAX_DEPENDENCY_LAYER];
+
 };
 
 }
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2913,6 +2913,7 @@
     pCtx->pFuncList->pfRc.pfWelsRcPictureInit (pCtx);
     PreprocessSliceCoding (pCtx);	// MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer()
 
+    //TODO Complexity Calculation here for screen content
     iLayerSize	= 0;
 
     if (SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) {	// only one slice within a sQualityStat layer
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -33,6 +33,7 @@
 // ref_list_mgr_svc.c
 #include "ref_list_mgr_svc.h"
 #include "utils.h"
+#include "picture_handle.h"
 namespace WelsSVCEnc {
 /*
  *	set picture as unreferenced
@@ -664,6 +665,40 @@
     }
   }
 }
+
+static int32_t UpdateSrcPicList (sWelsEncCtx* pCtx) {
+  int32_t iDIdx = pCtx->uiDependencyId;
+  SPicture** pLongRefList = pCtx->ppRefPicListExt[iDIdx]->pLongRefList;
+  SPicture** pLongRefSrcList = &pCtx->pVpp->m_pSpatialPic[iDIdx][0];
+  for (int32_t i = 0; i < MAX_REF_PIC_COUNT; ++i) {
+    if (NULL == pLongRefSrcList[i + 1] || (NULL != pLongRefList[i] && pLongRefList[i]->bUsedAsRef
+                                           && pLongRefList[i]->bIsLongRef)) {
+      continue;
+    } else {
+      SetUnref (pLongRefSrcList[i + 1]);
+    }
+  }
+  WelsExchangeSpatialPictures (&pCtx->pVpp->m_pSpatialPic[iDIdx][0],
+                               &pCtx->pVpp->m_pSpatialPic[iDIdx][1 + pCtx->pVaa->uiMarkLongTermPicIdx]);
+  SetUnref (pCtx->pVpp->m_pSpatialPic[iDIdx][0]);
+
+
+  //update info in src list
+  if (pCtx->pEncPic) {
+    pCtx->pEncPic->iPictureType	    = pCtx->pDecPic->iPictureType;
+    pCtx->pEncPic->iFramePoc		    = pCtx->pDecPic->iFramePoc;
+    pCtx->pEncPic->iFrameNum		    = pCtx->pDecPic->iFrameNum;
+    pCtx->pEncPic->uiSpatialId		  = pCtx->pDecPic->uiSpatialId;
+    pCtx->pEncPic->uiTemporalId	    = pCtx->pDecPic->uiTemporalId;
+    pCtx->pEncPic->iLongTermPicNum  = pCtx->pDecPic->iLongTermPicNum;
+    pCtx->pEncPic->bUsedAsRef       = pCtx->pDecPic->bUsedAsRef;
+    pCtx->pEncPic->bIsLongRef       = pCtx->pDecPic->bIsLongRef;
+    pCtx->pEncPic->bIsSceneLTR      = pCtx->pDecPic->bIsSceneLTR;
+    pCtx->pEncPic->iFrameAverageQp  = pCtx->pDecPic->iFrameAverageQp;
+  }
+  return 0;
+}
+
 bool WelsUpdateRefListScreen (void* pEncCtx) {
   sWelsEncCtx* pCtx     = (sWelsEncCtx*)pEncCtx;
   SRefList* pRefList		= pCtx->ppRefPicListExt[pCtx->uiDependencyId];
@@ -708,19 +743,7 @@
     pCtx->pVaa->uiValidLongTermPicIdx = 0;
   }
 
-  //update info in src list
-  if (pCtx->pEncPic) {
-    pCtx->pEncPic->iPictureType	    = pCtx->pDecPic->iPictureType;
-    pCtx->pEncPic->iFramePoc		= pCtx->pDecPic->iFramePoc;
-    pCtx->pEncPic->iFrameNum		= pCtx->pDecPic->iFrameNum;
-    pCtx->pEncPic->uiSpatialId		= pCtx->pDecPic->uiSpatialId;
-    pCtx->pEncPic->uiTemporalId	    = pCtx->pDecPic->uiTemporalId;
-    pCtx->pEncPic->iLongTermPicNum  = pCtx->pDecPic->iLongTermPicNum;
-    pCtx->pEncPic->bUsedAsRef       = pCtx->pDecPic->bUsedAsRef;
-    pCtx->pEncPic->bIsLongRef       = pCtx->pDecPic->bIsLongRef;
-    pCtx->pEncPic->bIsSceneLTR      = pCtx->pDecPic->bIsSceneLTR;
-    pCtx->pEncPic->iFrameAverageQp  = pCtx->pDecPic->iFrameAverageQp;
-  }
+  UpdateSrcPicList (pCtx);
   return true;
 }
 bool WelsBuildRefListScreen (void* pEncCtx, const int32_t iPOC, int32_t iBestLtrRefIdx) {
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -347,31 +347,47 @@
     iRefTemporalIdx = m_uiSpatialLayersInTemporal[kiDidx] + pCtx->pVaa->uiValidLongTermPicIdx;
 
   SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
-  SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
-  {
+  bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
+
+  if(pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME){
+     SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
+     SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[0]);
+	   SPicture *pRefPic= m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx];
+
+     VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD);
+
+     if (pSvcParam->bEnableBackgroundDetection) {
+       BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
+     }
+
+     if (bNeededMbAq) {
+     AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
+     }
+  } else {
+    SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
     SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
     bool bCalculateSQDiff = ((pLastPic->pData[0] == pRefPic->pData[0]) && bNeededMbAq);
     bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
 
     VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, bCalculateSQDiff, bCalculateVar, bCalculateBGD);
-  }
 
-  if (pSvcParam->bEnableBackgroundDetection) {
-    BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
-  }
+    if (pSvcParam->bEnableBackgroundDetection) {
+      BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
+    }
 
-  if (bNeededMbAq) {
-    SPicture* pCurPic = m_pLastSpatialPicture[kiDidx][1];
-    SPicture* pRefPic = m_pLastSpatialPicture[kiDidx][0];
+    if (bNeededMbAq) {
+      SPicture* pCurPic = m_pLastSpatialPicture[kiDidx][1];
+      SPicture* pRefPic = m_pLastSpatialPicture[kiDidx][0];
 
-    AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
-  }
+      AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
+    }
 
-  if(pSvcParam->iUsageType != SCREEN_CONTENT_REAL_TIME){
-    if (pSvcParam->iRCMode != RC_OFF_MODE) {
-      AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
+    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]);
     }
-    WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);
   }
   return 0;
 }
@@ -1132,7 +1148,7 @@
 {
   const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
   SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
-  SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);
+  SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);
 	int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum;
   return iLtrRefIdx;
 }