History

Multi-thread-fixed:RBC#1725:refactoring for ReOrderSliceInLayer module

huade committed 9 years ago

Commit 612a0a31 parent 57016556 files · +235 −124Browse files

Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 6 files). Show all

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+208−74
@@ -977,6 +977,47 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 976 unmodified lines
977 return ENC_RETURN_SUCCESS;977 return ENC_RETURN_SUCCESS;
978}978}
979 979
980int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx) {
981 SDqLayer* pDqLayer = pCtx->pCurDqLayer;
982 int32_t iSliceIdx = 0;
983
984 for( ; iSliceIdx < pDqLayer->iMaxSliceNum; iSliceIdx++) {
985 if(NULL == pDqLayer->ppSliceInLayer[iSliceIdx]) {
986 return ENC_RETURN_UNEXPECTED;
987 }
988
989 pDqLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx = -1;
990 }
991
992 return ENC_RETURN_SUCCESS;
993}
994
995int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
996 SSlice*& pSlice,
997 const int32_t kiThreadIdx,
998 const int32_t kiDlayerIdx,
999 const int32_t kiSliceIdx) {
1000 SDqLayer* pDqLayer = pCtx->pCurDqLayer;
1001 const int32_t kiCodedNumInThread = pDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[kiThreadIdx];
1002 const int32_t kiMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIdx];
1003 int32_t iRet = 0;
1004
1005 if (kiCodedNumInThread >= kiMaxSliceNumInThread) {
1006 iRet = ReallocateSliceInThread(pCtx, pDqLayer, kiDlayerIdx, kiThreadIdx);
1007 if (ENC_RETURN_SUCCESS != iRet) {
1008 return iRet;
1009 }
1010 }
1011
1012 pSlice = pDqLayer->sSliceThreadInfo.pSliceInThread [kiThreadIdx] + kiCodedNumInThread;
1013 // Initialize slice bs buffer info
1014 pSlice->sSliceBs.uiBsPos = 0;
1015 pSlice->sSliceBs.iNalIndex = 0;
1016 pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
1017
1018 return ENC_RETURN_SUCCESS;
1019}
1020
980int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx,1021int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx,
981 SDqLayer* pDqLayer,1022 SDqLayer* pDqLayer,
982 const int32_t kiDlayerIndex,1023 const int32_t kiDlayerIndex,
@@ -1214,25 +1255,21 @@ int32_t CalculateNewSliceNum (SDqLayer* pDqLayer, · 231 unmodified lines
1214 return ENC_RETURN_SUCCESS;1255 return ENC_RETURN_SUCCESS;
1215}1256}
1216 1257
1217int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) {1258int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
1259 SDqLayer* pDqLayer,
1260 const int32_t kiDlayerIdx,
1261 const int32_t kiThreadIndex) {
1218 1262
1219 CMemoryAlign* pMA = pCtx->pMemAlign;1263 int32_t iMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIndex];
1220 SDqLayer* pCurLayer = pCtx->pCurDqLayer;1264 int32_t iMaxSliceNumUpdate = 0;
1221 SSlice** ppSlice = NULL;1265 int32_t iRet = 0;
1222 int32_t iMaxSliceNumOld = pCurLayer->iMaxSliceNum;1266 SSlice* pLastCodedSlice = pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex] + (iMaxSliceNumInThread - 1);
1223 int32_t iMaxSliceNumNew = 0;1267 SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
1224 int32_t iRet = 0;
1225 int32_t iSliceIdx = 0;
1226 const int32_t kiCurDid = pCtx->uiDependencyId;
1227 1268
1228 int32_t* pFirstMbIdxofSlice = NULL;1269 iRet = CalculateNewSliceNum (pDqLayer,
1229 int32_t* pCountMbNumInSlice = NULL;
1230 SSlice* pLastCodedSlice = pCurLayer->sSliceThreadInfo.pSliceInThread[0] + (iMaxSliceNumOld - 1);
1231 SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument;
1232 iRet = CalculateNewSliceNum (pCurLayer,
1233 pLastCodedSlice,1270 pLastCodedSlice,
1234 iMaxSliceNumOld,1271 iMaxSliceNumInThread,
1235 iMaxSliceNumNew);1272 iMaxSliceNumUpdate);
1236 1273
1237 if (ENC_RETURN_SUCCESS != iRet) {1274 if (ENC_RETURN_SUCCESS != iRet) {
1238 return iRet;1275 return iRet;
@@ -1240,44 +1277,91 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 1 unmodified line
1240 1277
1241 iRet = ReallocateSliceList (pCtx,1278 iRet = ReallocateSliceList (pCtx,
1242 pSliceArgument,1279 pSliceArgument,
1243 pCurLayer->sSliceThreadInfo.pSliceInThread[0],1280 pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex],
1244 iMaxSliceNumOld,1281 iMaxSliceNumInThread,
1245 iMaxSliceNumNew);1282 iMaxSliceNumUpdate);
1246 if (ENC_RETURN_SUCCESS != iRet) {1283 if (ENC_RETURN_SUCCESS != iRet) {
1247 return iRet;1284 return iRet;
1248 }1285 }
1249 1286
1287 return ENC_RETURN_SUCCESS;
1288}
1289
1290int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx,
1291 const int32_t kiMaxSliceNumOld,
1292 const int32_t kiMaxSliceNumNew){
1293 CMemoryAlign* pMA = pCtx->pMemAlign;
1294 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
1295 SSlice** ppSlice = NULL;
1296 int32_t* pFirstMbIdxofSlice = NULL;
1297 int32_t* pCountMbNumInSlice = NULL;
1298
1250 // update for ppsliceInlayer1299 // update for ppsliceInlayer
1251 ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iMaxSliceNumNew, "ppSlice");1300 ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * kiMaxSliceNumNew, "ppSlice");
1252 if (NULL == ppSlice) {1301 if (NULL == ppSlice) {
1253 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocSliceBuffer: ppSlice is NULL");1302 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: ppSlice is NULL");
1254 return ENC_RETURN_MEMALLOCERR;1303 return ENC_RETURN_MEMALLOCERR;
1255 }1304 }
1256 pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");1305 pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");
1257 pCurLayer->ppSliceInLayer = ppSlice;1306 pCurLayer->ppSliceInLayer = ppSlice;
1258 1307
1259 // update for pFirstMbIdxInSlice1308 // update for pFirstMbIdxInSlice
1260 pFirstMbIdxofSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * iMaxSliceNumNew, "pFirstMbIdxofSlice");1309 pFirstMbIdxofSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * kiMaxSliceNumNew, "pFirstMbIdxofSlice");
1261 if (NULL == pFirstMbIdxofSlice) {1310 if (NULL == pFirstMbIdxofSlice) {
1262 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocSliceBuffer: pFirstMbIdxofSlice is NULL");1311 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pFirstMbIdxofSlice is NULL");
1263 return ENC_RETURN_MEMALLOCERR;1312 return ENC_RETURN_MEMALLOCERR;
1264 }1313 }
1265 memset (pFirstMbIdxofSlice, 0, sizeof(int32_t) * iMaxSliceNumNew);1314 memset (pFirstMbIdxofSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew);
1266 memcpy (pFirstMbIdxofSlice, pCurLayer->pFirstMbIdxOfSlice, sizeof (int32_t) * iMaxSliceNumOld);1315 memcpy (pFirstMbIdxofSlice, pCurLayer->pFirstMbIdxOfSlice, sizeof (int32_t) * kiMaxSliceNumOld);
1267 pMA->WelsFree (pCurLayer->pFirstMbIdxOfSlice, "pFirstMbIdxofSlice");1316 pMA->WelsFree (pCurLayer->pFirstMbIdxOfSlice, "pFirstMbIdxofSlice");
1268 pCurLayer->pFirstMbIdxOfSlice = pFirstMbIdxofSlice;1317 pCurLayer->pFirstMbIdxOfSlice = pFirstMbIdxofSlice;
1269 1318
1270 // update for pCountMbNumInSlice1319 // update for pCountMbNumInSlice
1271 pCountMbNumInSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * iMaxSliceNumNew, "pCountMbNumInSlice");1320 pCountMbNumInSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * kiMaxSliceNumNew, "pCountMbNumInSlice");
1272 if (NULL == pCountMbNumInSlice) {1321 if (NULL == pCountMbNumInSlice) {
1273 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocSliceBuffer: pCountMbNumInSlice is NULL");1322 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pCountMbNumInSlice is NULL");
1274 return ENC_RETURN_MEMALLOCERR;1323 return ENC_RETURN_MEMALLOCERR;
1275 }1324 }
1276 memset (pCountMbNumInSlice, 0, sizeof(int32_t) * iMaxSliceNumNew);1325 memset (pCountMbNumInSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew);
1277 memcpy (pCountMbNumInSlice, pCurLayer->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);1326 memcpy (pCountMbNumInSlice, pCurLayer->pCountMbNumInSlice, sizeof (int32_t) * kiMaxSliceNumOld);
1278 pMA->WelsFree (pCurLayer->pCountMbNumInSlice, "pCountMbNumInSlice");1327 pMA->WelsFree (pCurLayer->pCountMbNumInSlice, "pCountMbNumInSlice");
1279 pCurLayer->pCountMbNumInSlice = pCountMbNumInSlice;1328 pCurLayer->pCountMbNumInSlice = pCountMbNumInSlice;
1280 1329
1330 return ENC_RETURN_SUCCESS;
1331}
1332
1333int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) {
1334
1335 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
1336 int32_t iMaxSliceNumOld = pCurLayer->iMaxSliceNum;
1337 int32_t iMaxSliceNumNew = 0;
1338 int32_t iRet = 0;
1339 int32_t iSliceIdx = 0;
1340 const int32_t kiCurDid = pCtx->uiDependencyId;
1341 SSlice* pLastCodedSlice = pCurLayer->sSliceThreadInfo.pSliceInThread[0] + (iMaxSliceNumOld - 1);
1342 SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument;
1343 iRet = CalculateNewSliceNum (pCurLayer,
1344 pLastCodedSlice,
1345 iMaxSliceNumOld,
1346 iMaxSliceNumNew);
1347
1348 if (ENC_RETURN_SUCCESS != iRet) {
1349 return iRet;
1350 }
1351
1352 iRet = ReallocateSliceList (pCtx,
1353 pSliceArgument,
1354 pCurLayer->sSliceThreadInfo.pSliceInThread[0],
1355 iMaxSliceNumOld,
1356 iMaxSliceNumNew);
1357 if (ENC_RETURN_SUCCESS != iRet) {
1358 return iRet;
1359 }
1360
1361 iRet = ExtendLayerBuffer(pCtx, iMaxSliceNumOld, iMaxSliceNumNew);
1362 if (ENC_RETURN_SUCCESS != iRet) {
1363 return iRet;
1364 }
1281 1365
1282 for (iSliceIdx = 0; iSliceIdx < iMaxSliceNumNew; iSliceIdx++) {1366 for (iSliceIdx = 0; iSliceIdx < iMaxSliceNumNew; iSliceIdx++) {
1283 pCurLayer->ppSliceInLayer[iSliceIdx] = pCurLayer->sSliceThreadInfo.pSliceInThread[0] + iSliceIdx;1367 pCurLayer->ppSliceInLayer[iSliceIdx] = pCurLayer->sSliceThreadInfo.pSliceInThread[0] + iSliceIdx;
@@ -1292,6 +1376,22 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 8 unmodified lines
1292 return ENC_RETURN_SUCCESS;1376 return ENC_RETURN_SUCCESS;
1293}1377}
1294 1378
1379static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiCodedSliceNum) {
1380 int32_t iSliceIdx = 0;
1381 for(; iSliceIdx <kiCodedSliceNum ; iSliceIdx ++ ) {
1382 if ( NULL == pCurLayer->ppSliceInLayer[iSliceIdx]) {
1383 return ENC_RETURN_UNEXPECTED;
1384 }
1385
1386 if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) {
1387 return ENC_RETURN_UNEXPECTED;
1388 }
1389 }
1390
1391 return ENC_RETURN_SUCCESS;
1392}
1393
1394
1295int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,1395int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,
1296 const int32_t kiThreadNum,1396 const int32_t kiThreadNum,
1297 const int32_t kiPartitionNum) {1397 const int32_t kiPartitionNum) {
@@ -1301,18 +1401,26 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 3 unmodified lines
1301 int32_t iPartitionID = 0;1401 int32_t iPartitionID = 0;
1302 int32_t iSliceIdx = 0;1402 int32_t iSliceIdx = 0;
1303 int32_t iSliceNumInThread = 0;1403 int32_t iSliceNumInThread = 0;
1304 int32_t iPartitionOffset = 0;1404 int32_t iEncodeSliceNum = 0;
1305 int32_t iActualSliceIdx = 0;1405 int32_t iActualSliceIdx = 0;
1406 int32_t iNonUsedBufferNum = 0;
1407 int32_t iUsedSliceNum = 0;
1306 int32_t aiPartitionOffset[MAX_THREADS_NUM] = {0};1408 int32_t aiPartitionOffset[MAX_THREADS_NUM] = {0};
1307 1409
1308 //for non-dynamic slice mode, kiPartitionNum = 1, iPartitionOffset = 01410 //for non-dynamic slice mode, kiPartitionNum = 1, iPartitionOffset = 0
1309 for(iPartitionIdx = 0; iPartitionIdx < kiPartitionNum; iPartitionIdx++) {1411 for(iPartitionIdx = 0; iPartitionIdx < kiPartitionNum; iPartitionIdx++) {
1310 aiPartitionOffset[iPartitionIdx] = iPartitionOffset;1412 aiPartitionOffset[iPartitionIdx] = iEncodeSliceNum;
1311 iPartitionOffset += pCurLayer->pNumSliceCodedOfPartition[iPartitionIdx];1413 iEncodeSliceNum += pCurLayer->pNumSliceCodedOfPartition[iPartitionIdx];
1414 }
1415
1416 if( iEncodeSliceNum != pCurLayer->sSliceEncCtx.iSliceNumInFrame) {
1417 return ENC_RETURN_UNEXPECTED;
1312 }1418 }
1313 1419
1420 //before encode all slices in layer, slices' index are init with -1
1421 //pSliceInThread->iSliceIdx will be set to actual slice index when encode one slice
1314 for (iThreadIdx = 0; iThreadIdx < kiThreadNum; iThreadIdx++) {1422 for (iThreadIdx = 0; iThreadIdx < kiThreadNum; iThreadIdx++) {
1315 iSliceNumInThread = pCurLayer->sSliceThreadInfo.iEncodedSliceNumInThread[iThreadIdx];1423 iSliceNumInThread = pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
1316 1424
1317 for(iSliceIdx =0; iSliceIdx < iSliceNumInThread; iSliceIdx++) {1425 for(iSliceIdx =0; iSliceIdx < iSliceNumInThread; iSliceIdx++) {
1318 pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[iThreadIdx] + iSliceIdx;1426 pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[iThreadIdx] + iSliceIdx;
@@ -1320,78 +1428,105 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 1 unmodified line
1320 return ENC_RETURN_UNEXPECTED;1428 return ENC_RETURN_UNEXPECTED;
1321 }1429 }
1322 1430
1323 iPartitionID = pSliceInThread->iSliceIdx % kiPartitionNum;1431 if( -1 != pSliceInThread->iSliceIdx) {
1324 iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / kiPartitionNum;1432 iPartitionID = pSliceInThread->iSliceIdx % kiPartitionNum;
1325 pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;1433 iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / kiPartitionNum;
1434 pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;
1435 iUsedSliceNum ++;
1436 } else {
1437 pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceInThread;
1438 iNonUsedBufferNum ++;
1439 }
1326 }1440 }
1327 }1441 }
1328 1442
1443 if( iUsedSliceNum != iEncodeSliceNum ||
1444 pCurLayer->iMaxSliceNum != (iNonUsedBufferNum + iUsedSliceNum)) {
1445 return ENC_RETURN_UNEXPECTED;
1446 }
1447
1448 if (ENC_RETURN_SUCCESS != CheckAllSliceBuffer(pCurLayer, iEncodeSliceNum)) {
1449 return ENC_RETURN_UNEXPECTED;
1450 }
1451
1329 return ENC_RETURN_SUCCESS;1452 return ENC_RETURN_SUCCESS;
1330}1453}
1331 1454
1332static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiCodedSliceNum) {1455int32_t FrameBsRealloc (sWelsEncCtx* pCtx,
1333 int32_t iSliceIdx = 0;1456 SFrameBSInfo* pFrameBsInfo,
1334 for(; iSliceIdx <kiCodedSliceNum ; iSliceIdx ++ ) {1457 SLayerBSInfo* pLayerBsInfo,
1335 if ( NULL == pCurLayer->ppSliceInLayer[iSliceIdx]) {1458 const int32_t kiMaxSliceNumOld) {
1336 return ENC_RETURN_UNEXPECTED;1459 CMemoryAlign* pMA = pCtx->pMemAlign;
1337 }1460 int32_t iCountNals = pCtx->pOut->iCountNals;
1461 iCountNals += kiMaxSliceNumOld * (pCtx->pSvcParam->iSpatialLayerNum + pCtx->bNeedPrefixNalFlag);
1462
1463 SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMallocz (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
1464 if (NULL == pNalList) {
1465 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::FrameBsRealloc: pNalList is NULL");
1466 return ENC_RETURN_MEMALLOCERR;
1467 }
1468 memcpy (pNalList, pCtx->pOut->sNalList, sizeof (SWelsNalRaw) * pCtx->pOut->iCountNals);
1469 pMA->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList");
1470 pCtx->pOut->sNalList = pNalList;
1338 1471
1339 if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) {1472 int32_t* pNalLen = (int32_t*)pMA->WelsMallocz (iCountNals * sizeof (int32_t), "pOut->pNalLen");
1340 return ENC_RETURN_UNEXPECTED;1473 if (NULL == pNalLen) {
1341 }1474 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::FrameBsRealloc: pNalLen is NULL");
1475 return ENC_RETURN_MEMALLOCERR;
1476 }
1477 memcpy (pNalLen, pCtx->pOut->pNalLen, sizeof (int32_t) * pCtx->pOut->iCountNals);
1478 pMA->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen");
1479 pCtx->pOut->pNalLen = pNalLen;
1480
1481 pCtx->pOut->iCountNals = iCountNals;
1482 SLayerBSInfo* pLBI1, *pLBI2;
1483 pLBI1 = &pFrameBsInfo->sLayerInfo[0];
1484 pLBI1->pNalLengthInByte = pCtx->pOut->pNalLen;
1485 while (pLBI1 != pLayerBsInfo) {
1486 pLBI2 = pLBI1;
1487 ++ pLBI1;
1488 pLBI1->pNalLengthInByte = pLBI2->pNalLengthInByte + pLBI2->iNalCount;
1342 }1489 }
1343 1490
1344 return ENC_RETURN_SUCCESS;1491 return ENC_RETURN_SUCCESS;
1345}1492}
1346 1493
1347int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) {1494int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx,
1348 1495 SFrameBSInfo* pFrameBsInfo,
1349 CMemoryAlign* pMA = pCtx->pMemAlign;1496 SLayerBSInfo* pLayerBsInfo,
1497 const int32_t kiPartitionNum) {
1350 SDqLayer* pCurLayer = pCtx->pCurDqLayer;1498 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
1351 SSlice** ppSlice = NULL;1499 int32_t iMaxSliceNum = 0;
1352 int32_t iCodedSliceNum = 0;
1353 int32_t iThreadIdx = 0;1500 int32_t iThreadIdx = 0;
1354 int32_t iRet = 0;1501 int32_t iRet = 0;
1355 int32_t iThreadNum = 1; //TODO: should be equal to pCurLayer->iMaxSliceNum;1502 int32_t iThreadNum = 1; //TODO: should be equal to pCurLayer->iMaxSliceNum;
1356 SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
1357 int32_t iPartitionNum = (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? pCtx->iActiveThreadsNum : 1;
1358 1503
1359 for ( ; iThreadIdx < iThreadNum; iThreadIdx++) {1504 for ( ; iThreadIdx < iThreadNum; iThreadIdx++) {
1360 iCodedSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];1505 iMaxSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
1361 }
1362
1363 if (iCodedSliceNum <= 0) {
1364 return ENC_RETURN_UNEXPECTED;
1365 }1506 }
1366 1507
1367 //reallocate ppSliceInLayer if total encoded slice num exceed max slice num1508 //reallocate ppSliceInLayer if total encoded slice num exceed max slice num
1368 if (iCodedSliceNum > pCurLayer->iMaxSliceNum) {1509 if (iMaxSliceNum > pCurLayer->iMaxSliceNum) {
1369 ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iCodedSliceNum, "ppSlice");1510 iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo, pCtx->pCurDqLayer->iMaxSliceNum);
1370 if (NULL == ppSlice) {1511 if(ENC_RETURN_SUCCESS != iRet) {
1371 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ppSlice is NULL");1512 return iRet;
1372 return ENC_RETURN_MEMALLOCERR;
1373 }1513 }
1374 1514
1375 pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");1515 iRet = ExtendLayerBuffer(pCtx, pCtx->pCurDqLayer->iMaxSliceNum, iMaxSliceNum);
1376 pCurLayer->ppSliceInLayer = ppSlice;1516 if (ENC_RETURN_SUCCESS != iRet) {
1377 pCurLayer->iMaxSliceNum = iCodedSliceNum;1517 return iRet;
1518 }
1519 pCurLayer->iMaxSliceNum = iMaxSliceNum;
1378 }1520 }
1379 1521
1380 //update ppSliceInLayer based on pSliceInThread, reordering based on slice index1522 //update ppSliceInLayer based on pSliceInThread, reordering based on slice index
1381 iRet = ReOrderSliceInLayer (pCurLayer, iThreadNum, iPartitionNum);1523 iRet = ReOrderSliceInLayer (pCurLayer, iThreadNum, kiPartitionNum);
1382 if (ENC_RETURN_SUCCESS != iRet) {1524 if (ENC_RETURN_SUCCESS != iRet) {
1383 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,1525 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
1384 "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed");1526 "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed");
1385 return iRet;1527 return iRet;
1386 }1528 }
1387 1529
1388 iRet = CheckAllSliceBuffer(pCurLayer, pCtx->iActiveThreadsNum);
1389 if (ENC_RETURN_SUCCESS != iRet) {
1390 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
1391 "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayerDynamic failed");
1392 return iRet;
1393 }
1394
1395 return ENC_RETURN_SUCCESS;1530 return ENC_RETURN_SUCCESS;
1396}1531}
1397 1532
@@ -1450,7 +1585,6 @@ void UpdateMbNeighbourInfoForNextSlice (SDqLayer* pCurDq, · 52 unmodified lines
1450 (iIdx <= kiLastMbIdxInPartition));1585 (iIdx <= kiLastMbIdxInPartition));
1451}1586}
1452 1587
1453
1454void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,1588void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
1455 int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {1589 int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {
1456 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;1590 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;

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