ref: 7c8ce799c00e1de58c97dd5e17e72bec3c3e82b8
parent: ca457f57e9150ce48f8fe555909296444d253319
author: ruil2 <[email protected]>
date: Tue Mar 11 06:23:46 EDT 2014
fix SM_FIXEDSLCNUM_SLICE bug, add SM_AUTO_SLICE mode
--- a/codec/api/svc/codec_app_def.h
+++ b/codec/api/svc/codec_app_def.h
@@ -160,7 +160,8 @@
SM_RASTER_SLICE = 2, // | according to SlicesAssign | Need input of MB numbers each slice. In addition, if other constraint in SSliceArgument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved.
SM_ROWMB_SLICE = 3, // | according to PictureMBHeight | Typical of single row of mbs each slice?+ slice size constraint which including re-encoding
SM_DYN_SLICE = 4, // | according to SliceSize | Dynamic slicing (have no idea about slice_nums until encoding current frame)
- SM_RESERVED = 5
+ SM_AUTO_SLICE = 5, // | according to thread number
+ SM_RESERVED = 6
} SliceModeEnum;
typedef struct {
--- a/codec/console/enc/src/welsenc.cpp
+++ b/codec/console/enc/src/welsenc.cpp
@@ -552,6 +552,9 @@
case 4:
pDLayer->sSliceCfg.uiSliceMode = SM_DYN_SLICE;
break;
+ case 5:
+ pDLayer->sSliceCfg.uiSliceMode = SM_AUTO_SLICE;
+ break;
default:
pDLayer->sSliceCfg.uiSliceMode = SM_RESERVED;
break;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -226,7 +226,8 @@
fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[iIdx] = 0;
}
break;
- case SM_FIXEDSLCNUM_SLICE: {
+ case SM_FIXEDSLCNUM_SLICE:
+ case SM_AUTO_SLICE:{
fDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 0;
iMbWidth = (kiPicWidth + 15) >> 4;
@@ -1690,14 +1691,7 @@
const int32_t kiMbWidth = (pDlp->iFrameWidth + 15) >> 4;
const int32_t kiMbHeight = (pDlp->iFrameHeight + 15) >> 4;
const int32_t kiMbNumInFrame = kiMbWidth * kiMbHeight;
-#if defined(MT_ENABLED)
- int32_t iSliceNum = (SM_FIXEDSLCNUM_SLICE == pMso->uiSliceMode
- || SM_DYN_SLICE == pMso->uiSliceMode) ? kiCpuCores :
- pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()
-#else//!MT_ENABLED
- int16_t iSliceNum = pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()
-#endif//MT_ENABLED
-
+ int32_t iSliceNum = (SM_AUTO_SLICE == pMso->uiSliceMode)? kiCpuCores :pSlcArg->uiSliceNum;
// NOTE: Per design, in case MT/DYNAMIC_SLICE_ASSIGN enabled, for SM_FIXEDSLCNUM_SLICE mode,
// uiSliceNum of current spatial layer settings equals to uiCpuCores number; SM_DYN_SLICE mode,
// uiSliceNum intials as uiCpuCores also, stay tuned dynamically slicing in future
@@ -1710,6 +1704,7 @@
break; // go through for MT_ENABLED & SM_DYN_SLICE?
//#endif//MT_ENABLED
case SM_FIXEDSLCNUM_SLICE:
+ case SM_AUTO_SLICE:
if (iSliceNum > iMaxSliceCount)
iMaxSliceCount = iSliceNum;
// need perform check due uiSliceNum might change, although has been initialized somewhere outside
@@ -2950,7 +2945,8 @@
// Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed
switch (param_d->sSliceCfg.uiSliceMode) {
- case SM_FIXEDSLCNUM_SLICE: {
+ case SM_FIXEDSLCNUM_SLICE:
+ case SM_AUTO_SLICE:{
#if defined(MT_ENABLED)
if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&
(pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
@@ -3403,7 +3399,7 @@
}
#if defined(MT_ENABLED)
- if (param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE && pSvcParam->iMultipleThreadIdc > 1 &&
+ if ((param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE||param_d->sSliceCfg.uiSliceMode == SM_AUTO_SLICE) && pSvcParam->iMultipleThreadIdc > 1 &&
pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {
CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,
pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]);
@@ -3444,9 +3440,9 @@
#if defined(MT_ENABLED)
if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID
- && pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
+ && ((pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))
&& pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum
- && pSvcParam->sDependencyLayers[did_list[iSpatialNum - 1]].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
+ && ((pSvcParam->sDependencyLayers[did_list[iSpatialNum - 1]].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[did_list[iSpatialNum - 1]].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))
&& pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[did_list[iSpatialNum -
1]].sSliceCfg.sSliceArgument.uiSliceNum) {
AdjustBaseLayer (pCtx);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -325,7 +325,7 @@
while (iIdx < iNumSpatialLayers) {
SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg;
const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum;
- if (pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE && pPara->iMultipleThreadIdc > 1
+ if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE)) && pPara->iMultipleThreadIdc > 1
&& pPara->iMultipleThreadIdc >= kiSliceNum) {
pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]");
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx))
@@ -727,7 +727,7 @@
pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];
- bDsaFlag = (pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE &&
+ bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) &&
pCodingParam->iMultipleThreadIdc > 1 &&
pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum);
if (bDsaFlag)
@@ -1142,7 +1142,9 @@
SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx;
const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame;
if (pCtx->pSliceThreading) {
- if (pCtx->pSliceThreading->pFSliceDiff && pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE && pPara->iMultipleThreadIdc > 1
+ if (pCtx->pSliceThreading->pFSliceDiff
+ && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE))
+ && pPara->iMultipleThreadIdc > 1
&& pPara->iMultipleThreadIdc >= kuiCountSliceNum) {
uint32_t i = 0;
uint32_t uiMaxT = 0;
--- a/codec/encoder/core/src/svc_enc_slice_segment.cpp
+++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp
@@ -84,7 +84,8 @@
return 0;
} else if (SM_RASTER_SLICE == pSliceSeg->uiSliceMode ||
- SM_FIXEDSLCNUM_SLICE == pSliceSeg->uiSliceMode) {
+ SM_FIXEDSLCNUM_SLICE == pSliceSeg->uiSliceMode||
+ SM_AUTO_SLICE == pSliceSeg->uiSliceMode) {
const int32_t* kpSlicesAssignList = (int32_t*) & (kpMso->sSliceArgument.uiSliceMbNum[0]);
const int32_t kiCountNumMbInFrame = pSliceSeg->iMbNumInFrame;
const int32_t kiCountSliceNumInFrame = pSliceSeg->iSliceNumInFrame;
@@ -308,7 +309,8 @@
case SM_SINGLE_SLICE:
case SM_FIXEDSLCNUM_SLICE:
case SM_RASTER_SLICE:
- case SM_ROWMB_SLICE: {
+ case SM_ROWMB_SLICE:
+ case SM_AUTO_SLICE:{
return pMso->sSliceArgument.uiSliceNum;
}
case SM_DYN_SLICE: {
@@ -398,7 +400,7 @@
return AssignMbMapSingleSlice (pSliceSeg->pOverallMbMap, kiCountMbNum, sizeof (pSliceSeg->pOverallMbMap[0]));
} else { //if ( SM_MULTIPLE_SLICE == uiSliceMode )
if (uiSliceMode != SM_FIXEDSLCNUM_SLICE && uiSliceMode != SM_ROWMB_SLICE && uiSliceMode != SM_RASTER_SLICE
- && uiSliceMode != SM_DYN_SLICE)
+ && uiSliceMode != SM_DYN_SLICE&& uiSliceMode != SM_AUTO_SLICE)
return 1;
pSliceSeg->pOverallMbMap = (uint8_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint8_t), "pSliceSeg->pOverallMbMap");
--- a/testbin/layer2.cfg
+++ b/testbin/layer2.cfg
@@ -34,4 +34,4 @@
# 2 SM_RASTER_SLICE | according to SlicesAssign | Need input of MB numbers each slice. In addition, if other constraint in slice_argument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved.
# 3 SM_ROWMB_SLICE | according to PictureMBHeight | Typical of single row of mbs each slice?+ slice size constraint which including re-encoding
# 4 SM_DYN_SLICE | according to SliceSize | Dynamic slicing (have no idea about slice_nums until encoding current frame)
-
+# 5 SM_AUTO_SLICE | according to thread number | the number of slice is decided by the thread number
--- a/testbin/layer2_arbitrary_res.cfg
+++ b/testbin/layer2_arbitrary_res.cfg
@@ -35,4 +35,4 @@
# 2 SM_RASTER_SLICE | according to SlicesAssign | Need input of MB numbers each slice. In addition, if other constraint in slice_argument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved.
# 3 SM_ROWMB_SLICE | according to PictureMBHeight | Typical of single row of mbs each slice?+ slice size constraint which including re-encoding
# 4 SM_DYN_SLICE | according to SliceSize | Dynamic slicing (have no idea about slice_nums until encoding current frame)
-
+# 5 SM_AUTO_SLICE | according to thread number | the number of slice is decided by the thread number
--- a/testbin/layer2_vd.cfg
+++ b/testbin/layer2_vd.cfg
@@ -35,4 +35,4 @@
# 2 SM_RASTER_SLICE | according to SlicesAssign | Need input of MB numbers each slice. In addition, if other constraint in slice_argument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved.
# 3 SM_ROWMB_SLICE | according to PictureMBHeight | Specially for TP. Typical of single row of mbs each slice?+ slice size constraint which including re-encoding
# 4 SM_DYN_SLICE | according to SliceSize | Dynamic slicing (have no idea about slice_nums until encoding current frame)
-
+# 5 SM_AUTO_SLICE | according to thread number | the number of slice is decided by the thread number
--- a/testbin/layer2_vd_rc.cfg
+++ b/testbin/layer2_vd_rc.cfg
@@ -35,4 +35,4 @@
# 2 SM_RASTER_SLICE | according to SlicesAssign | Need input of MB numbers each slice. In addition, if other constraint in slice_argument is presented, need to follow the constraints. Typically if MB num and slice size are both constrained, re-encoding may be involved.
# 3 SM_ROWMB_SLICE | according to PictureMBHeight | Specially for TP. Typical of single row of mbs each slice?+ slice size constraint which including re-encoding
# 4 SM_DYN_SLICE | according to SliceSize | Dynamic slicing (have no idea about slice_nums until encoding current frame)
-
+# 5 SM_AUTO_SLICE | according to thread number | the number of slice is decided by the thread number