Skip to content

Commit

Permalink
MT#55283 fix ffmpeg deprecation warning
Browse files Browse the repository at this point in the history
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 65477ac)
  • Loading branch information
rfuchs committed Dec 3, 2024
1 parent 3bfeee5 commit 7297215
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/codeclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,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));

Expand Down Expand Up @@ -1839,15 +1845,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);

Expand Down
2 changes: 2 additions & 0 deletions lib/codeclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ struct decoder_s {
struct {
AVCodecContext *avcctx;
AVPacket *avpkt;
const enum AVSampleFormat *sample_fmts;

union {
struct {
Expand Down Expand Up @@ -317,6 +318,7 @@ struct encoder_s {
struct {
const AVCodec *codec;
AVCodecContext *avcctx;
const enum AVSampleFormat *sample_fmts;

union {
struct {
Expand Down

0 comments on commit 7297215

Please sign in to comment.