comparison av_helpers.c @ 33871:30f5e5cd3676

Move code for setting up libav* logging callbacks from vd_ffmpeg to a separate file and also use it when only initializing libavformat.
author reimar
date Tue, 09 Aug 2011 19:57:00 +0000
parents
children 5f1faa91717e
comparison
equal deleted inserted replaced
33870:15e182c07689 33871:30f5e5cd3676
1 #include "libavcodec/avcodec.h"
2 #include "libavformat/avformat.h"
3 #include "mp_msg.h"
4 #include "av_helpers.h"
5
6 int avcodec_initialized;
7 int avformat_initialized;
8
9 static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt,
10 va_list vl)
11 {
12 static int print_prefix=1;
13 AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
14 int type= MSGT_FIXME;
15 int mp_level;
16
17 switch(level){
18 case AV_LOG_VERBOSE: mp_level = MSGL_V ; break;
19 case AV_LOG_DEBUG: mp_level= MSGL_V ; break;
20 case AV_LOG_INFO : mp_level= MSGL_INFO; break;
21 case AV_LOG_ERROR: mp_level= MSGL_ERR ; break;
22 default : mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break;
23 }
24
25 if (ptr && !avc)
26 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n");
27 if (avc) {
28 if(!strcmp(avc->class_name, "AVCodecContext")){
29 AVCodecContext *s= ptr;
30 if(s->codec){
31 if(s->codec->type == AVMEDIA_TYPE_AUDIO){
32 if(s->codec->decode)
33 type= MSGT_DECAUDIO;
34 }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){
35 if(s->codec->decode)
36 type= MSGT_DECVIDEO;
37 }
38 //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...)
39 }
40 }else if(!strcmp(avc->class_name, "AVFormatContext")){
41 AVFormatContext *s= ptr;
42 if(s->iformat)
43 type= MSGT_DEMUXER;
44 else if(s->oformat)
45 type= MSGT_MUXER;
46 }
47 }
48
49 if (!mp_msg_test(type, mp_level)) return;
50
51 if(print_prefix && avc) {
52 mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
53 }
54
55 print_prefix= strchr(fmt, '\n') != NULL;
56 mp_msg_va(type, mp_level, fmt, vl);
57 }
58
59 void init_avcodec(void)
60 {
61 if (!avcodec_initialized) {
62 avcodec_init();
63 avcodec_register_all();
64 avcodec_initialized = 1;
65 av_log_set_callback(mp_msp_av_log_callback);
66 }
67 }
68
69 void init_avformat(void)
70 {
71 if (!avformat_initialized) {
72 av_register_all();
73 avformat_initialized = 1;
74 av_log_set_callback(mp_msp_av_log_callback);
75 }
76 }