From 8825393660b95664141ce818089359e1edd612a3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Jul 2016 20:33:24 +0200 Subject: [PATCH] decoder/ffmpeg: use avcodec_alloc_context3() This commit suppresses the remaining deprecation warnings with FFmpeg 3.1. --- src/decoder/plugins/FfmpegDecoderPlugin.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 81464e4bf..8926ec9bc 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -503,7 +503,10 @@ FfmpegDecode(Decoder &decoder, InputStream &input, AVStream &av_stream = *format_context.streams[audio_stream]; +#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57, 5, 0) AVCodecContext *codec_context = av_stream.codec; +#endif + const auto &codec_params = GetCodecParameters(av_stream); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 25, 0) @@ -525,6 +528,18 @@ FfmpegDecode(Decoder &decoder, InputStream &input, return; } +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0) + AVCodecContext *codec_context = avcodec_alloc_context3(codec); + if (codec_context == nullptr) { + LogError(ffmpeg_domain, "avcodec_alloc_context3() failed"); + return; + } + + AtScopeExit(&codec_context) { + avcodec_free_context(&codec_context); + }; +#endif + const SampleFormat sample_format = ffmpeg_sample_format(GetSampleFormat(codec_params)); if (sample_format == SampleFormat::UNDEFINED) { @@ -553,9 +568,11 @@ FfmpegDecode(Decoder &decoder, InputStream &input, return; } +#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57, 5, 0) AtScopeExit(codec_context) { avcodec_close(codec_context); }; +#endif const SignedSongTime total_time = FromFfmpegTimeChecked(av_stream.duration, av_stream.time_base);