From d055526a401bfde6c8ae67a6250e23a39dbf918d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 22 Nov 2024 13:18:22 -0400 Subject: [PATCH] MT#55283 fix ffmpeg deprecation warning ffmpeg 7.1+ has deprecated direct usage of ->sample_fmts in favour of a call to avcodec_get_supported_config(). Update accordingly. Change-Id: I0fbecbbcf52c38976f3387e34d816d11e1d09480 (cherry picked from commit 65477ac5d5de4bf39684791e6dacf7046724e71b) --- lib/codeclib.c | 20 ++++++++++++++++---- lib/codeclib.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index 5dc9b2779..d1a0ea4fc 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -803,7 +803,13 @@ static const char *avc_decoder_init(decoder_t *dec, const str *extra_opts) { return "failed to open codec context"; } - for (const enum AVSampleFormat *sfmt = codec->sample_fmts; sfmt && *sfmt != -1; sfmt++) +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 0) + avcodec_get_supported_config(dec->avc.avcctx, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **) &dec->avc.sample_fmts, NULL); +#else + dec->avc.sample_fmts = codec->sample_fmts; +#endif + + for (const enum AVSampleFormat *sfmt = dec->avc.sample_fmts; sfmt && *sfmt != -1; sfmt++) cdbg("supported sample format for input codec %s: %s", codec->name, av_get_sample_fmt_name(*sfmt)); @@ -1604,15 +1610,21 @@ static const char *avc_encoder_init(encoder_t *enc, const str *extra_opts) { enc->actual_format = enc->requested_format; +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 0) + avcodec_get_supported_config(enc->avc.avcctx, enc->avc.codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **) &enc->avc.sample_fmts, NULL); +#else + enc->avc.sample_fmts = enc->avc.codec->sample_fmts; +#endif + enc->actual_format.format = -1; - for (const enum AVSampleFormat *sfmt = enc->avc.codec->sample_fmts; sfmt && *sfmt != -1; sfmt++) { + for (const enum AVSampleFormat *sfmt = enc->avc.sample_fmts; sfmt && *sfmt != -1; sfmt++) { cdbg("supported sample format for output codec %s: %s", enc->avc.codec->name, av_get_sample_fmt_name(*sfmt)); if (*sfmt == enc->requested_format.format) enc->actual_format.format = *sfmt; } - if (enc->actual_format.format == -1 && enc->avc.codec->sample_fmts) - enc->actual_format.format = enc->avc.codec->sample_fmts[0]; + if (enc->actual_format.format == -1 && enc->avc.sample_fmts) + enc->actual_format.format = enc->avc.sample_fmts[0]; cdbg("using output sample format %s for codec %s", av_get_sample_fmt_name(enc->actual_format.format), enc->avc.codec->name); diff --git a/lib/codeclib.h b/lib/codeclib.h index 4ee4219ca..8ea5021c2 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -273,6 +273,7 @@ struct decoder_s { struct { AVCodecContext *avcctx; AVPacket *avpkt; + const enum AVSampleFormat *sample_fmts; union { struct { @@ -317,6 +318,7 @@ struct encoder_s { struct { const AVCodec *codec; AVCodecContext *avcctx; + const enum AVSampleFormat *sample_fmts; union { struct {