[PR] avcodec/codec_internal: Put bsfs and reconf in a union (PR #24131)

mkver via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178663986457.59.3798557502305099742@29965ddac10e>
PR #24131 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24131
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24131.patch

Also test the new stuff in avcodec/tests/avcodec.c.


>From bbbd4a27203d900da87cfb78a5e078289e1021cf Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 13 Aug 2026 18:23:25 +0200
Subject: [PATCH 1/3] avcodec/tests/avcodec: Test reconf callback, flags

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/tests/avcodec.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c
index c9afec4eb6..3c0809c489 100644
--- a/libavcodec/tests/avcodec.c
+++ b/libavcodec/tests/avcodec.c
@@ -174,6 +174,8 @@ int main(void){
                 ERR("Encoder %s is both subtitle encoder and not subtitle encoder.");
             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 (codec2->reconf && !(codec->capabilities & AV_CODEC_CAP_RECONF))
+                ERR("Encoder %s has reconf callback without supporting recondiguration.\n");
             if (codec->type == AVMEDIA_TYPE_AUDIO) {
                 if (!codec2->sample_fmts) {
                     av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
@@ -216,7 +218,9 @@ int main(void){
             if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME    |
                                        AV_CODEC_CAP_VARIABLE_FRAME_SIZE |
                                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
-                                       AV_CODEC_CAP_ENCODER_FLUSH))
+                                       AV_CODEC_CAP_ENCODER_FLUSH            |
+                                       AV_CODEC_CAP_RECONF                   |
+                                       AV_CODEC_CAP_ENCODER_RECON_FRAME))
                 ERR("Decoder %s has encoder-only capabilities\n");
             if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE &&
                 codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)
-- 
2.52.0


>From 3393f06db2a1f5bcef40b17d84c0b36f940ba454 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 13 Aug 2026 18:27:16 +0200
Subject: [PATCH 2/3] avcodec/codec_internal: Put bsfs and reconf in a union

Reduces sizeof(FFCodec)

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/codec_internal.h | 22 ++++++++++++----------
 libavcodec/tests/avcodec.c  |  2 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 6422c9996b..7b7bde7cae 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -256,17 +256,19 @@ typedef struct FFCodec {
      */
     void (*flush)(struct AVCodecContext *);
 
-    /**
-     * Reconfigure the encoder
-     * Called by avcodec_encode_reconfigure()
-     */
-    int (*reconf)(struct AVCodecContext *avctx, struct AVDictionary **dict);
+    union {
+        /**
+        * Encoding only. Reconfigure the encoder
+        * Called by avcodec_encode_reconfigure()
+        */
+        int (*reconf)(struct AVCodecContext *avctx, struct AVDictionary **dict);
 
-    /**
-     * Decoding only, a comma-separated list of bitstream filters to apply to
-     * packets before decoding.
-     */
-    const char *bsfs;
+        /**
+        * Decoding only, a comma-separated list of bitstream filters to apply to
+        * packets before decoding.
+        */
+        const char *bsfs;
+    };
 
     /**
      * Array of pointers to hardware configurations supported by the codec,
diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c
index 3c0809c489..8c873e6fcb 100644
--- a/libavcodec/tests/avcodec.c
+++ b/libavcodec/tests/avcodec.c
@@ -172,7 +172,7 @@ int main(void){
         if (is_encoder) {
             if ((codec->type == AVMEDIA_TYPE_SUBTITLE) != (codec2->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB))
                 ERR("Encoder %s is both subtitle encoder and not subtitle encoder.");
-            if (codec2->update_thread_context || codec2->update_thread_context_for_user || codec2->bsfs)
+            if (codec2->update_thread_context || codec2->update_thread_context_for_user)
                 ERR("Encoder %s has decoder-only thread functions or bsf.\n");
             if (codec2->reconf && !(codec->capabilities & AV_CODEC_CAP_RECONF))
                 ERR("Encoder %s has reconf callback without supporting recondiguration.\n");
-- 
2.52.0


>From c38bea8b580a836171e39566b6537c9ce6b7205c Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 13 Aug 2026 18:33:08 +0200
Subject: [PATCH 3/3] avcodec/encode: Remove pointless opt.h inclusion

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/encode.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/encode.h b/libavcodec/encode.h
index 0a9998062a..8cf24558f5 100644
--- a/libavcodec/encode.h
+++ b/libavcodec/encode.h
@@ -21,7 +21,6 @@
 #ifndef AVCODEC_ENCODE_H
 #define AVCODEC_ENCODE_H
 
-#include "libavutil/opt.h"
 #include "libavutil/dict.h"
 #include "libavutil/frame.h"
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.