2
* Generic libav* helpers
4
* This file is part of MPlayer.
6
* MPlayer is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* MPlayer is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "libavcodec/avcodec.h"
22
#include "libavformat/avformat.h"
24
#include "av_helpers.h"
26
int avcodec_initialized;
27
int avformat_initialized;
29
static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt,
32
static int print_prefix=1;
33
AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
38
case AV_LOG_VERBOSE: mp_level = MSGL_V ; break;
39
case AV_LOG_DEBUG: mp_level= MSGL_V ; break;
40
case AV_LOG_INFO : mp_level= MSGL_INFO; break;
41
case AV_LOG_ERROR: mp_level= MSGL_ERR ; break;
42
default : mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break;
46
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n");
48
if(!strcmp(avc->class_name, "AVCodecContext")){
49
AVCodecContext *s= ptr;
51
if(s->codec->type == AVMEDIA_TYPE_AUDIO){
54
}else if(s->codec->type == AVMEDIA_TYPE_VIDEO){
58
//FIXME subtitles, encoders (what msgt for them? there is no appropriate ...)
60
}else if(!strcmp(avc->class_name, "AVFormatContext")){
61
AVFormatContext *s= ptr;
69
if (!mp_msg_test(type, mp_level)) return;
71
if(print_prefix && avc) {
72
mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
75
print_prefix= strchr(fmt, '\n') != NULL;
76
mp_msg_va(type, mp_level, fmt, vl);
79
static void show_av_version(int type, const char *name,
80
int header_ver, int ver, const char *conf)
82
#ifdef CONFIG_FFMPEG_SO
83
#define FFMPEG_TYPE "external"
85
#define FFMPEG_TYPE "internal"
87
mp_msg(type, MSGL_INFO, "%s version %d.%d.%d (" FFMPEG_TYPE ")\n",
88
name, ver >> 16, (ver >> 8) & 0xFF, ver & 0xFF);
89
if (header_ver != ver)
90
mp_msg(type, MSGL_INFO, "Mismatching header version %d.%d.%d\n",
91
header_ver >> 16, (header_ver >> 8) & 0xFF, header_ver & 0xFF);
92
mp_msg(type, MSGL_V, "Configuration: %s\n", conf);
95
void init_avcodec(void)
97
if (!avcodec_initialized) {
98
show_av_version(MSGT_DECVIDEO, "libavcodec", LIBAVCODEC_VERSION_INT,
99
avcodec_version(), avcodec_configuration());
100
avcodec_register_all();
101
avcodec_initialized = 1;
102
av_log_set_callback(mp_msp_av_log_callback);
106
void init_avformat(void)
108
if (!avformat_initialized) {
109
show_av_version(MSGT_DEMUX, "libavformat", LIBAVFORMAT_VERSION_INT,
110
avformat_version(), avformat_configuration());
112
avformat_initialized = 1;
113
av_log_set_callback(mp_msp_av_log_callback);