| 1464 | } |
| 1465 | |
| 1466 | int32_t ReOrderSliceInLayer (sWelsEncCtx* pCtx, |
| 1467 | const SliceModeEnum kuiSliceMode, |
| 1468 | const int32_t kiThreadNum) { |
| 1469 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 1470 | SSlice* pSliceBuffer = NULL; |
| 1471 | int32_t iSlcBuffIdx = 0; |
| 1472 | int32_t iPartitionIdx = 0; |
| 1473 | int32_t iPartitionID = 0; |
| 1474 | int32_t iSliceIdx = 0; |
| 1475 | int32_t iSliceNumInThread = 0; |
| 1476 | int32_t iEncodeSliceNum = 0; |
| 1477 | int32_t iActualSliceIdx = 0; |
| 1478 | int32_t iNonUsedBufferNum = 0; |
| 1479 | int32_t iUsedSliceNum = 0; |
| 1480 | |
| 1481 | int32_t iPartitionNum = 0; |
| 1482 | int32_t aiPartitionOffset[MAX_THREADS_NUM] = {0}; |
| 1483 | |
| 1484 | //for non-dynamic slice mode, iPartitionNum = 1, iPartitionOffset = 0 |
| 1485 | iPartitionNum = (SM_SIZELIMITED_SLICE == kuiSliceMode) ? kiThreadNum : 1; |
| 1486 | for (iPartitionIdx = 0; iPartitionIdx < iPartitionNum; iPartitionIdx++) { |
| 1487 | aiPartitionOffset[iPartitionIdx] = iEncodeSliceNum; |
| 1488 | if (SM_SIZELIMITED_SLICE == kuiSliceMode) { |
| 1489 | iEncodeSliceNum += pCurLayer->NumSliceCodedOfPartition[iPartitionIdx]; |
| 1490 | } else { |
| 1491 | iEncodeSliceNum = pCurLayer->sSliceEncCtx.iSliceNumInFrame; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | if (iEncodeSliceNum != pCurLayer->sSliceEncCtx.iSliceNumInFrame) { |
| 1496 | return ENC_RETURN_UNEXPECTED; |
| 1497 | } |
| 1498 | |
| 1499 | //before encode all slices in layer, slices' index are init with -1 |
| 1500 | //pSliceBuffer->iSliceIdx will be set to actual slice index when encode one slice |
| 1501 | for (iSlcBuffIdx = 0; iSlcBuffIdx < kiThreadNum; iSlcBuffIdx++) { |
| 1502 | iSliceNumInThread = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].iMaxSliceNum; |
| 1503 | |
| 1504 | for (iSliceIdx = 0; iSliceIdx < iSliceNumInThread; iSliceIdx++) { |
| 1505 | pSliceBuffer = pCurLayer->sSliceBufferInfo[iSlcBuffIdx].pSliceBuffer + iSliceIdx; |
| 1506 | if (NULL == pSliceBuffer) { |
| 1507 | return ENC_RETURN_UNEXPECTED; |
| 1508 | } |
| 1509 | |
| 1510 | if (-1 != pSliceBuffer->iSliceIdx) { |
| 1511 | iPartitionID = pSliceBuffer->iSliceIdx % iPartitionNum; |
| 1512 | iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceBuffer->iSliceIdx / iPartitionNum; |
| 1513 | pSliceBuffer->iSliceIdx = iActualSliceIdx; |
| 1514 | pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceBuffer; |
| 1515 | iUsedSliceNum ++; |
| 1516 | } else { |
| 1517 | pCurLayer->ppSliceInLayer[iEncodeSliceNum + iNonUsedBufferNum] = pSliceBuffer; |
| 1518 | iNonUsedBufferNum ++; |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | if (iUsedSliceNum != iEncodeSliceNum || |
no test coverage detected