Merge pull request #2276 from shihuade/MultiThread_V4.2_SSliceCtx_pSliceCountInMB_V3

remove pCountMbNumInSlice from SSliceCtx
This commit is contained in:
HaiboZhu 2015-11-25 15:02:50 +08:00
commit 3dccfabce3
8 changed files with 40 additions and 72 deletions

View File

@ -181,6 +181,8 @@ uint8_t uiReservedFillByte; // reserved to meet 4 bytes alignment
SCabacCtx sCabacCtx;
int32_t iCabacInitIdc;
int32_t iMbSkipRun;
int32_t iCountMbNumInSlice;
uint32_t uiSliceConsumeTime;
int32_t iSliceComplexRatio;
} SSlice, *PSlice;

View File

@ -86,7 +86,6 @@ int16_t iMbHeight; /* height of picture size in mb
int32_t iSliceNumInFrame; /* count number of slices in frame; */
int32_t iMbNumInFrame; /* count number of MBs in frame */
uint16_t* pOverallMbMap; /* overall MB map in frame, store virtual slice idc; */
int32_t* pCountMbNumInSlice; /* count number of MBs in every slice respectively; */
uint32_t uiSliceSizeConstraint; /* in byte */
int32_t iMaxSliceNumConstraint; /* maximal number of slices constraint */

View File

@ -2766,18 +2766,18 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) {
i = 0;
while (i < iPartitionNum) {
if (i + 1 == iPartitionNum) {
pSliceCtx->pCountMbNumInSlice[i] = iAssignableMbLeft;
pSliceInLayer[i].iCountMbNumInSlice = iAssignableMbLeft;
} else {
pSliceCtx->pCountMbNumInSlice[i] = iCountMbNumPerPartition;
pSliceInLayer[i].iCountMbNumInSlice = iCountMbNumPerPartition;
}
pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i,
pSliceCtx->pCountMbNumInSlice[i], sizeof (uint16_t));
pSliceInLayer[i].iCountMbNumInSlice, sizeof (uint16_t));
// for next partition(or pSlice)
iFirstMbIdx += pSliceCtx->pCountMbNumInSlice[i];
iAssignableMbLeft -= pSliceCtx->pCountMbNumInSlice[i];
iFirstMbIdx += pSliceInLayer[i].iCountMbNumInSlice;
iAssignableMbLeft -= pSliceInLayer[i].iCountMbNumInSlice;
++ i;
}
}
@ -4803,21 +4803,6 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
}
pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice");
pCurLayer->sLayerInfo.pSliceInLayer = pSlice;
int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t),
"pSliceSeg->pCountMbNumInSlice");
if (NULL == pCountMbNumInSlice) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
"CWelsH264SVCEncoder::DynSliceRealloc: realloc pCountMbNumInSlice not successful");
return ENC_RETURN_MEMALLOCERR;
}
memcpy (pCountMbNumInSlice, pCurLayer->sSliceEncCtx.pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);
uiSliceIdx = iMaxSliceNumOld;
while (uiSliceIdx < iMaxSliceNum) {
pCountMbNumInSlice[uiSliceIdx] = pCurLayer->sSliceEncCtx.iMbNumInFrame;
uiSliceIdx++;
}
pMA->WelsFree (pCurLayer->sSliceEncCtx.pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
pCurLayer->sSliceEncCtx.pCountMbNumInSlice = pCountMbNumInSlice;
//deal with rate control variables
const int32_t kiCurDid = pCtx->uiDependencyId;
@ -4837,7 +4822,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
pSORC->iCalculatedQpSlice = pCtx->iGlobalQp;
pSORC->iTotalQpSlice = 0;
pSORC->iTotalMbSlice = 0;
pSORC->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurLayer->sSliceEncCtx.pCountMbNumInSlice[uiSliceIdx],
pSORC->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurLayer->sLayerInfo.pSliceInLayer[uiSliceIdx].iCountMbNumInSlice,
INT_MULTIPLY);
pSORC->iFrameBitsSlice = 0;
pSORC->iGomBitsSlice = 0;

View File

@ -511,7 +511,6 @@ void RcCalculatePictureQp (sWelsEncCtx* pEncCtx) {
}
void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
SSliceCtx* pCurSliceCtx = &pEncCtx->pCurDqLayer->sSliceEncCtx;
SSlice* pSliceInLayer = pEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId];
SRCSlicing* pSOverRc = &pWelsSvcRc->pSlicingOverRc[0];
@ -522,10 +521,10 @@ void RcInitSliceInformation (sWelsEncCtx* pEncCtx) {
for (int32_t i = 0; i < kiSliceNum; i++) {
pSOverRc->iStartMbSlice =
pSOverRc->iEndMbSlice = pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
pSOverRc->iEndMbSlice += (pCurSliceCtx->pCountMbNumInSlice[i] - 1);
pSOverRc->iEndMbSlice += (pSliceInLayer[i].iCountMbNumInSlice - 1);
pSOverRc->iTotalQpSlice = 0;
pSOverRc->iTotalMbSlice = 0;
pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurSliceCtx->pCountMbNumInSlice[i], INT_MULTIPLY);
pSOverRc->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pSliceInLayer[i].iCountMbNumInSlice, INT_MULTIPLY);
pSOverRc->iFrameBitsSlice = 0;
pSOverRc->iGomBitsSlice = 0;
++ pSOverRc;

View File

@ -85,7 +85,7 @@ void UpdateMbListNeighborParallel (SDqLayer* pCurDq,
const uint16_t* kpMbMap = pSliceCtx->pOverallMbMap;
const int32_t kiMbWidth = pSliceCtx->iMbWidth;
int32_t iIdx = pUpdateSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
const int32_t kiEndMbInSlice = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1;
const int32_t kiEndMbInSlice = iIdx + pUpdateSlice->iCountMbNumInSlice - 1;
do {
SMB* pMb = &pMbList[iIdx];
@ -132,7 +132,6 @@ void CalcSliceComplexRatio (SDqLayer* pCurDq) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
int32_t iSumAv = 0;
int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice;
const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame;
int32_t iSliceIdx = 0;
int32_t iAvI[MAX_SLICES_NUM];
@ -140,10 +139,11 @@ void CalcSliceComplexRatio (SDqLayer* pCurDq) {
WelsEmms();
while (iSliceIdx < kiSliceCount) {
iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pCountMbInSlice[iSliceIdx], pSliceInLayer[iSliceIdx].uiSliceConsumeTime);
iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
pSliceInLayer[iSliceIdx].uiSliceConsumeTime);
MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), uiSliceConsumeTime[%d]= %d us, slice_run= %d",
iSliceIdx,
pSliceInLayer[iSliceIdx].uiSliceConsumeTime, pCountMbInSlice[iSliceIdx]);
pSliceInLayer[iSliceIdx].uiSliceConsumeTime, pSliceInLayer[iSliceIdx].iCountMbNumInSlice);
iSumAv += iAvI[iSliceIdx];
++ iSliceIdx;
@ -271,7 +271,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
MT_TRACE_LOG (pCtx, 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,
pSliceCtx->pCountMbNumInSlice[iSliceIdx],
pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
iNumMbAssigning);
++ iSliceIdx;
iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts
@ -280,8 +280,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
"[MT] DynamicAdjustSlicing(), iSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY,
pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft);
if (DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen) == 0) {
const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum;
@ -367,7 +366,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
iIdx = 0;
while (iIdx < iNumSpatialLayers) {
SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[iIdx].sSliceArgument;
if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) {
if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) {
bWillUseTaskManage = true;
}
++ iIdx;
@ -789,7 +788,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
pEncPEncCtx->iCodingIndex, iSliceIdx,
pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime, iSliceSize,
pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
pCurDq->sSliceEncCtx.pCountMbNumInSlice[iSliceIdx]);
pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].iCountMbNumInSlice);
}
#if defined(SLICE_INFO_OUTPUT)
@ -898,7 +897,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
MT_TRACE_LOG (pEncPEncCtx, 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->sSliceEncCtx.pCountMbNumInSlice[iSliceIdx],
pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize,
pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].iCountMbNumInSlice,
kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
iAnyMbLeftInPartition = kiEndMbInPartition - (1 + pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);

View File

@ -83,7 +83,7 @@ int32_t AssignMbMapMultipleSlices (SDqLayer* pCurDq,const SSliceArgument* kpSlic
while (iSliceIdx < iSliceNum) {
const int32_t kiFirstMb = iSliceIdx * kiMbWidth;
SSliceHeaderExt* pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
pSliceSeg->pCountMbNumInSlice[iSliceIdx] = kiMbWidth;
pSliceInLayer[iSliceIdx].iCountMbNumInSlice = kiMbWidth;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = kiFirstMb;
WelsSetMemMultiplebytes_c(pSliceSeg->pOverallMbMap + kiFirstMb, iSliceIdx,
kiMbWidth, sizeof(uint16_t));
@ -100,11 +100,11 @@ int32_t AssignMbMapMultipleSlices (SDqLayer* pCurDq,const SSliceArgument* kpSlic
iSliceIdx = 0;
do {
const int32_t kiCurRunLength = kpSlicesAssignList[iSliceIdx];
int32_t iRunIdx = 0;
pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
const int32_t kiCurRunLength = kpSlicesAssignList[iSliceIdx];
int32_t iRunIdx = 0;
pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = iMbIdx;
pSliceSeg->pCountMbNumInSlice[iSliceIdx] = kiCurRunLength;
pSliceInLayer[iSliceIdx].iCountMbNumInSlice = kiCurRunLength;
// due here need check validate mb_assign_map for input pData, can not use memset
do {
@ -121,9 +121,9 @@ int32_t AssignMbMapMultipleSlices (SDqLayer* pCurDq,const SSliceArgument* kpSlic
iSliceIdx = 0;
do {
pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = 0;
pSliceSeg->pCountMbNumInSlice[iSliceIdx] = kiCountNumMbInFrame;
pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = 0;
pSliceInLayer[iSliceIdx].iCountMbNumInSlice = kiCountNumMbInFrame;
iSliceIdx++;
} while (iSliceIdx < kiMaxSliceNum);
} else { // any else uiSliceMode?
@ -366,6 +366,7 @@ int32_t InitSliceSegment (SDqLayer* pCurDq,
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;
@ -383,12 +384,6 @@ int32_t InitSliceSegment (SDqLayer* pCurDq,
pSliceSeg->pOverallMbMap = NULL;
}
if (NULL != pSliceSeg->pCountMbNumInSlice) {
pMa->WelsFree (pSliceSeg->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
pSliceSeg->pCountMbNumInSlice = NULL;
}
// just for safe
pSliceSeg->iSliceNumInFrame = 0;
pSliceSeg->iMbNumInFrame = 0;
@ -403,15 +398,11 @@ int32_t InitSliceSegment (SDqLayer* pCurDq,
WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap)
pSliceSeg->iSliceNumInFrame = 1;
pSliceSeg->pCountMbNumInSlice = (int32_t*)pMa->WelsMalloc (pSliceSeg->iSliceNumInFrame * sizeof (int32_t),
"pSliceSeg->pCountMbNumInSlice");
WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pCountMbNumInSlice)
pSliceSeg->uiSliceMode = uiSliceMode;
pSliceSeg->iMbWidth = kiMbWidth;
pSliceSeg->iMbHeight = kiMbHeight;
pSliceSeg->iMbNumInFrame = kiCountMbNum;
pSliceSeg->pCountMbNumInSlice[0] = kiCountMbNum;
pSliceInLayer[0].iCountMbNumInSlice = kiCountMbNum;
return AssignMbMapSingleSlice (pSliceSeg->pOverallMbMap, kiCountMbNum, sizeof (pSliceSeg->pOverallMbMap[0]));
} else { //if ( SM_MULTIPLE_SLICE == uiSliceMode )
@ -429,10 +420,6 @@ int32_t InitSliceSegment (SDqLayer* pCurDq,
if (-1 == pSliceSeg->iSliceNumInFrame)
return 1;
pSliceSeg->pCountMbNumInSlice = (int32_t*)pMa->WelsMalloc (pSliceSeg->iSliceNumInFrame * sizeof (int32_t),
"pSliceSeg->pCountMbNumInSlice");
WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pCountMbNumInSlice)
pSliceSeg->uiSliceMode = pSliceArgument->uiSliceMode;
pSliceSeg->iMbWidth = kiMbWidth;
@ -475,12 +462,6 @@ void UninitSliceSegment (SDqLayer* pCurDq, CMemoryAlign* pMa) {
pSliceSeg->pOverallMbMap = NULL;
}
if (NULL != pSliceSeg->pCountMbNumInSlice) {
pMa->WelsFree (pSliceSeg->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
pSliceSeg->pCountMbNumInSlice = NULL;
}
pSliceSeg->iMbNumInFrame = 0;
pSliceSeg->iMbWidth = 0;
pSliceSeg->iMbHeight = 0;
@ -641,18 +622,20 @@ int32_t WelsGetPrevMbOfSlice (SDqLayer* pCurDq, const int32_t kiMbXY) {
*/
int32_t WelsGetNumMbInSlice (SDqLayer* pCurDq, const int32_t kuiSliceIdc) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
SSlice* pSlice = &pCurDq->sLayerInfo.pSliceInLayer[kuiSliceIdc];
if (NULL == pSliceCtx || kuiSliceIdc < 0)
return -1;
{
SSliceCtx* pSliceSeg = pSliceCtx;
if (SM_SINGLE_SLICE != pSliceSeg->uiSliceMode) {
if (NULL == pSliceSeg->pCountMbNumInSlice || kuiSliceIdc >= pSliceSeg->iSliceNumInFrame)
if (kuiSliceIdc >= pSliceSeg->iSliceNumInFrame)
return -1;
return pSliceSeg->pCountMbNumInSlice[ kuiSliceIdc ];
return pSlice->iCountMbNumInSlice;
} else { /*if ( pSliceSeg->uiSliceMode == SM_SINGLE_SLICE )*/
if (kuiSliceIdc > 0 || NULL == pSliceSeg->pCountMbNumInSlice)
if (kuiSliceIdc > 0)
return -1;
return pSliceSeg->pCountMbNumInSlice[ kuiSliceIdc ];
return pSlice->iCountMbNumInSlice;
}
}
}
@ -674,7 +657,7 @@ int32_t DynamicAdjustSlicePEncCtxAll (SDqLayer* pCurDq,
assert (iCountSliceNumInFrame <= MAX_THREADS_NUM);
while (iSliceIdx < iCountSliceNumInFrame) {
if (pRunLength[iSliceIdx] != pSliceCtx->pCountMbNumInSlice[iSliceIdx]) {
if (pRunLength[iSliceIdx] != pSliceInLayer[iSliceIdx].iCountMbNumInSlice) {
iSameRunLenFlag = 0;
break;
}
@ -689,7 +672,7 @@ int32_t DynamicAdjustSlicePEncCtxAll (SDqLayer* pCurDq,
const int32_t kiSliceRun = pRunLength[iSliceIdx];
SSliceHeaderExt* pSliceHeaderExt = &pSliceInLayer[iSliceIdx].sSliceHeaderExt;
pSliceHeaderExt->sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
pSliceCtx->pCountMbNumInSlice[iSliceIdx] = kiSliceRun;
pSliceInLayer[iSliceIdx].iCountMbNumInSlice = kiSliceRun;
WelsSetMemMultiplebytes_c(pSliceCtx->pOverallMbMap + iFirstMbIdx, iSliceIdx,
kiSliceRun, sizeof(uint16_t));

View File

@ -617,7 +617,7 @@ TRY_REENCODING:
iNextMbIdx = WelsGetNextMbOfSlice (pCurLayer, iCurMbIdx);
//whether all of MB in current pSlice encoded or not
if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {
pSliceCtx->pCountMbNumInSlice[kiSliceIdx] = iCurMbIdx - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId];
pSlice->iCountMbNumInSlice = iCurMbIdx - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId];
pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] =
iCurMbIdx; // update pLastCodedMbIdxOfPartition, finish coding, use iCurMbIdx directly
break;

View File

@ -224,7 +224,7 @@ void CWelsLoadBalancingSlicingEncodingTask::FinishTask() {
m_pSlice->uiSliceConsumeTime,
m_iSliceSize,
m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
m_pCtx->pCurDqLayer->sSliceEncCtx.pCountMbNumInSlice[m_iSliceIdx]);
m_pSlice->iCountMbNumInSlice);
}