diff mbox series

[FFmpeg-devel,v2,04/17] avcodec/allcodecs: add backcompat for new config API

Message ID 20240408125950.53472-5-ffmpeg@haasn.xyz
State New
Headers show
Series Add avcodec_get_supported_config() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas April 8, 2024, 12:57 p.m. UTC
From: Niklas Haas <git@haasn.dev>

In order to avoid breaking older clients not yet using the new API, we
need to add backwards compatibility for codecs which have switched from
init_static() to get_supported_config().

This function can be removed entirely once the deprecated static fields
are removed.
---
 libavcodec/allcodecs.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb8..a9f1797930a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -916,8 +916,41 @@  static AVOnce av_codec_static_init = AV_ONCE_INIT;
 static void av_codec_init_static(void)
 {
     for (int i = 0; codec_list[i]; i++) {
-        if (codec_list[i]->init_static_data)
-            codec_list[i]->init_static_data((FFCodec*)codec_list[i]);
+        const FFCodec *codec = codec_list[i];
+        if (codec->init_static_data) {
+            codec->init_static_data((FFCodec*) codec);
+            continue;
+        }
+
+        /* Backward compatibility with deprecated public fields */
+        if (!codec->get_supported_config)
+            continue;
+
+FF_DISABLE_DEPRECATION_WARNINGS
+        switch (codec->p.type) {
+        case AVMEDIA_TYPE_VIDEO:
+            codec->get_supported_config(NULL, &codec->p,
+                                        AV_CODEC_CONFIG_PIX_FORMAT, 0,
+                                        (const void **) &codec->p.pix_fmts);
+            codec->get_supported_config(NULL, &codec->p,
+                                        AV_CODEC_CONFIG_FRAME_RATE, 0,
+                                        (const void **) &codec->p.supported_framerates);
+            break;
+        case AVMEDIA_TYPE_AUDIO:
+            codec->get_supported_config(NULL, &codec->p,
+                                        AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
+                                        (const void **) &codec->p.sample_fmts);
+            codec->get_supported_config(NULL, &codec->p,
+                                        AV_CODEC_CONFIG_SAMPLE_RATE, 0,
+                                        (const void **) &codec->p.supported_samplerates);
+            codec->get_supported_config(NULL, &codec->p,
+                                        AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+                                        (const void **) &codec->p.ch_layouts);
+            break;
+        default:
+            break;
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
     }
 }