History

astyle all files

huili2 committed 12 years ago

Commit 5ed24f21 parent 0c24686120 files · +3967 −3886Browse files

Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 120 files). Show all

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+52−46
@@ -132,8 +132,9 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 131 unmodified lines
132132
133133 while (iSliceIdx < kiSliceCount) {
134134 fAvI[iSliceIdx] = 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx];
135− MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx,
136− pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
135+ MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n",
136+ iSliceIdx,
137+ pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
137138 fSumAv += fAvI[iSliceIdx];
138139
139140 ++ iSliceIdx;
@@ -156,8 +157,9 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 16 unmodified lines
156157 iSliceIdx += 2;
157158 }
158159 if (uiTotalConsume == 0) {
159− MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
160− iSliceNum);
160+ MT_TRACE_LOG (NULL, WELS_LOG_DEBUG,
161+ "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
162+ iSliceNum);
161163 return false;
162164 }
163165
@@ -183,8 +185,8 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 19 unmodified lines
183185 if (fRmse > fThr)
184186 iNeedAdj = true;
185187 MT_TRACE_LOG (NULL, WELS_LOG_DEBUG,
186− "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
187− iNeedAdj, fRmse, fThr, iSliceNum);
188+ "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
189+ iNeedAdj, fRmse, fThr, iSliceNum);
188190
189191 return iNeedAdj;
190192 }
@@ -256,8 +258,8 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 65 unmodified lines
256258 }
257259 iRunLen[iSliceIdx] = iNumMbAssigning;
258260 MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
259− "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
260− iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning);
261+ "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
262+ iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning);
261263 ++ iSliceIdx;
262264 iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts
263265 }
@@ -313,16 +315,17 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 49 unmodified lines
313315
314316 #ifdef _WIN32
315317 // Dummy event namespace, the windows events don't actually use this
316− WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p", (void*) *ppCtx);
318+ WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p", (void*) *ppCtx);
317319 #else
318− WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
320+ WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
319321 #endif//!_WIN32
320322
321323 iIdx = 0;
322324 while (iIdx < iNumSpatialLayers) {
323325 SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg;
324326 const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum;
325− if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE)) && pPara->iMultipleThreadIdc > 1
327+ if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE))
328+ && pPara->iMultipleThreadIdc > 1
326329 && pPara->iMultipleThreadIdc >= kiSliceNum) {
327330 pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]");
328331 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx))
@@ -371,7 +374,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 42 unmodified lines
371374 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
372375 WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace);
373376 err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
374− MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
377+ MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err,
378+ errno);
375379 WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace);
376380 err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
377381 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
@@ -415,10 +419,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 37 unmodified lines
415419 iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
416420 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
417421
418− iReturn = WelsMutexInit (&(*ppCtx)->mutexEncoderError);
422+ iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError);
419423 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
420424
421− MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum,
425+ MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n",
426+ pPara->iCountThreadsNum,
422427 iMaxSliceNum);
423428
424429 return 0;
@@ -467,7 +472,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 42 unmodified lines
467472 WelsEventClose (&pSmt->pSliceCodedMasterEvent, ename);
468473
469474 WelsMutexDestroy (&pSmt->mutexSliceNumUpdate);
470− WelsMutexDestroy (&((*ppCtx)->mutexEncoderError));
475+ WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError));
471476
472477 if (pSmt->pThreadPEncCtx != NULL) {
473478 pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx");
@@ -595,7 +600,8 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 121 unmodified lines
595600 return iLayerSize;
596601 }
597602
598−int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, int32_t& iSliceSize) {
603+int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx,
604+ int32_t& iSliceSize) {
599605 SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx];
600606 SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
601607 uint8_t* pDst = pFrameBsBuffer;
@@ -610,8 +616,9 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 8 unmodified lines
610616
611617 while (iNalIdx < kiNalCnt) {
612618 iNalSize = 0;
613− iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize-kiWrittenLength-iSliceSize, pDst, &iNalSize);
614− WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
619+ iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize - kiWrittenLength - iSliceSize,
620+ pDst, &iNalSize);
621+ WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
615622 iSliceSize += iNalSize;
616623 pDst += iNalSize;
617624 pLbi->iNalLengthInByte[iNalBase + iNalIdx] = iNalSize;
@@ -653,8 +660,9 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 35 unmodified lines
653660
654661 while (iNalIdx < kiNalCnt) {
655662 iNalSize = 0;
656− iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize-kiWrittenLength-iSliceSize, pDst, &iNalSize);
657− WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
663+ iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize,
664+ pDst, &iNalSize);
665+ WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
658666 pNalLen[iNalIdx] = iNalSize;
659667 iSliceSize += iNalSize;
660668 pDst += iNalSize;
@@ -702,7 +710,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 41 unmodified lines
702710 "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!\n",
703711 pEventsList[0], pEventsList[1], pEventsList[1], (void*)pEncPEncCtx);
704712 iWaitRet = WelsMultipleEventsWaitSingleBlocking (iEventCount,
705− &pEventsList[0], &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled
713+ &pEventsList[0],
714+ &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled
706715 if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited
707716 SLayerBSInfo* pLbi = pPrivateData->pLayerBs;
708717 const int32_t kiCurDid = pEncPEncCtx->uiDependencyId;
@@ -722,7 +731,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 13 unmodified lines
722731 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
723732 pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];
724733
725− bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) &&
734+ bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)
735+ || (pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) &&
726736 pCodingParam->iMultipleThreadIdc > 1 &&
727737 pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum);
728738 if (bDsaFlag)
@@ -752,7 +762,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 23 unmodified lines
752762 WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
753763
754764 iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
755− if (ENC_RETURN_SUCCESS!=iReturn) {
765+ if (ENC_RETURN_SUCCESS != iReturn) {
756766 uiThrdRet = iReturn;
757767 break;
758768 }
@@ -762,15 +772,14 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines
762772 if (0 == iSliceIdx) {
763773 pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer;
764774 iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize);
765− if (ENC_RETURN_SUCCESS!=iReturn) {
775+ if (ENC_RETURN_SUCCESS != iReturn) {
766776 uiThrdRet = iReturn;
767777 break;
768778 }
769779 pEncPEncCtx->iPosBsBuffer += iSliceSize;
770− } else
771− {
780+ } else {
772781 iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize);
773− if (ENC_RETURN_SUCCESS!=iReturn) {
782+ if (ENC_RETURN_SUCCESS != iReturn) {
774783 uiThrdRet = iReturn;
775784 break;
776785 }
@@ -859,7 +868,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 82 unmodified lines
859868 WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
860869
861870 iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
862− if (ENC_RETURN_SUCCESS!=iReturn) {
871+ if (ENC_RETURN_SUCCESS != iReturn) {
863872 uiThrdRet = iReturn;
864873 break;
865874 }
@@ -869,16 +878,16 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines
869878 if (0 == kiPartitionId) {
870879 if (0 == iSliceIdx)
871880 pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer;
872− iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, iSliceSize);
873− if (ENC_RETURN_SUCCESS!=iReturn) {
881+ iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx,
882+ iSliceSize);
883+ if (ENC_RETURN_SUCCESS != iReturn) {
874884 uiThrdRet = iReturn;
875885 break;
876886 }
877887 pEncPEncCtx->iPosBsBuffer += iSliceSize;
878− } else
879− {
888+ } else {
880889 iSliceSize = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize);
881− if (ENC_RETURN_SUCCESS!=iReturn) {
890+ if (ENC_RETURN_SUCCESS != iReturn) {
882891 uiThrdRet = iReturn;
883892 break;
884893 }
@@ -918,20 +927,17 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 33 unmodified lines
918927 WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice
919928 WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent);
920929 }
921− }
922− else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal
930+ } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal
923931 uiThrdRet = 0;
924932 break;
925− }
926− else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal
933+ } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal
927934 iSliceIdx =
928935 iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable
929936 pCurDq = pEncPEncCtx->pCurDqLayer;
930937 UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx);
931938 WelsEventSignal (
932939 &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice
933− }
934− else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED
940+ } else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED
935941 WelsLog (pEncPEncCtx, WELS_LOG_WARNING,
936942 "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx,
937943 iWaitRet, iThreadIdx);
@@ -962,9 +968,9 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 24 unmodified lines
962968 return 0;
963969 }
964970
965−int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi,
966− const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode)
967−{
971+int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
972+ SLayerBSInfo* pLbi,
973+ const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) {
968974 int32_t iEndMbIdx = 0;
969975 int32_t iIdx = 0;
970976 const int32_t kiEventCnt = uiNumThreads;
@@ -1044,9 +1050,9 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 73 unmodified lines
10441050 // if using spatial base layer for complexity estimation
10451051
10461052 const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0)
1047− && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
1048− && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid -
1049− 1].sSliceCfg.sSliceArgument.uiSliceNum);
1053+ && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
1054+ && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid -
1055+ 1].sSliceCfg.sSliceArgument.uiSliceNum);
10501056
10511057 if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation
10521058 // do not need adjust due to not different at both slices of consumed time
@@ -1116,7 +1122,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 63 unmodified lines
11161122 const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame;
11171123 if (pCtx->pSliceThreading) {
11181124 if (pCtx->pSliceThreading->pFSliceDiff
1119− && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE))
1125+ && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE))
11201126 && pPara->iMultipleThreadIdc > 1
11211127 && pPara->iMultipleThreadIdc >= kuiCountSliceNum) {
11221128 uint32_t i = 0;

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