Commit 5b2d6204 authored by Konstantin Pavlov's avatar Konstantin Pavlov

Update av* code to use new APIs after Libav Big Bump.

Commit based on following commits from master branch:
c7255099d7a06663df733beaeff4520ae7c77d86
4308323da50d235ef4ac87cd1a0444f6c4f7aba4
052a73e1007741d7b63347d3a81cceda7e4dbfb3
db4b639b8ff754d771dd1f5057873820fb792cd8
parent 50e585e4
......@@ -98,8 +98,8 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
return VLC_ENOMEM;
}
p_codec->type = CODEC_TYPE_AUDIO;
p_context->codec_type = CODEC_TYPE_AUDIO;
p_codec->type = AVMEDIA_TYPE_AUDIO;
p_context->codec_type = AVMEDIA_TYPE_AUDIO;
p_context->codec_id = i_codec_id;
p_sys->p_context = p_context;
p_sys->p_codec = p_codec;
......@@ -330,7 +330,14 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
p_sys->p_output = av_realloc( p_sys->p_output, i_output );
}
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 52, 0, 0 )
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 0, 0 )
AVPacket pkt;
av_init_packet( &pkt );
pkt.data = p_block->p_buffer;
pkt.size = p_block->i_buffer;
i_used = avcodec_decode_audio3( p_sys->p_context,
(int16_t*)p_sys->p_output, &i_output, &pkt );
#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 52, 0, 0 )
i_used = avcodec_decode_audio2( p_sys->p_context,
(int16_t*)p_sys->p_output, &i_output,
p_block->p_buffer, p_block->i_buffer );
......
......@@ -262,39 +262,39 @@ static int OpenDecoder( vlc_object_t *p_this )
p_context->dsp_mask = 0;
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
p_context->dsp_mask |= FF_MM_MMX;
p_context->dsp_mask |= AV_CPU_FLAG_MMX;
}
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
p_context->dsp_mask |= FF_MM_MMXEXT;
p_context->dsp_mask |= AV_CPU_FLAG_MMX2;
}
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
p_context->dsp_mask |= FF_MM_3DNOW;
p_context->dsp_mask |= AV_CPU_FLAG_3DNOW;
}
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
p_context->dsp_mask |= FF_MM_SSE;
p_context->dsp_mask |= AV_CPU_FLAG_SSE;
}
if( !(i_cpu & CPU_CAPABILITY_SSE2) )
{
p_context->dsp_mask |= FF_MM_SSE2;
p_context->dsp_mask |= AV_CPU_FLAG_SSE2;
}
#ifdef FF_MM_SSE3
#ifdef AV_CPU_FLAG_SSE3
if( !(i_cpu & CPU_CAPABILITY_SSE3) )
p_context->dsp_mask |= FF_MM_SSE3;
p_context->dsp_mask |= AV_CPU_FLAG_SSE3;
#endif
#ifdef FF_MM_SSSE3
#ifdef AV_CPU_FLAG_SSSE3
if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
p_context->dsp_mask |= FF_MM_SSSE3;
p_context->dsp_mask |= AV_CPU_FLAG_SSSE3;
#endif
#ifdef FF_MM_SSE4
#ifdef AV_CPU_FLAG_SSE4
if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
p_context->dsp_mask |= FF_MM_SSE4;
p_context->dsp_mask |= AV_CPU_FLAG_SSE4;
#endif
#ifdef FF_MM_SSE42
#ifdef AV_CPU_FLAG_SSE42
if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
p_context->dsp_mask |= FF_MM_SSE42;
p_context->dsp_mask |= AV_CPU_FLAG_SSE42;
#endif
p_dec->b_need_packetized = true;
......
......@@ -270,3 +270,37 @@ void EndSubtitleDec( decoder_t *p_dec );
* system) */
//#define HAVE_AVCODEC_VAAPI 1
//#define HAVE_AVCODEC_DXVA2 1
/* Ugly ifdefinitions to provide backwards compatibility with older ffmpeg/libav
* versions */
#ifndef AV_CPU_FLAG_FORCE
# define AV_CPU_FLAG_FORCE FF_MM_FORCE
# define AV_CPU_FLAG_MMX FF_MM_MMX
# define AV_CPU_FLAG_3DNOW FF_MM_3DNOW
# define AV_CPU_FLAG_MMX2 FF_MM_MMX2
# define AV_CPU_FLAG_SSE FF_MM_SSE
# define AV_CPU_FLAG_SSE2 FF_MM_SSE2
# define AV_CPU_FLAG_SSE2SLOW FF_MM_SSE2SLOW
# define AV_CPU_FLAG_3DNOWEXT FF_MM_3DNOWEXT
# define AV_CPU_FLAG_SSE3 FF_MM_SSE3
# define AV_CPU_FLAG_SSE3SLOW FF_MM_SSE3SLOW
# define AV_CPU_FLAG_SSSE3 FF_MM_SSSE3
# define AV_CPU_FLAG_SSE4 FF_MM_SSE4
# define AV_CPU_FLAG_SSE42 FF_MM_SSE42
# define AV_CPU_FLAG_IWMMXT FF_MM_IWMMXT
# define AV_CPU_FLAG_ALTIVEC FF_MM_ALTIVEC
#endif
#if LIBAVCODEC_VERSION_MAJOR < 53
# define AVMediaType CodecType
# define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
# define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
# define AVMEDIA_TYPE_SUBTITLE CODEC_TYPE_SUBTITLE
# define AVMEDIA_TYPE_DATA CODEC_TYPE_DATA
# define AVMEDIA_TYPE_ATTACHMENT CODEC_TYPE_ATTACHMENT
#endif
#ifndef AV_PKT_FLAG_KEY
# define AV_PKT_FLAG_KEY PKT_FLAG_KEY
#endif
......@@ -289,20 +289,20 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->dsp_mask = 0;
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
p_context->dsp_mask |= FF_MM_MMX;
p_context->dsp_mask |= AV_CPU_FLAG_MMX;
}
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
p_context->dsp_mask |= FF_MM_MMXEXT;
p_context->dsp_mask |= AV_CPU_FLAG_MMX2;
}
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
p_context->dsp_mask |= FF_MM_3DNOW;
p_context->dsp_mask |= AV_CPU_FLAG_3DNOW;
}
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
p_context->dsp_mask |= FF_MM_SSE;
p_context->dsp_mask |= FF_MM_SSE2;
p_context->dsp_mask |= AV_CPU_FLAG_SSE;
p_context->dsp_mask |= AV_CPU_FLAG_SSE2;
}
config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
......@@ -397,7 +397,7 @@ int OpenEncoder( vlc_object_t *p_this )
return VLC_EGENERIC;
}
p_context->codec_type = CODEC_TYPE_VIDEO;
p_context->codec_type = AVMEDIA_TYPE_VIDEO;
p_context->width = p_enc->fmt_in.video.i_width;
p_context->height = p_enc->fmt_in.video.i_height;
......@@ -516,12 +516,12 @@ int OpenEncoder( vlc_object_t *p_this )
if( p_sys->i_qmin > 0 )
{
p_context->mb_qmin = p_context->qmin = p_sys->i_qmin;
p_context->qmin = p_sys->i_qmin;
p_context->mb_lmin = p_context->lmin = p_sys->i_qmin * FF_QP2LAMBDA;
}
if( p_sys->i_qmax > 0 )
{
p_context->mb_qmax = p_context->qmax = p_sys->i_qmax;
p_context->qmax = p_sys->i_qmax;
p_context->mb_lmax = p_context->lmax = p_sys->i_qmax * FF_QP2LAMBDA;
}
p_context->max_qdiff = 3;
......@@ -551,7 +551,7 @@ int OpenEncoder( vlc_object_t *p_this )
if( i_codec_id == CODEC_ID_MP3 && p_enc->fmt_in.audio.i_channels > 2 )
p_enc->fmt_in.audio.i_channels = 2;
p_context->codec_type = CODEC_TYPE_AUDIO;
p_context->codec_type = AVMEDIA_TYPE_AUDIO;
p_context->sample_fmt = p_codec->sample_fmts ?
p_codec->sample_fmts[0] :
SAMPLE_FMT_S16;
......@@ -593,20 +593,20 @@ int OpenEncoder( vlc_object_t *p_this )
/* Check that we don't overrun users qmin/qmax values */
if( !var_GetInteger( p_enc, ENC_CFG_PREFIX "qmin" ) )
{
p_context->mb_qmin = p_context->qmin = 10;
p_context->qmin = 10;
p_context->mb_lmin = p_context->lmin = 10 * FF_QP2LAMBDA;
}
if( !var_GetInteger( p_enc, ENC_CFG_PREFIX "qmax" ) )
{
p_context->mb_qmax = p_context->qmax = 42;
p_context->qmax = 42;
p_context->mb_lmax = p_context->lmax = 42 * FF_QP2LAMBDA;
}
} else {
if( !var_GetInteger( p_enc, ENC_CFG_PREFIX "qmin" ) )
{
p_context->mb_qmin = p_context->qmin = 1;
p_context->qmin = 1;
p_context->mb_lmin = p_context->lmin = FF_QP2LAMBDA;
}
}
......
......@@ -79,8 +79,8 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
if (!sys)
return VLC_ENOMEM;
codec->type = CODEC_TYPE_SUBTITLE;
context->codec_type = CODEC_TYPE_SUBTITLE;
codec->type = AVMEDIA_TYPE_SUBTITLE;
context->codec_type = AVMEDIA_TYPE_SUBTITLE;
context->codec_id = codec_id;
sys->p_context = context;
sys->p_codec = codec;
......
......@@ -201,8 +201,8 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL )
return VLC_ENOMEM;
p_codec->type = CODEC_TYPE_VIDEO;
p_context->codec_type = CODEC_TYPE_VIDEO;
p_codec->type = AVMEDIA_TYPE_VIDEO;
p_context->codec_type = AVMEDIA_TYPE_VIDEO;
p_context->codec_id = i_codec_id;
p_sys->p_context = p_context;
p_sys->p_codec = p_codec;
......@@ -547,9 +547,18 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
picture_t *p_pic;
p_sys->p_ff_pic->pts = p_sys->input_pts;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,23,0)
AVPacket pkt;
av_init_packet( &pkt );
pkt.data = p_block->p_buffer;
pkt.size = p_block->i_buffer;
i_used = avcodec_decode_video2( p_sys->p_context, p_sys->p_ff_pic,
&b_gotpicture, &pkt );
#else
i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic,
&b_gotpicture,
p_block->i_buffer <= 0 && p_sys->b_flush ? NULL : p_block->p_buffer, p_block->i_buffer );
#endif
if( b_null_size && p_sys->p_context->width > 0 &&
p_sys->p_context->height > 0 &&
......@@ -559,9 +568,14 @@ picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
b_null_size = false;
if( p_sys->b_hurry_up )
p_sys->p_context->skip_frame = p_sys->i_skip_frame;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,23,0)
i_used = avcodec_decode_video2( p_sys->p_context, p_sys->p_ff_pic,
&b_gotpicture, &pkt );
#else
i_used = avcodec_decode_video( p_sys->p_context, p_sys->p_ff_pic,
&b_gotpicture, p_block->p_buffer,
p_block->i_buffer );
#endif
}
if( p_sys->b_flush )
......
......@@ -244,7 +244,7 @@ int OpenDemux( vlc_object_t *p_this )
switch( cc->codec_type )
{
case CODEC_TYPE_AUDIO:
case AVMEDIA_TYPE_AUDIO:
es_format_Init( &fmt, AUDIO_ES, fcc );
fmt.i_bitrate = cc->bit_rate;
fmt.audio.i_channels = cc->channels;
......@@ -258,7 +258,7 @@ int OpenDemux( vlc_object_t *p_this )
psz_type = "audio";
break;
case CODEC_TYPE_VIDEO:
case AVMEDIA_TYPE_VIDEO:
es_format_Init( &fmt, VIDEO_ES, fcc );
/* Special case for raw video data */
......@@ -293,7 +293,7 @@ int OpenDemux( vlc_object_t *p_this )
#endif
break;
case CODEC_TYPE_SUBTITLE:
case AVMEDIA_TYPE_SUBTITLE:
es_format_Init( &fmt, SPU_ES, fcc );
if( strncmp( p_sys->ic->iformat->name, "matroska", 8 ) == 0 &&
cc->codec_id == CODEC_ID_DVD_SUBTITLE &&
......@@ -343,14 +343,24 @@ int OpenDemux( vlc_object_t *p_this )
default:
es_format_Init( &fmt, UNKNOWN_ES, 0 );
#ifdef HAVE_FFMPEG_CODEC_ATTACHMENT
if( cc->codec_type == CODEC_TYPE_ATTACHMENT )
if( cc->codec_type == AVMEDIA_TYPE_ATTACHMENT )
{
input_attachment_t *p_attachment;
psz_type = "attachment";
if( cc->codec_id == CODEC_ID_TTF )
{
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0)
AVMetadataTag *filename = av_metadata_get( s->metadata, "filename", NULL, 0 );
if( filename && filename->value )
{
p_attachment = vlc_input_attachment_New(
filename->value, "application/x-truetype-font",
NULL, cc->extradata, (int)cc->extradata_size );
}
#else
p_attachment = vlc_input_attachment_New( s->filename, "application/x-truetype-font", NULL,
cc->extradata, (int)cc->extradata_size );
#endif
TAB_APPEND( p_sys->i_attachments, p_sys->attachments, p_attachment );
}
else msg_Warn( p_demux, "unsupported attachment type in ffmpeg demux" );
......@@ -358,18 +368,24 @@ int OpenDemux( vlc_object_t *p_this )
break;
#endif
if( cc->codec_type == CODEC_TYPE_DATA )
if( cc->codec_type == AVMEDIA_TYPE_DATA )
psz_type = "data";
msg_Warn( p_demux, "unsupported track type in ffmpeg demux" );
break;
}
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0)
AVMetadataTag *language = av_metadata_get( s->metadata, "language", NULL, 0 );
if ( language && language->value )
fmt.psz_language = strdup( language->value );
#else
fmt.psz_language = strdup( s->language );
#endif
if( s->disposition & AV_DISPOSITION_DEFAULT )
fmt.i_priority = 1000;
#ifdef HAVE_FFMPEG_CODEC_ATTACHMENT
if( cc->codec_type != CODEC_TYPE_ATTACHMENT )
if( cc->codec_type != AVMEDIA_TYPE_ATTACHMENT )
#endif
{
const bool b_ogg = !strcmp( p_sys->fmt->name, "ogg" );
......@@ -459,9 +475,16 @@ int OpenDemux( vlc_object_t *p_this )
{
seekpoint_t *s = vlc_seekpoint_New();
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0)
AVMetadataTag *title = av_metadata_get( p_sys->ic->metadata, "title", NULL, 0);
if( title && title->value )
{
s->psz_name = strdup( title->value );
#else
if( p_sys->ic->chapters[i]->title )
{
s->psz_name = strdup( p_sys->ic->chapters[i]->title );
#endif
EnsureUTF8( s->psz_name );
msg_Dbg( p_demux, " - chapter %d: %s", i, s->psz_name );
}
......@@ -545,7 +568,7 @@ static int Demux( demux_t *p_demux )
memcpy( p_frame->p_buffer, pkt.data, pkt.size );
}
if( pkt.flags & PKT_FLAG_KEY )
if( pkt.flags & AV_PKT_FLAG_KEY )
p_frame->i_flags |= BLOCK_FLAG_TYPE_I;
i_start_time = ( p_sys->ic->start_time != (int64_t)AV_NOPTS_VALUE ) ?
......@@ -565,7 +588,7 @@ static int Demux( demux_t *p_demux )
p_stream->time_base.den;
if( pkt.dts != AV_NOPTS_VALUE && pkt.dts == pkt.pts &&
p_stream->codec->codec_type == CODEC_TYPE_VIDEO )
p_stream->codec->codec_type == AVMEDIA_TYPE_VIDEO )
{
/* Add here notoriously bugged file formats/samples regarding PTS */
if( !strcmp( p_sys->fmt->name, "flv" ) )
......@@ -746,6 +769,24 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
{
vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0)
AVMetadataTag *title = av_metadata_get( p_sys->ic->metadata, "language", NULL, 0 );
AVMetadataTag *artist = av_metadata_get( p_sys->ic->metadata, "artist", NULL, 0 );
AVMetadataTag *copyright = av_metadata_get( p_sys->ic->metadata, "copyright", NULL, 0 );
AVMetadataTag *comment = av_metadata_get( p_sys->ic->metadata, "comment", NULL, 0 );
AVMetadataTag *genre = av_metadata_get( p_sys->ic->metadata, "genre", NULL, 0 );
if( title && title->value )
vlc_meta_SetTitle( p_meta, title->value );
if( artist && artist->value )
vlc_meta_SetArtist( p_meta, artist->value );
if( copyright && copyright->value )
vlc_meta_SetCopyright( p_meta, copyright->value );
if( comment && comment->value )
vlc_meta_SetDescription( p_meta, comment->value );
if( genre && genre->value )
vlc_meta_SetGenre( p_meta, genre->value );
#else
if( p_sys->ic->title[0] )
vlc_meta_SetTitle( p_meta, p_sys->ic->title );
if( p_sys->ic->author[0] )
......@@ -756,6 +797,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
vlc_meta_SetDescription( p_meta, p_sys->ic->comment );
if( p_sys->ic->genre[0] )
vlc_meta_SetGenre( p_meta, p_sys->ic->genre );
#endif
return VLC_SUCCESS;
}
......
......@@ -101,12 +101,20 @@ int OpenMux( vlc_object_t *p_this )
psz_mux = var_GetNonEmptyString( p_mux, "ffmpeg-mux" );
if( psz_mux )
{
#if( LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT( 52, 45, 0 ) )
file_oformat = av_guess_format( psz_mux, NULL, NULL );
#else
file_oformat = guess_format( psz_mux, NULL, NULL );
#endif
}
else
{
file_oformat =
guess_format(NULL, p_mux->p_access->psz_path, NULL);
#if( LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT( 52, 45, 0 ) )
av_guess_format( NULL, p_mux->p_access->psz_path, NULL);
#else
guess_format( NULL, p_mux->p_access->psz_path, NULL);
#endif
}
if (!file_oformat)
{
......@@ -121,7 +129,11 @@ int OpenMux( vlc_object_t *p_this )
p_mux->pf_mux = Mux;
p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,26,0)
p_sys->oc = avformat_alloc_context();
#else
p_sys->oc = av_alloc_format_context();
#endif
p_sys->oc->oformat = file_oformat;
/* Create I/O wrapper */
......@@ -234,7 +246,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
switch( p_input->p_fmt->i_cat )
{
case AUDIO_ES:
codec->codec_type = CODEC_TYPE_AUDIO;
codec->codec_type = AVMEDIA_TYPE_AUDIO;
codec->channels = p_input->p_fmt->audio.i_channels;
codec->sample_rate = p_input->p_fmt->audio.i_rate;
codec->time_base = (AVRational){1, codec->sample_rate};
......@@ -249,7 +261,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
p_input->p_fmt->video.i_frame_rate = 25;
p_input->p_fmt->video.i_frame_rate_base = 1;
}
codec->codec_type = CODEC_TYPE_VIDEO;
codec->codec_type = AVMEDIA_TYPE_VIDEO;
codec->width = p_input->p_fmt->video.i_width;
codec->height = p_input->p_fmt->video.i_height;
av_reduce( &codec->sample_aspect_ratio.num,
......@@ -320,7 +332,7 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
pkt.size = p_data->i_buffer;
pkt.stream_index = i_stream;
if( p_data->i_flags & BLOCK_FLAG_TYPE_I ) pkt.flags |= PKT_FLAG_KEY;
if( p_data->i_flags & BLOCK_FLAG_TYPE_I ) pkt.flags |= AV_PKT_FLAG_KEY;
/* avformat expects pts/dts which start from 0 */
p_data->i_dts -= p_mux->p_sys->i_initial_dts;
......
......@@ -102,10 +102,10 @@ static const char *const ppsz_filter_options[] = {
struct filter_sys_t
{
/* Never changes after init */
pp_context_t *pp_context;
pp_context *pp_context;
/* Set to NULL if post processing is disabled */
pp_mode_t *pp_mode;
pp_mode *pp_mode;
/* Set to true if previous pic had a quant matrix
(used to prevent spamming warning messages) */
......@@ -345,7 +345,7 @@ static void PPChangeMode( filter_t *p_filter, const char *psz_name,
vlc_mutex_lock( &p_sys->lock );
if( i_quality > 0 )
{
pp_mode_t *pp_mode = pp_get_mode_by_name_and_quality( psz_name ?
pp_mode *pp_mode = pp_get_mode_by_name_and_quality( psz_name ?
psz_name :
"default",
i_quality );
......
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