Mercurial > mplayer.hg
annotate av_helpers.c @ 36085:d3e8f4f71514
Check return value to avoid segmentation fault.
author | ib |
---|---|
date | Mon, 29 Apr 2013 11:36:53 +0000 |
parents | d443d66a746c |
children | c1033e9288b1 |
rev | line source |
---|---|
33886 | 1 /* |
2 * Generic libav* helpers | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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. | |
19 */ | |
20 | |
33871
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
21 #include "libavcodec/avcodec.h" |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
22 #include "libavformat/avformat.h" |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
23 #include "mp_msg.h" |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
24 #include "av_helpers.h" |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
25 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
26 int avcodec_initialized; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
27 int avformat_initialized; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
28 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
29 static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt, |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
30 va_list vl) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
31 { |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
32 static int print_prefix=1; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
33 AVClass *avc= ptr ? *(AVClass **)ptr : NULL; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
34 int type= MSGT_FIXME; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
35 int mp_level; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
36 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
37 switch(level){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
38 case AV_LOG_VERBOSE: mp_level = MSGL_V ; break; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
39 case AV_LOG_DEBUG: mp_level= MSGL_V ; break; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
40 case AV_LOG_INFO : mp_level= MSGL_INFO; break; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
41 case AV_LOG_ERROR: mp_level= MSGL_ERR ; break; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
42 default : mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
43 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
44 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
45 if (ptr && !avc) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
46 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n"); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
47 if (avc) { |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
48 if(!strcmp(avc->class_name, "AVCodecContext")){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
49 AVCodecContext *s= ptr; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
50 if(s->codec){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
51 if(s->codec->type == AVMEDIA_TYPE_AUDIO){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
52 if(s->codec->decode) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
53 type= MSGT_DECAUDIO; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
54 }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
55 if(s->codec->decode) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
56 type= MSGT_DECVIDEO; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
57 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
58 //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
59 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
60 }else if(!strcmp(avc->class_name, "AVFormatContext")){ |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
61 AVFormatContext *s= ptr; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
62 if(s->iformat) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
63 type= MSGT_DEMUXER; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
64 else if(s->oformat) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
65 type= MSGT_MUXER; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
66 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
67 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
68 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
69 if (!mp_msg_test(type, mp_level)) return; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
70 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
71 if(print_prefix && avc) { |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
72 mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
73 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
74 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
75 print_prefix= strchr(fmt, '\n') != NULL; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
76 mp_msg_va(type, mp_level, fmt, vl); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
77 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
78 |
34377
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
79 static void show_av_version(int type, const char *name, |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
80 int header_ver, int ver, const char *conf) |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
81 { |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
82 #ifdef CONFIG_FFMPEG_SO |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
83 #define FFMPEG_TYPE "external" |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
84 #else |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
85 #define FFMPEG_TYPE "internal" |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
86 #endif |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
87 mp_msg(type, MSGL_INFO, "%s version %d.%d.%d (" FFMPEG_TYPE ")\n", |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
88 name, ver >> 16, (ver >> 8) & 0xFF, ver & 0xFF); |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
89 if (header_ver != ver) |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
90 mp_msg(type, MSGL_INFO, "Mismatching header version %d.%d.%d\n", |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
91 header_ver >> 16, (header_ver >> 8) & 0xFF, header_ver & 0xFF); |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
92 mp_msg(type, MSGL_V, "Configuration: %s\n", conf); |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
93 } |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
94 |
33871
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
95 void init_avcodec(void) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
96 { |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
97 if (!avcodec_initialized) { |
34377
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
98 show_av_version(MSGT_DECVIDEO, "libavcodec", LIBAVCODEC_VERSION_INT, |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
99 avcodec_version(), avcodec_configuration()); |
33871
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
100 avcodec_register_all(); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
101 avcodec_initialized = 1; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
102 av_log_set_callback(mp_msp_av_log_callback); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
103 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
104 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
105 |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
106 void init_avformat(void) |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
107 { |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
108 if (!avformat_initialized) { |
34377
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
109 show_av_version(MSGT_DEMUX, "libavformat", LIBAVFORMAT_VERSION_INT, |
d443d66a746c
av_helpers: show libav* version and configuration.
cigaes
parents:
34376
diff
changeset
|
110 avformat_version(), avformat_configuration()); |
33871
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
111 av_register_all(); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
112 avformat_initialized = 1; |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
113 av_log_set_callback(mp_msp_av_log_callback); |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
114 } |
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff
changeset
|
115 } |