mp_msg: Remove uses of MSGT_MENCODER
[mplayer.git] / av_log.c
blobe3bb9e860c1e5849cfab4087b66f9eef7079ee8c
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_FFMPEG
31 #include <libavcodec/avcodec.h>
32 #include <libavformat/avformat.h>
33 #endif
35 static int av_log_level_to_mp_level(int av_level)
37 if (av_level > AV_LOG_INFO)
38 return MSGL_V;
39 if (av_level > AV_LOG_WARNING)
40 return MSGL_INFO;
41 if (av_level > AV_LOG_ERROR)
42 return MSGL_WARN;
43 if (av_level > AV_LOG_FATAL)
44 return MSGL_ERR;
45 return MSGL_FATAL;
48 static int extract_msg_type_from_ctx(void *ptr)
50 if (!ptr)
51 return MSGT_FIXME;
53 AVClass *avc = *(AVClass **)ptr;
55 #ifdef CONFIG_FFMPEG
56 if (!strcmp(avc->class_name, "AVCodecContext")) {
57 AVCodecContext *s = ptr;
58 if (s->codec) {
59 if (s->codec->type == CODEC_TYPE_AUDIO) {
60 if (s->codec->decode)
61 return MSGT_DECAUDIO;
62 } else if (s->codec->type == CODEC_TYPE_VIDEO) {
63 if (s->codec->decode)
64 return MSGT_DECVIDEO;
66 // FIXME subtitles, encoders
67 // What msgt for them? There is nothing appropriate...
69 return MSGT_FIXME;
71 #endif
73 #ifdef CONFIG_FFMPEG
74 if (!strcmp(avc->class_name, "AVFormatContext")) {
75 AVFormatContext *s = ptr;
76 if (s->iformat)
77 return MSGT_DEMUXER;
78 else if (s->oformat)
79 return MSGT_MUXER;
80 return MSGT_FIXME;
82 #endif
84 return MSGT_FIXME;
87 static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt,
88 va_list vl)
90 static bool print_prefix = 1;
91 AVClass *avc = ptr ? *(AVClass **)ptr : NULL;
92 int mp_level = av_log_level_to_mp_level(level);
93 int type = extract_msg_type_from_ctx(ptr);
95 if (!mp_msg_test(type, mp_level))
96 return;
98 if (print_prefix && avc)
99 mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
100 print_prefix = fmt[strlen(fmt) - 1] == '\n';
102 mp_msg_va(type, mp_level, fmt, vl);
105 void set_av_log_callback(void)
107 av_log_set_callback(mp_msg_av_log_callback);