Adjust for libav 10 API

With libav 10 the API is (again...) changed, adjust for that and
add the appropriate version conditions
This commit is contained in:
ejurgensen 2014-02-17 23:05:24 +01:00
parent bdfb726c65
commit 7997377deb
3 changed files with 150 additions and 20 deletions

View File

@ -211,6 +211,24 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
goto out_close_src;
}
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
dst_fmt->video_codec = AV_CODEC_ID_NONE;
/* Try to keep same codec if possible */
if ((src->codec_id == AV_CODEC_ID_PNG) && (format & ART_CAN_PNG))
dst_fmt->video_codec = AV_CODEC_ID_PNG;
else if ((src->codec_id == AV_CODEC_ID_MJPEG) && (format & ART_CAN_JPEG))
dst_fmt->video_codec = AV_CODEC_ID_MJPEG;
/* If not possible, select new codec */
if (dst_fmt->video_codec == AV_CODEC_ID_NONE)
{
if (format & ART_CAN_PNG)
dst_fmt->video_codec = AV_CODEC_ID_PNG;
else if (format & ART_CAN_JPEG)
dst_fmt->video_codec = AV_CODEC_ID_MJPEG;
}
#else
dst_fmt->video_codec = CODEC_ID_NONE;
/* Try to keep same codec if possible */
@ -227,6 +245,7 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
else if (format & ART_CAN_JPEG)
dst_fmt->video_codec = CODEC_ID_MJPEG;
}
#endif
img_encoder = avcodec_find_encoder(dst_fmt->video_codec);
if (!img_encoder)
@ -353,8 +372,13 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
goto out_free_dst_ctx;
}
#if LIBAVCODEC_VERSION_MAJOR >= 56 || (LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR >= 29)
i_frame = av_frame_alloc();
o_frame = av_frame_alloc();
#else
i_frame = avcodec_alloc_frame();
o_frame = avcodec_alloc_frame();
#endif
if (!i_frame || !o_frame)
{
@ -533,11 +557,19 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
switch (dst_fmt->video_codec)
{
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_PNG:
#else
case CODEC_ID_PNG:
#endif
ret = ART_FMT_PNG;
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_MJPEG:
#else
case CODEC_ID_MJPEG:
#endif
ret = ART_FMT_JPEG;
break;
@ -559,10 +591,22 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
av_free(buf);
out_free_frames:
#if LIBAVCODEC_VERSION_MAJOR >= 56 || (LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR >= 29)
if (i_frame)
av_frame_free(&i_frame);
if (o_frame)
av_frame_free(&o_frame);
#elif LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
if (i_frame)
avcodec_free_frame(&i_frame);
if (o_frame)
avcodec_free_frame(&o_frame);
#else
if (i_frame)
av_free(i_frame);
if (o_frame)
av_free(o_frame);
#endif
avcodec_close(dst);
out_free_dst_ctx:
@ -620,12 +664,20 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
format_ok = 0;
for (s = 0; s < src_ctx->nb_streams; s++)
{
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
if (src_ctx->streams[s]->codec->codec_id == AV_CODEC_ID_PNG)
#else
if (src_ctx->streams[s]->codec->codec_id == CODEC_ID_PNG)
#endif
{
format_ok = (format & ART_CAN_PNG) ? ART_FMT_PNG : 0;
break;
}
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
else if (src_ctx->streams[s]->codec->codec_id == AV_CODEC_ID_MJPEG)
#else
else if (src_ctx->streams[s]->codec->codec_id == CODEC_ID_MJPEG)
#endif
{
format_ok = (format & ART_CAN_JPEG) ? ART_FMT_JPEG : 0;
break;
@ -713,12 +765,20 @@ artwork_get_embedded_image(char *filename, int max_w, int max_h, int format, str
{
if (src_ctx->streams[s]->disposition & AV_DISPOSITION_ATTACHED_PIC)
{
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
if (src_ctx->streams[s]->codec->codec_id == AV_CODEC_ID_PNG)
#else
if (src_ctx->streams[s]->codec->codec_id == CODEC_ID_PNG)
#endif
{
format_ok = (format & ART_CAN_PNG) ? ART_FMT_PNG : 0;
break;
}
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
else if (src_ctx->streams[s]->codec->codec_id == AV_CODEC_ID_MJPEG)
#else
else if (src_ctx->streams[s]->codec->codec_id == CODEC_ID_MJPEG)
#endif
{
format_ok = (format & ART_CAN_JPEG) ? ART_FMT_JPEG : 0;
break;
@ -1030,8 +1090,10 @@ artwork_get_group(int id, int max_w, int max_h, int format, struct evbuffer *evb
struct db_media_file_info dbmfi;
char *dir;
int got_art;
int artwork_t;
int ret;
#if LIBAVFORMAT_VERSION_MAJOR >= 55 || (LIBAVFORMAT_VERSION_MAJOR == 54 && LIBAVFORMAT_VERSION_MINOR >= 6)
int artwork_t;
#endif
DPRINTF(E_DBG, L_ART, "Artwork request for group %d\n", id);

View File

@ -376,11 +376,19 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
DPRINTF(E_DBG, L_SCAN, "File has %d streams\n", ctx->nb_streams);
/* Extract codec IDs, check for video */
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
video_codec_id = AV_CODEC_ID_NONE;
video_stream = NULL;
audio_codec_id = AV_CODEC_ID_NONE;
audio_stream = NULL;
#else
video_codec_id = CODEC_ID_NONE;
video_stream = NULL;
audio_codec_id = CODEC_ID_NONE;
audio_stream = NULL;
#endif
for (i = 0; i < ctx->nb_streams; i++)
{
@ -427,7 +435,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
}
}
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
if (audio_codec_id == AV_CODEC_ID_NONE)
#else
if (audio_codec_id == CODEC_ID_NONE)
#endif
{
DPRINTF(E_DBG, L_SCAN, "File has no audio streams, discarding\n");
@ -478,21 +490,33 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
codec_id = (mfi->has_video) ? video_codec_id : audio_codec_id;
switch (codec_id)
{
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_AAC:
#else
case CODEC_ID_AAC:
#endif
DPRINTF(E_DBG, L_SCAN, "AAC\n");
mfi->type = strdup("m4a");
mfi->codectype = strdup("mp4a");
mfi->description = strdup("AAC audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_ALAC:
#else
case CODEC_ID_ALAC:
#endif
DPRINTF(E_DBG, L_SCAN, "ALAC\n");
mfi->type = strdup("m4a");
mfi->codectype = strdup("alac");
mfi->description = strdup("Apple Lossless audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_FLAC:
#else
case CODEC_ID_FLAC:
#endif
DPRINTF(E_DBG, L_SCAN, "FLAC\n");
mfi->type = strdup("flac");
mfi->codectype = strdup("flac");
@ -501,16 +525,26 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
extra_md_map = md_map_vorbis;
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_MUSEPACK7:
case AV_CODEC_ID_MUSEPACK8:
#else
case CODEC_ID_MUSEPACK7:
case CODEC_ID_MUSEPACK8:
#endif
DPRINTF(E_DBG, L_SCAN, "Musepack\n");
mfi->type = strdup("mpc");
mfi->codectype = strdup("mpc");
mfi->description = strdup("Musepack audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_MPEG4: /* Video */
case AV_CODEC_ID_H264:
#else
case CODEC_ID_MPEG4: /* Video */
case CODEC_ID_H264:
#endif
DPRINTF(E_DBG, L_SCAN, "MPEG4 video\n");
mfi->type = strdup("m4v");
mfi->codectype = strdup("mp4v");
@ -519,7 +553,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
extra_md_map = md_map_tv;
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_MP3:
#else
case CODEC_ID_MP3:
#endif
DPRINTF(E_DBG, L_SCAN, "MP3\n");
mfi->type = strdup("mp3");
mfi->codectype = strdup("mpeg");
@ -528,7 +566,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
extra_md_map = md_map_id3;
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_VORBIS:
#else
case CODEC_ID_VORBIS:
#endif
DPRINTF(E_DBG, L_SCAN, "VORBIS\n");
mfi->type = strdup("ogg");
mfi->codectype = strdup("ogg");
@ -537,30 +579,48 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
extra_md_map = md_map_vorbis;
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_WMAV1:
case AV_CODEC_ID_WMAV2:
case AV_CODEC_ID_WMAVOICE:
#else
case CODEC_ID_WMAV1:
case CODEC_ID_WMAV2:
case CODEC_ID_WMAVOICE:
#endif
DPRINTF(E_DBG, L_SCAN, "WMA Voice\n");
mfi->type = strdup("wma");
mfi->codectype = strdup("wmav");
mfi->description = strdup("WMA audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_WMAPRO:
#else
case CODEC_ID_WMAPRO:
#endif
DPRINTF(E_DBG, L_SCAN, "WMA Pro\n");
mfi->type = strdup("wmap");
mfi->codectype = strdup("wma");
mfi->description = strdup("WMA audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_WMALOSSLESS:
#else
case CODEC_ID_WMALOSSLESS:
#endif
DPRINTF(E_DBG, L_SCAN, "WMA Lossless\n");
mfi->type = strdup("wma");
mfi->codectype = strdup("wmal");
mfi->description = strdup("WMA audio file");
break;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
case AV_CODEC_ID_PCM_S16LE ... AV_CODEC_ID_PCM_F64LE:
#else
case CODEC_ID_PCM_S16LE ... CODEC_ID_PCM_F64LE:
#endif
if (strcmp(ctx->iformat->name, "aiff") == 0)
{
DPRINTF(E_DBG, L_SCAN, "AIFF\n");
@ -637,6 +697,7 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
skip_extract:
if (mdcount == 0)
{
#if LIBAVFORMAT_VERSION_MAJOR < 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR < 21)
/* ffmpeg doesn't support FLAC nor Musepack metadata,
* and is buggy for some WMA variants, so fall back to the
* legacy format-specific parsers until it gets fixed */
@ -645,24 +706,14 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|| (codec_id == CODEC_ID_WMALOSSLESS))
{
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy WMA scanner\n");
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
avformat_close_input(&ctx);
#else
av_close_input_file(ctx);
#endif
return (scan_get_wmainfo(file, mfi) ? 0 : -1);
}
#ifdef FLAC
else if (codec_id == CODEC_ID_FLAC)
{
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy FLAC scanner\n");
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
avformat_close_input(&ctx);
#else
av_close_input_file(ctx);
#endif
return (scan_get_flacinfo(file, mfi) ? 0 : -1);
}
#endif /* FLAC */
@ -671,16 +722,12 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|| (codec_id == CODEC_ID_MUSEPACK8))
{
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy Musepack scanner\n");
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
avformat_close_input(&ctx);
#else
av_close_input_file(ctx);
#endif
return (scan_get_mpcinfo(file, mfi) ? 0 : -1);
}
#endif /* MUSEPACK */
else
#endif /* LIBAVFORMAT */
DPRINTF(E_WARN, L_SCAN, "ffmpeg/libav could not extract any metadata\n");
}

View File

@ -184,7 +184,26 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
/* Decode data */
while (ctx->apacket2.size > 0)
{
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
#if LIBAVCODEC_VERSION_MAJOR >= 56 || (LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR >= 29)
got_frame = 0;
if (!frame)
{
frame = av_frame_alloc();
if (!frame)
{
DPRINTF(E_LOG, L_XCODE, "Out of memory for decoded frame\n");
return -1;
}
}
else
av_frame_unref(frame);
used = avcodec_decode_audio4(ctx->acodec,
frame, &got_frame,
&ctx->apacket2);
#elif LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
got_frame = 0;
if (!frame)
@ -200,7 +219,6 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
else
avcodec_get_frame_defaults(frame);
used = avcodec_decode_audio4(ctx->acodec,
frame, &got_frame,
&ctx->apacket2);
@ -343,10 +361,13 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
ctx->offset += processed;
#if LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
#if LIBAVCODEC_VERSION_MAJOR >= 56 || (LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR >= 29)
if (frame)
av_frame_free(&frame);
#elif LIBAVCODEC_VERSION_MAJOR >= 55 || (LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR >= 35)
if (frame)
avcodec_free_frame(&frame);
#elif LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
#else
if (frame)
av_free(frame);
#endif