[vlc-devel] [PATCH 02/15] avcodec: update to libavcodec 54 (cherry picked from commit 8f24e725ff9945975f6d7232477cff7f7a8e2cff)

KO Myung-Hun komh78 at gmail.com
Fri Mar 2 16:02:59 CET 2012


From: Rafaël Carré <funman at videolan.org>

Signed-off-by: KO Myung-Hun <komh at chollian.net>
---
 modules/codec/avcodec/audio.c    |   52 +++++++++++++++++++------------------
 modules/codec/avcodec/avcodec.c  |   10 +++++++
 modules/codec/avcodec/avcodec.h  |   36 ++++++++++++++++++++++++++
 modules/codec/avcodec/encoder.c  |   30 ++++++++++++++++------
 modules/codec/avcodec/subtitle.c |    8 +++++-
 modules/codec/avcodec/video.c    |   29 +++++++++++++++------
 6 files changed, 123 insertions(+), 42 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 33e7418..548ff3c 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -41,6 +41,8 @@
 #   include <avcodec.h>
 #endif
 
+#include "libavutil/audioconvert.h"
+
 #include "avcodec.h"
 
 /*****************************************************************************
@@ -415,24 +417,24 @@ void GetVlcAudioFormat( vlc_fourcc_t *pi_codec, unsigned *pi_bits, int i_sample_
 {
     switch( i_sample_fmt )
     {
-    case SAMPLE_FMT_U8:
+    case AV_SAMPLE_FMT_U8:
         *pi_codec = VLC_CODEC_U8;
         *pi_bits = 8;
         break;
-    case SAMPLE_FMT_S32:
+    case AV_SAMPLE_FMT_S32:
         *pi_codec = VLC_CODEC_S32N;
         *pi_bits = 32;
         break;
-    case SAMPLE_FMT_FLT:
+    case AV_SAMPLE_FMT_FLT:
         *pi_codec = VLC_CODEC_FL32;
         *pi_bits = 32;
         break;
-    case SAMPLE_FMT_DBL:
+    case AV_SAMPLE_FMT_DBL:
         *pi_codec = VLC_CODEC_FL64;
         *pi_bits = 64;
         break;
 
-    case SAMPLE_FMT_S16:
+    case AV_SAMPLE_FMT_S16:
     default:
         *pi_codec = VLC_CODEC_S16N;
         *pi_bits = 16;
@@ -442,26 +444,26 @@ void GetVlcAudioFormat( vlc_fourcc_t *pi_codec, unsigned *pi_bits, int i_sample_
 
 static const uint64_t pi_channels_map[][2] =
 {
-    { CH_FRONT_LEFT,        AOUT_CHAN_LEFT },
-    { CH_FRONT_RIGHT,       AOUT_CHAN_RIGHT },
-    { CH_FRONT_CENTER,      AOUT_CHAN_CENTER },
-    { CH_LOW_FREQUENCY,     AOUT_CHAN_LFE },
-    { CH_BACK_LEFT,         AOUT_CHAN_REARLEFT },
-    { CH_BACK_RIGHT,        AOUT_CHAN_REARRIGHT },
-    { CH_FRONT_LEFT_OF_CENTER, 0 },
-    { CH_FRONT_RIGHT_OF_CENTER, 0 },
-    { CH_BACK_CENTER,       AOUT_CHAN_REARCENTER },
-    { CH_SIDE_LEFT,         AOUT_CHAN_MIDDLELEFT },
-    { CH_SIDE_RIGHT,        AOUT_CHAN_MIDDLERIGHT },
-    { CH_TOP_CENTER,        0 },
-    { CH_TOP_FRONT_LEFT,    0 },
-    { CH_TOP_FRONT_CENTER,  0 },
-    { CH_TOP_FRONT_RIGHT,   0 },
-    { CH_TOP_BACK_LEFT,     0 },
-    { CH_TOP_BACK_CENTER,   0 },
-    { CH_TOP_BACK_RIGHT,    0 },
-    { CH_STEREO_LEFT,       0 },
-    { CH_STEREO_RIGHT,      0 },
+    { AV_CH_FRONT_LEFT,        AOUT_CHAN_LEFT },
+    { AV_CH_FRONT_RIGHT,       AOUT_CHAN_RIGHT },
+    { AV_CH_FRONT_CENTER,      AOUT_CHAN_CENTER },
+    { AV_CH_LOW_FREQUENCY,     AOUT_CHAN_LFE },
+    { AV_CH_BACK_LEFT,         AOUT_CHAN_REARLEFT },
+    { AV_CH_BACK_RIGHT,        AOUT_CHAN_REARRIGHT },
+    { AV_CH_FRONT_LEFT_OF_CENTER, 0 },
+    { AV_CH_FRONT_RIGHT_OF_CENTER, 0 },
+    { AV_CH_BACK_CENTER,       AOUT_CHAN_REARCENTER },
+    { AV_CH_SIDE_LEFT,         AOUT_CHAN_MIDDLELEFT },
+    { AV_CH_SIDE_RIGHT,        AOUT_CHAN_MIDDLERIGHT },
+    { AV_CH_TOP_CENTER,        0 },
+    { AV_CH_TOP_FRONT_LEFT,    0 },
+    { AV_CH_TOP_FRONT_CENTER,  0 },
+    { AV_CH_TOP_FRONT_RIGHT,   0 },
+    { AV_CH_TOP_BACK_LEFT,     0 },
+    { AV_CH_TOP_BACK_CENTER,   0 },
+    { AV_CH_TOP_BACK_RIGHT,    0 },
+    { AV_CH_STEREO_LEFT,       0 },
+    { AV_CH_STEREO_RIGHT,      0 },
 };
 
 static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 513e17a..c9f9b1e 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -263,7 +263,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, "ffmpeg-debug" );
@@ -391,7 +395,9 @@ void InitLibavcodec( vlc_object_t *p_object )
     /* *** init ffmpeg library (libavcodec) *** */
     if( !b_ffmpeginit )
     {
+#if LIBAVCODEC_VERSION_MAJOR < 54
         avcodec_init();
+#endif
         avcodec_register_all();
         av_log_set_callback( LibavutilCallback );
         b_ffmpeginit = true;
@@ -443,7 +449,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 614afa5..07381c6 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -309,6 +309,42 @@ int ffmpeg_OpenCodec( decoder_t *p_dec );
 #   define AVMEDIA_TYPE_ATTACHMENT CODEC_TYPE_ATTACHMENT
 #endif
 
+#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 SAMPLE_FMT_NONE          AV_SAMPLE_FMT_NONE
+#   define SAMPLE_FMT_U8            AV_SAMPLE_FMT_U8
+#   define SAMPLE_FMT_S16           AV_SAMPLE_FMT_S16
+#   define SAMPLE_FMT_S32           AV_SAMPLE_FMT_S32
+#   define SAMPLE_FMT_FLT           AV_SAMPLE_FMT_FLT
+#   define SAMPLE_FMT_DBL           AV_SAMPLE_FMT_DBL
+
+#   define CH_FRONT_LEFT            AV_CH_FRONT_LEFT
+#   define CH_FRONT_RIGHT           AV_CH_FRONT_RIGHT
+#   define CH_FRONT_CENTER          AV_CH_FRONT_CENTER
+#   define CH_LOW_FREQUENCY         AV_CH_LOW_FREQUENCY
+#   define CH_BACK_LEFT             AV_CH_BACK_LEFT
+#   define CH_BACK_RIGHT            AV_CH_BACK_RIGHT
+#   define CH_FRONT_LEFT_OF_CENTER  AV_CH_FRONT_LEFT_OF_CENTER
+#   define CH_FRONT_RIGHT_OF_CENTER AV_CH_FRONT_RIGHT_OF_CENTER
+#   define CH_BACK_CENTER           AV_CH_BACK_CENTER
+#   define CH_SIDE_LEFT             AV_CH_SIDE_LEFT
+#   define CH_SIDE_RIGHT            AV_CH_SIDE_RIGHT
+#   define CH_TOP_CENTER            AV_CH_TOP_CENTER
+#   define CH_TOP_FRONT_LEFT        AV_CH_TOP_FRONT_LEFT
+#   define CH_TOP_FRONT_CENTER      AV_CH_TOP_FRONT_CENTER
+#   define CH_TOP_FRONT_RIGHT       AV_CH_TOP_FRONT_RIGHT
+#   define CH_TOP_BACK_LEFT         AV_CH_TOP_BACK_LEFT
+#   define CH_TOP_BACK_CENTER       AV_CH_TOP_BACK_CENTER
+#   define CH_TOP_BACK_RIGHT        AV_CH_TOP_BACK_RIGHT
+#   define CH_STEREO_LEFT           AV_CH_STEREO_LEFT
+#   define CH_STEREO_RIGHT          AV_CH_STEREO_RIGHT
+
+
+#endif
+
 #ifndef AV_PKT_FLAG_KEY
 #   define AV_PKT_FLAG_KEY         PKT_FLAG_KEY
 #endif
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index a9248e7..a992e90 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -304,7 +304,12 @@ int OpenEncoder( vlc_object_t *p_this )
     p_sys->p_buffer_out = NULL;
     p_sys->i_buffer_out = 0;
 
-    p_sys->p_context = p_context = avcodec_alloc_context();
+#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, "ffmpeg-debug" );
     p_context->opaque = (void *)p_this;
@@ -602,7 +607,7 @@ int OpenEncoder( vlc_object_t *p_this )
         p_context->codec_type  = AVMEDIA_TYPE_AUDIO;
         p_context->sample_fmt  = p_codec->sample_fmts ?
                                     p_codec->sample_fmts[0] :
-                                    SAMPLE_FMT_S16;
+                                    AV_SAMPLE_FMT_S16;
         p_enc->fmt_in.i_codec  = VLC_CODEC_S16N;
         p_context->sample_rate = p_enc->fmt_out.audio.i_rate;
         p_context->time_base.num = 1;
@@ -692,7 +697,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 )
     {
@@ -746,7 +755,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 )
             {
@@ -927,7 +940,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
 
                 if ( current_date + HURRY_UP_GUARD1 > frame.pts )
                 {
-                    frame.pict_type = FF_P_TYPE;
+                    frame.pict_type = AV_PICTURE_TYPE_P;
                     /* msg_Dbg( p_enc, "hurry up mode 1 %lld", current_date + HURRY_UP_GUARD1 - frame.pts ); */
                 }
             }
@@ -1013,8 +1026,8 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
         }
         /* End work-around */
 
-        if( p_sys->p_context->coded_frame->pict_type != FF_I_TYPE &&
-            p_sys->p_context->coded_frame->pict_type != FF_P_TYPE )
+        if( p_sys->p_context->coded_frame->pict_type != AV_PICTURE_TYPE_I &&
+            p_sys->p_context->coded_frame->pict_type != AV_PICTURE_TYPE_P )
         {
             p_block->i_dts = p_block->i_pts;
         }
@@ -1042,15 +1055,16 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
 
     switch ( p_sys->p_context->coded_frame->pict_type )
     {
-    case FF_I_TYPE:
+    case AV_PICTURE_TYPE_I:
         p_block->i_flags |= BLOCK_FLAG_TYPE_I;
         break;
-    case FF_P_TYPE:
+    case AV_PICTURE_TYPE_P:
         p_block->i_flags |= BLOCK_FLAG_TYPE_P;
         break;
-    case FF_B_TYPE:
+    case AV_PICTURE_TYPE_B:
         p_block->i_flags |= BLOCK_FLAG_TYPE_B;
         break;
+
     }
 
     return p_block;
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index c9ccce6..f3a72e0 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -90,8 +90,14 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
     context->extradata = NULL;
 
     /* */
+    int ret;
     vlc_avcodec_lock();
-    if (avcodec_open(context, codec) < 0) {
+#if LIBAVCODEC_VERSION_MAJOR < 54
+    ret = avcodec_open(context, codec);
+#else
+    ret = avcodec_open2(context, codec, NULL /* options */);
+#endif
+    if (ret < 0) {
         vlc_avcodec_unlock();
         msg_Err(dec, "cannot open codec (%s)", namecodec);
         free(context->extradata);
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 69ab06e..7332bf0 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -94,8 +94,13 @@ struct decoder_sys_t
     /* Hack to force display of still pictures */
     bool b_first_frame;
 
+
     /* */
+#if LIBAVCODEC_VERSION_MAJOR < 54
     AVPaletteControl palette;
+#else
+# warning FIXME
+#endif
 
     /* */
     bool b_flush;
@@ -114,9 +119,6 @@ struct decoder_sys_t
 #   define post_mt(s)
 #endif
 
-/* FIXME (dummy palette for now) */
-static const AVPaletteControl palette_control;
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -233,8 +235,12 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     /*  ***** Get configuration of ffmpeg plugin ***** */
     p_sys->p_context->workaround_bugs =
         var_InheritInteger( p_dec, "ffmpeg-workaround-bugs" );
+#if LIBAVCODEC_VERSION_MAJOR < 54
     p_sys->p_context->error_recognition =
         var_InheritInteger( p_dec, "ffmpeg-error-resilience" );
+#else
+# warning FIXME (moved to AVFormat)
+#endif
 
     if( var_CreateGetBool( p_dec, "grayscale" ) )
         p_sys->p_context->flags |= CODEC_FLAG_GRAY;
@@ -404,6 +410,7 @@ 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 */
     memset( &p_sys->palette, 0, sizeof(p_sys->palette) );
     if( p_dec->fmt_in.video.p_palette )
@@ -433,6 +440,9 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     {
         p_sys->p_context->palctrl = &p_sys->palette;
     }
+#else
+# warning FIXME
+#endif
 
     /* ***** init this codec with special data ***** */
     ffmpeg_InitCodec( p_dec );
@@ -654,7 +664,7 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         }
 
         /* Sanity check (seems to be needed for some streams) */
-        if( p_sys->p_ff_pic->pict_type == FF_B_TYPE )
+        if( p_sys->p_ff_pic->pict_type == AV_PICTURE_TYPE_B)
         {
             p_sys->b_has_b_frames = true;
         }
@@ -987,8 +997,10 @@ static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
 
         /* */
         p_ff_pic->type = FF_BUFFER_TYPE_USER;
-        /* FIXME what is that, should give good value */
-        p_ff_pic->age = 256*256*256*64; // FIXME FIXME from ffmpeg
+
+#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 ) )
         {
@@ -1078,8 +1090,9 @@ 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;
 
-    /* FIXME what is that, should give good value */
-    p_ff_pic->age = 256*256*256*64; // FIXME FIXME from ffmpeg
+#if LIBAVCODEC_VERSION_MAJOR < 54
+    p_ff_pic->age = 256*256*256*64;
+#endif
 
     post_mt( p_sys );
     return 0;
-- 
1.7.3.2




More information about the vlc-devel mailing list