ref: f263f0710a7b154ee161efad93909101f909470b
parent: aeb55e07fe5ca9f3ddcaec6730e81f61a5448ab4
author: huade <huashi@cisco.com>
date: Tue Nov 24 05:44:23 EST 2015
remove pSliceComplexRatio from SliceThreading
--- a/codec/encoder/core/inc/mt_defs.h
+++ b/codec/encoder/core/inc/mt_defs.h
@@ -80,8 +80,6 @@
WELS_MUTEX mutexSliceNumUpdate; // for dynamic slicing mode MT
-int32_t* pSliceComplexRatio[MAX_DEPENDENCY_LAYER]; // *INT_MULTIPLY
-
#ifdef MT_DEBUG
FILE* pFSliceDiff; // file handle for debug
#endif//MT_DEBUG
--- a/codec/encoder/core/inc/slice.h
+++ b/codec/encoder/core/inc/slice.h
@@ -182,6 +182,7 @@
int32_t iCabacInitIdc;
int32_t iMbSkipRun;
uint32_t uiSliceConsumeTime;
+int32_t iSliceComplexRatio;
} SSlice, *PSlice;
}
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -55,13 +55,12 @@
SMB* pMbList,
const int32_t kiSliceIdc);
-void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq);
+void CalcSliceComplexRatio (SDqLayer* pCurDq);
int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t kiSliceNum);
void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
SDqLayer* pCurDqLayer,
- void* pComplexRatio,
int32_t iCurDid);
int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pParam, const int32_t kiCountBsLen,
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -4299,7 +4299,7 @@
&& pSvcParam->bUseLoadBalancing
&& pSvcParam->iMultipleThreadIdc > 1 &&
pSvcParam->iMultipleThreadIdc >= pParam->sSliceArgument.uiSliceNum) {
- CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer);
+ CalcSliceComplexRatio (pCtx->pCurDqLayer);
#if defined(MT_DEBUG)
TrackSliceComplexities (pCtx, iCurDid);
#endif//#if defined(MT_DEBUG)
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -128,10 +128,9 @@
} while (iIdx <= kiEndMbInSlice);
}
-void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq) {
+void CalcSliceComplexRatio (SDqLayer* pCurDq) {
SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
- int32_t* pRatioList = (int32_t*)pRatio;
int32_t iSumAv = 0;
int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice;
const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame;
@@ -150,7 +149,7 @@
++ iSliceIdx;
}
while (-- iSliceIdx >= 0) {
- pRatioList[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv);
+ pSliceInLayer[iSliceIdx].iSliceComplexRatio = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv);
}
}
@@ -205,15 +204,14 @@
void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
SDqLayer* pCurDqLayer,
- void* pComplexRatio,
int32_t iCurDid) {
- SSliceCtx* pSliceCtx = &pCurDqLayer->sSliceEncCtx;
+ SSliceCtx* pSliceCtx = &pCurDqLayer->sSliceEncCtx;
+ SSlice* pSliceInLayer = pCurDqLayer->sLayerInfo.pSliceInLayer;
const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame;
const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame;
int32_t iMinimalMbNum =
pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required
int32_t iMaximalMbNum = 0; // dynamically assign later
- int32_t* pSliceComplexRatio = (int32_t*)pComplexRatio;
int32_t iMbNumLeft = kiCountNumMb;
int32_t iRunLen[MAX_THREADS_NUM] = {0};
int32_t iSliceIdx = 0;
@@ -249,7 +247,7 @@
iSliceIdx = 0;
while (iSliceIdx + 1 < kiCountSliceNum) {
- int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceComplexRatio[iSliceIdx], INT_MULTIPLY);
+ int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceInLayer[iSliceIdx].iSliceComplexRatio, INT_MULTIPLY);
// GOM boundary aligned
if (pCtx->pSvcParam->iRCMode != RC_OFF_MODE) {
@@ -271,8 +269,9 @@
}
iRunLen[iSliceIdx] = iNumMbAssigning;
MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
- "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
- iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx],
+ "[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],
iNumMbAssigning);
++ iSliceIdx;
iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts
@@ -279,8 +278,9 @@
}
iRunLen[iSliceIdx] = iMbNumLeft;
MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
- "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
- iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
+ "[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);
if (DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen) == 0) {
@@ -367,18 +367,7 @@
iIdx = 0;
while (iIdx < iNumSpatialLayers) {
SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[iIdx].sSliceArgument;
- const int32_t kiSliceNum = pSliceArgument->uiSliceNum;
- if ((pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE)
- && (pPara->bUseLoadBalancing)
- && (pPara->iMultipleThreadIdc > 1)
- && (pPara->iMultipleThreadIdc >= kiSliceNum)) {
- pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx))
- } else {
- pSmt->pSliceComplexRatio[iIdx] = NULL;
- }
-
- 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;
@@ -474,7 +463,6 @@
void ReleaseMtResource (sWelsEncCtx** ppCtx) {
SWelsSliceBs* pSliceB = NULL;
- SWelsSvcCodingParam* pCodingParam = NULL;
SSliceThreading* pSmt = NULL;
CMemoryAlign* pMa = NULL;
int32_t iIdx = 0;
@@ -485,7 +473,6 @@
return;
pMa = (*ppCtx)->pMemAlign;
- pCodingParam = (*ppCtx)->pSvcParam;
uiSliceNum = (*ppCtx)->iMaxSliceCount;
iThreadNum = (*ppCtx)->pSvcParam->iCountThreadsNum;
pSmt = (*ppCtx)->pSliceThreading;
@@ -550,15 +537,6 @@
(*ppCtx)->pTaskManage = NULL;
}
- iIdx = 0;
- while (iIdx < pCodingParam->iSpatialLayerNum) {
- if (pSmt->pSliceComplexRatio[iIdx] != NULL) {
- pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]");
- pSmt->pSliceComplexRatio[iIdx] = NULL;
- }
- ++ iIdx;
- }
-
#ifdef MT_DEBUG
// file handle for debug
if (pSmt->pFSliceDiff) {
@@ -1067,7 +1045,6 @@
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
pCurDq,
- pCtx->pSliceThreading->pSliceComplexRatio[0],
0);
#ifdef MT_DEBUG
iT0 = WelsTime() - iT0;
@@ -1101,7 +1078,6 @@
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
pCtx->pCurDqLayer,
- pCtx->pSliceThreading->pSliceComplexRatio[iCurDid - 1],
iCurDid
);
} else { // use temporal layer for complexity estimation
@@ -1111,7 +1087,6 @@
if (iNeedAdj)
DynamicAdjustSlicing (pCtx,
pCtx->pCurDqLayer,
- pCtx->pSliceThreading->pSliceComplexRatio[iCurDid],
iCurDid
);
}
@@ -1133,11 +1108,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;
if (kiCountSliceNum > 0) {
int32_t iSliceIdx = 0;
do {
fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6.3f complexity pRatio at iDid %d pSlice %d\n",
- pCtx->pSliceThreading->pSliceComplexRatio[iCurDid][iSliceIdx], iCurDid, iSliceIdx);
+ pSliceInLayer[iSliceIdx].iSliceComplexRatio, iCurDid, iSliceIdx);
++ iSliceIdx;
} while (iSliceIdx < kiCountSliceNum);
}