History

Multi-thread-fixed:RBC#1680:ppSliceInLayer instead of pSliceInLayer for all slice buffer management

huade committed 9 years ago

Commit 8ff579b1 parent 01e31ff11 files · +162 −153Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+55−30
@@ -939,6 +939,11 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 938 unmodified lines
939939
940940 FreeSliceInLayer (pDq, pMa);
941941
942+ if (pDq->ppSliceInLayer) {
943+ pMa->WelsFree (pDq->ppSliceInLayer, "pDq->ppSliceInLayer");
944+ pDq->ppSliceInLayer = NULL;
945+ }
946+
942947 if (pDq->pNumSliceCodedOfPartition) {
943948 pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition");
944949 pDq->pNumSliceCodedOfPartition = NULL;
@@ -1059,17 +1064,18 @@ static inline int32_t InitSliceThreadInfo (sWelsEncCtx** ppCtx, · 114 unmodified lines
10591064 pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
10601065 pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) *
10611066 iMaxSliceNumInThread, "pSliceInThread");
1062− if (NULL == pSliceThreadInfo->pSliceInThread[iIdx])
1067+ if(NULL == pSliceThreadInfo->pSliceInThread[iIdx]) {
10631068 return ENC_RETURN_MEMALLOCERR;
1064−
1069+ }
10651070 iRet = InitSliceList (ppCtx,
10661071 pDqLayer,
10671072 pSliceThreadInfo->pSliceInThread[iIdx],
10681073 iMaxSliceNumInThread,
10691074 kiDlayerIndex,
10701075 pMa);
1071− if (ENC_RETURN_SUCCESS != iRet)
1076+ if (ENC_RETURN_SUCCESS != iRet) {
10721077 return iRet;
1078+ }
10731079
10741080 iIdx++;
10751081 }
@@ -1089,34 +1095,43 @@ static inline int32_t InitSliceInLayer (sWelsEncCtx** ppCtx, · 13 unmodified lines
10891095
10901096 //SWelsSvcCodingParam* pParam = (*ppCtx)->pSvcParam;
10911097 int32_t iRet = 0;
1098+ int32_t iSliceIdx = 0;
10921099 int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum;
10931100
1094− //if (pParam->iMultipleThreadIdc > 1) {
1095− // to do, will add later, slice buffer allocated based on thread mode if() else ()
1101+
1102+ pDqLayer->ppSliceInLayer = (SSlice**)pMa->WelsMallocz (sizeof (SSlice*) * iMaxSliceNum, "ppSliceInLayer");
1103+ if(NULL == pDqLayer->ppSliceInLayer) {
1104+ return ENC_RETURN_MEMALLOCERR;
1105+ }
1106+
10961107 InitSliceThreadInfo (ppCtx,
10971108 pDqLayer,
10981109 kiDlayerIndex,
10991110 pMa);
1100− if (ENC_RETURN_SUCCESS != iRet)
1111+ if (ENC_RETURN_SUCCESS != iRet) {
11011112 return iRet;
1102−
1103− //} else {
1113+ }
11041114 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
1105− if (NULL == pDqLayer->sLayerInfo.pSliceInLayer)
1115+ if(NULL == pDqLayer->sLayerInfo.pSliceInLayer) {
11061116 return ENC_RETURN_MEMALLOCERR;
1107−
1117+ }
11081118 InitSliceList (ppCtx,
11091119 pDqLayer,
11101120 pDqLayer->sLayerInfo.pSliceInLayer,
11111121 iMaxSliceNum,
11121122 kiDlayerIndex,
11131123 pMa);
1114− if (ENC_RETURN_SUCCESS != iRet)
1115− return iRet;
1116− //}
1124+ if (ENC_RETURN_SUCCESS != iRet) {
1125+ return iRet;
1126+ }
1127+
1128+ for (iSliceIdx = 0; iSliceIdx < iMaxSliceNum; iSliceIdx++) {
1129+ pDqLayer->ppSliceInLayer[iSliceIdx] = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
1130+ }
11171131
11181132 return ENC_RETURN_SUCCESS;
11191133 }
1134+
11201135 /*!
11211136 * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available
11221137 * \pParam pCtx sWelsEncCtx*
@@ -2553,7 +2568,7 @@ void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) { · 1430 unmodified lines
25532568
25542569 void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) {
25552570 SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
2556− SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
2571+ SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer;
25572572 const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame;
25582573 int32_t iCountMbNumPerPartition = kiMbNumInFrame;
25592574 int32_t iAssignableMbLeft = kiMbNumInFrame;
@@ -2569,18 +2584,18 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 9 unmodified lines
25692584 i = 0;
25702585 while (i < iPartitionNum) {
25712586 if (i + 1 == iPartitionNum) {
2572− pSliceInLayer[i].iCountMbNumInSlice = iAssignableMbLeft;
2587+ ppSliceInLayer[i]->iCountMbNumInSlice = iAssignableMbLeft;
25732588 } else {
2574− pSliceInLayer[i].iCountMbNumInSlice = iCountMbNumPerPartition;
2589+ ppSliceInLayer[i]->iCountMbNumInSlice = iCountMbNumPerPartition;
25752590 }
2576− pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
2591+ ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx;
25772592
25782593 WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i,
2579− pSliceInLayer[i].iCountMbNumInSlice, sizeof (uint16_t));
2594+ ppSliceInLayer[i]->iCountMbNumInSlice, sizeof (uint16_t));
25802595
25812596 // for next partition(or pSlice)
2582− iFirstMbIdx += pSliceInLayer[i].iCountMbNumInSlice;
2583− iAssignableMbLeft -= pSliceInLayer[i].iCountMbNumInSlice;
2597+ iFirstMbIdx += ppSliceInLayer[i]->iCountMbNumInSlice;
2598+ iAssignableMbLeft -= ppSliceInLayer[i]->iCountMbNumInSlice;
25842599 ++ i;
25852600 }
25862601 }
@@ -2646,8 +2661,8 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 59 unmodified lines
26462661 SPicture* pEncPic = pCtx->pEncPic;
26472662 SPicture* pDecPic = pCtx->pDecPic;
26482663 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2649− SSlice* pBaseSlice = &pCurDq->sLayerInfo.pSliceInLayer[0];
2650− SSlice* pSlice = NULL;
2664+ SSlice* pBaseSlice = pCurDq->ppSliceInLayer[0];
2665+ SSlice* pSlice = NULL;
26512666 const uint8_t kiCurDid = pCtx->uiDependencyId;
26522667 const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID);
26532668 SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid];
@@ -2691,10 +2706,10 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 37 unmodified lines
26912706
26922707 pBaseSlice->bSliceHeaderExtFlag = (NAL_UNIT_CODED_SLICE_EXT == pCtx->eNalType);
26932708
2694− pSlice = pBaseSlice;
26952709 iIdx = 1;
26962710 while (iIdx < iSliceCount) {
2697− ++ pSlice;
2711+ pSlice = pCurDq->ppSliceInLayer[iIdx];
2712+
26982713 pSlice->sSliceHeaderExt.sSliceHeader.iPpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iPpsId;
26992714 pSlice->sSliceHeaderExt.sSliceHeader.pPps = pBaseSlice->sSliceHeaderExt.sSliceHeader.pPps;
27002715 pSlice->sSliceHeaderExt.sSliceHeader.iSpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iSpsId;
@@ -2928,7 +2943,6 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqId · 227 unmodified lines
29282943 * \brief prefetch reference picture after WelsBuildRefList
29292944 */
29302945 static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) {
2931− SSlice* pSliceBase = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0];
29322946 const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer);
29332947 int32_t iIdx = 0;
29342948 uint8_t uiRefIdx = -1;
@@ -2946,8 +2960,7 @@ static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFram · 11 unmodified lines
29462960
29472961 iIdx = 0;
29482962 while (iIdx < kiSliceCount) {
2949− pSliceBase->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx;
2950− ++ pSliceBase;
2963+ pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx;
29512964 ++ iIdx;
29522965 }
29532966 }
@@ -3876,7 +3889,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 922 unmodified lines
38763889 int32_t iEndMbIdx = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame;
38773890 for (int32_t iIdx = kiPartitionCnt - 1; iIdx >= 0; --iIdx) {
38783891 const int32_t iFirstMbIdx =
3879− pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
3892+ pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
38803893 pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iStartMbIndex = iFirstMbIdx;
38813894 pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iEndMbIndex = iEndMbIdx;
38823895 iEndMbIdx = iFirstMbIdx;
@@ -4645,6 +4658,19 @@ int32_t SliceBufferRealloc (sWelsEncCtx* pCtx) { · 762 unmodified lines
46454658 pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice");
46464659 pCurLayer->sLayerInfo.pSliceInLayer = pSlice;
46474660
4661+ // update for ppsliceInlayer
4662+ SSlice** ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iMaxSliceNum, "ppSlice");
4663+ if (NULL == ppSlice) {
4664+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: ppSlice is NULL");
4665+ return ENC_RETURN_MEMALLOCERR;
4666+ }
4667+ pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer");
4668+ pCurLayer->ppSliceInLayer = ppSlice;
4669+
4670+ for(uiSliceIdx = 0; uiSliceIdx < iMaxSliceNum; uiSliceIdx++){
4671+ pCurLayer->ppSliceInLayer[uiSliceIdx] = &pCurLayer->sLayerInfo.pSliceInLayer[uiSliceIdx];
4672+ }
4673+
46484674 if (pCtx->iMaxSliceCount < iMaxSliceNum)
46494675 pCtx->iMaxSliceCount = iMaxSliceNum;
46504676 pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNum;
@@ -4678,8 +4704,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 27 unmodified lines
46784704
46794705 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
46804706 SSliceCtx* pSliceCtx = &pCurLayer->sSliceEncCtx;
4681− SSlice* pSliceInLayer = pCurLayer->sLayerInfo.pSliceInLayer;
4682− SSlice* pStartSlice = &pSliceInLayer[iStartSliceIdx];
4707+ SSlice* pStartSlice = pCurLayer->ppSliceInLayer[iStartSliceIdx];
46834708 int32_t iNalIdxInLayer = *pNalIdxInLayer;
46844709 int32_t iSliceIdx = iStartSliceIdx;
46854710 const int32_t kiSliceStep = pCtx->iActiveThreadsNum;

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