From a4f41308190b79d79a5ac7a50791332e5c1d5600 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 18 Jul 2011 00:28:22 +0300 Subject: cleanup: do libav* initialization on startup Do the global initialization of libavcodec and libavformat (avcodec_register_all(), av_register_all()) immediately on program startup and remove the initialization calls from various individual modules that use libavcodec/libavformat functionality. --- av_log.c | 10 ++++++++-- av_log.h | 2 +- libaf/af_lavcac3enc.c | 3 --- libmpcodecs/ad_ffmpeg.c | 2 -- libmpcodecs/vd_ffmpeg.c | 14 -------------- libmpcodecs/vd_ffmpeg.h | 24 ------------------------ libmpcodecs/vf_fspp.c | 3 --- libmpcodecs/vf_lavc.c | 3 --- libmpcodecs/vf_lavcdeint.c | 6 ------ libmpcodecs/vf_mcdeint.c | 3 --- libmpcodecs/vf_screenshot.c | 1 - libmpcodecs/vf_spp.c | 3 --- libmpcodecs/vf_uspp.c | 3 --- libmpdemux/demux_lavf.c | 2 -- libmpdemux/demux_rtp_codec.cpp | 1 - libmpdemux/demuxer.c | 3 --- libvo/vo_png.c | 1 - mplayer.c | 2 +- stream/stream_ffmpeg.c | 1 - sub/av_sub.c | 2 -- 20 files changed, 10 insertions(+), 79 deletions(-) delete mode 100644 libmpcodecs/vd_ffmpeg.h diff --git a/av_log.c b/av_log.c index 622cb1193a..376144800a 100644 --- a/av_log.c +++ b/av_log.c @@ -105,7 +105,13 @@ static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt, mp_msg_va(type, mp_level, fmt, vl); } -void set_av_log_callback(void) +void init_libav(void) { - av_log_set_callback(mp_msg_av_log_callback); + av_log_set_callback(mp_msg_av_log_callback); +#ifdef CONFIG_FFMPEG + avcodec_init(); + avcodec_register_all(); + + av_register_all(); +#endif } diff --git a/av_log.h b/av_log.h index baffb276ce..3bb3b1edbb 100644 --- a/av_log.h +++ b/av_log.h @@ -1 +1 @@ -void set_av_log_callback(void); +void init_libav(void); diff --git a/libaf/af_lavcac3enc.c b/libaf/af_lavcac3enc.c index 1042f3691e..db6dc52163 100644 --- a/libaf/af_lavcac3enc.c +++ b/libaf/af_lavcac3enc.c @@ -26,7 +26,6 @@ #include #include -#include "libmpcodecs/vd_ffmpeg.h" #include "config.h" #include "af.h" #include "reorder_ch.h" @@ -286,8 +285,6 @@ static int af_open(af_instance_t* af){ af->data=calloc(1,sizeof(af_data_t)); af->setup=s; - init_avcodec(); - s->lavc_acodec = avcodec_find_encoder_by_name("ac3"); if (!s->lavc_acodec) { mp_tmsg(MSGT_AFILTER, MSGL_ERR, "Audio LAVC, couldn't find encoder for codec %s.\n", "ac3"); diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c index b4ecd628c4..fb2d94dbfd 100644 --- a/libmpcodecs/ad_ffmpeg.c +++ b/libmpcodecs/ad_ffmpeg.c @@ -25,7 +25,6 @@ #include "options.h" #include "ad_internal.h" -#include "vd_ffmpeg.h" #include "libaf/reorder_ch.h" #include "mpbswap.h" @@ -102,7 +101,6 @@ static int init(sh_audio_t *sh_audio) AVCodec *lavc_codec; mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); - init_avcodec(); lavc_codec = avcodec_find_decoder_by_name(sh_audio->codec->dll); if(!lavc_codec){ diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c index 0a50415f66..9d33d5d963 100644 --- a/libmpcodecs/vd_ffmpeg.c +++ b/libmpcodecs/vd_ffmpeg.c @@ -38,7 +38,6 @@ #include "libmpdemux/stheader.h" #include "codec-cfg.h" #include "osdep/numcores.h" -#include "vd_ffmpeg.h" static const vd_info_t info = { "FFmpeg's libavcodec codec family", @@ -54,8 +53,6 @@ static const vd_info_t info = { #error palette too large, adapt libmpcodecs/vf.c:vf_get_image #endif -int avcodec_initialized=0; - typedef struct { AVCodecContext *avctx; AVFrame *pic; @@ -151,15 +148,6 @@ static int control(sh_video_t *sh, int cmd, void *arg, ...){ return CONTROL_UNKNOWN; } -void init_avcodec(void) -{ - if (!avcodec_initialized) { - avcodec_init(); - avcodec_register_all(); - avcodec_initialized = 1; - } -} - // init driver static int init(sh_video_t *sh){ struct lavc_param *lavc_param = &sh->opts->lavc_param; @@ -168,8 +156,6 @@ static int init(sh_video_t *sh){ AVCodec *lavc_codec; int do_vis_debug= lavc_param->vismv || (lavc_param->debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); - init_avcodec(); - ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx); lavc_codec = avcodec_find_decoder_by_name(sh->codec->dll); diff --git a/libmpcodecs/vd_ffmpeg.h b/libmpcodecs/vd_ffmpeg.h deleted file mode 100644 index 004d477330..0000000000 --- a/libmpcodecs/vd_ffmpeg.h +++ /dev/null @@ -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 */ diff --git a/libmpcodecs/vf_fspp.c b/libmpcodecs/vf_fspp.c index c84422104f..e7e3af8310 100644 --- a/libmpcodecs/vf_fspp.c +++ b/libmpcodecs/vf_fspp.c @@ -45,7 +45,6 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #include "libvo/fastmemcpy.h" #include "libavutil/internal.h" @@ -637,8 +636,6 @@ static int vf_open(vf_instance_t *vf, char *args) vf->control= control; vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 ! - init_avcodec(); - //vf->priv->avctx= avcodec_alloc_context(); //dsputil_init(&vf->priv->dsp, vf->priv->avctx); diff --git a/libmpcodecs/vf_lavc.c b/libmpcodecs/vf_lavc.c index c31044ba21..ba870a8b85 100644 --- a/libmpcodecs/vf_lavc.c +++ b/libmpcodecs/vf_lavc.c @@ -27,7 +27,6 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #include "libavcodec/avcodec.h" struct vf_priv_s { @@ -138,8 +137,6 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv,0,sizeof(struct vf_priv_s)); - init_avcodec(); - vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name("mpeg1video"); if (!vf->priv->codec) { mp_tmsg(MSGT_VFILTER,MSGL_ERR,"Cannot find codec '%s' in libavcodec...\n", "mpeg1video"); diff --git a/libmpcodecs/vf_lavcdeint.c b/libmpcodecs/vf_lavcdeint.c index fd564e72af..3a67c8db59 100644 --- a/libmpcodecs/vf_lavcdeint.c +++ b/libmpcodecs/vf_lavcdeint.c @@ -27,7 +27,6 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #include "libavcodec/avcodec.h" @@ -171,11 +170,6 @@ vf_open(vf_instance_t *vf, char *args) vf->priv = malloc(sizeof(struct vf_priv_s)); memset(vf->priv,0,sizeof(struct vf_priv_s)); - /* This may not technically be necessary just for a deinterlace, - * but it seems like a good idea. - */ - init_avcodec(); - return 1; } diff --git a/libmpcodecs/vf_mcdeint.c b/libmpcodecs/vf_mcdeint.c index 444314ef47..82635e5dfd 100644 --- a/libmpcodecs/vf_mcdeint.c +++ b/libmpcodecs/vf_mcdeint.c @@ -61,7 +61,6 @@ Known Issues: #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #define MIN(a,b) ((a) > (b) ? (b) : (a)) #define MAX(a,b) ((a) < (b) ? (b) : (a)) @@ -312,8 +311,6 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv, 0, sizeof(struct vf_priv_s)); - init_avcodec(); - vf->priv->mode=0; vf->priv->parity= -1; vf->priv->qp=1; diff --git a/libmpcodecs/vf_screenshot.c b/libmpcodecs/vf_screenshot.c index 1b5d575fba..655a014886 100644 --- a/libmpcodecs/vf_screenshot.c +++ b/libmpcodecs/vf_screenshot.c @@ -301,7 +301,6 @@ static int vf_open(vf_instance_t *vf, char *args) vf->priv->outbuffer=0; vf->priv->ctx=0; vf->priv->avctx = avcodec_alloc_context(); - avcodec_register_all(); if (avcodec_open(vf->priv->avctx, avcodec_find_encoder(CODEC_ID_PNG))) { mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); return 0; diff --git a/libmpcodecs/vf_spp.c b/libmpcodecs/vf_spp.c index ab8a7d9dd0..2402d72554 100644 --- a/libmpcodecs/vf_spp.c +++ b/libmpcodecs/vf_spp.c @@ -44,7 +44,6 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #include "libvo/fastmemcpy.h" #define XMIN(a,b) ((a) < (b) ? (a) : (b)) @@ -571,8 +570,6 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv, 0, sizeof(struct vf_priv_s)); - init_avcodec(); - vf->priv->avctx= avcodec_alloc_context(); dsputil_init(&vf->priv->dsp, vf->priv->avctx); diff --git a/libmpcodecs/vf_uspp.c b/libmpcodecs/vf_uspp.c index 85383716b5..332d59ee22 100644 --- a/libmpcodecs/vf_uspp.c +++ b/libmpcodecs/vf_uspp.c @@ -35,7 +35,6 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" -#include "vd_ffmpeg.h" #include "libvo/fastmemcpy.h" #define XMIN(a,b) ((a) < (b) ? (a) : (b)) @@ -354,8 +353,6 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->priv=malloc(sizeof(struct vf_priv_s)); memset(vf->priv, 0, sizeof(struct vf_priv_s)); - init_avcodec(); - vf->priv->log2_count= 4; if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode); diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index 0b8c9190a4..545e3bdace 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -162,8 +162,6 @@ static int lavf_check_file(demuxer_t *demuxer) demuxer->priv = calloc(sizeof(lavf_priv_t), 1); priv = demuxer->priv; - av_register_all(); - char *format = lavfdopts->format; if (!format) format = demuxer->stream->lavf_type; diff --git a/libmpdemux/demux_rtp_codec.cpp b/libmpdemux/demux_rtp_codec.cpp index f0c3476aa5..68b1964c0c 100644 --- a/libmpdemux/demux_rtp_codec.cpp +++ b/libmpdemux/demux_rtp_codec.cpp @@ -137,7 +137,6 @@ void rtpCodecInitialize_video(demuxer_t* demuxer, #ifdef CONFIG_FFMPEG int fooLen; const uint8_t* fooData; - avcodec_register_all(); h264parserctx = av_parser_init(CODEC_ID_H264); avcctx = avcodec_alloc_context(); // Pass the config to the parser diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index b504ad4893..276d62dbae 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -41,7 +41,6 @@ #include "libaf/af_format.h" #include "libmpcodecs/dec_teletext.h" -#include "libmpcodecs/vd_ffmpeg.h" #ifdef CONFIG_FFMPEG #include "libavcodec/avcodec.h" @@ -495,8 +494,6 @@ static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parse { enum CodecID codec_id = CODEC_ID_NONE; - init_avcodec(); - switch (format) { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 0) case MKTAG('M', 'P', '4', 'L'): diff --git a/libvo/vo_png.c b/libvo/vo_png.c index 0b5d4a8eca..5ad683ad22 100644 --- a/libvo/vo_png.c +++ b/libvo/vo_png.c @@ -165,7 +165,6 @@ static int preinit(const char *arg) if (subopt_parse(arg, subopts) != 0) { return -1; } - avcodec_register_all(); avctx = avcodec_alloc_context(); if (avcodec_open(avctx, avcodec_find_encoder(CODEC_ID_PNG)) < 0) { uninit(); diff --git a/mplayer.c b/mplayer.c index a9175eb28c..432801426c 100644 --- a/mplayer.c +++ b/mplayer.c @@ -3845,7 +3845,7 @@ int i; srand(GetTimerMS()); mp_msg_init(); - set_av_log_callback(); + init_libav(); #ifdef CONFIG_X11 mpctx->x11_state = vo_x11_init_state(); diff --git a/stream/stream_ffmpeg.c b/stream/stream_ffmpeg.c index 343381afb0..101b112448 100644 --- a/stream/stream_ffmpeg.c +++ b/stream/stream_ffmpeg.c @@ -88,7 +88,6 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format) int64_t size; int dummy; - av_register_all(); if (mode == STREAM_READ) flags = URL_RDONLY; else if (mode == STREAM_WRITE) diff --git a/sub/av_sub.c b/sub/av_sub.c index a68fbce083..88f84db104 100644 --- a/sub/av_sub.c +++ b/sub/av_sub.c @@ -62,8 +62,6 @@ int decode_avsub(struct sh_sub *sh, uint8_t *data, int size, pkt.convergence_duration = duration * 1000; if (!ctx) { AVCodec *sub_codec; - avcodec_init(); - avcodec_register_all(); ctx = avcodec_alloc_context(); sub_codec = avcodec_find_decoder(cid); if (!ctx || !sub_codec || avcodec_open(ctx, sub_codec) < 0) { -- cgit v1.2.3