History

remove max slice number constraint

ganyang committed 12 years ago

Commit 2e6f1801 parent 3b782906 files · +3745 −12Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 6 files). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+120−6
@@ -58,7 +58,8 @@ namespace WelsSVCEnc { · 57 unmodified lines
5858
5959
6060 int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
61− SLayerBSInfo* pLbi,
61+ SFrameBSInfo* pFrameBsInfo,
62+ SLayerBSInfo* pLayerBsInfo,
6263 int32_t* pNalIdxInLayer,
6364 int32_t* pLayerSize,
6465 int32_t iFirstMbInPartition, // first mb inclusive in partition
@@ -1588,6 +1589,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 1523 unmodified lines
15881589 if (NULL != pDq->sLayerInfo.pSliceInLayer) {
15891590 int32_t iSliceIdx = 0;
15901591 int32_t iSliceNum = GetInitialSliceNum (pDq->iMbWidth, pDq->iMbHeight, &pDlp->sSliceCfg);
1592+ if (pDlp->sSliceCfg.uiSliceMode == SM_DYN_SLICE && pCtx->iActiveThreadsNum == 1) {
1593+ if (iSliceNum < pDq->pSliceEncCtx->iMaxSliceNumConstraint) {
1594+ iSliceNum = pDq->pSliceEncCtx->iMaxSliceNumConstraint;
1595+ }
1596+ }
15911597 if (iSliceNum < 1)
15921598 iSliceNum = 1;
15931599 while (iSliceIdx < iSliceNum) {
@@ -3117,7 +3123,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1523 unmodified lines
31173123 // for dynamic slicing single threading..
31183124 else if ((SM_DYN_SLICE == pParam->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) {
31193125 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;
3120− pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);
3126+ pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pFbi, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);
31213127 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
31223128 } else {
31233129 //other multi-slice uiSliceMode
@@ -3680,8 +3686,112 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 556 unmodified lines
36803686 return 0;
36813687 }
36823688
3689+int32_t DynSliceRealloc(sWelsEncCtx* pCtx,
3690+ SFrameBSInfo* pFrameBsInfo,
3691+ SLayerBSInfo* pLayerBsInfo) {
3692+ CMemoryAlign* pMA = pCtx->pMemAlign;
3693+ SDqLayer* pCurLayer = pCtx->pCurDqLayer;
3694+
3695+ int32_t iCountNals = pCtx->pOut->iCountNals;
3696+ int32_t iMaxSliceNumOld = pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint;
3697+ int32_t iMaxSliceNum = iMaxSliceNumOld;
3698+ iCountNals += iMaxSliceNum * (pCtx->pSvcParam->iSpatialLayerNum + pCtx->bNeedPrefixNalFlag);
3699+ iMaxSliceNum *= SLICE_NUM_EXPAND_COEF;
3700+
3701+ SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMalloc(iCountNals * sizeof(SWelsNalRaw), "pOut->sNalList");
3702+ if (NULL == pNalList)
3703+ return ENC_RETURN_MEMALLOCERR;
3704+ memcpy(pNalList, pCtx->pOut->sNalList, sizeof(SWelsNalRaw) * pCtx->pOut->iCountNals);
3705+ pMA->WelsFree(pCtx->pOut->sNalList, "pOut->sNalList");
3706+ pCtx->pOut->sNalList = pNalList;
3707+
3708+ int32_t* pNalLen = (int32_t*)pMA->WelsMalloc(iCountNals * sizeof(int32_t), "pOut->pNalLen");
3709+ if (NULL == pNalLen)
3710+ return ENC_RETURN_MEMALLOCERR;
3711+ memcpy(pNalLen, pCtx->pOut->pNalLen, sizeof(int32_t) * pCtx->pOut->iCountNals);
3712+ pMA->WelsFree(pCtx->pOut->pNalLen, "pOut->pNalLen");
3713+ pCtx->pOut->pNalLen = pNalLen;
3714+
3715+ pCtx->pOut->iCountNals = iCountNals;
3716+ SLayerBSInfo *pLBI1, *pLBI2;
3717+ pLBI1 = &pFrameBsInfo->sLayerInfo[0];
3718+ pLBI1->pNalLengthInByte = pCtx->pOut->pNalLen;
3719+ while (pLBI1 != pLayerBsInfo) {
3720+ pLBI2 = pLBI1;
3721+ ++ pLBI1;
3722+ pLBI1->pNalLengthInByte = pLBI2->pNalLengthInByte + pLBI2->iNalCount;
3723+ }
3724+
3725+ SSlice *pSlice = (SSlice*)pMA->WelsMallocz( sizeof(SSlice) * iMaxSliceNum, "Slice");
3726+ if (NULL == pSlice)
3727+ return ENC_RETURN_MEMALLOCERR;
3728+ memcpy(pSlice, pCurLayer->sLayerInfo.pSliceInLayer, sizeof(SSlice) * iMaxSliceNumOld);
3729+ uint32_t uiSliceIdx;
3730+ uiSliceIdx = iMaxSliceNumOld;
3731+ SSlice *pBaseSlice = &pCurLayer->sLayerInfo.pSliceInLayer[0];
3732+ SSliceHeaderExt *pBaseSHExt = &pBaseSlice->sSliceHeaderExt;
3733+ SSlice *pSliceIdx = &pSlice[uiSliceIdx];
3734+ while (uiSliceIdx < iMaxSliceNum) {
3735+ SSliceHeaderExt *pSHExt = &pSliceIdx->sSliceHeaderExt;
3736+ pSliceIdx->uiSliceIdx = uiSliceIdx;
3737+ if (pCtx->pSvcParam->iMultipleThreadIdc > 1)
3738+ pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite;
3739+ else
3740+ pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite;
3741+ if (AllocMbCacheAligned(&pSliceIdx->sMbCacheInfo, pMA))
3742+ return ENC_RETURN_MEMALLOCERR;
36833743
3744+ pSliceIdx->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag;
3745+ pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId;
3746+ pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps;
3747+ pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId;
3748+ pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps;
3749+ pSHExt->sSliceHeader.uiRefCount = pCtx->iNumRef0;
3750+ memcpy(&pSHExt->sSliceHeader.sRefMarking, &pBaseSHExt->sSliceHeader.sRefMarking, sizeof(SRefPicMarking));
3751+ memcpy(&pSHExt->sSliceHeader.sRefReordering, &pBaseSHExt->sSliceHeader.sRefReordering, sizeof(SRefPicListReorderSyntax));
3752+
3753+ pSliceIdx++;
3754+ uiSliceIdx++;
3755+ }
3756+ pMA->WelsFree(pCurLayer->sLayerInfo.pSliceInLayer, "Slice");
3757+ pCurLayer->sLayerInfo.pSliceInLayer = pSlice;
3758+
3759+ SRCSlicing *pSlcingOverRc = (SRCSlicing *)pMA->WelsMalloc(iMaxSliceNum * sizeof(SRCSlicing), "SlicingOverRC");
3760+ if (NULL == pSlcingOverRc)
3761+ return ENC_RETURN_MEMALLOCERR;
3762+ memcpy(pSlcingOverRc, pCtx->pWelsSvcRc->pSlicingOverRc, sizeof(SRCSlicing) * iMaxSliceNumOld);
3763+ uiSliceIdx = iMaxSliceNumOld;
3764+ SRCSlicing *pSORC = &pSlcingOverRc[uiSliceIdx];
3765+ while (uiSliceIdx < iMaxSliceNum) {
3766+ pSORC->iComplexityIndexSlice = 0;
3767+ pSORC->iCalculatedQpSlice = pCtx->iGlobalQp;
3768+ pSORC ++;
3769+ uiSliceIdx ++;
3770+ }
3771+ pMA->WelsFree(pCtx->pWelsSvcRc->pSlicingOverRc, "SlicingOverRC");
3772+ pCtx->pWelsSvcRc->pSlicingOverRc = pSlcingOverRc;
3773+
3774+ int16_t *pFirstMbInSlice = (int16_t *)pMA->WelsMalloc(iMaxSliceNum * sizeof(int16_t), "pSliceSeg->pFirstMbInSlice");
3775+ if (NULL == pFirstMbInSlice)
3776+ return ENC_RETURN_MEMALLOCERR;
3777+ memcpy(pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof(int16_t) * iMaxSliceNumOld);
3778+ pMA->WelsFree(pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice");
3779+ pCurLayer->pSliceEncCtx->pFirstMbInSlice = pFirstMbInSlice;
3780+
3781+ int32_t *pCountMbNumInSlice = (int32_t *)pMA->WelsMalloc(iMaxSliceNum * sizeof(int32_t), "pSliceSeg->pCountMbNumInSlice");
3782+ if (NULL == pCountMbNumInSlice)
3783+ return ENC_RETURN_MEMALLOCERR;
3784+ memcpy(pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof(int32_t) * iMaxSliceNumOld);
3785+ pMA->WelsFree(pCurLayer->pSliceEncCtx->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
3786+ pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice;
3787+
3788+ if (pCtx->iMaxSliceCount < iMaxSliceNum)
3789+ pCtx->iMaxSliceCount = iMaxSliceNum;
3790+ pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint = iMaxSliceNum;
3791+ return ENC_RETURN_SUCCESS;
3792+}
36843793 int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
3794+ SFrameBSInfo* pFrameBSInfo,
36853795 SLayerBSInfo* pLayerBsInfo,
36863796 int32_t* pNalIdxInLayer,
36873797 int32_t* pLayerSize,
@@ -3701,6 +3811,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 13 unmodified lines
37013811 const EWelsNalUnitType keNalType = pCtx->eNalType;
37023812 const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority;
37033813 const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag;
3814+ const int32_t kiSliceIdxStep = pCtx->iActiveThreadsNum;
37043815 int32_t iReturn = ENC_RETURN_SUCCESS;
37053816
37063817 //init
@@ -3715,10 +3826,13 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 8 unmodified lines
37153826 int32_t iSliceSize = 0;
37163827 int32_t iPayloadSize = 0;
37173828
3718− if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[]
3719− // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage
3720− // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure
3721− return ENC_RETURN_MEMALLOCERR;
3829+ if (iSliceIdx >= (pSliceCtx->iMaxSliceNumConstraint - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[]
3830+ if (pCtx->iActiveThreadsNum == 1)
3831+ if (DynSliceRealloc(pCtx, pFrameBSInfo, pLayerBsInfo)) //only single thread support re-alloc now
3832+ return ENC_RETURN_MEMALLOCERR;
3833+ else if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) {
3834+ return ENC_RETURN_MEMALLOCERR;
3835+ }
37223836 }
37233837
37243838 if (kbNeedPrefix) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t