shithub: openh264

Download patch

ref: 08f19b612688777b60ab537fa0f539f27278fded
parent: 969c415daa17f2552f2ac4b7f5abea61851d8894
parent: 0f8ebe92982024574a9d54cfc5c4959c0b5f503f
author: sijchen <sijchen@cisco.com>
date: Thu Apr 20 05:43:21 EDT 2017

Merge pull request #2715 from shihuade/MultiThread_V11.0_NewDesign

Slice buffer reallocate design::PR08::New slice buffer reallocate design

--- a/codec/encoder/core/inc/rc.h
+++ b/codec/encoder/core/inc/rc.h
@@ -181,6 +181,7 @@
 int32_t   iRemainingWeights;
 int32_t   iFrameDqBits;
 
+bool       bGomRC;
 double*    pGomComplexity;
 int32_t*   pGomForegroundBlockNum;
 int32_t*   pCurrentFrameGomSad;
@@ -261,7 +262,7 @@
 PWelsRCPostFrameSkippingFunc    pfWelsRcPostFrameSkipping;
 } SWelsRcFunc;
 
-void RCInitOneSliceInformation(sWelsEncCtx* pEncCtx, SSlice* pSlice);
+void GomRCInitForOneSlice(SSlice* pSlice, const int32_t kiBitsPerMb);
 void CheckFrameSkipBasedMaxbr (sWelsEncCtx* pCtx,const long long uiTimeStamp, int32_t iDidIdx);
 void UpdateBufferWhenFrameSkipped(sWelsEncCtx* pCtx, int32_t iSpatialNum);
 void UpdateMaxBrCheckWindowStatus(sWelsEncCtx* pCtx, int32_t iSpatialNum, const long long uiTimeStamp);
--- a/codec/encoder/core/inc/svc_enc_frame.h
+++ b/codec/encoder/core/inc/svc_enc_frame.h
@@ -112,6 +112,8 @@
 SPicture*               pDecPic;        // reconstruction picture pointer for layer
 SPicture*               pRefOri[MAX_REF_PIC_COUNT];
 
+bool                    bThreadSlcBufferFlag;
+bool                    bSliceBsBufferFlag;
 int32_t                 iMaxSliceNum;
 int32_t                 NumSliceCodedOfPartition[MAX_THREADS_NUM];      // for dynamic slicing mode
 int32_t                 LastCodedMbIdxOfPartition[MAX_THREADS_NUM];     // for dynamic slicing mode
--- a/codec/encoder/core/inc/svc_encode_slice.h
+++ b/codec/encoder/core/inc/svc_encode_slice.h
@@ -107,10 +107,11 @@
 
 void InitSliceRefInfoWithBase (SSlice* pSlice, SSlice* pBaseSlice, const uint8_t kuiRefCount);
 
-int32_t InitSliceList (sWelsEncCtx* pCtx,
-                       SSlice*& pSliceList,
+int32_t InitSliceList (SSlice*& pSliceList,
+                       SBitStringAux* pBsWrite,
                        const int32_t kiMaxSliceNum,
-                       const int32_t kiDlayerIndex,
+                       const int32_t kiMaxSliceBufferSize,
+                       const bool bIndependenceBsBuffer,
                        CMemoryAlign* pMa);
 
 int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3716,14 +3716,6 @@
         pLayerBsInfo->eFrameType    = eFrameType;
         pLayerBsInfo->iSubSeqId = GetSubSequenceId (pCtx, eFrameType);
 
-        int32_t iRet = InitAllSlicesInThread(pCtx);
-        if (iRet) {
-          WelsLog (pLogCtx, WELS_LOG_ERROR,
-                "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!",
-                   pParam->sSliceArgument.uiSliceMode);
-          return ENC_RETURN_UNEXPECTED;
-        }
-
         pCtx->pTaskManage->ExecuteTasks();
         if (pCtx->iEncoderError) {
           WelsLog (pLogCtx, WELS_LOG_ERROR,
@@ -3730,14 +3722,6 @@
                    "WelsEncoderEncodeExt(), multi-slice (mode %d) encoding error!",
                    pParam->sSliceArgument.uiSliceMode);
           return pCtx->iEncoderError;
-        }
-
-        iRet = SliceLayerInfoUpdate (pCtx, pFbi, pLayerBsInfo, pParam->sSliceArgument.uiSliceMode);
-        if (iRet) {
-          WelsLog (pLogCtx, WELS_LOG_ERROR,
-                   "WelsEncoderEncodeExt(), multi-slice (mode %d) SliceLayerInfoUpdate() error!",
-                   pParam->sSliceArgument.uiSliceMode);
-          return ENC_RETURN_UNEXPECTED;
         }
 
         iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -510,18 +510,12 @@
   pEncCtx->iGlobalQp = iLumaQp;
 }
 
-void RCInitOneSliceInformation(sWelsEncCtx* pEncCtx, SSlice* pSlice) {
-
-  bool bGomRC = (RC_OFF_MODE == pEncCtx->pSvcParam->iRCMode ||
-                 RC_BUFFERBASED_MODE == pEncCtx->pSvcParam->iRCMode ) ? false : true;
-  if(bGomRC) {
-    SRCSlicing* pSOverRc        = &pSlice->sSlicingOverRc;
-    const int32_t kiBitsPerMb   = pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].iBitsPerMb;
-    pSOverRc->iStartMbSlice     = pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
-    pSOverRc->iEndMbSlice       = pSOverRc->iStartMbSlice + pSlice->iCountMbNumInSlice - 1;
-    pSOverRc->iTargetBitsSlice  = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * pSlice->iCountMbNumInSlice,
-                                                  INT_MULTIPLY);
-  }
+void GomRCInitForOneSlice(SSlice* pSlice, const int32_t kiBitsPerMb) {
+  SRCSlicing* pSOverRc        = &pSlice->sSlicingOverRc;
+  pSOverRc->iStartMbSlice     = pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
+  pSOverRc->iEndMbSlice       = pSOverRc->iStartMbSlice + pSlice->iCountMbNumInSlice - 1;
+  pSOverRc->iTargetBitsSlice  = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * pSlice->iCountMbNumInSlice,
+                                                INT_MULTIPLY);
 }
 
 void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
@@ -530,6 +524,8 @@
   const int32_t kiSliceNum  = pEncCtx->pCurDqLayer->iMaxSliceNum;
   pWelsSvcRc->iBitsPerMb    = WELS_DIV_ROUND (static_cast<int64_t> (pWelsSvcRc->iTargetBits) * INT_MULTIPLY,
                                               pWelsSvcRc->iNumberMbFrame);
+  pWelsSvcRc->bGomRC        = (RC_OFF_MODE == pEncCtx->pSvcParam->iRCMode ||
+                              RC_BUFFERBASED_MODE == pEncCtx->pSvcParam->iRCMode) ? false : true;
   for (int32_t i = 0; i < kiSliceNum; i++) {
       SRCSlicing* pSOverRc        = &ppSliceInLayer[i]->sSlicingOverRc;
       pSOverRc->iTotalQpSlice     = 0;
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -450,7 +450,7 @@
   return true;
 }
 
-static inline void WlesMarkMMCORefInfoWithBase(SSlice** ppSliceList,
+static inline void WelsMarkMMCORefInfoWithBase(SSlice** ppSliceList,
                                                SSlice* pBaseSlice,
                                                const int32_t kiCountSliceNum) {
   int32_t iSliceIdx = 0;
@@ -463,7 +463,7 @@
   }
 }
 
-void WlesMarkMMCORefInfo (sWelsEncCtx* pCtx, SLTRState* pLtr,
+void WelsMarkMMCORefInfo (sWelsEncCtx* pCtx, SLTRState* pLtr,
                           SSlice** ppSliceList, const int32_t kiCountSliceNum) {
   SSlice* pBaseSlice            = ppSliceList[0];
   SRefPicMarking* pRefPicMark   = &pBaseSlice->sSliceHeaderExt.sSliceHeader.sRefMarking;
@@ -488,7 +488,7 @@
     }
   }
 
-  WlesMarkMMCORefInfoWithBase(ppSliceList, pBaseSlice, kiCountSliceNum);
+  WelsMarkMMCORefInfoWithBase(ppSliceList, pBaseSlice, kiCountSliceNum);
 }
 
 void WelsMarkPic (sWelsEncCtx* pCtx) {
@@ -511,7 +511,7 @@
     }
   }
 
-  WlesMarkMMCORefInfo (pCtx, pLtr, pCtx->pCurDqLayer->ppSliceInLayer, kiCountSliceNum);
+  WelsMarkMMCORefInfo (pCtx, pLtr, pCtx->pCurDqLayer->ppSliceInLayer, kiCountSliceNum);
 }
 
 int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest) {
@@ -889,7 +889,7 @@
   return (kiFrameNum < (1 << 30)); // TODO: use the original judge first, may be improved
 }
 
-void WlesMarkMMCORefInfoScreen (sWelsEncCtx* pCtx, SLTRState* pLtr,
+void WelsMarkMMCORefInfoScreen (sWelsEncCtx* pCtx, SLTRState* pLtr,
                                 SSlice** ppSliceList, const int32_t kiCountSliceNum) {
   SSlice* pBaseSlice          = ppSliceList[0];
   SRefPicMarking* pRefPicMark = &pBaseSlice->sSliceHeaderExt.sSliceHeader.sRefMarking;
@@ -904,7 +904,7 @@
     pRefPicMark->SMmcoRef[pRefPicMark->uiMmcoCount++].iMmcoType = MMCO_LONG;
   }
 
-  WlesMarkMMCORefInfoWithBase(ppSliceList, pBaseSlice, kiCountSliceNum);
+  WelsMarkMMCORefInfoWithBase(ppSliceList, pBaseSlice, kiCountSliceNum);
 }
 
 void WelsMarkPicScreen (sWelsEncCtx* pCtx) {
@@ -987,7 +987,7 @@
 
   const int32_t iSliceNum = pCtx->pCurDqLayer->iMaxSliceNum;
 
-  WlesMarkMMCORefInfoScreen (pCtx, pLtr, pCtx->pCurDqLayer->ppSliceInLayer, iSliceNum);
+  WelsMarkMMCORefInfoScreen (pCtx, pLtr, pCtx->pCurDqLayer->ppSliceInLayer, iSliceNum);
 
   return;
 }
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -928,21 +928,16 @@
   }
 }
 
-int32_t InitSliceList (sWelsEncCtx* pCtx,
-                       SSlice*& pSliceList,
+int32_t InitSliceList (SSlice*& pSliceList,
+                       SBitStringAux* pBsWrite,
                        const int32_t kiMaxSliceNum,
-                       const int32_t kiDlayerIndex,
+                       const int32_t kiMaxSliceBufferSize,
+                       const bool bIndependenceBsBuffer,
                        CMemoryAlign* pMa) {
-  SSliceArgument* pSliceArgument  = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
-  int32_t iMaxSliceBufferSize     = (pCtx)->iSliceBufferSize[kiDlayerIndex];
   int32_t iSliceIdx               = 0;
   int32_t iRet                    = 0;
 
-  //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite
-  //even though multi-thread is on for other layers
-  bool bIndependenceBsBuffer   = (pCtx->pSvcParam->iMultipleThreadIdc > 1 &&
-                                  SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false;
-  if (iMaxSliceBufferSize <= 0) {
+  if (kiMaxSliceBufferSize <= 0) {
     return ENC_RETURN_UNEXPECTED;
   }
 
@@ -958,9 +953,9 @@
     pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
 
     iRet = InitSliceBsBuffer (pSlice,
-                              &pCtx->pOut->sBsWrite,
+                              pBsWrite,
                               bIndependenceBsBuffer,
-                              iMaxSliceBufferSize,
+                              kiMaxSliceBufferSize,
                               pMa);
     if (ENC_RETURN_SUCCESS != iRet) {
       return iRet;
@@ -1001,11 +996,14 @@
                               const int32_t kiThreadIdx,
                               const int32_t kiDlayerIdx,
                               const int32_t kiSliceIdx) {
-  const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum;
 
-  assert(kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iMaxSliceNum -1 );
-
-  pSlice = &pCtx->pCurDqLayer->sSliceThreadInfo [kiThreadIdx].pSliceInThread[kiCodedNumInThread];
+  if (pCtx->pCurDqLayer->bThreadSlcBufferFlag) {
+      const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum;
+      assert(kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iMaxSliceNum -1 );
+      pSlice = &pCtx->pCurDqLayer->sSliceThreadInfo [kiThreadIdx].pSliceInThread[kiCodedNumInThread];
+  } else {
+      pSlice = &pCtx->pCurDqLayer->sSliceThreadInfo [0].pSliceInThread[kiSliceIdx];
+  }
   pSlice->iSliceIdx   = kiSliceIdx;
   pSlice->uiThreadIdx = kiThreadIdx;
 
@@ -1023,18 +1021,22 @@
                              CMemoryAlign* pMa) {
   int32_t iThreadNum      = pCtx->pSvcParam->iMultipleThreadIdc;
   int32_t iMaxSliceNum    = 0;
+  int32_t iSlcBufferNum   = 0;
   int32_t iIdx            = 0;
   int32_t iRet            = 0;
-  SliceModeEnum eSlicMode = pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument.uiSliceMode;
 
   assert (iThreadNum > 0);
-  if( SM_SIZELIMITED_SLICE == eSlicMode && iThreadNum > 1) {
-     iMaxSliceNum = pDqLayer->iMaxSliceNum / iThreadNum + 1;
+
+  //for fixed slice num case, no need to reallocate, so one slice buffer for all thread
+  if( pDqLayer->bThreadSlcBufferFlag) {
+    iMaxSliceNum  = pDqLayer->iMaxSliceNum / iThreadNum + 1;
+    iSlcBufferNum = iThreadNum;
   } else {
-    iMaxSliceNum = pDqLayer->iMaxSliceNum;
+    iMaxSliceNum  = pDqLayer->iMaxSliceNum;
+    iSlcBufferNum = 1;
   }
 
-  while (iIdx < iThreadNum) {
+  while (iIdx < iSlcBufferNum) {
     pDqLayer->sSliceThreadInfo[iIdx].iMaxSliceNum   = iMaxSliceNum;
     pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0;
     pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInThread");
@@ -1043,10 +1045,11 @@
                "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceInThread[iIdx] is NULL");
       return ENC_RETURN_MEMALLOCERR;
     }
-    iRet = InitSliceList (pCtx,
-                          pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread,
+    iRet = InitSliceList (pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread,
+                          &pCtx->pOut->sBsWrite,
                           iMaxSliceNum,
-                          kiDlayerIndex,
+                          pCtx->iSliceBufferSize[kiDlayerIndex],
+                          pDqLayer->bSliceBsBufferFlag,
                           pMa);
     if (ENC_RETURN_SUCCESS != iRet) {
       return iRet;
@@ -1059,6 +1062,7 @@
     pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0;
     pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = NULL;
   }
+
   return ENC_RETURN_SUCCESS;
 }
 
@@ -1071,7 +1075,16 @@
   int32_t iThreadIdx   = 0;
   int32_t iStartIdx    = 0;
   int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum;
+  SSliceArgument* pSliceArgument  = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
 
+  //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite
+  //even though multi-thread is on for other layers
+  pDqLayer->bSliceBsBufferFlag = (pCtx->pSvcParam->iMultipleThreadIdc > 1 &&
+                                 SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false;
+
+  pDqLayer->bThreadSlcBufferFlag = (pCtx->pSvcParam->iMultipleThreadIdc > 1 &&
+                                   SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? true : false;
+
   iRet = InitSliceThreadInfo (pCtx,
                         pDqLayer,
                         kiDlayerIndex,
@@ -1103,7 +1116,7 @@
     return ENC_RETURN_MEMALLOCERR;
   }
 
-  iRet = InitSliceBoundaryInfo (pDqLayer, &pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument, iMaxSliceNum);
+  iRet = InitSliceBoundaryInfo (pDqLayer, pSliceArgument, iMaxSliceNum);
   if (ENC_RETURN_SUCCESS != iRet) {
     return iRet;
   }
@@ -1605,10 +1618,11 @@
 }
 
 int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, const int32_t kiNalType) {
-  SDqLayer* pCurLayer                   = pEncCtx->pCurDqLayer;
-  SNalUnitHeaderExt* pNalHeadExt        = &pCurLayer->sLayerInfo.sNalHeaderExt;
-  SBitStringAux* pBs                    = pCurSlice->pSliceBsa;
-  const int32_t kiDynamicSliceFlag      = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode
+  SDqLayer* pCurLayer              = pEncCtx->pCurDqLayer;
+  SWelsSvcRc* pWelsSvcRc           = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
+  SNalUnitHeaderExt* pNalHeadExt   = &pCurLayer->sLayerInfo.sNalHeaderExt;
+  SBitStringAux* pBs               = pCurSlice->pSliceBsa;
+  const int32_t kiDynamicSliceFlag = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode
                                           == SM_SIZELIMITED_SLICE);
   if (I_SLICE == pEncCtx->eSliceType) {
     pNalHeadExt->bIdrFlag = 1;
@@ -1620,8 +1634,10 @@
 
   WelsSliceHeaderExtInit (pEncCtx, pCurLayer, pCurSlice);
 
-  //init slice RC information
-  RCInitOneSliceInformation(pEncCtx, pCurSlice);
+  //RomRC init slice by slice
+  if (pWelsSvcRc->bGomRC) {
+    GomRCInitForOneSlice(pCurSlice, pWelsSvcRc->iBitsPerMb);
+  }
 
   g_pWelsWriteSliceHeader[pCurSlice->bSliceHeaderExtFlag] (pEncCtx, pBs, pCurLayer, pCurSlice,
       pEncCtx->pFuncList->pParametersetStrategy);
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -119,9 +119,6 @@
   iReturn   = SetSliceBoundaryInfo(m_pCtx->pCurDqLayer, m_pSlice, m_iSliceIdx);
   WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
 
-  m_pCtx->iEncoderError   = SetSliceBoundaryInfo(m_pCtx->pCurDqLayer, m_pSlice, m_iSliceIdx);
-  WELS_VERIFY_RETURN_IFNEQ (m_pCtx->iEncoderError, ENC_RETURN_SUCCESS)
-
   SetOneSliceBsBufferUnderMultithread (m_pCtx, m_iThreadIdx, m_pSlice);
 
   assert ((void*) (&m_pSliceBs->sBsWrite) == (void*)m_pSlice->pSliceBsa);
@@ -195,7 +192,7 @@
 #if MT_DEBUG_BS_WR
   m_pSliceBs->bSliceCodedFlag = true;
 #endif//MT_DEBUG_BS_WR
-    m_pCtx->pCurDqLayer->sSliceThreadInfo[m_iThreadIdx].iCodedSliceNum ++;
+
   return ENC_RETURN_SUCCESS;
 }
 
--- a/run_NasmCheck.sh
+++ /dev/null
@@ -1,15 +1,0 @@
-#!/bin/bash
-
-echo "test common!"
-nasm=""
-nasm_list=(nasm /usr/bin/nasm /opt/local/bin/nasm)
-for cmd in ${nasm_list[@]}
-do
-    ver=`$cmd -v 2>/dev/null | awk '{print $3}'`
-	[[ $ver =~ ^2\.1[0-9] ]] && nasm=$cmd && break
-done
-
-echo "ver is $ver"
-echo "nasm is $nasm"
-[ "$nasm" = "" ] && echo "[Error] pls install nasm (2.10+)" 1>&2 && exit 1
-
--- a/test/encoder/EncUT_SliceBufferReallocate.cpp
+++ b/test/encoder/EncUT_SliceBufferReallocate.cpp
@@ -206,7 +206,9 @@
     SWelsFuncPtrList sEncFunctionList;
     pCtx->pFuncList = &sEncFunctionList;
 
+    //always multi thread cases
     pCtx->pSvcParam->iMultipleThreadIdc = (rand() % MAX_THREADS_NUM) + 1;
+    pCtx->pSvcParam->iMultipleThreadIdc = (pCtx->pSvcParam->iMultipleThreadIdc <= 1 )? 2 : pCtx->pSvcParam->iMultipleThreadIdc;
     pCtx->iActiveThreadsNum = pCtx->pSvcParam->iMultipleThreadIdc;
     pCtx->pSvcParam->iSpatialLayerNum = 1;
     pCtx->pSvcParam->bSimulcastAVC = (bool)rand() % 2;
@@ -366,13 +368,17 @@
 }
 
 void CSliceBufferReallocatTest::SimulateEncodedOneSlice(const int32_t kiSlcIdx, const int32_t kiThreadIdx) {
-    int32_t iCodedSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum;
+    if(m_EncContext.pCurDqLayer->bThreadSlcBufferFlag) {
+        int32_t iCodedSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum;
 
-    EXPECT_TRUE(NULL != m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread);
-    EXPECT_TRUE(NULL != &m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread[iCodedSlcNumInThrd]);
+        EXPECT_TRUE(NULL != m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread);
+        EXPECT_TRUE(NULL != &m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread[iCodedSlcNumInThrd]);
 
-    m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread[iCodedSlcNumInThrd].iSliceIdx = kiSlcIdx;
-    m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum ++;
+        m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread[iCodedSlcNumInThrd].iSliceIdx = kiSlcIdx;
+        m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum ++;
+    } else {
+        m_EncContext.pCurDqLayer->sSliceThreadInfo[0].pSliceInThread[kiSlcIdx].iSliceIdx = kiSlcIdx;
+    }
 }
 
 void CSliceBufferReallocatTest::SimulateSliceInOnePartition(const int32_t kiPartNum,
@@ -497,7 +503,7 @@
     int32_t iMaxSliceNumNew = 0;
     int32_t iSlcBuffNumInThrd = 0;
 
-    InitParamForTestCase(iLayerIdx);
+    InitParamForSizeLimitSlcModeCase(iLayerIdx);
     pCtx->pCurDqLayer = pCtx->ppDqLayerList[iLayerIdx];
     iRet = InitAllSlicesInThread(pCtx);
     EXPECT_TRUE(cmResultSuccess == iRet);
@@ -560,7 +566,7 @@
     sWelsEncCtx* pCtx = &m_EncContext;
     SSliceArgument* pSliceArgument = &pCtx->pSvcParam->sSpatialLayers[iLayerIdx].sSliceArgument;
 
-    InitParamForTestCase(iLayerIdx);
+    InitParamForSizeLimitSlcModeCase(iLayerIdx);
 
     pCtx->pCurDqLayer = pCtx->ppDqLayerList[iLayerIdx];
     int32_t iRet = InitAllSlicesInThread(pCtx);
@@ -591,7 +597,7 @@
     SFrameBSInfo FrameBsInfo;
     SLayerBSInfo* pLayerBsInfo = NULL;
 
-    InitParamForTestCase(iLayerIdx);
+    InitParamForSizeLimitSlcModeCase(iLayerIdx);
     pCtx->pCurDqLayer = pCtx->ppDqLayerList[iLayerIdx];
     iRet = InitAllSlicesInThread(pCtx);
     EXPECT_TRUE(cmResultSuccess == iRet);