History

remove (ppCtx)->pSliceCtxList and only keep DqLayer->sSliceCtx to simply the structure manage

huade committed 10 years ago

Commit 35ab32b1 parent f9d8e9a10 files · +67 −84Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+33−46
@@ -764,7 +764,7 @@ static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, con · 763 unmodified lines
764764 int32_t iMbHeight = pLayer->iMbHeight;
765765 int32_t iIdx;
766766 int32_t iMbNum = iMbWidth * iMbHeight;
767− SSliceCtx* pSliceCtx = pLayer->pSliceEncCtx;
767+ SSliceCtx* pSliceCtx = &pLayer->sSliceEncCtx;
768768 uint32_t uiNeighborAvail;
769769 const int32_t kiOffset = (kiDlayerId & 0x01) * kiMaxMbNum;
770770 SMVUnitXY (*pLayerMvUnitBlock4x4)[MB_BLOCK4x4_NUM] = (SMVUnitXY (*)[MB_BLOCK4x4_NUM]) (
@@ -1361,7 +1361,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 590 unmodified lines
13611361
13621362 // Not using FMO in SVC coding so far, come back if need FMO
13631363 {
1364− iResult = InitSlicePEncCtx (& (*ppCtx)->pSliceCtxList[iDlayerIndex],
1364+ iResult = InitSlicePEncCtx (&(*ppCtx)->ppDqLayerList[iDlayerIndex]->sSliceEncCtx,
13651365 (*ppCtx)->pMemAlign,
13661366 false,
13671367 pSps->iMbWidth,
@@ -1373,7 +1373,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 5 unmodified lines
13731373 FreeMemorySvc (ppCtx);
13741374 return iResult;
13751375 }
1376− (*ppCtx)->ppDqLayerList[iDlayerIndex]->pSliceEncCtx = & (*ppCtx)->pSliceCtxList[iDlayerIndex];
13771376 }
13781377 pDqIdc->iSpsId = iSpsId;
13791378 pDqIdc->iPpsId = iPpsId;
@@ -1860,10 +1859,6 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 480 unmodified lines
18601859 (*ppCtx)->ppRefPicListExt = (SRefList**)pMa->WelsMalloc (kiNumDependencyLayers * sizeof (SRefList*), "ppRefPicListExt");
18611860 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->ppRefPicListExt), FreeMemorySvc (ppCtx))
18621861
1863− // pSlice context list
1864− (*ppCtx)->pSliceCtxList = (SSliceCtx*)pMa->WelsMallocz (kiNumDependencyLayers * sizeof (SSliceCtx), "pSliceCtxList");
1865− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceCtxList), FreeMemorySvc (ppCtx))
1866−
18671862 (*ppCtx)->ppDqLayerList = (SDqLayer**)pMa->WelsMalloc (kiNumDependencyLayers * sizeof (SDqLayer*), "ppDqLayerList");
18681863 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->ppDqLayerList), FreeMemorySvc (ppCtx))
18691864
@@ -2096,8 +2091,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 226 unmodified lines
20962091 int32_t iSliceIdx = 0;
20972092 int32_t iSliceNum = GetInitialSliceNum (pDq->iMbWidth, pDq->iMbHeight, &pDlp->sSliceArgument);
20982093 if (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE && pCtx->iActiveThreadsNum == 1) {
2099− if (iSliceNum < pDq->pSliceEncCtx->iMaxSliceNumConstraint) {
2100− iSliceNum = pDq->pSliceEncCtx->iMaxSliceNumConstraint;
2094+ if (iSliceNum < pDq->sSliceEncCtx.iMaxSliceNumConstraint) {
2095+ iSliceNum = pDq->sSliceEncCtx.iMaxSliceNumConstraint;
21012096 }
21022097 }
21032098 if (iSliceNum < 1)
@@ -2125,6 +2120,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 21 unmodified lines
21252120 pDq->pFeatureSearchPreparation = NULL;
21262121 }
21272122
2123+ SSliceCtx* pSliceCtx = &pDq->sSliceEncCtx;
2124+ if (NULL != pSliceCtx) {
2125+ UninitSlicePEncCtx (pSliceCtx, pMa);
2126+ }
2127+
21282128 pMa->WelsFree (pDq, "pDq");
21292129 pDq = NULL;
21302130 pCtx->ppDqLayerList[ilayer] = NULL;
@@ -2158,19 +2158,6 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 27 unmodified lines
21582158 pCtx->ppRefPicListExt = NULL;
21592159 }
21602160
2161− // pSlice context list
2162− if (NULL != pCtx->pSliceCtxList && pParam != NULL) {
2163− ilayer = 0;
2164− while (ilayer < pParam->iSpatialLayerNum) {
2165− SSliceCtx* pSliceCtx = &pCtx->pSliceCtxList[ilayer];
2166− if (NULL != pSliceCtx)
2167− UninitSlicePEncCtx (pSliceCtx, pMa);
2168− ++ ilayer;
2169− }
2170− pMa->WelsFree (pCtx->pSliceCtxList, "pSliceCtxList");
2171− pCtx->pSliceCtxList = NULL;
2172− }
2173−
21742161 // VAA
21752162 if (NULL != pCtx->pVaa) {
21762163 if (pCtx->pSvcParam->bEnableAdaptiveQuant) { //free mem
@@ -2758,14 +2745,14 @@ int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) { · 581 unmodified lines
27582745 void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {
27592746 //pData init
27602747 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2761− SSliceCtx* pSliceCtx = (pCurDq->pSliceEncCtx);
2748+ SSliceCtx* pSliceCtx = &(pCurDq->sSliceEncCtx);
27622749
27632750 //mb_neighbor
27642751 DynslcUpdateMbNeighbourInfoListForAllSlices (pSliceCtx, pCurDq->sMbDataP);
27652752 }
27662753
27672754 void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) {
2768− SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx;
2755+ SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
27692756 const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame;
27702757 int32_t iCountMbNumPerPartition = kiMbNumInFrame;
27712758 int32_t iAssignableMbLeft = kiMbNumInFrame;
@@ -2799,7 +2786,7 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 27 unmodified lines
27992786
28002787 void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) {
28012788 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2802− SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx;
2789+ SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
28032790
28042791 UpdateSlicepEncCtxWithPartition (pCurDq, iPartitionNum);
28052792
@@ -2877,7 +2864,7 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 71 unmodified lines
28772864 if (fDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE) // need get extra slices for update
28782865 iSliceCount = GetInitialSliceNum (pCurDq->iMbWidth, pCurDq->iMbHeight, &fDlp->sSliceArgument);
28792866 else
2880− iSliceCount = GetCurrentSliceNum (pCurDq->pSliceEncCtx);
2867+ iSliceCount = GetCurrentSliceNum (&pCurDq->sSliceEncCtx);
28812868 assert (iSliceCount > 0);
28822869
28832870 int32_t iCurPpsId = pDqIdc->iPpsId;
@@ -3140,7 +3127,7 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqId · 256 unmodified lines
31403127 */
31413128 static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) {
31423129 SSlice* pSliceBase = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0];
3143− const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
3130+ const int32_t kiSliceCount = GetCurrentSliceNum (&pCtx->pCurDqLayer->sSliceEncCtx);
31443131 int32_t iIdx = 0;
31453132 uint8_t uiRefIdx = -1;
31463133
@@ -4019,7 +4006,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 872 unmodified lines
40194006 }
40204007 // for dynamic slicing single threading..
40214008 else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) {
4022− const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;
4009+ const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame;
40234010 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pFbi, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0,
40244011 kiLastMbInFrame, 0);
40254012 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
@@ -4028,7 +4015,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
40284015 int32_t iRet = 0;
40294016 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_SIZELIMITED_SLICE
40304017 if ((SM_SIZELIMITED_SLICE != pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
4031− iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
4018+ iSliceCount = GetCurrentSliceNum (&pCtx->pCurDqLayer->sSliceEncCtx);
40324019 if (iLayerNum + 1 >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info for further writing as followed
40334020 WelsLog (pLogCtx, WELS_LOG_ERROR,
40344021 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",
@@ -4061,7 +4048,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 26 unmodified lines
40614048 iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
40624049 &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
40634050 &pCtx->pSliceThreading->pThreadMasterEvent[0],
4064− pFbi, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
4051+ pFbi, kiPartitionCnt, &pCtx->pCurDqLayer->sSliceEncCtx, true);
40654052 if (iRet) {
40664053 WelsLog (pLogCtx, WELS_LOG_ERROR,
40674054 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
@@ -4078,7 +4065,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines
40784065 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
40794066 int32_t iSliceIdx = 0;
40804067
4081− iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
4068+ iSliceCount = GetCurrentSliceNum (&pCtx->pCurDqLayer->sSliceEncCtx);
40824069 while (iSliceIdx < iSliceCount) {
40834070 int32_t iSliceSize = 0;
40844071 int32_t iPayloadSize = 0;
@@ -4314,7 +4301,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 229 unmodified lines
43144301 && pSvcParam->bUseLoadBalancing
43154302 && pSvcParam->iMultipleThreadIdc > 1 &&
43164303 pSvcParam->iMultipleThreadIdc >= pParam->sSliceArgument.uiSliceNum) {
4317− CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,
4304+ CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], &pCtx->pCurDqLayer->sSliceEncCtx,
43184305 pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]);
43194306 #if defined(MT_DEBUG)
43204307 TrackSliceComplexities (pCtx, iCurDid);
@@ -4740,7 +4727,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 419 unmodified lines
47404727 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
47414728
47424729 int32_t iCountNals = pCtx->pOut->iCountNals;
4743− int32_t iMaxSliceNumOld = pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint;
4730+ int32_t iMaxSliceNumOld = pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint;
47444731 int32_t iMaxSliceNum = iMaxSliceNumOld;
47454732 iCountNals += iMaxSliceNum * (pCtx->pSvcParam->iSpatialLayerNum + pCtx->bNeedPrefixNalFlag);
47464733 iMaxSliceNum *= SLICE_NUM_EXPAND_COEF;
@@ -4820,9 +4807,9 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 73 unmodified lines
48204807 return ENC_RETURN_MEMALLOCERR;
48214808 }
48224809 memset (pFirstMbInSlice, 0, sizeof (int32_t) * iMaxSliceNum);
4823− memcpy (pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof (int32_t) * iMaxSliceNumOld);
4824− pMA->WelsFree (pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice");
4825− pCurLayer->pSliceEncCtx->pFirstMbInSlice = pFirstMbInSlice;
4810+ memcpy (pFirstMbInSlice, pCurLayer->sSliceEncCtx.pFirstMbInSlice, sizeof (int32_t) * iMaxSliceNumOld);
4811+ pMA->WelsFree (pCurLayer->sSliceEncCtx.pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice");
4812+ pCurLayer->sSliceEncCtx.pFirstMbInSlice = pFirstMbInSlice;
48264813
48274814 int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t),
48284815 "pSliceSeg->pCountMbNumInSlice");
@@ -4831,14 +4818,14 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 2 unmodified lines
48314818 "CWelsH264SVCEncoder::DynSliceRealloc: realloc pCountMbNumInSlice not successful");
48324819 return ENC_RETURN_MEMALLOCERR;
48334820 }
4834− memcpy (pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);
4821+ memcpy (pCountMbNumInSlice, pCurLayer->sSliceEncCtx.pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);
48354822 uiSliceIdx = iMaxSliceNumOld;
48364823 while (uiSliceIdx < iMaxSliceNum) {
4837− pCountMbNumInSlice[uiSliceIdx] = pCurLayer->pSliceEncCtx->iMbNumInFrame;
4824+ pCountMbNumInSlice[uiSliceIdx] = pCurLayer->sSliceEncCtx.iMbNumInFrame;
48384825 uiSliceIdx++;
48394826 }
4840− pMA->WelsFree (pCurLayer->pSliceEncCtx->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
4841− pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice;
4827+ pMA->WelsFree (pCurLayer->sSliceEncCtx.pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
4828+ pCurLayer->sSliceEncCtx.pCountMbNumInSlice = pCountMbNumInSlice;
48424829
48434830 uint32_t* pSliceConsumeTime = (uint32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (uint32_t),
48444831 "pSliceSeg->pSliceConsumeTime");
@@ -4847,9 +4834,9 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 2 unmodified lines
48474834 "CWelsH264SVCEncoder::DynSliceRealloc: realloc pSliceConsumeTime not successful");
48484835 return ENC_RETURN_MEMALLOCERR;
48494836 }
4850− memcpy (pSliceConsumeTime, pCurLayer->pSliceEncCtx->pSliceConsumeTime, sizeof (int32_t) * iMaxSliceNumOld);
4851− pMA->WelsFree (pCurLayer->pSliceEncCtx->pSliceConsumeTime, "pSliceSeg->pSliceConsumeTime");
4852− pCurLayer->pSliceEncCtx->pSliceConsumeTime = pSliceConsumeTime;
4837+ memcpy (pSliceConsumeTime, pCurLayer->sSliceEncCtx.pSliceConsumeTime, sizeof (int32_t) * iMaxSliceNumOld);
4838+ pMA->WelsFree (pCurLayer->sSliceEncCtx.pSliceConsumeTime, "pSliceSeg->pSliceConsumeTime");
4839+ pCurLayer->sSliceEncCtx.pSliceConsumeTime = pSliceConsumeTime;
48534840
48544841 //deal with rate control variables
48554842 const int32_t kiCurDid = pCtx->uiDependencyId;
@@ -4869,7 +4856,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 13 unmodified lines
48694856 pSORC->iCalculatedQpSlice = pCtx->iGlobalQp;
48704857 pSORC->iTotalQpSlice = 0;
48714858 pSORC->iTotalMbSlice = 0;
4872− pSORC->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurLayer->pSliceEncCtx->pCountMbNumInSlice[uiSliceIdx],
4859+ pSORC->iTargetBitsSlice = WELS_DIV_ROUND (kiBitsPerMb * pCurLayer->sSliceEncCtx.pCountMbNumInSlice[uiSliceIdx],
48734860 INT_MULTIPLY);
48744861 pSORC->iFrameBitsSlice = 0;
48754862 pSORC->iGomBitsSlice = 0;
@@ -4881,7 +4868,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 5 unmodified lines
48814868
48824869 if (pCtx->iMaxSliceCount < iMaxSliceNum)
48834870 pCtx->iMaxSliceCount = iMaxSliceNum;
4884− pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint = iMaxSliceNum;
4871+ pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNum;
48854872 return ENC_RETURN_SUCCESS;
48864873 }
48874874
@@ -4896,7 +4883,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 8 unmodified lines
48964883 ) {
48974884
48984885 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
4899− SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
4886+ SSliceCtx* pSliceCtx = &pCurLayer->sSliceEncCtx;
49004887 int32_t iNalIdxInLayer = *pNalIdxInLayer;
49014888 int32_t iSliceIdx = iStartSliceIdx;
49024889 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