shithub: openh264

Download patch

ref: dfcc78eaf5035f1d097df0de3e1607537188fbab
parent: 82a0d3e4a2236e3913b91e7e36e19dc667bc2a80
author: Sijia Chen <sijchen@cisco.com>
date: Fri Jun 26 11:04:30 EDT 2015

refactor for future simplification

--- 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;