shithub: openh264

Download patch

ref: 13080273773867f5aaf9b13b8c6856acd1e27e48
parent: 82a0d3e4a2236e3913b91e7e36e19dc667bc2a80
parent: dfcc78eaf5035f1d097df0de3e1607537188fbab
author: huili2 <huili2@cisco.com>
date: Tue Jun 30 10:25:33 EDT 2015

Merge pull request #2013 from sijchen/mem10

[Encoder] refactoring: simplify and wrap a function

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -1067,6 +1067,25 @@
   return INVALID_ID;
 }
 
+static inline int32_t InitpSliceInLayer (sWelsEncCtx** ppCtx, SDqLayer* pDqLayer, CMemoryAlign* pMa,
+    const int32_t iMaxSliceNum, bool bMultithread) {
+  int32_t iSliceIdx = 0;
+  while (iSliceIdx < iMaxSliceNum) {
+    SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
+    pSlice->uiSliceIdx = iSliceIdx;
+    if (bMultithread)
+      pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;
+    else
+      pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
+    if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
+      FreeMemorySvc (ppCtx);
+      return ENC_RETURN_MEMALLOCERR;
+    }
+    ++ iSliceIdx;
+  }
+  return ENC_RETURN_SUCCESS;
+}
+
 /*!
  * \brief   initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available
  * \pParam  pCtx            sWelsEncCtx*
@@ -1161,35 +1180,11 @@
     pDqLayer->iMbWidth  = kiMbW;
     pDqLayer->iMbHeight = kiMbH;
     {
-      int32_t iSliceIdx = 0;
       pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
-
       WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx))
-      if (iMaxSliceNum > 1) {
-        while (iSliceIdx < iMaxSliceNum) {
-          SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
-          pSlice->uiSliceIdx = iSliceIdx;
-          if (pParam->iMultipleThreadIdc > 1)
-            pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;
-          else
-            pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
-          if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
-            FreeMemorySvc (ppCtx);
-            return 1;
-          }
-          ++ iSliceIdx;
-        }
-      }
-      // fix issue in case single pSlice coding might be inclusive exist in variant spatial layer setting, also introducing multi-pSlice modes
-      else { // only one pSlice
-        SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[0];
-        pSlice->uiSliceIdx = 0;
-        pSlice->pSliceBsa  = & (*ppCtx)->pOut->sBsWrite;
-        if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
-          FreeMemorySvc (ppCtx);
-          return 1;
-        }
-      }
+
+      int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, pParam->iMultipleThreadIdc > 1);
+      WELS_VERIFY_RETURN_PROC_IF (1, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx))
     }
 
     //deblocking parameters initialization
--- a/codec/encoder/core/src/nal_encap.cpp
+++ b/codec/encoder/core/src/nal_encap.cpp
@@ -77,9 +77,8 @@
 /*!
  * \brief   load an initialize NAL pRawNal pData
  */
-void WelsLoadNalForSlice (SWelsSliceBs* pSliceBsIn, const int32_t/*EWelsNalUnitType*/ kiType,
+void WelsLoadNalForSlice (SWelsSliceBs* pSliceBs, const int32_t/*EWelsNalUnitType*/ kiType,
                           const int32_t/*EWelsNalRefIdc*/ kiNalRefIdc) {
-  SWelsSliceBs* pSliceBs                = pSliceBsIn;
   SWelsNalRaw* pRawNal                  = &pSliceBs->sNalList[ pSliceBs->iNalIndex ];
   SNalUnitHeader* sNalUnitHeader        = &pRawNal->sNalExt.sNalUnitHeader;
   SBitStringAux* pBitStringAux          = &pSliceBs->sBsWrite;
@@ -97,8 +96,7 @@
 /*!
  * \brief   unload pRawNal NAL
  */
-void WelsUnloadNalForSlice (SWelsSliceBs* pSliceBsIn) {
-  SWelsSliceBs* pSliceBs        = pSliceBsIn;
+void WelsUnloadNalForSlice (SWelsSliceBs* pSliceBs) {
   int32_t*      pIdx            = &pSliceBs->iNalIndex;
   SWelsNalRaw* pRawNal          = &pSliceBs->sNalList[ *pIdx ];
   SBitStringAux* pBitStringAux  = &pSliceBs->sBsWrite;