[FFmpeg-devel] [PATCH 2/3] libavutil: register all threads with the logging facility

Martin Carroll martin.carroll at alcatel-lucent.com
Wed Jul 18 17:22:20 CEST 2012


When the variable print_threadname in libavutil/log.c is set
to 1, the logger prefixes each log message with the name of the
calling thread, if that thread was registered with the logger.
This commit registers all the threads with the logger.

Signed-off-by: Martin Carroll <martin.carroll at alcatel-lucent.com>
---
 ffmpeg.c                      |    1 +
 ffplay.c                      |    9 +++++++++
 libavcodec/libstagefright.cpp |    1 +
 libavcodec/pthread.c          |    3 +++
 libavformat/udp.c             |    1 +
 5 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 61840cc..4a09dca 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3540,6 +3540,7 @@ static int init_input_threads(void)
 
         if ((ret = pthread_create(&f->thread, NULL, input_thread, f)))
             return AVERROR(ret);
+    	av_log_set_threadname(f->thread, "input", (void*)input_thread);
     }
     return 0;
 }
diff --git a/ffplay.c b/ffplay.c
index c026c4c..e5a76fa 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -28,6 +28,7 @@
 #include <math.h>
 #include <limits.h>
 #include <signal.h>
+#include <pthread.h>
 #include "libavutil/avstring.h"
 #include "libavutil/colorspace.h"
 #include "libavutil/mathematics.h"
@@ -2231,6 +2232,8 @@ static int stream_component_open(VideoState *is, int stream_index)
 
         packet_queue_start(&is->videoq);
         is->video_tid = SDL_CreateThread(video_thread, is);
+        if (is->video_tid)
+            av_log_set_threadname(SDL_GetThreadID(is->video_tid), "video", (void*)video_thread);
         break;
     case AVMEDIA_TYPE_SUBTITLE:
         is->subtitle_stream = stream_index;
@@ -2238,6 +2241,8 @@ static int stream_component_open(VideoState *is, int stream_index)
         packet_queue_start(&is->subtitleq);
 
         is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
+        if (is->subtitle_tid)
+            av_log_set_threadname(SDL_GetThreadID(is->subtitle_tid), "subtitle", (void*)subtitle_thread);
         break;
     default:
         break;
@@ -2443,6 +2448,8 @@ static int read_thread(void *arg)
         ret = stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]);
     }
     is->refresh_tid = SDL_CreateThread(refresh_thread, is);
+    if (is->refresh_tid)
+        av_log_set_threadname(SDL_GetThreadID(is->refresh_tid), "refresh", (void*)refresh_thread);
     if (is->show_mode == SHOW_MODE_NONE)
         is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT;
 
@@ -2624,6 +2631,7 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
         av_free(is);
         return NULL;
     }
+    av_log_set_threadname(SDL_GetThreadID(is->read_tid), "read", (void*)read_thread);
     return is;
 }
 
@@ -3074,6 +3082,7 @@ int main(int argc, char **argv)
     char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    av_log_set_threadname(pthread_self(), "main", (void*)main);
     parse_loglevel(argc, argv, options);
 
     /* register all codecs, demux and protocols */
diff --git a/libavcodec/libstagefright.cpp b/libavcodec/libstagefright.cpp
index 6b9c245..df1665e 100644
--- a/libavcodec/libstagefright.cpp
+++ b/libavcodec/libstagefright.cpp
@@ -365,6 +365,7 @@ static int Stagefright_decode_frame(AVCodecContext *avctx, void *data,
 
     if (!s->thread_started) {
         pthread_create(&s->decode_thread_id, NULL, &decode_thread, avctx);
+        av_log_set_threadname(s->decode_thread_id, "sfdecode", (void*)decode_thread);
         s->thread_started = true;
     }
 
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 7f2ea09..439678b 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -337,6 +337,7 @@ static int thread_init(AVCodecContext *avctx)
     pthread_mutex_lock(&c->current_job_lock);
     for (i=0; i<thread_count; i++) {
         if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
+		   av_log_set_threadname(c->workers[i], "avctxworker", (void*)worker);
            avctx->thread_count = i;
            pthread_mutex_unlock(&c->current_job_lock);
            ff_thread_free(avctx);
@@ -871,6 +872,8 @@ static int frame_thread_init(AVCodecContext *avctx)
         if (err) goto error;
 
         err = AVERROR(pthread_create(&p->thread, NULL, frame_worker_thread, p));
+        if (!err)
+    		av_log_set_threadname(p->thread, "frame_worker", (void*)frame_worker_thread);
         p->thread_init= !err;
         if(!p->thread_init)
             goto error;
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 5b5c7cb..51aceca 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -662,6 +662,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
             av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", strerror(ret));
             goto thread_fail;
         }
+        av_log_set_threadname(s->circular_buffer_thread, "circular_buffer", circular_buffer_task);
         s->thread_started = 1;
     }
 #endif
-- 
1.7.8.6



More information about the ffmpeg-devel mailing list