diff options
author | Max Kellermann <max@duempel.org> | 2011-07-19 00:24:20 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-07-19 00:24:20 +0200 |
commit | eb2f413cf030a8c9ed51d8dc081e51e4afd287fb (patch) | |
tree | 47c1265e07af284e8a2ced6cb968b5359b754274 /src/decoder | |
parent | e54748d3554d57f8320dff7390fa605bf23d7cd0 (diff) | |
parent | 736fd0e29326548152e91e4e3fb8c0ea9c1b50ac (diff) | |
download | mpd-eb2f413cf030a8c9ed51d8dc081e51e4afd287fb.tar.gz mpd-eb2f413cf030a8c9ed51d8dc081e51e4afd287fb.tar.xz mpd-eb2f413cf030a8c9ed51d8dc081e51e4afd287fb.zip |
Merge branch 'v0.16.x'
Conflicts:
NEWS
configure.ac
Diffstat (limited to 'src/decoder')
-rw-r--r-- | src/decoder/ffmpeg_decoder_plugin.c | 54 | ||||
-rw-r--r-- | src/decoder/flac_metadata.c | 3 | ||||
-rw-r--r-- | src/decoder/flac_metadata.h | 3 |
3 files changed, 52 insertions, 8 deletions
diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 5f11683a0..78e874d9e 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -138,6 +138,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) { @@ -317,9 +344,9 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) } //ffmpeg works with ours "fileops" helper - AVFormatContext *format_context; - if (av_open_input_stream(&format_context, stream->io, input->uri, - input_format, NULL) != 0) { + AVFormatContext *format_context = NULL; + 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; @@ -441,13 +468,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; } @@ -463,9 +503,9 @@ ffmpeg_stream_tag(struct input_stream *is) if (stream == NULL) return NULL; - AVFormatContext *f; - if (av_open_input_stream(&f, stream->io, is->uri, - input_format, NULL) != 0) { + AVFormatContext *f = NULL; + if (mpd_ffmpeg_open_input(&f, stream->io, is->uri, + input_format) != 0) { mpd_ffmpeg_stream_close(stream); return NULL; } diff --git a/src/decoder/flac_metadata.c b/src/decoder/flac_metadata.c index 6987971c8..a19220572 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 642a1d60d..01bc1924a 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 <assert.h> #include <stdbool.h> #include <FLAC/metadata.h> @@ -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; } |