summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordiego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-09-04 08:11:31 +0000
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-11-02 04:15:51 +0200
commitf2899d96eecc7de5a3f4b2ef231e514085e467e0 (patch)
tree43afa4796389fd043b0b6d8172a71b069598bb0b
parenta92b4adf61c4f2a77822326d18b983e7e8fb21fb (diff)
downloadmpv-f2899d96eecc7de5a3f4b2ef231e514085e467e0.tar.bz2
mpv-f2899d96eecc7de5a3f4b2ef231e514085e467e0.tar.xz
Add central init_avcodec() to avoid duplicated libavcodec init code
Patch by Vlad Seryakov, vseryakov gmail com git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32043 b3059339-0415-0410-9bf9-f77b7e298cf2 Refactor more instances of avcodec_initialized handling into init_avcodec(). This is a leftover from the previous commit. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32044 b3059339-0415-0410-9bf9-f77b7e298cf2 Add missing #include for vd_ffmpeg.h; fixes the warning: libmpcodecs/vf_zrmjpeg.c:472: warning: implicit declaration of function 'init_avcodec' git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32176 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--libaf/af_lavcac3enc.c9
-rw-r--r--libmpcodecs/ad_ffmpeg.c8
-rw-r--r--libmpcodecs/vd_ffmpeg.c16
-rw-r--r--libmpcodecs/vd_ffmpeg.h24
-rw-r--r--libmpcodecs/ve_lavc.c8
-rw-r--r--libmpcodecs/vf_fspp.c3
-rw-r--r--libmpcodecs/vf_lavc.c8
-rw-r--r--libmpcodecs/vf_lavcdeint.c9
-rw-r--r--libmpcodecs/vf_mcdeint.c4
-rw-r--r--libmpcodecs/vf_spp.c3
-rw-r--r--libmpcodecs/vf_uspp.c4
-rw-r--r--libmpcodecs/vf_zrmjpeg.c24
-rw-r--r--libmpdemux/demuxer.c10
-rw-r--r--libvo/jpeg_enc.c13
14 files changed, 62 insertions, 81 deletions
diff --git a/libaf/af_lavcac3enc.c b/libaf/af_lavcac3enc.c
index 10a9eb58c8..ae557579d6 100644
--- a/libaf/af_lavcac3enc.c
+++ b/libaf/af_lavcac3enc.c
@@ -26,6 +26,7 @@
#include <inttypes.h>
#include <assert.h>
+#include "libmpcodecs/vd_ffmpeg.h"
#include "config.h"
#include "af.h"
#include "reorder_ch.h"
@@ -54,8 +55,6 @@ typedef struct af_ac3enc_s {
int min_channel_num;
} af_ac3enc_t;
-extern int avcodec_initialized;
-
// Initialization and runtime control
static int control(struct af_instance_s *af, int cmd, void *arg)
{
@@ -287,11 +286,7 @@ static int af_open(af_instance_t* af){
af->data=calloc(1,sizeof(af_data_t));
af->setup=s;
- if (!avcodec_initialized){
- avcodec_init();
- avcodec_register_all();
- avcodec_initialized=1;
- }
+ init_avcodec();
s->lavc_acodec = avcodec_find_encoder_by_name("ac3");
if (!s->lavc_acodec) {
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 6b7ca97885..6dd5dcf492 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -25,6 +25,7 @@
#include "options.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)
{
@@ -99,11 +99,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){
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 0101c5d39d..30ee162743 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -37,6 +37,7 @@
#include "img_format.h"
#include "libmpdemux/stheader.h"
#include "codec-cfg.h"
+#include "vd_ffmpeg.h"
static const vd_info_t info = {
"FFmpeg's libavcodec codec family",
@@ -158,6 +159,15 @@ 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;
@@ -167,11 +177,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;
- }
+ init_avcodec();
ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx);
diff --git a/libmpcodecs/vd_ffmpeg.h b/libmpcodecs/vd_ffmpeg.h
new file mode 100644
index 0000000000..004d477330
--- /dev/null
+++ b/libmpcodecs/vd_ffmpeg.h
@@ -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 */
diff --git a/libmpcodecs/ve_lavc.c b/libmpcodecs/ve_lavc.c
index 4cd7cd778d..b36dad73ee 100644
--- a/libmpcodecs/ve_lavc.c
+++ b/libmpcodecs/ve_lavc.c
@@ -45,6 +45,7 @@
#include "fmt-conversion.h"
#include "mp_image.h"
#include "vf.h"
+#include "vd_ffmpeg.h"
extern char* passtmpfile;
@@ -52,7 +53,6 @@ extern char* passtmpfile;
#include "libavcodec/avcodec.h"
-extern int avcodec_initialized;
/* video options */
static char *lavc_param_vcodec = "mpeg4";
@@ -1030,11 +1030,7 @@ static int vf_open(vf_instance_t *vf, char* args){
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) {
diff --git a/libmpcodecs/vf_fspp.c b/libmpcodecs/vf_fspp.c
index 2435587a5a..1819ac636c 100644
--- a/libmpcodecs/vf_fspp.c
+++ b/libmpcodecs/vf_fspp.c
@@ -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, char *args)
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);
diff --git a/libmpcodecs/vf_lavc.c b/libmpcodecs/vf_lavc.c
index 757a05cdc2..2efccf093b 100644
--- a/libmpcodecs/vf_lavc.c
+++ b/libmpcodecs/vf_lavc.c
@@ -27,9 +27,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;
@@ -139,11 +139,7 @@ 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));
- 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) {
diff --git a/libmpcodecs/vf_lavcdeint.c b/libmpcodecs/vf_lavcdeint.c
index 8d2cca43c0..fd564e72af 100644
--- a/libmpcodecs/vf_lavcdeint.c
+++ b/libmpcodecs/vf_lavcdeint.c
@@ -27,9 +27,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
{
@@ -174,12 +174,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;
}
diff --git a/libmpcodecs/vf_mcdeint.c b/libmpcodecs/vf_mcdeint.c
index 3253d59033..1d92697955 100644
--- a/libmpcodecs/vf_mcdeint.c
+++ b/libmpcodecs/vf_mcdeint.c
@@ -61,6 +61,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))
@@ -311,8 +312,7 @@ 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));
- avcodec_init();
- avcodec_register_all();
+ init_avcodec();
vf->priv->mode=0;
vf->priv->parity= -1;
diff --git a/libmpcodecs/vf_spp.c b/libmpcodecs/vf_spp.c
index e53a95174b..5a4214d872 100644
--- a/libmpcodecs/vf_spp.c
+++ b/libmpcodecs/vf_spp.c
@@ -44,6 +44,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))
@@ -570,7 +571,7 @@ 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));
- avcodec_init();
+ 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 ad311ca9b7..2e1e055ff5 100644
--- a/libmpcodecs/vf_uspp.c
+++ b/libmpcodecs/vf_uspp.c
@@ -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, char *args){
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;
diff --git a/libmpcodecs/vf_zrmjpeg.c b/libmpcodecs/vf_zrmjpeg.c
index 0b87d01ce8..7d504ad290 100644
--- a/libmpcodecs/vf_zrmjpeg.c
+++ b/libmpcodecs/vf_zrmjpeg.c
@@ -43,6 +43,7 @@
#include "img_format.h"
#include "mp_image.h"
+#include "vd_ffmpeg.h"
#include "vf.h"
/* We need this #define because we need ../libavcodec/common.h to #define
@@ -63,10 +64,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 +470,7 @@ static jpeg_enc_t *jpeg_enc_init(int w, int h, int y_rsize,
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 +908,7 @@ static int vf_open(vf_instance_t *vf, char *args){
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;
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 837faa6b94..9906ec85de 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -41,6 +41,7 @@
#include "libaf/af_format.h"
#include "libmpcodecs/dec_teletext.h"
+#include "libmpcodecs/vd_ffmpeg.h"
#include "ass_mp.h"
@@ -439,12 +440,9 @@ static void ds_add_packet_internal(demux_stream_t *ds, demux_packet_t *dp)
static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, unsigned format)
{
enum CodecID codec_id = CODEC_ID_NONE;
- extern int avcodec_initialized;
- if (!avcodec_initialized) {
- avcodec_init();
- avcodec_register_all();
- avcodec_initialized = 1;
- }
+
+ init_avcodec();
+
switch (format) {
case 0x2000:
case 0x332D6361:
diff --git a/libvo/jpeg_enc.c b/libvo/jpeg_enc.c
index 5356d4b26d..37b5010250 100644
--- a/libvo/jpeg_enc.c
+++ b/libvo/jpeg_enc.c
@@ -41,10 +41,9 @@
#include "libavcodec/mpegvideo.h"
#include "libavcodec/mjpegenc.h"
+#include "libmpcodecs/vd_ffmpeg.h"
#include "jpeg_enc.h"
-extern int avcodec_initialized;
-
/* Begin excessive code duplication ************************************/
/* Code coming from mpegvideo.c and mjpeg.c in ../libavcodec ***********/
@@ -320,15 +319,7 @@ jpeg_enc_t *jpeg_enc_init(int w, int h, int y_psize, int y_rsize,
j->cheap_upsample = cu;
j->bw = b;
- /* 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) {
- /* we need to initialize libavcodec */
- avcodec_init();
- avcodec_register_all();
- avcodec_initialized=1;
- }
+ init_avcodec();
if (ff_mjpeg_encode_init(j->s) < 0) {
av_free(j->s);