2 * av_log to mp_msg converter
3 * Copyright (C) 2006 Michael Niedermayer
4 * Copyright (C) 2009 Uoti Urpala
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <libavutil/log.h>
32 #include <libavcodec/avcodec.h>
33 #include <libavformat/avformat.h>
36 static int av_log_level_to_mp_level(int av_level
)
38 if (av_level
> AV_LOG_VERBOSE
)
40 if (av_level
> AV_LOG_INFO
)
42 if (av_level
> AV_LOG_WARNING
)
44 if (av_level
> AV_LOG_ERROR
)
46 if (av_level
> AV_LOG_FATAL
)
51 static int extract_msg_type_from_ctx(void *ptr
)
56 AVClass
*avc
= *(AVClass
**)ptr
;
58 mp_msg(MSGT_FIXME
, MSGL_WARN
,
59 "av_log callback called with bad parameters (NULL AVClass).\n"
60 "This is a bug in one of Libav/FFmpeg libraries used.\n");
65 if (!strcmp(avc
->class_name
, "AVCodecContext")) {
66 AVCodecContext
*s
= ptr
;
68 if (s
->codec
->type
== AVMEDIA_TYPE_AUDIO
) {
71 } else if (s
->codec
->type
== AVMEDIA_TYPE_VIDEO
) {
75 // FIXME subtitles, encoders
76 // What msgt for them? There is nothing appropriate...
81 if (!strcmp(avc
->class_name
, "AVFormatContext")) {
82 AVFormatContext
*s
= ptr
;
94 static void mp_msg_av_log_callback(void *ptr
, int level
, const char *fmt
,
97 static bool print_prefix
= 1;
98 AVClass
*avc
= ptr
? *(AVClass
**)ptr
: NULL
;
99 int mp_level
= av_log_level_to_mp_level(level
);
100 int type
= extract_msg_type_from_ctx(ptr
);
102 if (!mp_msg_test(type
, mp_level
))
105 if (print_prefix
&& avc
)
106 mp_msg(type
, mp_level
, "[%s @ %p]", avc
->item_name(ptr
), avc
);
107 print_prefix
= fmt
[strlen(fmt
) - 1] == '\n';
109 mp_msg_va(type
, mp_level
, fmt
, vl
);
112 void init_libav(void)
114 av_log_set_callback(mp_msg_av_log_callback
);
117 avcodec_register_all();