This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 38221d0ec9d835e42125c4ff9c71214e27049b24 Author: Andreas Rheinhardt <[email protected]> AuthorDate: Thu Jun 4 23:39:48 2026 +0200 Commit: Andreas Rheinhardt <[email protected]> CommitDate: Tue Jun 23 19:15:57 2026 +0200 avcodec/codec: Remove deprecated AVCodec arrays They were deprecated in 3305767560a6303f474fffa3afb10c500059b455 on 2024-09-08. Removing them allows to constify all FFCodecs; furthermore, it allows to use a union of a video-only and a audio-only structure to reduce sizeof(FFCodec). Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/allcodecs.c | 50 +++------------------------------------------ libavcodec/avcodec.c | 4 +--- libavcodec/codec.h | 22 -------------------- libavcodec/codec_internal.h | 29 ++++++++++++++++---------- libavcodec/libaomenc.c | 2 +- libavcodec/libvpxenc.c | 2 +- libavcodec/libx265.c | 2 +- libavcodec/tests/avcodec.c | 29 +++++++++++--------------- libavcodec/tests/encinfo.c | 9 +++++++- 9 files changed, 45 insertions(+), 104 deletions(-) diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index b165a5925d..47eded261f 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -28,8 +28,6 @@ #include <string.h> #include "config.h" -#include "libavutil/thread.h" -#include "avcodec.h" #include "codec.h" #include "codec_id.h" #include "codec_internal.h" @@ -769,7 +767,7 @@ extern const FFCodec ff_pcm_mulaw_at_encoder; extern const FFCodec ff_pcm_mulaw_at_decoder; extern const FFCodec ff_qdmc_at_decoder; extern const FFCodec ff_qdm2_at_decoder; -extern FFCodec ff_libaom_av1_encoder; +extern const FFCodec ff_libaom_av1_encoder; /* preferred over libaribb24 */ extern const FFCodec ff_libaribcaption_decoder; extern const FFCodec ff_libaribb24_decoder; @@ -816,7 +814,7 @@ extern const FFCodec ff_libvorbis_encoder; extern const FFCodec ff_libvorbis_decoder; extern const FFCodec ff_libvpx_vp8_encoder; extern const FFCodec ff_libvpx_vp8_decoder; -extern FFCodec ff_libvpx_vp9_encoder; +extern const FFCodec ff_libvpx_vp9_encoder; extern const FFCodec ff_libvpx_vp9_decoder; extern const FFCodec ff_libvvenc_encoder; /* preferred over libwebp */ @@ -825,7 +823,7 @@ extern const FFCodec ff_libwebp_encoder; extern const FFCodec ff_libx262_encoder; extern const FFCodec ff_libx264_encoder; extern const FFCodec ff_libx264rgb_encoder; -extern FFCodec ff_libx265_encoder; +extern const FFCodec ff_libx265_encoder; extern const FFCodec ff_libxeve_encoder; extern const FFCodec ff_libxevd_decoder; extern const FFCodec ff_libxavs_encoder; @@ -940,53 +938,11 @@ const FFCodec * codec_list[] = { #include "libavcodec/codec_list.c" #endif -static AVOnce av_codec_static_init = AV_ONCE_INIT; -static void av_codec_init_static(void) -{ - int dummy; - for (int i = 0; codec_list[i]; i++) { - /* Backward compatibility with deprecated public fields */ - const FFCodec *codec = codec_list[i]; - if (!codec->get_supported_config) - continue; - -FF_DISABLE_DEPRECATION_WARNINGS - switch (codec->p.type) { - case AVMEDIA_TYPE_VIDEO: - if (!codec->p.pix_fmts) - codec->get_supported_config(NULL, &codec->p, - AV_CODEC_CONFIG_PIX_FORMAT, 0, - (const void **) &codec->p.pix_fmts, - &dummy); - break; - case AVMEDIA_TYPE_AUDIO: - codec->get_supported_config(NULL, &codec->p, - AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, - (const void **) &codec->p.sample_fmts, - &dummy); - codec->get_supported_config(NULL, &codec->p, - AV_CODEC_CONFIG_SAMPLE_RATE, 0, - (const void **) &codec->p.supported_samplerates, - &dummy); - codec->get_supported_config(NULL, &codec->p, - AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, - (const void **) &codec->p.ch_layouts, - &dummy); - break; - default: - break; - } -FF_ENABLE_DEPRECATION_WARNINGS - } -} - const AVCodec *av_codec_iterate(void **opaque) { uintptr_t i = (uintptr_t)*opaque; const FFCodec *c = codec_list[i]; - ff_thread_once(&av_codec_static_init, av_codec_init_static); - if (c) { *opaque = (void*)(i + 1); return &c->p; diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 23ccac1a85..5320dfc06c 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -726,7 +726,7 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) do { \ if (codec->type != (allowed_type)) \ return AVERROR(EINVAL); \ - const field_type *ptr = codec->field; \ + const field_type *ptr = codec2->field; \ *out_configs = ptr; \ if (ptr) { \ for (int i = 0;; i++) { \ @@ -772,7 +772,6 @@ int ff_default_get_supported_config(const AVCodecContext *avctx, const FFCodec *codec2 = ffcodec(codec); switch (config) { -FF_DISABLE_DEPRECATION_WARNINGS case AV_CODEC_CONFIG_PIX_FORMAT: WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, pix_fmts, pix_fmt, enum AVPixelFormat, pix_fmt == AV_PIX_FMT_NONE); case AV_CODEC_CONFIG_FRAME_RATE: @@ -783,7 +782,6 @@ FF_DISABLE_DEPRECATION_WARNINGS WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, sample_fmts, sample_fmt, enum AVSampleFormat, sample_fmt == AV_SAMPLE_FMT_NONE); case AV_CODEC_CONFIG_CHANNEL_LAYOUT: WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, ch_layouts, ch_layout, AVChannelLayout, ch_layout.nb_channels == 0); -FF_ENABLE_DEPRECATION_WARNINGS case AV_CODEC_CONFIG_COLOR_RANGE: if (codec->type != AVMEDIA_TYPE_VIDEO) diff --git a/libavcodec/codec.h b/libavcodec/codec.h index f509e5d94e..0966d2e616 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -27,11 +27,8 @@ #include "libavutil/hwcontext.h" #include "libavutil/log.h" #include "libavutil/pixfmt.h" -#include "libavutil/rational.h" -#include "libavutil/samplefmt.h" #include "libavcodec/codec_id.h" -#include "libavcodec/version_major.h" /** * @addtogroup lavc_core @@ -191,18 +188,6 @@ typedef struct AVCodec { int capabilities; uint8_t max_lowres; ///< maximum value for lowres supported by the decoder - /** - * Deprecated codec capabilities. - */ - attribute_deprecated - const AVRational *supported_framerates; ///< @deprecated use avcodec_get_supported_config() - attribute_deprecated - const enum AVPixelFormat *pix_fmts; ///< @deprecated use avcodec_get_supported_config() - attribute_deprecated - const int *supported_samplerates; ///< @deprecated use avcodec_get_supported_config() - attribute_deprecated - const enum AVSampleFormat *sample_fmts; ///< @deprecated use avcodec_get_supported_config() - const AVClass *priv_class; ///< AVClass for the private context const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN} @@ -217,13 +202,6 @@ typedef struct AVCodec { * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>"). */ const char *wrapper_name; - - /** - * Array of supported channel layouts, terminated with a zeroed layout. - * @deprecated use avcodec_get_supported_config() - */ - attribute_deprecated - const AVChannelLayout *ch_layouts; } AVCodec; /** diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index 720788210d..5cb65a06e2 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -285,6 +285,23 @@ typedef struct FFCodec { unsigned flags, const void **out_configs, int *out_num_configs); +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + struct { +#else + union { +#endif + /// Video-only fields + struct { + const AVRational *supported_framerates; + const enum AVPixelFormat *pix_fmts; + }; + /// Audio-only fields + struct { + const AVChannelLayout *ch_layouts; + const int *supported_samplerates; + const enum AVSampleFormat *sample_fmts; + }; + }; } FFCodec; static av_always_inline const FFCodec *ffcodec(const AVCodec *codec) @@ -369,14 +386,6 @@ int ff_default_get_supported_config(const struct AVCodecContext *avctx, .cb_type = FF_CODEC_CB_TYPE_RECEIVE_PACKET, \ .cb.receive_packet = (func) -#ifdef __clang__ -#define DISABLE_DEPRECATION_WARNINGS FF_DISABLE_DEPRECATION_WARNINGS -#define ENABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS -#else -#define DISABLE_DEPRECATION_WARNINGS -#define ENABLE_DEPRECATION_WARNINGS -#endif - #define CODEC_CH_LAYOUTS(...) CODEC_CH_LAYOUTS_ARRAY(((const AVChannelLayout[]) { __VA_ARGS__, { 0 } })) #define CODEC_CH_LAYOUTS_ARRAY(array) CODEC_ARRAY(ch_layouts, (array)) @@ -393,8 +402,6 @@ int ff_default_get_supported_config(const struct AVCodecContext *avctx, #define CODEC_PIXFMTS_ARRAY(array) CODEC_ARRAY(pix_fmts, (array)) #define CODEC_ARRAY(field, array) \ - DISABLE_DEPRECATION_WARNINGS \ - .p.field = (array) \ - ENABLE_DEPRECATION_WARNINGS + .field = (array) \ #endif /* AVCODEC_CODEC_INTERNAL_H */ diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index b6877401f0..7cabea3003 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -1622,7 +1622,7 @@ static const AVClass class_aom = { .version = LIBAVUTIL_VERSION_INT, }; -FFCodec ff_libaom_av1_encoder = { +const FFCodec ff_libaom_av1_encoder = { .p.name = "libaom-av1", CODEC_LONG_NAME("libaom AV1"), .p.type = AVMEDIA_TYPE_VIDEO, diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 963fa6c619..942e28dd73 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -2214,7 +2214,7 @@ static const AVClass class_vp9 = { .version = LIBAVUTIL_VERSION_INT, }; -FFCodec ff_libvpx_vp9_encoder = { +const FFCodec ff_libvpx_vp9_encoder = { .p.name = "libvpx-vp9", CODEC_LONG_NAME("libvpx VP9"), .p.type = AVMEDIA_TYPE_VIDEO, diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 7d488c0f4b..c5e6b8c150 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -1081,7 +1081,7 @@ static const FFCodecDefault x265_defaults[] = { { NULL }, }; -FFCodec ff_libx265_encoder = { +const FFCodec ff_libx265_encoder = { .p.name = "libx265", CODEC_LONG_NAME("libx265 H.265 / HEVC"), .p.type = AVMEDIA_TYPE_VIDEO, diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c index ea7e1bada5..c9afec4eb6 100644 --- a/libavcodec/tests/avcodec.c +++ b/libavcodec/tests/avcodec.c @@ -58,7 +58,7 @@ static int priv_data_size_wrong(const FFCodec *codec) #define ARRAY_CHECK(field, var, type, is_sentinel, check, sentinel_check) \ do { \ - const type *ptr = codec->field; \ + const type *ptr = codec2->field; \ if (!ptr) \ break; \ type var = *ptr; \ @@ -102,17 +102,16 @@ int main(void){ ERR_EXT("Codec %s has unsupported type %s\n", get_type_string(codec->type)); if (codec->type != AVMEDIA_TYPE_AUDIO) { -FF_DISABLE_DEPRECATION_WARNINGS - if (codec->ch_layouts || codec->sample_fmts || - codec->supported_samplerates) +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + if (codec2->ch_layouts || codec2->sample_fmts || + codec2->supported_samplerates) ERR("Non-audio codec %s has audio-only fields set\n"); -FF_ENABLE_DEPRECATION_WARNINGS +#endif if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) ERR("Non-audio codec %s has audio-only capabilities set\n"); } else { -FF_DISABLE_DEPRECATION_WARNINGS ARRAY_CHECK(supported_samplerates, sample_rate, int, sample_rate == 0, sample_rate > 0, 1); ARRAY_CHECK(sample_fmts, sample_fmt, enum AVSampleFormat, sample_fmt == AV_SAMPLE_FMT_NONE, @@ -120,14 +119,14 @@ FF_DISABLE_DEPRECATION_WARNINGS static const AVChannelLayout zero_channel_layout = { 0 }; ARRAY_CHECK(ch_layouts, ch_layout, AVChannelLayout, ch_layout.nb_channels == 0, av_channel_layout_check(&ch_layout), !memcmp(ptr, &zero_channel_layout, sizeof(ch_layout))); -FF_ENABLE_DEPRECATION_WARNINGS } if (codec->type != AVMEDIA_TYPE_VIDEO) { -FF_DISABLE_DEPRECATION_WARNINGS - if (codec->pix_fmts || codec->supported_framerates || - codec2->color_ranges || codec2->alpha_modes) + if (codec2->color_ranges || +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + codec2->pix_fmts || codec2->supported_framerates || +#endif + codec2->alpha_modes) ERR("Non-video codec %s has video-only fields set\n"); -FF_ENABLE_DEPRECATION_WARNINGS if (codec2->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING) ERR("Non-video codec %s exports cropping\n"); } @@ -176,8 +175,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (codec2->update_thread_context || codec2->update_thread_context_for_user || codec2->bsfs) ERR("Encoder %s has decoder-only thread functions or bsf.\n"); if (codec->type == AVMEDIA_TYPE_AUDIO) { -FF_DISABLE_DEPRECATION_WARNINGS - if (!codec->sample_fmts) { + if (!codec2->sample_fmts) { av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name); ret = 1; } @@ -186,7 +184,6 @@ FF_DISABLE_DEPRECATION_WARNINGS av_pix_fmt_desc_get(pix_fmt), 1); ARRAY_CHECK(supported_framerates, framerate, AVRational, framerate.num == 0, framerate.num > 0 && framerate.den > 0, framerate.den == 0); -FF_ENABLE_DEPRECATION_WARNINGS } if (codec2->caps_internal & (FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_SETS_PKT_DTS | @@ -225,10 +222,8 @@ FF_ENABLE_DEPRECATION_WARNINGS codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS) ERR("Decoder %s is marked as setting pkt_dts when it doesn't have" "any effect\n"); -FF_DISABLE_DEPRECATION_WARNINGS - if (codec->type == AVMEDIA_TYPE_VIDEO && (codec->pix_fmts || codec->supported_framerates)) + if (codec->type == AVMEDIA_TYPE_VIDEO && (codec2->pix_fmts || codec2->supported_framerates)) ERR("Decoder %s sets pix_fmts or supported_framerates.\n"); -FF_ENABLE_DEPRECATION_WARNINGS } if (priv_data_size_wrong(codec2)) ERR_EXT("Private context of codec %s is impossibly-sized (size %d).", diff --git a/libavcodec/tests/encinfo.c b/libavcodec/tests/encinfo.c index a24d769cd3..32bd3ec2bb 100644 --- a/libavcodec/tests/encinfo.c +++ b/libavcodec/tests/encinfo.c @@ -60,7 +60,14 @@ int main(int argc, char **argv) return AVERROR(ENOMEM); ctx->sample_rate = sample_rate; - ctx->sample_fmt = codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_S16; + const void *sample_fmts; + ret = avcodec_get_supported_config(ctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, &sample_fmts, NULL); + if (ret < 0) { + fprintf(stderr, "avcodec_get_supported_config failed: %d\n", ret); + avcodec_free_context(&ctx); + return 1; + } + ctx->sample_fmt = sample_fmts ? *(const enum AVSampleFormat*)sample_fmts : AV_SAMPLE_FMT_S16; av_channel_layout_default(&ctx->ch_layout, channels); ret = avcodec_open2(ctx, codec, NULL); _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
