ref: 14725d43561724d2cc4bae1e85f7206aa7d8a527
parent: 08f19b612688777b60ab537fa0f539f27278fded
parent: 3fc24c3036ea58275d9674d2b82af9694c6b2d63
author: sijchen <sijchen@cisco.com>
date: Thu Apr 20 05:43:54 EDT 2017
Merge pull request #2716 from shihuade/MultiThread_V11.0_Rename rename variables, change thread idx to bufferIdx,which lead to misunderstanding
--- a/codec/encoder/core/inc/slice.h
+++ b/codec/encoder/core/inc/slice.h
@@ -185,7 +185,7 @@
uint8_t sScaleShift;
int32_t iSliceIdx;
-uint32_t uiThreadIdx;
+uint32_t uiBufferIdx;
bool bSliceHeaderExtFlag; // Indicate which slice header is used, avc or ext?
uint8_t uiLastMbQp; // stored qp for last mb coded, maybe more efficient for mb skip detection etc.
--- a/codec/encoder/core/inc/svc_enc_frame.h
+++ b/codec/encoder/core/inc/svc_enc_frame.h
@@ -68,12 +68,11 @@
int32_t iHighFreMbCount;
} SFeatureSearchPreparation; //maintain only one
-typedef struct TagSliceThreadInfo {
-SSlice* pSliceInThread;// slice buffer for multi thread,
- // pSliceInThread[0] for single thread
+typedef struct TagSliceBufferInfo {
+SSlice* pSliceBuffer; // slice buffer for multi thread,
int32_t iMaxSliceNum;
int32_t iCodedSliceNum;
-}SSliceThreadInfo;
+}SSliceBufferInfo;
typedef struct TagLayerInfo {
SNalUnitHeaderExt sNalHeaderExt;
@@ -84,7 +83,7 @@
/* Layer Representation */
struct TagDqLayer {
SLayerInfo sLayerInfo;
-SSliceThreadInfo sSliceThreadInfo[MAX_THREADS_NUM];
+SSliceBufferInfo sSliceBufferInfo[MAX_THREADS_NUM];
SSlice** ppSliceInLayer;
SSliceCtx sSliceEncCtx; // current slice context
uint8_t* pCsData[3]; // pointer to reconstructed picture pData
--- a/codec/encoder/core/inc/svc_encode_slice.h
+++ b/codec/encoder/core/inc/svc_encode_slice.h
@@ -118,7 +118,7 @@
int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
SSlice*& pSlice,
- const int32_t kiThreadIdx,
+ const int32_t kiSlcBuffIdx,
const int32_t kiDlayerIdx,
const int32_t kiSliceIdx);
@@ -136,7 +136,7 @@
int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
SDqLayer* pDqLayer,
const int32_t kiDlayerIdx,
- const int32_t kiThreadIndex);
+ const int32_t KiSlcBuffIdx);
int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -923,9 +923,9 @@
void FreeSliceInLayer (SDqLayer* pDq, CMemoryAlign* pMa) {
int32_t iIdx = 0;
for (; iIdx < MAX_THREADS_NUM; iIdx ++) {
- FreeSliceBuffer (pDq->sSliceThreadInfo[iIdx].pSliceInThread,
- pDq->sSliceThreadInfo[iIdx].iMaxSliceNum,
- pMa, "pSliceInThread");
+ FreeSliceBuffer (pDq->sSliceBufferInfo[iIdx].pSliceBuffer,
+ pDq->sSliceBufferInfo[iIdx].iMaxSliceNum,
+ pMa, "pSliceBuffer");
}
}
@@ -3643,7 +3643,7 @@
if (SM_SINGLE_SLICE == pParam->sSliceArgument.uiSliceMode) { // only one slice within a sQualityStat layer
int32_t iSliceSize = 0;
int32_t iPayloadSize = 0;
- SSlice* pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo[0].pSliceInThread[0];
+ SSlice* pCurSlice = &pCtx->pCurDqLayer->sSliceBufferInfo[0].pSliceBuffer[0];
if (pCtx->bNeedPrefixNalFlag) {
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType,
@@ -3777,7 +3777,6 @@
} else { // for non-dynamic-slicing mode single threading branch..
const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
int32_t iSliceIdx = 0;
- uint32_t uiTheadIdx = 0;
SSlice* pCurSlice = NULL;
iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer);
@@ -3795,7 +3794,7 @@
WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);
- pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo[uiTheadIdx].pSliceInThread[iSliceIdx];
+ pCurSlice = &pCtx->pCurDqLayer->sSliceBufferInfo[0].pSliceBuffer[iSliceIdx];
assert (iSliceIdx == pCurSlice->iSliceIdx);
pCtx->iEncoderError = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, iSliceIdx);
@@ -4450,8 +4449,8 @@
) {
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
- uint32_t uiTheadIdx = 0;
- SSlice* pStartSlice = &pCurLayer->sSliceThreadInfo[uiTheadIdx].pSliceInThread[iStartSliceIdx];
+ uint32_t uSlcBuffIdx = 0;
+ SSlice* pStartSlice = &pCurLayer->sSliceBufferInfo[uSlcBuffIdx].pSliceBuffer[iStartSliceIdx];
int32_t iNalIdxInLayer = *pNalIdxInLayer;
int32_t iSliceIdx = iStartSliceIdx;
const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
@@ -4471,7 +4470,7 @@
int32_t iPayloadSize = 0;
SSlice* pCurSlice = NULL;
- if (iSliceIdx >= (pCurLayer->sSliceThreadInfo[uiTheadIdx].iMaxSliceNum - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[]
+ if (iSliceIdx >= (pCurLayer->sSliceBufferInfo[uSlcBuffIdx].iMaxSliceNum - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[]
if (pCtx->iActiveThreadsNum == 1) {
//only single thread support re-alloc now
if (DynSliceRealloc (pCtx, pFrameBSInfo, pLayerBsInfo)) {
@@ -4495,7 +4494,7 @@
}
WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc);
- pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo[uiTheadIdx].pSliceInThread[iSliceIdx];
+ pCurSlice = &pCtx->pCurDqLayer->sSliceBufferInfo[uSlcBuffIdx].pSliceBuffer[iSliceIdx];
pCurSlice->iSliceIdx = iSliceIdx;
iReturn = WelsCodeOneSlice (pCtx, pCurSlice, keNalType);
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -948,7 +948,7 @@
}
pSlice->iSliceIdx = iSliceIdx;
- pSlice->uiThreadIdx = 0;
+ pSlice->uiBufferIdx = 0;
pSlice->iCountMbNumInSlice = 0;
pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -974,7 +974,7 @@
int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx) {
SDqLayer* pCurDqLayer = pCtx->pCurDqLayer;
int32_t iSliceIdx = 0;
- int32_t iTheadIdx = 0;
+ int32_t iSlcBuffIdx = 0;
for( ; iSliceIdx < pCurDqLayer->iMaxSliceNum; iSliceIdx++) {
if(NULL == pCurDqLayer->ppSliceInLayer[iSliceIdx]) {
@@ -984,8 +984,8 @@
pCurDqLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx = -1;
}
- for( ; iTheadIdx < pCtx->iActiveThreadsNum; iTheadIdx++ ) {
- pCurDqLayer->sSliceThreadInfo[iTheadIdx].iCodedSliceNum = 0;
+ for( ; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) {
+ pCurDqLayer->sSliceBufferInfo[iSlcBuffIdx].iCodedSliceNum = 0;
}
return ENC_RETURN_SUCCESS;
@@ -993,24 +993,24 @@
int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
SSlice*& pSlice,
- const int32_t kiThreadIdx,
+ const int32_t kiSlcBuffIdx,
const int32_t kiDlayerIdx,
const int32_t kiSliceIdx) {
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];
+ const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iCodedSliceNum;
+ assert(kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iMaxSliceNum -1 );
+ pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [kiSlcBuffIdx].pSliceBuffer[kiCodedNumInThread];
} else {
- pSlice = &pCtx->pCurDqLayer->sSliceThreadInfo [0].pSliceInThread[kiSliceIdx];
+ pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [0].pSliceBuffer[kiSliceIdx];
}
pSlice->iSliceIdx = kiSliceIdx;
- pSlice->uiThreadIdx = kiThreadIdx;
+ pSlice->uiBufferIdx = kiSlcBuffIdx;
// Initialize slice bs buffer info
pSlice->sSliceBs.uiBsPos = 0;
pSlice->sSliceBs.iNalIndex = 0;
- pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
+ pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiSlcBuffIdx];
return ENC_RETURN_SUCCESS;
}
@@ -1037,15 +1037,15 @@
}
while (iIdx < iSlcBufferNum) {
- pDqLayer->sSliceThreadInfo[iIdx].iMaxSliceNum = iMaxSliceNum;
- pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0;
- pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInThread");
- if (NULL == pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread) {
+ pDqLayer->sSliceBufferInfo[iIdx].iMaxSliceNum = iMaxSliceNum;
+ pDqLayer->sSliceBufferInfo[iIdx].iCodedSliceNum = 0;
+ pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceBuffer");
+ if (NULL == pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
- "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceInThread[iIdx] is NULL");
+ "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceBuffer[iIdx] is NULL");
return ENC_RETURN_MEMALLOCERR;
}
- iRet = InitSliceList (pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread,
+ iRet = InitSliceList (pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer,
&pCtx->pOut->sBsWrite,
iMaxSliceNum,
pCtx->iSliceBufferSize[kiDlayerIndex],
@@ -1058,9 +1058,9 @@
}
for (; iIdx < MAX_THREADS_NUM; iIdx++) {
- pDqLayer->sSliceThreadInfo[iIdx].iMaxSliceNum = 0;
- pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0;
- pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = NULL;
+ pDqLayer->sSliceBufferInfo[iIdx].iMaxSliceNum = 0;
+ pDqLayer->sSliceBufferInfo[iIdx].iCodedSliceNum = 0;
+ pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer = NULL;
}
return ENC_RETURN_SUCCESS;
@@ -1072,7 +1072,7 @@
CMemoryAlign* pMa) {
int32_t iRet = 0;
int32_t iSliceIdx = 0;
- int32_t iThreadIdx = 0;
+ int32_t iSlcBuffIdx = 0;
int32_t iStartIdx = 0;
int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum;
SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
@@ -1094,8 +1094,8 @@
}
pDqLayer->iMaxSliceNum = 0;
- for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) {
- pDqLayer->iMaxSliceNum += pDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) {
+ pDqLayer->iMaxSliceNum += pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
}
pDqLayer->ppSliceInLayer = (SSlice**)pMa->WelsMallocz (sizeof (SSlice*) * pDqLayer->iMaxSliceNum, "ppSliceInLayer");
@@ -1122,12 +1122,12 @@
}
iStartIdx = 0;
- for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) {
- for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum; iSliceIdx++ ) {
- pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceThreadInfo[iThreadIdx].pSliceInThread+ iSliceIdx;
+ for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) {
+ for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; iSliceIdx++ ) {
+ pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer+ iSliceIdx;
}
- iStartIdx += pDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ iStartIdx += pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
}
return ENC_RETURN_SUCCESS;
@@ -1200,7 +1200,7 @@
bool bIndependenceBsBuffer = (pCtx->pSvcParam->iMultipleThreadIdc > 1 &&
SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false;
- pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "pSliceInThread");
+ pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "pSliceBuffer");
if (NULL == pNewSliceList) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocateSliceList: pNewSliceList is NULL");
return ENC_RETURN_MEMALLOCERR;
@@ -1212,7 +1212,7 @@
for (iSliceIdx = 0; iSliceIdx < kiMaxSliceNumOld; iSliceIdx++) {
pSlice = pNewSliceList + iSliceIdx;
if (NULL == pSlice) {
- FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer");
return ENC_RETURN_MEMALLOCERR;
}
@@ -1230,12 +1230,12 @@
for (iSliceIdx = kiMaxSliceNumOld; iSliceIdx < kiMaxSliceNumNew; iSliceIdx++) {
pSlice = pNewSliceList + iSliceIdx;
if (NULL == pSlice) {
- FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer");
return ENC_RETURN_MEMALLOCERR;
}
pSlice->iSliceIdx = -1;
- pSlice->uiThreadIdx = 0;
+ pSlice->uiBufferIdx = 0;
pSlice->iCountMbNumInSlice = 0;
pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -1245,13 +1245,13 @@
iMaxSliceBufferSize,
pMA);
if (ENC_RETURN_SUCCESS != iRet) {
- FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer");
return iRet;
}
iRet = AllocateSliceMBBuffer (pSlice, pMA);
if (ENC_RETURN_SUCCESS != iRet) {
- FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer");
return iRet;
}
@@ -1260,12 +1260,12 @@
iRet = InitSliceRC (pSlice, pCtx->iGlobalQp);
if (ENC_RETURN_SUCCESS != iRet) {
- FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer");
return iRet;
}
}
- pMA->WelsFree (pSliceList, "pSliceInThread");
+ pMA->WelsFree (pSliceList, "pSliceBuffer");
pSliceList = pNewSliceList;
return ENC_RETURN_SUCCESS;
@@ -1300,11 +1300,11 @@
int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
SDqLayer* pDqLayer,
const int32_t kiDlayerIdx,
- const int32_t kiThreadIndex) {
- int32_t iMaxSliceNum = pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum;
+ const int32_t KiSlcBuffIdx) {
+ int32_t iMaxSliceNum = pDqLayer->sSliceBufferInfo[KiSlcBuffIdx].iMaxSliceNum;
int32_t iMaxSliceNumNew = 0;
int32_t iRet = 0;
- SSlice* pLastCodedSlice = &pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread [iMaxSliceNum - 1];
+ SSlice* pLastCodedSlice = &pDqLayer->sSliceBufferInfo[KiSlcBuffIdx].pSliceBuffer [iMaxSliceNum - 1];
SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
iRet = CalculateNewSliceNum (pCtx,
@@ -1317,7 +1317,7 @@
iRet = ReallocateSliceList (pCtx,
pSliceArgument,
- pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread,
+ pDqLayer->sSliceBufferInfo[KiSlcBuffIdx].pSliceBuffer,
iMaxSliceNum,
iMaxSliceNumNew);
if (ENC_RETURN_SUCCESS != iRet) {
@@ -1324,7 +1324,7 @@
return iRet;
}
- pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum = iMaxSliceNumNew;
+ pDqLayer->sSliceBufferInfo[KiSlcBuffIdx].iMaxSliceNum = iMaxSliceNumNew;
return ENC_RETURN_SUCCESS;
}
@@ -1375,14 +1375,14 @@
int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) {
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
- int32_t iMaxSliceNumOld = pCurLayer->sSliceThreadInfo[0].iMaxSliceNum;
+ int32_t iMaxSliceNumOld = pCurLayer->sSliceBufferInfo[0].iMaxSliceNum;
int32_t iMaxSliceNumNew = 0;
int32_t iRet = 0;
int32_t iSliceIdx = 0;
- int32_t iThreadIdx = 0;
+ int32_t iSlcBuffIdx = 0;
int32_t iStartIdx = 0;
const int32_t kiCurDid = pCtx->uiDependencyId;
- SSlice* pLastCodedSlice = pCurLayer->sSliceThreadInfo[0].pSliceInThread + (iMaxSliceNumOld - 1);
+ SSlice* pLastCodedSlice = pCurLayer->sSliceBufferInfo[0].pSliceBuffer + (iMaxSliceNumOld - 1);
SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument;
iRet = CalculateNewSliceNum (pCtx,
pLastCodedSlice,
@@ -1395,7 +1395,7 @@
iRet = ReallocateSliceList (pCtx,
pSliceArgument,
- pCurLayer->sSliceThreadInfo[0].pSliceInThread,
+ pCurLayer->sSliceBufferInfo[0].pSliceBuffer,
iMaxSliceNumOld,
iMaxSliceNumNew);
if (ENC_RETURN_SUCCESS != iRet) {
@@ -1402,11 +1402,11 @@
return iRet;
}
- pCurLayer->sSliceThreadInfo[0].iMaxSliceNum = iMaxSliceNumNew;
+ pCurLayer->sSliceBufferInfo[0].iMaxSliceNum = iMaxSliceNumNew;
iMaxSliceNumNew = 0;
- for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) {
- iMaxSliceNumNew += pCurLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) {
+ iMaxSliceNumNew += pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
}
iRet = ExtendLayerBuffer(pCtx, pCurLayer->iMaxSliceNum, iMaxSliceNumNew);
@@ -1414,11 +1414,11 @@
return iRet;
}
- for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) {
- for (iSliceIdx = 0; iSliceIdx < pCurLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum; iSliceIdx++) {
- pCurLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pCurLayer->sSliceThreadInfo[iThreadIdx].pSliceInThread + iSliceIdx;
+ for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) {
+ for (iSliceIdx = 0; iSliceIdx < pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; iSliceIdx++) {
+ pCurLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx;
}
- iStartIdx += pCurLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ iStartIdx += pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
}
pCurLayer->iMaxSliceNum = iMaxSliceNumNew;
@@ -1445,8 +1445,8 @@
const SliceModeEnum kuiSliceMode,
const int32_t kiThreadNum) {
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
- SSlice* pSliceInThread = NULL;
- int32_t iThreadIdx = 0;
+ SSlice* pSliceBuffer = NULL;
+ int32_t iSlcBuffIdx = 0;
int32_t iPartitionIdx = 0;
int32_t iPartitionID = 0;
int32_t iSliceIdx = 0;
@@ -1475,24 +1475,24 @@
}
//before encode all slices in layer, slices' index are init with -1
- //pSliceInThread->iSliceIdx will be set to actual slice index when encode one slice
- for (iThreadIdx = 0; iThreadIdx < kiThreadNum; iThreadIdx++) {
- iSliceNumInThread = pCurLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ //pSliceBuffer->iSliceIdx will be set to actual slice index when encode one slice
+ for (iSlcBuffIdx = 0; iSlcBuffIdx < kiThreadNum; iSlcBuffIdx++) {
+ iSliceNumInThread = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
for(iSliceIdx =0; iSliceIdx < iSliceNumInThread; iSliceIdx++) {
- pSliceInThread = pCurLayer->sSliceThreadInfo[iThreadIdx].pSliceInThread + iSliceIdx;
- if (NULL == pSliceInThread) {
+ pSliceBuffer = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx;
+ if (NULL == pSliceBuffer) {
return ENC_RETURN_UNEXPECTED;
}
- if( -1 != pSliceInThread->iSliceIdx) {
- iPartitionID = pSliceInThread->iSliceIdx % iPartitionNum;
- iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / iPartitionNum;
- pSliceInThread->iSliceIdx = iActualSliceIdx;
- pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;
+ if( -1 != pSliceBuffer->iSliceIdx) {
+ iPartitionID = pSliceBuffer->iSliceIdx % iPartitionNum;
+ iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceBuffer->iSliceIdx / iPartitionNum;
+ pSliceBuffer->iSliceIdx = iActualSliceIdx;
+ pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceBuffer;
iUsedSliceNum ++;
} else {
- pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceInThread;
+ pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceBuffer;
iNonUsedBufferNum ++;
}
}
@@ -1581,8 +1581,8 @@
int32_t iCodedNalCount = 0;
int32_t iRet = 0;
- for ( int32_t iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) {
- iMaxSliceNum += pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ for ( int32_t iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) {
+ iMaxSliceNum += pCtx->pCurDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum;
}
//reallocate ppSliceInLayer if total encoded slice num exceed max slice num
@@ -1594,7 +1594,7 @@
pCtx->pCurDqLayer->iMaxSliceNum = iMaxSliceNum;
}
- //update ppSliceInLayer based on pSliceInThread, reordering based on slice index
+ //update ppSliceInLayer based on pSliceBuffer, reordering based on slice index
iRet = ReOrderSliceInLayer (pCtx, kuiSliceMode, pCtx->iActiveThreadsNum);
if (ENC_RETURN_SUCCESS != iRet) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
@@ -1678,8 +1678,8 @@
void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
- SSlice* pSliceInThread = pCurLayer->sSliceThreadInfo[pCurSlice->uiThreadIdx].pSliceInThread;
- int32_t iCodedSliceNum = pCurLayer->sSliceThreadInfo[pCurSlice->uiThreadIdx].iCodedSliceNum;
+ SSlice* pSliceBuffer = pCurLayer->sSliceBufferInfo[pCurSlice->uiBufferIdx].pSliceBuffer;
+ int32_t iCodedSliceNum = pCurLayer->sSliceBufferInfo[pCurSlice->uiBufferIdx].iCodedSliceNum;
int32_t iCurMbIdx = pCurMb->iMbXY;
uint16_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ];
const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum;
@@ -1693,9 +1693,9 @@
//pNextSlice pointer/initialization
if(pEncCtx->iActiveThreadsNum > 1) {
- pNextSlice = &pSliceInThread[ iCodedSliceNum + 1 ];
+ pNextSlice = &pSliceBuffer[ iCodedSliceNum + 1 ];
} else {
- pNextSlice = &pSliceInThread[ iNextSliceIdc ];
+ pNextSlice = &pSliceBuffer[ iNextSliceIdc ];
}
#if _DEBUG
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -237,13 +237,12 @@
const int32_t kiPartitionId = m_iSliceIdx % kiSliceIdxStep;
const int32_t kiFirstMbInPartition = pCurDq->FirstMbIdxOfPartition[kiPartitionId];
const int32_t kiEndMbIdxInPartition = pCurDq->EndMbIdxOfPartition[kiPartitionId];
- const int32_t kiCodedSliceNumByThread = pCurDq->sSliceThreadInfo[m_iThreadIdx].iCodedSliceNum;
- m_pSlice = &pCurDq->sSliceThreadInfo[m_iThreadIdx].pSliceInThread[kiCodedSliceNumByThread];
+ const int32_t kiCodedSliceNumByThread = pCurDq->sSliceBufferInfo[m_iThreadIdx].iCodedSliceNum;
+ m_pSlice = &pCurDq->sSliceBufferInfo[m_iThreadIdx].pSliceBuffer[kiCodedSliceNumByThread];
m_pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
int32_t iReturn = 0;
bool bNeedReallocate = false;
- //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
int32_t iDiffMbIdx = kiEndMbIdxInPartition - kiFirstMbInPartition;
if( 0 == iDiffMbIdx) {
m_pSlice->iSliceIdx = -1;
@@ -253,8 +252,8 @@
int32_t iAnyMbLeftInPartition = iDiffMbIdx + 1;
int32_t iLocalSliceIdx = m_iSliceIdx;
while (iAnyMbLeftInPartition > 0) {
- bNeedReallocate = (pCurDq->sSliceThreadInfo[m_iThreadIdx].iCodedSliceNum
- >= pCurDq->sSliceThreadInfo[m_iThreadIdx].iMaxSliceNum -1) ? true : false;
+ bNeedReallocate = (pCurDq->sSliceBufferInfo[m_iThreadIdx].iCodedSliceNum
+ >= pCurDq->sSliceBufferInfo[m_iThreadIdx].iMaxSliceNum -1) ? true : false;
if (bNeedReallocate) {
WelsMutexLock (&m_pCtx->pSliceThreading->mutexThreadSlcBuffReallocate);
//for memory statistic variable
@@ -316,7 +315,7 @@
iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->LastCodedMbIdxOfPartition[kiPartitionId];
iLocalSliceIdx += kiSliceIdxStep;
- m_pCtx->pCurDqLayer->sSliceThreadInfo[m_iThreadIdx].iCodedSliceNum ++;
+ m_pCtx->pCurDqLayer->sSliceBufferInfo[m_iThreadIdx].iCodedSliceNum ++;
}
return ENC_RETURN_SUCCESS;
--- a/test/encoder/EncUT_SliceBufferReallocate.cpp
+++ b/test/encoder/EncUT_SliceBufferReallocate.cpp
@@ -30,8 +30,8 @@
}
for (int32_t iThrdIdx = 0; iThrdIdx < pCtx->iActiveThreadsNum; iThrdIdx++) {
- iCodedSlcNum = pCtx->pCurDqLayer->sSliceThreadInfo[iThrdIdx].iCodedSliceNum;
- iMaxSlcNumInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iThrdIdx].iMaxSliceNum;
+ iCodedSlcNum = pCtx->pCurDqLayer->sSliceBufferInfo[iThrdIdx].iCodedSliceNum;
+ iMaxSlcNumInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iThrdIdx].iMaxSliceNum;
if ((iCodedSlcNum + kiMinBufferNum) <= iMaxSlcNumInThrd) {
aiThrdList[iAvailableThrdNum] = iThrdIdx;
@@ -147,9 +147,9 @@
SSpatialLayerConfig* pLayerCfg = &pCtx->pSvcParam->sSpatialLayers[iLayerIdx];
int32_t iPartitionID = rand() % iPartitionNum;
int32_t iMBNumInPatition = 0;
- int32_t iCodedSlcNum = pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iMaxSliceNum - 1;
+ int32_t iCodedSlcNum = pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iMaxSliceNum - 1;
int32_t iLastCodeSlcIdx = iPartitionID + iCodedSlcNum * iPartitionNum;
- SSlice* pLastCodedSlc = &pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].pSliceInThread[iCodedSlcNum - 1];
+ SSlice* pLastCodedSlc = &pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].pSliceBuffer[iCodedSlcNum - 1];
pLastCodedSlc->iSliceIdx = iLastCodeSlcIdx;
SetPartitonMBNum(pCtx->ppDqLayerList[iLayerIdx], pLayerCfg, iPartitionNum);
@@ -156,7 +156,7 @@
iMBNumInPatition = pCtx->pCurDqLayer->EndMbIdxOfPartition[iPartitionID] -
pCtx->pCurDqLayer->FirstMbIdxOfPartition[iPartitionID] + 1;
- pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iCodedSliceNum = iCodedSlcNum;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iCodedSliceNum = iCodedSlcNum;
pCtx->pCurDqLayer->LastCodedMbIdxOfPartition[iPartitionID] = rand() % iMBNumInPatition + 1;
}
@@ -369,15 +369,15 @@
void CSliceBufferReallocatTest::SimulateEncodedOneSlice(const int32_t kiSlcIdx, const int32_t kiThreadIdx) {
if(m_EncContext.pCurDqLayer->bThreadSlcBufferFlag) {
- int32_t iCodedSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum;
+ int32_t iCodedSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceBufferInfo[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->sSliceBufferInfo[kiThreadIdx].pSliceBuffer);
+ EXPECT_TRUE(NULL != &m_EncContext.pCurDqLayer->sSliceBufferInfo[kiThreadIdx].pSliceBuffer[iCodedSlcNumInThrd]);
- m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].pSliceInThread[iCodedSlcNumInThrd].iSliceIdx = kiSlcIdx;
- m_EncContext.pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum ++;
+ m_EncContext.pCurDqLayer->sSliceBufferInfo[kiThreadIdx].pSliceBuffer[iCodedSlcNumInThrd].iSliceIdx = kiSlcIdx;
+ m_EncContext.pCurDqLayer->sSliceBufferInfo[kiThreadIdx].iCodedSliceNum ++;
} else {
- m_EncContext.pCurDqLayer->sSliceThreadInfo[0].pSliceInThread[kiSlcIdx].iSliceIdx = kiSlcIdx;
+ m_EncContext.pCurDqLayer->sSliceBufferInfo[0].pSliceBuffer[kiSlcIdx].iSliceIdx = kiSlcIdx;
}
}
@@ -409,7 +409,7 @@
if (SM_SIZELIMITED_SLICE == pLayerCfg->sSliceArgument.uiSliceMode) {
int32_t iPartNum = m_EncContext.iActiveThreadsNum;
int32_t iSlicNumPerPart = iSimulateSliceNum / iPartNum;
- int32_t iMaxSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceThreadInfo[0].iMaxSliceNum;
+ int32_t iMaxSlcNumInThrd = m_EncContext.pCurDqLayer->sSliceBufferInfo[0].iMaxSliceNum;
int32_t iLastPartSlcNum = 0;
iSlicNumPerPart = WelsClip3(iSlicNumPerPart, 1, iMaxSlcNumInThrd);
@@ -449,14 +449,14 @@
// thrd_1: partition_1
// thrd_2: idle
int32_t iThreadIndex = rand() % pCtx->iActiveThreadsNum;
- int32_t iPartitionNum = rand() % pCtx->iActiveThreadsNum + 1;
- int32_t iSlcBufferNum = pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iMaxSliceNum;
+ int32_t iPartitionNum = rand() % pCtx->iActiveThreadsNum + 1; //include cases which part num less than thread num
+ int32_t iSlcBufferNum = pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iMaxSliceNum;
ParamSetForReallocateTest(pCtx, iLayerIdx, iThreadIndex, iPartitionNum);
iRet = ReallocateSliceInThread(pCtx, pCtx->pCurDqLayer, iLayerIdx, iThreadIndex);
EXPECT_TRUE(cmResultSuccess == iRet);
- EXPECT_TRUE(NULL != pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].pSliceInThread);
- EXPECT_TRUE(iSlcBufferNum < pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iMaxSliceNum);
+ EXPECT_TRUE(NULL != pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].pSliceBuffer);
+ EXPECT_TRUE(iSlcBufferNum < pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iMaxSliceNum);
UnInitParamForTestCase(iLayerIdx);
}
@@ -484,12 +484,12 @@
ParamSetForReallocateTest(pCtx, iLayerIdx, iThreadIndex, iPartitionNum);
for (int32_t iPartIdx = 0; iPartIdx < iPartitionNum; iPartIdx++) {
- iSlcBufferNum = pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iMaxSliceNum;
+ iSlcBufferNum = pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iMaxSliceNum;
iRet = ReallocateSliceInThread(pCtx, pCtx->pCurDqLayer, iLayerIdx, iThreadIndex);
EXPECT_TRUE(cmResultSuccess == iRet);
- EXPECT_TRUE(NULL != pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].pSliceInThread);
- EXPECT_TRUE(iSlcBufferNum < pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIndex].iMaxSliceNum);
+ EXPECT_TRUE(NULL != pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].pSliceBuffer);
+ EXPECT_TRUE(iSlcBufferNum < pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIndex].iMaxSliceNum);
}
UnInitParamForTestCase(iLayerIdx);
@@ -510,18 +510,18 @@
//before extend, simulate reallocate slice buffer in one thread
int32_t iReallocateThrdIdx = rand() % pCtx->iActiveThreadsNum;
- iSlcBuffNumInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iMaxSliceNum;
- pSlcListInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].pSliceInThread;
+ iSlcBuffNumInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iMaxSliceNum;
+ pSlcListInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].pSliceBuffer;
iRet = ReallocateSliceList(pCtx, &pCtx->pSvcParam->sSpatialLayers[iLayerIdx].sSliceArgument,
pSlcListInThrd, iSlcBuffNumInThrd, iSlcBuffNumInThrd * 2);
EXPECT_TRUE(cmResultSuccess == iRet);
EXPECT_TRUE(NULL != pSlcListInThrd);
- pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].pSliceInThread = pSlcListInThrd;
- pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iMaxSliceNum = iSlcBuffNumInThrd * 2;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].pSliceBuffer = pSlcListInThrd;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iMaxSliceNum = iSlcBuffNumInThrd * 2;
for (int32_t iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) {
- iMaxSliceNumNew += pCtx->pCurDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum;
+ iMaxSliceNumNew += pCtx->pCurDqLayer->sSliceBufferInfo[iThreadIdx].iMaxSliceNum;
}
iRet = ExtendLayerBuffer(pCtx, pCtx->pCurDqLayer->iMaxSliceNum, iMaxSliceNumNew);
@@ -606,9 +606,9 @@
//simulate reallocate slice buffer in one thread
int32_t iReallocateThrdIdx = rand() % pCtx->iActiveThreadsNum;
- int32_t iSlcBuffNumInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iMaxSliceNum;
- int32_t iCodedSlcNumInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iCodedSliceNum;
- SSlice* pSlcListInThrd = pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].pSliceInThread;
+ int32_t iSlcBuffNumInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iMaxSliceNum;
+ int32_t iCodedSlcNumInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iCodedSliceNum;
+ SSlice* pSlcListInThrd = pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].pSliceBuffer;
SliceModeEnum eSlcMode = pCtx->pSvcParam->sSpatialLayers[iLayerIdx].sSliceArgument.uiSliceMode;
int32_t iSlcIdxInThrd = 0;
int32_t iPartitionNum = (SM_SIZELIMITED_SLICE == eSlcMode) ? pCtx->iActiveThreadsNum : 1;
@@ -620,8 +620,8 @@
pSlcListInThrd, iSlcBuffNumInThrd, iSlcBuffNumInThrd * 2);
EXPECT_TRUE(cmResultSuccess == iRet);
EXPECT_TRUE(NULL != pSlcListInThrd);
- pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].pSliceInThread = pSlcListInThrd;
- pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iMaxSliceNum = iSlcBuffNumInThrd * 2;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].pSliceBuffer = pSlcListInThrd;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iMaxSliceNum = iSlcBuffNumInThrd * 2;
//update reallocate slice idx/NalNum info
for (int32_t iSlcIdx = iCodedSlcNumInThrd; iSlcIdx < iSlcBuffNumInThrd * 2; iSlcIdx++) {
@@ -636,7 +636,7 @@
pSlcListInThrd[iSlcIdx].sSliceBs.iNalIndex = rand() % 2 + 1;
pSlcListInThrd[iSlcIdx].sSliceBs.uiBsPos = rand() % pSlcListInThrd[iSlcIdx].sSliceBs.uiSize + 1;
pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame ++;
- pCtx->pCurDqLayer->sSliceThreadInfo[iReallocateThrdIdx].iCodedSliceNum++;
+ pCtx->pCurDqLayer->sSliceBufferInfo[iReallocateThrdIdx].iCodedSliceNum++;
}
//simulate for layer bs