Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 5 files). Show all
Unified · Split
| @@ -1095,15 +1095,37 @@ int32_t FindExistingPps (SWelsSPS* pSps, SSubsetSps* pSubsetSps, const bool kbUs · 1094 unmodified lines | |||
| 1095 | } | 1095 | } |
| 1096 | 1096 | ||
| 1097 | static inline int32_t InitpSliceInLayer (sWelsEncCtx** ppCtx, SDqLayer* pDqLayer, CMemoryAlign* pMa, | 1097 | static inline int32_t InitpSliceInLayer (sWelsEncCtx** ppCtx, SDqLayer* pDqLayer, CMemoryAlign* pMa, |
| 1098 | const int32_t iMaxSliceNum, bool bMultithread) { | 1098 | const int32_t iMaxSliceNum, const int32_t kiDlayerIndex) { |
| 1099 | int32_t iSliceIdx = 0; | 1099 | int32_t iMaxSliceBufferSize = (*ppCtx)->iSliceBufferSize[kiDlayerIndex]; |
| 1100 | int32_t iSliceIdx = 0; | ||
| 1101 | SliceModeEnum uiSliceMode = (*ppCtx)->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument.uiSliceMode; | ||
| 1102 | |||
| 1103 | //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite | ||
| 1104 | //even though multi-thread is on for other layers | ||
| 1105 | bool bIndependenceBsBuffer = ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && | ||
| 1106 | SM_SINGLE_SLICE != uiSliceMode) ? true : false; | ||
| 1107 | |||
| 1108 | if ( iMaxSliceBufferSize <= 0) { | ||
| 1109 | return ENC_RETURN_UNEXPECTED; | ||
| 1110 | } | ||
| 1111 | |||
| 1100 | while (iSliceIdx < iMaxSliceNum) { | 1112 | while (iSliceIdx < iMaxSliceNum) { |
| 1101 | SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx]; | 1113 | SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| 1102 | pSlice->uiSliceIdx = iSliceIdx; | 1114 | |
| 1103 | if (bMultithread) | 1115 | pSlice->uiSliceIdx = iSliceIdx; |
| 1104 | pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite; | 1116 | pSlice->sSliceBs.uiSize = iMaxSliceBufferSize; |
| 1105 | else | 1117 | pSlice->sSliceBs.uiBsPos = 0; |
| 1106 | pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite; | 1118 | if (bIndependenceBsBuffer){ |
| 1119 | pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite; | ||
| 1120 | pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "SliceBs"); | ||
| 1121 | if ( NULL == pSlice->sSliceBs.pBs) { | ||
| 1122 | return ENC_RETURN_MEMALLOCERR; | ||
| 1123 | } | ||
| 1124 | } else { | ||
| 1125 | pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite; | ||
| 1126 | pSlice->sSliceBs.pBs = NULL; | ||
| 1127 | } | ||
| 1128 | |||
| 1107 | if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) { | 1129 | if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) { |
| 1108 | FreeMemorySvc (ppCtx); | 1130 | FreeMemorySvc (ppCtx); |
| 1109 | return ENC_RETURN_MEMALLOCERR; | 1131 | return ENC_RETURN_MEMALLOCERR; |
| @@ -1211,7 +1233,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 101 unmodified lines | |||
| 1211 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); | 1233 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); |
| 1212 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx)) | 1234 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx)) |
| 1213 | 1235 | ||
| 1214 | int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, pParam->iMultipleThreadIdc > 1); | 1236 | int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, iDlayerIndex); |
| 1215 | WELS_VERIFY_RETURN_PROC_IF (1, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx)) | 1237 | WELS_VERIFY_RETURN_PROC_IF (1, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx)) |
| 1216 | } | 1238 | } |
| 1217 | 1239 | ||
| @@ -1809,16 +1831,15 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 591 unmodified lines | |||
| 1809 | (*ppCtx)->iMaxSliceCount = WELS_MAX ((*ppCtx)->iMaxSliceCount, (int) pSliceArgument->uiSliceNum); | 1831 | (*ppCtx)->iMaxSliceCount = WELS_MAX ((*ppCtx)->iMaxSliceCount, (int) pSliceArgument->uiSliceNum); |
| 1810 | iSliceBufferSize = ((iLayerBsSize / pSliceArgument->uiSliceNum)<<1) + MAX_MACROBLOCK_SIZE_IN_BYTE_x2; | 1832 | iSliceBufferSize = ((iLayerBsSize / pSliceArgument->uiSliceNum)<<1) + MAX_MACROBLOCK_SIZE_IN_BYTE_x2; |
| 1811 | } | 1833 | } |
| 1812 | iMaxSliceBufferSize = WELS_MAX(iMaxSliceBufferSize, iSliceBufferSize); | 1834 | iMaxSliceBufferSize = WELS_MAX(iMaxSliceBufferSize, iSliceBufferSize); |
| 1813 | 1835 | (*ppCtx)->iSliceBufferSize[iIndex] = iSliceBufferSize; | |
| 1814 | ++ iIndex; | 1836 | ++ iIndex; |
| 1815 | } | 1837 | } |
| 1816 | iTargetSpatialBsSize = iLayerBsSize; | 1838 | iTargetSpatialBsSize = iLayerBsSize; |
| 1817 | iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount; | 1839 | iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount; |
| 1818 | 1840 | ||
| 1819 | iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize); | 1841 | iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize); |
| 1820 | iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + (*ppCtx)->iMaxSliceCount * | 1842 | iTotalLength = iCountBsLen; |
| 1821 | iMaxSliceBufferSize); | ||
| 1822 | 1843 | ||
| 1823 | pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, | 1844 | pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, |
| 1824 | (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA : | 1845 | (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA : |
| @@ -2125,6 +2146,12 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 300 unmodified lines | |||
| 2125 | while (iSliceIdx < iSliceNum) { | 2146 | while (iSliceIdx < iSliceNum) { |
| 2126 | SSlice* pSlice = &pDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | 2147 | SSlice* pSlice = &pDq->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| 2127 | FreeMbCache (&pSlice->sMbCacheInfo, pMa); | 2148 | FreeMbCache (&pSlice->sMbCacheInfo, pMa); |
| 2149 | |||
| 2150 | //slice bs buffer | ||
| 2151 | if(NULL != pSlice->sSliceBs.pBs) { | ||
| 2152 | pMa->WelsFree(pSlice->sSliceBs.pBs,"sSliceBs.pBs"); | ||
| 2153 | pSlice->sSliceBs.pBs = NULL; | ||
| 2154 | } | ||
| 2128 | ++ iSliceIdx; | 2155 | ++ iSliceIdx; |
| 2129 | } | 2156 | } |
| 2130 | pMa->WelsFree (pDq->sLayerInfo.pSliceInLayer, "pSliceInLayer"); | 2157 | pMa->WelsFree (pDq->sLayerInfo.pSliceInLayer, "pSliceInLayer"); |
| @@ -3896,11 +3923,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1765 unmodified lines | |||
| 3896 | 3923 | ||
| 3897 | WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc); | 3924 | WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc); |
| 3898 | 3925 | ||
| 3899 | //the following line is to fix a problem with a specific setting as in test DiffSlicingInDlayerMixed: | ||
| 3900 | // (multi-th on with SM_SINGLE_SLICE in one of the D layers) | ||
| 3901 | //TODO: this may not be needed any more after the slice buffer refactoring | ||
| 3902 | pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0].pSliceBsa = &(pCtx->pOut->sBsWrite); | ||
| 3903 | |||
| 3904 | pCtx->iEncoderError = WelsCodeOneSlice (pCtx, 0, eNalType); | 3926 | pCtx->iEncoderError = WelsCodeOneSlice (pCtx, 0, eNalType); |
| 3905 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) | 3927 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3906 | 3928 | ||
| @@ -4734,7 +4756,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 827 unmodified lines | |||
| 4734 | SSliceHeaderExt* pSHExt = &pSliceIdx->sSliceHeaderExt; | 4756 | SSliceHeaderExt* pSHExt = &pSliceIdx->sSliceHeaderExt; |
| 4735 | pSliceIdx->uiSliceIdx = uiSliceIdx; | 4757 | pSliceIdx->uiSliceIdx = uiSliceIdx; |
| 4736 | if (pCtx->pSvcParam->iMultipleThreadIdc > 1) | 4758 | if (pCtx->pSvcParam->iMultipleThreadIdc > 1) |
| 4737 | pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite; | 4759 | pSliceIdx->pSliceBsa = &pSliceIdx->sSliceBs.sBsWrite; |
| 4738 | else | 4760 | else |
| 4739 | pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite; | 4761 | pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite; |
| 4740 | if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) { | 4762 | if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) { |