shithub: openh264

Download patch

ref: 475309307c74cee0453888df87c6774d0407cddc
parent: 488482811cfc55c11b397541fd0b43a8cc4f3e5d
author: volvet <[email protected]>
date: Mon Feb 17 06:35:52 EST 2014

move spatial picture related variable to CWelsPreProcess

--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -190,14 +190,8 @@
   int32_t						iFrameBsSize;	// count size of frame bs in bytes allocated
   int32_t						iPosBsBuffer;	// current writing position of frame bs pBuffer
 
-  /* For Downsampling & VAA I420 based source pictures */
-  SPicture*					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)
-
   SSpatialPicIndex			sSpatialIndexMap[MAX_DEPENDENCY_LAYER];
-  uint8_t						uiSpatialLayersInTemporal[MAX_DEPENDENCY_LAYER];
 
-  uint8_t                     uiSpatialPicNum[MAX_DEPENDENCY_LAYER];
   bool						bLongTermRefFlag[MAX_DEPENDENCY_LAYER][MAX_TEMPORAL_LEVEL + 1/*+LONG_TERM_REF_NUM*/];
 
   int16_t						iMaxSliceCount;// maximal count number of slices for all layers observation
--- a/codec/encoder/core/inc/wels_preprocess.h
+++ b/codec/encoder/core/inc/wels_preprocess.h
@@ -151,6 +151,11 @@
   sWelsEncCtx*     m_pEncCtx;
   bool             m_bInitDone;
   bool             m_bOfficialBranch;
+  /* 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
@@ -3694,11 +3694,9 @@
       pCtx->bLongTermRefFlag[d_idx][0] = true;
     }
 
-    if (iCurTid < pCtx->uiSpatialLayersInTemporal[d_idx] - 1 || pSvcParam->iDecompStages == 0) {
-      if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){
-        ForceCodingIDR(pCtx);
-        return -1;
-      }
+    if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){
+      ForceCodingIDR(pCtx);
+      return -1;
     }
 
     if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -212,6 +212,9 @@
   m_bOfficialBranch  = false;
   m_pEncCtx = pEncCtx;
   memset (&m_sScaledPicture, 0, sizeof (m_sScaledPicture));
+  memset (m_pSpatialPic, 0, sizeof(m_pSpatialPic));
+  memset (m_uiSpatialLayersInTemporal, 0, sizeof(m_uiSpatialLayersInTemporal));
+  memset (m_uiSpatialPicNum, 0, sizeof(m_uiSpatialPicNum));
 }
 
 CWelsPreProcess::~CWelsPreProcess() {
@@ -277,12 +280,12 @@
     do {
       SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false);
       WELS_VERIFY_RETURN_IF(1, (NULL == pPic))
-      pCtx->pSpatialPic[iDlayerIndex][i] = pPic;
+      m_pSpatialPic[iDlayerIndex][i] = pPic;
       ++ i;
     } while (i < kuiRefNumInTemporal);
 
-    pCtx->uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
-    pCtx->uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
+    m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
+    m_uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
     ++ iDlayerIndex;
   } while (iDlayerIndex < kiDlayerCount);
 
@@ -294,15 +297,15 @@
   int32_t j = 0;
   while (j < pCtx->pSvcParam->iNumDependencyLayer) {
     uint8_t i = 0;
-    uint8_t uiRefNumInTemporal = pCtx->uiSpatialPicNum[j];
+    uint8_t uiRefNumInTemporal = m_uiSpatialPicNum[j];
 
     while (i < uiRefNumInTemporal) {
-      if (NULL != pCtx->pSpatialPic[j][i]) {
-        FreePicture (pMa, &pCtx->pSpatialPic[j][i]);
+      if (NULL != m_pSpatialPic[j][i]) {
+        FreePicture (pMa, &m_pSpatialPic[j][i]);
       }
       ++ i;
     }
-    pCtx->uiSpatialLayersInTemporal[j]	= 0;
+    m_uiSpatialLayersInTemporal[j] = 0;
     ++ j;
   }
 }
@@ -361,15 +364,15 @@
   bool bNeededMbAq = (pSvcParam->bEnableAdaptiveQuant && (pCtx->eSliceType == P_SLICE));
   bool bCalculateBGD = (pCtx->eSliceType == P_SLICE && pSvcParam->bEnableBackgroundDetection);
 
-  int32_t iCurTemporalIdx  = pCtx->uiSpatialLayersInTemporal[kiDidx] - 1;
+  int32_t iCurTemporalIdx  = m_uiSpatialLayersInTemporal[kiDidx] - 1;
 
   int32_t iRefTemporalIdx = (int32_t)g_kuiRefTemporalIdx[pSvcParam->iDecompStages][pCtx->iCodingIndex &
                             (pSvcParam->uiGopSize - 1)];
   if (pCtx->uiTemporalId == 0 && pCtx->pLtr[pCtx->uiDependencyId].bReceivedT0LostFlag)
-    iRefTemporalIdx = pCtx->uiSpatialLayersInTemporal[kiDidx] + pCtx->pVaa->uiValidLongTermPicIdx;
+    iRefTemporalIdx = m_uiSpatialLayersInTemporal[kiDidx] + pCtx->pVaa->uiValidLongTermPicIdx;
 
-  SPicture* pCurPic = pCtx->pSpatialPic[kiDidx][iCurTemporalIdx];
-  SPicture* pRefPic = pCtx->pSpatialPic[kiDidx][iRefTemporalIdx];
+  SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
+  SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
   {
     SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
     bool bCalculateSQDiff = ((pLastPic->pData[0] == pRefPic->pData[0]) && bNeededMbAq);
@@ -400,20 +403,22 @@
 
 int32_t CWelsPreProcess::UpdateSpatialPictures(sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam, 
     const int8_t iCurTid, const int32_t d_idx) {
-  if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (pCtx->uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
-    return 1;
+  if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0){
+    if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
+      return 1;
+    }
+    if (pParam->bEnableLongTermReference && pCtx->bLongTermRefFlag[d_idx][iCurTid]) {
+      SPicture* tmp	= m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx];
+      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx] =
+      m_pSpatialPic[d_idx][iCurTid];
+      m_pSpatialPic[d_idx][iCurTid] = m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1];
+      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1] = tmp;
+      pCtx->bLongTermRefFlag[d_idx][iCurTid] = false;
+    } else {
+      WelsExchangeSpatialPictures (&m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1],
+                                   &m_pSpatialPic[d_idx][iCurTid]);
+    }
   }
-  if (pParam->bEnableLongTermReference && pCtx->bLongTermRefFlag[d_idx][iCurTid]) {
-    SPicture* tmp	= pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx];
-    pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx] =
-    pCtx->pSpatialPic[d_idx][iCurTid];
-    pCtx->pSpatialPic[d_idx][iCurTid] = pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1];
-    pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1] = tmp;
-    pCtx->bLongTermRefFlag[d_idx][iCurTid] = false;
-  } else {
-    WelsExchangeSpatialPictures (&pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1],
-                                 &pCtx->pSpatialPic[d_idx][iCurTid]);
-  }
   return 0;
 }
 
@@ -425,8 +430,8 @@
 int32_t CWelsPreProcess::SingleLayerPreprocess (sWelsEncCtx* pCtx, const SSourcePicture* kpSrc,
     Scaled_Picture* pScaledPicture) {
   SWelsSvcCodingParam* pSvcParam    = pCtx->pSvcParam;
-  int8_t	iDependencyId			= pSvcParam->iNumDependencyLayer - 1;
-  int32_t iPicturePos	                    = pCtx->uiSpatialLayersInTemporal[iDependencyId] - 1;
+  int8_t	iDependencyId	    = pSvcParam->iNumDependencyLayer - 1;
+  int32_t iPicturePos	            = m_uiSpatialLayersInTemporal[iDependencyId] - 1;
 
   SPicture* pSrcPic					= NULL;	// large
   SPicture* pDstPic					= NULL;	// small
@@ -447,7 +452,7 @@
   iSrcHeight  = pSvcParam->SUsedPicRect.iHeight;
 
   pSrcPic = pScaledPicture->pScaledInputPicture ? pScaledPicture->pScaledInputPicture :
-            pCtx->pSpatialPic[iDependencyId][iPicturePos];
+            m_pSpatialPic[iDependencyId][iPicturePos];
 
   WelsMoveMemoryWrapper (pSvcParam, pSrcPic, kpSrc, iSrcWidth, iSrcHeight);
 
@@ -460,7 +465,7 @@
   pDstPic = pSrcPic;
   if (pScaledPicture->pScaledInputPicture) {
     // for highest downsampling
-    pDstPic		= pCtx->pSpatialPic[iDependencyId][iPicturePos];
+    pDstPic		= m_pSpatialPic[iDependencyId][iPicturePos];
     iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
     iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
   }
@@ -470,7 +475,7 @@
       && !pCtx->bEncCurFrmAsIdrFlag
       && ! (pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1))) {
     SPicture* pRefPic = pCtx->pLtr[iDependencyId].bReceivedT0LostFlag ?
-                        pCtx->pSpatialPic[iDependencyId][pCtx->uiSpatialLayersInTemporal[iDependencyId] +
+                        m_pSpatialPic[iDependencyId][m_uiSpatialLayersInTemporal[iDependencyId] +
                             pCtx->pVaa->uiValidLongTermPicIdx] : m_pLastSpatialPicture[iDependencyId][0];
 
     pCtx->pVaa->bSceneChangeFlag = DetectSceneChange (pDstPic, pRefPic);
@@ -489,7 +494,7 @@
     -- iActualSpatialLayerNum;
   }
 
-  m_pLastSpatialPicture[iDependencyId][1]	= pCtx->pSpatialPic[iDependencyId][iPicturePos];
+  m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
   -- iDependencyId;
 
   // generate other spacial layer
@@ -502,7 +507,7 @@
       iTargetWidth	= pDlayerParam->iFrameWidth;
       iTargetHeight	= pDlayerParam->iFrameHeight;
       iTemporalId = pDlayerParam->uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)];
-      iPicturePos		= pCtx->uiSpatialLayersInTemporal[iDependencyId] - 1;
+      iPicturePos		= m_uiSpatialLayersInTemporal[iDependencyId] - 1;
 
       // NOT work for CGS, FIXME
       // spatial layer is able to encode indeed
@@ -509,7 +514,7 @@
       if ((iTemporalId != INVALID_TEMPORAL_ID)) {
         // down sampling performed
 
-        pDstPic	= pCtx->pSpatialPic[iDependencyId][iPicturePos];	// small
+        pDstPic	= m_pSpatialPic[iDependencyId][iPicturePos];	// small
         iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
         iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
         DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
@@ -519,7 +524,7 @@
         -- iActualSpatialLayerNum;
         ++ iSpatialNum;
 
-        m_pLastSpatialPicture[iDependencyId][1]	= pCtx->pSpatialPic[iDependencyId][iPicturePos];
+        m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
       }
       -- iDependencyId;
     }
@@ -551,7 +556,7 @@
     } while (j < iSpatialLayersCfgCount);
 
     assert (j < iSpatialLayersCfgCount);
-    pDstPic = pCtx->pSpatialPic[j][pCtx->uiSpatialLayersInTemporal[j] - 1];
+    pDstPic = m_pSpatialPic[j][m_uiSpatialLayersInTemporal[j] - 1];
 
     WelsUpdateSpatialIdxMap (pCtx, i, pDstPic, j);
 
@@ -567,7 +572,7 @@
   if (pSvcParam->bEnableSceneChangeDetect && (kiSpatialNum == pSvcParam->iNumDependencyLayer)
       && !pCtx->pVaa->bIdrPeriodFlag && !pCtx->bEncCurFrmAsIdrFlag) {
     SPicture* pRef = pCtx->pLtr[0].bReceivedT0LostFlag ?
-                     pCtx->pSpatialPic[0][pCtx->uiSpatialLayersInTemporal[0] + pCtx->pVaa->uiValidLongTermPicIdx] :
+                     m_pSpatialPic[0][m_uiSpatialLayersInTemporal[0] + pCtx->pVaa->uiValidLongTermPicIdx] :
                      m_pLastSpatialPicture[0][0];
 
     pCtx->pVaa->bSceneChangeFlag = DetectSceneChange (pDstPic, pRef);
@@ -636,8 +641,8 @@
   int32_t iDlayerIndex					= 0;
 
   for (; iDlayerIndex < kiDlayerCount; iDlayerIndex++) {
-    const int32_t kiLayerInTemporal = pCtx->uiSpatialLayersInTemporal[iDlayerIndex];
-    m_pLastSpatialPicture[iDlayerIndex][0]	= pCtx->pSpatialPic[iDlayerIndex][kiLayerInTemporal - 2];
+    const int32_t kiLayerInTemporal = m_uiSpatialLayersInTemporal[iDlayerIndex];
+    m_pLastSpatialPicture[iDlayerIndex][0]	= m_pSpatialPic[iDlayerIndex][kiLayerInTemporal - 2];
     m_pLastSpatialPicture[iDlayerIndex][1]	= NULL;
   }
   for (; iDlayerIndex < MAX_DEPENDENCY_LAYER; iDlayerIndex++) {