History

improve the logic of locking in the function

Sijia Chen committed 12 years ago

Commit 2479abf1 parent 3ad4d901 file · +35 −34Browse files

Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 1 file). Show all

Unified · Split

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

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