History

Merge pull request #369 from sijchen/mt_refactor3

[Encoder] remove macros to clear codes

Ethan Hugg committed 12 years ago

Commit 6e9df662 parents 33017fa 10a4fb05 files · +35 −520Browse 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+19−192
@@ -54,9 +54,7 @@ · 53 unmodified lines
54#if defined(MT_ENABLED)54#if defined(MT_ENABLED)
55#include "slice_multi_threading.h"55#include "slice_multi_threading.h"
56#endif//MT_ENABLED56#endif//MT_ENABLED
57#if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG)
58#include "measure_time.h"57#include "measure_time.h"
59#endif//DYNAMIC_SLICE_ASSIGN
60 58
61namespace WelsSVCEnc {59namespace WelsSVCEnc {
62 60
@@ -467,9 +465,6 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 404 unmodified lines
467 int32_t iCountNumNals = 0;465 int32_t iCountNumNals = 0;
468 int32_t iNumDependencyLayers = 0;466 int32_t iNumDependencyLayers = 0;
469 int32_t iDIndex = 0;467 int32_t iDIndex = 0;
470#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
471 int32_t iNumLayersPack = 0;
472#endif//MT_ENABLED && PACKING_ONE_SLICE_PER_LAYER
473 468
474 if (NULL == pParam || NULL == ppCtx || NULL == *ppCtx)469 if (NULL == pParam || NULL == ppCtx || NULL == *ppCtx)
475 return 1;470 return 1;
@@ -491,12 +486,7 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 15 unmodified lines
491 if (iDIndex == 0)486 if (iDIndex == 0)
492 iCountNumNals += MAX_SLICES_NUM;487 iCountNumNals += MAX_SLICES_NUM;
493 // MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME ensured at svc_enc_slice_segment.h488 // MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME ensured at svc_enc_slice_segment.h
494#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
495 assert (MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME);
496 // iNumLayersPack += MAX_SLICES_NUM; // do not count it for dynamic slicing mode
497#else//!MT_ENABLED || !PACKING_ONE_SLICE_PER_LAYER
498 assert (iCountNumNals - iOrgNumNals <= MAX_NAL_UNITS_IN_LAYER);489 assert (iCountNumNals - iOrgNumNals <= MAX_NAL_UNITS_IN_LAYER);
499#endif//MT_ENABLED && PACKING_ONE_SLICE_PER_LAYER
500 } else { /*if ( SM_SINGLE_SLICE != pDLayer->sSliceCfg.uiSliceMode )*/490 } else { /*if ( SM_SINGLE_SLICE != pDLayer->sSliceCfg.uiSliceMode )*/
501 const int32_t kiNumOfSlice = GetInitialSliceNum ((pDLayer->iFrameWidth + 0x0f) >> 4,491 const int32_t kiNumOfSlice = GetInitialSliceNum ((pDLayer->iFrameWidth + 0x0f) >> 4,
502 (pDLayer->iFrameHeight + 0x0f) >> 4,492 (pDLayer->iFrameHeight + 0x0f) >> 4,
@@ -507,12 +497,7 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 4 unmodified lines
507 // plus prefix NALs497 // plus prefix NALs
508 if (iDIndex == 0)498 if (iDIndex == 0)
509 iCountNumNals += kiNumOfSlice;499 iCountNumNals += kiNumOfSlice;
510#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
511 assert (num_of_slice <= MAX_SLICES_NUM && MAX_SLICES_NUM < MAX_LAYER_NUM_OF_FRAME);
512 iNumLayersPack += num_of_slice;
513#else//!MT_ENABLED || !PACKING_ONE_SLICE_PER_LAYER
514 assert (iCountNumNals - iOrgNumNals <= MAX_NAL_UNITS_IN_LAYER);500 assert (iCountNumNals - iOrgNumNals <= MAX_NAL_UNITS_IN_LAYER);
515#endif//MT_ENALBED && PACKING_ONE_SLICE_PER_LAYER
516 if (kiNumOfSlice > MAX_SLICES_NUM) {501 if (kiNumOfSlice > MAX_SLICES_NUM) {
517 WelsLog (*ppCtx, WELS_LOG_ERROR,502 WelsLog (*ppCtx, WELS_LOG_ERROR,
518 "AcquireLayersNals(), num_of_slice(%d) > MAX_SLICES_NUM(%d) per (iDid= %d, qid= %d) settings!\n",503 "AcquireLayersNals(), num_of_slice(%d) > MAX_SLICES_NUM(%d) per (iDid= %d, qid= %d) settings!\n",
@@ -520,14 +505,13 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 1 unmodified line
520 return 1;505 return 1;
521 }506 }
522 }507 }
523#if !defined(MT_ENABLED) || !defined(PACKING_ONE_SLICE_PER_LAYER)508
524 if (iCountNumNals - iOrgNumNals > MAX_NAL_UNITS_IN_LAYER) {509 if (iCountNumNals - iOrgNumNals > MAX_NAL_UNITS_IN_LAYER) {
525 WelsLog (*ppCtx, WELS_LOG_ERROR,510 WelsLog (*ppCtx, WELS_LOG_ERROR,
526 "AcquireLayersNals(), num_of_nals(%d) > MAX_NAL_UNITS_IN_LAYER(%d) per (iDid= %d, qid= %d) settings!\n",511 "AcquireLayersNals(), num_of_nals(%d) > MAX_NAL_UNITS_IN_LAYER(%d) per (iDid= %d, qid= %d) settings!\n",
527 (iCountNumNals - iOrgNumNals), MAX_NAL_UNITS_IN_LAYER, iDIndex, 0);512 (iCountNumNals - iOrgNumNals), MAX_NAL_UNITS_IN_LAYER, iDIndex, 0);
528 return 1;513 return 1;
529 }514 }
530#endif//!MT_ENABLED) || !PACKING_ONE_SLICE_PER_LAYER
531 515
532 iCountNumLayers ++;516 iCountNumLayers ++;
533 517
@@ -536,9 +520,6 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 2 unmodified lines
536 520
537 iCountNumNals += 1 + iNumDependencyLayers + (iCountNumLayers << 1) +521 iCountNumNals += 1 + iNumDependencyLayers + (iCountNumLayers << 1) +
538 iCountNumLayers; // plus iCountNumLayers for reserved application522 iCountNumLayers; // plus iCountNumLayers for reserved application
539#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
540 iNumLayersPack += 1 + iNumDependencyLayers + (iCountNumLayers << 1);
541#endif//MT_ENABLED && PACKING_ONE_SLICE_PER_LAYER
542 523
543 // to check number of layers / nals / slices dependencies, 12/8/2010524 // to check number of layers / nals / slices dependencies, 12/8/2010
544#if !defined(MT_ENABLED)525#if !defined(MT_ENABLED)
@@ -548,19 +529,11 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 3 unmodified lines
548 return 1;529 return 1;
549 }530 }
550#else//MT_ENABLED531#else//MT_ENABLED
551#if defined(PACKING_ONE_SLICE_PER_LAYER)
552 if (iNumLayersPack > MAX_LAYER_NUM_OF_FRAME) {
553 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), num_layers_pack_overall(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
554 iNumLayersPack, MAX_LAYER_NUM_OF_FRAME);
555 return 1;
556 }
557#else//!PACKING_ONE_SLICE_PER_LAYER
558 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {532 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
559 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",533 WelsLog (*ppCtx, WELS_LOG_ERROR, "AcquireLayersNals(), iCountNumLayers(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
560 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);534 iCountNumLayers, MAX_LAYER_NUM_OF_FRAME);
561 return 1;535 return 1;
562 }536 }
563#endif//PACKING_ONE_SLICE_PER_LAYER
564#endif//!MT_ENABLED537#endif//!MT_ENABLED
565 538
566 if (NULL != pCountLayers)539 if (NULL != pCountLayers)
@@ -1770,14 +1743,9 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 1203 unmodified lines
1770 const int32_t kiMbHeight = (pDlp->iFrameHeight + 15) >> 4;1743 const int32_t kiMbHeight = (pDlp->iFrameHeight + 15) >> 4;
1771 const int32_t kiMbNumInFrame = kiMbWidth * kiMbHeight;1744 const int32_t kiMbNumInFrame = kiMbWidth * kiMbHeight;
1772#if defined(MT_ENABLED)1745#if defined(MT_ENABLED)
1773#if defined(DYNAMIC_SLICE_ASSIGN)
1774 int32_t iSliceNum = (SM_FIXEDSLCNUM_SLICE == pMso->uiSliceMode1746 int32_t iSliceNum = (SM_FIXEDSLCNUM_SLICE == pMso->uiSliceMode
1775 || SM_DYN_SLICE == pMso->uiSliceMode) ? kiCpuCores :1747 || SM_DYN_SLICE == pMso->uiSliceMode) ? kiCpuCores :
1776 pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()1748 pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()
1777#else//!DYNAMIC_SLICE_ASSIGN
1778 int32_t iSliceNum = (SM_DYN_SLICE == pMso->uiSliceMode) ? kiCpuCores :
1779 pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()
1780#endif//DYNAMIC_SLICE_ASSIGN
1781#else//!MT_ENABLED1749#else//!MT_ENABLED
1782 int16_t iSliceNum = pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()1750 int16_t iSliceNum = pSlcArg->uiSliceNum; // uiSliceNum per input has been validated at ParamValidationExt()
1783#endif//MT_ENABLED1751#endif//MT_ENABLED
@@ -2215,7 +2183,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 431 unmodified lines
2215 res);2183 res);
2216 (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;2184 (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;
2217 }2185 }
2218#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE)
2219 if ((*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx]) {2186 if ((*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx]) {
2220 res = WelsThreadCancel ((*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx]);2187 res = WelsThreadCancel ((*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx]);
2221 WelsLog (*ppCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), WelsThreadCancel(pUpdateMbListThrdHandles%d) return %d..\n",2188 WelsLog (*ppCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), WelsThreadCancel(pUpdateMbListThrdHandles%d) return %d..\n",
@@ -2225,7 +2192,6 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 3 unmodified lines
2225 iThreadIdx, res);2192 iThreadIdx, res);
2226 (*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx] = 0;2193 (*ppCtx)->pSliceThreading->pUpdateMbListThrdHandles[iThreadIdx] = 0;
2227 }2194 }
2228#endif//DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE
2229 ++ iThreadIdx;2195 ++ iThreadIdx;
2230 }2196 }
2231#endif//WIN322197#endif//WIN32
@@ -2306,10 +2272,8 @@ int32_t PicPartitionNumDecision (sWelsEncCtx* pCtx) { · 74 unmodified lines
2306#ifdef MT_ENABLED2272#ifdef MT_ENABLED
2307 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {2273 if (pCtx->pSvcParam->iMultipleThreadIdc > 1) {
2308 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;2274 iPartitionNum = pCtx->pSvcParam->iCountThreadsNum;
2309#if !defined(FIXED_PARTITION_ASSIGN)
2310 if (P_SLICE == pCtx->eSliceType)2275 if (P_SLICE == pCtx->eSliceType)
2311 iPartitionNum = 1;2276 iPartitionNum = 1;
2312#endif//!FIXED_PARTITION_ASSIGN
2313 }2277 }
2314 return iPartitionNum;2278 return iPartitionNum;
2315#else2279#else
@@ -2946,71 +2910,6 @@ int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen, int32_t& iSize) { · 630 unmodified lines
2946 return ENC_RETURN_SUCCESS;2910 return ENC_RETURN_SUCCESS;
2947}2911}
2948 2912
2949/*
2950 * post process of dynamic slicing bs writing in case PACKING_ONE_SLICE_PER_LAYER
2951 * include: count bs size of over all the slices in layer,
2952 * return: count number of slices in layer
2953 */
2954#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)
2955int32_t PostProcDynamicSlicingBsWriting (sWelsEncCtx* pCtx, SLayerBSInfo* pLayerBsInfo, int32_t* pLayerSize,
2956 const int32_t kiPartitionCnt) {
2957 SDqLayer* pCurDq = pCtx->pCurDqLayer;
2958 int32_t iPartitionIdx = 0;
2959 int32_t iCheckingIdx = 0;
2960 int32_t iSwappingIdx = -1;
2961 int32_t iSliceCount = 0;
2962 int32_t iLayerSize = 0;
2963
2964 // count number of slices in layer and layer size
2965 while (iPartitionIdx < kiPartitionCnt) {
2966 const int32_t coded_slice_cnt = pCurDq->pNumSliceCodedOfPartition[iPartitionIdx];
2967 iLayerSize += pCtx->pSliceThreading->pCountBsSizeInPartition[iPartitionIdx];
2968 iSliceCount += coded_slice_cnt;
2969 ++ iPartitionIdx;
2970 }
2971 *pLayerSize = iLayerSize;
2972
2973 // reordering pLayerBs pointers, but do not ensure raster scan order of picture
2974 // just maintain discontinuous items,i.e,
2975 // input:
2976 // partition 1: uiSliceIdx: 0 2 4 6
2977 // partition 2: uiSliceIdx: 1 3 5 7 9 11 13
2978 // output:
2979 // uiSliceIdx: 0 1 2 3 4 5 6 7 8 9 10
2980 iCheckingIdx = 0;
2981 while (true) {
2982 bool bMatchFlag = false;
2983 iPartitionIdx = 0;
2984 while (iPartitionIdx < kiPartitionCnt) {
2985 const int32_t coded_slice_cnt = pCurDq->pNumSliceCodedOfPartition[iPartitionIdx];
2986 // iCheckingIdx need convert to iIndex of iPartitionIdx based to avoid linear searching
2987 // belong this partition and not exceed the number of slices coded in partition
2988 if (iPartitionIdx == (iCheckingIdx % kiPartitionCnt)
2989 && iCheckingIdx / kiPartitionCnt < coded_slice_cnt) {
2990 if (iSwappingIdx >= 0) {
2991 // memory swapping
2992 memmove (pLayerBsInfo + iSwappingIdx, LayerBsInfo + iCheckingIdx, sizeof (SLayerBSInfo)); // confirmed_safe_unsafe_usage
2993 ++ iSwappingIdx; // record iSwappingIdx
2994 }
2995 ++ iCheckingIdx;
2996 bMatchFlag = true;
2997 break;
2998 }
2999 ++ iPartitionIdx;
3000 }
3001 if (!bMatchFlag) {
3002 if (iSwappingIdx < 0)
3003 iSwappingIdx = iCheckingIdx;
3004 ++ iCheckingIdx;
3005 }
3006 if (iSwappingIdx >= iSliceCount)
3007 break;
3008 }
3009
3010 return iSliceCount;
3011}
3012#endif//MT_ENABLED && PACKING_ONE_SLICE_PER_LAYER
3013
3014/*2913/*
3015 * Force coding IDR as follows2914 * Force coding IDR as follows
3016 */2915 */
@@ -3072,9 +2971,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 55 unmodified lines
3072 SPicture* fsnr = NULL;2971 SPicture* fsnr = NULL;
3073#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC2972#endif//ENABLE_FRAME_DUMP || ENABLE_PSNR_CALC
3074 SPicture* pEncPic = NULL; // to be decided later2973 SPicture* pEncPic = NULL; // to be decided later
3075#if defined(MT_ENABLED) && (defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG))2974#if defined(MT_ENABLED)
3076 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};2975 int32_t did_list[MAX_DEPENDENCY_LAYER] = {0};
3077#endif//MT_ENABLED && DYNAMIC_SLICE_ASSIGN2976#endif//MT_ENABLED
3078 int32_t iLayerNum = 0;2977 int32_t iLayerNum = 0;
3079 int32_t iLayerSize = 0;2978 int32_t iLayerSize = 0;
3080 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame2979 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
@@ -3164,21 +3063,21 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 83 unmodified lines
3164 iCurWidth = param_d->iFrameWidth;3063 iCurWidth = param_d->iFrameWidth;
3165 iCurHeight = param_d->iFrameHeight;3064 iCurHeight = param_d->iFrameHeight;
3166 3065
3167#if defined(MT_ENABLED) && (defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG))3066#if defined(MT_ENABLED)
3168 did_list[iSpatialIdx] = iCurDid;3067 did_list[iSpatialIdx] = iCurDid;
3169#endif//MT_ENABLED && DYNAMIC_SLICE_ASSIGN3068#endif//MT_ENABLED
3170 3069
3171 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed3070 // Encoding this picture might mulitiple sQualityStat layers potentially be encoded as followed
3172 3071
3173 switch (param_d->sSliceCfg.uiSliceMode) {3072 switch (param_d->sSliceCfg.uiSliceMode) {
3174 case SM_FIXEDSLCNUM_SLICE: {3073 case SM_FIXEDSLCNUM_SLICE: {
3175#if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN)3074#if defined(MT_ENABLED)
3176 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&3075 if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) &&
3177 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE3076 (pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
3178 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)3077 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[iCurDid].sSliceCfg.sSliceArgument.uiSliceNum)
3179 )3078 )
3180 AdjustEnhanceLayer (pCtx, iCurDid);3079 AdjustEnhanceLayer (pCtx, iCurDid);
3181#endif//MT_ENABLED && DYNAMIC_SLICE_ASSIGN3080#endif//MT_ENABLED
3182 break;3081 break;
3183 }3082 }
3184 case SM_DYN_SLICE: {3083 case SM_DYN_SLICE: {
@@ -3307,13 +3206,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 122 unmodified lines
3307 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE3206 // THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE
3308 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {3207 if ((SM_DYN_SLICE != param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
3309 iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);3208 iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
3310 if (iLayerNum +3209 if (iLayerNum + 1 >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info for further writing as followed
3311#if defined(PACKING_ONE_SLICE_PER_LAYER)
3312 iSliceCount
3313#else
3314 1
3315#endif//PACKING_ONE_SLICE_PER_LAYER
3316 >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info for further writing as followed
3317 WelsLog (pCtx, WELS_LOG_ERROR,3210 WelsLog (pCtx, WELS_LOG_ERROR,
3318 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",3211 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",
3319 iLayerNum, MAX_LAYER_NUM_OF_FRAME, iCurDid, param_d->sSliceCfg.uiSliceMode, iSliceCount);3212 iLayerNum, MAX_LAYER_NUM_OF_FRAME, iCurDid, param_d->sSliceCfg.uiSliceMode, iSliceCount);
@@ -3327,17 +3220,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 7 unmodified lines
3327 }3220 }
3328 3221
3329 if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE3222 if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE
3330#if defined(PACKING_ONE_SLICE_PER_LAYER)3223#if defined(MT_DEBUG)
3331 int32_t iSliceIdx = 1;
3332 int32_t iOrgSlicePos[MAX_SLICES_NUM] = {0};
3333 iOrgSlicePos[0] = pCtx->iPosBsBuffer;
3334 while (uiSliceIdx < iSliceCount) {
3335 iOrgSlicePos[uiSliceIdx] = pCtx->pSliceBs[uiSliceIdx].uiBsPos;
3336 ++ uiSliceIdx;
3337 }
3338#elif defined(MT_DEBUG)
3339 int64_t t_bs_append = 0;3224 int64_t t_bs_append = 0;
3340#endif//PACKING_ONE_SLICE_PER_LAYER3225#endif
3341 3226
3342 pCtx->iActiveThreadsNum = iSliceCount;3227 pCtx->iActiveThreadsNum = iSliceCount;
3343 // to fire slice coding threads3228 // to fire slice coding threads
@@ -3357,16 +3242,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 13 unmodified lines
3357 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)3242 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3358 3243
3359 // append exclusive slice 0 bs to pFrameBs3244 // append exclusive slice 0 bs to pFrameBs
3360#if defined(PACKING_ONE_SLICE_PER_LAYER)
3361 iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0];
3362 uiSliceIdx = 1;
3363 while (uiSliceIdx < iSliceCount) {
3364 iLayerSize += pCtx->pSliceBs[uiSliceIdx].uiBsPos - iOrgSlicePos[uiSliceIdx];
3365 ++ uiSliceIdx;
3366 }
3367 iLayerNum += iSliceCount; // each slice stickly output as layer info for performance improvement directly
3368 pLayerBsInfo += iSliceCount;
3369#else
3370#if defined(MT_DEBUG)3245#if defined(MT_DEBUG)
3371 t_bs_append = WelsTime();3246 t_bs_append = WelsTime();
3372#endif//MT_DEBUG3247#endif//MT_DEBUG
@@ -3383,20 +3258,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 10 unmodified lines
3383 t_bs_append, pCtx->iCodingIndex, iCurDid, 0);3258 t_bs_append, pCtx->iCodingIndex, iCurDid, 0);
3384 }3259 }
3385#endif//MT_DEBUG3260#endif//MT_DEBUG
3386#endif//PACKING_ONE_SLICE_PER_LAYER
3387 } else { //THREAD_PICK_UP_MODE3261 } else { //THREAD_PICK_UP_MODE
3388 int32_t iNumThreadsRunning = 0;3262 int32_t iNumThreadsRunning = 0;
3389 int32_t iNumThreadsScheduled = 0;3263 int32_t iNumThreadsScheduled = 0;
3390 int32_t iIndexOfSliceToBeCoded = 0;3264 int32_t iIndexOfSliceToBeCoded = 0;
3391#if defined(PACKING_ONE_SLICE_PER_LAYER)
3392 int32_t iSliceIdx = 1;
3393 int32_t iOrgSlicePos[MAX_SLICES_NUM] = {0};
3394 iOrgSlicePos[0] = pCtx->iPosBsBuffer;
3395 while (uiSliceIdx < iSliceCount) {
3396 iOrgSlicePos[uiSliceIdx] = pCtx->pSliceBs[uiSliceIdx].uiBsPos;
3397 ++ uiSliceIdx;
3398 }
3399#endif//PACKING_ONE_SLICE_PER_LAYER
3400 3265
3401 pCtx->iActiveThreadsNum = pSvcParam->iCountThreadsNum;3266 pCtx->iActiveThreadsNum = pSvcParam->iCountThreadsNum;
3402 iNumThreadsScheduled = pCtx->iActiveThreadsNum;3267 iNumThreadsScheduled = pCtx->iActiveThreadsNum;
@@ -3428,9 +3293,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 25 unmodified lines
3428 // pick up succeeding slice for threading3293 // pick up succeeding slice for threading
3429 // thread_id equal to iEventId per implementation here3294 // thread_id equal to iEventId per implementation here
3430 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;3295 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;
3431#ifdef PACKING_ONE_SLICE_PER_LAYER
3432 pCtx->pSliceThreading->pThreadPEncCtx[iEventId].pLayerBs = pLayerBsInfo + iIndexOfSliceToBeCoded;
3433#endif//PACKING_ONE_SLICE_PER_LAYER
3434 WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);3296 WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);
3435 3297
3436 ++ iIndexOfSliceToBeCoded;3298 ++ iIndexOfSliceToBeCoded;
@@ -3452,9 +3314,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 15 unmodified lines
3452 if (iIndexOfSliceToBeCoded >= iSliceCount)3314 if (iIndexOfSliceToBeCoded >= iSliceCount)
3453 break;3315 break;
3454 pCtx->pSliceThreading->pThreadPEncCtx[iThreadIdx].iSliceIndex = iIndexOfSliceToBeCoded;3316 pCtx->pSliceThreading->pThreadPEncCtx[iThreadIdx].iSliceIndex = iIndexOfSliceToBeCoded;
3455#ifdef PACKING_ONE_SLICE_PER_LAYER
3456 pCtx->pSliceThreading->pThreadPEncCtx[iThreadIdx].pLayerBs = pLayerBsInfo + iIndexOfSliceToBeCoded;
3457#endif//PACKING_ONE_SLICE_PER_LAYER
3458 WelsEventSignal (pCtx->pSliceThreading->pReadySliceCodingEvent[iThreadIdx]);3317 WelsEventSignal (pCtx->pSliceThreading->pReadySliceCodingEvent[iThreadIdx]);
3459 3318
3460 ++ iIndexOfSliceToBeCoded;3319 ++ iIndexOfSliceToBeCoded;
@@ -3468,31 +3327,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 7 unmodified lines
3468#endif//_WIN323327#endif//_WIN32
3469 }//while(1)3328 }//while(1)
3470 3329
3471// all slices are finished coding here3330 // all slices are finished coding here
3472 // append exclusive slice 0 bs to pFrameBs3331 // append exclusive slice 0 bs to pFrameBs
3473#if defined(PACKING_ONE_SLICE_PER_LAYER)
3474 iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0];
3475 uiSliceIdx = 1;
3476 while (uiSliceIdx < iSliceCount) {
3477 iLayerSize += pCtx->pSliceBs[uiSliceIdx].uiBsPos - iOrgSlicePos[uiSliceIdx];
3478 ++ uiSliceIdx;
3479 }
3480 iLayerNum += iSliceCount; // each slice stickly output as layer info for performance improvement directly
3481 pLayerBsInfo += iSliceCount;
3482#else
3483 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);3332 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
3484#endif//PACKING_ONE_SLICE_PER_LAYER
3485 }3333 }
3486 }3334 }
3487 // THREAD_FULLY_FIRE_MODE && SM_DYN_SLICE3335 // THREAD_FULLY_FIRE_MODE && SM_DYN_SLICE
3488 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {3336 else if ((SM_DYN_SLICE == param_d->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
3489 const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; //pSvcParam->iCountThreadsNum;3337 const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; //pSvcParam->iCountThreadsNum;
3490#if defined(PACKING_ONE_SLICE_PER_LAYER)
3491 ResetCountBsSizeInPartitions (pCtx->pSliceThreading->pCountBsSizeInPartition, kiPartitionCnt);
3492 pCtx->pCurDqLayer->pSliceEncCtx->iMaxSliceNumConstraint = WELS_MIN (MAX_SLICES_NUM,
3493 DynamicMaxSliceNumConstraint (MAX_LAYER_NUM_OF_FRAME, iLayerNum, 1 + /*( num_qlayer - 1) +*/ (((iCurDid == 0)
3494 && (pSvcParam->uiGopSize > 1)) ? 1 : 0)));
3495#endif//PACKING_ONE_SLICE_PER_LAYER
3496 3338
3497 // to fire slice coding threads3339 // to fire slice coding threads
3498 err = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],3340 err = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
@@ -3507,14 +3349,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 8 unmodified lines
3507 WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]);3349 WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3508 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)3350 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3509 3351
3510#if defined(PACKING_ONE_SLICE_PER_LAYER)
3511 iSliceCount = PostProcDynamicSlicingBsWriting (pCtx, pLayerBsInfo, &iLayerSize, kiPartitionCnt);
3512 assert (iLayerNum + iSliceCount < MAX_LAYER_NUM_OF_FRAME);
3513 pLayerBsInfo += iSliceCount;
3514 iLayerNum += iSliceCount;
3515#else
3516 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);3352 iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, kiPartitionCnt);
3517#endif//PACKING_ONE_SLICE_PER_LAYER
3518 } else // for non-dynamic-slicing mode single threading branch..3353 } else // for non-dynamic-slicing mode single threading branch..
3519#endif//MT_ENABLED3354#endif//MT_ENABLED
3520 {3355 {
@@ -3681,16 +3516,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 160 unmodified lines
3681 }3516 }
3682#endif//STAT_OUTPUT3517#endif//STAT_OUTPUT
3683 3518
3684#if defined(MT_ENABLED) && defined(PACKING_ONE_SLICE_PER_LAYER)3519 ++ iLayerNum;
3685 if (pSvcParam->iMultipleThreadIdc <= 1 || SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) // sigle thread actually used3520 ++ pLayerBsInfo;
3686#else
3687 if (1)
3688#endif//MT_ENABLED && PACKING_ONE_SLICE_PER_LAYER
3689 {
3690 ++ iLayerNum;
3691 ++ pLayerBsInfo;
3692 }
3693
3694 3521
3695 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;3522 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3696 3523
@@ -3722,7 +3549,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 25 unmodified lines
3722 ++ iLayerNum;3549 ++ iLayerNum;
3723 }3550 }
3724 3551
3725#if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE)3552#if defined(MT_ENABLED)
3726 if (param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE && pSvcParam->iMultipleThreadIdc > 1 &&3553 if (param_d->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE && pSvcParam->iMultipleThreadIdc > 1 &&
3727 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {3554 pSvcParam->iMultipleThreadIdc >= param_d->sSliceCfg.sSliceArgument.uiSliceNum) {
3728 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,3555 CalcSliceComplexRatio (pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], pCtx->pCurDqLayer->pSliceEncCtx,
@@ -3731,7 +3558,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3731 TrackSliceComplexities (pCtx, iCurDid);3558 TrackSliceComplexities (pCtx, iCurDid);
3732#endif//#if defined(MT_DEBUG)3559#endif//#if defined(MT_DEBUG)
3733 }3560 }
3734#endif//MT_ENABLED && DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE3561#endif//MT_ENABLED
3735 3562
3736 ++ iSpatialIdx;3563 ++ iSpatialIdx;
3737 3564
@@ -3762,7 +3589,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 24 unmodified lines
3762 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);3589 TrackSliceConsumeTime (pCtx, did_list, iSpatialNum);
3763#endif//MT_ENABLED && MT_DEBUG3590#endif//MT_ENABLED && MT_DEBUG
3764 3591
3765#if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN)3592#if defined(MT_ENABLED)
3766 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID3593 if (pSvcParam->iMultipleThreadIdc > 1 && did_list[0] == BASE_DEPENDENCY_ID
3767 && pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE3594 && pSvcParam->sDependencyLayers[0].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
3768 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum3595 && pSvcParam->iMultipleThreadIdc >= pSvcParam->sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum
@@ -3771,7 +3598,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou · 2 unmodified lines
3771 1]].sSliceCfg.sSliceArgument.uiSliceNum) {3598 1]].sSliceCfg.sSliceArgument.uiSliceNum) {
3772 AdjustBaseLayer (pCtx);3599 AdjustBaseLayer (pCtx);
3773 }3600 }
3774#endif//DYNAMIC_SLICE_ASSIGN3601#endif
3775 3602
3776#ifdef ENABLE_FRAME_DUMP3603#ifdef ENABLE_FRAME_DUMP
3777 DumpRecFrame (fsnr, &pSvcParam->sDependencyLayers[pSvcParam->iSpatialLayerNum -3604 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