ref: 71750df1cc651fc435e7e19aed6f9cf111e9d76e
parent: c62e70da54203e86d40ead65b20c5ee9f67b7213
author: huade <[email protected]>
date: Wed Dec 21 11:52:27 EST 2016
Multi-thread-fixed:RBC#1721:replace ppSliceInLayer by pSliceInThread
--- a/codec/encoder/core/inc/slice.h
+++ b/codec/encoder/core/inc/slice.h
@@ -185,6 +185,7 @@
uint8_t sScaleShift;
uint32_t uiSliceIdx;
+uint32_t uiThreadIdx;
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/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3670,7 +3670,8 @@
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->ppSliceInLayer[0];
+ uint32_t uiTheadIdx = 0;
+ SSlice* pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][0];
if (pCtx->bNeedPrefixNalFlag) {
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType,
@@ -3808,13 +3809,16 @@
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);
} else { // for non-dynamic-slicing mode single threading branch..
const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
- int32_t iSliceIdx = 0;
- SSlice* pCurSlice = NULL;
+ int32_t iSliceIdx = 0;
+ uint32_t uiTheadIdx = 0;
+ SSlice* pCurSlice = NULL;
+
iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer);
while (iSliceIdx < iSliceCount) {
int32_t iSliceSize = 0;
int32_t iPayloadSize = 0;
+
if (bNeedPrefix) {
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType,
eNalRefIdc,
@@ -3824,7 +3828,8 @@
}
WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);
- pCurSlice = pCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx];
+
+ pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx];
assert (iSliceIdx == (int) pCurSlice->uiSliceIdx);
pCtx->iEncoderError = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, iSliceIdx);
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
@@ -4516,7 +4521,8 @@
) {
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
- SSlice* pStartSlice = pCurLayer->ppSliceInLayer[iStartSliceIdx];
+ uint32_t uiTheadIdx = 0;
+ SSlice* pStartSlice = &pCurLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iStartSliceIdx];
int32_t iNalIdxInLayer = *pNalIdxInLayer;
int32_t iSliceIdx = iStartSliceIdx;
const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
@@ -4529,6 +4535,7 @@
const int32_t kiSliceIdxStep = pCtx->iActiveThreadsNum;
int32_t iReturn = ENC_RETURN_SUCCESS;
+
//init
{
pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxInPartition;
@@ -4565,8 +4572,10 @@
}
WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc);
- pCurSlice = pCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx];
+
+ pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx];
assert (iSliceIdx == (int) pCurSlice->uiSliceIdx);
+
iReturn = WelsCodeOneSlice (pCtx, pCurSlice, keNalType);
WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
WelsUnloadNal (pCtx->pOut);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -603,9 +603,9 @@
if (pParamD->sSliceArgument.uiSliceMode != SM_SIZELIMITED_SLICE) {
int64_t iSliceStart = 0;
bool bDsaFlag = false;
- iSliceIdx = pPrivateData->iSliceIndex;
- pSlice = pCurDq->ppSliceInLayer[iSliceIdx];
- pSliceBs = &pSlice->sSliceBs;
+ iSliceIdx = pPrivateData->iSliceIndex;
+ pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx];
+ pSliceBs = &pSlice->sSliceBs;
bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) &&
pCodingParam->iMultipleThreadIdc > 1 &&
@@ -645,7 +645,7 @@
iEventIdx);
}
- iReturn = WelsCodeOneSlice (pEncPEncCtx, pCurSlice, eNalType);
+ iReturn = SetSliceBoundaryInfo(pEncPEncCtx->pCurDqLayer, pSlice, iSliceIdx);
if (ENC_RETURN_SUCCESS != iReturn) {
uiThrdRet = iReturn;
WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
@@ -653,6 +653,15 @@
iEventIdx);
}
+ assert (iSliceIdx == (int) pSlice->uiSliceIdx);
+ iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType);
+ if (ENC_RETURN_SUCCESS != iReturn) {
+ uiThrdRet = iReturn;
+ WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
+ pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
+ iEventIdx);
+ }
+
WelsUnloadNalForSlice (pSliceBs);
iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs, iSliceIdx, iSliceSize);
@@ -666,14 +675,13 @@
pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
if (bDsaFlag) {
- pEncPEncCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime = (uint32_t) (
- WelsTime() - iSliceStart);
+ pSlice->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->ppSliceInLayer[iSliceIdx]->uiSliceConsumeTime, iSliceSize,
- pCurDq->ppSliceInLayer[iSliceIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
- pCurDq->ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice);
+ pSlice->uiSliceConsumeTime, iSliceSize,
+ pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
+ pSlice->iCountMbNumInSlice);
}
#if defined(SLICE_INFO_OUTPUT)
@@ -701,11 +709,11 @@
const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId];
int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1;
SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid];
- iSliceIdx = pPrivateData->iSliceIndex;
- SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->ppSliceInLayer[iSliceIdx]->sSliceHeaderExt;
- pStartSliceHeaderExt->sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
- pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1;
- pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0;
+ iSliceIdx = pPrivateData->iSliceIndex;
+ SSlice* pStartSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx];
+ pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
+ pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1;
+ pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0;
while (iAnyMbLeftInPartition > 0) {
if (iSliceIdx >= pCurDq->iMaxSliceNum) {
@@ -720,8 +728,7 @@
pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
iEventIdx);
}
-
- pSlice = pCurDq->ppSliceInLayer[iSliceIdx];
+ pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx];
pSliceBs = &pSlice->sSliceBs;
pSliceBs->uiBsPos = 0;
pSliceBs->iNalIndex = 0;
@@ -741,11 +748,10 @@
}
}
-
WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
- pCurSlice = pEncPEncCtx->pCurDqLayer->ppSliceInLayer[iSliceIdx];
- assert (iSliceIdx == (int) pCurSlice->uiSliceIdx);
- iReturn = WelsCodeOneSlice (pEncPEncCtx, pCurSlice, eNalType);
+
+ assert (iSliceIdx == (int) pSlice->uiSliceIdx);
+ iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType);
if (ENC_RETURN_SUCCESS != iReturn) {
uiThrdRet = iReturn;
WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
@@ -783,7 +789,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->ppSliceInLayer[iSliceIdx]->iCountMbNumInSlice,
+ pSlice->iCountMbNumInSlice,
kiEndMbIdxInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId];
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -954,6 +954,7 @@
}
pSlice->uiSliceIdx = iSliceIdx;
+ pSlice->uiThreadIdx = 0;
pSlice->iCountMbNumInSlice = 0;
pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -1185,6 +1186,7 @@
}
pSlice->uiSliceIdx = iSliceIdx;
+ pSlice->uiThreadIdx = 0;
pSlice->iCountMbNumInSlice = 0;
pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -1354,7 +1356,6 @@
pCurLayer->iMaxSliceNum = iMaxSliceNumNew;
return ENC_RETURN_SUCCESS;
}
-
/*
int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,
const int32_t kiThreadNum,
@@ -1518,7 +1519,7 @@
void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {
SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
- SSlice** ppSliceInLayer = pCurLayer->ppSliceInLayer;
+ SSlice* pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[0];
int32_t iCurMbIdx = pCurMb->iMbXY;
uint16_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ];
const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum;
@@ -1531,7 +1532,7 @@
pCurSlice->sSliceHeaderExt.uiNumMbsInSlice = 1 + iCurMbIdx - pCurSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
//pNextSlice pointer/initialization
- pNextSlice = pCurLayer->ppSliceInLayer[ iNextSliceIdc ];
+ pNextSlice = &pSliceInThread[ iNextSliceIdc ];
#if _DEBUG
assert (NULL != pNextSlice);
@@ -1542,7 +1543,7 @@
(NAL_UNIT_CODED_SLICE_EXT == pCurLayer->sLayerInfo.sNalHeaderExt.sNalUnitHeader.eNalUnitType);
memcpy (&pNextSlice->sSliceHeaderExt, &pCurSlice->sSliceHeaderExt,
sizeof (SSliceHeaderExt)); // confirmed_safe_unsafe_usage
- ppSliceInLayer[iNextSliceIdc]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxOfNextSlice;
+ pNextSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxOfNextSlice;
WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdxOfNextSlice, iNextSliceIdc,
(kiLastMbIdxInPartition - iFirstMbIdxOfNextSlice + 1), sizeof (uint16_t));
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -113,7 +113,7 @@
}
// InitOneSliceInThread();
- m_pSlice = m_pCtx->pCurDqLayer->ppSliceInLayer[m_iSliceIdx];
+ m_pSlice = &m_pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[0][m_iSliceIdx];
m_pSliceBs = &m_pSlice->sSliceBs;
m_pSliceBs->uiBsPos = 0;
@@ -166,9 +166,9 @@
}
WelsLoadNalForSlice (m_pSliceBs, m_eNalType, m_eNalRefIdc);
- SSlice* pCurSlice = m_pCtx->pCurDqLayer->ppSliceInLayer[m_iSliceIdx];
- assert (m_iSliceIdx == (int) pCurSlice->uiSliceIdx);
- int32_t iReturn = WelsCodeOneSlice (m_pCtx, pCurSlice, m_eNalType);
+
+ assert (m_iSliceIdx == (int) m_pSlice->uiSliceIdx);
+ int32_t iReturn = WelsCodeOneSlice (m_pCtx, m_pSlice, m_eNalType);
if (ENC_RETURN_SUCCESS != iReturn) {
return iReturn;
}
@@ -239,11 +239,11 @@
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
const int32_t kiSliceIdxStep = m_pCtx->iActiveThreadsNum;
SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId];
- SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->ppSliceInLayer[m_iSliceIdx]->sSliceHeaderExt;
const int32_t kiPartitionId = m_iSliceIdx % kiSliceIdxStep;
const int32_t kiFirstMbInPartition = pCurDq->pFirstMbIdxOfPartition[kiPartitionId];
const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId];
- pStartSliceHeaderExt->sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
+ m_pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[0][m_iSliceIdx];
+ m_pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1;
pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0;
@@ -261,7 +261,7 @@
return ENC_RETURN_KNOWN_ISSUE;
}
- m_pSlice = pCurDq->ppSliceInLayer[iLocalSliceIdx];
+ m_pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[0][iLocalSliceIdx];
m_pSliceBs = &m_pSlice->sSliceBs;
m_pSliceBs->uiBsPos = 0;
@@ -283,9 +283,9 @@
}
WelsLoadNalForSlice (m_pSliceBs, m_eNalType, m_eNalRefIdc);
- SSlice* pCurSlice = m_pCtx->pCurDqLayer->ppSliceInLayer[iLocalSliceIdx];
- assert (iLocalSliceIdx == (int) pCurSlice->uiSliceIdx);
- int32_t iReturn = WelsCodeOneSlice (m_pCtx, pCurSlice, m_eNalType);
+
+ assert (iLocalSliceIdx == (int) m_pSlice->uiSliceIdx);
+ int32_t iReturn = WelsCodeOneSlice (m_pCtx, m_pSlice, m_eNalType);
if (ENC_RETURN_SUCCESS != iReturn) {
return iReturn;
}