diff --git a/codec/encoder/core/inc/mt_defs.h b/codec/encoder/core/inc/mt_defs.h index f46eda63..7fdaf0ed 100644 --- a/codec/encoder/core/inc/mt_defs.h +++ b/codec/encoder/core/inc/mt_defs.h @@ -91,6 +91,7 @@ int32_t iEndMbIndex; // exclusive typedef struct TagSliceThreading { SSliceThreadPrivateData* pThreadPEncCtx;// thread context, [iThreadIdx] +char eventNamespace[100]; WELS_THREAD_HANDLE pThreadHandles[MAX_THREADS_NUM];// thread handles, [iThreadIdx] WELS_EVENT pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded state, [iThreadIdx] WELS_EVENT pReadySliceCodingEvent[MAX_THREADS_NUM]; // events for slice coding ready, [iThreadIdx] diff --git a/codec/encoder/core/src/slice_multi_threading.cpp b/codec/encoder/core/src/slice_multi_threading.cpp index d237340e..fce8acfe 100644 --- a/codec/encoder/core/src/slice_multi_threading.cpp +++ b/codec/encoder/core/src/slice_multi_threading.cpp @@ -43,6 +43,7 @@ #include #if !defined(_WIN32) #include +#include #endif//!_WIN32 #ifndef SEM_NAME_MAX // length of semaphore name should be system constrained at least on mac 10.7 @@ -317,6 +318,13 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara "pThreadPEncCtx"); WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) +#ifdef _WIN32 + // Dummy event namespace, the windows events don't actually use this + WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p", (void*) (*ppCtx)); +#else + WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p%x", (void*) (*ppCtx), getpid()); +#endif//!_WIN32 + iIdx = 0; while (iIdx < iNumSpatialLayers) { SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg; @@ -360,34 +368,34 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara pSmt->pThreadHandles[iIdx] = 0; #ifdef _WIN32 - WelsSnprintf (name, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); #endif - WelsSnprintf (name, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); #endif #endif//_WIN32 // length of semaphore name should be system constrained at least on mac 10.7 - WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); #endif - WelsSnprintf (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); #endif - WelsSnprintf (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); #endif - WelsSnprintf (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (name, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace); err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name); #if defined(ENABLE_TRACE_MT) WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx, @@ -464,18 +472,18 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL) WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]); - WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pFinSliceCodingEvent[iIdx], ename); - WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pExitEncodeEvent[iIdx], ename); #endif//_WIN32 - WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename); - WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pReadySliceCodingEvent[iIdx], ename); - WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename); - WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); + WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename); ++ iIdx;