Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 15 files). Show all
Unified · Split
| @@ -827,7 +827,7 @@ int32_t InitSliceBoundaryInfo (SDqLayer* pCurLayer, · 826 unmodified lines | ||
| 827 | 827 | int32_t iFirstMBInSlice = 0; |
| 828 | 828 | int32_t iMbNumInSlice = 0; |
| 829 | 829 | |
| 830 | − for( ;iSliceIdx < kiSliceNumInFrame; iSliceIdx++ ){ | |
| 830 | + for (; iSliceIdx < kiSliceNumInFrame; iSliceIdx++) { | |
| 831 | 831 | if (SM_SINGLE_SLICE == pSliceArgument->uiSliceMode) { |
| 832 | 832 | iFirstMBInSlice = 0; |
| 833 | 833 | iMbNumInSlice = kiCountNumMbInFrame; |
| @@ -836,7 +836,7 @@ int32_t InitSliceBoundaryInfo (SDqLayer* pCurLayer, · 2 unmodified lines | ||
| 836 | 836 | iFirstMBInSlice = iSliceIdx * kiMBWidth; |
| 837 | 837 | iMbNumInSlice = kiMBWidth; |
| 838 | 838 | } else if (SM_RASTER_SLICE == pSliceArgument->uiSliceMode || |
| 839 | − SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode) { | |
| 839 | + SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode) { | |
| 840 | 840 | int32_t iMbIdx = 0; |
| 841 | 841 | for (int i = 0; i < iSliceIdx; i++) { |
| 842 | 842 | iMbIdx += kpSlicesAssignList[i]; |
| @@ -864,10 +864,10 @@ int32_t InitSliceBoundaryInfo (SDqLayer* pCurLayer, · 21 unmodified lines | ||
| 864 | 864 | return ENC_RETURN_SUCCESS; |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | −int32_t SetSliceBoundaryInfo(SDqLayer* pCurLayer, SSlice* pSlice, const int32_t kiSliceIdx) { | |
| 868 | − if(NULL == pCurLayer || NULL == pSlice || | |
| 869 | − NULL == pCurLayer->pFirstMbIdxOfSlice || | |
| 870 | − NULL == pCurLayer->pCountMbNumInSlice) { | |
| 867 | +int32_t SetSliceBoundaryInfo (SDqLayer* pCurLayer, SSlice* pSlice, const int32_t kiSliceIdx) { | |
| 868 | + if (NULL == pCurLayer || NULL == pSlice || | |
| 869 | + NULL == pCurLayer->pFirstMbIdxOfSlice || | |
| 870 | + NULL == pCurLayer->pCountMbNumInSlice) { | |
| 871 | 871 | |
| 872 | 872 | return ENC_RETURN_UNEXPECTED; |
| 873 | 873 | } |
| @@ -977,15 +977,15 @@ int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx) { · 103 unmodified lines | ||
| 977 | 977 | int32_t iSliceIdx = 0; |
| 978 | 978 | int32_t iSlcBuffIdx = 0; |
| 979 | 979 | |
| 980 | − for( ; iSliceIdx < pCurDqLayer->iMaxSliceNum; iSliceIdx++) { | |
| 981 | − if(NULL == pCurDqLayer->ppSliceInLayer[iSliceIdx]) { | |
| 980 | + for (; iSliceIdx < pCurDqLayer->iMaxSliceNum; iSliceIdx++) { | |
| 981 | + if (NULL == pCurDqLayer->ppSliceInLayer[iSliceIdx]) { | |
| 982 | 982 | return ENC_RETURN_UNEXPECTED; |
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | pCurDqLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx = -1; |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | − for( ; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) { | |
| 988 | + for (; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 989 | 989 | pCurDqLayer->sSliceBufferInfo[iSlcBuffIdx].iCodedSliceNum = 0; |
| 990 | 990 | } |
| 991 | 991 | |
| @@ -999,11 +999,11 @@ int32_t InitOneSliceInThread (sWelsEncCtx* pCtx, · 7 unmodified lines | ||
| 999 | 999 | const int32_t kiSliceIdx) { |
| 1000 | 1000 | |
| 1001 | 1001 | if (pCtx->pCurDqLayer->bThreadSlcBufferFlag) { |
| 1002 | − const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iCodedSliceNum; | |
| 1003 | − assert(kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iMaxSliceNum -1 ); | |
| 1004 | − pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [kiSlcBuffIdx].pSliceBuffer[kiCodedNumInThread]; | |
| 1002 | + const int32_t kiCodedNumInThread = pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iCodedSliceNum; | |
| 1003 | + assert (kiCodedNumInThread <= pCtx->pCurDqLayer->sSliceBufferInfo[kiSlcBuffIdx].iMaxSliceNum - 1); | |
| 1004 | + pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [kiSlcBuffIdx].pSliceBuffer[kiCodedNumInThread]; | |
| 1005 | 1005 | } else { |
| 1006 | − pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [0].pSliceBuffer[kiSliceIdx]; | |
| 1006 | + pSlice = &pCtx->pCurDqLayer->sSliceBufferInfo [0].pSliceBuffer[kiSliceIdx]; | |
| 1007 | 1007 | } |
| 1008 | 1008 | pSlice->iSliceIdx = kiSliceIdx; |
| 1009 | 1009 | pSlice->uiBufferIdx = kiSlcBuffIdx; |
| @@ -1029,7 +1029,7 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 19 unmodified lines | ||
| 1029 | 1029 | assert (iThreadNum > 0); |
| 1030 | 1030 | |
| 1031 | 1031 | //for fixed slice num case, no need to reallocate, so one slice buffer for all thread |
| 1032 | − if( pDqLayer->bThreadSlcBufferFlag) { | |
| 1032 | + if (pDqLayer->bThreadSlcBufferFlag) { | |
| 1033 | 1033 | iMaxSliceNum = pDqLayer->iMaxSliceNum / iThreadNum + 1; |
| 1034 | 1034 | iSlcBufferNum = iThreadNum; |
| 1035 | 1035 | } else { |
| @@ -1040,7 +1040,8 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 4 unmodified lines | ||
| 1040 | 1040 | while (iIdx < iSlcBufferNum) { |
| 1041 | 1041 | pDqLayer->sSliceBufferInfo[iIdx].iMaxSliceNum = iMaxSliceNum; |
| 1042 | 1042 | pDqLayer->sSliceBufferInfo[iIdx].iCodedSliceNum = 0; |
| 1043 | − pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceBuffer"); | |
| 1043 | + pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, | |
| 1044 | + "pSliceBuffer"); | |
| 1044 | 1045 | if (NULL == pDqLayer->sSliceBufferInfo[iIdx].pSliceBuffer) { |
| 1045 | 1046 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, |
| 1046 | 1047 | "CWelsH264SVCEncoder::InitSliceThreadInfo: pSliceThreadInfo->pSliceBuffer[iIdx] is NULL"); |
| @@ -1081,21 +1082,21 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 34 unmodified lines | ||
| 1081 | 1082 | //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite |
| 1082 | 1083 | //even though multi-thread is on for other layers |
| 1083 | 1084 | pDqLayer->bSliceBsBufferFlag = (pCtx->pSvcParam->iMultipleThreadIdc > 1 && |
| 1084 | − SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false; | |
| 1085 | + SM_SINGLE_SLICE != pSliceArgument->uiSliceMode) ? true : false; | |
| 1085 | 1086 | |
| 1086 | 1087 | pDqLayer->bThreadSlcBufferFlag = (pCtx->pSvcParam->iMultipleThreadIdc > 1 && |
| 1087 | − SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? true : false; | |
| 1088 | + SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? true : false; | |
| 1088 | 1089 | |
| 1089 | 1090 | iRet = InitSliceThreadInfo (pCtx, |
| 1090 | − pDqLayer, | |
| 1091 | − kiDlayerIndex, | |
| 1092 | − pMa); | |
| 1091 | + pDqLayer, | |
| 1092 | + kiDlayerIndex, | |
| 1093 | + pMa); | |
| 1093 | 1094 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1094 | 1095 | return ENC_RETURN_MEMALLOCERR; |
| 1095 | 1096 | } |
| 1096 | 1097 | |
| 1097 | 1098 | pDqLayer->iMaxSliceNum = 0; |
| 1098 | − for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) { | |
| 1099 | + for (iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1099 | 1100 | pDqLayer->iMaxSliceNum += pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; |
| 1100 | 1101 | } |
| 1101 | 1102 | |
| @@ -1105,15 +1106,19 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 3 unmodified lines | ||
| 1105 | 1106 | return ENC_RETURN_MEMALLOCERR; |
| 1106 | 1107 | } |
| 1107 | 1108 | |
| 1108 | − pDqLayer->pFirstMbIdxOfSlice = (int32_t*)pMa->WelsMallocz (sizeof (int32_t*) * pDqLayer->iMaxSliceNum, "pFirstMbIdxOfSlice"); | |
| 1109 | + pDqLayer->pFirstMbIdxOfSlice = (int32_t*)pMa->WelsMallocz (sizeof (int32_t*) * pDqLayer->iMaxSliceNum, | |
| 1110 | + "pFirstMbIdxOfSlice"); | |
| 1109 | 1111 | if (NULL == pDqLayer->pFirstMbIdxOfSlice) { |
| 1110 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitSliceInLayer() pDqLayer->pFirstMbIdxOfSlice is NULL"); | |
| 1112 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, | |
| 1113 | + "CWelsH264SVCEncoder::InitSliceInLayer() pDqLayer->pFirstMbIdxOfSlice is NULL"); | |
| 1111 | 1114 | return ENC_RETURN_MEMALLOCERR; |
| 1112 | 1115 | } |
| 1113 | 1116 | |
| 1114 | − pDqLayer->pCountMbNumInSlice = (int32_t*)pMa->WelsMallocz (sizeof (int32_t*) * pDqLayer->iMaxSliceNum, "pCountMbNumInSlice"); | |
| 1117 | + pDqLayer->pCountMbNumInSlice = (int32_t*)pMa->WelsMallocz (sizeof (int32_t*) * pDqLayer->iMaxSliceNum, | |
| 1118 | + "pCountMbNumInSlice"); | |
| 1115 | 1119 | if (NULL == pDqLayer->pCountMbNumInSlice) { |
| 1116 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitSliceInLayer() pDqLayer->pCountMbNumInSlice is NULL"); | |
| 1120 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, | |
| 1121 | + "CWelsH264SVCEncoder::InitSliceInLayer() pDqLayer->pCountMbNumInSlice is NULL"); | |
| 1117 | 1122 | return ENC_RETURN_MEMALLOCERR; |
| 1118 | 1123 | } |
| 1119 | 1124 | |
| @@ -1123,9 +1128,9 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 3 unmodified lines | ||
| 1123 | 1128 | } |
| 1124 | 1129 | |
| 1125 | 1130 | iStartIdx = 0; |
| 1126 | − for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) { | |
| 1127 | − for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; iSliceIdx++ ) { | |
| 1128 | − pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer+ iSliceIdx; | |
| 1131 | + for (iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1132 | + for (iSliceIdx = 0; iSliceIdx < pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; iSliceIdx++) { | |
| 1133 | + pDqLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pDqLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx; | |
| 1129 | 1134 | } |
| 1130 | 1135 | |
| 1131 | 1136 | iStartIdx += pDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; |
| @@ -1135,7 +1140,7 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 3 unmodified lines | ||
| 1135 | 1140 | } |
| 1136 | 1141 | |
| 1137 | 1142 | void InitSliceHeadWithBase (SSlice* pSlice, SSlice* pBaseSlice) { |
| 1138 | − if(NULL == pSlice || NULL == pBaseSlice) { | |
| 1143 | + if (NULL == pSlice || NULL == pBaseSlice) { | |
| 1139 | 1144 | return; |
| 1140 | 1145 | } |
| 1141 | 1146 | |
| @@ -1150,7 +1155,7 @@ void InitSliceHeadWithBase (SSlice* pSlice, SSlice* pBaseSlice) { · 8 unmodified lines | ||
| 1150 | 1155 | } |
| 1151 | 1156 | |
| 1152 | 1157 | void InitSliceRefInfoWithBase (SSlice* pSlice, SSlice* pBaseSlice, const uint8_t kuiRefCount) { |
| 1153 | − if( NULL == pSlice || NULL == pBaseSlice) { | |
| 1158 | + if (NULL == pSlice || NULL == pBaseSlice) { | |
| 1154 | 1159 | return; |
| 1155 | 1160 | } |
| 1156 | 1161 | |
| @@ -1213,7 +1218,7 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 56 unmodified lines | ||
| 1213 | 1218 | for (iSliceIdx = 0; iSliceIdx < kiMaxSliceNumOld; iSliceIdx++) { |
| 1214 | 1219 | pSlice = pNewSliceList + iSliceIdx; |
| 1215 | 1220 | if (NULL == pSlice) { |
| 1216 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1221 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1217 | 1222 | return ENC_RETURN_MEMALLOCERR; |
| 1218 | 1223 | } |
| 1219 | 1224 | |
| @@ -1224,14 +1229,14 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 4 unmodified lines | ||
| 1224 | 1229 | |
| 1225 | 1230 | pBaseSlice = &pSliceList[0]; |
| 1226 | 1231 | if (NULL == pBaseSlice) { |
| 1227 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()"); | |
| 1232 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()"); | |
| 1228 | 1233 | return ENC_RETURN_MEMALLOCERR; |
| 1229 | 1234 | } |
| 1230 | 1235 | |
| 1231 | 1236 | for (iSliceIdx = kiMaxSliceNumOld; iSliceIdx < kiMaxSliceNumNew; iSliceIdx++) { |
| 1232 | 1237 | pSlice = pNewSliceList + iSliceIdx; |
| 1233 | 1238 | if (NULL == pSlice) { |
| 1234 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1239 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1235 | 1240 | return ENC_RETURN_MEMALLOCERR; |
| 1236 | 1241 | } |
| 1237 | 1242 | |
| @@ -1246,13 +1251,13 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 8 unmodified lines | ||
| 1246 | 1251 | iMaxSliceBufferSize, |
| 1247 | 1252 | pMA); |
| 1248 | 1253 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1249 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1254 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1250 | 1255 | return iRet; |
| 1251 | 1256 | } |
| 1252 | 1257 | |
| 1253 | 1258 | iRet = AllocateSliceMBBuffer (pSlice, pMA); |
| 1254 | 1259 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1255 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1260 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1256 | 1261 | return iRet; |
| 1257 | 1262 | } |
| 1258 | 1263 | |
| @@ -1261,7 +1266,7 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 2 unmodified lines | ||
| 1261 | 1266 | |
| 1262 | 1267 | iRet = InitSliceRC (pSlice, pCtx->iGlobalQp); |
| 1263 | 1268 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1264 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1269 | + FreeSliceBuffer (pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceBuffer"); | |
| 1265 | 1270 | return iRet; |
| 1266 | 1271 | } |
| 1267 | 1272 | } |
| @@ -1276,11 +1281,11 @@ int32_t CalculateNewSliceNum (sWelsEncCtx* pCtx, · 8 unmodified lines | ||
| 1276 | 1281 | SSlice* pLastCodedSlice, |
| 1277 | 1282 | const int32_t iMaxSliceNumOld, |
| 1278 | 1283 | int32_t& iMaxSliceNumNew) { |
| 1279 | − if ( NULL == pCtx || NULL == pLastCodedSlice || 0 == iMaxSliceNumOld ) { | |
| 1284 | + if (NULL == pCtx || NULL == pLastCodedSlice || 0 == iMaxSliceNumOld) { | |
| 1280 | 1285 | return ENC_RETURN_INVALIDINPUT; |
| 1281 | 1286 | } |
| 1282 | 1287 | |
| 1283 | − if ( 1 == pCtx->iActiveThreadsNum ) { | |
| 1288 | + if (1 == pCtx->iActiveThreadsNum) { | |
| 1284 | 1289 | iMaxSliceNumNew = iMaxSliceNumOld * SLICE_NUM_EXPAND_COEF; |
| 1285 | 1290 | return ENC_RETURN_SUCCESS; |
| 1286 | 1291 | } |
| @@ -1292,7 +1297,7 @@ int32_t CalculateNewSliceNum (sWelsEncCtx* pCtx, · 5 unmodified lines | ||
| 1292 | 1297 | - pCtx->pCurDqLayer->LastCodedMbIdxOfPartition[iPartitionID] + 1; |
| 1293 | 1298 | int32_t iIncreaseSlicNum = (iLeftMBNum * INT_MULTIPLY / iMBNumInPatition) * iMaxSliceNumOld; |
| 1294 | 1299 | |
| 1295 | − iIncreaseSlicNum = ( 0 == (iIncreaseSlicNum / INT_MULTIPLY) ) ? 1 : (iIncreaseSlicNum / INT_MULTIPLY); | |
| 1300 | + iIncreaseSlicNum = (0 == (iIncreaseSlicNum / INT_MULTIPLY)) ? 1 : (iIncreaseSlicNum / INT_MULTIPLY); | |
| 1296 | 1301 | iIncreaseSlicNum = (iIncreaseSlicNum < iMaxSliceNumOld / 2) ? (iMaxSliceNumOld / 2) : iIncreaseSlicNum; |
| 1297 | 1302 | iMaxSliceNumNew = iMaxSliceNumOld + iIncreaseSlicNum; |
| 1298 | 1303 | |
| @@ -1332,9 +1337,9 @@ int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx, · 33 unmodified lines | ||
| 1332 | 1337 | return ENC_RETURN_SUCCESS; |
| 1333 | 1338 | } |
| 1334 | 1339 | |
| 1335 | −int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx, | |
| 1336 | − const int32_t kiMaxSliceNumOld, | |
| 1337 | − const int32_t kiMaxSliceNumNew){ | |
| 1340 | +int32_t ExtendLayerBuffer (sWelsEncCtx* pCtx, | |
| 1341 | + const int32_t kiMaxSliceNumOld, | |
| 1342 | + const int32_t kiMaxSliceNumNew) { | |
| 1338 | 1343 | CMemoryAlign* pMA = pCtx->pMemAlign; |
| 1339 | 1344 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 1340 | 1345 | SSlice** ppSlice = NULL; |
| @@ -1356,7 +1361,7 @@ int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx, · 15 unmodified lines | ||
| 1356 | 1361 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pFirstMbIdxOfSlice is NULL"); |
| 1357 | 1362 | return ENC_RETURN_MEMALLOCERR; |
| 1358 | 1363 | } |
| 1359 | − memset (pFirstMbIdxOfSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew); | |
| 1364 | + memset (pFirstMbIdxOfSlice, 0, sizeof (int32_t) * kiMaxSliceNumNew); | |
| 1360 | 1365 | memcpy (pFirstMbIdxOfSlice, pCurLayer->pFirstMbIdxOfSlice, sizeof (int32_t) * kiMaxSliceNumOld); |
| 1361 | 1366 | pMA->WelsFree (pCurLayer->pFirstMbIdxOfSlice, "pFirstMbIdxOfSlice"); |
| 1362 | 1367 | pCurLayer->pFirstMbIdxOfSlice = pFirstMbIdxOfSlice; |
| @@ -1367,7 +1372,7 @@ int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx, · 4 unmodified lines | ||
| 1367 | 1372 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pCountMbNumInSlice is NULL"); |
| 1368 | 1373 | return ENC_RETURN_MEMALLOCERR; |
| 1369 | 1374 | } |
| 1370 | − memset (pCountMbNumInSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew); | |
| 1375 | + memset (pCountMbNumInSlice, 0, sizeof (int32_t) * kiMaxSliceNumNew); | |
| 1371 | 1376 | memcpy (pCountMbNumInSlice, pCurLayer->pCountMbNumInSlice, sizeof (int32_t) * kiMaxSliceNumOld); |
| 1372 | 1377 | pMA->WelsFree (pCurLayer->pCountMbNumInSlice, "pCountMbNumInSlice"); |
| 1373 | 1378 | pCurLayer->pCountMbNumInSlice = pCountMbNumInSlice; |
| @@ -1408,16 +1413,16 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 34 unmodified lines | ||
| 1408 | 1413 | pCurLayer->sSliceBufferInfo[0].iMaxSliceNum = iMaxSliceNumNew; |
| 1409 | 1414 | |
| 1410 | 1415 | iMaxSliceNumNew = 0; |
| 1411 | − for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) { | |
| 1412 | − iMaxSliceNumNew += pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; | |
| 1416 | + for (iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1417 | + iMaxSliceNumNew += pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; | |
| 1413 | 1418 | } |
| 1414 | 1419 | |
| 1415 | − iRet = ExtendLayerBuffer(pCtx, pCurLayer->iMaxSliceNum, iMaxSliceNumNew); | |
| 1420 | + iRet = ExtendLayerBuffer (pCtx, pCurLayer->iMaxSliceNum, iMaxSliceNumNew); | |
| 1416 | 1421 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1417 | 1422 | return iRet; |
| 1418 | 1423 | } |
| 1419 | 1424 | |
| 1420 | − for(iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++ ) { | |
| 1425 | + for (iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1421 | 1426 | for (iSliceIdx = 0; iSliceIdx < pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; iSliceIdx++) { |
| 1422 | 1427 | pCurLayer->ppSliceInLayer[iStartIdx + iSliceIdx] = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx; |
| 1423 | 1428 | } |
| @@ -1429,14 +1434,14 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 5 unmodified lines | ||
| 1429 | 1434 | return ENC_RETURN_SUCCESS; |
| 1430 | 1435 | } |
| 1431 | 1436 | |
| 1432 | −static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiCodedSliceNum) { | |
| 1437 | +static inline int32_t CheckAllSliceBuffer (SDqLayer* pCurLayer, const int32_t kiCodedSliceNum) { | |
| 1433 | 1438 | int32_t iSliceIdx = 0; |
| 1434 | − for(; iSliceIdx <kiCodedSliceNum ; iSliceIdx ++ ) { | |
| 1435 | − if ( NULL == pCurLayer->ppSliceInLayer[iSliceIdx]) { | |
| 1439 | + for (; iSliceIdx < kiCodedSliceNum ; iSliceIdx ++) { | |
| 1440 | + if (NULL == pCurLayer->ppSliceInLayer[iSliceIdx]) { | |
| 1436 | 1441 | return ENC_RETURN_UNEXPECTED; |
| 1437 | 1442 | } |
| 1438 | 1443 | |
| 1439 | − if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) { | |
| 1444 | + if (iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) { | |
| 1440 | 1445 | return ENC_RETURN_UNEXPECTED; |
| 1441 | 1446 | } |
| 1442 | 1447 | } |
| @@ -1464,16 +1469,16 @@ int32_t ReOrderSliceInLayer (sWelsEncCtx* pCtx, · 21 unmodified lines | ||
| 1464 | 1469 | |
| 1465 | 1470 | //for non-dynamic slice mode, iPartitionNum = 1, iPartitionOffset = 0 |
| 1466 | 1471 | iPartitionNum = (SM_SIZELIMITED_SLICE == kuiSliceMode) ? kiThreadNum : 1; |
| 1467 | − for(iPartitionIdx = 0; iPartitionIdx < iPartitionNum; iPartitionIdx++) { | |
| 1472 | + for (iPartitionIdx = 0; iPartitionIdx < iPartitionNum; iPartitionIdx++) { | |
| 1468 | 1473 | aiPartitionOffset[iPartitionIdx] = iEncodeSliceNum; |
| 1469 | − if ( SM_SIZELIMITED_SLICE == kuiSliceMode) { | |
| 1474 | + if (SM_SIZELIMITED_SLICE == kuiSliceMode) { | |
| 1470 | 1475 | iEncodeSliceNum += pCurLayer->NumSliceCodedOfPartition[iPartitionIdx]; |
| 1471 | 1476 | } else { |
| 1472 | 1477 | iEncodeSliceNum = pCurLayer->sSliceEncCtx.iSliceNumInFrame; |
| 1473 | 1478 | } |
| 1474 | 1479 | } |
| 1475 | 1480 | |
| 1476 | − if( iEncodeSliceNum != pCurLayer->sSliceEncCtx.iSliceNumInFrame) { | |
| 1481 | + if (iEncodeSliceNum != pCurLayer->sSliceEncCtx.iSliceNumInFrame) { | |
| 1477 | 1482 | return ENC_RETURN_UNEXPECTED; |
| 1478 | 1483 | } |
| 1479 | 1484 | |
| @@ -1482,42 +1487,42 @@ int32_t ReOrderSliceInLayer (sWelsEncCtx* pCtx, · 2 unmodified lines | ||
| 1482 | 1487 | for (iSlcBuffIdx = 0; iSlcBuffIdx < kiThreadNum; iSlcBuffIdx++) { |
| 1483 | 1488 | iSliceNumInThread = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; |
| 1484 | 1489 | |
| 1485 | − for(iSliceIdx =0; iSliceIdx < iSliceNumInThread; iSliceIdx++) { | |
| 1490 | + for (iSliceIdx = 0; iSliceIdx < iSliceNumInThread; iSliceIdx++) { | |
| 1486 | 1491 | pSliceBuffer = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx; |
| 1487 | 1492 | if (NULL == pSliceBuffer) { |
| 1488 | 1493 | return ENC_RETURN_UNEXPECTED; |
| 1489 | 1494 | } |
| 1490 | 1495 | |
| 1491 | − if( -1 != pSliceBuffer->iSliceIdx) { | |
| 1496 | + if (-1 != pSliceBuffer->iSliceIdx) { | |
| 1492 | 1497 | iPartitionID = pSliceBuffer->iSliceIdx % iPartitionNum; |
| 1493 | 1498 | iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceBuffer->iSliceIdx / iPartitionNum; |
| 1494 | 1499 | pSliceBuffer->iSliceIdx = iActualSliceIdx; |
| 1495 | 1500 | pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceBuffer; |
| 1496 | 1501 | iUsedSliceNum ++; |
| 1497 | 1502 | } else { |
| 1498 | − pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceBuffer; | |
| 1499 | − iNonUsedBufferNum ++; | |
| 1503 | + pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceBuffer; | |
| 1504 | + iNonUsedBufferNum ++; | |
| 1500 | 1505 | } |
| 1501 | 1506 | } |
| 1502 | 1507 | } |
| 1503 | 1508 | |
| 1504 | − if( iUsedSliceNum != iEncodeSliceNum || | |
| 1505 | − pCurLayer->iMaxSliceNum != (iNonUsedBufferNum + iUsedSliceNum)) { | |
| 1509 | + if (iUsedSliceNum != iEncodeSliceNum || | |
| 1510 | + pCurLayer->iMaxSliceNum != (iNonUsedBufferNum + iUsedSliceNum)) { | |
| 1506 | 1511 | return ENC_RETURN_UNEXPECTED; |
| 1507 | 1512 | } |
| 1508 | 1513 | |
| 1509 | − if (ENC_RETURN_SUCCESS != CheckAllSliceBuffer(pCurLayer, iEncodeSliceNum)) { | |
| 1514 | + if (ENC_RETURN_SUCCESS != CheckAllSliceBuffer (pCurLayer, iEncodeSliceNum)) { | |
| 1510 | 1515 | return ENC_RETURN_UNEXPECTED; |
| 1511 | 1516 | } |
| 1512 | 1517 | |
| 1513 | 1518 | return ENC_RETURN_SUCCESS; |
| 1514 | 1519 | } |
| 1515 | 1520 | |
| 1516 | −int32_t GetCurLayerNalCount(const SDqLayer* pCurDq, const int32_t kiCodedSliceNum) { | |
| 1521 | +int32_t GetCurLayerNalCount (const SDqLayer* pCurDq, const int32_t kiCodedSliceNum) { | |
| 1517 | 1522 | int32_t iTotalNalCount = 0; |
| 1518 | 1523 | int32_t iSliceIdx = 0; |
| 1519 | 1524 | SWelsSliceBs* pSliceBs = NULL; |
| 1520 | − for ( ; iSliceIdx < kiCodedSliceNum; iSliceIdx++ ) { | |
| 1525 | + for (; iSliceIdx < kiCodedSliceNum; iSliceIdx++) { | |
| 1521 | 1526 | pSliceBs = &pCurDq->ppSliceInLayer[iSliceIdx]->sSliceBs; |
| 1522 | 1527 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 1523 | 1528 | iTotalNalCount += pSliceBs->iNalIndex; |
| @@ -1527,7 +1532,7 @@ int32_t GetCurLayerNalCount(const SDqLayer* pCurDq, const int32_t kiCodedSliceNu · 3 unmodified lines | ||
| 1527 | 1532 | return iTotalNalCount; |
| 1528 | 1533 | } |
| 1529 | 1534 | |
| 1530 | −int32_t GetTotalCodedNalCount(SFrameBSInfo* pFbi) { | |
| 1535 | +int32_t GetTotalCodedNalCount (SFrameBSInfo* pFbi) { | |
| 1531 | 1536 | int32_t iTotalCodedNalCount = 0; |
| 1532 | 1537 | for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) { |
| 1533 | 1538 | iTotalCodedNalCount += pFbi->sLayerInfo[iNalIdx].iNalCount; |
| @@ -1584,13 +1589,13 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, · 50 unmodified lines | ||
| 1584 | 1589 | int32_t iCodedNalCount = 0; |
| 1585 | 1590 | int32_t iRet = 0; |
| 1586 | 1591 | |
| 1587 | − for ( int32_t iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1592 | + for (int32_t iSlcBuffIdx = 0; iSlcBuffIdx < pCtx->iActiveThreadsNum; iSlcBuffIdx++) { | |
| 1588 | 1593 | iMaxSliceNum += pCtx->pCurDqLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; |
| 1589 | 1594 | } |
| 1590 | 1595 | |
| 1591 | 1596 | //reallocate ppSliceInLayer if total encoded slice num exceed max slice num |
| 1592 | 1597 | if (iMaxSliceNum > pCtx->pCurDqLayer->iMaxSliceNum) { |
| 1593 | − iRet = ExtendLayerBuffer(pCtx, pCtx->pCurDqLayer->iMaxSliceNum, iMaxSliceNum); | |
| 1598 | + iRet = ExtendLayerBuffer (pCtx, pCtx->pCurDqLayer->iMaxSliceNum, iMaxSliceNum); | |
| 1594 | 1599 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1595 | 1600 | return iRet; |
| 1596 | 1601 | } |
| @@ -1607,12 +1612,12 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, · 10 unmodified lines | ||
| 1607 | 1612 | |
| 1608 | 1613 | //Extend NalList buffer if exceed |
| 1609 | 1614 | iCodedSliceNum = GetCurrentSliceNum (pCtx->pCurDqLayer); |
| 1610 | − pLayerBsInfo->iNalCount = GetCurLayerNalCount(pCtx->pCurDqLayer, iCodedSliceNum); | |
| 1611 | − iCodedNalCount = GetTotalCodedNalCount(pFrameBsInfo); | |
| 1615 | + pLayerBsInfo->iNalCount = GetCurLayerNalCount (pCtx->pCurDqLayer, iCodedSliceNum); | |
| 1616 | + iCodedNalCount = GetTotalCodedNalCount (pFrameBsInfo); | |
| 1612 | 1617 | |
| 1613 | − if( iCodedNalCount > pCtx->pOut->iCountNals) { | |
| 1618 | + if (iCodedNalCount > pCtx->pOut->iCountNals) { | |
| 1614 | 1619 | iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo, pCtx->pCurDqLayer->iMaxSliceNum); |
| 1615 | − if(ENC_RETURN_SUCCESS != iRet) { | |
| 1620 | + if (ENC_RETURN_SUCCESS != iRet) { | |
| 1616 | 1621 | return iRet; |
| 1617 | 1622 | } |
| 1618 | 1623 | } |
| @@ -1625,8 +1630,9 @@ int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, const int32_t · 6 unmodified lines | ||
| 1625 | 1630 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 1626 | 1631 | SNalUnitHeaderExt* pNalHeadExt = &pCurLayer->sLayerInfo.sNalHeaderExt; |
| 1627 | 1632 | SBitStringAux* pBs = pCurSlice->pSliceBsa; |
| 1628 | − const int32_t kiDynamicSliceFlag = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode | |
| 1629 | − == SM_SIZELIMITED_SLICE); | |
| 1633 | + const int32_t kiDynamicSliceFlag = | |
| 1634 | + (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode | |
| 1635 | + == SM_SIZELIMITED_SLICE); | |
| 1630 | 1636 | if (I_SLICE == pEncCtx->eSliceType) { |
| 1631 | 1637 | pNalHeadExt->bIdrFlag = 1; |
| 1632 | 1638 | pCurSlice->sScaleShift = 0; |
| @@ -1639,7 +1645,7 @@ int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, const int32_t · 6 unmodified lines | ||
| 1639 | 1645 | |
| 1640 | 1646 | //RomRC init slice by slice |
| 1641 | 1647 | if (pWelsSvcRc->bGomRC) { |
| 1642 | − GomRCInitForOneSlice(pCurSlice, pWelsSvcRc->iBitsPerMb); | |
| 1648 | + GomRCInitForOneSlice (pCurSlice, pWelsSvcRc->iBitsPerMb); | |
| 1643 | 1649 | } |
| 1644 | 1650 | |
| 1645 | 1651 | g_pWelsWriteSliceHeader[pCurSlice->bSliceHeaderExtFlag] (pEncCtx, pBs, pCurLayer, pCurSlice, |
| @@ -1695,7 +1701,7 @@ void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSlic · 49 unmodified lines | ||
| 1695 | 1701 | pCurSlice->sSliceHeaderExt.uiNumMbsInSlice = 1 + iCurMbIdx - pCurSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; |
| 1696 | 1702 | |
| 1697 | 1703 | //pNextSlice pointer/initialization |
| 1698 | − if(pEncCtx->iActiveThreadsNum > 1) { | |
| 1704 | + if (pEncCtx->iActiveThreadsNum > 1) { | |
| 1699 | 1705 | pNextSlice = &pSliceBuffer[ iCodedSliceNum + 1 ]; |
| 1700 | 1706 | } else { |
| 1701 | 1707 | pNextSlice = &pSliceBuffer[ iNextSliceIdc ]; |