Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 7 files). Show all
Unified · Split
| @@ -64,8 +64,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 63 unmodified lines | ||
| 64 | 64 | SLayerBSInfo* pLayerBsInfo, |
| 65 | 65 | int32_t* pNalIdxInLayer, |
| 66 | 66 | int32_t* pLayerSize, |
| 67 | − int32_t iFirstMbInPartition, // first mb inclusive in partition | |
| 68 | − int32_t iEndMbInPartition, // end mb exclusive in partition | |
| 67 | + int32_t iFirstMbIdxInPartition, | |
| 68 | + int32_t iEndMbIdxInPartition, | |
| 69 | 69 | int32_t iStartSliceIdx |
| 70 | 70 | ); |
| 71 | 71 | |
| @@ -952,9 +952,15 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 880 unmodified lines | ||
| 952 | 952 | pMa->WelsFree (pDq->pLastCodedMbIdxOfPartition, "pLastCodedMbIdxOfPartition"); |
| 953 | 953 | pDq->pLastCodedMbIdxOfPartition = NULL; |
| 954 | 954 | } |
| 955 | − if (pDq->pLastMbIdxOfPartition) { | |
| 956 | − pMa->WelsFree (pDq->pLastMbIdxOfPartition, "pLastMbIdxOfPartition"); | |
| 957 | − pDq->pLastMbIdxOfPartition = NULL; | |
| 955 | + | |
| 956 | + if (pDq->pFirstMbIdxOfPartition) { | |
| 957 | + pMa->WelsFree (pDq->pFirstMbIdxOfPartition, "pFirstMbIdxOfPartition"); | |
| 958 | + pDq->pFirstMbIdxOfPartition = NULL; | |
| 959 | + } | |
| 960 | + | |
| 961 | + if (pDq->pEndMbIdxOfPartition) { | |
| 962 | + pMa->WelsFree (pDq->pEndMbIdxOfPartition, "pEndMbIdxOfPartition"); | |
| 963 | + pDq->pEndMbIdxOfPartition = NULL; | |
| 958 | 964 | } |
| 959 | 965 | |
| 960 | 966 | if (pDq->pFeatureSearchPreparation) { |
| @@ -1073,11 +1079,13 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 112 unmodified lines | ||
| 1073 | 1079 | |
| 1074 | 1080 | pDqLayer->pNumSliceCodedOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pNumSliceCodedOfPartition"); |
| 1075 | 1081 | pDqLayer->pLastCodedMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pLastCodedMbIdxOfPartition"); |
| 1076 | − pDqLayer->pLastMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pLastMbIdxOfPartition"); | |
| 1082 | + pDqLayer->pFirstMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pFirstMbIdxOfPartition"); | |
| 1083 | + pDqLayer->pEndMbIdxOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pEndMbIdxOfPartition"); | |
| 1077 | 1084 | WELS_VERIFY_RETURN_PROC_IF (1, |
| 1078 | − (NULL == pDqLayer->pNumSliceCodedOfPartition || | |
| 1085 | + (NULL == pDqLayer->pNumSliceCodedOfPartition || | |
| 1079 | 1086 | NULL == pDqLayer->pLastCodedMbIdxOfPartition || |
| 1080 | − NULL == pDqLayer->pLastMbIdxOfPartition), | |
| 1087 | + NULL == pDqLayer->pFirstMbIdxOfPartition || | |
| 1088 | + NULL == pDqLayer->pEndMbIdxOfPartition), | |
| 1081 | 1089 | FreeDqLayer (pDqLayer, pMa)) |
| 1082 | 1090 | } |
| 1083 | 1091 | pDqLayer->bNeedAdjustingSlicing = false; |
| @@ -2423,10 +2431,10 @@ void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) { · 1339 unmodified lines | ||
| 2423 | 2431 | |
| 2424 | 2432 | void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { |
| 2425 | 2433 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; |
| 2426 | − SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer; | |
| 2427 | 2434 | const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame; |
| 2428 | 2435 | int32_t iCountMbNumPerPartition = kiMbNumInFrame; |
| 2429 | 2436 | int32_t iAssignableMbLeft = kiMbNumInFrame; |
| 2437 | + int32_t iCountMbNumInPartition = 0; | |
| 2430 | 2438 | int32_t iFirstMbIdx = 0; |
| 2431 | 2439 | int32_t i/*, j*/; |
| 2432 | 2440 | |
| @@ -2439,18 +2447,20 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 6 unmodified lines | ||
| 2439 | 2447 | i = 0; |
| 2440 | 2448 | while (i < iPartitionNum) { |
| 2441 | 2449 | if (i + 1 == iPartitionNum) { |
| 2442 | − ppSliceInLayer[i]->iCountMbNumInSlice = iAssignableMbLeft; | |
| 2450 | + iCountMbNumInPartition = iAssignableMbLeft; | |
| 2443 | 2451 | } else { |
| 2444 | − ppSliceInLayer[i]->iCountMbNumInSlice = iCountMbNumPerPartition; | |
| 2452 | + iCountMbNumInPartition = iCountMbNumPerPartition; | |
| 2445 | 2453 | } |
| 2446 | − ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx; | |
| 2454 | + | |
| 2455 | + pCurDq->pFirstMbIdxOfPartition[i] = iFirstMbIdx; | |
| 2456 | + pCurDq->pEndMbIdxOfPartition[i] = iFirstMbIdx + iCountMbNumInPartition - 1; | |
| 2447 | 2457 | |
| 2448 | 2458 | WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i, |
| 2449 | − ppSliceInLayer[i]->iCountMbNumInSlice, sizeof (uint16_t)); | |
| 2459 | + iCountMbNumInPartition, sizeof (uint16_t)); | |
| 2450 | 2460 | |
| 2451 | 2461 | // for next partition(or pSlice) |
| 2452 | − iFirstMbIdx += ppSliceInLayer[i]->iCountMbNumInSlice; | |
| 2453 | − iAssignableMbLeft -= ppSliceInLayer[i]->iCountMbNumInSlice; | |
| 2462 | + iFirstMbIdx += iCountMbNumInPartition; | |
| 2463 | + iAssignableMbLeft -= iCountMbNumInPartition; | |
| 2454 | 2464 | ++ i; |
| 2455 | 2465 | } |
| 2456 | 2466 | } |
| @@ -3690,7 +3700,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1233 unmodified lines | ||
| 3690 | 3700 | else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) { |
| 3691 | 3701 | const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame; |
| 3692 | 3702 | pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pFbi, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, |
| 3693 | − kiLastMbInFrame, 0); | |
| 3703 | + kiLastMbInFrame - 1, 0); | |
| 3694 | 3704 | pLayerBsInfo->eFrameType = eFrameType; |
| 3695 | 3705 | pLayerBsInfo->iSubSeqId = GetSubSequenceId (pCtx, eFrameType); |
| 3696 | 3706 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| @@ -3736,15 +3746,24 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 39 unmodified lines | ||
| 3736 | 3746 | else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) { |
| 3737 | 3747 | const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; |
| 3738 | 3748 | |
| 3739 | − int32_t iEndMbIdx = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame; | |
| 3740 | − for (int32_t iIdx = kiPartitionCnt - 1; iIdx >= 0; --iIdx) { | |
| 3741 | − const int32_t iFirstMbIdx = | |
| 3742 | − pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; | |
| 3743 | − pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iStartMbIndex = iFirstMbIdx; | |
| 3744 | − pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iEndMbIndex = iEndMbIdx; | |
| 3745 | − iEndMbIdx = iFirstMbIdx; | |
| 3749 | +#if 0 //TODO: temporarily use this to keep old codes for a while, will remove old codes later | |
| 3750 | + int32_t iRet = 0; | |
| 3751 | + // to fire slice coding threads | |
| 3752 | + iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0], | |
| 3753 | + &pCtx->pSliceThreading->pReadySliceCodingEvent[0], | |
| 3754 | + &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3755 | + pFbi, kiPartitionCnt); | |
| 3756 | + if (iRet) { | |
| 3757 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 3758 | + "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!", | |
| 3759 | + iRet, iSliceCount, pParam->sSliceArgument.uiSliceMode, pSvcParam->iMultipleThreadIdc); | |
| 3760 | + return ENC_RETURN_UNEXPECTED; | |
| 3746 | 3761 | } |
| 3747 | 3762 | |
| 3763 | + WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0], | |
| 3764 | + &pCtx->pSliceThreading->pSliceCodedMasterEvent); | |
| 3765 | + WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3766 | +#else | |
| 3748 | 3767 | //TODO: use a function to remove duplicate code here and ln3994 |
| 3749 | 3768 | int32_t iLayerBsIdx = pCtx->pOut->iLayerBsIndex; |
| 3750 | 3769 | SLayerBSInfo* pLbi = &pFbi->sLayerInfo[iLayerBsIdx]; |
| @@ -3771,13 +3790,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 20 unmodified lines | ||
| 3771 | 3790 | pParam->sSliceArgument.uiSliceMode, pCtx->iEncoderError); |
| 3772 | 3791 | return pCtx->iEncoderError; |
| 3773 | 3792 | } |
| 3774 | − | |
| 3775 | − //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum] | |
| 3776 | − // UpdateSliceInLayerInfo(); // reordering | |
| 3777 | − | |
| 3778 | − //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum] | |
| 3779 | − // UpdateSliceInLayerInfo(); // reordering | |
| 3780 | − | |
| 3793 | +#endif | |
| 3781 | 3794 | //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum] |
| 3782 | 3795 | // UpdateSliceInLayerInfo(); // reordering |
| 3783 | 3796 | |
| @@ -4480,8 +4493,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 696 unmodified lines | ||
| 4480 | 4493 | SLayerBSInfo* pLayerBsInfo, |
| 4481 | 4494 | int32_t* pNalIdxInLayer, |
| 4482 | 4495 | int32_t* pLayerSize, |
| 4483 | − int32_t iFirstMbInPartition, // first mb inclusive in partition | |
| 4484 | − int32_t iEndMbInPartition, // end mb exclusive in partition | |
| 4496 | + int32_t iFirstMbIdxInPartition, | |
| 4497 | + int32_t iEndMbIdxInPartition, | |
| 4485 | 4498 | int32_t iStartSliceIdx |
| 4486 | 4499 | ) { |
| 4487 | 4500 | |
| @@ -4493,7 +4506,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 5 unmodified lines | ||
| 4493 | 4506 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; |
| 4494 | 4507 | const int32_t kiPartitionId = iStartSliceIdx % kiSliceStep; |
| 4495 | 4508 | int32_t iPartitionBsSize = 0; |
| 4496 | − int32_t iAnyMbLeftInPartition = iEndMbInPartition - iFirstMbInPartition; | |
| 4509 | + int32_t iAnyMbLeftInPartition = iEndMbIdxInPartition - iFirstMbIdxInPartition + 1; | |
| 4497 | 4510 | const EWelsNalUnitType keNalType = pCtx->eNalType; |
| 4498 | 4511 | const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority; |
| 4499 | 4512 | const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag; |
| @@ -4502,10 +4515,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 2 unmodified lines | ||
| 4502 | 4515 | |
| 4503 | 4516 | //init |
| 4504 | 4517 | { |
| 4505 | − pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbInPartition; | |
| 4506 | − pCurLayer->pNumSliceCodedOfPartition[kiPartitionId] = | |
| 4507 | − 1; // one slice per partition intialized, dynamic slicing inside | |
| 4508 | − pCurLayer->pLastMbIdxOfPartition[kiPartitionId] = iEndMbInPartition - 1; | |
| 4518 | + pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdxInPartition; | |
| 4519 | + pCurLayer->pNumSliceCodedOfPartition[kiPartitionId] = 1; | |
| 4509 | 4520 | } |
| 4510 | 4521 | pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; |
| 4511 | 4522 | |
| @@ -4563,7 +4574,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 51 unmodified lines | ||
| 4563 | 4574 | |
| 4564 | 4575 | ++ iNalIdxInLayer; |
| 4565 | 4576 | iSliceIdx += kiSliceStep; //if uiSliceIdx is not continuous |
| 4566 | − iAnyMbLeftInPartition = iEndMbInPartition - (1 + pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId]); | |
| 4577 | + iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId]; | |
| 4567 | 4578 | } |
| 4568 | 4579 | |
| 4569 | 4580 | *pLayerSize = iPartitionBsSize; |