From 65f118f840b4e258521f42b44079f879ea231ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 30 Sep 2024 21:40:28 +0200 Subject: [PATCH] Fix use of deprecated member variables in video recorder Use the new `avcodec_get_supported_config` function instead of the deprecated `sample_fmts` and `supported_samplerates` members with libavcodec 61.13.100 and newer. See https://github.com/FFmpeg/FFmpeg/blob/76eb3e5ff3a35eff01dd71aca82efcda50c4441f/doc/APIchanges#L53-L56 Closes #9085. --- src/engine/client/video.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/engine/client/video.cpp b/src/engine/client/video.cpp index e4ac9cdfc..d5b914fce 100644 --- a/src/engine/client/video.cpp +++ b/src/engine/client/video.cpp @@ -893,13 +893,23 @@ bool CVideo::AddStream(COutputStream *pStream, AVFormatContext *pFormatContext, switch((*ppCodec)->type) { case AVMEDIA_TYPE_AUDIO: - pContext->sample_fmt = (*ppCodec)->sample_fmts ? (*ppCodec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; - if((*ppCodec)->supported_samplerates) + { + const AVSampleFormat *pSampleFormats = nullptr; + const int *pSampleRates = nullptr; +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) + avcodec_get_supported_config(pContext, *ppCodec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **)&pSampleFormats, nullptr); + avcodec_get_supported_config(pContext, *ppCodec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, (const void **)&pSampleRates, nullptr); +#else + pSampleFormats = (*ppCodec)->sample_fmts; + pSampleRates = (*ppCodec)->supported_samplerates; +#endif + pContext->sample_fmt = pSampleFormats ? pSampleFormats[0] : AV_SAMPLE_FMT_FLTP; + if(pSampleRates) { - pContext->sample_rate = (*ppCodec)->supported_samplerates[0]; - for(int i = 0; (*ppCodec)->supported_samplerates[i]; i++) + pContext->sample_rate = pSampleRates[0]; + for(int i = 0; pSampleRates[i]; i++) { - if((*ppCodec)->supported_samplerates[i] == m_pSound->MixingRate()) + if(pSampleRates[i] == m_pSound->MixingRate()) { pContext->sample_rate = m_pSound->MixingRate(); break; @@ -921,6 +931,7 @@ bool CVideo::AddStream(COutputStream *pStream, AVFormatContext *pFormatContext, pStream->m_pStream->time_base.num = 1; pStream->m_pStream->time_base.den = pContext->sample_rate; break; + } case AVMEDIA_TYPE_VIDEO: pContext->codec_id = CodecId;