vo_gl: fix 10 bit with Mesa drivers (Intel/Nouveau on Linux)
[mplayer.git] / av_log.c
blob7c6307d274837ca6d6258d20f33bfb3428f36f9a
1 /*
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.
23 #include <stdlib.h>
24 #include <stdbool.h>
26 #include "av_log.h"
27 #include "config.h"
28 #include "mp_msg.h"
29 #include <libavutil/avutil.h>
30 #include <libavutil/log.h>
32 #ifdef CONFIG_FFMPEG
33 #include <libavcodec/avcodec.h>
34 #include <libavformat/avformat.h>
35 #include <libswscale/swscale.h>
36 #include <libpostproc/postprocess.h>
37 #endif
39 static int av_log_level_to_mp_level(int av_level)
41 if (av_level > AV_LOG_VERBOSE)
42 return MSGL_DBG2;
43 if (av_level > AV_LOG_INFO)
44 return MSGL_V;
45 if (av_level > AV_LOG_WARNING)
46 return MSGL_INFO;
47 if (av_level > AV_LOG_ERROR)
48 return MSGL_WARN;
49 if (av_level > AV_LOG_FATAL)
50 return MSGL_ERR;
51 return MSGL_FATAL;
54 static int extract_msg_type_from_ctx(void *ptr)
56 if (!ptr)
57 return MSGT_FIXME;
59 AVClass *avc = *(AVClass **)ptr;
60 if (!avc) {
61 mp_msg(MSGT_FIXME, MSGL_WARN,
62 "av_log callback called with bad parameters (NULL AVClass).\n"
63 "This is a bug in one of Libav/FFmpeg libraries used.\n");
64 return MSGT_FIXME;
67 #ifdef CONFIG_FFMPEG
68 if (!strcmp(avc->class_name, "AVCodecContext")) {
69 AVCodecContext *s = ptr;
70 if (s->codec) {
71 if (s->codec->type == AVMEDIA_TYPE_AUDIO) {
72 if (s->codec->decode)
73 return MSGT_DECAUDIO;
74 } else if (s->codec->type == AVMEDIA_TYPE_VIDEO) {
75 if (s->codec->decode)
76 return MSGT_DECVIDEO;
78 // FIXME subtitles, encoders
79 // What msgt for them? There is nothing appropriate...
81 return MSGT_FIXME;
84 if (!strcmp(avc->class_name, "AVFormatContext")) {
85 AVFormatContext *s = ptr;
86 if (s->iformat)
87 return MSGT_DEMUXER;
88 else if (s->oformat)
89 return MSGT_MUXER;
90 return MSGT_FIXME;
92 #endif
94 return MSGT_FIXME;
97 static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt,
98 va_list vl)
100 static bool print_prefix = 1;
101 AVClass *avc = ptr ? *(AVClass **)ptr : NULL;
102 int mp_level = av_log_level_to_mp_level(level);
103 int type = extract_msg_type_from_ctx(ptr);
105 if (!mp_msg_test(type, mp_level))
106 return;
108 if (print_prefix && avc)
109 mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
110 print_prefix = fmt[strlen(fmt) - 1] == '\n';
112 mp_msg_va(type, mp_level, fmt, vl);
115 void init_libav(void)
117 av_log_set_callback(mp_msg_av_log_callback);
118 #ifdef CONFIG_FFMPEG
119 avcodec_init();
120 avcodec_register_all();
122 av_register_all();
123 #endif
126 #define V(x) (x)>>16, (x)>>8 & 255, (x) & 255
127 static void print_version(char *name, unsigned buildv, unsigned runv)
130 if (buildv == runv)
131 mp_msg(MSGT_CPLAYER, MSGL_V, "Compiled against %s version %d.%d.%d\n",
132 name, V(buildv));
133 else
134 mp_msg(MSGT_CPLAYER, MSGL_V, "Compiled against %s version %d.%d.%d "
135 "(runtime %d.%d.%d)\n", name, V(buildv), V(runv));
137 #undef V
139 void print_libav_versions(void)
141 print_version("libavutil", LIBAVUTIL_VERSION_INT, avutil_version());
142 #ifdef CONFIG_FFMPEG
143 print_version("libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version());
144 print_version("libavformat", LIBAVFORMAT_VERSION_INT, avformat_version());
145 print_version("libswscale", LIBSWSCALE_VERSION_INT, swscale_version());
146 print_version("libpostproc", LIBPOSTPROC_VERSION_INT, postproc_version());
147 #endif