History

Merge pull request #2028 from sijchen/mt42

[Encoder] save memory usage and improve error return logic under VLCOVERFLOW

HaiboZhu committed 11 years ago

Commit b6ddfab2 parents 2407292 e70621c7 files · +63 −45Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+35−13
@@ -702,7 +702,12 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 701 unmodified lines
702702 if (iDIndex == 0)
703703 iCountNumNals += MAX_SLICES_NUM;
704704 // MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME ensured at svc_enc_slice_segment.h
705− assert (iCountNumNals - iOrgNumNals <= MAX_NAL_UNITS_IN_LAYER);
705+ if (iCountNumNals - iOrgNumNals > MAX_NAL_UNITS_IN_LAYER) {
706+ WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR,
707+ "AcquireLayersNals(), num_of_slice(%d) > existing slice(%d) at (iDid= %d), max=%d",
708+ iCountNumNals, iOrgNumNals, iDIndex, MAX_NAL_UNITS_IN_LAYER);
709+ return 1;
710+ }
706711 } else { /*if ( SM_SINGLE_SLICE != pDLayer->sSliceCfg.uiSliceMode )*/
707712 const int32_t kiNumOfSlice = GetInitialSliceNum ((pDLayer->iVideoWidth + 0x0f) >> 4,
708713 (pDLayer->iVideoHeight + 0x0f) >> 4,
@@ -1754,6 +1759,11 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 1045 unmodified lines
17541759 const int32_t kiPpsSize = (*ppCtx)->GetNeededPpsNum() * PPS_BUFFER_SIZE;
17551760 iNonVclLayersBsSizeCount = SSEI_BUFFER_SIZE + kiSpsSize + kiPpsSize;
17561761
1762+ bool bDynamicSlice = false;
1763+ uint32_t uiMaxSliceNumEstimation = 0;
1764+ int32_t iSliceBufferSize = 0;
1765+ int32_t iMaxSliceBufferSize = 0;
1766+ int32_t iTotalLength = 0;
17571767 int32_t iLayerBsSize = 0;
17581768 iIndex = 0;
17591769 while (iIndex < pParam->iSpatialLayerNum) {
@@ -1765,11 +1775,29 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 5 unmodified lines
17651775 MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
17661776 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged
17671777 iVclLayersBsSizeCount += iLayerBsSize;
1778+
1779+ SSliceConfig* pMso = & (fDlp->sSliceCfg);
1780+ if (pMso->uiSliceMode == SM_DYN_SLICE) {
1781+ bDynamicSlice = true;
1782+ uiMaxSliceNumEstimation = WELS_MIN (AVERSLICENUM_CONSTRAINT,
1783+ (iLayerBsSize / pMso->sSliceArgument.uiSliceSizeConstraint) + 1);
1784+ (*ppCtx)->iMaxSliceCount = WELS_MAX ((*ppCtx)->iMaxSliceCount, uiMaxSliceNumEstimation);
1785+ iSliceBufferSize = (WELS_MAX(pMso->sSliceArgument.uiSliceSizeConstraint, iLayerBsSize/uiMaxSliceNumEstimation)<<1) + MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
1786+ } else {
1787+ (*ppCtx)->iMaxSliceCount = WELS_MAX ((*ppCtx)->iMaxSliceCount, pMso->sSliceArgument.uiSliceNum);
1788+ iSliceBufferSize = ((iLayerBsSize / pMso->sSliceArgument.uiSliceNum)<<1) + MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
1789+ }
1790+ iMaxSliceBufferSize = WELS_MAX(iMaxSliceBufferSize, iSliceBufferSize);
1791+
17681792 ++ iIndex;
17691793 }
17701794 iTargetSpatialBsSize = iLayerBsSize;
17711795 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
17721796
1797+ iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize);
1798+ iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + ((*ppCtx)->iMaxSliceCount - 1) *
1799+ iMaxSliceBufferSize);
1800+
17731801 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT,
17741802 (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA :
17751803 MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN));
@@ -1787,20 +1815,14 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 11 unmodified lines
17871815 (*ppCtx)->pOut->iCountNals = iCountNals;
17881816 (*ppCtx)->pOut->iNalIndex = 0;
17891817
1790− if (pParam->iMultipleThreadIdc > 1) {
1791− const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));
1792− (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1793− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1794− (*ppCtx)->iFrameBsSize = iTotalLength;
1795− } else {
1796− (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pFrameBs");
1797− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1798− (*ppCtx)->iFrameBsSize = iCountBsLen;
1799− }
1818+
1819+ (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1820+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1821+ (*ppCtx)->iFrameBsSize = iTotalLength;
18001822 (*ppCtx)->iPosBsBuffer = 0;
18011823
18021824 // for pSlice bs buffers
1803− if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iTargetSpatialBsSize)) {
1825+ if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iMaxSliceBufferSize, bDynamicSlice)) {
18041826 WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");
18051827 FreeMemorySvc (ppCtx);
18061828 return 1;
@@ -4075,7 +4097,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2268 unmodified lines
40754097 // pick up succeeding slice for threading
40764098 // thread_id equal to iEventId per implementation here
40774099 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;
4078− SetOneSliceBsBufferUnderMultithread(pCtx, iEventId, iIndexOfSliceToBeCoded);
4100+ SetOneSliceBsBufferUnderMultithread (pCtx, iEventId, iIndexOfSliceToBeCoded);
40794101 WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);
40804102 WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iEventId]);
40814103 ++ iIndexOfSliceToBeCoded;

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