This avoids having an extra ifdef around every single WelsLog call.
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 1 file). Show all
Unified · Split
| @@ -63,6 +63,13 @@ · 62 unmodified lines | ||
| 63 | 63 | #include "cpu.h" |
| 64 | 64 | |
| 65 | 65 | #include "measure_time.h" |
| 66 | + | |
| 67 | +#if defined(ENABLE_TRACE_MT) | |
| 68 | +#define MT_TRACE_LOG(x, ...) WelsLog(x, __VA_ARGS__) | |
| 69 | +#else | |
| 70 | +#define MT_TRACE_LOG(x, ...) | |
| 71 | +#endif | |
| 72 | + | |
| 66 | 73 | namespace WelsSVCEnc { |
| 67 | 74 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, |
| 68 | 75 | SMB* pMbList, |
| @@ -126,10 +133,8 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 57 unmodified lines | ||
| 126 | 133 | |
| 127 | 134 | while (iSliceIdx < kiSliceCount) { |
| 128 | 135 | fAvI[iSliceIdx] = 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx]; |
| 129 | −#if defined(ENABLE_TRACE_MT) | |
| 130 | − WelsLog (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx, | |
| 131 | − pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | |
| 132 | −#endif//ENABLE_TRACE_MT | |
| 136 | + MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx, | |
| 137 | + pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | |
| 133 | 138 | fSumAv += fAvI[iSliceIdx]; |
| 134 | 139 | |
| 135 | 140 | ++ iSliceIdx; |
| @@ -153,10 +158,8 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 17 unmodified lines | ||
| 153 | 158 | iSliceIdx += 2; |
| 154 | 159 | } |
| 155 | 160 | if (uiTotalConsume == 0) { |
| 156 | −#if defined(ENABLE_TRACE_MT) | |
| 157 | − WelsLog (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n", | |
| 158 | − iSliceNum); | |
| 159 | −#endif//ENABLE_TRACE_MT | |
| 161 | + MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n", | |
| 162 | + iSliceNum); | |
| 160 | 163 | return false; |
| 161 | 164 | } |
| 162 | 165 | |
| @@ -181,11 +184,9 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 18 unmodified lines | ||
| 181 | 184 | fThr = 1.0f; |
| 182 | 185 | if (fRmse > fThr) |
| 183 | 186 | iNeedAdj = true; |
| 184 | −#if defined(ENABLE_TRACE_MT) | |
| 185 | − WelsLog (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 | −#endif//ENABLE_TRACE_MT | |
| 187 | + MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, | |
| 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); | |
| 189 | 190 | |
| 190 | 191 | return iNeedAdj; |
| 191 | 192 | } |
| @@ -232,9 +233,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 40 unmodified lines | ||
| 232 | 233 | |
| 233 | 234 | WelsEmms(); |
| 234 | 235 | |
| 235 | −#if defined(ENABLE_TRACE_MT) | |
| 236 | − WelsLog (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d\n", iCurDid, kiCountNumMb); | |
| 237 | −#endif//ENABLE_TRACE_MT | |
| 236 | + MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d\n", iCurDid, kiCountNumMb); | |
| 238 | 237 | |
| 239 | 238 | iSliceIdx = 0; |
| 240 | 239 | while (iSliceIdx + 1 < kiCountSliceNum) { |
| @@ -259,20 +258,16 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 18 unmodified lines | ||
| 259 | 258 | return; |
| 260 | 259 | } |
| 261 | 260 | iRunLen[iSliceIdx] = iNumMbAssigning; |
| 262 | −#if defined(ENABLE_TRACE_MT) | |
| 263 | − WelsLog (pCtx, WELS_LOG_DEBUG, | |
| 261 | + MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, | |
| 264 | 262 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n", |
| 265 | 263 | iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning); |
| 266 | −#endif//ENABLE_TRACE_MT | |
| 267 | 264 | ++ iSliceIdx; |
| 268 | 265 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts |
| 269 | 266 | } |
| 270 | 267 | iRunLen[iSliceIdx] = iMbNumLeft; |
| 271 | −#if defined(ENABLE_TRACE_MT) | |
| 272 | − WelsLog (pCtx, WELS_LOG_DEBUG, | |
| 273 | − "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n", | |
| 274 | − iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft); | |
| 275 | −#endif//ENABLE_TRACE_MT | |
| 268 | + MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, | |
| 269 | + "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n", | |
| 270 | + iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft); | |
| 276 | 271 | |
| 277 | 272 | |
| 278 | 273 | if (DynamicAdjustSlicePEncCtxAll (pSliceCtx, iRunLen) == 0) { |
| @@ -354,9 +349,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 75 unmodified lines | ||
| 354 | 349 | pSmt->pFSliceDiff = fopen ("slice_time.txt", "wt+"); |
| 355 | 350 | #endif//MT_DEBUG |
| 356 | 351 | |
| 357 | −#if defined(ENABLE_TRACE_MT) | |
| 358 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "encpEncCtx= 0x%p\n", (void*) (*ppCtx)); | |
| 359 | −#endif//ENABLE_TRACE_MT | |
| 352 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "encpEncCtx= 0x%p\n", (void*) (*ppCtx)); | |
| 360 | 353 | |
| 361 | 354 | iIdx = 0; |
| 362 | 355 | while (iIdx < iThreadNum) { |
| @@ -370,37 +363,25 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 7 unmodified lines | ||
| 370 | 363 | #ifdef _WIN32 |
| 371 | 364 | WelsSnprintf (name, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace); |
| 372 | 365 | err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name); |
| 373 | −#if defined(ENABLE_TRACE_MT) | |
| 374 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 375 | −#endif | |
| 366 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 376 | 367 | WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace); |
| 377 | 368 | err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name); |
| 378 | −#if defined(ENABLE_TRACE_MT) | |
| 379 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 380 | −#endif | |
| 369 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 381 | 370 | #endif//_WIN32 |
| 382 | 371 | // length of semaphore name should be system constrained at least on mac 10.7 |
| 383 | 372 | WelsSnprintf (name, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace); |
| 384 | 373 | err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name); |
| 385 | −#if defined(ENABLE_TRACE_MT) | |
| 386 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 387 | −#endif | |
| 374 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 388 | 375 | WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); |
| 389 | 376 | err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name); |
| 390 | −#if defined(ENABLE_TRACE_MT) | |
| 391 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 392 | −#endif | |
| 377 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 393 | 378 | WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); |
| 394 | 379 | err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name); |
| 395 | −#if defined(ENABLE_TRACE_MT) | |
| 396 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 397 | −#endif | |
| 380 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | |
| 398 | 381 | WelsSnprintf (name, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace); |
| 399 | 382 | err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name); |
| 400 | −#if defined(ENABLE_TRACE_MT) | |
| 401 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx, | |
| 402 | − (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); | |
| 403 | −#endif | |
| 383 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx, | |
| 384 | + (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); | |
| 404 | 385 | |
| 405 | 386 | ++ iIdx; |
| 406 | 387 | } |
| @@ -436,10 +417,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 29 unmodified lines | ||
| 436 | 417 | iReturn = WelsMutexInit (&(*ppCtx)->mutexEncoderError); |
| 437 | 418 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 438 | 419 | |
| 439 | −#if defined(ENABLE_TRACE_MT) | |
| 440 | − WelsLog ((*ppCtx), WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum, | |
| 441 | − iMaxSliceNum); | |
| 442 | −#endif | |
| 420 | + MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum, | |
| 421 | + iMaxSliceNum); | |
| 443 | 422 | |
| 444 | 423 | return 0; |
| 445 | 424 | } |
| @@ -708,10 +687,8 @@ WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { · 262 unmodified lines | ||
| 708 | 687 | iEventIdx = pPrivateData->iThreadIndex; |
| 709 | 688 | |
| 710 | 689 | do { |
| 711 | −#if defined(ENABLE_TRACE_MT) | |
| 712 | − WelsLog (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n", | |
| 713 | − iEventIdx); | |
| 714 | −#endif | |
| 690 | + MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n", | |
| 691 | + iEventIdx); | |
| 715 | 692 | iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]); |
| 716 | 693 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { |
| 717 | 694 | pCurDq = pEncPEncCtx->pCurDqLayer; |
| @@ -775,11 +752,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 57 unmodified lines | ||
| 775 | 752 | &pEventsList[0], |
| 776 | 753 | (uint32_t) - 1); // blocking until at least one event is |
| 777 | 754 | #else |
| 778 | −#if defined(ENABLE_TRACE_MT) | |
| 779 | − WelsLog (pEncPEncCtx, WELS_LOG_INFO, | |
| 780 | − "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n", | |
| 781 | − iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx); | |
| 782 | −#endif | |
| 755 | + MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO, | |
| 756 | + "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n", | |
| 757 | + iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx); | |
| 783 | 758 | iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]); |
| 784 | 759 | #endif//WIN32 |
| 785 | 760 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| @@ -867,13 +842,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 81 unmodified lines | ||
| 867 | 842 | if (bDsaFlag) { |
| 868 | 843 | pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) ( |
| 869 | 844 | WelsTime() - iSliceStart); |
| 870 | −#if defined(ENABLE_TRACE_MT) | |
| 871 | − WelsLog (pEncPEncCtx, WELS_LOG_INFO, | |
| 872 | − "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d\n", | |
| 873 | − pEncPEncCtx->iCodingIndex, iSliceIdx, | |
| 874 | − pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize, | |
| 875 | − pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]); | |
| 876 | −#endif//ENABLE_TRACE_MT | |
| 845 | + MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO, | |
| 846 | + "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d\n", | |
| 847 | + pEncPEncCtx->iCodingIndex, iSliceIdx, | |
| 848 | + pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize, | |
| 849 | + pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]); | |
| 877 | 850 | } |
| 878 | 851 | |
| 879 | 852 | #if defined(SLICE_INFO_OUTPUT) |
| @@ -982,12 +955,10 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 102 unmodified lines | ||
| 982 | 955 | ); |
| 983 | 956 | #endif//SLICE_INFO_OUTPUT |
| 984 | 957 | |
| 985 | −#if defined(ENABLE_TRACE_MT) | |
| 986 | − WelsLog (pEncPEncCtx, WELS_LOG_INFO, | |
| 987 | − "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n", | |
| 988 | − pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx], | |
| 989 | − kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]); | |
| 990 | −#endif//ENABLE_TRACE_MT | |
| 958 | + MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO, | |
| 959 | + "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n", | |
| 960 | + pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx], | |
| 961 | + kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]); | |
| 991 | 962 | |
| 992 | 963 | iAnyMbLeftInPartition = kiEndMbInPartition - (1 + pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]); |
| 993 | 964 | iSliceIdx += kiSliceIdxStep; |
| @@ -1070,9 +1041,7 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 76 unmodified lines | ||
| 1070 | 1041 | |
| 1071 | 1042 | ++ iIdx; |
| 1072 | 1043 | } |
| 1073 | −#if defined(ENABLE_TRACE_MT) | |
| 1074 | − WelsLog (pCtx, WELS_LOG_INFO, "CreateSliceThreads() exit..\n"); | |
| 1075 | −#endif | |
| 1044 | + MT_TRACE_LOG (pCtx, WELS_LOG_INFO, "CreateSliceThreads() exit..\n"); | |
| 1076 | 1045 | return 0; |
| 1077 | 1046 | } |
| 1078 | 1047 | |