History

Multi-thread-fixed:RBC#1751:Dynamic slice mode under multiThread reallocate feature enable

huade committed 9 years ago

Commit 095f0b61 parent 623599014 files · +325 −336Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+62−66
@@ -927,7 +927,7 @@ void FreeSliceInLayer (SDqLayer* pDq, CMemoryAlign* pMa) { · 926 unmodified lines
927927 for (; iIdx < MAX_THREADS_NUM; iIdx ++) {
928928 FreeSliceBuffer (pDq->sSliceThreadInfo.pSliceInThread[iIdx],
929929 pDq->sSliceThreadInfo.iMaxSliceNumInThread[iIdx],
930− pMa, "pSliceInLayer");
930+ pMa, "pSliceInThread");
931931 }
932932 }
933933
@@ -939,40 +939,20 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 5 unmodified lines
939939 FreeSliceInLayer (pDq, pMa);
940940
941941 if (pDq->ppSliceInLayer) {
942− pMa->WelsFree (pDq->ppSliceInLayer, "pDq->ppSliceInLayer");
942+ pMa->WelsFree (pDq->ppSliceInLayer, "ppSliceInLayer");
943943 pDq->ppSliceInLayer = NULL;
944944 }
945945
946946 if (pDq->pFirstMbIdxOfSlice) {
947− pMa->WelsFree (pDq->pFirstMbIdxOfSlice, "pDq->pFirstMbIdxOfSlice");
947+ pMa->WelsFree (pDq->pFirstMbIdxOfSlice, "pFirstMbIdxOfSlice");
948948 pDq->pFirstMbIdxOfSlice = NULL;
949949 }
950950
951951 if (pDq->pCountMbNumInSlice) {
952− pMa->WelsFree (pDq->pCountMbNumInSlice, "pDq->pCountMbNumInSlice");
952+ pMa->WelsFree (pDq->pCountMbNumInSlice, "pCountMbNumInSlice");
953953 pDq->pCountMbNumInSlice = NULL;
954954 }
955955
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−
976956 if (pDq->pFeatureSearchPreparation) {
977957 ReleaseFeatureSearchPreparation (pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock);
978958 pMa->WelsFree (pDq->pFeatureSearchPreparation, "pFeatureSearchPreparation");
@@ -1083,21 +1063,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 104 unmodified lines
10831063 pDqLayer = (SDqLayer*)pMa->WelsMallocz (sizeof (SDqLayer), "pDqLayer");
10841064 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer), FreeDqLayer (pDqLayer, pMa))
10851065
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− }
11011066 pDqLayer->bNeedAdjustingSlicing = false;
11021067
11031068 pDqLayer->iMbWidth = kiMbW;
@@ -2453,7 +2418,13 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 1349 unmodified lines
24532418 else if (iPartitionNum > AVERSLICENUM_CONSTRAINT)
24542419 iPartitionNum = AVERSLICENUM_CONSTRAINT; // AVERSLICENUM_CONSTRAINT might be variable, however not fixed by MACRO
24552420 iCountMbNumPerPartition /= iPartitionNum;
2421+ if(iCountMbNumPerPartition == 0 || iCountMbNumPerPartition == 1) {
2422+ iCountMbNumPerPartition = kiMbNumInFrame;
2423+ iPartitionNum = 1;
2424+ }
2425+
24562426 pSliceCtx->iSliceNumInFrame = iPartitionNum;
2427+
24572428 i = 0;
24582429 while (i < iPartitionNum) {
24592430 if (i + 1 == iPartitionNum) {
@@ -2462,8 +2433,10 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 2 unmodified lines
24622433 iCountMbNumInPartition = iCountMbNumPerPartition;
24632434 }
24642435
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;
24672440
24682441 WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i,
24692442 iCountMbNumInPartition, sizeof (uint16_t));
@@ -2473,6 +2446,14 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 3 unmodified lines
24732446 iAssignableMbLeft -= iCountMbNumInPartition;
24742447 ++ i;
24752448 }
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+ }
24762457 }
24772458
24782459 void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) {
@@ -2537,22 +2518,17 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 58 unmodified lines
25372518 SSlice* pBaseSlice = pCurDq->ppSliceInLayer[0];
25382519 const uint8_t kiCurDid = pCtx->uiDependencyId;
25392520 const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID);
2540− SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid];
25412521 SNalUnitHeaderExt* pNalHdExt = &pCurDq->sLayerInfo.sNalHeaderExt;
25422522 SNalUnitHeader* pNalHd = &pNalHdExt->sNalUnitHeader;
25432523 SDqIdc* pDqIdc = &pCtx->pDqIdcMap[kiCurDid];
25442524 int32_t iIdx = 0;
2545− int32_t iSliceCount = 0;
2525+ int32_t iSliceCount = pCurDq->iMaxSliceNum;
25462526 SSpatialLayerInternal* pParamInternal = &pParam->sDependencyLayers[kiCurDid];
25472527 if (NULL == pCurDq || NULL == pBaseSlice)
25482528 return;
25492529
25502530 pCurDq->pDecPic = pDecPic;
25512531
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);
25562532 assert (iSliceCount > 0);
25572533
25582534 int32_t iCurPpsId = pDqIdc->iPpsId;
@@ -2809,7 +2785,7 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqId · 250 unmodified lines
28092785 * \brief prefetch reference picture after WelsBuildRefList
28102786 */
28112787 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;
28132789 int32_t iIdx = 0;
28142790 uint8_t uiRefIdx = -1;
28152791
@@ -3494,6 +3470,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 678 unmodified lines
34943470 pCtx->pSvcParam->sSpatialLayers[pCtx->pSvcParam->iSpatialLayerNum - 1].fFrameRate);
34953471 for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) {
34963472 pFbi->sLayerInfo[iNalIdx].eFrameType = videoFrameTypeSkip;
3473+ pFbi->sLayerInfo[iNalIdx].iNalCount = 0;
34973474 }
34983475 // perform csc/denoise/downsample/padding, generate spatial layers
34993476 iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, pSrcPic);
@@ -3666,7 +3643,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 166 unmodified lines
36663643
36673644 //TODO Complexity Calculation here for screen content
36683645 iLayerSize = 0;
3669−
36703646 if (SM_SINGLE_SLICE == pParam->sSliceArgument.uiSliceMode) { // only one slice within a sQualityStat layer
36713647 int32_t iSliceSize = 0;
36723648 int32_t iPayloadSize = 0;
@@ -3744,7 +3720,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 71 unmodified lines
37443720 pLayerBsInfo->eFrameType = eFrameType;
37453721 pLayerBsInfo->iSubSeqId = GetSubSequenceId (pCtx, eFrameType);
37463722
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+
37483731 pCtx->pTaskManage->ExecuteTasks();
37493732 if (pCtx->iEncoderError) {
37503733 WelsLog (pLogCtx, WELS_LOG_ERROR,
@@ -3753,8 +3736,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
37533736 return pCtx->iEncoderError;
37543737 }
37553738
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+
37583747 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
37593748 }
37603749 // THREAD_FULLY_FIRE_MODE && SM_SIZELIMITED_SLICE
@@ -3797,6 +3786,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 36 unmodified lines
37973786 ++ iIdx;
37983787 }
37993788
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+ }
38003796 pCtx->pTaskManage->ExecuteTasks();
38013797
38023798 if (pCtx->iEncoderError) {
@@ -3805,10 +3801,17 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
38053801 pParam->sSliceArgument.uiSliceMode, pCtx->iEncoderError);
38063802 return pCtx->iEncoderError;
38073803 }
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);
38123815 } else { // for non-dynamic-slicing mode single threading branch..
38133816 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
38143817 int32_t iSliceIdx = 0;
@@ -3833,7 +3836,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 18 unmodified lines
38333836 pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx];
38343837 assert (iSliceIdx == pCurSlice->iSliceIdx);
38353838 pCtx->iEncoderError = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, iSliceIdx);
3836− WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
38373839
38383840 pCtx->iEncoderError = WelsCodeOneSlice (pCtx, pCurSlice, eNalType);
38393841 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
@@ -4492,13 +4494,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 652 unmodified lines
44924494 const int32_t kiSliceIdxStep = pCtx->iActiveThreadsNum;
44934495 int32_t iReturn = ENC_RETURN_SUCCESS;
44944496
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;
45024498
45034499 while (iAnyMbLeftInPartition > 0) {
45044500 int32_t iSliceSize = 0;
@@ -4530,7 +4526,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 25 unmodified lines
45304526
45314527 WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc);
45324528 pCurSlice = &pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[uiTheadIdx][iSliceIdx];
4533− assert (iSliceIdx == pCurSlice->iSliceIdx);
4529+ pCurSlice->iSliceIdx = iSliceIdx;
45344530
45354531 iReturn = WelsCodeOneSlice (pCtx, pCurSlice, keNalType);
45364532 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
@@ -4558,7 +4554,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 21 unmodified lines
45584554
45594555 ++ iNalIdxInLayer;
45604556 iSliceIdx += kiSliceStep; //if iSliceIdx is not continuous
4561− iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId];
4557+ iAnyMbLeftInPartition = iEndMbIdxInPartition - pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId];
45624558 }
45634559
45644560 *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