Mercurial > mplayer.hg
changeset 33871:30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
separate file and also use it when only initializing libavformat.
author | reimar |
---|---|
date | Tue, 09 Aug 2011 19:57:00 +0000 |
parents | 15e182c07689 |
children | d7bc4bcc3523 |
files | Makefile av_helpers.c av_helpers.h libaf/af_lavcac3enc.c libmpcodecs/ad_ffmpeg.c libmpcodecs/ae_lavc.c libmpcodecs/vd_ffmpeg.c libmpcodecs/vd_ffmpeg.h libmpcodecs/ve_lavc.c libmpcodecs/vf_fspp.c libmpcodecs/vf_lavc.c libmpcodecs/vf_lavcdeint.c libmpcodecs/vf_mcdeint.c libmpcodecs/vf_spp.c libmpcodecs/vf_uspp.c libmpdemux/demux_lavf.c libmpdemux/demuxer.c libmpdemux/muxer_lavf.c stream/stream_ffmpeg.c |
diffstat | 19 files changed, 102 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Tue Aug 09 19:23:41 2011 +0000 +++ b/Makefile Tue Aug 09 19:57:00 2011 +0000 @@ -60,6 +60,7 @@ SRCS_COMMON-$(FAAD) += libmpcodecs/ad_faad.c SRCS_COMMON-$(FASTMEMCPY) += libvo/aclib.c SRCS_COMMON-$(FFMPEG) += av_opts.c \ + av_helpers.c \ libaf/af_lavcresample.c \ libmpcodecs/ad_ffmpeg.c \ libmpcodecs/vd_ffmpeg.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/av_helpers.c Tue Aug 09 19:57:00 2011 +0000 @@ -0,0 +1,76 @@ +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "mp_msg.h" +#include "av_helpers.h" + +int avcodec_initialized; +int avformat_initialized; + +static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt, + va_list vl) +{ + static int print_prefix=1; + AVClass *avc= ptr ? *(AVClass **)ptr : NULL; + int type= MSGT_FIXME; + int mp_level; + + switch(level){ + case AV_LOG_VERBOSE: mp_level = MSGL_V ; break; + case AV_LOG_DEBUG: mp_level= MSGL_V ; break; + case AV_LOG_INFO : mp_level= MSGL_INFO; break; + case AV_LOG_ERROR: mp_level= MSGL_ERR ; break; + default : mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break; + } + + if (ptr && !avc) + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n"); + if (avc) { + if(!strcmp(avc->class_name, "AVCodecContext")){ + AVCodecContext *s= ptr; + if(s->codec){ + if(s->codec->type == AVMEDIA_TYPE_AUDIO){ + if(s->codec->decode) + type= MSGT_DECAUDIO; + }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){ + if(s->codec->decode) + type= MSGT_DECVIDEO; + } + //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...) + } + }else if(!strcmp(avc->class_name, "AVFormatContext")){ + AVFormatContext *s= ptr; + if(s->iformat) + type= MSGT_DEMUXER; + else if(s->oformat) + type= MSGT_MUXER; + } + } + + if (!mp_msg_test(type, mp_level)) return; + + if(print_prefix && avc) { + mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc); + } + + print_prefix= strchr(fmt, '\n') != NULL; + mp_msg_va(type, mp_level, fmt, vl); +} + +void init_avcodec(void) +{ + if (!avcodec_initialized) { + avcodec_init(); + avcodec_register_all(); + avcodec_initialized = 1; + av_log_set_callback(mp_msp_av_log_callback); + } +} + +void init_avformat(void) +{ + if (!avformat_initialized) { + av_register_all(); + avformat_initialized = 1; + av_log_set_callback(mp_msp_av_log_callback); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/av_helpers.h Tue Aug 09 19:57:00 2011 +0000 @@ -0,0 +1,7 @@ +#ifndef MPLAYER_AV_HELPERS_H +#define MPLAYER_AV_HELPERS_H + +void init_avcodec(void); +void init_avformat(void); + +#endif /* MPLAYER_AV_HELPERS_H */
--- a/libaf/af_lavcac3enc.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libaf/af_lavcac3enc.c Tue Aug 09 19:57:00 2011 +0000 @@ -25,11 +25,11 @@ #include <string.h> #include <inttypes.h> -#include "libmpcodecs/vd_ffmpeg.h" #include "config.h" #include "af.h" #include "help_mp.h" #include "reorder_ch.h" +#include "av_helpers.h" #include "libavcodec/avcodec.h" #include "libavcodec/ac3.h"
--- a/libmpcodecs/ad_ffmpeg.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/ad_ffmpeg.c Tue Aug 09 19:57:00 2011 +0000 @@ -26,7 +26,7 @@ #include "ad_internal.h" #include "dec_audio.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libaf/reorder_ch.h" #include "fmt-conversion.h"
--- a/libmpcodecs/ae_lavc.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/ae_lavc.c Tue Aug 09 19:57:00 2011 +0000 @@ -30,7 +30,7 @@ #include "stream/stream.h" #include "libmpdemux/muxer.h" #include "ae_lavc.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "ve.h" #include "help_mp.h" #include "av_opts.h"
--- a/libmpcodecs/vd_ffmpeg.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vd_ffmpeg.c Tue Aug 09 19:57:00 2011 +0000 @@ -25,6 +25,7 @@ #include "mp_msg.h" #include "help_mp.h" #include "av_opts.h" +#include "av_helpers.h" #include "libavutil/common.h" #include "libavutil/intreadwrite.h" @@ -32,7 +33,6 @@ #include "fmt-conversion.h" #include "vd_internal.h" -#include "vd_ffmpeg.h" static const vd_info_t info = { "FFmpeg's libavcodec codec family", @@ -54,8 +54,6 @@ #include "libavcodec/xvmc.h" #endif -int avcodec_initialized=0; - typedef struct { AVCodecContext *avctx; AVFrame *pic; @@ -181,59 +179,6 @@ return CONTROL_UNKNOWN; } -static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt, - va_list vl) -{ - static int print_prefix=1; - AVClass *avc= ptr ? *(AVClass **)ptr : NULL; - int type= MSGT_FIXME; - int mp_level; - - switch(level){ - case AV_LOG_VERBOSE: mp_level = MSGL_V ; break; - case AV_LOG_DEBUG: mp_level= MSGL_V ; break; - case AV_LOG_INFO : mp_level= MSGL_INFO; break; - case AV_LOG_ERROR: mp_level= MSGL_ERR ; break; - default : mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break; - } - - if (ptr && !avc) - mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n"); - if (avc) { - if(!strcmp(avc->class_name, "AVCodecContext")){ - AVCodecContext *s= ptr; - if(s->codec){ - if(s->codec->type == AVMEDIA_TYPE_AUDIO){ - if(s->codec->decode) - type= MSGT_DECAUDIO; - }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){ - if(s->codec->decode) - type= MSGT_DECVIDEO; - } - //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...) - } - }else if(!strcmp(avc->class_name, "AVFormatContext")){ - type= MSGT_DEMUXER; -#if 0 //needs libavformat include FIXME iam too lazy to do this cleanly, probably the whole should be moved out of this file ... - AVFormatContext *s= ptr; - if(s->iformat) - type= MSGT_DEMUXER; - else if(s->oformat) - type= MSGT_MUXER; -#endif - } - } - - if (!mp_msg_test(type, mp_level)) return; - - if(print_prefix && avc) { - mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc); - } - - print_prefix= strchr(fmt, '\n') != NULL; - mp_msg_va(type, mp_level, fmt, vl); -} - static void set_format_params(struct AVCodecContext *avctx, enum PixelFormat fmt){ int imgfmt; if (fmt == PIX_FMT_NONE) @@ -261,16 +206,6 @@ } } -void init_avcodec(void) -{ - if (!avcodec_initialized) { - avcodec_init(); - avcodec_register_all(); - avcodec_initialized = 1; - av_log_set_callback(mp_msp_av_log_callback); - } -} - // init driver static int init(sh_video_t *sh){ AVCodecContext *avctx;
--- a/libmpcodecs/vd_ffmpeg.h Tue Aug 09 19:23:41 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_VD_FFMPEG_H -#define MPLAYER_VD_FFMPEG_H - -void init_avcodec(void); - -#endif /* MPLAYER_VD_FFMPEG_H */
--- a/libmpcodecs/ve_lavc.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/ve_lavc.c Tue Aug 09 19:57:00 2011 +0000 @@ -47,7 +47,7 @@ #include "mp_image.h" #include "ve.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" //===========================================================================//
--- a/libmpcodecs/vf_fspp.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_fspp.c Tue Aug 09 19:57:00 2011 +0000 @@ -45,7 +45,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libvo/fastmemcpy.h" #include "libavutil/internal.h"
--- a/libmpcodecs/vf_lavc.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_lavc.c Tue Aug 09 19:57:00 2011 +0000 @@ -28,7 +28,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libavcodec/avcodec.h"
--- a/libmpcodecs/vf_lavcdeint.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_lavcdeint.c Tue Aug 09 19:57:00 2011 +0000 @@ -28,7 +28,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libavcodec/avcodec.h"
--- a/libmpcodecs/vf_mcdeint.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_mcdeint.c Tue Aug 09 19:57:00 2011 +0000 @@ -66,7 +66,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #define MIN(a,b) ((a) > (b) ? (b) : (a)) #define MAX(a,b) ((a) < (b) ? (b) : (a))
--- a/libmpcodecs/vf_spp.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_spp.c Tue Aug 09 19:57:00 2011 +0000 @@ -49,7 +49,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libvo/fastmemcpy.h" #define XMIN(a,b) ((a) < (b) ? (a) : (b))
--- a/libmpcodecs/vf_uspp.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpcodecs/vf_uspp.c Tue Aug 09 19:57:00 2011 +0000 @@ -35,7 +35,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" +#include "av_helpers.h" #include "libvo/fastmemcpy.h" #define XMIN(a,b) ((a) < (b) ? (a) : (b))
--- a/libmpdemux/demux_lavf.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpdemux/demux_lavf.c Tue Aug 09 19:57:00 2011 +0000 @@ -27,6 +27,7 @@ #include "mp_msg.h" #include "help_mp.h" #include "av_opts.h" +#include "av_helpers.h" #include "stream/stream.h" #include "aviprint.h" @@ -154,7 +155,7 @@ demuxer->priv=calloc(sizeof(lavf_priv_t),1); priv= demuxer->priv; - av_register_all(); + init_avformat(); if (opt_format) { if (strcmp(opt_format, "help") == 0) {
--- a/libmpdemux/demuxer.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpdemux/demuxer.c Tue Aug 09 19:57:00 2011 +0000 @@ -44,7 +44,6 @@ #include "libmpcodecs/dec_audio.h" #include "libmpcodecs/dec_video.h" #include "libmpcodecs/dec_teletext.h" -#include "libmpcodecs/vd_ffmpeg.h" #ifdef CONFIG_ASS #include "libass/ass.h" @@ -56,6 +55,7 @@ #if MP_INPUT_BUFFER_PADDING_SIZE < FF_INPUT_BUFFER_PADDING_SIZE #error MP_INPUT_BUFFER_PADDING_SIZE is too small! #endif +#include "av_helpers.h" #endif // This is quite experimental, in particular it will mess up the pts values
--- a/libmpdemux/muxer_lavf.c Tue Aug 09 19:23:41 2011 +0000 +++ b/libmpdemux/muxer_lavf.c Tue Aug 09 19:57:00 2011 +0000 @@ -29,6 +29,7 @@ #include "aviheader.h" #include "ms_hdr.h" #include "av_opts.h" +#include "av_helpers.h" #include "stream/stream.h" #include "muxer.h" @@ -317,7 +318,7 @@ muxer_priv_t *priv; AVOutputFormat *fmt = NULL; - av_register_all(); + init_avformat(); if (conf_format && strcmp(conf_format, "help") == 0) { list_formats();
--- a/stream/stream_ffmpeg.c Tue Aug 09 19:23:41 2011 +0000 +++ b/stream/stream_ffmpeg.c Tue Aug 09 19:57:00 2011 +0000 @@ -24,6 +24,7 @@ #include "stream.h" #include "m_option.h" #include "m_struct.h" +#include "av_helpers.h" static int fill_buffer(stream_t *s, char *buffer, int max_len) { @@ -87,7 +88,7 @@ int64_t size; int dummy; - av_register_all(); + init_avformat(); if (mode == STREAM_READ) flags = URL_RDONLY; else if (mode == STREAM_WRITE)