Commit 56888ce8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

libavcodec: require version 55 "The Evil Plan"

parent a3ce78af
......@@ -2277,7 +2277,7 @@ dnl
AC_ARG_ENABLE(avcodec,
[ --enable-avcodec libavcodec codec (default enabled)])
AS_IF([test "${enable_avcodec}" != "no"], [
PKG_CHECK_MODULES(AVCODEC,[libavcodec >= 54.25.0 libavutil >= 52.0.0], [
PKG_CHECK_MODULES(AVCODEC,[libavcodec >= 55.0.0 libavutil >= 52.0.0], [
dnl PKG_CHECK_EXISTS([libavcodec < 56],, [
dnl AC_MSG_ERROR([libavcodec versions 56 and later are not supported yet.])
dnl ])
......
......@@ -151,7 +151,6 @@ static int OpenAudioCodec( decoder_t *p_dec )
/**
* Allocates decoded audio buffer for libavcodec to use.
*/
#if (LIBAVCODEC_VERSION_MAJOR >= 55)
typedef struct
{
block_t self;
......@@ -186,49 +185,6 @@ static block_t *vlc_av_frame_Wrap(AVFrame *frame)
b->frame = frame;
return block;
}
#else
static int GetAudioBuf( AVCodecContext *ctx, AVFrame *buf )
{
block_t *block;
bool planar = av_sample_fmt_is_planar( ctx->sample_fmt );
unsigned channels = planar ? 1 : ctx->channels;
unsigned planes = planar ? ctx->channels : 1;
int bytes = av_samples_get_buffer_size( &buf->linesize[0], channels,
buf->nb_samples, ctx->sample_fmt,
16 );
assert( bytes >= 0 );
block = block_Alloc( bytes * planes );
if( unlikely(block == NULL) )
return AVERROR(ENOMEM);
block->i_nb_samples = buf->nb_samples;
buf->opaque = block;
if( planes > AV_NUM_DATA_POINTERS )
{
uint8_t **ext = malloc( sizeof( *ext ) * planes );
if( unlikely(ext == NULL) )
{
block_Release( block );
return AVERROR(ENOMEM);
}
buf->extended_data = ext;
}
else
buf->extended_data = buf->data;
uint8_t *buffer = block->p_buffer;
for( unsigned i = 0; i < planes; i++ )
{
buf->linesize[i] = buf->linesize[0];
buf->extended_data[i] = buffer;
buffer += bytes;
}
return 0;
}
#endif
/*****************************************************************************
* InitAudioDec: initialize audio decoder
......@@ -246,11 +202,7 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
return VLC_ENOMEM;
}
#if (LIBAVCODEC_VERSION_MAJOR >= 55)
p_context->refcounted_frames = true;
#else
p_context->get_buffer = GetAudioBuf;
#endif
p_sys->p_context = p_context;
p_sys->p_codec = p_codec;
p_sys->b_delayed_open = true;
......@@ -338,13 +290,9 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
p_block->i_flags |= BLOCK_FLAG_PRIVATE_REALLOCATED;
}
#if (LIBAVCODEC_VERSION_MAJOR >= 55)
AVFrame *frame = av_frame_alloc();
if (unlikely(frame == NULL))
goto end;
#else
AVFrame *frame = &(AVFrame) { };
#endif
for( int got_frame = 0; !got_frame; )
{
......@@ -391,17 +339,13 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
*pp_block = NULL;
}
#if (LIBAVCODEC_VERSION_MAJOR < 55)
/* NOTE WELL: Beyond this point, p_block refers to the DECODED block! */
p_block = frame->opaque;
#endif
SetupOutputFormat( p_dec, true );
if( decoder_UpdateAudioFormat( p_dec ) )
goto drop;
/* Interleave audio if required */
if( av_sample_fmt_is_planar( ctx->sample_fmt ) )
#if (LIBAVCODEC_VERSION_MAJOR >= 55)
{
p_block = block_Alloc(frame->linesize[0] * ctx->channels);
if (unlikely(p_block == NULL))
......@@ -422,25 +366,6 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
if (unlikely(p_block == NULL))
goto drop;
}
#else
{
block_t *p_buffer = block_Alloc( p_block->i_buffer );
if( unlikely(p_buffer == NULL) )
goto drop;
const void *planes[ctx->channels];
for( int i = 0; i < ctx->channels; i++)
planes[i] = frame->extended_data[i];
aout_Interleave( p_buffer->p_buffer, planes, frame->nb_samples,
ctx->channels, p_dec->fmt_out.audio.i_format );
if( ctx->channels > AV_NUM_DATA_POINTERS )
free( frame->extended_data );
block_Release( p_block );
p_block = p_buffer;
}
p_block->i_nb_samples = frame->nb_samples;
#endif
if (p_sys->b_extract)
{ /* TODO: do not drop channels... at least not here */
......
......@@ -147,9 +147,6 @@ struct encoder_sys_t
bool b_trellis;
int i_quality; /* for VBR */
float f_lumi_masking, f_dark_masking, f_p_masking, f_border_masking;
#if (LIBAVCODEC_VERSION_MAJOR < 55)
int i_luma_elim, i_chroma_elim;
#endif
int i_aac_profile; /* AAC profile to use.*/
AVFrame *frame;
......@@ -200,9 +197,6 @@ static const char *const ppsz_enc_options[] = {
"interlace", "interlace-me", "i-quant-factor", "noise-reduction", "mpeg4-matrix",
"trellis", "qscale", "strict", "lumi-masking", "dark-masking",
"p-masking", "border-masking",
#if (LIBAVCODEC_VERSION_MAJOR < 55)
"luma-elim-threshold", "chroma-elim-threshold",
#endif
"aac-profile", "options",
NULL
};
......@@ -421,10 +415,6 @@ int OpenEncoder( vlc_object_t *p_this )
p_sys->f_dark_masking = var_GetFloat( p_enc, ENC_CFG_PREFIX "dark-masking" );
p_sys->f_p_masking = var_GetFloat( p_enc, ENC_CFG_PREFIX "p-masking" );
p_sys->f_border_masking = var_GetFloat( p_enc, ENC_CFG_PREFIX "border-masking" );
#if (LIBAVCODEC_VERSION_MAJOR < 55)
p_sys->i_luma_elim = var_GetInteger( p_enc, ENC_CFG_PREFIX "luma-elim-threshold" );
p_sys->i_chroma_elim = var_GetInteger( p_enc, ENC_CFG_PREFIX "chroma-elim-threshold" );
#endif
psz_val = var_GetString( p_enc, ENC_CFG_PREFIX "aac-profile" );
/* libavcodec uses faac encoder atm, and it has issues with
......@@ -440,7 +430,6 @@ int OpenEncoder( vlc_object_t *p_this )
p_sys->i_aac_profile = FF_PROFILE_AAC_SSR;
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;
......@@ -450,7 +439,6 @@ int OpenEncoder( vlc_object_t *p_this )
p_sys->i_aac_profile = FF_PROFILE_AAC_LD;
else if( !strncmp( psz_val, "eld", 3 ) )
p_sys->i_aac_profile = FF_PROFILE_AAC_ELD;
#endif
else
{
msg_Warn( p_enc, "unknown AAC profile requested, setting it to low" );
......@@ -504,10 +492,6 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->dark_masking = p_sys->f_dark_masking;
p_context->p_masking = p_sys->f_p_masking;
p_context->border_masking = p_sys->f_border_masking;
#if (LIBAVCODEC_VERSION_MAJOR < 55)
p_context->luma_elim_threshold = p_sys->i_luma_elim;
p_context->chroma_elim_threshold = p_sys->i_chroma_elim;
#endif
if( p_sys->i_key_int > 0 )
p_context->gop_size = p_sys->i_key_int;
......@@ -1408,12 +1392,7 @@ void CloseEncoder( vlc_object_t *p_this )
encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0))
avcodec_free_frame( &p_sys->frame );
#else
av_free( p_sys->frame );
p_sys->frame = NULL;
#endif
vlc_avcodec_lock();
avcodec_close( p_sys->p_context );
......
......@@ -218,27 +218,13 @@ static const struct
{ VLC_CODEC_CDXL, AV_CODEC_ID_CDXL, VIDEO_ES },
/* AV_CODEC_ID_XBM */
/* AV_CODEC_ID_ZEROCODEC */
#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, 24, 0, 47, 100 )
{ VLC_CODEC_CLLC, AV_CODEC_ID_CLLC, VIDEO_ES },
#endif
#if LIBAVCODEC_VERSION_CHECK( 54, 27, 0, 55, 100 )
{ VLC_CODEC_MSS2, AV_CODEC_ID_MSS2, VIDEO_ES },
#endif
#if LIBAVCODEC_VERSION_CHECK( 54, 41, 0, 89, 100 )
{ VLC_CODEC_VP9, AV_CODEC_ID_VP9, VIDEO_ES },
#endif
#if LIBAVCODEC_VERSION_CHECK( 55, 5, 0, 10, 100 )
{ VLC_CODEC_ICOD, AV_CODEC_ID_AIC, VIDEO_ES },
#endif
......@@ -449,17 +435,11 @@ static const struct
/* AV_CODEC_ID_8SVX_FIB */
{ VLC_CODEC_BMVAUDIO, AV_CODEC_ID_BMV_AUDIO, AUDIO_ES },
{ VLC_CODEC_RALF, AV_CODEC_ID_RALF, AUDIO_ES },
#if LIBAVCODEC_VERSION_CHECK( 54, 14, 0, 26, 100 )
{ VLC_CODEC_INDEO_AUDIO, AV_CODEC_ID_IAC, AUDIO_ES },
#endif
/* AV_CODEC_ID_ILBC */
#if LIBAVCODEC_VERSION_CHECK( 54, 29, 0, 17, 101 )
{ VLC_CODEC_OPUS, AV_CODEC_ID_OPUS, AUDIO_ES },
#endif
/* AV_CODEC_ID_COMFORT_NOISE */
#if LIBAVCODEC_VERSION_CHECK( 54, 34, 0, 65, 100 )
{ VLC_CODEC_TAK, AV_CODEC_ID_TAK, AUDIO_ES },
#endif
#if LIBAVCODEC_VERSION_CHECK( 55, 15, 0, 24, 100 )
{ VLC_CODEC_METASOUND, AV_CODEC_ID_METASOUND, AUDIO_ES },
#endif
......
......@@ -96,12 +96,7 @@ struct decoder_sys_t
* Local prototypes
*****************************************************************************/
static void ffmpeg_InitCodec ( decoder_t * );
#if LIBAVCODEC_VERSION_MAJOR >= 55
static int lavc_GetFrame(struct AVCodecContext *, AVFrame *, int);
#else
static int ffmpeg_GetFrameBuf ( struct AVCodecContext *, AVFrame * );
static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *, AVFrame * );
#endif
static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *,
const enum PixelFormat * );
static picture_t *DecodeVideo( decoder_t *, block_t ** );
......@@ -351,9 +346,7 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
p_context->flags |= CODEC_FLAG_GRAY;
/* ***** Output always the frames ***** */
#if LIBAVCODEC_VERSION_CHECK(55, 23, 1, 40, 101)
p_context->flags |= CODEC_FLAG_OUTPUT_CORRUPT;
#endif
i_val = var_CreateGetInteger( p_dec, "avcodec-skiploopfilter" );
if( i_val >= 4 ) p_context->skip_loop_filter = AVDISCARD_ALL;
......@@ -414,13 +407,7 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
p_context->get_format = ffmpeg_GetFormat;
/* Always use our get_buffer wrapper so we can calculate the
* PTS correctly */
#if LIBAVCODEC_VERSION_MAJOR >= 55
p_context->get_buffer2 = lavc_GetFrame;
#else
p_context->get_buffer = ffmpeg_GetFrameBuf;
p_context->reget_buffer = avcodec_default_reget_buffer;
p_context->release_buffer = ffmpeg_ReleaseFrameBuf;
#endif
p_context->opaque = p_dec;
#ifdef HAVE_AVCODEC_MT
......@@ -962,7 +949,6 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
}
}
#if LIBAVCODEC_VERSION_MAJOR >= 55
static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
int flags)
{
......@@ -1142,172 +1128,6 @@ static int lavc_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, int flags)
}
return 0;
}
#else
static int ffmpeg_va_GetFrameBuf( struct AVCodecContext *p_context, AVFrame *p_ff_pic )
{
decoder_t *p_dec = (decoder_t *)p_context->opaque;
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_va_t *p_va = p_sys->p_va;
/* hwaccel_context is not present in old ffmpeg version */
if( vlc_va_Setup( p_va, p_context, &p_dec->fmt_out.video.i_chroma ) )
{
msg_Err( p_dec, "vlc_va_Setup failed" );
return -1;
}
if( vlc_va_Get( p_va, &p_ff_pic->opaque, &p_ff_pic->data[0] ) )
{
msg_Err( p_dec, "vlc_va_Get failed" );
return -1;
}
p_ff_pic->data[3] = p_ff_pic->data[0];
p_ff_pic->type = FF_BUFFER_TYPE_USER;
return 0;
}
static picture_t *ffmpeg_dr_GetFrameBuf(struct AVCodecContext *p_context)
{
decoder_t *p_dec = (decoder_t *)p_context->opaque;
int i_width = p_context->width;
int i_height = p_context->height;
avcodec_align_dimensions( p_context, &i_width, &i_height );
picture_t *p_pic = NULL;
if (GetVlcChroma(&p_dec->fmt_out.video, p_context->pix_fmt) != VLC_SUCCESS)
goto no_dr;
if (p_context->pix_fmt == PIX_FMT_PAL8)
goto no_dr;
p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma;
p_pic = ffmpeg_NewPictBuf( p_dec, p_context );
if( !p_pic )
goto no_dr;
if( p_pic->p[0].i_pitch / p_pic->p[0].i_pixel_pitch < i_width ||
p_pic->p[0].i_lines < i_height )
goto no_dr;
for( int i = 0; i < p_pic->i_planes; i++ )
{
unsigned i_align;
switch( p_context->codec_id )
{
case AV_CODEC_ID_SVQ1:
case AV_CODEC_ID_VP5:
case AV_CODEC_ID_VP6:
case AV_CODEC_ID_VP6F:
case AV_CODEC_ID_VP6A:
i_align = 16;
break;
default:
i_align = i == 0 ? 16 : 8;
break;
}
if( p_pic->p[i].i_pitch % i_align )
goto no_dr;
if( (intptr_t)p_pic->p[i].p_pixels % i_align )
goto no_dr;
}
if( p_context->pix_fmt == PIX_FMT_YUV422P )
{
if( 2 * p_pic->p[1].i_pitch != p_pic->p[0].i_pitch ||
2 * p_pic->p[2].i_pitch != p_pic->p[0].i_pitch )
goto no_dr;
}
return p_pic;
no_dr:
if (p_pic)
picture_Release( p_pic );
return NULL;
}
static int ffmpeg_GetFrameBuf( struct AVCodecContext *p_context,
AVFrame *p_ff_pic )
{
decoder_t *p_dec = (decoder_t *)p_context->opaque;
decoder_sys_t *p_sys = p_dec->p_sys;
/* */
p_ff_pic->opaque = NULL;
#if ! LIBAVCODEC_VERSION_CHECK(54, 34, 0, 79, 101)
p_ff_pic->pkt_pts = p_context->pkt ? p_context->pkt->pts : AV_NOPTS_VALUE;
#endif
if( p_sys->p_va )
return ffmpeg_va_GetFrameBuf(p_context, p_ff_pic);
if( !p_sys->b_direct_rendering )
return avcodec_default_get_buffer( p_context, p_ff_pic );
wait_mt( p_sys );
/* Some codecs set pix_fmt only after the 1st frame has been decoded,
* so we need to check for direct rendering again. */
picture_t *p_pic = ffmpeg_dr_GetFrameBuf(p_context);
if (!p_pic) {
if( p_sys->i_direct_rendering_used != 0 )
{
msg_Warn( p_dec, "disabling direct rendering" );
p_sys->i_direct_rendering_used = 0;
}
post_mt( p_sys );
return avcodec_default_get_buffer( p_context, p_ff_pic );
}
if( p_sys->i_direct_rendering_used != 1 ) {
msg_Dbg( p_dec, "using direct rendering" );
p_sys->i_direct_rendering_used = 1;
}
p_context->draw_horiz_band = NULL;
post_mt( p_sys );
p_ff_pic->opaque = (void*)p_pic;
p_ff_pic->type = FF_BUFFER_TYPE_USER;
p_ff_pic->data[0] = p_pic->p[0].p_pixels;
p_ff_pic->data[1] = p_pic->p[1].p_pixels;
p_ff_pic->data[2] = p_pic->p[2].p_pixels;
p_ff_pic->data[3] = NULL; /* alpha channel but I'm not sure */
p_ff_pic->linesize[0] = p_pic->p[0].i_pitch;
p_ff_pic->linesize[1] = p_pic->p[1].i_pitch;
p_ff_pic->linesize[2] = p_pic->p[2].i_pitch;
p_ff_pic->linesize[3] = 0;
return 0;
}
static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
AVFrame *p_ff_pic )
{
decoder_t *p_dec = (decoder_t *)p_context->opaque;
decoder_sys_t *p_sys = p_dec->p_sys;
if( p_sys->p_va )
vlc_va_Release( p_sys->p_va, p_ff_pic->opaque, p_ff_pic->data[0] );
else if( p_ff_pic->opaque )
picture_Release( (picture_t*)p_ff_pic->opaque);
else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL )
/* We can end up here without the AVFrame being allocated by
* avcodec_default_get_buffer() if VA is used and the frame is
* released when the decoder is closed
*/
avcodec_default_release_buffer( p_context, p_ff_pic );
for( int i = 0; i < 4; i++ )
p_ff_pic->data[i] = NULL;
}
#endif
static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
const enum PixelFormat *pi_fmt )
......
......@@ -386,15 +386,7 @@ int OpenDemux( vlc_object_t *p_this )
get_rotation(&fmt, s);
#if LIBAVCODEC_VERSION_MAJOR < 54
if( cc->palctrl )
{
fmt.video.p_palette = xmalloc( 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 );
......@@ -549,7 +541,6 @@ int OpenDemux( vlc_object_t *p_this )
fmt.p_extra = NULL;
}
}
#if LIBAVCODEC_VERSION_CHECK( 54, 29, 0, 17, 101 )
else if( cc->codec_id == AV_CODEC_ID_OPUS )
{
const uint8_t p_dummy_comment[] = {
......@@ -576,7 +567,6 @@ int OpenDemux( vlc_object_t *p_this )
fmt.p_extra = NULL;
}
}
#endif
else if( cc->extradata_size > 0 )
{
fmt.p_extra = malloc( i_extra );
......
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