ref: d02addd90f0aec5384bf30ee6809c20517a5c5fb
parent: 60f36eb25a9b30499aedc33e63c82ae3c15e277a
author: huade <[email protected]>
date: Wed Nov 25 08:36:37 EST 2015
remove pCountMbNumInSlice from SSliceCtx
--- a/codec/encoder/core/inc/slice.h
+++ b/codec/encoder/core/inc/slice.h
@@ -181,6 +181,8 @@
SCabacCtx sCabacCtx;
int32_t iCabacInitIdc;
int32_t iMbSkipRun;
+
+int32_t iCountMbNumInSlice;
uint32_t uiSliceConsumeTime;
int32_t iSliceComplexRatio;
} SSlice, *PSlice;
--- a/codec/encoder/core/inc/svc_enc_slice_segment.h
+++ b/codec/encoder/core/inc/svc_enc_slice_segment.h
@@ -86,7 +86,6 @@
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 */
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2766,18 +2766,18 @@
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 @@
}
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 @@
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;
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -511,7 +511,6 @@
}
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 @@
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;
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -85,7 +85,7 @@
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 @@
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 @@
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 @@
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,9 +280,8 @@
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;
int32_t iThreadIdx = 0;
@@ -367,7 +366,7 @@
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 @@
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 @@
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]);
--- a/codec/encoder/core/src/svc_enc_slice_segment.cpp
+++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp
@@ -83,7 +83,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 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 @@
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 @@
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));
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -617,7 +617,7 @@
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;
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -224,7 +224,7 @@
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);
}