History

clean multi-threading macro

volvet committed 12 years ago

Commit 9f50e0c1 parent cad753d16 files · +12 −258Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+5−173
@@ -51,9 +51,7 @@ · 50 unmodified lines
51#include "ref_list_mgr_svc.h"51#include "ref_list_mgr_svc.h"
52#include "ls_defines.h"52#include "ls_defines.h"
53#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross platforms53#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross platforms
54#if defined(MT_ENABLED)
55#include "slice_multi_threading.h"54#include "slice_multi_threading.h"
56#endif//MT_ENABLED
57#include "measure_time.h"55#include "measure_time.h"
58 56
59namespace WelsSVCEnc {57namespace WelsSVCEnc {
@@ -165,7 +163,6 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 105 unmodified lines
165 }163 }
166 164
167 165
168#ifdef MT_ENABLED
169 //about iMultipleThreadIdc, bDeblockingParallelFlag, iLoopFilterDisableIdc, & uiSliceMode166 //about iMultipleThreadIdc, bDeblockingParallelFlag, iLoopFilterDisableIdc, & uiSliceMode
170 // (1) Single Thread167 // (1) Single Thread
171 // if (THREAD==1)//single thread168 // if (THREAD==1)//single thread
@@ -177,9 +174,6 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 5 unmodified lines
177 } else {174 } else {
178 pCodingParam->bDeblockingParallelFlag = true;175 pCodingParam->bDeblockingParallelFlag = true;
179 }176 }
180#else
181 pCodingParam->bDeblockingParallelFlag = false;
182#endif//MT_ENABLED
183 177
184 for (i = 0; i < pCodingParam->iSpatialLayerNum; ++ i) {178 for (i = 0; i < pCodingParam->iSpatialLayerNum; ++ i) {
185 SDLayerParam* fDlp = &pCodingParam->sDependencyLayers[i];179 SDLayerParam* fDlp = &pCodingParam->sDependencyLayers[i];
@@ -295,11 +289,9 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 109 unmodified lines
295 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;289 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
296 break;290 break;
297 }291 }
298#ifdef MT_ENABLED
299 if (pCodingParam->bEnableRc && fDlp->sSliceCfg.sSliceArgument.uiSliceNum > 1) {292 if (pCodingParam->bEnableRc && fDlp->sSliceCfg.sSliceArgument.uiSliceNum > 1) {
300 WelsLog (pCtx, WELS_LOG_ERROR, "ParamValidationExt(), WARNING: GOM based RC do not support SM_RASTER_SLICE!\n");293 WelsLog (pCtx, WELS_LOG_ERROR, "ParamValidationExt(), WARNING: GOM based RC do not support SM_RASTER_SLICE!\n");
301 }294 }
302#endif
303 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting295 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
304 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {296 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {
305 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;297 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@@ -505,19 +497,11 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 199 unmodified lines
505 iCountNumLayers; // plus iCountNumLayers for reserved application497 iCountNumLayers; // plus iCountNumLayers for reserved application
506 498
507 // to check number of layers / nals / slices dependencies, 12/8/2010499 // to check number of layers / nals / slices dependencies, 12/8/2010
508#if !defined(MT_ENABLED)
509 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {500 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
510 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",501 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
511 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);502 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);
512 return 1;503 return 1;
513 }504 }
514#else//MT_ENABLED
515 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
516 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
517 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);
518 return 1;
519 }
520#endif//!MT_ENABLED
521 505
522 if (NULL != pCountLayers)506 if (NULL != pCountLayers)
523 *pCountLayers = iCountNumLayers;507 *pCountLayers = iCountNumLayers;
@@ -781,31 +765,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 257 unmodified lines
781 765
782 pDqLayer->iMbWidth = kiMbW;766 pDqLayer->iMbWidth = kiMbW;
783 pDqLayer->iMbHeight = kiMbH;767 pDqLayer->iMbHeight = kiMbH;
784#ifndef MT_ENABLED
785 if (SM_DYN_SLICE == pDlayer->sSliceCfg.uiSliceMode) { //wmalloc pSliceInLayer
786 SSlice* pSlice = NULL;
787 int32_t iSliceIdx = 0;
788 //wmalloc AVERSLICENUM_CONSTANT of pDqLayer->sLayerInfo.pSliceInLayer,
789 //wmalloc AVERSLICENUM_CONSTANT num of pSlice as initialization
790 //only set value for the first pSlice
791 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
792
793 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx)) {
794 pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[0];
795 pSlice->uiSliceIdx = 0;
796 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
797 }
798
799 while (iSliceIdx < iMaxSliceNum) {
800 pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
801 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
802 FreeMemorySvc (ppCtx);
803 return 1;
804 }
805 ++ iSliceIdx;
806 }
807 } else
808#endif//!MT_ENABLED
809 {768 {
810 int32_t iSliceIdx = 0;769 int32_t iSliceIdx = 0;
811 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");770 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
@@ -815,14 +774,10 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 3 unmodified lines
815 while (iSliceIdx < iMaxSliceNum) {774 while (iSliceIdx < iMaxSliceNum) {
816 SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];775 SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
817 pSlice->uiSliceIdx = iSliceIdx;776 pSlice->uiSliceIdx = iSliceIdx;
818#ifdef MT_ENABLED
819 if (pParam->iMultipleThreadIdc > 1)777 if (pParam->iMultipleThreadIdc > 1)
820 pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;778 pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;
821 else779 else
822 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;780 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
823#else
824 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
825#endif//MT_ENABLED
826 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {781 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
827 FreeMemorySvc (ppCtx);782 FreeMemorySvc (ppCtx);
828 return 1;783 return 1;
@@ -860,11 +815,9 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 31 unmodified lines
860 pDqLayer->bDeblockingParallelFlag = false;815 pDqLayer->bDeblockingParallelFlag = false;
861 } else {816 } else {
862 //multi-pSlice817 //multi-pSlice
863#ifdef MT_ENABLED
864 if (0 == pDqLayer->iLoopFilterDisableIdc) {818 if (0 == pDqLayer->iLoopFilterDisableIdc) {
865 pDqLayer->bDeblockingParallelFlag = false;819 pDqLayer->bDeblockingParallelFlag = false;
866 }820 }
867#endif
868 }821 }
869 822
870 (*ppCtx)->ppDqLayerList[iDlayerIndex] = pDqLayer;823 (*ppCtx)->ppDqLayerList[iDlayerIndex] = pDqLayer;
@@ -1231,9 +1184,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 360 unmodified lines
1231 const uint32_t kuiMvdCacheAlignedSize = kuiMvdInterTableSize * sizeof (uint16_t);1184 const uint32_t kuiMvdCacheAlignedSize = kuiMvdInterTableSize * sizeof (uint16_t);
1232 int32_t iVclLayersBsSizeCount = 0;1185 int32_t iVclLayersBsSizeCount = 0;
1233 int32_t iNonVclLayersBsSizeCount = 0;1186 int32_t iNonVclLayersBsSizeCount = 0;
1234#if defined(MT_ENABLED)
1235 int32_t iTargetSpatialBsSize = 0;1187 int32_t iTargetSpatialBsSize = 0;
1236#endif//MT_ENABLED
1237 1188
1238 if (kiNumDependencyLayers < 1 || kiNumDependencyLayers > MAX_DEPENDENCY_LAYER) {1189 if (kiNumDependencyLayers < 1 || kiNumDependencyLayers > MAX_DEPENDENCY_LAYER) {
1239 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc() failed due to invalid iNumDependencyLayers(%d)!\n",1190 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc() failed due to invalid iNumDependencyLayers(%d)!\n",
@@ -1277,9 +1228,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 37 unmodified lines
1277 iVclLayersBsSizeCount += iLayerBsSize;1228 iVclLayersBsSizeCount += iLayerBsSize;
1278 ++ iIndex;1229 ++ iIndex;
1279 }1230 }
1280#if defined(MT_ENABLED)
1281 iTargetSpatialBsSize = iLayerBsSize;1231 iTargetSpatialBsSize = iLayerBsSize;
1282#endif//MT_ENABLED
1283 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;1232 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
1284 1233
1285 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);1234 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
@@ -1295,14 +1244,12 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 9 unmodified lines
1295 (*ppCtx)->pOut->iCountNals = iCountNals;1244 (*ppCtx)->pOut->iCountNals = iCountNals;
1296 (*ppCtx)->pOut->iNalIndex = 0;1245 (*ppCtx)->pOut->iNalIndex = 0;
1297 1246
1298#ifdef MT_ENABLED
1299 if (pParam->iMultipleThreadIdc > 1) {1247 if (pParam->iMultipleThreadIdc > 1) {
1300 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));1248 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));
1301 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");1249 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1302 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1250 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1303 (*ppCtx)->iFrameBsSize = iTotalLength;1251 (*ppCtx)->iFrameBsSize = iTotalLength;
1304 } else1252 } else
1305#endif//MT_ENABLED
1306 {1253 {
1307 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pFrameBs");1254 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pFrameBs");
1308 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1255 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
@@ -1310,14 +1257,12 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1 unmodified line
1310 }1257 }
1311 (*ppCtx)->iPosBsBuffer = 0;1258 (*ppCtx)->iPosBsBuffer = 0;
1312 1259
1313#ifdef MT_ENABLED
1314 // for pSlice bs buffers1260 // for pSlice bs buffers
1315 if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iTargetSpatialBsSize)) {1261 if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iTargetSpatialBsSize)) {
1316 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");1262 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");
1317 FreeMemorySvc (ppCtx);1263 FreeMemorySvc (ppCtx);
1318 return 1;1264 return 1;
1319 }1265 }
1320#endif
1321 1266
1322 (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*>1267 (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*>
1323 (pMa->WelsMallocz (iCountMaxMbNum * INTRA_4x4_MODE_NUM, "pIntra4x4PredModeBlocks"));1268 (pMa->WelsMallocz (iCountMaxMbNum * INTRA_4x4_MODE_NUM, "pIntra4x4PredModeBlocks"));
@@ -1485,10 +1430,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 161 unmodified lines
1485 pCtx->pOut = NULL;1430 pCtx->pOut = NULL;
1486 }1431 }
1487 1432
1488#ifdef MT_ENABLED
1489 if (pParam != NULL && pParam->iMultipleThreadIdc > 1)1433 if (pParam != NULL && pParam->iMultipleThreadIdc > 1)
1490 ReleaseMtResource (ppCtx);1434 ReleaseMtResource (ppCtx);
1491#endif//MT_ENABLED
1492 1435
1493 // frame bitstream pBuffer1436 // frame bitstream pBuffer
1494 if (NULL != pCtx->pFrameBs) {1437 if (NULL != pCtx->pFrameBs) {
@@ -1726,9 +1669,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 231 unmodified lines
1726 switch (pMso->uiSliceMode) {1669 switch (pMso->uiSliceMode) {
1727 case SM_DYN_SLICE:1670 case SM_DYN_SLICE:
1728 iMaxSliceCount = AVERSLICENUM_CONSTRAINT;1671 iMaxSliceCount = AVERSLICENUM_CONSTRAINT;
1729//#ifndef MT_ENABLED1672 break; // go through for SM_DYN_SLICE?
1730 break; // go through for MT_ENABLED & SM_DYN_SLICE?
1731//#endif//MT_ENABLED
1732 case SM_FIXEDSLCNUM_SLICE:1673 case SM_FIXEDSLCNUM_SLICE:
1733 if (iSliceNum > iMaxSliceCount)1674 if (iSliceNum > iMaxSliceCount)
1734 iMaxSliceCount = iSliceNum;1675 iMaxSliceCount = iSliceNum;
@@ -1792,13 +1733,8 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 57 unmodified lines
1792 ++ iSpatialIdx;1733 ++ iSpatialIdx;
1793 } while (iSpatialIdx < iSpatialNum);1734 } while (iSpatialIdx < iSpatialNum);
1794 1735
1795#ifdef MT_ENABLED
1796 pCodingParam->iCountThreadsNum = WELS_MIN (kiCpuCores, iMaxSliceCount);1736 pCodingParam->iCountThreadsNum = WELS_MIN (kiCpuCores, iMaxSliceCount);
1797 pCodingParam->iMultipleThreadIdc = pCodingParam->iCountThreadsNum;1737 pCodingParam->iMultipleThreadIdc = pCodingParam->iCountThreadsNum;
1798#else
1799 pCodingParam->iMultipleThreadIdc = 1;
1800 pCodingParam->iCountThreadsNum = 1;
1801#endif//MT_ENABLED
1802 1738
1803#ifndef WELS_TESTBED // for product release and non-SGE testing1739#ifndef WELS_TESTBED // for product release and non-SGE testing
1804 1740
@@ -1907,7 +1843,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 102 unmodified lines
1907 1843
1908#ifndef WELS_TESTBED1844#ifndef WELS_TESTBED
1909 1845
1910#if defined(MT_ENABLED) && defined(DYNAMIC_DETECT_CPU_CORES)1846#if defined(DYNAMIC_DETECT_CPU_CORES)
1911 if (pCodingParam->iMultipleThreadIdc > 0)1847 if (pCodingParam->iMultipleThreadIdc > 0)
1912 uiCpuCores = pCodingParam->iMultipleThreadIdc;1848 uiCpuCores = pCodingParam->iMultipleThreadIdc;
1913 else {1849 else {
@@ -1921,7 +1857,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 7 unmodified lines
1921 else if (uiCpuCores < 1) // just for safe1857 else if (uiCpuCores < 1) // just for safe
1922 uiCpuCores = 1;1858 uiCpuCores = 1;
1923 }1859 }
1924#endif//MT_ENABLED && DYNAMIC_DETECT_CPU_CORES1860#endif//DYNAMIC_DETECT_CPU_CORES
1925 1861
1926#else//WELS_TESTBED1862#else//WELS_TESTBED
1927 1863
@@ -1983,10 +1919,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 55 unmodified lines
1983 return iRet;1919 return iRet;
1984 }1920 }
1985 1921
1986#ifdef MT_ENABLED
1987 if (pCodingParam->iMultipleThreadIdc > 1)1922 if (pCodingParam->iMultipleThreadIdc > 1)
1988 iRet = CreateSliceThreads (pCtx);1923 iRet = CreateSliceThreads (pCtx);
1989#endif
1990 1924
1991 WelsRcInitModule (pCtx, pCtx->pSvcParam->bEnableRc ? WELS_RC_GOM : WELS_RC_DISABLE);1925 WelsRcInitModule (pCtx, pCtx->pSvcParam->bEnableRc ? WELS_RC_GOM : WELS_RC_DISABLE);
1992 1926
@@ -2112,7 +2046,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 119 unmodified lines
2112 StatOverallEncodingExt (*ppCtx);2046 StatOverallEncodingExt (*ppCtx);
2113#endif2047#endif
2114 2048
2115#if defined(MT_ENABLED)
2116 if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {2049 if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
2117 const int32_t iThreadCount = (*ppCtx)->pSvcParam->iCountThreadsNum;2050 const int32_t iThreadCount = (*ppCtx)->pSvcParam->iCountThreadsNum;
2118 int32_t iThreadIdx = 0;2051 int32_t iThreadIdx = 0;
@@ -2132,7 +2065,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 13 unmodified lines
2132 }2065 }
2133 }2066 }
2134 }2067 }
2135#endif//MT_ENABLED
2136 2068
2137 if ((*ppCtx)->pVpp) {2069 if ((*ppCtx)->pVpp) {
2138 (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);2070 (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);
@@ -2205,19 +2137,14 @@ void DynslcUpdateMbNeighbourInfoListForAllSlices (SSliceCtx* pSliceCtx, SMB* pMb · 66 unmodified lines
2205 */2137 */
2206int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) {2138int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) {
2207 int32_t iPartitionNum = 1;2139 int32_t iPartitionNum = 1;
2208#ifdef MT_ENABLED
2209 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {2140 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {
2210 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;2141 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;
2211 if (P_SLICE == pCtx->eSliceType)2142 if (P_SLICE == pCtx->eSliceType)
2212 iPartitionNum = 1;2143 iPartitionNum = 1;
2213 }2144 }
2214 return iPartitionNum;2145 return iPartitionNum;
2215#else
2216 return iPartitionNum;
2217#endif//MT_ENABLED
2218}2146}
2219 2147
2220#if defined(MT_ENABLED)
2221void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {2148void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {
2222 //pData init2149 //pData init
2223 SDqLayer* pCurDq = pCtx->pCurDqLayer;2150 SDqLayer* pCurDq = pCtx->pCurDqLayer;
@@ -2308,83 +2235,6 @@ void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) { · 84 unmodified lines
2308 2235
2309 WelsInitCurrentQBLayerMltslc (pCtx);2236 WelsInitCurrentQBLayerMltslc (pCtx);
2310}2237}
2311#else
2312void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {
2313 //pData init
2314 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2315 SSliceCtx* pSliceCtx = (pCurDq->pSliceEncCtx);
2316 SSlice* pSlice = &pCurDq->sLayerInfo.pSliceInLayer[0];
2317 int32_t iTtlMbNumInFrame = pSliceCtx->iMbNumInFrame;
2318
2319 //pSliceCtx
2320 memset (pSliceCtx->pOverallMbMap, 0, iTtlMbNumInFrame * sizeof (uint8_t));
2321 memset (pSliceCtx->pCountMbNumInSlice, 0, pSliceCtx->iSliceNumInFrame * sizeof (int32_t));
2322 memset (pSliceCtx->pFirstMbInSlice, 0, pSliceCtx->iSliceNumInFrame * sizeof (int16_t));
2323 pSliceCtx->iSliceNumInFrame = 1;//
2324 pSliceCtx->pCountMbNumInSlice[0] = iTtlMbNumInFrame;
2325
2326 //mb_neighbor
2327 DynslcUpdateMbNeighbourInfoListForAllSlices (pSliceCtx, pCurDq->sMbDataP);
2328
2329 //pSlice init
2330 pSlice->uiSliceIdx = 0;
2331 pSlice->pSliceBsa = &pCtx->pOut->sBsWrite;
2332 pSlice->bDynamicSlicingSliceSizeCtrlFlag = false;
2333 pSlice->uiAssumeLog2BytePerMb = (pCtx->eSliceType == P_SLICE) ? 0 : 1;
2334}
2335
2336void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) {
2337 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2338 SSliceCtx* pSliceCtx = (pCurDq->pSliceEncCtx);
2339 int32_t iTtlMbNumInFrame = pCurDq->iMbHeight * pCurDq->iMbWidth;
2340
2341 pSliceCtx->iMbNumInFrame
2342 = pSliceCtx->pCountMbNumInSlice[0] = iTtlMbNumInFrame;
2343
2344 if (I_SLICE == pCtx->eSliceType) { //check if uiSliceSizeConstraint too small
2345#define byte_complexIMBat26 (60)
2346 uint8_t iCurDid = pCtx->uiDependencyId;
2347 uint32_t uiFrmByte = 0;
2348
2349 if (pCtx->pSvcParam->bEnableRc) {
2350 //RC case
2351 uiFrmByte = (
2352 ((uint32_t) (pCtx->pSvcParam->sDependencyLayers[iCurDid].iSpatialBitrate)
2353 / (uint32_t) (pCtx->pSvcParam->sDependencyLayers[iCurDid].fInputFrameRate)) >> 3);
2354 } else {
2355 //fixed QP case
2356 int32_t iQDeltaTo26 = (26 - pCtx->pSvcParam->sDependencyLayers[iCurDid].iDLayerQp);
2357
2358 uiFrmByte = (iTtlMbNumInFrame * byte_complexIMBat26);
2359 if (iQDeltaTo26 > 0) {
2360 //smaller QP than 26
2361 uiFrmByte = (uint32_t) (uiFrmByte * ((float)iQDeltaTo26 / 4));
2362 } else if (iQDeltaTo26 < 0) {
2363 //larger QP than 26
2364 iQDeltaTo26 = ((-iQDeltaTo26) >> 2); //delta mod 4
2365 uiFrmByte = (uiFrmByte >> (iQDeltaTo26)); //if delta 4, byte /2
2366 }
2367 }
2368
2369 //MINPACKETSIZE_CONSTRAINT
2370 if (pSliceCtx->uiSliceSizeConstraint
2371 <
2372 (uint32_t) (uiFrmByte//suppose 16 byte per mb at average
2373 / (pSliceCtx->iMaxSliceNumConstraint))
2374 ) {
2375
2376 WelsLog (pCtx,
2377 WELS_LOG_WARNING,
2378 "Set-SliceConstraint(%d) too small for current resolution (MB# %d) under QP/BR!\n",
2379 pSliceCtx->uiSliceSizeConstraint,
2380 pSliceCtx->iMbNumInFrame
2381 );
2382 }
2383 }
2384
2385 WelsInitCurrentQBLayerMltslc (pCtx);
2386}
2387#endif
2388 2238
2389/*!2239/*!
2390 * \brief initialize current layer2240 * \brief initialize current layer
@@ -2884,9 +2734,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 493 unmodified lines
2884 SPicture* fsnr = NULL;2734 SPicture* fsnr = NULL;
2885#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC2735#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC
2886 SPicture* pEncPic = NULL; // to be decided later2736 SPicture* pEncPic = NULL; // to be decided later
2887#if defined(MT_ENABLED)
2888 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};2737 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};
2889#endif//MT_ENABLED
2890 int32_t iLayerNum = 0;2738 int32_t iLayerNum = 0;
2891 int32_t iLayerSize = 0;2739 int32_t iLayerSize = 0;
2892 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame2740 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
@@ -2976,22 +2824,18 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 83 unmodified lines
2976 iCurWidth = param_d->iFrameWidth;2824 iCurWidth = param_d->iFrameWidth;
2977 iCurHeight = param_d->iFrameHeight;2825 iCurHeight = param_d->iFrameHeight;
2978 2826
2979#if defined(MT_ENABLED)
2980 did_list[iSpatialIdx] = iCurDid;2827 did_list[iSpatialIdx] = iCurDid;
2981#endif//MT_ENABLED
2982 2828
2983 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed2829 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed
2984 2830
2985 switch (param_d->sSliceCfg.uiSliceMode) {2831 switch (param_d->sSliceCfg.uiSliceMode) {
2986 case SM_FIXEDSLCNUM_SLICE:2832 case SM_FIXEDSLCNUM_SLICE:
2987 case SM_AUTO_SLICE:{2833 case SM_AUTO_SLICE:{
2988#if defined(MT_ENABLED)
2989 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&2834 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&
2990 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE2835 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
2991 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)2836 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)
2992 )2837 )
2993 AdjustEnhanceLayer (pCtx, iCurDid);2838 AdjustEnhanceLayer (pCtx, iCurDid);
2994#endif//MT_ENABLED
2995 break;2839 break;
2996 }2840 }
2997 case SM_DYN_SLICE: {2841 case SM_DYN_SLICE: {
@@ -3104,18 +2948,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 106 unmodified lines
3104 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;2948 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;
3105 }2949 }
3106 // for dynamic slicing single threading..2950 // for dynamic slicing single threading..
3107#ifndef MT_ENABLED
3108 else if (SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode)
3109#else // MT_ENABLED
3110 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1))2951 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1))
3111#endif//MT_ENABLED
3112 {2952 {
3113 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;2953 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;
3114 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);2954 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);
3115 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)2955 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3116 } else {2956 } else {
3117 //other multi-slice uiSliceMode2957 //other multi-slice uiSliceMode
3118#if defined(MT_ENABLED)
3119 int err = 0;2958 int err = 0;
3120 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE2959 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE
3121 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {2960 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
@@ -3239,7 +3078,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 117 unmodified lines
3239 3078
3240 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);3079 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);
3241 } else // for non-dynamic-slicing mode single threading branch..3080 } else // for non-dynamic-slicing mode single threading branch..
3242#endif//MT_ENABLED
3243 {3081 {
3244 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;3082 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
3245 int32_t iSliceIdx = 0;3083 int32_t iSliceIdx = 0;
@@ -3294,9 +3132,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 48 unmodified lines
3294 3132
3295 // deblocking filter3133 // deblocking filter
3296 if (3134 if (
3297#if defined(MT_ENABLED)
3298 (!pCtx->pCurDqLayer->bDeblockingParallelFlag) &&3135 (!pCtx->pCurDqLayer->bDeblockingParallelFlag) &&
3299#endif//MT_ENABLED
3300#if !defined(ENABLE_FRAME_DUMP)3136#if !defined(ENABLE_FRAME_DUMP)
3301 ((eNalRefIdc != NRI_PRI_LOWEST) && (param_d->iHighestTemporalId == 0 || iCurTid < param_d->iHighestTemporalId)) &&3137 ((eNalRefIdc != NRI_PRI_LOWEST) && (param_d->iHighestTemporalId == 0 || iCurTid < param_d->iHighestTemporalId)) &&
3302#endif//!ENABLE_FRAME_DUMP3138#endif//!ENABLE_FRAME_DUMP
@@ -3436,7 +3272,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 133 unmodified lines
3436 ++ iLayerNum;3272 ++ iLayerNum;
3437 }3273 }
3438 3274
3439#if defined(MT_ENABLED)
3440 if ((param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE||param_d->sSliceCfg.uiSliceMode == SM_AUTO_SLICE) && pSvcParam->iMultipleThreadIdc > 1 &&3275 if ((param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE||param_d->sSliceCfg.uiSliceMode == SM_AUTO_SLICE) && pSvcParam->iMultipleThreadIdc > 1 &&
3441 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {3276 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {
3442 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,3277 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,
@@ -3445,7 +3280,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3445 TrackSliceComplexities (pCtx, iCurDid);3280 TrackSliceComplexities (pCtx, iCurDid);
3446#endif//#if defined(MT_DEBUG)3281#endif//#if defined(MT_DEBUG)
3447 }3282 }
3448#endif//MT_ENABLED
3449 3283
3450 ++ iSpatialIdx;3284 ++ iSpatialIdx;
3451 3285
@@ -3472,11 +3306,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 20 unmodified lines
3472 }3306 }
3473 }3307 }
3474 3308
3475#if defined(MT_ENABLED) && defined(MT_DEBUG)3309#if defined(MT_DEBUG)
3476 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);3310 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);
3477#endif//MT_ENABLED && MT_DEBUG3311#endif//MT_DEBUG
3478 3312
3479#if defined(MT_ENABLED)
3480 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID3313 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID
3481 && ((pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))3314 && ((pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))
3482 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum3315 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum
@@ -3485,7 +3318,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3485 1]].sSliceCfg.sSliceArgument.uiSliceNum) {3318 1]].sSliceCfg.sSliceArgument.uiSliceNum) {
3486 AdjustBaseLayer (pCtx);3319 AdjustBaseLayer (pCtx);
3487 }3320 }
3488#endif
3489 3321
3490#ifdef ENABLE_FRAME_DUMP3322#ifdef ENABLE_FRAME_DUMP
3491 DumpRecFrame (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum -3323 DumpRecFrame (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum -

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