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
702 if (iDIndex == 0)702 if (iDIndex == 0)
703 iCountNumNals += MAX_SLICES_NUM;703 iCountNumNals += MAX_SLICES_NUM;
704 // MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME ensured at svc_enc_slice_segment.h704 // 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 }
706 } else { /*if ( SM_SINGLE_SLICE != pDLayer->sSliceCfg.uiSliceMode )*/711 } else { /*if ( SM_SINGLE_SLICE != pDLayer->sSliceCfg.uiSliceMode )*/
707 const int32_t kiNumOfSlice = GetInitialSliceNum ((pDLayer->iVideoWidth + 0x0f) >> 4,712 const int32_t kiNumOfSlice = GetInitialSliceNum ((pDLayer->iVideoWidth + 0x0f) >> 4,
708 (pDLayer->iVideoHeight + 0x0f) >> 4,713 (pDLayer->iVideoHeight + 0x0f) >> 4,
@@ -1754,6 +1759,11 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 1045 unmodified lines
1754 const int32_t kiPpsSize = (*ppCtx)->GetNeededPpsNum() * PPS_BUFFER_SIZE;1759 const int32_t kiPpsSize = (*ppCtx)->GetNeededPpsNum() * PPS_BUFFER_SIZE;
1755 iNonVclLayersBsSizeCount = SSEI_BUFFER_SIZE + kiSpsSize + kiPpsSize;1760 iNonVclLayersBsSizeCount = SSEI_BUFFER_SIZE + kiSpsSize + kiPpsSize;
1756 1761
1762 bool bDynamicSlice = false;
1763 uint32_t uiMaxSliceNumEstimation = 0;
1764 int32_t iSliceBufferSize = 0;
1765 int32_t iMaxSliceBufferSize = 0;
1766 int32_t iTotalLength = 0;
1757 int32_t iLayerBsSize = 0;1767 int32_t iLayerBsSize = 0;
1758 iIndex = 0;1768 iIndex = 0;
1759 while (iIndex < pParam->iSpatialLayerNum) {1769 while (iIndex < pParam->iSpatialLayerNum) {
@@ -1765,11 +1775,29 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 5 unmodified lines
1765 MAX_MACROBLOCK_SIZE_IN_BYTE_x2;1775 MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
1766 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged1776 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged
1767 iVclLayersBsSizeCount += iLayerBsSize;1777 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
1768 ++ iIndex;1792 ++ iIndex;
1769 }1793 }
1770 iTargetSpatialBsSize = iLayerBsSize;1794 iTargetSpatialBsSize = iLayerBsSize;
1771 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;1795 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
1772 1796
1797 iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize);
1798 iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + ((*ppCtx)->iMaxSliceCount - 1) *
1799 iMaxSliceBufferSize);
1800
1773 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT,1801 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT,
1774 (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA :1802 (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA :
1775 MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN));1803 MAX_REFERENCE_PICTURE_COUNT_NUM_SCREEN));
@@ -1787,20 +1815,14 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 11 unmodified lines
1787 (*ppCtx)->pOut->iCountNals = iCountNals;1815 (*ppCtx)->pOut->iCountNals = iCountNals;
1788 (*ppCtx)->pOut->iNalIndex = 0;1816 (*ppCtx)->pOut->iNalIndex = 0;
1789 1817
1790 if (pParam->iMultipleThreadIdc > 1) {1818
1791 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));1819 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1792 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");1820 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1793 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1821 (*ppCtx)->iFrameBsSize = iTotalLength;
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 }
1800 (*ppCtx)->iPosBsBuffer = 0;1822 (*ppCtx)->iPosBsBuffer = 0;
1801 1823
1802 // for pSlice bs buffers1824 // 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)) {
1804 WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");1826 WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");
1805 FreeMemorySvc (ppCtx);1827 FreeMemorySvc (ppCtx);
1806 return 1;1828 return 1;
@@ -4075,7 +4097,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2268 unmodified lines
4075 // pick up succeeding slice for threading4097 // pick up succeeding slice for threading
4076 // thread_id equal to iEventId per implementation here4098 // thread_id equal to iEventId per implementation here
4077 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;4099 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;
4078 SetOneSliceBsBufferUnderMultithread(pCtx, iEventId, iIndexOfSliceToBeCoded);4100 SetOneSliceBsBufferUnderMultithread (pCtx, iEventId, iIndexOfSliceToBeCoded);
4079 WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);4101 WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);
4080 WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iEventId]);4102 WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iEventId]);
4081 ++ iIndexOfSliceToBeCoded;4103 ++ 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