ref: ff5976515f5dbc4fbf48d6e56832866211e46468
parent: 01e31ffe532c1b16d4300ff06f0a081f075ff4f1
parent: 37a6e8fac05abd8c7aa2f8c6cd9e26eceb1d8ee9
author: ruil2 <ruil2@cisco.com>
date: Thu Mar 23 13:43:50 EDT 2017
Merge pull request #2698 from shihuade/MultiThread_V10.1#1680#1683 Slice buffer reallocate design::PR01::ppSliceLayer instead pSliceInLayer
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -57,7 +57,7 @@
void CalcSliceComplexRatio (SDqLayer* pCurDq);
-int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t kiSliceNum);
+int32_t NeedDynamicAdjust (SSlice** ppSliceInLayer, const int32_t iSliceNum);
void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
SDqLayer* pCurDqLayer,
--- a/codec/encoder/core/inc/svc_enc_slice_segment.h
+++ b/codec/encoder/core/inc/svc_enc_slice_segment.h
@@ -149,12 +149,12 @@
/*!
* \brief Get first mb in slice/slice_group: uiSliceIdc (apply in Single/multiple slices and FMO)
*
- * \param pSliceInLayer slice list in current layer
+ * \param ppSliceInLayer slice list in current layer
* \param kiSliceIdc slice idc
*
* \return first_mb - successful; -1 - failed;
*/
-int32_t WelsGetFirstMbOfSlice (SSlice* pSliceInLayer, const int32_t kiSliceIdc);
+int32_t WelsGetFirstMbOfSlice (SSlice** ppSliceInLayer, const int32_t kiSliceIdc);
/*!
* \brief Get successive mb to be processed in slice/slice_group: uiSliceIdc (apply in Single/multiple slices and FMO)
--- a/codec/encoder/core/inc/svc_encode_slice.h
+++ b/codec/encoder/core/inc/svc_encode_slice.h
@@ -80,7 +80,7 @@
int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice); // for intra non-dynamic slice
int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice); // for intra dynamic slice
-//slice buffer init, allocate and free process
+//slice buffer init, allocate/re-allocate and free process
int32_t AllocMbCacheAligned (SMbCache* pMbCache, CMemoryAlign* pMa);
void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa);
@@ -87,8 +87,7 @@
int32_t InitSliceMBInfo (SSliceArgument* pSliceArgument,
SSlice* pSlice,
const int32_t kiMBWidth,
- const int32_t kiMBHeight,
- CMemoryAlign* pMa);
+ const int32_t kiMBHeight);
int32_t AllocateSliceMBBuffer (SSlice* pSlice, CMemoryAlign* pMa);
@@ -98,10 +97,43 @@
const int32_t iMaxSliceBufferSize,
CMemoryAlign* pMa);
-void FreeSliceBuffer(SSlice*& pSliceList,
- const int32_t kiMaxSliceNum,
- CMemoryAlign* pMa,
- const char* kpTag);
+void FreeSliceBuffer (SSlice*& pSliceList,
+ const int32_t kiMaxSliceNum,
+ CMemoryAlign* pMa,
+ const char* kpTag);
+
+int32_t InitSliceList (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ SSlice*& pSliceList,
+ const int32_t kiMaxSliceNum,
+ const int32_t kiDlayerIndex,
+ CMemoryAlign* pMa);
+
+int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
+ SSlice*& pSlice,
+ const int32_t kiThreadIdx,
+ const int32_t kiDlayerIdx,
+ const int32_t kiSliceIdx);
+
+int32_t InitSliceInLayer (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ const int32_t kiDlayerIndex,
+ CMemoryAlign* pMa);
+
+int32_t ReallocateSliceList (sWelsEncCtx* pCtx,
+ SSliceArgument* pSliceArgument,
+ SSlice*& pSliceList,
+ const int32_t kiMaxSliceNumOld,
+ const int32_t kiMaxSliceNumNew);
+
+int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ const int32_t kiDlayerIdx,
+ const int32_t kiThreadIndex);
+
+int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx);
+
+int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx);
//slice encoding process
int32_t WelsCodePSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice);
--- a/codec/encoder/core/src/deblocking.cpp
+++ b/codec/encoder/core/src/deblocking.cpp
@@ -658,7 +658,7 @@
const int32_t kiMbWidth = pCurDq->iMbWidth;
const int32_t kiMbHeight = pCurDq->iMbHeight;
SMB* pCurrentMbBlock = pCurDq->sMbDataP;
- SSliceHeaderExt* sSliceHeaderExt = &pCurDq->sLayerInfo.pSliceInLayer[0].sSliceHeaderExt;
+ SSliceHeaderExt* sSliceHeaderExt = &pCurDq->ppSliceInLayer[0]->sSliceHeaderExt;
SDeblockingFilter pFilter;
/* Step1: parameters set */
@@ -692,7 +692,7 @@
void DeblockingFilterSliceAvcbase (SDqLayer* pCurDq, SWelsFuncPtrList* pFunc, const int32_t kiSliceIdx) {
SMB* pMbList = pCurDq->sMbDataP;
- SSliceHeaderExt* sSliceHeaderExt = &pCurDq->sLayerInfo.pSliceInLayer[kiSliceIdx].sSliceHeaderExt;
+ SSliceHeaderExt* sSliceHeaderExt = &pCurDq->ppSliceInLayer[kiSliceIdx]->sSliceHeaderExt;
SMB* pCurrentMbBlock;
const int32_t kiMbWidth = pCurDq->iMbWidth;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -921,6 +921,7 @@
return 0;
}
+
void FreeSliceInLayer (SDqLayer* pDq, CMemoryAlign* pMa) {
int32_t iIdx = 0;
@@ -939,6 +940,11 @@
FreeSliceInLayer (pDq, pMa);
+ if (pDq->ppSliceInLayer) {
+ pMa->WelsFree (pDq->ppSliceInLayer, "pDq->ppSliceInLayer");
+ pDq->ppSliceInLayer = NULL;
+ }
+
if (pDq->pNumSliceCodedOfPartition) {
pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition");
pDq->pNumSliceCodedOfPartition = NULL;
@@ -983,140 +989,6 @@
pRefList = NULL;
}
-
-
-static inline int32_t InitSliceList (sWelsEncCtx** ppCtx,
- SDqLayer* pDqLayer,
- SSlice* pSliceList,
- const int32_t kiMaxSliceNum,
- const int32_t kiDlayerIndex,
- CMemoryAlign* pMa) {
- const int32_t kiMBWidth = pDqLayer->iMbWidth;
- const int32_t kiMBHeight = pDqLayer->iMbHeight;
- SSliceArgument* pSliceArgument = & (*ppCtx)->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
- int32_t iMaxSliceBufferSize = (*ppCtx)->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 = ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 &&
- SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false;
-
- if (iMaxSliceBufferSize <= 0 || kiMBWidth <= 0 || kiMBHeight <= 0) {
- return ENC_RETURN_UNEXPECTED;
- }
-
- while (iSliceIdx < kiMaxSliceNum) {
- SSlice* pSlice = pSliceList + iSliceIdx;
- if (NULL == pSlice)
- return ENC_RETURN_MEMALLOCERR;
-
- pSlice->uiSliceIdx = iSliceIdx;
-
- iRet = InitSliceBsBuffer (pSlice,
- & (*ppCtx)->pOut->sBsWrite,
- bIndependenceBsBuffer,
- iMaxSliceBufferSize,
- pMa);
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
-
- iRet = InitSliceMBInfo (pSliceArgument, pSlice,
- kiMBWidth, kiMBHeight,
- pMa);
-
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
-
- iRet = AllocateSliceMBBuffer (pSlice, pMa);
-
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
-
- ++ iSliceIdx;
- }
- return ENC_RETURN_SUCCESS;
-}
-
-static inline int32_t InitSliceThreadInfo (sWelsEncCtx** ppCtx,
- SDqLayer* pDqLayer,
- const int32_t kiDlayerIndex,
- CMemoryAlign* pMa) {
-
- SSliceThreadInfo* pSliceThreadInfo = &pDqLayer->sSliceThreadInfo;
- int32_t iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
- int32_t iMaxSliceNumInThread = 0;
- int32_t iIdx = 0;
- int32_t iRet = 0;
-
- assert (iThreadNum > 0);
- iMaxSliceNumInThread = ((*ppCtx)->iMaxSliceCount / iThreadNum + 1) * 2;
- iMaxSliceNumInThread = WELS_MIN ((*ppCtx)->iMaxSliceCount, (int) iMaxSliceNumInThread);
-
- while (iIdx < iThreadNum) {
- pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
- pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
- pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) *
- iMaxSliceNumInThread, "pSliceInThread");
- if (NULL == pSliceThreadInfo->pSliceInThread[iIdx])
- return ENC_RETURN_MEMALLOCERR;
-
- iRet = InitSliceList (ppCtx,
- pDqLayer,
- pSliceThreadInfo->pSliceInThread[iIdx],
- iMaxSliceNumInThread,
- kiDlayerIndex,
- pMa);
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
-
- iIdx++;
- }
-
- for (; iIdx < MAX_THREADS_NUM; iIdx++) {
- pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
- pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
- pSliceThreadInfo->pSliceInThread[iIdx] = NULL;
- }
- return ENC_RETURN_SUCCESS;
-}
-
-static inline int32_t InitSliceInLayer (sWelsEncCtx** ppCtx,
- SDqLayer* pDqLayer,
- const int32_t kiDlayerIndex,
- CMemoryAlign* pMa) {
-
- //SWelsSvcCodingParam* pParam = (*ppCtx)->pSvcParam;
- int32_t iRet = 0;
- int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum;
-
- //if (pParam->iMultipleThreadIdc > 1) {
- // to do, will add later, slice buffer allocated based on thread mode if() else ()
- InitSliceThreadInfo (ppCtx,
- pDqLayer,
- kiDlayerIndex,
- pMa);
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
-
- //} else {
- pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
- if (NULL == pDqLayer->sLayerInfo.pSliceInLayer)
- return ENC_RETURN_MEMALLOCERR;
-
- InitSliceList (ppCtx,
- pDqLayer,
- pDqLayer->sLayerInfo.pSliceInLayer,
- iMaxSliceNum,
- kiDlayerIndex,
- pMa);
- if (ENC_RETURN_SUCCESS != iRet)
- return iRet;
- //}
-
- return ENC_RETURN_SUCCESS;
-}
/*!
* \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available
* \pParam pCtx sWelsEncCtx*
@@ -1221,7 +1093,7 @@
iMaxSliceNum = kiSliceNum;
pDqLayer->iMaxSliceNum = iMaxSliceNum;
- iResult = InitSliceInLayer (ppCtx, pDqLayer, iDlayerIndex, pMa);
+ iResult = InitSliceInLayer (*ppCtx, pDqLayer, iDlayerIndex, pMa);
if (iResult) {
WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_WARNING, "InitDqLayers(), InitSliceInLayer failed(%d)!", iResult);
FreeDqLayer (pDqLayer, pMa);
@@ -2553,7 +2425,7 @@
void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame;
int32_t iCountMbNumPerPartition = kiMbNumInFrame;
int32_t iAssignableMbLeft = kiMbNumInFrame;
@@ -2569,18 +2441,18 @@
i = 0;
while (i < iPartitionNum) {
if (i + 1 == iPartitionNum) {
- pSliceInLayer[i].iCountMbNumInSlice = iAssignableMbLeft;
+ ppSliceInLayer[i]->iCountMbNumInSlice = iAssignableMbLeft;
} else {
- pSliceInLayer[i].iCountMbNumInSlice = iCountMbNumPerPartition;
+ ppSliceInLayer[i]->iCountMbNumInSlice = iCountMbNumPerPartition;
}
- pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
+ ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i,
- pSliceInLayer[i].iCountMbNumInSlice, sizeof (uint16_t));
+ ppSliceInLayer[i]->iCountMbNumInSlice, sizeof (uint16_t));
// for next partition(or pSlice)
- iFirstMbIdx += pSliceInLayer[i].iCountMbNumInSlice;
- iAssignableMbLeft -= pSliceInLayer[i].iCountMbNumInSlice;
+ iFirstMbIdx += ppSliceInLayer[i]->iCountMbNumInSlice;
+ iAssignableMbLeft -= ppSliceInLayer[i]->iCountMbNumInSlice;
++ i;
}
}
@@ -2646,8 +2518,8 @@
SPicture* pEncPic = pCtx->pEncPic;
SPicture* pDecPic = pCtx->pDecPic;
SDqLayer* pCurDq = pCtx->pCurDqLayer;
- SSlice* pBaseSlice = &pCurDq->sLayerInfo.pSliceInLayer[0];
- SSlice* pSlice = NULL;
+ SSlice* pBaseSlice = pCurDq->ppSliceInLayer[0];
+ SSlice* pSlice = NULL;
const uint8_t kiCurDid = pCtx->uiDependencyId;
const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID);
SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid];
@@ -2691,10 +2563,10 @@
pBaseSlice->bSliceHeaderExtFlag = (NAL_UNIT_CODED_SLICE_EXT == pCtx->eNalType);
- pSlice = pBaseSlice;
iIdx = 1;
while (iIdx < iSliceCount) {
- ++ pSlice;
+ pSlice = pCurDq->ppSliceInLayer[iIdx];
+
pSlice->sSliceHeaderExt.sSliceHeader.iPpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iPpsId;
pSlice->sSliceHeaderExt.sSliceHeader.pPps = pBaseSlice->sSliceHeaderExt.sSliceHeader.pPps;
pSlice->sSliceHeaderExt.sSliceHeader.iSpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iSpsId;
@@ -2928,7 +2800,6 @@
* \brief prefetch reference picture after WelsBuildRefList
*/
static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) {
- SSlice* pSliceBase = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0];
const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer);
int32_t iIdx = 0;
uint8_t uiRefIdx = -1;
@@ -2946,8 +2817,7 @@
iIdx = 0;
while (iIdx < kiSliceCount) {
- pSliceBase->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx;
- ++ pSliceBase;
+ pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx;
++ iIdx;
}
}
@@ -3867,6 +3737,8 @@
return pCtx->iEncoderError;
}
+ //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum]
+ // UpdateSliceInLayerInfo(); // reordering
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
}
// THREAD_FULLY_FIRE_MODE && SM_SIZELIMITED_SLICE
@@ -3876,7 +3748,7 @@
int32_t iEndMbIdx = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame;
for (int32_t iIdx = kiPartitionCnt - 1; iIdx >= 0; --iIdx) {
const int32_t iFirstMbIdx =
- pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
+ pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iStartMbIndex = iFirstMbIdx;
pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iEndMbIndex = iEndMbIdx;
iEndMbIdx = iFirstMbIdx;
@@ -3909,6 +3781,12 @@
return pCtx->iEncoderError;
}
+ //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum]
+ // UpdateSliceInLayerInfo(); // reordering
+
+ //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum]
+ // UpdateSliceInLayerInfo(); // reordering
+
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);
} else { // for non-dynamic-slicing mode single threading branch..
const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
@@ -4554,7 +4432,7 @@
SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMallocz (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
if (NULL == pNalList) {
- WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pNalList is NULL");
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::FrameBsRealloc: pNalList is NULL");
return ENC_RETURN_MEMALLOCERR;
}
memcpy (pNalList, pCtx->pOut->sNalList, sizeof (SWelsNalRaw) * pCtx->pOut->iCountNals);
@@ -4563,7 +4441,7 @@
int32_t* pNalLen = (int32_t*)pMA->WelsMallocz (iCountNals * sizeof (int32_t), "pOut->pNalLen");
if (NULL == pNalLen) {
- WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pNalLen is NULL");
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::FrameBsRealloc: pNalLen is NULL");
return ENC_RETURN_MEMALLOCERR;
}
memcpy (pNalLen, pCtx->pOut->pNalLen, sizeof (int32_t) * pCtx->pOut->iCountNals);
@@ -4584,74 +4462,6 @@
}
-int32_t SliceBufferRealloc (sWelsEncCtx* pCtx) {
- CMemoryAlign* pMA = pCtx->pMemAlign;
- SDqLayer* pCurLayer = pCtx->pCurDqLayer;
- int32_t iMaxSliceNumOld = pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint;
- int32_t iMaxSliceNum = iMaxSliceNumOld;
- iMaxSliceNum *= SLICE_NUM_EXPAND_COEF;
-
- SSlice* pSlice = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "Slice");
- if (NULL == pSlice) {
- WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pSlice is NULL");
- return ENC_RETURN_MEMALLOCERR;
- }
- memcpy (pSlice, pCurLayer->sLayerInfo.pSliceInLayer, sizeof (SSlice) * iMaxSliceNumOld);
- int32_t uiSliceIdx;
- uiSliceIdx = iMaxSliceNumOld;
- SSlice* pBaseSlice = &pCurLayer->sLayerInfo.pSliceInLayer[0];
- SSliceHeaderExt* pBaseSHExt = &pBaseSlice->sSliceHeaderExt;
- SSlice* pSliceIdx = &pSlice[uiSliceIdx];
- const int32_t kiCurDid = pCtx->uiDependencyId;
- const int32_t kiBitsPerMb = WELS_DIV_ROUND (pCtx->pWelsSvcRc[kiCurDid].iTargetBits * INT_MULTIPLY,
- pCtx->pWelsSvcRc[kiCurDid].iNumberMbFrame);
- while (uiSliceIdx < iMaxSliceNum) {
- SSliceHeaderExt* pSHExt = &pSliceIdx->sSliceHeaderExt;
- pSliceIdx->uiSliceIdx = uiSliceIdx;
- if (pCtx->pSvcParam->iMultipleThreadIdc > 1)
- pSliceIdx->pSliceBsa = &pSliceIdx->sSliceBs.sBsWrite;
- else
- pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite;
- if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) {
- WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
- "CWelsH264SVCEncoder::DynSliceRealloc: realloc MbCache not successful at slice_idx=%d (max-slice=%d)",
- uiSliceIdx, iMaxSliceNum);
- return ENC_RETURN_MEMALLOCERR;
- }
-
- pSliceIdx->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag;
- pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId;
- pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps;
- pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId;
- pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps;
- pSHExt->sSliceHeader.uiRefCount = pCtx->iNumRef0;
- memcpy (&pSHExt->sSliceHeader.sRefMarking, &pBaseSHExt->sSliceHeader.sRefMarking, sizeof (SRefPicMarking));
- memcpy (&pSHExt->sSliceHeader.sRefReordering, &pBaseSHExt->sSliceHeader.sRefReordering,
- sizeof (SRefPicListReorderSyntax));
-
- pSliceIdx->sSlicingOverRc.iComplexityIndexSlice = 0;
- pSliceIdx->sSlicingOverRc.iCalculatedQpSlice = pCtx->iGlobalQp;
- pSliceIdx->sSlicingOverRc.iTotalQpSlice = 0;
- pSliceIdx->sSlicingOverRc.iTotalMbSlice = 0;
- pSliceIdx->sSlicingOverRc.iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb *
- pSlice[uiSliceIdx].iCountMbNumInSlice,
- INT_MULTIPLY);
- pSliceIdx->sSlicingOverRc.iFrameBitsSlice = 0;
- pSliceIdx->sSlicingOverRc.iGomBitsSlice = 0;
-
- pSliceIdx++;
- uiSliceIdx++;
- }
- pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice");
- pCurLayer->sLayerInfo.pSliceInLayer = pSlice;
-
- if (pCtx->iMaxSliceCount < iMaxSliceNum)
- pCtx->iMaxSliceCount = iMaxSliceNum;
- pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNum;
- pCurLayer->iMaxSliceNum = iMaxSliceNum;
- return ENC_RETURN_SUCCESS;
-}
-
int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
SFrameBSInfo* pFrameBsInfo,
SLayerBSInfo* pLayerBsInfo) {
@@ -4658,10 +4468,15 @@
int32_t iRet = 0;
iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo);
- if (ENC_RETURN_SUCCESS != iRet)
+
+ if(ENC_RETURN_SUCCESS != iRet) {
return iRet;
+ }
- iRet = SliceBufferRealloc (pCtx);
+ iRet = ReallocSliceBuffer (pCtx);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
return iRet;
}
@@ -4678,8 +4493,7 @@
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
SSliceCtx* pSliceCtx = &pCurLayer->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurLayer->sLayerInfo.pSliceInLayer;
- SSlice* pStartSlice = &pSliceInLayer[iStartSliceIdx];
+ SSlice* pStartSlice = pCurLayer->ppSliceInLayer[iStartSliceIdx];
int32_t iNalIdxInLayer = *pNalIdxInLayer;
int32_t iSliceIdx = iStartSliceIdx;
const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -513,21 +513,21 @@
}
void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
- SRCSlicing* pSOverRc = &pSliceInLayer[0].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[0]->sSlicingOverRc;
const int32_t kiSliceNum = pWelsSvcRc->iSliceNum;
const int32_t kiBitsPerMb = WELS_DIV_ROUND (static_cast<int64_t> (pWelsSvcRc->iTargetBits) * INT_MULTIPLY,
pWelsSvcRc->iNumberMbFrame);
for (int32_t i = 0; i < kiSliceNum; i++) {
- pSOverRc = &pSliceInLayer[i].sSlicingOverRc;
+ pSOverRc = &ppSliceInLayer[i]->sSlicingOverRc;
pSOverRc->iStartMbSlice =
- pSOverRc->iEndMbSlice = pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
- pSOverRc->iEndMbSlice += (pSliceInLayer[i].iCountMbNumInSlice - 1);
+ pSOverRc->iEndMbSlice = ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
+ pSOverRc->iEndMbSlice += (ppSliceInLayer[i]->iCountMbNumInSlice - 1);
pSOverRc->iTotalQpSlice = 0;
pSOverRc->iTotalMbSlice = 0;
- pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * pSliceInLayer[i].iCountMbNumInSlice,
+ pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (static_cast<int64_t> (kiBitsPerMb) * ppSliceInLayer[i]->iCountMbNumInSlice,
INT_MULTIPLY);
pSOverRc->iFrameBitsSlice = 0;
pSOverRc->iGomBitsSlice = 0;
@@ -610,15 +610,15 @@
}
void RcInitGomParameters (sWelsEncCtx* pEncCtx) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
- SRCSlicing* pSOverRc = &pSliceInLayer[0].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[0]->sSlicingOverRc;
const int32_t kiSliceNum = pWelsSvcRc->iSliceNum;
const int32_t kiGlobalQp = pEncCtx->iGlobalQp;
pWelsSvcRc->iAverageFrameQp = 0;
for (int32_t i = 0; i < kiSliceNum; ++i) {
- pSOverRc = &pSliceInLayer[i].sSlicingOverRc;
+ pSOverRc = &ppSliceInLayer[i]->sSlicingOverRc;
pSOverRc->iComplexityIndexSlice = 0;
pSOverRc->iCalculatedQpSlice = kiGlobalQp;
}
@@ -627,9 +627,9 @@
}
void RcCalculateMbQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, const int32_t kiSliceId) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
- SRCSlicing* pSOverRc = &pSliceInLayer[kiSliceId].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[kiSliceId]->sSlicingOverRc;
int32_t iLumaQp = pSOverRc->iCalculatedQpSlice;
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
@@ -667,10 +667,10 @@
}
void RcGomTargetBits (sWelsEncCtx* pEncCtx, const int32_t kiSliceId) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
SWelsSvcRc* pWelsSvcRc_Base = NULL;
- SRCSlicing* pSOverRc = &pSliceInLayer[kiSliceId].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[kiSliceId]->sSlicingOverRc;
int32_t iAllocateBits = 0;
int32_t iSumSad = 0;
@@ -705,9 +705,9 @@
void RcCalculateGomQp (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iSliceId) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
- SRCSlicing* pSOverRc = &pSliceInLayer[iSliceId].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[iSliceId]->sSlicingOverRc;
int64_t iBitsRatio = 1;
int64_t iLeftBits = pSOverRc->iTargetBitsSlice - pSOverRc->iFrameBitsSlice;
@@ -1016,8 +1016,8 @@
}
void RcUpdatePictureQpBits (sWelsEncCtx* pEncCtx, int32_t iCodedBits) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- SRCSlicing* pSOverRc = &pSliceInLayer[0].sSlicingOverRc;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[0]->sSlicingOverRc;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
SSliceCtx* pCurSliceCtx = &pEncCtx->pCurDqLayer->sSliceEncCtx;
int32_t iTotalQp = 0, iTotalMb = 0;
@@ -1025,7 +1025,7 @@
if (pEncCtx->eSliceType == P_SLICE) {
for (i = 0; i < pCurSliceCtx->iSliceNumInFrame; i++) {
- pSOverRc = &pSliceInLayer[i].sSlicingOverRc;
+ pSOverRc = &ppSliceInLayer[i]->sSlicingOverRc;
iTotalQp += pSOverRc->iTotalQpSlice;
iTotalMb += pSOverRc->iTotalMbSlice;
}
@@ -1191,10 +1191,10 @@
}
void WelsRcMbInitGom (sWelsEncCtx* pEncCtx, SMB* pCurMb, SSlice* pSlice) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
const int32_t kiSliceId = pSlice->uiSliceIdx;
- SRCSlicing* pSOverRc = &pSliceInLayer[kiSliceId].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[kiSliceId]->sSlicingOverRc;
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
@@ -1218,10 +1218,10 @@
}
void WelsRcMbInfoUpdateGom (sWelsEncCtx* pEncCtx, SMB* pCurMb, int32_t iCostLuma, SSlice* pSlice) {
- SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
int32_t iSliceId = pSlice->uiSliceIdx;
- SRCSlicing* pSOverRc = &pSliceInLayer[iSliceId].sSlicingOverRc;
+ SRCSlicing* pSOverRc = &ppSliceInLayer[iSliceId]->sSlicingOverRc;
const int32_t kiComplexityIndex = pSOverRc->iComplexityIndexSlice;
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -450,12 +450,12 @@
return true;
}
void WlesMarkMMCORefInfo (sWelsEncCtx* pCtx, SLTRState* pLtr,
- SSlice* pSliceList, const int32_t kiCountSliceNum) {
+ SSlice** ppSliceList, const int32_t kiCountSliceNum) {
int32_t iSliceIdx = 0;
int32_t iGoPFrameNumInterval = ((pCtx->pSvcParam->uiGopSize >> 1) > 1) ? (pCtx->pSvcParam->uiGopSize >> 1) : (1);
for (iSliceIdx = 0; iSliceIdx < kiCountSliceNum; iSliceIdx++) {
- SSliceHeaderExt* pSliceHdrExt = &pSliceList[iSliceIdx].sSliceHeaderExt;
+ SSliceHeaderExt* pSliceHdrExt = &ppSliceList[iSliceIdx]->sSliceHeaderExt;
SSliceHeader* pSliceHdr = &pSliceHdrExt->sSliceHeader;
SRefPicMarking* pRefPicMark = &pSliceHdr->sRefMarking;
@@ -483,7 +483,7 @@
void WelsMarkPic (sWelsEncCtx* pCtx) {
SLTRState* pLtr = &pCtx->pLtr[pCtx->uiDependencyId];
const int32_t kiCountSliceNum = GetCurrentSliceNum (pCtx->pCurDqLayer);
- SSlice* pSliceList = NULL;
+ SSlice** ppSliceList = NULL;
if (pCtx->pSvcParam->bEnableLongTermReference && pLtr->bLTRMarkEnable && pCtx->uiTemporalId == 0) {
if (!pLtr->bReceivedT0LostFlag && pLtr->uiLtrMarkInterval > pCtx->pSvcParam->iLtrMarkPeriod
@@ -501,14 +501,8 @@
}
}
- if (pCtx->iActiveThreadsNum > 1) {
- //will replace with thread-base pslice buffer later
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- WlesMarkMMCORefInfo (pCtx, pLtr, pSliceList, kiCountSliceNum);
- } else {
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- WlesMarkMMCORefInfo (pCtx, pLtr, pSliceList, kiCountSliceNum);
- }
+ ppSliceList = pCtx->pCurDqLayer->ppSliceInLayer;
+ WlesMarkMMCORefInfo (pCtx, pLtr, ppSliceList, kiCountSliceNum);
}
int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest) {
@@ -656,7 +650,7 @@
}
void WelsUpdateSliceHeaderSyntax (sWelsEncCtx* pCtx, const int32_t iAbsDiffPicNumMinus1,
- SSlice* pSliceList, const int32_t uiFrameType) {
+ SSlice** ppSliceList, const int32_t uiFrameType) {
const int32_t kiCountSliceNum = GetCurrentSliceNum (pCtx->pCurDqLayer);
SLTRState* pLtr = &pCtx->pLtr[pCtx->uiDependencyId];
int32_t iIdx = 0;
@@ -664,7 +658,7 @@
assert (kiCountSliceNum > 0);
for (iIdx = 0; iIdx < kiCountSliceNum; iIdx++) {
- SSliceHeaderExt* pSliceHdrExt = &pSliceList[iIdx].sSliceHeaderExt;
+ SSliceHeaderExt* pSliceHdrExt = &ppSliceList[iIdx]->sSliceHeaderExt;
SSliceHeader* pSliceHdr = &pSliceHdrExt->sSliceHeader;
SRefPicListReorderSyntax* pRefReorder = &pSliceHdr->sRefReordering;
SRefPicMarking* pRefPicMark = &pSliceHdr->sRefMarking;
@@ -706,7 +700,7 @@
void WelsUpdateRefSyntax (sWelsEncCtx* pCtx, const int32_t iPOC, const int32_t uiFrameType) {
int32_t iAbsDiffPicNumMinus1 = -1;
- SSlice* pSliceList = NULL;
+ SSlice** ppSliceList = NULL;
SSpatialLayerInternal* pParamD = &pCtx->pSvcParam->sDependencyLayers[pCtx->uiDependencyId];
/*syntax for ref_pic_list_reordering()*/
if (pCtx->iNumRef0 > 0) {
@@ -720,15 +714,8 @@
}
}
- if (pCtx->iActiveThreadsNum > 0) {
- // to do: will replace with thread based buffer later
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- } else {
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- }
-
- WelsUpdateSliceHeaderSyntax (pCtx, iAbsDiffPicNumMinus1, pSliceList, uiFrameType);
-
+ ppSliceList = pCtx->pCurDqLayer->ppSliceInLayer;
+ WelsUpdateSliceHeaderSyntax (pCtx, iAbsDiffPicNumMinus1, ppSliceList, uiFrameType);
}
static inline void UpdateOriginalPicInfo (SPicture* pOrigPic, SPicture* pReconPic) {
@@ -897,11 +884,11 @@
}
void WlesMarkMMCORefInfoScreen (sWelsEncCtx* pCtx, SLTRState* pLtr,
- SSlice* pSliceList, const int32_t kiCountSliceNum) {
+ SSlice** ppSliceList, const int32_t kiCountSliceNum) {
const int32_t iMaxLtrIdx = pCtx->pSvcParam->iNumRefFrame - STR_ROOM - 1;
for (int32_t iSliceIdx = 0; iSliceIdx < kiCountSliceNum; iSliceIdx++) {
- SSliceHeaderExt* pSliceHdrExt = &pSliceList[iSliceIdx].sSliceHeaderExt;
+ SSliceHeaderExt* pSliceHdrExt = &ppSliceList[iSliceIdx]->sSliceHeaderExt;
SSliceHeader* pSliceHdr = &pSliceHdrExt->sSliceHeader;
SRefPicMarking* pRefPicMark = &pSliceHdr->sRefMarking;
@@ -920,7 +907,7 @@
SLTRState* pLtr = &pCtx->pLtr[pCtx->uiDependencyId];
int32_t iMaxTid = WELS_LOG2 (pCtx->pSvcParam->uiGopSize);
int32_t iMaxActualLtrIdx = -1;
- SSlice* pSliceList = NULL;
+ SSlice** ppSliceList = NULL;
SSpatialLayerInternal* pParamD = &pCtx->pSvcParam->sDependencyLayers[pCtx->uiDependencyId];
if (pCtx->pSvcParam->bEnableLongTermReference)
iMaxActualLtrIdx = pCtx->pSvcParam->iNumRefFrame - STR_ROOM - 1 - WELS_MAX (iMaxTid , 1);
@@ -997,13 +984,9 @@
const int32_t iSliceNum = GetCurrentSliceNum (pCtx->pCurDqLayer);
- if (pCtx->iActiveThreadsNum > 1) {
- // to do: will replace with thread based buffer later
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- } else {
- pSliceList = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
- }
- WlesMarkMMCORefInfoScreen (pCtx, pLtr, pSliceList, iSliceNum);
+
+ ppSliceList = pCtx->pCurDqLayer->ppSliceInLayer;
+ WlesMarkMMCORefInfoScreen (pCtx, pLtr, ppSliceList, iSliceNum);
return;
}
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -81,7 +81,7 @@
SMB* pMbList,
const int32_t uiSliceIdc) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
- SSlice* pUpdateSlice = &pCurDq->sLayerInfo.pSliceInLayer[uiSliceIdc];
+ SSlice* pUpdateSlice = pCurDq->ppSliceInLayer[uiSliceIdc];
const int32_t kiMbWidth = pSliceCtx->iMbWidth;
int32_t iIdx = pUpdateSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
const int32_t kiEndMbInSlice = iIdx + pUpdateSlice->iCountMbNumInSlice - 1;
@@ -94,7 +94,7 @@
void CalcSliceComplexRatio (SDqLayer* pCurDq) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
int32_t iSumAv = 0;
const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame;
int32_t iSliceIdx = 0;
@@ -103,23 +103,24 @@
WelsEmms();
while (iSliceIdx < kiSliceCount) {
- iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
- pSliceInLayer[iSliceIdx].uiSliceConsumeTime);
+ iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice,
+ ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime);
MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), uiSliceConsumeTime[%d]= %d us, slice_run= %d",
iSliceIdx,
- pSliceInLayer[iSliceIdx].uiSliceConsumeTime, pSliceInLayer[iSliceIdx].iCountMbNumInSlice);
+ ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime, ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice);
iSumAv += iAvI[iSliceIdx];
++ iSliceIdx;
}
while (-- iSliceIdx >= 0) {
- pSliceInLayer[iSliceIdx].iSliceComplexRatio = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv);
+ ppSliceInLayer[iSliceIdx]->iSliceComplexRatio = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv);
}
}
-int32_t NeedDynamicAdjust (SSlice* pSliceInLayer, const int32_t iSliceNum) {
- if (NULL == pSliceInLayer)
+int32_t NeedDynamicAdjust (SSlice** ppSliceInLayer, const int32_t iSliceNum) {
+ if ( NULL == ppSliceInLayer ) {
return false;
+ }
uint32_t uiTotalConsume = 0;
int32_t iSliceIdx = 0;
@@ -128,7 +129,11 @@
WelsEmms();
while (iSliceIdx < iSliceNum) {
- uiTotalConsume += pSliceInLayer[iSliceIdx].uiSliceConsumeTime;
+ if ( NULL == ppSliceInLayer[iSliceIdx] ) {
+ return false;
+ }
+
+ uiTotalConsume += ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime;
iSliceIdx ++;
}
if (uiTotalConsume == 0) {
@@ -143,7 +148,7 @@
float fRmse = .0f; // root mean square error of pSlice consume ratios
const float kfMeanRatio = 1.0f / iSliceNum;
do {
- const float fRatio = 1.0f * pSliceInLayer[iSliceIdx].uiSliceConsumeTime / uiTotalConsume;
+ const float fRatio = 1.0f * ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime / uiTotalConsume;
const float fDiffRatio = fRatio - kfMeanRatio;
fRmse += (fDiffRatio * fDiffRatio);
++ iSliceIdx;
@@ -170,7 +175,7 @@
SDqLayer* pCurDqLayer,
int32_t iCurDid) {
SSliceCtx* pSliceCtx = &pCurDqLayer->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurDqLayer->ppSliceInLayer;
const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame;
const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame;
int32_t iMinimalMbNum =
@@ -212,7 +217,7 @@
iSliceIdx = 0;
while (iSliceIdx + 1 < kiCountSliceNum) {
- int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceInLayer[iSliceIdx].iSliceComplexRatio, INT_MULTIPLY);
+ int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * ppSliceInLayer[iSliceIdx]->iSliceComplexRatio, INT_MULTIPLY);
// GOM boundary aligned
if (pCtx->pSvcParam->iRCMode != RC_OFF_MODE) {
@@ -235,8 +240,8 @@
iRunLen[iSliceIdx] = iNumMbAssigning;
MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
"[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
- iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY,
- pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
+ iSliceIdx, ppSliceInLayer[iSliceIdx]->iSliceComplexRatio * 1.0f / INT_MULTIPLY,
+ ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice,
iNumMbAssigning);
++ iSliceIdx;
iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts
@@ -244,9 +249,8 @@
iRunLen[iSliceIdx] = iMbNumLeft;
MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
"[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
- iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY,
- pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft);
-
+ iSliceIdx, ppSliceInLayer[iSliceIdx]->iSliceComplexRatio * 1.0f / INT_MULTIPLY,
+ ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice, iMbNumLeft);
pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);
}
@@ -438,7 +442,7 @@
int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) {
SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam;
SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId];
- SSlice* pSliceInlayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer;
SWelsSliceBs* pSliceBs = NULL;
const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE);
@@ -449,7 +453,7 @@
if (!kbIsDynamicSlicingMode) {
iNalIdxBase = pLbi->iNalCount = 0;
while (iSliceIdx < iSliceCount) {
- pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
+ pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs;
if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
int32_t iNalIdx = 0;
const int32_t iCountNal = pSliceBs->iNalIndex;
@@ -484,7 +488,7 @@
iSliceIdx = iPartitionIdx;
while (iIdx < kiCountSlicesCoded) {
- pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
+ pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs;
if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
@@ -600,7 +604,7 @@
int64_t iSliceStart = 0;
bool bDsaFlag = false;
iSliceIdx = pPrivateData->iSliceIndex;
- pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
+ pSlice = pCurDq->ppSliceInLayer[iSliceIdx];
pSliceBs = &pSlice->sSliceBs;
bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) &&
@@ -653,14 +657,14 @@
pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
if (bDsaFlag) {
- pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime = (uint32_t) (
+ pEncPEncCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime = (uint32_t) (
WelsTime() - iSliceStart);
MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO,
"[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, uiSliceConsumeTime %d, iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d",
pEncPEncCtx->iCodingIndex, iSliceIdx,
- pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime, iSliceSize,
- pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
- pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].iCountMbNumInSlice);
+ pEncPEncCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime, iSliceSize,
+ pCurDq->ppSliceInLayer[iSliceIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
+ pCurDq->ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice);
}
#if defined(SLICE_INFO_OUTPUT)
@@ -690,7 +694,7 @@
int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition;
SSpatialLayerInternal* pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid];
iSliceIdx = pPrivateData->iSliceIndex;
- SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt;
+ SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->ppSliceInLayer[iSliceIdx]->sSliceHeaderExt;
pStartSliceHeaderExt->sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
pCurDq->pNumSliceCodedOfPartition[kiPartitionId] =
1; // one pSlice per partition intialized, dynamic slicing inside
@@ -712,7 +716,7 @@
}
SetOneSliceBsBufferUnderMultithread (pEncPEncCtx, kiPartitionId, iSliceIdx);
- pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
+ pSlice = pCurDq->ppSliceInLayer[iSliceIdx];
pSliceBs = &pSlice->sSliceBs;
pSliceBs->uiBsPos = 0;
@@ -772,7 +776,7 @@
MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO,
"[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n",
pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize,
- pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
+ pCurDq->ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice,
kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
iAnyMbLeftInPartition = kiEndMbInPartition - (1 + pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
@@ -840,7 +844,7 @@
const int32_t kiEventCnt = uiNumThreads;
int32_t iLayerBsIdx = pCtx->pOut->iLayerBsIndex;
SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo[iLayerBsIdx];
- SSlice* pSliceInLayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCtx->pCurDqLayer->ppSliceInLayer;
if (pPriData == NULL || pFrameBsInfo == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) {
@@ -854,7 +858,7 @@
if (bIsDynamicSlicingMode) {
iEndMbIdx = pSliceCtx->iMbNumInFrame;
for (iIdx = kiEventCnt - 1; iIdx >= 0; --iIdx) {
- const int32_t iFirstMbIdx = pSliceInLayer[iIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
+ const int32_t iFirstMbIdx = ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
pPriData[iIdx].iStartMbIndex = iFirstMbIdx;
pPriData[iIdx].iEndMbIndex = iEndMbIdx;
iEndMbIdx = iFirstMbIdx;
@@ -897,7 +901,8 @@
pCtx->pCurDqLayer = pCurDq;
// do not need adjust due to not different at both slices of consumed time
- iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[0]->sLayerInfo.pSliceInLayer, pCurDq->sSliceEncCtx.iSliceNumInFrame);
+ iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[0]->ppSliceInLayer
+ , pCurDq->sSliceEncCtx.iSliceNumInFrame);
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
pCurDq,
@@ -929,7 +934,7 @@
if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation
// do not need adjust due to not different at both slices of consumed time
- iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid - 1]->sLayerInfo.pSliceInLayer,
+ iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid - 1]->ppSliceInLayer,
pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame);
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
@@ -938,7 +943,7 @@
);
} else { // use temporal layer for complexity estimation
// do not need adjust due to not different at both slices of consumed time
- iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid]->sLayerInfo.pSliceInLayer,
+ iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid]->ppSliceInLayer,
pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame);
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
@@ -964,12 +969,12 @@
#if defined(MT_DEBUG)
void TrackSliceComplexities (sWelsEncCtx* pCtx, const int32_t iCurDid) {
const int32_t kiCountSliceNum = pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame;
- SSlice* pSliceInLayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCtx->pCurDqLayer->ppSliceInLayer;
if (kiCountSliceNum > 0) {
int32_t iSliceIdx = 0;
do {
fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6.3f complexity pRatio at iDid %d pSlice %d\n",
- pSliceInLayer[iSliceIdx].iSliceComplexRatio, iCurDid, iSliceIdx);
+ ppSliceInLayer[iSliceIdx]->iSliceComplexRatio, iCurDid, iSliceIdx);
++ iSliceIdx;
} while (iSliceIdx < kiCountSliceNum);
}
@@ -987,9 +992,9 @@
pPara = pCtx->pSvcParam;
while (iSpatialIdx < iSpatialNum) {
const int32_t kiDid = pDidList[iSpatialIdx];
- SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[kiDid].sSliceArgument;
+ SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[kiDid].sSliceArgument;
SDqLayer* pCurDq = pCtx->ppDqLayerList[kiDid];
- SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame;
if (pCtx->pSliceThreading) {
@@ -1002,9 +1007,9 @@
int32_t iMaxI = 0;
while (i < kuiCountSliceNum) {
fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6d us consume_time coding_idx %d iDid %d pSlice %d\n",
- pSliceInLayer[i].uiSliceConsumeTime, pCtx->iCodingIndex, kiDid, i /*/ 1000*/);
- if (pSliceInLayer[i].uiSliceConsumeTime > uiMaxT) {
- uiMaxT = pSliceInLayer[i].uiSliceConsumeTime;
+ ppSliceInLayer[i]->uiSliceConsumeTime, pCtx->iCodingIndex, kiDid, i /*/ 1000*/);
+ if (ppSliceInLayer[i]->uiSliceConsumeTime > uiMaxT) {
+ uiMaxT = ppSliceInLayer[i]->uiSliceConsumeTime;
iMaxI = i;
}
++ i;
@@ -1019,7 +1024,7 @@
#endif//#if defined(MT_DEBUG)
void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) {
- SWelsSliceBs* pSliceBs = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceBs;
+ SWelsSliceBs* pSliceBs = &pCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx]->sSliceBs;
pSliceBs->pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
pSliceBs->uiBsPos = 0;
}
--- a/codec/encoder/core/src/svc_enc_slice_segment.cpp
+++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp
@@ -356,7 +356,6 @@
const int32_t kiMbWidth,
const int32_t kiMbHeight) {
SSliceCtx* pSliceSeg = &pCurDq->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
const int32_t kiCountMbNum = kiMbWidth * kiMbHeight;
SliceModeEnum uiSliceMode = SM_SINGLE_SLICE;
@@ -392,7 +391,6 @@
pSliceSeg->iMbWidth = kiMbWidth;
pSliceSeg->iMbHeight = kiMbHeight;
pSliceSeg->iMbNumInFrame = kiCountMbNum;
- pSliceInLayer[0].iCountMbNumInSlice = kiCountMbNum;
return AssignMbMapSingleSlice (pSliceSeg->pOverallMbMap, kiCountMbNum, sizeof (pSliceSeg->pOverallMbMap[0]));
} else { //if ( SM_MULTIPLE_SLICE == uiSliceMode )
@@ -494,6 +492,7 @@
return 0;
}
+
/*!
* \brief Uninitialize Wels SSlice context (Single/multiple slices and FMO)
*
@@ -528,16 +527,18 @@
/*!
* \brief Get first mb in slice/slice_group: uiSliceIdc (apply in Single/multiple slices and FMO)
*
- * \param pSliceInLayer slice list in current layer
+ * \param ppSliceInLayer slice list in current layer
* \param kuiSliceIdc slice idc
*
* \return iFirstMb - successful; -1 - failed;
*/
-int32_t WelsGetFirstMbOfSlice (SSlice* pSliceInLayer, const int32_t kuiSliceIdc) {
- if ( NULL == pSliceInLayer || NULL == &pSliceInLayer[kuiSliceIdc] )
+int32_t WelsGetFirstMbOfSlice (SSlice** ppSliceInLayer, const int32_t kuiSliceIdc) {
+ if ( NULL == ppSliceInLayer || NULL == ppSliceInLayer[kuiSliceIdc] ) {
return -1;
+ }
- return pSliceInLayer[kuiSliceIdc].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
+
+ return ppSliceInLayer[kuiSliceIdc]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
}
/*!
@@ -614,7 +615,7 @@
*/
int32_t WelsGetNumMbInSlice (SDqLayer* pCurDq, const int32_t kuiSliceIdc) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
- SSlice* pSlice = &pCurDq->sLayerInfo.pSliceInLayer[kuiSliceIdc];
+ SSlice* pSlice = pCurDq->ppSliceInLayer[kuiSliceIdc];
if (NULL == pSliceCtx || kuiSliceIdc < 0)
return -1;
@@ -639,7 +640,7 @@
int32_t DynamicAdjustSlicePEncCtxAll (SDqLayer* pCurDq,
int32_t* pRunLength) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
- SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
const int32_t iCountNumMbInFrame = pSliceCtx->iMbNumInFrame;
const int32_t iCountSliceNumInFrame = pSliceCtx->iSliceNumInFrame;
int32_t iSameRunLenFlag = 1;
@@ -649,7 +650,7 @@
assert (iCountSliceNumInFrame <= MAX_THREADS_NUM);
while (iSliceIdx < iCountSliceNumInFrame) {
- if (pRunLength[iSliceIdx] != pSliceInLayer[iSliceIdx].iCountMbNumInSlice) {
+ if (pRunLength[iSliceIdx] != ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice) {
iSameRunLenFlag = 0;
break;
}
@@ -662,9 +663,9 @@
iSliceIdx = 0;
do {
const int32_t kiSliceRun = pRunLength[iSliceIdx];
- SSliceHeaderExt* pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
+ SSliceHeaderExt* pSliceHeaderExt = &ppSliceInLayer[iSliceIdx]->sSliceHeaderExt;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
- pSliceInLayer[iSliceIdx].iCountMbNumInSlice = kiSliceRun;
+ ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice = kiSliceRun;
WelsSetMemMultiplebytes_c(pSliceCtx->pOverallMbMap + iFirstMbIdx, iSliceIdx,
kiSliceRun, sizeof(uint16_t));
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -94,7 +94,7 @@
pCurSliceExt->bStoreRefBasePicFlag = false;
- pCurSliceHeader->iFirstMbInSlice = WelsGetFirstMbOfSlice (pCurLayer->sLayerInfo.pSliceInLayer, pSlice->uiSliceIdx);
+ pCurSliceHeader->iFirstMbInSlice = WelsGetFirstMbOfSlice (pCurLayer->ppSliceInLayer, pSlice->uiSliceIdx);
pCurSliceHeader->iFrameNum = pParamInternal->iFrameNum;
pCurSliceHeader->uiIdrPicId = pParamInternal->uiIdrPicId;
@@ -818,8 +818,7 @@
int32_t InitSliceMBInfo (SSliceArgument* pSliceArgument,
SSlice* pSlice,
const int32_t kiMBWidth,
- const int32_t kiMBHeight,
- CMemoryAlign* pMa) {
+ const int32_t kiMBHeight) {
SSliceHeader* pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
const int32_t* kpSlicesAssignList = (int32_t*) & (pSliceArgument->uiSliceMbNum[0]);
const int32_t kiCountNumMbInFrame = kiMBWidth * kiMBHeight;
@@ -841,8 +840,9 @@
iMbIdx += kpSlicesAssignList[i];
}
- if (iMbIdx >= kiCountNumMbInFrame)
+ if (iMbIdx >= kiCountNumMbInFrame) {
return ENC_RETURN_UNEXPECTED;
+ }
iFirstMBInSlice = iMbIdx;
iMbNumInSlice = kpSlicesAssignList[kiSliceIdx];
@@ -912,15 +912,530 @@
}
}
+int32_t InitSliceList (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ SSlice*& pSliceList,
+ const int32_t kiMaxSliceNum,
+ const int32_t kiDlayerIndex,
+ CMemoryAlign* pMa) {
+ const int32_t kiMBWidth = pDqLayer->iMbWidth;
+ const int32_t kiMBHeight = pDqLayer->iMbHeight;
+ 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 || kiMBWidth <= 0 || kiMBHeight <= 0) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+
+ while (iSliceIdx < kiMaxSliceNum) {
+ SSlice* pSlice = pSliceList + iSliceIdx;
+ if (NULL == pSlice) {
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ pSlice->uiSliceIdx = iSliceIdx;
+
+ iRet = InitSliceBsBuffer (pSlice,
+ & pCtx->pOut->sBsWrite,
+ bIndependenceBsBuffer,
+ iMaxSliceBufferSize,
+ pMa);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ iRet = InitSliceMBInfo (pSliceArgument, pSlice,
+ kiMBWidth, kiMBHeight);
+
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+ iRet = AllocateSliceMBBuffer (pSlice, pMa);
+
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+ ++ iSliceIdx;
+ }
+ return ENC_RETURN_SUCCESS;
+}
+/*
+int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
+ SSlice*& pSlice,
+ const int32_t kiThreadIdx,
+ const int32_t kiDlayerIdx,
+ const int32_t kiSliceIdx) {
+ SDqLayer* pDqLayer = pCtx->pCurDqLayer;
+ SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
+ const int32_t kiMBWidth = pDqLayer->iMbWidth;
+ const int32_t kiMBHeight = pDqLayer->iMbHeight;
+ const int32_t kiCodedNumInThread = pDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[kiThreadIdx];
+ const int32_t kiMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIdx];
+ int32_t iRet = 0;
+
+ if (kiCodedNumInThread >= kiMaxSliceNumInThread) {
+ iRet = ReallocateSliceInThread(pCtx, pDqLayer, kiDlayerIdx, kiThreadIdx);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+ }
+
+ pSlice = pDqLayer->sSliceThreadInfo.pSliceInThread [kiThreadIdx] + kiCodedNumInThread;
+ // Initialize slice bs buffer info
+ pSlice->sSliceBs.uiBsPos = 0;
+ pSlice->sSliceBs.iNalIndex = 0;
+ pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
+
+ // init slice MB info
+ iRet = InitSliceMBInfo (pSliceArgument, pSlice, kiMBWidth, kiMBHeight);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+ return ENC_RETURN_SUCCESS;
+}
+*/
+
+int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ const int32_t kiDlayerIndex,
+ CMemoryAlign* pMa) {
+
+ SSliceThreadInfo* pSliceThreadInfo = &pDqLayer->sSliceThreadInfo;
+ int32_t iThreadNum = pCtx->pSvcParam->iMultipleThreadIdc;
+ int32_t iMaxSliceNumInThread = 0;
+ int32_t iIdx = 0;
+ int32_t iRet = 0;
+
+ assert (iThreadNum > 0);
+ iMaxSliceNumInThread = (pCtx->iMaxSliceCount / iThreadNum + 1) * 2;
+ iMaxSliceNumInThread = WELS_MIN (pCtx->iMaxSliceCount, (int) iMaxSliceNumInThread);
+
+ while (iIdx < iThreadNum) {
+ pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
+ pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
+ pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) *
+ iMaxSliceNumInThread, "pSliceInThread");
+ if (NULL == pSliceThreadInfo->pSliceInThread[iIdx]) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
+ "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceInThread[iIdx] is NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+ iRet = InitSliceList (pCtx,
+ pDqLayer,
+ pSliceThreadInfo->pSliceInThread[iIdx],
+ iMaxSliceNumInThread,
+ kiDlayerIndex,
+ pMa);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+ iIdx++;
+ }
+
+ for (; iIdx < MAX_THREADS_NUM; iIdx++) {
+ pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
+ pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
+ pSliceThreadInfo->pSliceInThread[iIdx] = NULL;
+ }
+ return ENC_RETURN_SUCCESS;
+}
+
+int32_t InitSliceInLayer (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ const int32_t kiDlayerIndex,
+ CMemoryAlign* pMa) {
+ int32_t iRet = 0;
+ int32_t iSliceIdx = 0;
+ int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum;
+
+ pDqLayer->ppSliceInLayer = (SSlice**)pMa->WelsMallocz (sizeof (SSlice*) * iMaxSliceNum, "ppSliceInLayer");
+ if (NULL == pDqLayer->ppSliceInLayer) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitSliceInLayer() pDqLayer->ppSliceInLayer is NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ InitSliceThreadInfo (pCtx,
+ pDqLayer,
+ kiDlayerIndex,
+ pMa);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
+ if (NULL == pDqLayer->sLayerInfo.pSliceInLayer) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
+ "CWelsH264SVCEncoder::InitSliceInLayer: pDqLayer->sLayerInfo.pSliceInLayeris NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ iRet = InitSliceList (pCtx,
+ pDqLayer,
+ pDqLayer->sLayerInfo.pSliceInLayer,
+ iMaxSliceNum,
+ kiDlayerIndex,
+ pMa);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ for (iSliceIdx = 0; iSliceIdx < iMaxSliceNum; iSliceIdx++) {
+ pDqLayer->ppSliceInLayer[iSliceIdx] = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
+ }
+
+ return ENC_RETURN_SUCCESS;
+}
+
+static inline int32_t InitSliceHeadWithBase (SSlice* pSlice, SSlice* pBaseSlice, const uint8_t kuiRefCount) {
+ SSliceHeaderExt* pBaseSHExt = &pBaseSlice->sSliceHeaderExt;
+ SSliceHeaderExt* pSHExt = &pSlice->sSliceHeaderExt;
+
+ if (NULL == pSlice || NULL == pBaseSlice)
+ return ENC_RETURN_INVALIDINPUT;
+
+ pSlice->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag;
+ pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId;
+ pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps;
+ pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId;
+ pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps;
+ pSHExt->sSliceHeader.uiRefCount = kuiRefCount;
+ memcpy (&pSHExt->sSliceHeader.sRefMarking, &pBaseSHExt->sSliceHeader.sRefMarking, sizeof (SRefPicMarking));
+ memcpy (&pSHExt->sSliceHeader.sRefReordering, &pBaseSHExt->sSliceHeader.sRefReordering,
+ sizeof (SRefPicListReorderSyntax));
+ return ENC_RETURN_SUCCESS;
+
+}
+static inline int32_t InitSliceRC (SSlice* pSlice, const int32_t kiGlobalQp, const int32_t kiBitsPerMb) {
+
+ if (NULL == pSlice || kiGlobalQp < 0 || kiBitsPerMb < 0)
+ return ENC_RETURN_INVALIDINPUT;
+
+ pSlice->sSlicingOverRc.iComplexityIndexSlice = 0;
+ pSlice->sSlicingOverRc.iCalculatedQpSlice = kiGlobalQp;
+ pSlice->sSlicingOverRc.iTotalQpSlice = 0;
+ pSlice->sSlicingOverRc.iTotalMbSlice = 0;
+ pSlice->sSlicingOverRc.iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb *
+ pSlice->iCountMbNumInSlice,
+ INT_MULTIPLY);
+ pSlice->sSlicingOverRc.iFrameBitsSlice = 0;
+ pSlice->sSlicingOverRc.iGomBitsSlice = 0;
+
+ return ENC_RETURN_SUCCESS;
+}
+
+int32_t ReallocateSliceList (sWelsEncCtx* pCtx,
+ SSliceArgument* pSliceArgument,
+ SSlice*& pSliceList,
+ const int32_t kiMaxSliceNumOld,
+ const int32_t kiMaxSliceNumNew) {
+ CMemoryAlign* pMA = pCtx->pMemAlign;
+ SDqLayer* pCurLayer = pCtx->pCurDqLayer;
+ SSlice* pBaseSlice = NULL;
+ SSlice* pNewSliceList = NULL;
+ SSlice* pSlice = NULL;
+ int32_t iSliceIdx = 0;
+ int32_t iRet = 0;
+ const int32_t kiCurDid = pCtx->uiDependencyId;
+ int32_t iMaxSliceBufferSize = (pCtx)->iSliceBufferSize[kiCurDid];
+ int32_t iBitsPerMb = WELS_DIV_ROUND (pCtx->pWelsSvcRc[kiCurDid].iTargetBits * INT_MULTIPLY,
+ pCtx->pWelsSvcRc[kiCurDid].iNumberMbFrame);
+ bool bIndependenceBsBuffer = (pCtx->pSvcParam->iMultipleThreadIdc > 1 &&
+ SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false;
+
+ if (NULL == pSliceList || NULL == pSliceArgument) {
+ return ENC_RETURN_INVALIDINPUT;
+ }
+
+ pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "Slice");
+ if (NULL == pNewSliceList) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocateSliceList: pNewSliceList is NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ memcpy (pNewSliceList, pSliceList, sizeof (SSlice) * kiMaxSliceNumOld);
+ iSliceIdx = kiMaxSliceNumOld;
+ pBaseSlice = &pSliceList[0];
+
+ for (; iSliceIdx < kiMaxSliceNumNew; iSliceIdx++) {
+ pSlice = pNewSliceList + iSliceIdx;
+ if (NULL == pSlice) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ pSlice->uiSliceIdx = iSliceIdx;
+
+ iRet = InitSliceBsBuffer (pSlice,
+ & pCtx->pOut->sBsWrite,
+ bIndependenceBsBuffer,
+ iMaxSliceBufferSize,
+ pMA);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return iRet;
+ }
+
+ iRet = AllocateSliceMBBuffer (pSlice, pMA);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return iRet;
+ }
+
+ iRet = InitSliceMBInfo (pSliceArgument,
+ pSlice,
+ pCurLayer->iMbWidth,
+ pCurLayer->iMbHeight);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return iRet;
+ }
+
+ iRet = InitSliceHeadWithBase (pSlice, pBaseSlice, pCtx->iNumRef0);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return iRet;
+ }
+
+ iRet = InitSliceRC (pSlice, pCtx->iGlobalQp, iBitsPerMb);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
+ return iRet;
+ }
+ }
+
+ pMA->WelsFree (pSliceList, "Slice");
+ pSliceList = pNewSliceList;
+
+ return ENC_RETURN_SUCCESS;
+
+}
+
+int32_t CalculateNewSliceNum (SDqLayer* pDqLayer,
+ SSlice* pLastCodedSlice,
+ const int32_t iMaxSliceNumOld,
+ int32_t& iMaxSliceNumNew) {
+ int32_t CodedMBNum = 0;
+
+ if (NULL == pLastCodedSlice)
+ return ENC_RETURN_INVALIDINPUT;
+
+ CodedMBNum = pLastCodedSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice +
+ pLastCodedSlice->iCountMbNumInSlice;
+ if (CodedMBNum <= 0) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+ //iMaxSliceNumNew = iMaxSliceNumOld * (pDqLayer->iMbWidth * pDqLayer->iMbHeight / CodedMBNum + 1);
+ //TO DO, will used above logic later, here keep origin logic in order to pass ut
+ iMaxSliceNumNew = iMaxSliceNumOld;
+ iMaxSliceNumNew *= SLICE_NUM_EXPAND_COEF;
+ return ENC_RETURN_SUCCESS;
+}
+
+/*
+int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
+ SDqLayer* pDqLayer,
+ const int32_t kiDlayerIdx,
+ const int32_t kiThreadIndex) {
+
+ int32_t iMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIndex];
+ int32_t iMaxSliceNumUpdate = 0;
+ int32_t iRet = 0;
+ SSlice* pLastCodedSlice = pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex] + (iMaxSliceNumInThread - 1);
+ SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
+
+ iRet = CalculateNewSliceNum (pDqLayer,
+ pLastCodedSlice,
+ iMaxSliceNumInThread,
+ iMaxSliceNumUpdate);
+
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ iRet = ReallocateSliceList (pCtx,
+ pSliceArgument,
+ pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex],
+ iMaxSliceNumInThread,
+ iMaxSliceNumUpdate);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ return ENC_RETURN_SUCCESS;
+}
+*/
+
+int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) {
+
+ CMemoryAlign* pMA = pCtx->pMemAlign;
+ SDqLayer* pCurLayer = pCtx->pCurDqLayer;
+ SSlice** ppSlice = NULL;
+ int32_t iMaxSliceNumOld = pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint;
+ int32_t iMaxSliceNumNew = 0;
+ int32_t iRet = 0;
+ int32_t iSliceIdx = 0;
+ const int32_t kiCurDid = pCtx->uiDependencyId;
+
+ SSlice* pLastCodedSlice = pCurLayer->sLayerInfo.pSliceInLayer + (iMaxSliceNumOld - 1);
+ SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument;
+ iRet = CalculateNewSliceNum (pCurLayer,
+ pLastCodedSlice,
+ iMaxSliceNumOld,
+ iMaxSliceNumNew);
+
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ iRet = ReallocateSliceList (pCtx,
+ pSliceArgument,
+ pCurLayer->sLayerInfo.pSliceInLayer,
+ iMaxSliceNumOld,
+ iMaxSliceNumNew);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ return iRet;
+ }
+
+ // update for ppsliceInlayer
+ ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iMaxSliceNumNew, "ppSlice");
+ if (NULL == ppSlice) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocSliceBuffer: ppSlice is NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+ pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");
+ pCurLayer->ppSliceInLayer = ppSlice;
+
+ for (iSliceIdx = 0; iSliceIdx < iMaxSliceNumNew; iSliceIdx++) {
+ pCurLayer->ppSliceInLayer[iSliceIdx] = &pCurLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
+ }
+
+ if (pCtx->iMaxSliceCount < iMaxSliceNumNew) {
+ pCtx->iMaxSliceCount = iMaxSliceNumNew;
+ }
+
+ pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNumNew;
+ pCurLayer->iMaxSliceNum = iMaxSliceNumNew;
+ return ENC_RETURN_SUCCESS;
+}
+
+/*
+int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,
+ const int32_t kiThreadNum,
+ const int32_t kiPartitionNum) {
+ SSlice* pSliceInThread = NULL;
+ int32_t iThreadIdx = 0;
+ int32_t iPartitionIdx = 0;
+ int32_t iPartitionID = 0;
+ int32_t iSliceIdx = 0;
+ int32_t iSliceNumInThread = 0;
+ int32_t iPartitionOffset = 0;
+ int32_t iActualSliceIdx = 0;
+ int32_t aiPartitionOffset[MAX_THREADS_NUM] = {0};
+
+ //for non-dynamic slice mode, kiPartitionNum = 1, iPartitionOffset = 0
+ for(iPartitionIdx = 0; iPartitionIdx < kiPartitionNum; iPartitionIdx++) {
+ aiPartitionOffset[iPartitionIdx] = iPartitionOffset;
+ iPartitionOffset += pCurLayer->pNumSliceCodedOfPartition[iPartitionIdx];
+ }
+
+ for (iThreadIdx = 0; iThreadIdx < kiThreadNum; iThreadIdx++) {
+ iSliceNumInThread = pCurLayer->sSliceThreadInfo.iEncodedSliceNumInThread[iThreadIdx];
+
+ for(iSliceIdx =0; iSliceIdx < iSliceNumInThread; iSliceIdx++) {
+ pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[iThreadIdx] + iSliceIdx;
+ if (NULL == pSliceInThread) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+
+ iPartitionID = pSliceInThread->uiSliceIdx % kiPartitionNum;
+ iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->uiSliceIdx / kiPartitionNum;
+ pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;
+ }
+ }
+
+ return ENC_RETURN_SUCCESS;
+}
+
+static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiCodedSliceNum) {
+ int32_t iSliceIdx = 0;
+ for(; iSliceIdx <kiCodedSliceNum ; iSliceIdx ++ ) {
+ if ( NULL == pCurLayer->ppSliceInLayer[iSliceIdx]) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+
+ if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->uiSliceIdx) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+ }
+
+ return ENC_RETURN_SUCCESS;
+}
+
+int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) {
+
+ CMemoryAlign* pMA = pCtx->pMemAlign;
+ SDqLayer* pCurLayer = pCtx->pCurDqLayer;
+ SSlice** ppSlice = NULL;
+ int32_t iCodedSliceNum = 0;
+ int32_t iThreadIdx = 0;
+ int32_t iRet = 0;
+ SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
+ int32_t iPartitionNum = (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? pCtx->iActiveThreadsNum : 1;
+
+ for ( ; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) {
+ iCodedSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
+ }
+
+ if (iCodedSliceNum <= 0) {
+ return ENC_RETURN_UNEXPECTED;
+ }
+
+ //reallocate ppSliceInLayer if total encoded slice num exceed max slice num
+ if (iCodedSliceNum > pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint) {
+ ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iCodedSliceNum, "ppSlice");
+ if (NULL == ppSlice) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ppSlice is NULL");
+ return ENC_RETURN_MEMALLOCERR;
+ }
+
+ pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");
+ pCurLayer->ppSliceInLayer = ppSlice;
+ pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iCodedSliceNum;
+ }
+
+ //update ppSliceInLayer based on pSliceInThread, reordering based on slice index
+ iRet = ReOrderSliceInLayer (pCurLayer, pCtx->iActiveThreadsNum, iPartitionNum);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
+ "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed");
+ return iRet;
+ }
+
+ iRet = CheckAllSliceBuffer(pCurLayer, pCtx->iActiveThreadsNum);
+ if (ENC_RETURN_SUCCESS != iRet) {
+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
+ "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayerDynamic failed");
+ return iRet;
+ }
+
+ return ENC_RETURN_SUCCESS;
+}
+*/
+
int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int32_t kiNalType) {
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
SNalUnitHeaderExt* pNalHeadExt = &pCurLayer->sLayerInfo.sNalHeaderExt;
- SSlice* pCurSlice = &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];
+ SSlice* pCurSlice = pCurLayer->ppSliceInLayer[kiSliceIdx];
SBitStringAux* pBs = pCurSlice->pSliceBsa;
- const int32_t kiDynamicSliceFlag =
- (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode
- ==
- SM_SIZELIMITED_SLICE);
+ const int32_t kiDynamicSliceFlag = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode
+ == SM_SIZELIMITED_SLICE);
assert (kiSliceIdx == (int) pCurSlice->uiSliceIdx);
@@ -974,7 +1489,7 @@
void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
- SSlice* pSliceInLayer = pCurLayer->sLayerInfo.pSliceInLayer;
+ SSlice** ppSliceInLayer = pCurLayer->ppSliceInLayer;
int32_t iCurMbIdx = pCurMb->iMbXY;
uint16_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ];
const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum;
@@ -987,7 +1502,7 @@
pCurSlice->sSliceHeaderExt.uiNumMbsInSlice = 1 + iCurMbIdx - pCurSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
//pNextSlice pointer/initialization
- pNextSlice = & (pCurLayer->sLayerInfo.pSliceInLayer[ iNextSliceIdc ]);
+ pNextSlice = pCurLayer->ppSliceInLayer[ iNextSliceIdc ];
#if _DEBUG
assert (NULL != pNextSlice);
@@ -999,7 +1514,7 @@
(NAL_UNIT_CODED_SLICE_EXT == pCurLayer->sLayerInfo.sNalHeaderExt.sNalUnitHeader.eNalUnitType);
memcpy (&pNextSlice->sSliceHeaderExt, &pCurSlice->sSliceHeaderExt,
sizeof (SSliceHeaderExt)); // confirmed_safe_unsafe_usage
- pSliceInLayer[iNextSliceIdc].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxOfNextSlice;
+ ppSliceInLayer[iNextSliceIdc]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxOfNextSlice;
WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdxOfNextSlice, iNextSliceIdc,
(kiLastMbIdxInPartition - iFirstMbIdxOfNextSlice + 1), sizeof (uint16_t));
--- a/codec/encoder/core/src/svc_motion_estimate.cpp
+++ b/codec/encoder/core/src/svc_motion_estimate.cpp
@@ -1019,10 +1019,10 @@
const int32_t kiSliceCount = GetCurrentSliceNum (pCurLayer);
if (kiSliceCount >= 1) {
int32_t iSliceIndex = 0;
- SSlice* pSlice = &pCurLayer->sLayerInfo.pSliceInLayer[iSliceIndex];
+ SSlice* pSlice = pCurLayer->ppSliceInLayer[iSliceIndex];
while (iSliceIndex < kiSliceCount) {
+ pSlice = pCurLayer->ppSliceInLayer[iSliceIndex];
uiCostDownSum += pSlice->uiSliceFMECostDown;
- ++ pSlice;
++ iSliceIndex;
}
}
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -56,7 +56,7 @@
namespace WelsEnc {
CWelsSliceEncodingTask::CWelsSliceEncodingTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx,
- const int32_t iSliceIdx) : CWelsBaseTask(pSink), m_eTaskResult (ENC_RETURN_SUCCESS) {
+ const int32_t iSliceIdx) : CWelsBaseTask (pSink), m_eTaskResult (ENC_RETURN_SUCCESS) {
m_pCtx = pCtx;
m_iSliceIdx = iSliceIdx;
}
@@ -111,9 +111,11 @@
"[MT] CWelsSliceEncodingTask InitTask(), Cannot find available thread for m_iSliceIdx = %d", m_iSliceIdx);
return ENC_RETURN_UNEXPECTED;
}
+
+ // InitOneSliceInThread();
SetOneSliceBsBufferUnderMultithread (m_pCtx, m_iThreadIdx, m_iSliceIdx);
- m_pSlice = &m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx];
+ m_pSlice = m_pCtx->pCurDqLayer->ppSliceInLayer[m_iSliceIdx];
m_pSliceBs = &m_pSlice->sSliceBs;
m_pSliceBs->uiBsPos = 0;
@@ -147,7 +149,7 @@
#if MT_DEBUG_BS_WR
m_pSliceBs->bSliceCodedFlag = false;
#endif//MT_DEBUG_BS_WR
- SSpatialLayerInternal *pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
+ SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
if (m_bNeedPrefix) {
if (m_eNalRefIdc != NRI_PRI_LOWEST) {
WelsLoadNalForSlice (m_pSliceBs, NAL_UNIT_PREFIX, m_eNalRefIdc);
@@ -211,15 +213,16 @@
void CWelsLoadBalancingSlicingEncodingTask::FinishTask() {
CWelsSliceEncodingTask::FinishTask();
- SSpatialLayerInternal *pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
+ SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
m_pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - m_iSliceStart);
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
- "[MT] CWelsLoadBalancingSlicingEncodingTask()FinishTask, coding_idx %d, um_iSliceIdx %d, uiSliceConsumeTime %d, m_iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d at time=%" PRId64,
+ "[MT] CWelsLoadBalancingSlicingEncodingTask()FinishTask, coding_idx %d, um_iSliceIdx %d, uiSliceConsumeTime %d, m_iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d at time=%"
+ PRId64,
pParamInternal->iCodingIndex,
m_iSliceIdx,
m_pSlice->uiSliceConsumeTime,
m_iSliceSize,
- m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
+ m_pCtx->pCurDqLayer->ppSliceInLayer[m_iSliceIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
m_pSlice->iCountMbNumInSlice,
(m_pSlice->uiSliceConsumeTime + m_iSliceStart));
}
@@ -232,11 +235,11 @@
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
const int32_t kiSliceIdxStep = m_pCtx->iActiveThreadsNum;
- SSpatialLayerInternal *pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
- SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt;
+ SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
+ SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->ppSliceInLayer[m_iSliceIdx]->sSliceHeaderExt;
//deal with partition: TODO: here SSliceThreadPrivateData is just for parition info and actually has little relationship with threadbuffer, and iThreadIndex is not used in threadpool model, need renaming after removing old logic to avoid confusion
- const int32_t kiPartitionId = m_iSliceIdx%kiSliceIdxStep;
+ const int32_t kiPartitionId = m_iSliceIdx % kiSliceIdxStep;
SSliceThreadPrivateData* pPrivateData = & (m_pCtx->pSliceThreading->pThreadPEncCtx[kiPartitionId]);
const int32_t kiFirstMbInPartition = pPrivateData->iStartMbIndex; // inclusive
const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive
@@ -260,7 +263,7 @@
}
SetOneSliceBsBufferUnderMultithread (m_pCtx, m_iThreadIdx, iLocalSliceIdx);
- m_pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iLocalSliceIdx];
+ m_pSlice = pCurDq->ppSliceInLayer[iLocalSliceIdx];
m_pSliceBs = &m_pSlice->sSliceBs;
m_pSliceBs->uiBsPos = 0;
@@ -285,7 +288,7 @@
return iReturn;
}
WelsUnloadNalForSlice (m_pSliceBs);
-
+
iReturn = WriteSliceBs (m_pCtx, m_pSliceBs, iLocalSliceIdx, m_iSliceSize);
if (ENC_RETURN_SUCCESS != iReturn) {
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING,
@@ -318,7 +321,8 @@
}
-CWelsUpdateMbMapTask::CWelsUpdateMbMapTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx, const int32_t iSliceIdx): CWelsBaseTask(pSink) {
+CWelsUpdateMbMapTask::CWelsUpdateMbMapTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx,
+ const int32_t iSliceIdx): CWelsBaseTask (pSink) {
m_pCtx = pCtx;
m_iSliceIdx = iSliceIdx;
}