annotate av_helpers.c @ 34359:2cc52bc15984

Support SBG decoding using ffwavesynth.
author cigaes
date Thu, 15 Dec 2011 22:32:22 +0000
parents 5f1faa91717e
children fd7abb6f787a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33886
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
1 /*
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
2 * Generic libav* helpers
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
3 *
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
4 * This file is part of MPlayer.
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
5 *
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
7 * it under the terms of the GNU General Public License as published by
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
9 * (at your option) any later version.
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
10 *
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
14 * GNU General Public License for more details.
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
15 *
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
16 * You should have received a copy of the GNU General Public License along
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
19 */
5f1faa91717e Add license boilerplate.
reimar
parents: 33871
diff changeset
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
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
79 void init_avcodec(void)
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
80 {
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
81 if (!avcodec_initialized) {
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
82 avcodec_init();
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
83 avcodec_register_all();
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
84 avcodec_initialized = 1;
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
85 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
86 }
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
87 }
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
88
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
89 void init_avformat(void)
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
90 {
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
91 if (!avformat_initialized) {
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
92 av_register_all();
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
93 avformat_initialized = 1;
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
94 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
95 }
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
diff changeset
96 }