Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 1 file). Show all
Unified · Split
| @@ -862,10 +862,6 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 861 unmodified lines | ||
| 862 | 862 | const bool kbCurMbNotFirstMbOfCurSlice = (pSliceCtx->pOverallMbMap[iCurMbIdx] == |
| 863 | 863 | pSliceCtx->pOverallMbMap[iCurMbIdx - 1]); |
| 864 | 864 | const bool kbCurMbNotLastMbOfCurPartition = iCurMbIdx < kiLastMbIdxInPartition; |
| 865 | − const bool kbSliceNumNotExceedConstraint = pSliceCtx->iSliceNumInFrame < | |
| 866 | − pSliceCtx->iMaxSliceNumConstraint; /*tmp choice to avoid complex memory operation, 100520, to be modify*/ | |
| 867 | − const bool kbSliceNumReachConstraint = (pSliceCtx->iSliceNumInFrame == | |
| 868 | − pSliceCtx->iMaxSliceNumConstraint); | |
| 869 | 865 | |
| 870 | 866 | if (pCurSlice->bDynamicSlicingSliceSizeCtrlFlag) |
| 871 | 867 | return false; |
| @@ -876,45 +872,50 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 4 unmodified lines | ||
| 876 | 872 | #endif |
| 877 | 873 | uiLen = ((iPosBitOffset >> 3) + ((iPosBitOffset & 0x07) ? 1 : 0)); |
| 878 | 874 | |
| 879 | − if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) | |
| 880 | − WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 875 | + if ((kbCurMbNotFirstMbOfCurSlice | |
| 876 | + && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, pSliceCtx->uiSliceSizeConstraint)) /*jump_avoiding_pack_exceed*/ | |
| 877 | + && kbCurMbNotLastMbOfCurPartition) { //decide to add new pSlice | |
| 881 | 878 | |
| 882 | − //DYNAMIC_SLICING_ONE_THREAD: judge jump_avoiding_pack_exceed | |
| 883 | − if ( | |
| 884 | − ((kbCurMbNotFirstMbOfCurSlice | |
| 885 | − && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, pSliceCtx->uiSliceSizeConstraint)) /*jump_avoiding_pack_exceed*/ | |
| 886 | − && kbCurMbNotLastMbOfCurPartition) //decide to add new pSlice | |
| 887 | − && (kbSliceNumNotExceedConstraint | |
| 888 | − && ((pCurSlice->uiSliceIdx + kiActiveThreadsNum) < pSliceCtx->iMaxSliceNumConstraint) | |
| 889 | − )//able to add new pSlice | |
| 879 | + if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { | |
| 880 | + WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 881 | + //lock the acessing to this variable: pSliceCtx->iSliceNumInFrame | |
| 882 | + } | |
| 883 | + const bool kbSliceNumNotExceedConstraint = pSliceCtx->iSliceNumInFrame < | |
| 884 | + pSliceCtx->iMaxSliceNumConstraint; /*tmp choice to avoid complex memory operation, 100520, to be modify*/ | |
| 885 | + const bool kbSliceIdxNotExceedConstraint = (pCurSlice->uiSliceIdx + kiActiveThreadsNum) < | |
| 886 | + pSliceCtx->iMaxSliceNumConstraint; | |
| 887 | + const bool kbSliceNumReachConstraint = (pSliceCtx->iSliceNumInFrame == | |
| 888 | + pSliceCtx->iMaxSliceNumConstraint); | |
| 890 | 889 | |
| 891 | − ) { | |
| 890 | + //DYNAMIC_SLICING_ONE_THREAD: judge jump_avoiding_pack_exceed | |
| 891 | + if (kbSliceNumNotExceedConstraint && kbSliceIdxNotExceedConstraint) {//able to add new pSlice | |
| 892 | 892 | |
| 893 | − AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiLastMbIdxInPartition); | |
| 893 | + AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiLastMbIdxInPartition); | |
| 894 | 894 | |
| 895 | − ++ pSliceCtx->iSliceNumInFrame; | |
| 895 | + ++ pSliceCtx->iSliceNumInFrame; | |
| 896 | 896 | |
| 897 | − if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) | |
| 898 | − WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 897 | + if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { | |
| 898 | + WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 899 | + } | |
| 899 | 900 | |
| 900 | − return true; | |
| 901 | − } | |
| 901 | + return true; | |
| 902 | + } | |
| 903 | + if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { | |
| 904 | + WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 905 | + } | |
| 902 | 906 | |
| 903 | − if ( | |
| 904 | − (kbSliceNumReachConstraint | |
| 905 | − || ((pCurSlice->uiSliceIdx + kiActiveThreadsNum) >= pSliceCtx->iMaxSliceNumConstraint) | |
| 906 | − ) | |
| 907 | − && ((JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, | |
| 908 | − pSliceCtx->uiSliceSizeConstraint - ((kiLastMbIdxInPartition - iCurMbIdx) << | |
| 909 | − (pCurSlice->uiAssumeLog2BytePerMb) /* assume each MB consumes two byte under largest QP */))) | |
| 910 | − && kbCurMbNotLastMbOfCurPartition) //risk of exceeding the size constraint when pSlice num reaches constraint | |
| 911 | − ) { | |
| 912 | − pCurSlice->bDynamicSlicingSliceSizeCtrlFlag = true; | |
| 907 | + if ((kbSliceNumReachConstraint || !kbSliceIdxNotExceedConstraint) | |
| 908 | + && kbCurMbNotLastMbOfCurPartition | |
| 909 | + && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, | |
| 910 | + pSliceCtx->uiSliceSizeConstraint - ((kiLastMbIdxInPartition - iCurMbIdx) << | |
| 911 | + (pCurSlice->uiAssumeLog2BytePerMb) //assume each MB consumes these byte under largest QP | |
| 912 | + )) | |
| 913 | + ) { | |
| 914 | + // to minimize the impact under the risk of exceeding the size constraint when pSlice num reaches constraint | |
| 915 | + pCurSlice->bDynamicSlicingSliceSizeCtrlFlag = true; | |
| 916 | + } | |
| 913 | 917 | } |
| 914 | 918 | |
| 915 | − if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) | |
| 916 | − WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | |
| 917 | − | |
| 918 | 919 | return false; |
| 919 | 920 | } |
| 920 | 921 | |