Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1005,12 +1005,11 @@ int32_t InitOneSliceInThread (sWelsEncCtx* pCtx, · 1004 unmodified lines | |||
| 1005 | const int32_t kiThreadIdx, | 1005 | const int32_t kiThreadIdx, |
| 1006 | const int32_t kiDlayerIdx, | 1006 | const int32_t kiDlayerIdx, |
| 1007 | const int32_t kiSliceIdx) { | 1007 | const int32_t kiSliceIdx) { |
| 1008 | SDqLayer* pDqLayer = pCtx->pCurDqLayer; | 1008 | const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum; |
| 1009 | const int32_t kiCodedNumInThread = pDqLayer->sSliceThreadInfo[kiThreadIdx].iCodedSliceNum; | ||
| 1010 | 1009 | ||
| 1011 | assert(kiCodedNumInThread < pDqLayer->sSliceThreadInfo[kiThreadIdx].iMaxSliceNum -1 ); | 1010 | assert(kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceThreadInfo[kiThreadIdx].iMaxSliceNum -1 ); |
| 1012 | 1011 | ||
| 1013 | pSlice = &pDqLayer->sSliceThreadInfo [kiThreadIdx].pSliceInThread[kiCodedNumInThread]; | 1012 | pSlice = &pCtx->pCurDqLayer->sSliceThreadInfo [kiThreadIdx].pSliceInThread[kiCodedNumInThread]; |
| 1014 | pSlice->iSliceIdx = kiSliceIdx; | 1013 | pSlice->iSliceIdx = kiSliceIdx; |
| 1015 | pSlice->uiThreadIdx = kiThreadIdx; | 1014 | pSlice->uiThreadIdx = kiThreadIdx; |
| 1016 | 1015 | ||
| @@ -1026,17 +1025,23 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 9 unmodified lines | |||
| 1026 | SDqLayer* pDqLayer, | 1025 | SDqLayer* pDqLayer, |
| 1027 | const int32_t kiDlayerIndex, | 1026 | const int32_t kiDlayerIndex, |
| 1028 | CMemoryAlign* pMa) { | 1027 | CMemoryAlign* pMa) { |
| 1029 | int32_t iThreadNum = pCtx->pSvcParam->iMultipleThreadIdc; | 1028 | int32_t iThreadNum = pCtx->pSvcParam->iMultipleThreadIdc; |
| 1030 | int32_t iMaxSliceNumInThread = 0; | 1029 | int32_t iMaxSliceNum = 0; |
| 1031 | int32_t iIdx = 0; | 1030 | int32_t iIdx = 0; |
| 1032 | int32_t iRet = 0; | 1031 | int32_t iRet = 0; |
| 1032 | SliceModeEnum eSlicMode = pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument.uiSliceMode; | ||
| 1033 | 1033 | ||
| 1034 | assert (iThreadNum > 0); | 1034 | assert (iThreadNum > 0); |
| 1035 | iMaxSliceNumInThread = pDqLayer->iMaxSliceNum; | 1035 | if( SM_SIZELIMITED_SLICE == eSlicMode && iThreadNum > 1) { |
| 1036 | iMaxSliceNum = pDqLayer->iMaxSliceNum / iThreadNum + 1; | ||
| 1037 | } else { | ||
| 1038 | iMaxSliceNum = pDqLayer->iMaxSliceNum; | ||
| 1039 | } | ||
| 1040 | |||
| 1036 | while (iIdx < iThreadNum) { | 1041 | while (iIdx < iThreadNum) { |
| 1037 | pDqLayer->sSliceThreadInfo[iIdx].iMaxSliceNum = iMaxSliceNumInThread; | 1042 | pDqLayer->sSliceThreadInfo[iIdx].iMaxSliceNum = iMaxSliceNum; |
| 1038 | pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0; | 1043 | pDqLayer->sSliceThreadInfo[iIdx].iCodedSliceNum = 0; |
| 1039 | pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNumInThread, "pSliceInThread"); | 1044 | pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInThread"); |
| 1040 | if (NULL == pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread) { | 1045 | if (NULL == pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread) { |
| 1041 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, | 1046 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, |
| 1042 | "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceInThread[iIdx] is NULL"); | 1047 | "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceInThread[iIdx] is NULL"); |
| @@ -1045,7 +1050,7 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 2 unmodified lines | |||
| 1045 | iRet = InitSliceList (pCtx, | 1050 | iRet = InitSliceList (pCtx, |
| 1046 | pDqLayer, | 1051 | pDqLayer, |
| 1047 | pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread, | 1052 | pDqLayer->sSliceThreadInfo[iIdx].pSliceInThread, |
| 1048 | iMaxSliceNumInThread, | 1053 | iMaxSliceNum, |
| 1049 | kiDlayerIndex, | 1054 | kiDlayerIndex, |
| 1050 | pMa); | 1055 | pMa); |
| 1051 | if (ENC_RETURN_SUCCESS != iRet) { | 1056 | if (ENC_RETURN_SUCCESS != iRet) { |
| @@ -1110,7 +1115,7 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 58 unmodified lines | |||
| 1110 | 1115 | ||
| 1111 | iStartIdx = 0; | 1116 | iStartIdx = 0; |
| 1112 | for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) { | 1117 | for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) { |
| 1113 | for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum; iSliceIdx++ ) { | 1118 | for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceThreadInfo[iThreadIdx].iMaxSliceNum; iSliceIdx++ ) { |
| 1114 | pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceThreadInfo[iThreadIdx].pSliceInThread+ iSliceIdx; | 1119 | pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceThreadInfo[iThreadIdx].pSliceInThread+ iSliceIdx; |
| 1115 | } | 1120 | } |
| 1116 | 1121 | ||
| @@ -1179,13 +1184,14 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 62 unmodified lines | |||
| 1179 | int32_t iRet = 0; | 1184 | int32_t iRet = 0; |
| 1180 | const int32_t kiCurDid = pCtx->uiDependencyId; | 1185 | const int32_t kiCurDid = pCtx->uiDependencyId; |
| 1181 | int32_t iMaxSliceBufferSize = (pCtx)->iSliceBufferSize[kiCurDid]; | 1186 | int32_t iMaxSliceBufferSize = (pCtx)->iSliceBufferSize[kiCurDid]; |
| 1182 | bool bIndependenceBsBuffer = (pCtx->pSvcParam->iMultipleThreadIdc > 1 && | ||
| 1183 | SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false; | ||
| 1184 | 1187 | ||
| 1185 | if (NULL == pSliceList || NULL == pSliceArgument) { | 1188 | if (NULL == pSliceList || NULL == pSliceArgument) { |
| 1186 | return ENC_RETURN_INVALIDINPUT; | 1189 | return ENC_RETURN_INVALIDINPUT; |
| 1187 | } | 1190 | } |
| 1188 | 1191 | ||
| 1192 | bool bIndependenceBsBuffer = (pCtx->pSvcParam->iMultipleThreadIdc > 1 && | ||
| 1193 | SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false; | ||
| 1194 | |||
| 1189 | pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "pSliceInThread"); | 1195 | pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "pSliceInThread"); |
| 1190 | if (NULL == pNewSliceList) { | 1196 | if (NULL == pNewSliceList) { |
| 1191 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocateSliceList: pNewSliceList is NULL"); | 1197 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocateSliceList: pNewSliceList is NULL"); |
| @@ -1257,24 +1263,29 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 65 unmodified lines | |||
| 1257 | return ENC_RETURN_SUCCESS; | 1263 | return ENC_RETURN_SUCCESS; |
| 1258 | } | 1264 | } |
| 1259 | 1265 | ||
| 1260 | int32_t CalculateNewSliceNum (SDqLayer* pDqLayer, | 1266 | int32_t CalculateNewSliceNum (sWelsEncCtx* pCtx, |
| 1261 | SSlice* pLastCodedSlice, | 1267 | SSlice* pLastCodedSlice, |
| 1262 | const int32_t iMaxSliceNumOld, | 1268 | const int32_t iMaxSliceNumOld, |
| 1263 | int32_t& iMaxSliceNumNew) { | 1269 | int32_t& iMaxSliceNumNew) { |
| 1264 | int32_t CodedMBNum = 0; | 1270 | if ( NULL == pCtx || NULL == pLastCodedSlice || 0 == iMaxSliceNumOld ) { |
| 1265 | |||
| 1266 | if (NULL == pLastCodedSlice) | ||
| 1267 | return ENC_RETURN_INVALIDINPUT; | 1271 | return ENC_RETURN_INVALIDINPUT; |
| 1272 | } | ||
| 1268 | 1273 | ||
| 1269 | CodedMBNum = pLastCodedSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice + | 1274 | if ( 1 == pCtx->iActiveThreadsNum ) { |
| 1270 | pLastCodedSlice->iCountMbNumInSlice; | 1275 | iMaxSliceNumNew = iMaxSliceNumOld * SLICE_NUM_EXPAND_COEF; |
| 1271 | if (CodedMBNum <= 0) { | 1276 | return ENC_RETURN_SUCCESS; |
| 1272 | return ENC_RETURN_UNEXPECTED; | ||
| 1273 | } | 1277 | } |
| 1274 | //iMaxSliceNumNew = iMaxSliceNumOld * (pDqLayer->iMbWidth * pDqLayer->iMbHeight / CodedMBNum + 1); | 1278 | |
| 1275 | //TO DO, will used above logic later, here keep origin logic in order to pass ut | 1279 | int32_t iPartitionID = pLastCodedSlice->iSliceIdx / pCtx->iActiveThreadsNum; |
| 1276 | iMaxSliceNumNew = iMaxSliceNumOld; | 1280 | int32_t iMBNumInPatition = pCtx->pCurDqLayer->EndMbIdxOfPartition[iPartitionID] |
| 1277 | iMaxSliceNumNew *= SLICE_NUM_EXPAND_COEF; | 1281 | - pCtx->pCurDqLayer->FirstMbIdxOfPartition[iPartitionID] + 1; |
| 1282 | int32_t iLeftMBNum = pCtx->pCurDqLayer->EndMbIdxOfPartition[iPartitionID] | ||
| 1283 | - pCtx->pCurDqLayer->LastCodedMbIdxOfPartition[iPartitionID] + 1; | ||
| 1284 | int32_t iIncreaseSlicNum = (iLeftMBNum * INT_MULTIPLY / iMBNumInPatition) * iMaxSliceNumOld; | ||
| 1285 | |||
| 1286 | iIncreaseSlicNum = ( 0 == (iIncreaseSlicNum / INT_MULTIPLY) ) ? 1 : (iIncreaseSlicNum / INT_MULTIPLY); | ||
| 1287 | iMaxSliceNumNew = iMaxSliceNumOld + iIncreaseSlicNum; | ||
| 1288 | |||
| 1278 | return ENC_RETURN_SUCCESS; | 1289 | return ENC_RETURN_SUCCESS; |
| 1279 | } | 1290 | } |
| 1280 | 1291 | ||
| @@ -1282,18 +1293,16 @@ int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx, · 1 unmodified line | |||
| 1282 | SDqLayer* pDqLayer, | 1293 | SDqLayer* pDqLayer, |
| 1283 | const int32_t kiDlayerIdx, | 1294 | const int32_t kiDlayerIdx, |
| 1284 | const int32_t kiThreadIndex) { | 1295 | const int32_t kiThreadIndex) { |
| 1285 | 1296 | int32_t iMaxSliceNum = pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum; | |
| 1286 | int32_t iMaxSliceNumInThread = pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum; | 1297 | int32_t iMaxSliceNumNew = 0; |
| 1287 | int32_t iMaxSliceNumUpdate = 0; | 1298 | int32_t iRet = 0; |
| 1288 | int32_t iRet = 0; | 1299 | SSlice* pLastCodedSlice = &pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread [iMaxSliceNum - 1]; |
| 1289 | SSlice* pLastCodedSlice = pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread + (iMaxSliceNumInThread - 1); | ||
| 1290 | SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument; | 1300 | SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument; |
| 1291 | 1301 | ||
| 1292 | iRet = CalculateNewSliceNum (pDqLayer, | 1302 | iRet = CalculateNewSliceNum (pCtx, |
| 1293 | pLastCodedSlice, | 1303 | pLastCodedSlice, |
| 1294 | iMaxSliceNumInThread, | 1304 | iMaxSliceNum, |
| 1295 | iMaxSliceNumUpdate); | 1305 | iMaxSliceNumNew); |
| 1296 | |||
| 1297 | if (ENC_RETURN_SUCCESS != iRet) { | 1306 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1298 | return iRet; | 1307 | return iRet; |
| 1299 | } | 1308 | } |
| @@ -1301,13 +1310,13 @@ int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx, · 1 unmodified line | |||
| 1301 | iRet = ReallocateSliceList (pCtx, | 1310 | iRet = ReallocateSliceList (pCtx, |
| 1302 | pSliceArgument, | 1311 | pSliceArgument, |
| 1303 | pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread, | 1312 | pDqLayer->sSliceThreadInfo[kiThreadIndex].pSliceInThread, |
| 1304 | iMaxSliceNumInThread, | 1313 | iMaxSliceNum, |
| 1305 | iMaxSliceNumUpdate); | 1314 | iMaxSliceNumNew); |
| 1306 | if (ENC_RETURN_SUCCESS != iRet) { | 1315 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1307 | return iRet; | 1316 | return iRet; |
| 1308 | } | 1317 | } |
| 1309 | 1318 | ||
| 1310 | pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum = iMaxSliceNumUpdate; | 1319 | pDqLayer->sSliceThreadInfo[kiThreadIndex].iMaxSliceNum = iMaxSliceNumNew; |
| 1311 | 1320 | ||
| 1312 | return ENC_RETURN_SUCCESS; | 1321 | return ENC_RETURN_SUCCESS; |
| 1313 | } | 1322 | } |
| @@ -1367,7 +1376,7 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 53 unmodified lines | |||
| 1367 | const int32_t kiCurDid = pCtx->uiDependencyId; | 1376 | const int32_t kiCurDid = pCtx->uiDependencyId; |
| 1368 | SSlice* pLastCodedSlice = pCurLayer->sSliceThreadInfo[0].pSliceInThread + (iMaxSliceNumOld - 1); | 1377 | SSlice* pLastCodedSlice = pCurLayer->sSliceThreadInfo[0].pSliceInThread + (iMaxSliceNumOld - 1); |
| 1369 | SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument; | 1378 | SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument; |
| 1370 | iRet = CalculateNewSliceNum (pCurLayer, | 1379 | iRet = CalculateNewSliceNum (pCtx, |
| 1371 | pLastCodedSlice, | 1380 | pLastCodedSlice, |
| 1372 | iMaxSliceNumOld, | 1381 | iMaxSliceNumOld, |
| 1373 | iMaxSliceNumNew); | 1382 | iMaxSliceNumNew); |
| @@ -1705,8 +1714,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 331 unmodified lines | |||
| 1705 | const int32_t kiActiveThreadsNum = pEncCtx->iActiveThreadsNum; | 1714 | const int32_t kiActiveThreadsNum = pEncCtx->iActiveThreadsNum; |
| 1706 | const int32_t kiPartitaionId = pCurSlice->iSliceIdx % kiActiveThreadsNum; | 1715 | const int32_t kiPartitaionId = pCurSlice->iSliceIdx % kiActiveThreadsNum; |
| 1707 | const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->EndMbIdxOfPartition[kiPartitaionId]; | 1716 | const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->EndMbIdxOfPartition[kiPartitaionId]; |
| 1708 | const int32_t kiMaxSliceNum = pEncCtx->pCurDqLayer->sSliceThreadInfo[pCurSlice->uiThreadIdx].iMaxSliceNum; | 1717 | const bool kbCurMbNotFirstMbOfCurSlice = ((iCurMbIdx > 0) && (pSliceCtx->pOverallMbMap[iCurMbIdx] == |
| 1709 | const bool kbCurMbNotFirstMbOfCurSlice = ((iCurMbIdx > 0) && (pSliceCtx->pOverallMbMap[iCurMbIdx] == | ||
| 1710 | pSliceCtx->pOverallMbMap[iCurMbIdx - 1])); | 1718 | pSliceCtx->pOverallMbMap[iCurMbIdx - 1])); |
| 1711 | const bool kbCurMbNotLastMbOfCurPartition = iCurMbIdx < kiEndMbIdxOfPartition; | 1719 | const bool kbCurMbNotLastMbOfCurPartition = iCurMbIdx < kiEndMbIdxOfPartition; |
| 1712 | 1720 | ||