History

Multi-thread-fixed:RBC#1710:move PartitionMBIdx info from slice thread private to layer data structure and refactoring for its int/update module

Huade Shi (huashi) committed 9 years ago

Commit 0d84ead1 parent 83305d87 files · +73 −83Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+49−38
@@ -64,8 +64,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 63 unmodified lines
6464 SLayerBSInfo* pLayerBsInfo,
6565 int32_t* pNalIdxInLayer,
6666 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,
6969 int32_t iStartSliceIdx
7070 );
7171
@@ -952,9 +952,15 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 880 unmodified lines
952952 pMa->WelsFree (pDq->pLastCodedMbIdxOfPartition, "pLastCodedMbIdxOfPartition");
953953 pDq->pLastCodedMbIdxOfPartition = NULL;
954954 }
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;
958964 }
959965
960966 if (pDq->pFeatureSearchPreparation) {
@@ -1073,11 +1079,13 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 112 unmodified lines
10731079
10741080 pDqLayer->pNumSliceCodedOfPartition = (int32_t*)pMa->WelsMallocz (iSize, "pNumSliceCodedOfPartition");
10751081 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");
10771084 WELS_VERIFY_RETURN_PROC_IF (1,
1078− (NULL == pDqLayer->pNumSliceCodedOfPartition ||
1085+ (NULL == pDqLayer->pNumSliceCodedOfPartition ||
10791086 NULL == pDqLayer->pLastCodedMbIdxOfPartition ||
1080− NULL == pDqLayer->pLastMbIdxOfPartition),
1087+ NULL == pDqLayer->pFirstMbIdxOfPartition ||
1088+ NULL == pDqLayer->pEndMbIdxOfPartition),
10811089 FreeDqLayer (pDqLayer, pMa))
10821090 }
10831091 pDqLayer->bNeedAdjustingSlicing = false;
@@ -2423,10 +2431,10 @@ void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) { · 1339 unmodified lines
24232431
24242432 void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) {
24252433 SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
2426− SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
24272434 const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame;
24282435 int32_t iCountMbNumPerPartition = kiMbNumInFrame;
24292436 int32_t iAssignableMbLeft = kiMbNumInFrame;
2437+ int32_t iCountMbNumInPartition = 0;
24302438 int32_t iFirstMbIdx = 0;
24312439 int32_t i/*, j*/;
24322440
@@ -2439,18 +2447,20 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 6 unmodified lines
24392447 i = 0;
24402448 while (i < iPartitionNum) {
24412449 if (i + 1 == iPartitionNum) {
2442− ppSliceInLayer[i]->iCountMbNumInSlice = iAssignableMbLeft;
2450+ iCountMbNumInPartition = iAssignableMbLeft;
24432451 } else {
2444− ppSliceInLayer[i]->iCountMbNumInSlice = iCountMbNumPerPartition;
2452+ iCountMbNumInPartition = iCountMbNumPerPartition;
24452453 }
2446− ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
2454+
2455+ pCurDq->pFirstMbIdxOfPartition[i] = iFirstMbIdx;
2456+ pCurDq->pEndMbIdxOfPartition[i] = iFirstMbIdx + iCountMbNumInPartition - 1;
24472457
24482458 WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i,
2449− ppSliceInLayer[i]->iCountMbNumInSlice, sizeof (uint16_t));
2459+ iCountMbNumInPartition, sizeof (uint16_t));
24502460
24512461 // for next partition(or pSlice)
2452− iFirstMbIdx += ppSliceInLayer[i]->iCountMbNumInSlice;
2453− iAssignableMbLeft -= ppSliceInLayer[i]->iCountMbNumInSlice;
2462+ iFirstMbIdx += iCountMbNumInPartition;
2463+ iAssignableMbLeft -= iCountMbNumInPartition;
24542464 ++ i;
24552465 }
24562466 }
@@ -3690,7 +3700,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1233 unmodified lines
36903700 else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) {
36913701 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame;
36923702 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pFbi, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0,
3693− kiLastMbInFrame, 0);
3703+ kiLastMbInFrame - 1, 0);
36943704 pLayerBsInfo->eFrameType = eFrameType;
36953705 pLayerBsInfo->iSubSeqId = GetSubSequenceId (pCtx, eFrameType);
36963706 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
37363746 else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
37373747 const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum;
37383748
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;
37463761 }
37473762
3763+ WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0],
3764+ &pCtx->pSliceThreading->pSliceCodedMasterEvent);
3765+ WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3766+#else
37483767 //TODO: use a function to remove duplicate code here and ln3994
37493768 int32_t iLayerBsIdx = pCtx->pOut->iLayerBsIndex;
37503769 SLayerBSInfo* pLbi = &pFbi->sLayerInfo[iLayerBsIdx];
@@ -3771,13 +3790,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 20 unmodified lines
37713790 pParam->sSliceArgument.uiSliceMode, pCtx->iEncoderError);
37723791 return pCtx->iEncoderError;
37733792 }
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
37813794 //TO DO: add update ppSliceInLayer module based on pSliceInThread[ThreadNum]
37823795 // UpdateSliceInLayerInfo(); // reordering
37833796
@@ -4480,8 +4493,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 696 unmodified lines
44804493 SLayerBSInfo* pLayerBsInfo,
44814494 int32_t* pNalIdxInLayer,
44824495 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,
44854498 int32_t iStartSliceIdx
44864499 ) {
44874500
@@ -4493,7 +4506,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 5 unmodified lines
44934506 const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
44944507 const int32_t kiPartitionId = iStartSliceIdx % kiSliceStep;
44954508 int32_t iPartitionBsSize = 0;
4496− int32_t iAnyMbLeftInPartition = iEndMbInPartition - iFirstMbInPartition;
4509+ int32_t iAnyMbLeftInPartition = iEndMbIdxInPartition - iFirstMbIdxInPartition + 1;
44974510 const EWelsNalUnitType keNalType = pCtx->eNalType;
44984511 const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority;
44994512 const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag;
@@ -4502,10 +4515,8 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 2 unmodified lines
45024515
45034516 //init
45044517 {
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;
45094520 }
45104521 pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = 0;
45114522
@@ -4563,7 +4574,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 51 unmodified lines
45634574
45644575 ++ iNalIdxInLayer;
45654576 iSliceIdx += kiSliceStep; //if uiSliceIdx is not continuous
4566− iAnyMbLeftInPartition = iEndMbInPartition - (1 + pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId]);
4577+ iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId];
45674578 }
45684579
45694580 *pLayerSize = iPartitionBsSize;

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