[MPlayer-cvslog] r32043 - in trunk/libmpcodecs: ad_ffmpeg.c ae_lavc.c vd_ffmpeg.c vd_ffmpeg.h ve_lavc.c vf_fspp.c vf_lavc.c vf_lavcdeint.c vf_mcdeint.c vf_spp.c vf_uspp.c vf_zrmjpeg.c

diego subversion at mplayerhq.hu
Sat Sep 4 10:11:31 CEST 2010


Author: diego
Date: Sat Sep  4 10:11:31 2010
New Revision: 32043

Log:
Introduce init_avcodec function to avoid duplicated FFmpeg initializations.
Vlad Seryakov, vseryakov gmail com

Added:
   trunk/libmpcodecs/vd_ffmpeg.h
Modified:
   trunk/libmpcodecs/ad_ffmpeg.c
   trunk/libmpcodecs/ae_lavc.c
   trunk/libmpcodecs/vd_ffmpeg.c
   trunk/libmpcodecs/ve_lavc.c
   trunk/libmpcodecs/vf_fspp.c
   trunk/libmpcodecs/vf_lavc.c
   trunk/libmpcodecs/vf_lavcdeint.c
   trunk/libmpcodecs/vf_mcdeint.c
   trunk/libmpcodecs/vf_spp.c
   trunk/libmpcodecs/vf_uspp.c
   trunk/libmpcodecs/vf_zrmjpeg.c

Modified: trunk/libmpcodecs/ad_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/ad_ffmpeg.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/ad_ffmpeg.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ LIBAD_EXTERN(ffmpeg)
 
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 static int preinit(sh_audio_t *sh)
 {
@@ -95,11 +95,7 @@ static int init(sh_audio_t *sh_audio)
     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){

Modified: trunk/libmpcodecs/ae_lavc.c
==============================================================================
--- trunk/libmpcodecs/ae_lavc.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/ae_lavc.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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_abitrate;
 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 @@ int mpae_init_lavc(audio_encoder_t *enco
 		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)

Modified: trunk/libmpcodecs/vd_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/vd_ffmpeg.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vd_ffmpeg.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static void set_format_params(struct AVC
     }
 }
 
+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 @@ static int init(sh_video_t *sh){
     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)

Added: trunk/libmpcodecs/vd_ffmpeg.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libmpcodecs/vd_ffmpeg.h	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 */

Modified: trunk/libmpcodecs/ve_lavc.c
==============================================================================
--- trunk/libmpcodecs/ve_lavc.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/ve_lavc.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ extern char* passtmpfile;
 
 #include "libavcodec/avcodec.h"
 
-extern int avcodec_initialized;
 
 /* video options */
 static char *lavc_param_vcodec = "mpeg4";
@@ -1033,11 +1033,7 @@ static int vf_open(vf_instance_t *vf, ch
 	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) {

Modified: trunk/libmpcodecs/vf_fspp.c
==============================================================================
--- trunk/libmpcodecs/vf_fspp.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_fspp.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static int vf_open(vf_instance_t *vf, ch
     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);

Modified: trunk/libmpcodecs/vf_lavc.c
==============================================================================
--- trunk/libmpcodecs/vf_lavc.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_lavc.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static int vf_open(vf_instance_t *vf, ch
     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) {

Modified: trunk/libmpcodecs/vf_lavcdeint.c
==============================================================================
--- trunk/libmpcodecs/vf_lavcdeint.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_lavcdeint.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ vf_open(vf_instance_t *vf, char *args)
   /* 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;
 }

Modified: trunk/libmpcodecs/vf_mcdeint.c
==============================================================================
--- trunk/libmpcodecs/vf_mcdeint.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_mcdeint.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -66,6 +66,7 @@ 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))
@@ -316,8 +317,7 @@ static int vf_open(vf_instance_t *vf, ch
     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;

Modified: trunk/libmpcodecs/vf_spp.c
==============================================================================
--- trunk/libmpcodecs/vf_spp.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_spp.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static int vf_open(vf_instance_t *vf, ch
     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);

Modified: trunk/libmpcodecs/vf_uspp.c
==============================================================================
--- trunk/libmpcodecs/vf_uspp.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_uspp.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static int vf_open(vf_instance_t *vf, ch
     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;
 

Modified: trunk/libmpcodecs/vf_zrmjpeg.c
==============================================================================
--- trunk/libmpcodecs/vf_zrmjpeg.c	Sat Sep  4 02:20:08 2010	(r32042)
+++ trunk/libmpcodecs/vf_zrmjpeg.c	Sat Sep  4 10:11:31 2010	(r32043)
@@ -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 @@ static jpeg_enc_t *jpeg_enc_init(int w, 
 	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 @@ static int vf_open(vf_instance_t *vf, ch
 	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;


More information about the MPlayer-cvslog mailing list