Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 7 files). Show all
Unified · Split
| @@ -894,61 +894,14 @@ int32_t InitMbListD (sWelsEncCtx** ppCtx) { · 893 unmodified lines | |||
| 894 | 894 | ||
| 895 | return 0; | 895 | return 0; |
| 896 | } | 896 | } |
| 897 | void FreeSliceInLayer (SDqLayer* pDq, CMemoryAlign* pMa) { | ||
| 898 | int32_t iIdx = 0; | ||
| 897 | 899 | ||
| 898 | int32_t AllocMbCacheAligned (SMbCache* pMbCache, CMemoryAlign* pMa) { | 900 | FreeSliceBuffer (pDq->sLayerInfo.pSliceInLayer, pDq->iMaxSliceNum, pMa, "pSliceInLayer"); |
| 899 | pMbCache->pCoeffLevel = (int16_t*)pMa->WelsMallocz (MB_COEFF_LIST_SIZE * sizeof (int16_t), "pMbCache->pCoeffLevel"); | 901 | for (; iIdx < MAX_THREADS_NUM; iIdx ++) { |
| 900 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pCoeffLevel)); | 902 | FreeSliceBuffer (pDq->sSliceThreadInfo.pSliceInThread[iIdx], |
| 901 | pMbCache->pMemPredMb = (uint8_t*)pMa->WelsMallocz (2 * 256 * sizeof (uint8_t), "pMbCache->pMemPredMb"); | 903 | pDq->sSliceThreadInfo.iMaxSliceNumInThread[iIdx], |
| 902 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pMemPredMb)); | 904 | pMa, "pSliceInLayer"); |
| 903 | pMbCache->pSkipMb = (uint8_t*)pMa->WelsMallocz (384 * sizeof (uint8_t), "pMbCache->pSkipMb"); | ||
| 904 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pSkipMb)); | ||
| 905 | pMbCache->pMemPredBlk4 = (uint8_t*)pMa->WelsMallocz (2 * 16 * sizeof (uint8_t), "pMbCache->pMemPredBlk4"); | ||
| 906 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pMemPredBlk4)); | ||
| 907 | pMbCache->pBufferInterPredMe = (uint8_t*)pMa->WelsMallocz (4 * 640 * sizeof (uint8_t), "pMbCache->pBufferInterPredMe"); | ||
| 908 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pBufferInterPredMe)); | ||
| 909 | pMbCache->pPrevIntra4x4PredModeFlag = (bool*)pMa->WelsMallocz (16 * sizeof (bool), | ||
| 910 | "pMbCache->pPrevIntra4x4PredModeFlag"); | ||
| 911 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pPrevIntra4x4PredModeFlag)); | ||
| 912 | pMbCache->pRemIntra4x4PredModeFlag = (int8_t*)pMa->WelsMallocz (16 * sizeof (int8_t), | ||
| 913 | "pMbCache->pRemIntra4x4PredModeFlag"); | ||
| 914 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pRemIntra4x4PredModeFlag)); | ||
| 915 | pMbCache->pDct = (SDCTCoeff*)pMa->WelsMallocz (sizeof (SDCTCoeff), "pMbCache->pDct"); | ||
| 916 | WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pDct)); | ||
| 917 | return 0; | ||
| 918 | } | ||
| 919 | |||
| 920 | void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa) { | ||
| 921 | if (NULL != pMbCache->pCoeffLevel) { | ||
| 922 | pMa->WelsFree (pMbCache->pCoeffLevel, "pMbCache->pCoeffLevel"); | ||
| 923 | pMbCache->pCoeffLevel = NULL; | ||
| 924 | } | ||
| 925 | if (NULL != pMbCache->pMemPredMb) { | ||
| 926 | pMa->WelsFree (pMbCache->pMemPredMb, "pMbCache->pMemPredMb"); | ||
| 927 | pMbCache->pMemPredMb = NULL; | ||
| 928 | } | ||
| 929 | if (NULL != pMbCache->pSkipMb) { | ||
| 930 | pMa->WelsFree (pMbCache->pSkipMb, "pMbCache->pSkipMb"); | ||
| 931 | pMbCache->pSkipMb = NULL; | ||
| 932 | } | ||
| 933 | if (NULL != pMbCache->pMemPredBlk4) { | ||
| 934 | pMa->WelsFree (pMbCache->pMemPredBlk4, "pMbCache->pMemPredBlk4"); | ||
| 935 | pMbCache->pMemPredBlk4 = NULL; | ||
| 936 | } | ||
| 937 | if (NULL != pMbCache->pBufferInterPredMe) { | ||
| 938 | pMa->WelsFree (pMbCache->pBufferInterPredMe, "pMbCache->pBufferInterPredMe"); | ||
| 939 | pMbCache->pBufferInterPredMe = NULL; | ||
| 940 | } | ||
| 941 | if (NULL != pMbCache->pPrevIntra4x4PredModeFlag) { | ||
| 942 | pMa->WelsFree (pMbCache->pPrevIntra4x4PredModeFlag, "pMbCache->pPrevIntra4x4PredModeFlag"); | ||
| 943 | pMbCache->pPrevIntra4x4PredModeFlag = NULL; | ||
| 944 | } | ||
| 945 | if (NULL != pMbCache->pRemIntra4x4PredModeFlag) { | ||
| 946 | pMa->WelsFree (pMbCache->pRemIntra4x4PredModeFlag, "pMbCache->pRemIntra4x4PredModeFlag"); | ||
| 947 | pMbCache->pRemIntra4x4PredModeFlag = NULL; | ||
| 948 | } | ||
| 949 | if (NULL != pMbCache->pDct) { | ||
| 950 | pMa->WelsFree (pMbCache->pDct, "pMbCache->pDct"); | ||
| 951 | pMbCache->pDct = NULL; | ||
| 952 | } | 905 | } |
| 953 | } | 906 | } |
| 954 | 907 | ||
| @@ -957,22 +910,7 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 2 unmodified lines | |||
| 957 | return; | 910 | return; |
| 958 | } | 911 | } |
| 959 | 912 | ||
| 960 | if (NULL != pDq->sLayerInfo.pSliceInLayer) { | 913 | FreeSliceInLayer (pDq, pMa); |
| 961 | int32_t iSliceIdx = 0; | ||
| 962 | while (iSliceIdx < pDq->iMaxSliceNum) { | ||
| 963 | SSlice* pSlice = &pDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | ||
| 964 | FreeMbCache (&pSlice->sMbCacheInfo, pMa); | ||
| 965 | |||
| 966 | //slice bs buffer | ||
| 967 | if (NULL != pSlice->sSliceBs.pBs) { | ||
| 968 | pMa->WelsFree (pSlice->sSliceBs.pBs, "sSliceBs.pBs"); | ||
| 969 | pSlice->sSliceBs.pBs = NULL; | ||
| 970 | } | ||
| 971 | ++ iSliceIdx; | ||
| 972 | } | ||
| 973 | pMa->WelsFree (pDq->sLayerInfo.pSliceInLayer, "pSliceInLayer"); | ||
| 974 | pDq->sLayerInfo.pSliceInLayer = NULL; | ||
| 975 | } | ||
| 976 | 914 | ||
| 977 | if (pDq->pNumSliceCodedOfPartition) { | 915 | if (pDq->pNumSliceCodedOfPartition) { |
| 978 | pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition"); | 916 | pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition"); |
| @@ -1165,47 +1103,138 @@ int32_t FindExistingPps (SWelsSPS* pSps, SSubsetSps* pSubsetSps, const bool kbUs · 186 unmodified lines | |||
| 1165 | return INVALID_ID; | 1103 | return INVALID_ID; |
| 1166 | } | 1104 | } |
| 1167 | 1105 | ||
| 1168 | static inline int32_t InitpSliceInLayer (sWelsEncCtx** ppCtx, SDqLayer* pDqLayer, CMemoryAlign* pMa, | 1106 | static inline int32_t InitSliceList (sWelsEncCtx** ppCtx, |
| 1169 | const int32_t iMaxSliceNum, const int32_t kiDlayerIndex) { | 1107 | SDqLayer* pDqLayer, |
| 1170 | int32_t iMaxSliceBufferSize = (*ppCtx)->iSliceBufferSize[kiDlayerIndex]; | 1108 | SSlice* pSliceList, |
| 1171 | int32_t iSliceIdx = 0; | 1109 | const int32_t kiMaxSliceNum, |
| 1172 | SliceModeEnum uiSliceMode = (*ppCtx)->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument.uiSliceMode; | 1110 | const int32_t kiDlayerIndex, |
| 1111 | CMemoryAlign* pMa) { | ||
| 1112 | const int32_t kiMBWidth = pDqLayer->iMbWidth; | ||
| 1113 | const int32_t kiMBHeight = pDqLayer->iMbHeight; | ||
| 1114 | SSliceArgument* pSliceArgument = & (*ppCtx)->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument; | ||
| 1115 | int32_t iMaxSliceBufferSize = (*ppCtx)->iSliceBufferSize[kiDlayerIndex]; | ||
| 1116 | int32_t iSliceIdx = 0; | ||
| 1117 | int32_t iRet = 0; | ||
| 1173 | 1118 | ||
| 1174 | //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite | 1119 | //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite |
| 1175 | //even though multi-thread is on for other layers | 1120 | //even though multi-thread is on for other layers |
| 1176 | bool bIndependenceBsBuffer = ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && | 1121 | bool bIndependenceBsBuffer = ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && |
| 1177 | SM_SINGLE_SLICE != uiSliceMode) ? true : false; | 1122 | SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false; |
| 1178 | 1123 | ||
| 1179 | if (iMaxSliceBufferSize <= 0) { | 1124 | if (iMaxSliceBufferSize <= 0 || kiMBWidth <= 0 || kiMBHeight <= 0) { |
| 1180 | return ENC_RETURN_UNEXPECTED; | 1125 | return ENC_RETURN_UNEXPECTED; |
| 1181 | } | 1126 | } |
| 1182 | 1127 | ||
| 1183 | while (iSliceIdx < iMaxSliceNum) { | 1128 | while (iSliceIdx < kiMaxSliceNum) { |
| 1184 | SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx]; | 1129 | SSlice* pSlice = pSliceList + iSliceIdx; |
| 1130 | if (NULL == pSlice) | ||
| 1131 | return ENC_RETURN_MEMALLOCERR; | ||
| 1185 | 1132 | ||
| 1186 | pSlice->uiSliceIdx = iSliceIdx; | 1133 | pSlice->uiSliceIdx = iSliceIdx; |
| 1187 | pSlice->sSliceBs.uiSize = iMaxSliceBufferSize; | ||
| 1188 | pSlice->sSliceBs.uiBsPos = 0; | ||
| 1189 | if (bIndependenceBsBuffer) { | ||
| 1190 | pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite; | ||
| 1191 | pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "SliceBs"); | ||
| 1192 | if (NULL == pSlice->sSliceBs.pBs) { | ||
| 1193 | return ENC_RETURN_MEMALLOCERR; | ||
| 1194 | } | ||
| 1195 | } else { | ||
| 1196 | pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite; | ||
| 1197 | pSlice->sSliceBs.pBs = NULL; | ||
| 1198 | } | ||
| 1199 | 1134 | ||
| 1200 | if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) { | 1135 | iRet = InitSliceBsBuffer (pSlice, |
| 1201 | FreeMemorySvc (ppCtx); | 1136 | & (*ppCtx)->pOut->sBsWrite, |
| 1202 | return ENC_RETURN_MEMALLOCERR; | 1137 | bIndependenceBsBuffer, |
| 1203 | } | 1138 | iMaxSliceBufferSize, |
| 1139 | pMa); | ||
| 1140 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1141 | return iRet; | ||
| 1142 | |||
| 1143 | iRet = InitSliceMBInfo (pSliceArgument, pSlice, | ||
| 1144 | kiMBWidth, kiMBHeight, | ||
| 1145 | pMa); | ||
| 1146 | |||
| 1147 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1148 | return iRet; | ||
| 1149 | |||
| 1150 | iRet = AllocateSliceMBBuffer (pSlice, pMa); | ||
| 1151 | |||
| 1152 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1153 | return iRet; | ||
| 1154 | |||
| 1204 | ++ iSliceIdx; | 1155 | ++ iSliceIdx; |
| 1205 | } | 1156 | } |
| 1206 | return ENC_RETURN_SUCCESS; | 1157 | return ENC_RETURN_SUCCESS; |
| 1207 | } | 1158 | } |
| 1208 | 1159 | ||
| 1160 | static inline int32_t InitSliceThreadInfo (sWelsEncCtx** ppCtx, | ||
| 1161 | SDqLayer* pDqLayer, | ||
| 1162 | const int32_t kiDlayerIndex, | ||
| 1163 | CMemoryAlign* pMa) { | ||
| 1164 | |||
| 1165 | SSliceThreadInfo* pSliceThreadInfo = &pDqLayer->sSliceThreadInfo; | ||
| 1166 | int32_t iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc; | ||
| 1167 | int32_t iMaxSliceNumInThread = 0; | ||
| 1168 | int32_t iIdx = 0; | ||
| 1169 | int32_t iRet = 0; | ||
| 1170 | |||
| 1171 | assert (iThreadNum > 0); | ||
| 1172 | iMaxSliceNumInThread = ((*ppCtx)->iMaxSliceCount / iThreadNum + 1) * 2; | ||
| 1173 | iMaxSliceNumInThread = WELS_MIN ((*ppCtx)->iMaxSliceCount, (int) iMaxSliceNumInThread); | ||
| 1174 | |||
| 1175 | while (iIdx < iThreadNum) { | ||
| 1176 | pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread; | ||
| 1177 | pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0; | ||
| 1178 | pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * | ||
| 1179 | iMaxSliceNumInThread, "pSliceInThread"); | ||
| 1180 | if(NULL == pSliceThreadInfo->pSliceInThread[iIdx]) | ||
| 1181 | return ENC_RETURN_MEMALLOCERR; | ||
| 1182 | |||
| 1183 | iRet = InitSliceList (ppCtx, | ||
| 1184 | pDqLayer, | ||
| 1185 | pSliceThreadInfo->pSliceInThread[iIdx], | ||
| 1186 | iMaxSliceNumInThread, | ||
| 1187 | kiDlayerIndex, | ||
| 1188 | pMa); | ||
| 1189 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1190 | return iRet; | ||
| 1191 | |||
| 1192 | iIdx++; | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | for (; iIdx < MAX_THREADS_NUM; iIdx++) { | ||
| 1196 | pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread; | ||
| 1197 | pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0; | ||
| 1198 | pSliceThreadInfo->pSliceInThread[iIdx] = NULL; | ||
| 1199 | } | ||
| 1200 | return ENC_RETURN_SUCCESS; | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | static inline int32_t InitSliceInLayer (sWelsEncCtx** ppCtx, | ||
| 1204 | SDqLayer* pDqLayer, | ||
| 1205 | const int32_t kiDlayerIndex, | ||
| 1206 | CMemoryAlign* pMa) { | ||
| 1207 | |||
| 1208 | //SWelsSvcCodingParam* pParam = (*ppCtx)->pSvcParam; | ||
| 1209 | int32_t iRet = 0; | ||
| 1210 | int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum; | ||
| 1211 | |||
| 1212 | //if (pParam->iMultipleThreadIdc > 1) { | ||
| 1213 | // to do, will add later, slice buffer allocated based on thread mode if() else () | ||
| 1214 | InitSliceThreadInfo (ppCtx, | ||
| 1215 | pDqLayer, | ||
| 1216 | kiDlayerIndex, | ||
| 1217 | pMa); | ||
| 1218 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1219 | return iRet; | ||
| 1220 | |||
| 1221 | //} else { | ||
| 1222 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); | ||
| 1223 | if(NULL == pDqLayer->sLayerInfo.pSliceInLayer) | ||
| 1224 | return ENC_RETURN_MEMALLOCERR; | ||
| 1225 | |||
| 1226 | InitSliceList (ppCtx, | ||
| 1227 | pDqLayer, | ||
| 1228 | pDqLayer->sLayerInfo.pSliceInLayer, | ||
| 1229 | iMaxSliceNum, | ||
| 1230 | kiDlayerIndex, | ||
| 1231 | pMa); | ||
| 1232 | if (ENC_RETURN_SUCCESS != iRet) | ||
| 1233 | return iRet; | ||
| 1234 | //} | ||
| 1235 | |||
| 1236 | return ENC_RETURN_SUCCESS; | ||
| 1237 | } | ||
| 1209 | /*! | 1238 | /*! |
| 1210 | * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available | 1239 | * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available |
| 1211 | * \pParam pCtx sWelsEncCtx* | 1240 | * \pParam pCtx sWelsEncCtx* |
| @@ -1309,12 +1338,12 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 97 unmodified lines | |||
| 1309 | if (iMaxSliceNum < kiSliceNum) | 1338 | if (iMaxSliceNum < kiSliceNum) |
| 1310 | iMaxSliceNum = kiSliceNum; | 1339 | iMaxSliceNum = kiSliceNum; |
| 1311 | pDqLayer->iMaxSliceNum = iMaxSliceNum; | 1340 | pDqLayer->iMaxSliceNum = iMaxSliceNum; |
| 1312 | { | ||
| 1313 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); | ||
| 1314 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeDqLayer (pDqLayer, pMa)) | ||
| 1315 | 1341 | ||
| 1316 | int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, iDlayerIndex); | 1342 | iResult = InitSliceInLayer (ppCtx, pDqLayer, iDlayerIndex, pMa); |
| 1317 | WELS_VERIFY_RETURN_PROC_IF (1, (ENC_RETURN_SUCCESS != iReturn), FreeDqLayer (pDqLayer, pMa)) | 1343 | if (iResult) { |
| 1344 | WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_WARNING, "InitDqLayers(), InitSliceInLayer failed(%d)!", iResult); | ||
| 1345 | FreeDqLayer (pDqLayer, pMa); | ||
| 1346 | return iResult; | ||
| 1318 | } | 1347 | } |
| 1319 | 1348 | ||
| 1320 | //deblocking parameters initialization | 1349 | //deblocking parameters initialization |
| @@ -3769,8 +3798,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2448 unmodified lines | |||
| 3769 | pCtx->iEncoderError = ENC_RETURN_SUCCESS; | 3798 | pCtx->iEncoderError = ENC_RETURN_SUCCESS; |
| 3770 | pCtx->bCurFrameMarkedAsSceneLtr = false; | 3799 | pCtx->bCurFrameMarkedAsSceneLtr = false; |
| 3771 | pFbi->iLayerNum = 0; // for initialization | 3800 | pFbi->iLayerNum = 0; // for initialization |
| 3772 | pFbi->uiTimeStamp = GetTimestampForRc (pSrcPic->uiTimeStamp, pCtx->uiLastTimestamp, | 3801 | pFbi->uiTimeStamp = GetTimestampForRc (pSrcPic->uiTimeStamp, pCtx->uiLastTimestamp, pCtx->pSvcParam->sSpatialLayers[pCtx->pSvcParam->iSpatialLayerNum - 1].fFrameRate); |
| 3773 | pCtx->pSvcParam->sSpatialLayers[pCtx->pSvcParam->iSpatialLayerNum - 1].fFrameRate); | ||
| 3774 | for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) { | 3802 | for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) { |
| 3775 | pFbi->sLayerInfo[iNalIdx].eFrameType = videoFrameTypeSkip; | 3803 | pFbi->sLayerInfo[iNalIdx].eFrameType = videoFrameTypeSkip; |
| 3776 | } | 3804 | } |