History

Merge pull request #605 from volvet/clean_mt_macro

clean multi-threading macro

Licai Guo committed 12 years ago

Commit 9a812602 parents 535fd74 9f50e0c16 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 {
@@ -161,7 +159,6 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 101 unmodified lines
161 }159 }
162 160
163 161
164#ifdef MT_ENABLED
165 //about iMultipleThreadIdc, bDeblockingParallelFlag, iLoopFilterDisableIdc, & uiSliceMode162 //about iMultipleThreadIdc, bDeblockingParallelFlag, iLoopFilterDisableIdc, & uiSliceMode
166 // (1) Single Thread163 // (1) Single Thread
167 // if (THREAD==1)//single thread164 // if (THREAD==1)//single thread
@@ -173,9 +170,6 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 5 unmodified lines
173 } else {170 } else {
174 pCodingParam->bDeblockingParallelFlag = true;171 pCodingParam->bDeblockingParallelFlag = true;
175 }172 }
176#else
177 pCodingParam->bDeblockingParallelFlag = false;
178#endif//MT_ENABLED
179 173
180 for (i = 0; i < pCodingParam->iSpatialLayerNum; ++ i) {174 for (i = 0; i < pCodingParam->iSpatialLayerNum; ++ i) {
181 SDLayerParam* fDlp = &pCodingParam->sDependencyLayers[i];175 SDLayerParam* fDlp = &pCodingParam->sDependencyLayers[i];
@@ -291,11 +285,9 @@ int32_t ParamValidationExt (sWelsEncCtx*pCtx,SWelsSvcCodingParam* pCodingParam) · 109 unmodified lines
291 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;285 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
292 break;286 break;
293 }287 }
294#ifdef MT_ENABLED
295 if (pCodingParam->bEnableRc && fDlp->sSliceCfg.sSliceArgument.uiSliceNum > 1) {288 if (pCodingParam->bEnableRc && fDlp->sSliceCfg.sSliceArgument.uiSliceNum > 1) {
296 WelsLog (pCtx, WELS_LOG_ERROR, "ParamValidationExt(), WARNING: GOM based RC do not support SM_RASTER_SLICE!\n");289 WelsLog (pCtx, WELS_LOG_ERROR, "ParamValidationExt(), WARNING: GOM based RC do not support SM_RASTER_SLICE!\n");
297 }290 }
298#endif
299 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting291 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
300 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {292 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {
301 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;293 fDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@@ -501,19 +493,11 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 199 unmodified lines
501 iCountNumLayers; // plus iCountNumLayers for reserved application493 iCountNumLayers; // plus iCountNumLayers for reserved application
502 494
503 // to check number of layers / nals / slices dependencies, 12/8/2010495 // to check number of layers / nals / slices dependencies, 12/8/2010
504#if !defined(MT_ENABLED)
505 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {496 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
506 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",497 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
507 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);498 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);
508 return 1;499 return 1;
509 }500 }
510#else//MT_ENABLED
511 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
512 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
513 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);
514 return 1;
515 }
516#endif//!MT_ENABLED
517 501
518 if (NULL != pCountLayers)502 if (NULL != pCountLayers)
519 *pCountLayers = iCountNumLayers;503 *pCountLayers = iCountNumLayers;
@@ -777,31 +761,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 257 unmodified lines
777 761
778 pDqLayer->iMbWidth = kiMbW;762 pDqLayer->iMbWidth = kiMbW;
779 pDqLayer->iMbHeight = kiMbH;763 pDqLayer->iMbHeight = kiMbH;
780#ifndef MT_ENABLED
781 if (SM_DYN_SLICE == pDlayer->sSliceCfg.uiSliceMode) { //wmalloc pSliceInLayer
782 SSlice* pSlice = NULL;
783 int32_t iSliceIdx = 0;
784 //wmalloc AVERSLICENUM_CONSTANT of pDqLayer->sLayerInfo.pSliceInLayer,
785 //wmalloc AVERSLICENUM_CONSTANT num of pSlice as initialization
786 //only set value for the first pSlice
787 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
788
789 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer->sLayerInfo.pSliceInLayer), FreeMemorySvc (ppCtx)) {
790 pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[0];
791 pSlice->uiSliceIdx = 0;
792 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
793 }
794
795 while (iSliceIdx < iMaxSliceNum) {
796 pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
797 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
798 FreeMemorySvc (ppCtx);
799 return 1;
800 }
801 ++ iSliceIdx;
802 }
803 } else
804#endif//!MT_ENABLED
805 {764 {
806 int32_t iSliceIdx = 0;765 int32_t iSliceIdx = 0;
807 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");766 pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer");
@@ -811,14 +770,10 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 3 unmodified lines
811 while (iSliceIdx < iMaxSliceNum) {770 while (iSliceIdx < iMaxSliceNum) {
812 SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];771 SSlice* pSlice = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx];
813 pSlice->uiSliceIdx = iSliceIdx;772 pSlice->uiSliceIdx = iSliceIdx;
814#ifdef MT_ENABLED
815 if (pParam->iMultipleThreadIdc > 1)773 if (pParam->iMultipleThreadIdc > 1)
816 pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;774 pSlice->pSliceBsa = & (*ppCtx)->pSliceBs[iSliceIdx].sBsWrite;
817 else775 else
818 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;776 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
819#else
820 pSlice->pSliceBsa = & (*ppCtx)->pOut->sBsWrite;
821#endif//MT_ENABLED
822 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {777 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
823 FreeMemorySvc (ppCtx);778 FreeMemorySvc (ppCtx);
824 return 1;779 return 1;
@@ -856,11 +811,9 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 31 unmodified lines
856 pDqLayer->bDeblockingParallelFlag = false;811 pDqLayer->bDeblockingParallelFlag = false;
857 } else {812 } else {
858 //multi-pSlice813 //multi-pSlice
859#ifdef MT_ENABLED
860 if (0 == pDqLayer->iLoopFilterDisableIdc) {814 if (0 == pDqLayer->iLoopFilterDisableIdc) {
861 pDqLayer->bDeblockingParallelFlag = false;815 pDqLayer->bDeblockingParallelFlag = false;
862 }816 }
863#endif
864 }817 }
865 818
866 (*ppCtx)->ppDqLayerList[iDlayerIndex] = pDqLayer;819 (*ppCtx)->ppDqLayerList[iDlayerIndex] = pDqLayer;
@@ -1227,9 +1180,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 360 unmodified lines
1227 const uint32_t kuiMvdCacheAlignedSize = kuiMvdInterTableSize * sizeof (uint16_t);1180 const uint32_t kuiMvdCacheAlignedSize = kuiMvdInterTableSize * sizeof (uint16_t);
1228 int32_t iVclLayersBsSizeCount = 0;1181 int32_t iVclLayersBsSizeCount = 0;
1229 int32_t iNonVclLayersBsSizeCount = 0;1182 int32_t iNonVclLayersBsSizeCount = 0;
1230#if defined(MT_ENABLED)
1231 int32_t iTargetSpatialBsSize = 0;1183 int32_t iTargetSpatialBsSize = 0;
1232#endif//MT_ENABLED
1233 1184
1234 if (kiNumDependencyLayers < 1 || kiNumDependencyLayers > MAX_DEPENDENCY_LAYER) {1185 if (kiNumDependencyLayers < 1 || kiNumDependencyLayers > MAX_DEPENDENCY_LAYER) {
1235 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc() failed due to invalid iNumDependencyLayers(%d)!\n",1186 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc() failed due to invalid iNumDependencyLayers(%d)!\n",
@@ -1273,9 +1224,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 37 unmodified lines
1273 iVclLayersBsSizeCount += iLayerBsSize;1224 iVclLayersBsSizeCount += iLayerBsSize;
1274 ++ iIndex;1225 ++ iIndex;
1275 }1226 }
1276#if defined(MT_ENABLED)
1277 iTargetSpatialBsSize = iLayerBsSize;1227 iTargetSpatialBsSize = iLayerBsSize;
1278#endif//MT_ENABLED
1279 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;1228 iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
1280 1229
1281 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);1230 pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
@@ -1291,14 +1240,12 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 9 unmodified lines
1291 (*ppCtx)->pOut->iCountNals = iCountNals;1240 (*ppCtx)->pOut->iCountNals = iCountNals;
1292 (*ppCtx)->pOut->iNalIndex = 0;1241 (*ppCtx)->pOut->iNalIndex = 0;
1293 1242
1294#ifdef MT_ENABLED
1295 if (pParam->iMultipleThreadIdc > 1) {1243 if (pParam->iMultipleThreadIdc > 1) {
1296 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));1244 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));
1297 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");1245 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1298 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1246 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1299 (*ppCtx)->iFrameBsSize = iTotalLength;1247 (*ppCtx)->iFrameBsSize = iTotalLength;
1300 } else1248 } else
1301#endif//MT_ENABLED
1302 {1249 {
1303 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pFrameBs");1250 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pFrameBs");
1304 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1251 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
@@ -1306,14 +1253,12 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1 unmodified line
1306 }1253 }
1307 (*ppCtx)->iPosBsBuffer = 0;1254 (*ppCtx)->iPosBsBuffer = 0;
1308 1255
1309#ifdef MT_ENABLED
1310 // for pSlice bs buffers1256 // for pSlice bs buffers
1311 if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iTargetSpatialBsSize)) {1257 if (pParam->iMultipleThreadIdc > 1 && RequestMtResource (ppCtx, pParam, iCountBsLen, iTargetSpatialBsSize)) {
1312 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");1258 WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMtResource failed!");
1313 FreeMemorySvc (ppCtx);1259 FreeMemorySvc (ppCtx);
1314 return 1;1260 return 1;
1315 }1261 }
1316#endif
1317 1262
1318 (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*>1263 (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*>
1319 (pMa->WelsMallocz (iCountMaxMbNum * INTRA_4x4_MODE_NUM, "pIntra4x4PredModeBlocks"));1264 (pMa->WelsMallocz (iCountMaxMbNum * INTRA_4x4_MODE_NUM, "pIntra4x4PredModeBlocks"));
@@ -1481,10 +1426,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 161 unmodified lines
1481 pCtx->pOut = NULL;1426 pCtx->pOut = NULL;
1482 }1427 }
1483 1428
1484#ifdef MT_ENABLED
1485 if (pParam != NULL && pParam->iMultipleThreadIdc > 1)1429 if (pParam != NULL && pParam->iMultipleThreadIdc > 1)
1486 ReleaseMtResource (ppCtx);1430 ReleaseMtResource (ppCtx);
1487#endif//MT_ENABLED
1488 1431
1489 // frame bitstream pBuffer1432 // frame bitstream pBuffer
1490 if (NULL != pCtx->pFrameBs) {1433 if (NULL != pCtx->pFrameBs) {
@@ -1722,9 +1665,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 231 unmodified lines
1722 switch (pMso->uiSliceMode) {1665 switch (pMso->uiSliceMode) {
1723 case SM_DYN_SLICE:1666 case SM_DYN_SLICE:
1724 iMaxSliceCount = AVERSLICENUM_CONSTRAINT;1667 iMaxSliceCount = AVERSLICENUM_CONSTRAINT;
1725//#ifndef MT_ENABLED1668 break; // go through for SM_DYN_SLICE?
1726 break; // go through for MT_ENABLED & SM_DYN_SLICE?
1727//#endif//MT_ENABLED
1728 case SM_FIXEDSLCNUM_SLICE:1669 case SM_FIXEDSLCNUM_SLICE:
1729 if (iSliceNum > iMaxSliceCount)1670 if (iSliceNum > iMaxSliceCount)
1730 iMaxSliceCount = iSliceNum;1671 iMaxSliceCount = iSliceNum;
@@ -1788,13 +1729,8 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 57 unmodified lines
1788 ++ iSpatialIdx;1729 ++ iSpatialIdx;
1789 } while (iSpatialIdx < iSpatialNum);1730 } while (iSpatialIdx < iSpatialNum);
1790 1731
1791#ifdef MT_ENABLED
1792 pCodingParam->iCountThreadsNum = WELS_MIN (kiCpuCores, iMaxSliceCount);1732 pCodingParam->iCountThreadsNum = WELS_MIN (kiCpuCores, iMaxSliceCount);
1793 pCodingParam->iMultipleThreadIdc = pCodingParam->iCountThreadsNum;1733 pCodingParam->iMultipleThreadIdc = pCodingParam->iCountThreadsNum;
1794#else
1795 pCodingParam->iMultipleThreadIdc = 1;
1796 pCodingParam->iCountThreadsNum = 1;
1797#endif//MT_ENABLED
1798 1734
1799#ifndef WELS_TESTBED // for product release and non-SGE testing1735#ifndef WELS_TESTBED // for product release and non-SGE testing
1800 1736
@@ -1903,7 +1839,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 102 unmodified lines
1903 1839
1904#ifndef WELS_TESTBED1840#ifndef WELS_TESTBED
1905 1841
1906#if defined(MT_ENABLED) && defined(DYNAMIC_DETECT_CPU_CORES)1842#if defined(DYNAMIC_DETECT_CPU_CORES)
1907 if (pCodingParam->iMultipleThreadIdc > 0)1843 if (pCodingParam->iMultipleThreadIdc > 0)
1908 uiCpuCores = pCodingParam->iMultipleThreadIdc;1844 uiCpuCores = pCodingParam->iMultipleThreadIdc;
1909 else {1845 else {
@@ -1917,7 +1853,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 7 unmodified lines
1917 else if (uiCpuCores < 1) // just for safe1853 else if (uiCpuCores < 1) // just for safe
1918 uiCpuCores = 1;1854 uiCpuCores = 1;
1919 }1855 }
1920#endif//MT_ENABLED && DYNAMIC_DETECT_CPU_CORES1856#endif//DYNAMIC_DETECT_CPU_CORES
1921 1857
1922#else//WELS_TESTBED1858#else//WELS_TESTBED
1923 1859
@@ -1979,10 +1915,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 55 unmodified lines
1979 return iRet;1915 return iRet;
1980 }1916 }
1981 1917
1982#ifdef MT_ENABLED
1983 if (pCodingParam->iMultipleThreadIdc > 1)1918 if (pCodingParam->iMultipleThreadIdc > 1)
1984 iRet = CreateSliceThreads (pCtx);1919 iRet = CreateSliceThreads (pCtx);
1985#endif
1986 1920
1987 WelsRcInitModule (pCtx, pCtx->pSvcParam->bEnableRc ? WELS_RC_GOM : WELS_RC_DISABLE);1921 WelsRcInitModule (pCtx, pCtx->pSvcParam->bEnableRc ? WELS_RC_GOM : WELS_RC_DISABLE);
1988 1922
@@ -2108,7 +2042,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 119 unmodified lines
2108 StatOverallEncodingExt (*ppCtx);2042 StatOverallEncodingExt (*ppCtx);
2109#endif2043#endif
2110 2044
2111#if defined(MT_ENABLED)
2112 if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {2045 if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
2113 const int32_t iThreadCount = (*ppCtx)->pSvcParam->iCountThreadsNum;2046 const int32_t iThreadCount = (*ppCtx)->pSvcParam->iCountThreadsNum;
2114 int32_t iThreadIdx = 0;2047 int32_t iThreadIdx = 0;
@@ -2128,7 +2061,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 13 unmodified lines
2128 }2061 }
2129 }2062 }
2130 }2063 }
2131#endif//MT_ENABLED
2132 2064
2133 if ((*ppCtx)->pVpp) {2065 if ((*ppCtx)->pVpp) {
2134 (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);2066 (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);
@@ -2201,19 +2133,14 @@ void DynslcUpdateMbNeighbourInfoListForAllSlices (SSliceCtx* pSliceCtx, SMB* pMb · 66 unmodified lines
2201 */2133 */
2202int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) {2134int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) {
2203 int32_t iPartitionNum = 1;2135 int32_t iPartitionNum = 1;
2204#ifdef MT_ENABLED
2205 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {2136 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {
2206 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;2137 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;
2207 if (P_SLICE == pCtx->eSliceType)2138 if (P_SLICE == pCtx->eSliceType)
2208 iPartitionNum = 1;2139 iPartitionNum = 1;
2209 }2140 }
2210 return iPartitionNum;2141 return iPartitionNum;
2211#else
2212 return iPartitionNum;
2213#endif//MT_ENABLED
2214}2142}
2215 2143
2216#if defined(MT_ENABLED)
2217void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {2144void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {
2218 //pData init2145 //pData init
2219 SDqLayer* pCurDq = pCtx->pCurDqLayer;2146 SDqLayer* pCurDq = pCtx->pCurDqLayer;
@@ -2304,83 +2231,6 @@ void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) { · 84 unmodified lines
2304 2231
2305 WelsInitCurrentQBLayerMltslc (pCtx);2232 WelsInitCurrentQBLayerMltslc (pCtx);
2306}2233}
2307#else
2308void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) {
2309 //pData init
2310 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2311 SSliceCtx* pSliceCtx = (pCurDq->pSliceEncCtx);
2312 SSlice* pSlice = &pCurDq->sLayerInfo.pSliceInLayer[0];
2313 int32_t iTtlMbNumInFrame = pSliceCtx->iMbNumInFrame;
2314
2315 //pSliceCtx
2316 memset (pSliceCtx->pOverallMbMap, 0, iTtlMbNumInFrame * sizeof (uint8_t));
2317 memset (pSliceCtx->pCountMbNumInSlice, 0, pSliceCtx->iSliceNumInFrame * sizeof (int32_t));
2318 memset (pSliceCtx->pFirstMbInSlice, 0, pSliceCtx->iSliceNumInFrame * sizeof (int16_t));
2319 pSliceCtx->iSliceNumInFrame = 1;//
2320 pSliceCtx->pCountMbNumInSlice[0] = iTtlMbNumInFrame;
2321
2322 //mb_neighbor
2323 DynslcUpdateMbNeighbourInfoListForAllSlices (pSliceCtx, pCurDq->sMbDataP);
2324
2325 //pSlice init
2326 pSlice->uiSliceIdx = 0;
2327 pSlice->pSliceBsa = &pCtx->pOut->sBsWrite;
2328 pSlice->bDynamicSlicingSliceSizeCtrlFlag = false;
2329 pSlice->uiAssumeLog2BytePerMb = (pCtx->eSliceType == P_SLICE) ? 0 : 1;
2330}
2331
2332void WelsInitCurrentDlayerMltslc (sWelsEncCtx* pCtx, int32_t iPartitionNum) {
2333 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2334 SSliceCtx* pSliceCtx = (pCurDq->pSliceEncCtx);
2335 int32_t iTtlMbNumInFrame = pCurDq->iMbHeight * pCurDq->iMbWidth;
2336
2337 pSliceCtx->iMbNumInFrame
2338 = pSliceCtx->pCountMbNumInSlice[0] = iTtlMbNumInFrame;
2339
2340 if (I_SLICE == pCtx->eSliceType) { //check if uiSliceSizeConstraint too small
2341#define byte_complexIMBat26 (60)
2342 uint8_t iCurDid = pCtx->uiDependencyId;
2343 uint32_t uiFrmByte = 0;
2344
2345 if (pCtx->pSvcParam->bEnableRc) {
2346 //RC case
2347 uiFrmByte = (
2348 ((uint32_t) (pCtx->pSvcParam->sDependencyLayers[iCurDid].iSpatialBitrate)
2349 / (uint32_t) (pCtx->pSvcParam->sDependencyLayers[iCurDid].fInputFrameRate)) >> 3);
2350 } else {
2351 //fixed QP case
2352 int32_t iQDeltaTo26 = (26 - pCtx->pSvcParam->sDependencyLayers[iCurDid].iDLayerQp);
2353
2354 uiFrmByte = (iTtlMbNumInFrame * byte_complexIMBat26);
2355 if (iQDeltaTo26 > 0) {
2356 //smaller QP than 26
2357 uiFrmByte = (uint32_t) (uiFrmByte * ((float)iQDeltaTo26 / 4));
2358 } else if (iQDeltaTo26 < 0) {
2359 //larger QP than 26
2360 iQDeltaTo26 = ((-iQDeltaTo26) >> 2); //delta mod 4
2361 uiFrmByte = (uiFrmByte >> (iQDeltaTo26)); //if delta 4, byte /2
2362 }
2363 }
2364
2365 //MINPACKETSIZE_CONSTRAINT
2366 if (pSliceCtx->uiSliceSizeConstraint
2367 <
2368 (uint32_t) (uiFrmByte//suppose 16 byte per mb at average
2369 / (pSliceCtx->iMaxSliceNumConstraint))
2370 ) {
2371
2372 WelsLog (pCtx,
2373 WELS_LOG_WARNING,
2374 "Set-SliceConstraint(%d) too small for current resolution (MB# %d) under QP/BR!\n",
2375 pSliceCtx->uiSliceSizeConstraint,
2376 pSliceCtx->iMbNumInFrame
2377 );
2378 }
2379 }
2380
2381 WelsInitCurrentQBLayerMltslc (pCtx);
2382}
2383#endif
2384 2234
2385/*!2235/*!
2386 * \brief initialize current layer2236 * \brief initialize current layer
@@ -2880,9 +2730,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 493 unmodified lines
2880 SPicture* fsnr = NULL;2730 SPicture* fsnr = NULL;
2881#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC2731#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC
2882 SPicture* pEncPic = NULL; // to be decided later2732 SPicture* pEncPic = NULL; // to be decided later
2883#if defined(MT_ENABLED)
2884 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};2733 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};
2885#endif//MT_ENABLED
2886 int32_t iLayerNum = 0;2734 int32_t iLayerNum = 0;
2887 int32_t iLayerSize = 0;2735 int32_t iLayerSize = 0;
2888 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame2736 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
@@ -2972,22 +2820,18 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 83 unmodified lines
2972 iCurWidth = param_d->iFrameWidth;2820 iCurWidth = param_d->iFrameWidth;
2973 iCurHeight = param_d->iFrameHeight;2821 iCurHeight = param_d->iFrameHeight;
2974 2822
2975#if defined(MT_ENABLED)
2976 did_list[iSpatialIdx] = iCurDid;2823 did_list[iSpatialIdx] = iCurDid;
2977#endif//MT_ENABLED
2978 2824
2979 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed2825 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed
2980 2826
2981 switch (param_d->sSliceCfg.uiSliceMode) {2827 switch (param_d->sSliceCfg.uiSliceMode) {
2982 case SM_FIXEDSLCNUM_SLICE:2828 case SM_FIXEDSLCNUM_SLICE:
2983 case SM_AUTO_SLICE:{2829 case SM_AUTO_SLICE:{
2984#if defined(MT_ENABLED)
2985 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&2830 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&
2986 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE2831 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
2987 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)2832 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)
2988 )2833 )
2989 AdjustEnhanceLayer (pCtx, iCurDid);2834 AdjustEnhanceLayer (pCtx, iCurDid);
2990#endif//MT_ENABLED
2991 break;2835 break;
2992 }2836 }
2993 case SM_DYN_SLICE: {2837 case SM_DYN_SLICE: {
@@ -3100,18 +2944,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 106 unmodified lines
3100 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;2944 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;
3101 }2945 }
3102 // for dynamic slicing single threading..2946 // for dynamic slicing single threading..
3103#ifndef MT_ENABLED
3104 else if (SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode)
3105#else // MT_ENABLED
3106 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1))2947 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1))
3107#endif//MT_ENABLED
3108 {2948 {
3109 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;2949 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;
3110 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);2950 pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0);
3111 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)2951 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3112 } else {2952 } else {
3113 //other multi-slice uiSliceMode2953 //other multi-slice uiSliceMode
3114#if defined(MT_ENABLED)
3115 int err = 0;2954 int err = 0;
3116 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE2955 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE
3117 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {2956 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
@@ -3235,7 +3074,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 117 unmodified lines
3235 3074
3236 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);3075 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);
3237 } else // for non-dynamic-slicing mode single threading branch..3076 } else // for non-dynamic-slicing mode single threading branch..
3238#endif//MT_ENABLED
3239 {3077 {
3240 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;3078 const bool bNeedPrefix = pCtx->bNeedPrefixNalFlag;
3241 int32_t iSliceIdx = 0;3079 int32_t iSliceIdx = 0;
@@ -3290,9 +3128,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 48 unmodified lines
3290 3128
3291 // deblocking filter3129 // deblocking filter
3292 if (3130 if (
3293#if defined(MT_ENABLED)
3294 (!pCtx->pCurDqLayer->bDeblockingParallelFlag) &&3131 (!pCtx->pCurDqLayer->bDeblockingParallelFlag) &&
3295#endif//MT_ENABLED
3296#if !defined(ENABLE_FRAME_DUMP)3132#if !defined(ENABLE_FRAME_DUMP)
3297 ((eNalRefIdc != NRI_PRI_LOWEST) && (param_d->iHighestTemporalId == 0 || iCurTid < param_d->iHighestTemporalId)) &&3133 ((eNalRefIdc != NRI_PRI_LOWEST) && (param_d->iHighestTemporalId == 0 || iCurTid < param_d->iHighestTemporalId)) &&
3298#endif//!ENABLE_FRAME_DUMP3134#endif//!ENABLE_FRAME_DUMP
@@ -3432,7 +3268,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 133 unmodified lines
3432 ++ iLayerNum;3268 ++ iLayerNum;
3433 }3269 }
3434 3270
3435#if defined(MT_ENABLED)
3436 if ((param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE||param_d->sSliceCfg.uiSliceMode == SM_AUTO_SLICE) && pSvcParam->iMultipleThreadIdc > 1 &&3271 if ((param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE||param_d->sSliceCfg.uiSliceMode == SM_AUTO_SLICE) && pSvcParam->iMultipleThreadIdc > 1 &&
3437 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {3272 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {
3438 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,3273 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,
@@ -3441,7 +3276,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3441 TrackSliceComplexities (pCtx, iCurDid);3276 TrackSliceComplexities (pCtx, iCurDid);
3442#endif//#if defined(MT_DEBUG)3277#endif//#if defined(MT_DEBUG)
3443 }3278 }
3444#endif//MT_ENABLED
3445 3279
3446 ++ iSpatialIdx;3280 ++ iSpatialIdx;
3447 3281
@@ -3468,11 +3302,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 20 unmodified lines
3468 }3302 }
3469 }3303 }
3470 3304
3471#if defined(MT_ENABLED) && defined(MT_DEBUG)3305#if defined(MT_DEBUG)
3472 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);3306 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);
3473#endif//MT_ENABLED && MT_DEBUG3307#endif//MT_DEBUG
3474 3308
3475#if defined(MT_ENABLED)
3476 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID3309 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID
3477 && ((pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))3310 && ((pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_AUTO_SLICE))
3478 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum3311 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum
@@ -3481,7 +3314,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3481 1]].sSliceCfg.sSliceArgument.uiSliceNum) {3314 1]].sSliceCfg.sSliceArgument.uiSliceNum) {
3482 AdjustBaseLayer (pCtx);3315 AdjustBaseLayer (pCtx);
3483 }3316 }
3484#endif
3485 3317
3486#ifdef ENABLE_FRAME_DUMP3318#ifdef ENABLE_FRAME_DUMP
3487 DumpRecFrame (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum -3319 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