Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 14 files). Show all
Unified · Split
| @@ -927,7 +927,7 @@ void FreeSliceInLayer (SDqLayer* pDq, CMemoryAlign* pMa) { · 926 unmodified lines | ||
| 927 | 927 | for (; iIdx < MAX_THREADS_NUM; iIdx ++) { |
| 928 | 928 | FreeSliceBuffer (pDq->sSliceThreadInfo.pSliceInThread[iIdx], |
| 929 | 929 | pDq->sSliceThreadInfo.iMaxSliceNumInThread[iIdx], |
| 930 | − pMa, "pSliceInLayer"); | |
| 930 | + pMa, "pSliceInThread"); | |
| 931 | 931 | } |
| 932 | 932 | } |
| 933 | 933 | |
| @@ -939,40 +939,20 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 5 unmodified lines | ||
| 939 | 939 | FreeSliceInLayer (pDq, pMa); |
| 940 | 940 | |
| 941 | 941 | if (pDq->ppSliceInLayer) { |
| 942 | − pMa->WelsFree (pDq->ppSliceInLayer, "pDq->ppSliceInLayer"); | |
| 942 | + pMa->WelsFree (pDq->ppSliceInLayer, "ppSliceInLayer"); | |
| 943 | 943 | pDq->ppSliceInLayer = NULL; |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | if (pDq->pFirstMbIdxOfSlice) { |
| 947 | − pMa->WelsFree (pDq->pFirstMbIdxOfSlice, "pDq->pFirstMbIdxOfSlice"); | |
| 947 | + pMa->WelsFree (pDq->pFirstMbIdxOfSlice, "pFirstMbIdxOfSlice"); | |
| 948 | 948 | pDq->pFirstMbIdxOfSlice = NULL; |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | if (pDq->pCountMbNumInSlice) { |
| 952 | − pMa->WelsFree (pDq->pCountMbNumInSlice, "pDq->pCountMbNumInSlice"); | |
| 952 | + pMa->WelsFree (pDq->pCountMbNumInSlice, "pCountMbNumInSlice"); | |
| 953 | 953 | pDq->pCountMbNumInSlice = NULL; |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | − if (pDq->pNumSliceCodedOfPartition) { | |
| 957 | − pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition"); | |
| 958 | − pDq->pNumSliceCodedOfPartition = NULL; | |
| 959 | − } | |
| 960 | − | |
| 961 | − if (pDq->pLastCodedMbIdxOfPartition) { | |
| 962 | − pMa->WelsFree (pDq->pLastCodedMbIdxOfPartition, "pLastCodedMbIdxOfPartition"); | |
| 963 | − pDq->pLastCodedMbIdxOfPartition = NULL; | |
| 964 | − } | |
| 965 | − | |
| 966 | − if (pDq->pFirstMbIdxOfPartition) { | |
| 967 | − pMa->WelsFree (pDq->pFirstMbIdxOfPartition, "pFirstMbIdxOfPartition"); | |
| 968 | − pDq->pFirstMbIdxOfPartition = NULL; | |
| 969 | − } | |
| 970 | − | |
| 971 | − if (pDq->pEndMbIdxOfPartition) { | |
| 972 | − pMa->WelsFree (pDq->pEndMbIdxOfPartition, "pEndMbIdxOfPartition"); | |
| 973 | − pDq->pEndMbIdxOfPartition = NULL; | |
| 974 | − } | |
| 975 | − | |
| 976 | 956 | if (pDq->pFeatureSearchPreparation) { |
| 977 | 957 | ReleaseFeatureSearchPreparation (pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock); |
| 978 | 958 | pMa->WelsFree (pDq->pFeatureSearchPreparation, "pFeatureSearchPreparation"); |
| @@ -1083,21 +1063,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 104 unmodified lines | ||
| 1083 | 1063 | pDqLayer = (SDqLayer*)pMa->WelsMallocz (sizeof (SDqLayer), "pDqLayer"); |
| 1084 | 1064 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer), FreeDqLayer (pDqLayer, pMa)) |
| 1085 | 1065 | |
| 1086 | − // for dynamic slicing mode | |
| 1087 | − if (SM_SIZELIMITED_SLICE == pDlayer->sSliceArgument.uiSliceMode) { | |
| 1088 | − const int32_t iSize = pParam->iMultipleThreadIdc * sizeof (int32_t); | |
| 1089 | − | |
| 1090 | − pDqLayer->pNumSliceCodedOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pNumSliceCodedOfPartition"); | |
| 1091 | − pDqLayer->pLastCodedMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pLastCodedMbIdxOfPartition"); | |
| 1092 | − pDqLayer->pFirstMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pFirstMbIdxOfPartition"); | |
| 1093 | − pDqLayer->pEndMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pEndMbIdxOfPartition"); | |
| 1094 | − WELS_VERIFY_RETURN_PROC_IF (1, | |
| 1095 | − (NULL == pDqLayer->pNumSliceCodedOfPartition || | |
| 1096 | − NULL == pDqLayer->pLastCodedMbIdxOfPartition || | |
| 1097 | − NULL == pDqLayer->pFirstMbIdxOfPartition || | |
| 1098 | − NULL == pDqLayer->pEndMbIdxOfPartition), | |
| 1099 | − FreeDqLayer (pDqLayer, pMa)) | |
| 1100 | − } | |
| 1101 | 1066 | pDqLayer->bNeedAdjustingSlicing = false; |
| 1102 | 1067 | |
| 1103 | 1068 | pDqLayer->iMbWidth = kiMbW; |
| @@ -2453,7 +2418,13 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 1349 unmodified lines | ||
| 2453 | 2418 | else if (iPartitionNum > AVERSLICENUM_CONSTRAINT) |
| 2454 | 2419 | iPartitionNum = AVERSLICENUM_CONSTRAINT; // AVERSLICENUM_CONSTRAINT might be variable, however not fixed by MACRO |
| 2455 | 2420 | iCountMbNumPerPartition /= iPartitionNum; |
| 2421 | + if(iCountMbNumPerPartition == 0 || iCountMbNumPerPartition == 1) { | |
| 2422 | + iCountMbNumPerPartition = kiMbNumInFrame; | |
| 2423 | + iPartitionNum = 1; | |
| 2424 | + } | |
| 2425 | + | |
| 2456 | 2426 | pSliceCtx->iSliceNumInFrame = iPartitionNum; |
| 2427 | + | |
| 2457 | 2428 | i = 0; |
| 2458 | 2429 | while (i < iPartitionNum) { |
| 2459 | 2430 | if (i + 1 == iPartitionNum) { |
| @@ -2462,8 +2433,10 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 2 unmodified lines | ||
| 2462 | 2433 | iCountMbNumInPartition = iCountMbNumPerPartition; |
| 2463 | 2434 | } |
| 2464 | 2435 | |
| 2465 | − pCurDq->pFirstMbIdxOfPartition[i] = iFirstMbIdx; | |
| 2466 | − pCurDq->pEndMbIdxOfPartition[i] = iFirstMbIdx + iCountMbNumInPartition - 1; | |
| 2436 | + pCurDq->FirstMbIdxOfPartition[i] = iFirstMbIdx; | |
| 2437 | + pCurDq->EndMbIdxOfPartition[i] = iFirstMbIdx + iCountMbNumInPartition - 1; | |
| 2438 | + pCurDq->LastCodedMbIdxOfPartition[i] = 0; | |
| 2439 | + pCurDq->NumSliceCodedOfPartition[i] = 0; | |
| 2467 | 2440 | |
| 2468 | 2441 | WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i, |
| 2469 | 2442 | iCountMbNumInPartition, sizeof (uint16_t)); |
| @@ -2473,6 +2446,14 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 3 unmodified lines | ||
| 2473 | 2446 | iAssignableMbLeft -= iCountMbNumInPartition; |
| 2474 | 2447 | ++ i; |
| 2475 | 2448 | } |
| 2449 | + | |
| 2450 | + while(i<MAX_THREADS_NUM) { | |
| 2451 | + pCurDq->FirstMbIdxOfPartition[i] = 0; | |
| 2452 | + pCurDq->EndMbIdxOfPartition[i] = 0; | |
| 2453 | + pCurDq->LastCodedMbIdxOfPartition[i] = 0; | |
| 2454 | + pCurDq->NumSliceCodedOfPartition[i] = 0; | |
| 2455 | + ++ i; | |
| 2456 | + } | |
| 2476 | 2457 | } |
| 2477 | 2458 | |
| 2478 | 2459 | void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) { |
| @@ -2537,22 +2518,17 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 58 unmodified lines | ||
| 2537 | 2518 | SSlice* pBaseSlice = pCurDq->ppSliceInLayer[0]; |
| 2538 | 2519 | const uint8_t kiCurDid = pCtx->uiDependencyId; |
| 2539 | 2520 | const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID); |
| 2540 | − SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid]; | |
| 2541 | 2521 | SNalUnitHeaderExt* pNalHdExt = &pCurDq->sLayerInfo.sNalHeaderExt; |
| 2542 | 2522 | SNalUnitHeader* pNalHd = &pNalHdExt->sNalUnitHeader; |
| 2543 | 2523 | SDqIdc* pDqIdc = &pCtx->pDqIdcMap[kiCurDid]; |
| 2544 | 2524 | int32_t iIdx = 0; |
| 2545 | − int32_t iSliceCount = 0; | |
| 2525 | + int32_t iSliceCount = pCurDq->iMaxSliceNum; | |
| 2546 | 2526 | SSpatialLayerInternal* pParamInternal = &pParam->sDependencyLayers[kiCurDid]; |
| 2547 | 2527 | if (NULL == pCurDq || NULL == pBaseSlice) |
| 2548 | 2528 | return; |
| 2549 | 2529 | |
| 2550 | 2530 | pCurDq->pDecPic = pDecPic; |
| 2551 | 2531 | |
| 2552 | − if (fDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) // need get extra slices for update | |
| 2553 | − iSliceCount = GetInitialSliceNum (pCurDq->iMbWidth, pCurDq->iMbHeight, &fDlp->sSliceArgument); | |
| 2554 | − else | |
| 2555 | − iSliceCount = GetCurrentSliceNum (pCurDq); | |
| 2556 | 2532 | assert (iSliceCount > 0); |
| 2557 | 2533 | |
| 2558 | 2534 | int32_t iCurPpsId = pDqIdc->iPpsId; |
| @@ -2809,7 +2785,7 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqId · 250 unmodified lines | ||
| 2809 | 2785 | * \brief prefetch reference picture after WelsBuildRefList |
| 2810 | 2786 | */ |
| 2811 | 2787 | static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) { |
| 2812 | − const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer); | |
| 2788 | + const int32_t kiSliceCount = pCtx->pCurDqLayer->iMaxSliceNum; | |
| 2813 | 2789 | int32_t iIdx = 0; |
| 2814 | 2790 | uint8_t uiRefIdx = -1; |
| 2815 | 2791 | |
| @@ -3494,6 +3470,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 678 unmodified lines | ||
| 3494 | 3470 | pCtx->pSvcParam->sSpatialLayers[pCtx->pSvcParam->iSpatialLayerNum - 1].fFrameRate); |
| 3495 | 3471 | for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) { |
| 3496 | 3472 | pFbi->sLayerInfo[iNalIdx].eFrameType = videoFrameTypeSkip; |
| 3473 | + pFbi->sLayerInfo[iNalIdx].iNalCount = 0; | |
| 3497 | 3474 | } |
| 3498 | 3475 | // perform csc/denoise/downsample/padding, generate spatial layers |
| 3499 | 3476 | iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic); |
| @@ -3666,7 +3643,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 166 unmodified lines | ||
| 3666 | 3643 | |
| 3667 | 3644 | //TODO Complexity Calculation here for screen content |
| 3668 | 3645 | iLayerSize = 0; |
| 3669 | − | |
| 3670 | 3646 | if (SM_SINGLE_SLICE == pParam->sSliceArgument.uiSliceMode) { // only one slice within a sQualityStat layer |
| 3671 | 3647 | int32_t iSliceSize = 0; |
| 3672 | 3648 | int32_t iPayloadSize = 0; |
| @@ -3744,7 +3720,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 71 unmodified lines | ||
| 3744 | 3720 | pLayerBsInfo->eFrameType = eFrameType; |
| 3745 | 3721 | pLayerBsInfo->iSubSeqId = GetSubSequenceId (pCtx, eFrameType); |
| 3746 | 3722 | |
| 3747 | − //InitAllSlicesInThread(pCtx); | |
| 3723 | + int32_t iRet = InitAllSlicesInThread(pCtx); | |
| 3724 | + if (iRet) { | |
| 3725 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 3726 | + "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!", | |
| 3727 | + pParam->sSliceArgument.uiSliceMode); | |
| 3728 | + return ENC_RETURN_UNEXPECTED; | |
| 3729 | + } | |
| 3730 | + | |
| 3748 | 3731 | pCtx->pTaskManage->ExecuteTasks(); |
| 3749 | 3732 | if (pCtx->iEncoderError) { |
| 3750 | 3733 | WelsLog (pLogCtx, WELS_LOG_ERROR, |
| @@ -3753,8 +3736,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 3753 | 3736 | return pCtx->iEncoderError; |
| 3754 | 3737 | } |
| 3755 | 3738 | |
| 3756 | − //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum] | |
| 3757 | − //SliceLayerInfoUpdate (pCtx, pFbi, pLayerBsInfo, 1); | |
| 3739 | + iRet = SliceLayerInfoUpdate (pCtx, pFbi, pLayerBsInfo, pParam->sSliceArgument.uiSliceMode); | |
| 3740 | + if (iRet) { | |
| 3741 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 3742 | + "WelsEncoderEncodeExt(), multi-slice (mode %d) SliceLayerInfoUpdate() error!", | |
| 3743 | + pParam->sSliceArgument.uiSliceMode); | |
| 3744 | + return ENC_RETURN_UNEXPECTED; | |
| 3745 | + } | |
| 3746 | + | |
| 3758 | 3747 | iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount); |
| 3759 | 3748 | } |
| 3760 | 3749 | // THREAD_FULLY_FIRE_MODE && SM_SIZELIMITED_SLICE |
| @@ -3797,6 +3786,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 36 unmodified lines | ||
| 3797 | 3786 | ++ iIdx; |
| 3798 | 3787 | } |
| 3799 | 3788 | |
| 3789 | + int32_t iRet = InitAllSlicesInThread(pCtx); | |
| 3790 | + if (iRet) { | |
| 3791 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 3792 | + "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!", | |
| 3793 | + pParam->sSliceArgument.uiSliceMode); | |
| 3794 | + return ENC_RETURN_UNEXPECTED; | |
| 3795 | + } | |
| 3800 | 3796 | pCtx->pTaskManage->ExecuteTasks(); |
| 3801 | 3797 | |
| 3802 | 3798 | if (pCtx->iEncoderError) { |
| @@ -3805,10 +3801,17 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 3805 | 3801 | pParam->sSliceArgument.uiSliceMode, pCtx->iEncoderError); |
| 3806 | 3802 | return pCtx->iEncoderError; |
| 3807 | 3803 | } |
| 3808 | −#endif | |
| 3809 | − //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum] | |
| 3810 | − // UpdateSliceInLayerInfo(); // reordering | |
| 3811 | − iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt); | |
| 3804 | +#endif | |
| 3805 | + iRet = SliceLayerInfoUpdate (pCtx, pFbi, pLayerBsInfo, pParam->sSliceArgument.uiSliceMode); | |
| 3806 | + if (iRet) { | |
| 3807 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 3808 | + "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!", | |
| 3809 | + pParam->sSliceArgument.uiSliceMode); | |
| 3810 | + return ENC_RETURN_UNEXPECTED; | |
| 3811 | + } | |
| 3812 | + | |
| 3813 | + iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer); | |
| 3814 | + iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount); | |
| 3812 | 3815 | } else { // for non-dynamic-slicing mode single threading branch.. |
| 3813 | 3816 | const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag; |
| 3814 | 3817 | int32_t iSliceIdx = 0; |
| @@ -3833,7 +3836,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 18 unmodified lines | ||
| 3833 | 3836 | pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx]; |
| 3834 | 3837 | assert (iSliceIdx == pCurSlice->iSliceIdx); |
| 3835 | 3838 | pCtx->iEncoderError = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, iSliceIdx); |
| 3836 | − WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3837 | 3839 | |
| 3838 | 3840 | pCtx->iEncoderError = WelsCodeOneSlice (pCtx, pCurSlice, eNalType); |
| 3839 | 3841 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| @@ -4492,13 +4494,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 652 unmodified lines | ||
| 4492 | 4494 | const int32_t kiSliceIdxStep = pCtx->iActiveThreadsNum; |
| 4493 | 4495 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 4494 | 4496 | |
| 4495 | − | |
| 4496 | − //init | |
| 4497 | − { | |
| 4498 | − pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxInPartition; | |
| 4499 | − pCurLayer->pNumSliceCodedOfPartition[kiPartitionId] = 1; | |
| 4500 | − } | |
| 4501 | − pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | |
| 4497 | + pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxInPartition; | |
| 4502 | 4498 | |
| 4503 | 4499 | while (iAnyMbLeftInPartition > 0) { |
| 4504 | 4500 | int32_t iSliceSize = 0; |
| @@ -4530,7 +4526,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 25 unmodified lines | ||
| 4530 | 4526 | |
| 4531 | 4527 | WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc); |
| 4532 | 4528 | pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx]; |
| 4533 | − assert (iSliceIdx == pCurSlice->iSliceIdx); | |
| 4529 | + pCurSlice->iSliceIdx = iSliceIdx; | |
| 4534 | 4530 | |
| 4535 | 4531 | iReturn = WelsCodeOneSlice (pCtx, pCurSlice, keNalType); |
| 4536 | 4532 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| @@ -4558,7 +4554,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 21 unmodified lines | ||
| 4558 | 4554 | |
| 4559 | 4555 | ++ iNalIdxInLayer; |
| 4560 | 4556 | iSliceIdx += kiSliceStep; //if iSliceIdx is not continuous |
| 4561 | − iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId]; | |
| 4557 | + iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId]; | |
| 4562 | 4558 | } |
| 4563 | 4559 | |
| 4564 | 4560 | *pLayerSize = iPartitionBsSize; |