changeset 31959:f957f330aa6d

Introduce init_avcodec function to avoid duplicated FFmpeg initializations. Vlad Seryakov, vseryakov gmail com
author diego
date Sat, 04 Sep 2010 08:11:31 +0000
parents 4cccb69779ef
children 1ba5eef167aa
files 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 libmpcodecs/vf_zrmjpeg.c
diffstat 12 files changed, 56 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/ad_ffmpeg.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/ad_ffmpeg.c	Sat Sep 04 08:11:31 2010 +0000
@@ -25,6 +25,7 @@
 #include "help_mp.h"
 
 #include "ad_internal.h"
+#include "vd_ffmpeg.h"
 #include "libaf/reorder_ch.h"
 
 #include "mpbswap.h"
@@ -44,7 +45,6 @@
 
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 static int preinit(sh_audio_t *sh)
 {
@@ -95,11 +95,7 @@
     AVCodec *lavc_codec;
 
     mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
-    if(!avcodec_initialized){
-      avcodec_init();
-      avcodec_register_all();
-      avcodec_initialized=1;
-    }
+    init_avcodec();
 
     lavc_codec = avcodec_find_decoder_by_name(sh_audio->codec->dll);
     if(!lavc_codec){
--- a/libmpcodecs/ae_lavc.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/ae_lavc.c	Sat Sep 04 08:11:31 2010 +0000
@@ -30,6 +30,7 @@
 #include "stream/stream.h"
 #include "libmpdemux/muxer.h"
 #include "ae_lavc.h"
+#include "vd_ffmpeg.h"
 #include "help_mp.h"
 #include "av_opts.h"
 #include "libaf/af_format.h"
@@ -44,7 +45,6 @@
 extern int  lavc_param_atag;
 extern int  lavc_param_audio_global_header;
 extern char *lavc_param_audio_avopt;
-extern int  avcodec_initialized;
 static int compressed_frame_size = 0;
 #ifdef CONFIG_LIBAVFORMAT
 #include "libavformat/avformat.h"
@@ -190,11 +190,7 @@
 		return 0;
 	}
 
-	if(!avcodec_initialized){
-		avcodec_init();
-		avcodec_register_all();
-		avcodec_initialized=1;
-	}
+	init_avcodec();
 
 	lavc_acodec = avcodec_find_encoder_by_name(lavc_param_acodec);
 	if (!lavc_acodec)
--- a/libmpcodecs/vd_ffmpeg.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sat Sep 04 08:11:31 2010 +0000
@@ -32,6 +32,7 @@
 #include "fmt-conversion.h"
 
 #include "vd_internal.h"
+#include "vd_ffmpeg.h"
 
 static const vd_info_t info = {
     "FFmpeg's libavcodec codec family",
@@ -249,6 +250,16 @@
     }
 }
 
+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;
@@ -257,12 +268,7 @@
     int lowres_w=0;
     int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP));
 
-    if(!avcodec_initialized){
-        avcodec_init();
-        avcodec_register_all();
-        avcodec_initialized=1;
-        av_log_set_callback(mp_msp_av_log_callback);
-    }
+    init_avcodec();
 
     ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx));
     if (!ctx)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpcodecs/vd_ffmpeg.h	Sat Sep 04 08:11:31 2010 +0000
@@ -0,0 +1,24 @@
+/*
+ * 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	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/ve_lavc.c	Sat Sep 04 08:11:31 2010 +0000
@@ -46,6 +46,7 @@
 #include "fmt-conversion.h"
 #include "mp_image.h"
 #include "vf.h"
+#include "vd_ffmpeg.h"
 
 extern char* passtmpfile;
 
@@ -53,7 +54,6 @@
 
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 /* video options */
 static char *lavc_param_vcodec = "mpeg4";
@@ -1033,11 +1033,7 @@
 	mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0],
 		lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */
 
-    if (!avcodec_initialized){
-	avcodec_init();
-	avcodec_register_all();
-	avcodec_initialized=1;
-    }
+    init_avcodec();
 
     vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec);
     if (!vf->priv->codec) {
--- a/libmpcodecs/vf_fspp.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_fspp.c	Sat Sep 04 08:11:31 2010 +0000
@@ -45,6 +45,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
+#include "vd_ffmpeg.h"
 #include "libvo/fastmemcpy.h"
 
 #include "libavutil/internal.h"
@@ -636,7 +637,7 @@
     vf->control= control;
     vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
 
-    avcodec_init();
+    init_avcodec();
 
     //vf->priv->avctx= avcodec_alloc_context();
     //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
--- a/libmpcodecs/vf_lavc.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_lavc.c	Sat Sep 04 08:11:31 2010 +0000
@@ -28,9 +28,9 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
+#include "vd_ffmpeg.h"
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 struct vf_priv_s {
     unsigned char* outbuf;
@@ -140,11 +140,7 @@
     vf->priv=malloc(sizeof(struct vf_priv_s));
     memset(vf->priv,0,sizeof(struct vf_priv_s));
 
-    if (!avcodec_initialized){
-	avcodec_init();
-	avcodec_register_all();
-	avcodec_initialized=1;
-    }
+    init_avcodec();
 
     vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name("mpeg1video");
     if (!vf->priv->codec) {
--- a/libmpcodecs/vf_lavcdeint.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_lavcdeint.c	Sat Sep 04 08:11:31 2010 +0000
@@ -28,9 +28,9 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
+#include "vd_ffmpeg.h"
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 struct vf_priv_s
 {
@@ -175,12 +175,7 @@
   /* This may not technically be necessary just for a deinterlace,
    * but it seems like a good idea.
    */
-  if(!avcodec_initialized)
-    {
-      avcodec_init();
-      avcodec_register_all();
-      avcodec_initialized=1;
-    }
+  init_avcodec();
 
   return 1;
 }
--- a/libmpcodecs/vf_mcdeint.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_mcdeint.c	Sat Sep 04 08:11:31 2010 +0000
@@ -66,6 +66,7 @@
 #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))
@@ -316,8 +317,7 @@
     vf->priv=malloc(sizeof(struct vf_priv_s));
     memset(vf->priv, 0, sizeof(struct vf_priv_s));
 
-    avcodec_init();
-    avcodec_register_all();
+    init_avcodec();
 
     vf->priv->mode=0;
     vf->priv->parity= -1;
--- a/libmpcodecs/vf_spp.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_spp.c	Sat Sep 04 08:11:31 2010 +0000
@@ -49,6 +49,7 @@
 #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))
@@ -575,7 +576,7 @@
     vf->priv=malloc(sizeof(struct vf_priv_s));
     memset(vf->priv, 0, sizeof(struct vf_priv_s));
 
-    avcodec_init();
+    init_avcodec();
 
     vf->priv->avctx= avcodec_alloc_context();
     dsputil_init(&vf->priv->dsp, vf->priv->avctx);
--- a/libmpcodecs/vf_uspp.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_uspp.c	Sat Sep 04 08:11:31 2010 +0000
@@ -35,6 +35,7 @@
 #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))
@@ -353,8 +354,7 @@
     vf->priv=malloc(sizeof(struct vf_priv_s));
     memset(vf->priv, 0, sizeof(struct vf_priv_s));
 
-    avcodec_init();
-    avcodec_register_all();
+    init_avcodec();
 
     vf->priv->log2_count= 4;
 
--- a/libmpcodecs/vf_zrmjpeg.c	Sat Sep 04 00:20:08 2010 +0000
+++ b/libmpcodecs/vf_zrmjpeg.c	Sat Sep 04 08:11:31 2010 +0000
@@ -63,10 +63,6 @@
 #define WARNING(...) mp_msg(MSGT_DECVIDEO, MSGL_WARN, \
 		"vf_zrmjpeg: " __VA_ARGS__)
 
-// "local" flag in vd_ffmpeg.c. If not set, avcodec_init() et. al. need to be called
-// set when init is done, so that initialization is not done twice.
-extern int avcodec_initialized;
-
 /// The get_pixels() routine to use. The real routine comes from dsputil
 static void (*get_pixels)(DCTELEM *restrict block, const uint8_t *pixels, int line_size);
 
@@ -473,15 +469,7 @@
 	j->cheap_upsample = cu;
 	j->bw = b;
 
-	// Is this needed?
-	/* if libavcodec is used by the decoder then we must not
-	 * initialize again, but if it is not initialized then we must
-	 * initialize it here. */
-	if (!avcodec_initialized) {
-		avcodec_init();
-		avcodec_register_all();
-		avcodec_initialized=1;
-	}
+	init_avcodec();
 
 	// Build mjpeg huffman code tables, setting up j->s->mjpeg_ctx
 	if (ff_mjpeg_encode_init(j->s) < 0) {
@@ -919,14 +907,7 @@
 	priv->hdec = 1;
 	priv->vdec = 1;
 
-	/* if libavcodec is already initialized, we must not initialize it
-	 * again, but if it is not initialized then we mustinitialize it now. */
-	if (!avcodec_initialized) {
-		/* we need to initialize libavcodec */
-		avcodec_init();
-		avcodec_register_all();
-		avcodec_initialized=1;
-	}
+	init_avcodec();
 
 	if (args) {
 		char *arg, *tmp, *ptr, junk;