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

Martin Carroll martin.carroll at alcatel-lucent.com
Mon Jul 2 21:24:27 CEST 2012


When the variable print_threadid in libavutil/log.c is set
to 1, the logger prefixes all log messages with the name or
id of the thread.  The name is used if the thread was
previously registered by calling av_log_set_threadname().
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(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index 25112d3..9eed743 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3470,6 +3470,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 a879471..92750e1 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"
@@ -2229,6 +2230,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;
@@ -2236,6 +2239,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;
@@ -2441,6 +2446,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;
 
@@ -2621,6 +2628,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;
 }
 
@@ -3070,6 +3078,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.10.4



More information about the ffmpeg-devel mailing list