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
862862 const bool kbCurMbNotFirstMbOfCurSlice = (pSliceCtx->pOverallMbMap[iCurMbIdx] ==
863863 pSliceCtx->pOverallMbMap[iCurMbIdx - 1]);
864864 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);
869865
870866 if (pCurSlice->bDynamicSlicingSliceSizeCtrlFlag)
871867 return false;
@@ -876,45 +872,50 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 4 unmodified lines
876872 #endif
877873 uiLen = ((iPosBitOffset >> 3) + ((iPosBitOffset & 0x07) ? 1 : 0));
878874
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
881878
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);
890889
891− ) {
890+ //DYNAMIC_SLICING_ONE_THREAD: judge jump_avoiding_pack_exceed
891+ if (kbSliceNumNotExceedConstraint && kbSliceIdxNotExceedConstraint) {//able to add new pSlice
892892
893− AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiLastMbIdxInPartition);
893+ AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiLastMbIdxInPartition);
894894
895− ++ pSliceCtx->iSliceNumInFrame;
895+ ++ pSliceCtx->iSliceNumInFrame;
896896
897− if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1)
898− WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
897+ if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) {
898+ WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
899+ }
899900
900− return true;
901− }
901+ return true;
902+ }
903+ if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) {
904+ WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
905+ }
902906
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+ }
913917 }
914918
915− if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1)
916− WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
917−
918919 return false;
919920 }
920921

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