shithub: openh264

Download patch

ref: 94a1d4426e26e01ee5170d2f3d404c124d329407
parent: 23b5a611539dec22e214500cb632226e0b5a21b2
parent: 41720f8df5812634c500a9c5a45ed99bd88f2986
author: huili2 <[email protected]>
date: Thu Oct 23 14:03:24 EDT 2014

Merge pull request #1437 from sijchen/after_review2

[Encoder] add a thread name for easier profiling

--- a/codec/common/inc/WelsThreadLib.h
+++ b/codec/common/inc/WelsThreadLib.h
@@ -117,6 +117,8 @@
 WELS_THREAD_ERROR_CODE    WelsThreadCreate (WELS_THREAD_HANDLE* thread,  LPWELS_THREAD_ROUTINE  routine,
     void* arg, WELS_THREAD_ATTR attr);
 
+WELS_THREAD_ERROR_CODE    WelsThreadSetName (const char* thread_name);
+
 WELS_THREAD_ERROR_CODE    WelsThreadJoin (WELS_THREAD_HANDLE  thread);
 
 WELS_THREAD_HANDLE        WelsThreadSelf();
--- a/codec/common/src/WelsThreadLib.cpp
+++ b/codec/common/src/WelsThreadLib.cpp
@@ -195,6 +195,12 @@
   return WELS_THREAD_ERROR_OK;
 }
 
+WELS_THREAD_ERROR_CODE WelsThreadSetName (const char* thread_name) {
+  // do nothing
+  return WELS_THREAD_ERROR_OK;
+}
+
+
 WELS_THREAD_ERROR_CODE    WelsThreadJoin (WELS_THREAD_HANDLE  thread) {
   WaitForSingleObject (thread, INFINITE);
   CloseHandle (thread);
@@ -240,6 +246,17 @@
   pthread_attr_destroy (&at);
 
   return err;
+}
+
+WELS_THREAD_ERROR_CODE WelsThreadSetName (const char* thread_name) {
+#ifdef APPLE_IOS
+  pthread_setname_np(thread_name);
+#endif
+#ifdef __ANDROID__
+  pthread_setname_np(pthread_self(), thread_name);
+#endif
+  // do nothing
+  return WELS_THREAD_ERROR_OK;
 }
 
 WELS_THREAD_ERROR_CODE    WelsThreadJoin (WELS_THREAD_HANDLE  thread) {
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -705,6 +705,8 @@
   pEventsList[iEventCount++]	= pEncPEncCtx->pSliceThreading->pExitEncodeEvent[iEventIdx];
   pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx];
 
+  WelsThreadSetName ("OpenH264Enc_CodingSliceThreadProc");
+
   do {
     MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO,
                   "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!",