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