demux_y4m: increase error message verbosity from MSGL_V to MSGL_ERR
[mplayer/glamo.git] / av_log.c
blob99f6e91a8149592bdf7ac028f8929e334c49e6d7
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 "config.h"
27 #include "mp_msg.h"
28 #include <libavutil/log.h>
30 #ifdef CONFIG_LIBAVCODEC
31 #include <libavcodec/avcodec.h>
32 #endif
34 #ifdef CONFIG_LIBAVFORMAT
35 #include <libavformat/avformat.h>
36 #endif
38 static int av_log_level_to_mp_level(int av_level)
40 if (av_level > AV_LOG_INFO)
41 return MSGL_V;
42 if (av_level > AV_LOG_WARNING)
43 return MSGL_INFO;
44 if (av_level > AV_LOG_ERROR)
45 return MSGL_WARN;
46 if (av_level > AV_LOG_FATAL)
47 return MSGL_ERR;
48 return MSGL_FATAL;
51 static int extract_msg_type_from_ctx(void *ptr)
53 if (!ptr)
54 return MSGT_FIXME;
56 AVClass *avc = *(AVClass **)ptr;
58 #ifdef CONFIG_LIBAVCODEC
59 if (!strcmp(avc->class_name, "AVCodecContext")) {
60 AVCodecContext *s = ptr;
61 if (s->codec) {
62 if (s->codec->type == CODEC_TYPE_AUDIO) {
63 if (s->codec->decode)
64 return MSGT_DECAUDIO;
65 } else if (s->codec->type == CODEC_TYPE_VIDEO) {
66 if (s->codec->decode)
67 return MSGT_DECVIDEO;
69 // FIXME subtitles, encoders
70 // What msgt for them? There is nothing appropriate...
72 return MSGT_FIXME;
74 #endif
76 #ifdef CONFIG_LIBAVFORMAT
77 if (!strcmp(avc->class_name, "AVFormatContext")) {
78 AVFormatContext *s = ptr;
79 if (s->iformat)
80 return MSGT_DEMUXER;
81 else if (s->oformat)
82 return MSGT_MUXER;
83 return MSGT_FIXME;
85 #endif
87 return MSGT_FIXME;
90 static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt,
91 va_list vl)
93 static bool print_prefix = 1;
94 AVClass *avc = ptr ? *(AVClass **)ptr : NULL;
95 int mp_level = av_log_level_to_mp_level(level);
96 int type = extract_msg_type_from_ctx(ptr);
98 if (!mp_msg_test(type, mp_level))
99 return;
101 if (print_prefix && avc)
102 mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
103 print_prefix = fmt[strlen(fmt) - 1] == '\n';
105 mp_msg_va(type, mp_level, fmt, vl);
108 void set_av_log_callback(void)
110 av_log_set_callback(mp_msg_av_log_callback);