History

remove pSliceBs from ctx

huade committed 10 years ago

Commit f1615661 parent 04bfacd5 files · +54 −89Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+40−18
@@ -1095,15 +1095,37 @@ int32_t FindExistingPps (SWelsSPS* pSps, SSubsetSps* pSubsetSps, const bool kbUs · 1094 unmodified lines
10951095 }
10961096
10971097 static inline int32_t InitpSliceInLayer (sWelsEncCtx** ppCtx, SDqLayer* pDqLayer, CMemoryAlign* pMa,
1098− const int32_t iMaxSliceNum, bool bMultithread) {
1099− int32_t iSliceIdx = 0;
1098+ const int32_t iMaxSliceNum, const int32_t kiDlayerIndex) {
1099+ int32_t iMaxSliceBufferSize = (*ppCtx)->iSliceBufferSize[kiDlayerIndex];
1100+ int32_t iSliceIdx = 0;
1101+ SliceModeEnum uiSliceMode = (*ppCtx)->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument.uiSliceMode;
1102+
1103+ //SM_SINGLE_SLICE mode using single-thread bs writer pOut->sBsWrite
1104+ //even though multi-thread is on for other layers
1105+ bool bIndependenceBsBuffer = ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 &&
1106+ SM_SINGLE_SLICE != uiSliceMode) ? true : false;
1107+
1108+ if ( iMaxSliceBufferSize <= 0) {
1109+ return ENC_RETURN_UNEXPECTED;
1110+ }
1111+
11001112 while (iSliceIdx < iMaxSliceNum) {
11011113 SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
1102− pSlice->uiSliceIdx = iSliceIdx;
1103− if (bMultithread)
1104− pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;
1105− else
1106− pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
1114+
1115+ pSlice->uiSliceIdx = iSliceIdx;
1116+ pSlice->sSliceBs.uiSize = iMaxSliceBufferSize;
1117+ pSlice->sSliceBs.uiBsPos = 0;
1118+ if (bIndependenceBsBuffer){
1119+ pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite;
1120+ pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "SliceBs");
1121+ if ( NULL == pSlice->sSliceBs.pBs) {
1122+ return ENC_RETURN_MEMALLOCERR;
1123+ }
1124+ } else {
1125+ pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
1126+ pSlice->sSliceBs.pBs = NULL;
1127+ }
1128+
11071129 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
11081130 FreeMemorySvc (ppCtx);
11091131 return ENC_RETURN_MEMALLOCERR;
@@ -1211,7 +1233,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 101 unmodified lines
12111233 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
12121234 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx))
12131235
1214− int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, pParam->iMultipleThreadIdc > 1);
1236+ int32_t iReturn = InitpSliceInLayer (ppCtx, pDqLayer, pMa, iMaxSliceNum, iDlayerIndex);
12151237 WELS_VERIFY_RETURN_PROC_IF (1, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx))
12161238 }
12171239
@@ -1809,16 +1831,15 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 591 unmodified lines
18091831 (*ppCtx)->iMaxSliceCount = WELS_MAX ((*ppCtx)->iMaxSliceCount, (int) pSliceArgument->uiSliceNum);
18101832 iSliceBufferSize = ((iLayerBsSize / pSliceArgument->uiSliceNum)<<1) + MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
18111833 }
1812− iMaxSliceBufferSize = WELS_MAX(iMaxSliceBufferSize, iSliceBufferSize);
1813−
1834+ iMaxSliceBufferSize = WELS_MAX(iMaxSliceBufferSize, iSliceBufferSize);
1835+ (*ppCtx)->iSliceBufferSize[iIndex] = iSliceBufferSize;
18141836 ++ iIndex;
18151837 }
18161838 iTargetSpatialBsSize = iLayerBsSize;
18171839 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
18181840
18191841 iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize);
1820− iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + (*ppCtx)->iMaxSliceCount *
1821− iMaxSliceBufferSize);
1842+ iTotalLength = iCountBsLen;
18221843
18231844 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT,
18241845 (pParam->iUsageType == CAMERA_VIDEO_REAL_TIME ? MAX_REFERENCE_PICTURE_COUNT_NUM_CAMERA :
@@ -2125,6 +2146,12 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 300 unmodified lines
21252146 while (iSliceIdx < iSliceNum) {
21262147 SSlice* pSlice = &pDq->sLayerInfo.pSliceInLayer[iSliceIdx];
21272148 FreeMbCache (&pSlice->sMbCacheInfo, pMa);
2149+
2150+ //slice bs buffer
2151+ if(NULL != pSlice->sSliceBs.pBs) {
2152+ pMa->WelsFree(pSlice->sSliceBs.pBs,"sSliceBs.pBs");
2153+ pSlice->sSliceBs.pBs = NULL;
2154+ }
21282155 ++ iSliceIdx;
21292156 }
21302157 pMa->WelsFree (pDq->sLayerInfo.pSliceInLayer, "pSliceInLayer");
@@ -3896,11 +3923,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1765 unmodified lines
38963923
38973924 WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);
38983925
3899− //the following line is to fix a problem with a specific setting as in test DiffSlicingInDlayerMixed:
3900− // (multi-th on with SM_SINGLE_SLICE in one of the D layers)
3901− //TODO: this may not be needed any more after the slice buffer refactoring
3902− pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0].pSliceBsa = &(pCtx->pOut->sBsWrite);
3903−
39043926 pCtx->iEncoderError = WelsCodeOneSlice (pCtx, 0, eNalType);
39053927 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
39063928
@@ -4734,7 +4756,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 827 unmodified lines
47344756 SSliceHeaderExt* pSHExt = &pSliceIdx->sSliceHeaderExt;
47354757 pSliceIdx->uiSliceIdx = uiSliceIdx;
47364758 if (pCtx->pSvcParam->iMultipleThreadIdc > 1)
4737− pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite;
4759+ pSliceIdx->pSliceBsa = &pSliceIdx->sSliceBs.sBsWrite;
47384760 else
47394761 pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite;
47404762 if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) {

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