From 8d1c7ca2065444dfe2da432a30c95782e3ead48d Mon Sep 17 00:00:00 2001 From: oblique Date: Sun, 3 Jul 2011 14:54:56 +0200 Subject: ffmpeg: workaround for semantic API change in recent ffmpeg versions --- src/decoder/ffmpeg_decoder_plugin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 6d794db49..156853faf 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -321,7 +321,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) } //ffmpeg works with ours "fileops" helper - AVFormatContext *format_context; + AVFormatContext *format_context = NULL; if (av_open_input_stream(&format_context, stream->io, input->uri, input_format, NULL) != 0) { g_warning("Open failed\n"); @@ -470,7 +470,7 @@ ffmpeg_stream_tag(struct input_stream *is) if (stream == NULL) return NULL; - AVFormatContext *f; + AVFormatContext *f = NULL; if (av_open_input_stream(&f, stream->io, is->uri, input_format, NULL) != 0) { mpd_ffmpeg_stream_close(stream); -- cgit v1.2.3 From 6aa6a9c2727c863239d6396a40a781e98e922565 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 3 Jul 2011 14:57:56 +0200 Subject: decoder/flac: validate the sample rate when scanning the tag Don't calculate the song duration when the sample rate is 0 (division by zero crash). --- src/decoder/flac_metadata.c | 3 ++- src/decoder/flac_metadata.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/src/decoder/flac_metadata.c b/src/decoder/flac_metadata.c index f2f2f954d..5b94fd426 100644 --- a/src/decoder/flac_metadata.c +++ b/src/decoder/flac_metadata.c @@ -224,7 +224,8 @@ flac_tag_apply_metadata(struct tag *tag, const char *track, break; case FLAC__METADATA_TYPE_STREAMINFO: - tag->time = flac_duration(&block->data.stream_info); + if (block->data.stream_info.sample_rate > 0) + tag->time = flac_duration(&block->data.stream_info); break; default: diff --git a/src/decoder/flac_metadata.h b/src/decoder/flac_metadata.h index 06e691d1d..e52b0fb82 100644 --- a/src/decoder/flac_metadata.h +++ b/src/decoder/flac_metadata.h @@ -20,6 +20,7 @@ #ifndef MPD_FLAC_METADATA_H #define MPD_FLAC_METADATA_H +#include #include #include @@ -29,6 +30,8 @@ struct replay_gain_info; static inline unsigned flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info) { + assert(stream_info->sample_rate > 0); + return (stream_info->total_samples + stream_info->sample_rate - 1) / stream_info->sample_rate; } -- cgit v1.2.3 From 6592ca9f8805c3cf5154626087a01a183c38b6d5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Jul 2011 23:29:42 +0200 Subject: decoder: use AVDictionary instead of AVMetadata AVMetadata has been deprecated. --- src/decoder/ffmpeg_decoder_plugin.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 156853faf..15ea77f70 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -446,13 +446,26 @@ static const ffmpeg_tag_map ffmpeg_tag_maps[] = { }; static bool -ffmpeg_copy_metadata(struct tag *tag, AVMetadata *m, +ffmpeg_copy_metadata(struct tag *tag, +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0) + AVDictionary *m, +#else + AVMetadata *m, +#endif const ffmpeg_tag_map tag_map) { +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0) + AVDictionaryEntry *mt = NULL; + + while ((mt = av_dict_get(m, tag_map.name, mt, 0)) != NULL) + tag_add_item(tag, tag_map.type, mt->value); +#else AVMetadataTag *mt = NULL; while ((mt = av_metadata_get(m, tag_map.name, mt, 0)) != NULL) tag_add_item(tag, tag_map.type, mt->value); +#endif + return mt != NULL; } -- cgit v1.2.3 From 736fd0e29326548152e91e4e3fb8c0ea9c1b50ac Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Jul 2011 23:31:47 +0200 Subject: decoder/ffmpeg: use avformat_open_input() if available av_open_input_stream() has been deprecated. --- src/decoder/ffmpeg_decoder_plugin.c | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 15ea77f70..70628df9d 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -89,7 +89,11 @@ struct mpd_ffmpeg_stream { struct decoder *decoder; struct input_stream *input; +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0) + AVIOContext *io; +#else ByteIOContext *io; +#endif unsigned char buffer[8192]; }; @@ -135,6 +139,33 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input) return stream; } +/** + * API compatibility wrapper for av_open_input_stream() and + * avformat_open_input(). + */ +static int +mpd_ffmpeg_open_input(AVFormatContext **ic_ptr, +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0) + AVIOContext *pb, +#else + ByteIOContext *pb, +#endif + const char *filename, + AVInputFormat *fmt) +{ +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,1,3) + AVFormatContext *context = avformat_alloc_context(); + if (context == NULL) + return AVERROR(ENOMEM); + + context->pb = pb; + *ic_ptr = context; + return avformat_open_input(ic_ptr, filename, fmt, NULL); +#else + return av_open_input_stream(ic_ptr, pb, filename, fmt, NULL); +#endif +} + static void mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream) { @@ -322,8 +353,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) //ffmpeg works with ours "fileops" helper AVFormatContext *format_context = NULL; - if (av_open_input_stream(&format_context, stream->io, input->uri, - input_format, NULL) != 0) { + if (mpd_ffmpeg_open_input(&format_context, stream->io, input->uri, + input_format) != 0) { g_warning("Open failed\n"); mpd_ffmpeg_stream_close(stream); return; @@ -484,8 +515,8 @@ ffmpeg_stream_tag(struct input_stream *is) return NULL; AVFormatContext *f = NULL; - if (av_open_input_stream(&f, stream->io, is->uri, - input_format, NULL) != 0) { + if (mpd_ffmpeg_open_input(&f, stream->io, is->uri, + input_format) != 0) { mpd_ffmpeg_stream_close(stream); return NULL; } -- cgit v1.2.3