From 142fdc8d86d26ebf478d87fc751181fd578e8c70 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Jan 2017 23:05:04 +0100 Subject: [PATCH] decoder/flac: add options "probesize" and "analyzeduration" https://bugs.musicpd.org/view.php?id=3876 --- NEWS | 2 + doc/user.xml | 42 +++++++++++++++++++++ src/decoder/plugins/FfmpegDecoderPlugin.cxx | 33 ++++++++++++++-- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 679d1b25b..510aff088 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ ver 0.20.2 (not yet released) +* decoder + - flac: add options "probesize" and "analyzeduration" ver 0.20.1 (2017/01/09) * input diff --git a/doc/user.xml b/doc/user.xml index a3add674d..b9797d03a 100644 --- a/doc/user.xml +++ b/doc/user.xml @@ -2206,6 +2206,48 @@ run Decodes various codecs using FFmpeg. + + + + + + Setting + Description + + + + + + analyzeduration + VALUE + + + Sets the FFmpeg muxer option + analyzeduration, which specifies + how many microseconds are analyzed to probe the + input. The FFmpeg + formats documentation has more information. + + + + + + probesize + VALUE + + + Sets the FFmpeg muxer option + probesize, which specifies + probing size in bytes, i.e. the size of the data to + analyze to get stream information. The FFmpeg + formats documentation has more information. + + + + +
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 1ba0c9de2..698645380 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -56,6 +56,11 @@ extern "C" { #include #include +/** + * Muxer options to be passed to avformat_open_input(). + */ +static AVDictionary *avformat_options = nullptr; + static AVFormatContext * FfmpegOpenInput(AVIOContext *pb, const char *filename, @@ -67,7 +72,11 @@ FfmpegOpenInput(AVIOContext *pb, context->pb = pb; - int err = avformat_open_input(&context, filename, fmt, nullptr); + AVDictionary *options = nullptr; + AtScopeExit(&options) { av_dict_free(&options); }; + av_dict_copy(&options, avformat_options, 0); + + int err = avformat_open_input(&context, filename, fmt, &options); if (err < 0) throw MakeFfmpegError(err, "avformat_open_input() failed"); @@ -75,12 +84,30 @@ FfmpegOpenInput(AVIOContext *pb, } static bool -ffmpeg_init(gcc_unused const ConfigBlock &block) +ffmpeg_init(const ConfigBlock &block) { FfmpegInit(); + + static constexpr const char *option_names[] = { + "probesize", + "analyzeduration", + }; + + for (const char *name : option_names) { + const char *value = block.GetBlockValue(name); + if (value != nullptr) + av_dict_set(&avformat_options, name, value, 0); + } + return true; } +static void +ffmpeg_finish() +{ + av_dict_free(&avformat_options); +} + #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 25, 0) /* FFmpeg 3.1 */ gcc_pure @@ -967,7 +994,7 @@ static const char *const ffmpeg_mime_types[] = { const struct DecoderPlugin ffmpeg_decoder_plugin = { "ffmpeg", ffmpeg_init, - nullptr, + ffmpeg_finish, ffmpeg_decode, nullptr, nullptr,