From 57d5df8118ba1fa70be892d631b5d6a278cea498 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 27 Jul 2022 10:55:43 +0200 Subject: [PATCH] decoder/ffmpeg: fix FFmpeg 5.1 deprecation warnings --- src/decoder/plugins/FfmpegDecoderPlugin.cxx | 17 +++++++++++++++-- src/lib/ffmpeg/Interleave.cxx | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index d575a6eb1..b0d9f2c3e 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -523,9 +523,15 @@ FfmpegDecode(DecoderClient &client, InputStream *input, return; } +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 25, 100) + const unsigned channels = codec_context->ch_layout.nb_channels; +#else + const unsigned channels = codec_context->channels; +#endif + const auto audio_format = CheckAudioFormat(codec_context->sample_rate, sample_format, - codec_context->channels); + channels); const SignedSongTime total_time = av_stream.duration != (int64_t)AV_NOPTS_VALUE @@ -635,10 +641,17 @@ FfmpegScanStream(AVFormatContext &format_context, TagHandler &handler) AV_TIME_BASE_Q)); const auto &codec_params = *stream.codecpar; + +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 25, 100) + const unsigned channels = codec_params.ch_layout.nb_channels; +#else + const unsigned channels = codec_params.channels; +#endif + try { handler.OnAudioFormat(CheckAudioFormat(codec_params.sample_rate, ffmpeg_sample_format(AVSampleFormat(codec_params.format)), - codec_params.channels)); + channels)); } catch (...) { } diff --git a/src/lib/ffmpeg/Interleave.cxx b/src/lib/ffmpeg/Interleave.cxx index 4e901315f..47c2a85d8 100644 --- a/src/lib/ffmpeg/Interleave.cxx +++ b/src/lib/ffmpeg/Interleave.cxx @@ -38,7 +38,11 @@ InterleaveFrame(const AVFrame &frame, FfmpegBuffer &buffer) assert(frame.nb_samples > 0); const auto format = AVSampleFormat(frame.format); +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 25, 100) + const unsigned channels = frame.ch_layout.nb_channels; +#else const unsigned channels = frame.channels; +#endif const std::size_t n_frames = frame.nb_samples; int plane_size;