Commit 8f24e725 authored by Rafaël Carré's avatar Rafaël Carré

avcodec: update to libavcodec 54

parent 4c3037ac
......@@ -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 )
......
......@@ -262,7 +262,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" );
......@@ -390,7 +394,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;
......@@ -442,7 +448,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;
......
......@@ -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
......@@ -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;
......@@ -604,7 +609,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;
......@@ -694,7 +699,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 )
{
......@@ -748,7 +757,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 )
{
......@@ -929,7 +942,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 ); */
}
}
......@@ -1015,8 +1028,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;
}
......@@ -1044,15 +1057,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;
......
......@@ -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);
......
......@@ -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;
......@@ -400,6 +406,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 )
......@@ -429,6 +436,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 );
......@@ -650,7 +660,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;
}
......@@ -983,8 +993,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 ) )
{
......@@ -1074,8 +1086,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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment