[vlc-devel] [PATCH 1/7] Revert "avcodec: remove support for old versions"
Jean-Baptiste Kempf
jb at videolan.org
Tue Mar 12 14:30:17 CET 2013
This reverts and adapts commit cde81e52f2d6e17383aced57fe6312eafa79cacf.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
---
modules/codec/avcodec/avcodec.c | 12 +++++--
modules/codec/avcodec/avcodec.h | 76 ++++++++++++++++++++++++++++++++++++++++
modules/codec/avcodec/avcommon.h | 5 +++
modules/codec/avcodec/encoder.c | 14 ++++++++
modules/codec/avcodec/fourcc.c | 18 ++++++++++
modules/codec/avcodec/subtitle.c | 4 +++
modules/codec/avcodec/video.c | 52 +++++++++++++++++++++++++--
modules/demux/avformat/demux.c | 8 +++++
modules/stream_out/switcher.c | 31 ++++++++++++++--
9 files changed, 213 insertions(+), 7 deletions(-)
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 19ba42c..f42621f 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -42,8 +42,8 @@
#include "chroma.h"
#include "avcommon.h"
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 54, 25, 0 )
-# error You must update libavcodec to a version >= 54.25.0
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
+# error You must update libavcodec to a version >= 53.34.0
#endif
/*****************************************************************************
@@ -293,7 +293,11 @@ static int OpenDecoder( vlc_object_t *p_this )
}
/* *** get a p_context *** */
+#if LIBAVCODEC_VERSION_MAJOR >= 54
p_context = avcodec_alloc_context3(p_codec);
+#else
+ p_context = avcodec_alloc_context();
+#endif
if( !p_context )
return VLC_ENOMEM;
p_context->debug = var_InheritInteger( p_dec, "avcodec-debug" );
@@ -418,7 +422,11 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
}
int ret;
vlc_avcodec_lock();
+#if LIBAVCODEC_VERSION_MAJOR >= 54
ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, NULL /* options */ );
+#else
+ ret = avcodec_open( p_sys->p_context, p_sys->p_codec );
+#endif
vlc_avcodec_unlock();
if( ret < 0 )
return VLC_EGENERIC;
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index 526fde9..3785f06 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -283,3 +283,79 @@ int ffmpeg_OpenCodec( decoder_t *p_dec );
#define LIBAVCODEC_VERSION_CHECK( a, b, c, d, e ) \
(LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \
(LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) )
+
+
+#if LIBAVCODEC_VERSION_MAJOR < 54
+# define AV_PICTURE_TYPE_B FF_B_TYPE
+# define AV_PICTURE_TYPE_I FF_I_TYPE
+# define AV_PICTURE_TYPE_P FF_P_TYPE
+
+# define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE
+# define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8
+# define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16
+# define AV_SAMPLE_FMT_S32 SAMPLE_FMT_S32
+# define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT
+# define AV_SAMPLE_FMT_DBL SAMPLE_FMT_DBL
+
+#ifndef AV_CH_FRONT_LEFT
+# define AV_CH_FRONT_LEFT CH_FRONT_LEFT
+#endif
+#ifndef AV_CH_FRONT_RIGHT
+# define AV_CH_FRONT_RIGHT CH_FRONT_RIGHT
+#endif
+#ifndef AV_CH_FRONT_CENTER
+# define AV_CH_FRONT_CENTER CH_FRONT_CENTER
+#endif
+#ifndef AV_CH_LOW_FREQUENCY
+# define AV_CH_LOW_FREQUENCY CH_LOW_FREQUENCY
+#endif
+#ifndef AV_CH_BACK_LEFT
+# define AV_CH_BACK_LEFT CH_BACK_LEFT
+#endif
+#ifndef AV_CH_BACK_RIGHT
+# define AV_CH_BACK_RIGHT CH_BACK_RIGHT
+#endif
+#ifndef AV_CH_FRONT_LEFT_OF_CENTER
+# define AV_CH_FRONT_LEFT_OF_CENTER CH_FRONT_LEFT_OF_CENTER
+#endif
+#ifndef AV_CH_FRONT_RIGHT_OF_CENTER
+# define AV_CH_FRONT_RIGHT_OF_CENTER CH_FRONT_RIGHT_OF_CENTER
+#endif
+#ifndef AV_CH_BACK_CENTER
+# define AV_CH_BACK_CENTER CH_BACK_CENTER
+#endif
+#ifndef AV_CH_SIDE_LEFT
+# define AV_CH_SIDE_LEFT CH_SIDE_LEFT
+#endif
+#ifndef AV_CH_SIDE_RIGHT
+# define AV_CH_SIDE_RIGHT CH_SIDE_RIGHT
+#endif
+#ifndef AV_CH_TOP_CENTER
+# define AV_CH_TOP_CENTER CH_TOP_CENTER
+#endif
+#ifndef AV_CH_TOP_FRONT_LEFT
+# define AV_CH_TOP_FRONT_LEFT CH_TOP_FRONT_LEFT
+#endif
+#ifndef AV_CH_TOP_FRONT_CENTER
+# define AV_CH_TOP_FRONT_CENTER CH_TOP_FRONT_CENTER
+#endif
+#ifndef AV_CH_TOP_FRONT_RIGHT
+# define AV_CH_TOP_FRONT_RIGHT CH_TOP_FRONT_RIGHT
+#endif
+#ifndef AV_CH_TOP_BACK_LEFT
+# define AV_CH_TOP_BACK_LEFT CH_TOP_BACK_LEFT
+#endif
+#ifndef AV_CH_TOP_BACK_CENTER
+# define AV_CH_TOP_BACK_CENTER CH_TOP_BACK_CENTER
+#endif
+#ifndef AV_CH_TOP_BACK_RIGHT
+# define AV_CH_TOP_BACK_RIGHT CH_TOP_BACK_RIGHT
+#endif
+#ifndef AV_CH_STEREO_LEFT
+# define AV_CH_STEREO_LEFT CH_STEREO_LEFT
+#endif
+#ifndef AV_CH_STEREO_RIGHT
+# define AV_CH_STEREO_RIGHT CH_STEREO_RIGHT
+#endif
+
+#endif /* LIBAVCODEC_VERSION_MAJOR < 54 */
diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index 86df112..057d772 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -63,7 +63,12 @@ static inline void vlc_init_avformat(void)
static inline void vlc_init_avcodec(void)
{
vlc_avcodec_lock();
+
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ avcodec_init();
+#endif
avcodec_register_all();
+
vlc_avcodec_unlock();
}
#endif
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 5490bd2..66664cf 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -304,7 +304,11 @@ int OpenEncoder( vlc_object_t *p_this )
p_sys->p_buffer = NULL;
p_sys->i_buffer_out = 0;
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ p_context = avcodec_alloc_context();
+#else
p_context = avcodec_alloc_context3(p_codec);
+#endif
p_sys->p_context = p_context;
p_sys->p_context->codec_id = p_sys->p_codec->id;
p_context->debug = var_InheritInteger( p_enc, "avcodec-debug" );
@@ -389,11 +393,13 @@ int OpenEncoder( vlc_object_t *p_this )
#endif
else if( !strncmp( psz_val, "ltp", 3 ) )
p_sys->i_aac_profile = FF_PROFILE_AAC_LTP;
+#if LIBAVCODEC_VERSION_CHECK( 54, 19, 0, 35, 100 )
/* These require libavcodec with libfdk-aac */
else if( !strncmp( psz_val, "hev2", 4 ) )
p_sys->i_aac_profile = FF_PROFILE_AAC_HE_V2;
else if( !strncmp( psz_val, "hev1", 4 ) )
p_sys->i_aac_profile = FF_PROFILE_AAC_HE;
+#endif
else
{
msg_Warn( p_enc, "unknown AAC profile requested, setting it to low" );
@@ -699,7 +705,11 @@ int OpenEncoder( vlc_object_t *p_this )
int ret;
vlc_avcodec_lock();
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ ret = avcodec_open( p_context, p_codec );
+#else
ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
+#endif
vlc_avcodec_unlock();
if( ret )
{
@@ -753,7 +763,11 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->codec = NULL;
vlc_avcodec_lock();
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ ret = avcodec_open( p_context, p_codec );
+#else
ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
+#endif
vlc_avcodec_unlock();
if( ret )
{
diff --git a/modules/codec/avcodec/fourcc.c b/modules/codec/avcodec/fourcc.c
index 78aaf54..317249c 100644
--- a/modules/codec/avcodec/fourcc.c
+++ b/modules/codec/avcodec/fourcc.c
@@ -192,19 +192,31 @@ static const struct
{ VLC_CODEC_VBLE, AV_CODEC_ID_VBLE, VIDEO_ES },
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 1, 0 )
{ VLC_CODEC_CDXL, AV_CODEC_ID_CDXL, VIDEO_ES },
+#endif
{ VLC_CODEC_UTVIDEO, AV_CODEC_ID_UTVIDEO, VIDEO_ES },
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 42, 0 )
{ VLC_CODEC_DXTORY, AV_CODEC_ID_DXTORY, VIDEO_ES },
+#endif
+#if LIBAVCODEC_VERSION_CHECK( 54, 16, 0, 27, 100 )
{ VLC_CODEC_MSS1, AV_CODEC_ID_MSS1, VIDEO_ES },
+#endif
+#if LIBAVCODEC_VERSION_CHECK( 54, 17, 0, 32, 100 )
{ VLC_CODEC_MSA1, AV_CODEC_ID_MSA1, VIDEO_ES },
+#endif
+#if LIBAVCODEC_VERSION_CHECK( 54, 18, 0, 34, 100 )
{ VLC_CODEC_TSC2, AV_CODEC_ID_TSCC2, VIDEO_ES },
+#endif
+#if LIBAVCODEC_VERSION_CHECK( 54, 20, 0, 37, 100 )
{ VLC_CODEC_MTS2, AV_CODEC_ID_MTS2, VIDEO_ES },
+#endif
#if LIBAVCODEC_VERSION_CHECK( 54, 27, 0, 55, 100 )
{ VLC_CODEC_MSS2, AV_CODEC_ID_MSS2, VIDEO_ES },
@@ -379,11 +391,17 @@ static const struct
{ VLC_CODEC_TRUEHD, AV_CODEC_ID_TRUEHD, AUDIO_ES },
{ VLC_CODEC_MLP, AV_CODEC_ID_MLP, AUDIO_ES },
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 5, 0 )
{ VLC_CODEC_WMAL, AV_CODEC_ID_WMALOSSLESS, AUDIO_ES },
+#endif
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 12, 0 )
{ VLC_CODEC_RALF, AV_CODEC_ID_RALF, AUDIO_ES },
+#endif
+#if LIBAVCODEC_VERSION_CHECK( 54, 14, 0, 26, 100 )
{ VLC_CODEC_INDEO_AUDIO, AV_CODEC_ID_IAC, AUDIO_ES },
+#endif
/* PCM */
{ VLC_CODEC_S8, AV_CODEC_ID_PCM_S8, AUDIO_ES },
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index a1543ef..d4bfdbe 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -83,7 +83,11 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
/* */
int ret;
vlc_avcodec_lock();
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ ret = avcodec_open(context, codec);
+#else
ret = avcodec_open2(context, codec, NULL /* options */);
+#endif
vlc_avcodec_unlock();
if (ret < 0) {
msg_Err(dec, "cannot open codec (%s)", namecodec);
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index ac7f51d..83d5b24 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -75,8 +75,11 @@ struct decoder_sys_t
/* */
- //AVPaletteControl palette;
-#warning FIXME
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ AVPaletteControl palette;
+#else
+# warning FIXME
+#endif
/* */
bool b_flush;
@@ -209,7 +212,11 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
/* ***** Get configuration of ffmpeg plugin ***** */
p_sys->p_context->workaround_bugs =
var_InheritInteger( p_dec, "avcodec-workaround-bugs" );
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ p_sys->p_context->error_recognition =
+#else
p_sys->p_context->err_recognition =
+#endif
var_InheritInteger( p_dec, "avcodec-error-resilience" );
if( var_CreateGetBool( p_dec, "grayscale" ) )
@@ -376,8 +383,39 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
}
p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma;
+#if LIBAVCODEC_VERSION_MAJOR < 54
/* Setup palette */
-# warning FIXME: palette
+ memset( &p_sys->palette, 0, sizeof(p_sys->palette) );
+ if( p_dec->fmt_in.video.p_palette )
+ {
+ p_sys->palette.palette_changed = 1;
+
+ for( int i = 0; i < __MIN( AVPALETTE_COUNT, p_dec->fmt_in.video.p_palette->i_entries ); i++ )
+ {
+ union {
+ uint32_t u;
+ uint8_t a[4];
+ } c;
+ c.a[0] = p_dec->fmt_in.video.p_palette->palette[i][0];
+ c.a[1] = p_dec->fmt_in.video.p_palette->palette[i][1];
+ c.a[2] = p_dec->fmt_in.video.p_palette->palette[i][2];
+ c.a[3] = p_dec->fmt_in.video.p_palette->palette[i][3];
+
+ p_sys->palette.palette[i] = c.u;
+ }
+ p_sys->p_context->palctrl = &p_sys->palette;
+
+ p_dec->fmt_out.video.p_palette = malloc( sizeof(video_palette_t) );
+ if( p_dec->fmt_out.video.p_palette )
+ *p_dec->fmt_out.video.p_palette = *p_dec->fmt_in.video.p_palette;
+ }
+ else if( p_sys->i_codec_id != CODEC_ID_MSVIDEO1 && p_sys->i_codec_id != CODEC_ID_CINEPAK )
+ {
+ p_sys->p_context->palctrl = &p_sys->palette;
+ }
+#else
+# warning FIXME
+#endif
/* ***** init this codec with special data ***** */
ffmpeg_InitCodec( p_dec );
@@ -912,6 +950,10 @@ static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
/* */
p_ff_pic->type = FF_BUFFER_TYPE_USER;
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ p_ff_pic->age = 256*256*256*64;
+#endif
+
if( vlc_va_Get( p_sys->p_va, p_ff_pic ) )
{
msg_Err( p_dec, "VaGrabSurface failed" );
@@ -1000,6 +1042,10 @@ static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
p_ff_pic->linesize[2] = p_pic->p[2].i_pitch;
p_ff_pic->linesize[3] = 0;
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ p_ff_pic->age = 256*256*256*64;
+#endif
+
post_mt( p_sys );
return 0;
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 00e826b..da81d59 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -325,7 +325,15 @@ int OpenDemux( vlc_object_t *p_this )
fmt.video.i_width = cc->width;
fmt.video.i_height = cc->height;
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ if( cc->palctrl )
+ {
+ fmt.video.p_palette = malloc( sizeof(video_palette_t) );
+ *fmt.video.p_palette = *(video_palette_t *)cc->palctrl;
+ }
+#else
# warning FIXME: implement palette transmission
+#endif
psz_type = "video";
fmt.video.i_frame_rate = cc->time_base.den;
fmt.video.i_frame_rate_base = cc->time_base.num * __MAX( cc->ticks_per_frame, 1 );
diff --git a/modules/stream_out/switcher.c b/modules/stream_out/switcher.c
index 1f957a9..b7e34cb 100644
--- a/modules/stream_out/switcher.c
+++ b/modules/stream_out/switcher.c
@@ -131,8 +131,10 @@ vlc_module_begin ()
QSCALE_TEXT, QSCALE_LONGTEXT, true )
add_bool( SOUT_CFG_PREFIX "mute-audio", true,
AUDIO_TEXT, AUDIO_LONGTEXT, true )
+#if LIBAVCODEC_VERSION_MAJOR >= 54
add_string( SOUT_CFG_PREFIX "options", NULL,
AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
+#endif
vlc_module_end ()
static const char *const ppsz_sout_options[] = {
@@ -156,7 +158,9 @@ struct sout_stream_sys_t
int i_fd;
int i_cmd, i_old_cmd;
+#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary *options;
+#endif
};
struct sout_stream_id_t
@@ -293,6 +297,7 @@ static int Open( vlc_object_t *p_this )
p_stream->pf_send = Send;
p_stream->p_sys = p_sys;
+#if LIBAVCODEC_VERSION_MAJOR >= 54
char *psz_opts = var_InheritString( p_stream, SOUT_CFG_PREFIX "options" );
if (psz_opts && *psz_opts) {
p_sys->options = vlc_av_get_options(psz_opts);
@@ -300,6 +305,7 @@ static int Open( vlc_object_t *p_this )
p_sys->options = NULL;
}
free(psz_opts);
+#endif
return VLC_SUCCESS;
}
@@ -312,7 +318,10 @@ static void Close( vlc_object_t * p_this )
sout_stream_t *p_stream = (sout_stream_t *)p_this;
sout_stream_sys_t *p_sys = p_stream->p_sys;
+#if LIBAVCODEC_VERSION_MAJOR >= 54
av_dict_free( &p_sys->options );
+#endif
+
free( p_sys );
}
@@ -362,7 +371,11 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
return NULL;
}
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ id->ff_enc_c = avcodec_alloc_context();
+#else
id->ff_enc_c = avcodec_alloc_context3( id->ff_enc );
+#endif
id->ff_enc_c->dsp_mask = GetVlcDspMask();
id->ff_enc_c->sample_rate = p_fmt->audio.i_rate;
id->ff_enc_c->time_base.num = 1;
@@ -371,6 +384,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id->ff_enc_c->bit_rate = p_fmt->i_bitrate;
int ret;
+#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary *options = NULL;
if (p_sys->options)
av_dict_copy(&options, p_sys->options, 0);
@@ -382,6 +396,11 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
msg_Err( p_stream, "Unknown option \"%s\"", t->key );
}
av_dict_free(&options);
+#else
+ vlc_avcodec_lock();
+ ret = avcodec_open( id->ff_enc_c, id->ff_enc );
+ vlc_avcodec_unlock();
+#endif
if (ret)
{
@@ -741,7 +760,11 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
return 0;
}
+#if LIBAVCODEC_VERSION_MAJOR < 54
+ id->ff_enc_c = avcodec_alloc_context();
+#else
id->ff_enc_c = avcodec_alloc_context3( id->ff_enc );
+#endif
id->ff_enc_c->dsp_mask = GetVlcDspMask();
id->ff_enc_c->width = p_sys->p_pictures[p_sys->i_cmd-1].format.i_width;
id->ff_enc_c->height = p_sys->p_pictures[p_sys->i_cmd-1].format.i_height;
@@ -768,18 +791,22 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
vlc_avcodec_lock();
int ret;
+#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary *options = NULL;
if (p_sys->options)
av_dict_copy(&options, p_sys->options, 0);
ret = avcodec_open2( id->ff_enc_c, id->ff_enc, options ? &options : NULL );
+#else
+ ret = avcodec_open( id->ff_enc_c, id->ff_enc );
+#endif
vlc_avcodec_unlock();
-
+#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionaryEntry *t = NULL;
while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
msg_Err( p_stream, "Unknown option \"%s\"", t->key );
}
av_dict_free(&options);
-
+#endif
if (ret)
{
msg_Err( p_stream, "cannot open encoder" );
--
1.8.1.5
More information about the vlc-devel
mailing list