PR #26207 opened by olivierayache
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26207
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26207.patch

# Summary of changes

By working on CBCS implementation for mov muxer with @stevenliu on 
https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25965, we discuss about the 
possibility to improve CBS support in libavformat to be able to use bitstream 
parsing for other codecs than AV1 directly in `libavformat`. 

The following PR integrates CBS for H264 and HEVC in `libavformat`. As CBS is 
already build in `libavcodec`, the PR needs to create new symbol especially for 
libavformat by using the already existing approach based on macro CBS_FUNC.



>From f3a222424173491cb737d2ac90f8d07249198410 Mon Sep 17 00:00:00 2001
From: Olivier Ayache <[email protected]>
Date: Thu, 19 Nov 2026 19:06:08 +0100
Subject: [PATCH 1/3] avformat/cbs: Enable H264 & HEVC

---
 libavformat/cbs_h264.c  | 20 ++++++++++++++++++++
 libavformat/cbs_h264.h  | 26 ++++++++++++++++++++++++++
 libavformat/cbs_h2645.c | 20 ++++++++++++++++++++
 libavformat/cbs_h2645.h | 26 ++++++++++++++++++++++++++
 libavformat/cbs_h265.c  | 20 ++++++++++++++++++++
 libavformat/cbs_h265.h  | 26 ++++++++++++++++++++++++++
 libavformat/cbs_sei.c   | 20 ++++++++++++++++++++
 libavformat/cbs_sei.h   | 26 ++++++++++++++++++++++++++
 8 files changed, 184 insertions(+)
 create mode 100644 libavformat/cbs_h264.c
 create mode 100644 libavformat/cbs_h264.h
 create mode 100644 libavformat/cbs_h2645.c
 create mode 100644 libavformat/cbs_h2645.h
 create mode 100644 libavformat/cbs_h265.c
 create mode 100644 libavformat/cbs_h265.h
 create mode 100644 libavformat/cbs_sei.c
 create mode 100644 libavformat/cbs_sei.h

diff --git a/libavformat/cbs_h264.c b/libavformat/cbs_h264.c
new file mode 100644
index 00000000000..d0f13b94fc6
--- /dev/null
+++ b/libavformat/cbs_h264.c
@@ -0,0 +1,20 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cbs_h264.h"
+#include "libavcodec/cbs_h264.c"
diff --git a/libavformat/cbs_h264.h b/libavformat/cbs_h264.h
new file mode 100644
index 00000000000..ef99e14405c
--- /dev/null
+++ b/libavformat/cbs_h264.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_CBS_H264_H
+#define AVFORMAT_CBS_H264_H
+
+#include "cbs.h"
+
+#include "libavcodec/cbs_h264.h"
+
+#endif /* AVFORMAT_CBS_H264_H */
diff --git a/libavformat/cbs_h2645.c b/libavformat/cbs_h2645.c
new file mode 100644
index 00000000000..50e78074fe0
--- /dev/null
+++ b/libavformat/cbs_h2645.c
@@ -0,0 +1,20 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cbs_h265.h"
+#include "libavcodec/cbs_h2645.c"
diff --git a/libavformat/cbs_h2645.h b/libavformat/cbs_h2645.h
new file mode 100644
index 00000000000..18c9b47b4cf
--- /dev/null
+++ b/libavformat/cbs_h2645.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_CBS_H2645_H
+#define AVFORMAT_CBS_H2645_H
+
+#include "cbs.h"
+
+#include "libavcodec/cbs_h2645.h"
+
+#endif /* AVFORMAT_CBS_H2645_H */
diff --git a/libavformat/cbs_h265.c b/libavformat/cbs_h265.c
new file mode 100644
index 00000000000..c616819e4c2
--- /dev/null
+++ b/libavformat/cbs_h265.c
@@ -0,0 +1,20 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cbs_h265.h"
+#include "libavcodec/cbs_h265.c"
diff --git a/libavformat/cbs_h265.h b/libavformat/cbs_h265.h
new file mode 100644
index 00000000000..ca2e7d461e3
--- /dev/null
+++ b/libavformat/cbs_h265.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_CBS_H265_H
+#define AVFORMAT_CBS_H265_H
+
+#include "cbs.h"
+
+#include "libavcodec/cbs_h265.h"
+
+#endif /* AVFORMAT_CBS_H265_H */
diff --git a/libavformat/cbs_sei.c b/libavformat/cbs_sei.c
new file mode 100644
index 00000000000..fafbc736532
--- /dev/null
+++ b/libavformat/cbs_sei.c
@@ -0,0 +1,20 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cbs_sei.h"
+#include "libavcodec/cbs_sei.c"
diff --git a/libavformat/cbs_sei.h b/libavformat/cbs_sei.h
new file mode 100644
index 00000000000..fe3eb9e39a5
--- /dev/null
+++ b/libavformat/cbs_sei.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_CBS_SEI_H
+#define AVFORMAT_CBS_SEI_H
+
+#include "cbs.h"
+
+#include "libavcodec/cbs_sei.h"
+
+#endif /* AVFORMAT_CBS_SEI_H */
-- 
2.54.1


>From 9e3b187422448474602f99c343b86f5971bd2912 Mon Sep 17 00:00:00 2001
From: Olivier Ayache <[email protected]>
Date: Thu, 19 Nov 2026 19:11:46 +0100
Subject: [PATCH 2/3] avformat/cbs: Use CBS_FUNC to generate the correct method
 name between libavcodec and libavformat

---
 libavcodec/cbs_h264.c                 | 52 ++++++++++++-------------
 libavcodec/cbs_h2645.c                | 20 +++++-----
 libavcodec/cbs_h2645.h                | 18 ++++-----
 libavcodec/cbs_h265.c                 | 50 ++++++++++++------------
 libavcodec/cbs_h265_syntax_template.c |  4 +-
 libavcodec/cbs_sei.c                  | 56 +++++++++++++--------------
 libavcodec/cbs_sei.h                  | 26 ++++++-------
 libavcodec/cbs_sei_syntax_template.c  |  8 ++--
 8 files changed, 117 insertions(+), 117 deletions(-)

diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c
index 8b5a7c71fa5..4f20d8309f5 100644
--- a/libavcodec/cbs_h264.c
+++ b/libavcodec/cbs_h264.c
@@ -27,7 +27,7 @@
 #include "get_bits.h"
 
 #define HEADER(name) do { \
-        ff_cbs_trace_header(ctx, name); \
+        CBS_FUNC(trace_header)(ctx, name); \
     } while (0)
 
 #define CHECK(call) do { \
@@ -39,9 +39,9 @@
 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
 #define FUNC_H264(name) FUNC_NAME1(READWRITE, h264, name)
-#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## 
name
-#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
-#define FUNC_SEI(name)  FUNC_NAME1_EXPORT(READWRITE, sei,  name)
+#define FUNC_NAME2_EXPORT(prefix, rw, codec, name) ff_ ## prefix ## _ ## codec 
## _ ## rw ## _ ## name
+#define FUNC_NAME1_EXPORT(prefix, rw, codec, name) FUNC_NAME2_EXPORT(prefix, 
rw, codec, name)
+#define FUNC_SEI(name)  FUNC_NAME1_EXPORT(CBS_PREFIX, READWRITE, sei,  name)
 
 #define SEI_FUNC(name, args) \
 static int FUNC_H264(name) args;  \
@@ -94,34 +94,34 @@ static int FUNC_H264(name) args
 
 #define ub(width, name) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, #name, \
                                           &value)); \
         current->name = value; \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
                                    SUBSCRIPTS(subs, __VA_ARGS__), \
                                    &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_ue_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_se_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
@@ -132,7 +132,7 @@ static int FUNC_H264(name) args
         current->name = value; \
     } while (0)
 
-#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
+#define more_rbsp_data(var) ((var) = CBS_FUNC(h2645_read_more_rbsp_data)(rw))
 
 #define bit_position(rw)   (get_bits_count(rw))
 #define byte_alignment(rw) (get_bits_count(rw) % 8)
@@ -172,30 +172,30 @@ static int FUNC_H264(name) args
 
 #define ub(width, name) do { \
         uint32_t value = current->name; \
-        CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
                                            value)); \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
                                     SUBSCRIPTS(subs, __VA_ARGS__), \
                                     value, range_min, range_max)); \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_ue_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_se_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
@@ -305,7 +305,7 @@ static int cbs_h264_split_fragment(CodedBitstreamContext 
*ctx,
             av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS 
array.\n");
             return err;
         }
-        err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
+        err = CBS_FUNC(h2645_fragment_add_nals)(ctx, frag, 
&h2645->read_packet);
         if (err < 0)
             return err;
 
@@ -330,7 +330,7 @@ static int cbs_h264_split_fragment(CodedBitstreamContext 
*ctx,
             av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS 
array.\n");
             return err;
         }
-        err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
+        err = CBS_FUNC(h2645_fragment_add_nals)(ctx, frag, 
&h2645->read_packet);
         if (err < 0)
             return err;
 
@@ -350,7 +350,7 @@ static int cbs_h264_split_fragment(CodedBitstreamContext 
*ctx,
         if (err < 0)
             return err;
 
-        err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
+        err = CBS_FUNC(h2645_fragment_add_nals)(ctx, frag, 
&h2645->read_packet);
         if (err < 0)
             return err;
     }
@@ -365,7 +365,7 @@ static int cbs_h264_replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
     CodedBitstreamH264Context *priv = ctx->priv_data; \
     H264Raw ## ps_name *ps_var = unit->content; \
     unsigned int id = ps_var->id_element; \
-    int err = ff_cbs_make_unit_refcounted(ctx, unit); \
+    int err = CBS_FUNC(make_unit_refcounted)(ctx, unit); \
     if (err < 0) \
         return err; \
     if (priv->ps_var[id] == priv->active_ ## ps_var) \
@@ -388,7 +388,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
     if (err < 0)
         return err;
 
-    err = ff_cbs_alloc_unit_content(ctx, unit);
+    err = CBS_FUNC(alloc_unit_content)(ctx, unit);
     if (err < 0)
         return err;
 
@@ -440,7 +440,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
             if (err < 0)
                 return err;
 
-            if (!ff_cbs_h2645_read_more_rbsp_data(&gbc))
+            if (!CBS_FUNC(h2645_read_more_rbsp_data)(&gbc))
                 return AVERROR_INVALIDDATA;
 
             pos = get_bits_count(&gbc);
@@ -553,7 +553,7 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext 
*ctx,
                 return err;
 
             if (slice->data) {
-                err = ff_cbs_h2645_write_slice_data(ctx, pbc, slice->data,
+                err = CBS_FUNC(h2645_write_slice_data)(ctx, pbc, slice->data,
                                                  slice->data_size,
                                                  slice->data_bit_start);
                 if (err < 0)
@@ -696,7 +696,7 @@ static av_cold void cbs_h264_close(CodedBitstreamContext 
*ctx)
 static void cbs_h264_free_sei(AVRefStructOpaque unused, void *content)
 {
     H264RawSEI *sei = content;
-    ff_cbs_sei_free_message_list(&sei->message_list);
+    CBS_FUNC(sei_free_message_list)(&sei->message_list);
 }
 
 static CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = {
@@ -719,7 +719,7 @@ static CodedBitstreamUnitTypeDescriptor 
cbs_h264_unit_types[] = {
     CBS_UNIT_TYPE_END_OF_LIST
 };
 
-const CodedBitstreamType ff_cbs_type_h264 = {
+const CodedBitstreamType CBS_FUNC(type_h264) = {
     .codec_id          = AV_CODEC_ID_H264,
 
     .priv_data_size    = sizeof(CodedBitstreamH264Context),
@@ -730,7 +730,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
     .read_unit         = &cbs_h264_read_nal_unit,
     .write_unit        = &cbs_h264_write_nal_unit,
     .discarded_unit    = &cbs_h264_discarded_nal_unit,
-    .assemble_fragment = &ff_cbs_h2645_assemble_fragment,
+    .assemble_fragment = &CBS_FUNC(h2645_assemble_fragment),
 
     .flush             = &cbs_h264_flush,
     .close             = &cbs_h264_close,
@@ -741,7 +741,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
     .read  = cbs_ ## codec ## _read_  ## name ## _internal, \
     .write = cbs_ ## codec ## _write_ ## name ## _internal
 
-const SEIMessageTypeDescriptor ff_cbs_sei_h264_types[] = {
+const SEIMessageTypeDescriptor CBS_FUNC(sei_h264_types)[] = {
     {
         SEI_TYPE_BUFFERING_PERIOD,
         1, 0,
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 653e4117a21..de47c11310f 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -30,7 +30,7 @@
 
 #include "hevc/hevc.h"
 
-int ff_cbs_h2645_payload_extension_present(GetBitContext *gbc, uint32_t 
payload_size,
+int CBS_FUNC(h2645_payload_extension_present)(GetBitContext *gbc, uint32_t 
payload_size,
                                              int cur_pos)
 {
     int bits_left = payload_size * 8 - cur_pos;
@@ -38,7 +38,7 @@ int ff_cbs_h2645_payload_extension_present(GetBitContext 
*gbc, uint32_t payload_
             (bits_left > 7 || show_bits(gbc, bits_left) & 
MAX_UINT_BITS(bits_left - 1)));
 }
 
-int ff_cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_ue_golomb)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                               const char *name, const int *subscripts,
                               uint32_t *write_to,
                               uint32_t range_min, uint32_t range_max)
@@ -87,7 +87,7 @@ int ff_cbs_read_ue_golomb(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
     return 0;
 }
 
-int ff_cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_se_golomb)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                               const char *name, const int *subscripts,
                               int32_t *write_to,
                               int32_t range_min, int32_t range_max)
@@ -142,7 +142,7 @@ int ff_cbs_read_se_golomb(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
     return 0;
 }
 
-int ff_cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_ue_golomb)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                const char *name, const int *subscripts,
                                uint32_t value,
                                uint32_t range_min, uint32_t range_max)
@@ -174,7 +174,7 @@ int ff_cbs_write_ue_golomb(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
     return 0;
 }
 
-int ff_cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_se_golomb)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                const char *name, const int *subscripts,
                                int32_t value,
                                int32_t range_min, int32_t range_max)
@@ -214,7 +214,7 @@ int ff_cbs_write_se_golomb(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
     return 0;
 }
 
-int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
+int CBS_FUNC(h2645_read_more_rbsp_data)(GetBitContext *gbc)
 {
     int bits_left = get_bits_left(gbc);
     if (bits_left > 8)
@@ -226,7 +226,7 @@ int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
     return 0;
 }
 
-int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_fragment_add_nals)(CodedBitstreamContext *ctx,
                                        CodedBitstreamFragment *frag,
                                        const H2645Packet *packet)
 {
@@ -253,7 +253,7 @@ int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext 
*ctx,
         ref = (nal->data == nal->raw_data) ? frag->data_ref
                                            : packet->rbsp.rbsp_buffer_ref;
 
-        err = ff_cbs_append_unit_data(frag, nal->type,
+        err = CBS_FUNC(append_unit_data)(frag, nal->type,
                             (uint8_t*)nal->data, size, ref);
         if (err < 0)
             return err;
@@ -262,7 +262,7 @@ int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext 
*ctx,
     return 0;
 }
 
-int ff_cbs_h2645_write_slice_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_write_slice_data)(CodedBitstreamContext *ctx,
                                       PutBitContext *pbc, const uint8_t *data,
                                       size_t data_size, int data_bit_start)
 {
@@ -320,7 +320,7 @@ int ff_cbs_h2645_write_slice_data(CodedBitstreamContext 
*ctx,
     return 0;
 }
 
-int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_assemble_fragment)(CodedBitstreamContext *ctx,
                                        CodedBitstreamFragment *frag)
 {
     uint8_t *data;
diff --git a/libavcodec/cbs_h2645.h b/libavcodec/cbs_h2645.h
index 4b11845644c..8a44b75ec3c 100644
--- a/libavcodec/cbs_h2645.h
+++ b/libavcodec/cbs_h2645.h
@@ -36,41 +36,41 @@ typedef struct CodedBitstreamH2645Context {
 struct GetBitContext;
 struct PutBitContext;
 
-int ff_cbs_read_ue_golomb(CodedBitstreamContext *ctx, struct GetBitContext 
*gbc,
+int CBS_FUNC(read_ue_golomb)(CodedBitstreamContext *ctx, struct GetBitContext 
*gbc,
                           const char *name, const int *subscripts,
                           uint32_t *write_to,
                           uint32_t range_min, uint32_t range_max);
-int ff_cbs_read_se_golomb(CodedBitstreamContext *ctx, struct GetBitContext 
*gbc,
+int CBS_FUNC(read_se_golomb)(CodedBitstreamContext *ctx, struct GetBitContext 
*gbc,
                           const char *name, const int *subscripts,
                           int32_t *write_to,
                           int32_t range_min, int32_t range_max);
-int ff_cbs_write_ue_golomb(CodedBitstreamContext *ctx, struct PutBitContext 
*pbc,
+int CBS_FUNC(write_ue_golomb)(CodedBitstreamContext *ctx, struct PutBitContext 
*pbc,
                            const char *name, const int *subscripts,
                            uint32_t value,
                            uint32_t range_min, uint32_t range_max);
-int ff_cbs_write_se_golomb(CodedBitstreamContext *ctx, struct PutBitContext 
*pbc,
+int CBS_FUNC(write_se_golomb)(CodedBitstreamContext *ctx, struct PutBitContext 
*pbc,
                            const char *name, const int *subscripts,
                            int32_t value,
                            int32_t range_min, int32_t range_max);
 
-int ff_cbs_h2645_read_more_rbsp_data(struct GetBitContext *gbc);
+int CBS_FUNC(h2645_read_more_rbsp_data)(struct GetBitContext *gbc);
 
-int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_fragment_add_nals)(CodedBitstreamContext *ctx,
                                    CodedBitstreamFragment *frag,
                                    const H2645Packet *packet);
 
-int ff_cbs_h2645_write_slice_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_write_slice_data)(CodedBitstreamContext *ctx,
                                   struct PutBitContext *pbc, const uint8_t 
*data,
                                   size_t data_size, int data_bit_start);
 
-int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
+int CBS_FUNC(h2645_assemble_fragment)(CodedBitstreamContext *ctx,
                                    CodedBitstreamFragment *frag);
 
 /**
  * payload_extension_present() - true if we are before the last 1-bit
  * in the payload structure, which must be in the last byte.
  */
-int ff_cbs_h2645_payload_extension_present(struct GetBitContext *gbc, uint32_t 
payload_size,
+int CBS_FUNC(h2645_payload_extension_present)(struct GetBitContext *gbc, 
uint32_t payload_size,
                                            int cur_pos);
 
 #endif /* AVCODEC_CBS_H2645_H */
diff --git a/libavcodec/cbs_h265.c b/libavcodec/cbs_h265.c
index 5d6718dfa13..998436580bc 100644
--- a/libavcodec/cbs_h265.c
+++ b/libavcodec/cbs_h265.c
@@ -37,7 +37,7 @@ static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps,
 }
 
 #define HEADER(name) do { \
-        ff_cbs_trace_header(ctx, name); \
+        CBS_FUNC(trace_header)(ctx, name); \
     } while (0)
 
 #define CHECK(call) do { \
@@ -49,9 +49,9 @@ static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps,
 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
 #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
-#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## 
name
-#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
-#define FUNC_SEI(name)  FUNC_NAME1_EXPORT(READWRITE, sei,  name)
+#define FUNC_NAME2_EXPORT(prefix, rw, codec, name) ff_ ## prefix ## _ ## codec 
## _ ## rw ## _ ## name
+#define FUNC_NAME1_EXPORT(prefix, rw, codec, name) FUNC_NAME2_EXPORT(prefix, 
rw, codec, name)
+#define FUNC_SEI(name)  FUNC_NAME1_EXPORT(CBS_PREFIX, READWRITE, sei,  name)
 
 #define SEI_FUNC(name, args) \
 static int FUNC_H265(name) args;  \
@@ -104,34 +104,34 @@ static int FUNC_H265(name) args
 
 #define ub(width, name) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, #name, \
                                           &value)); \
         current->name = value; \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
                                    SUBSCRIPTS(subs, __VA_ARGS__), \
                                    &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_ue_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_se_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
@@ -142,7 +142,7 @@ static int FUNC_H265(name) args
         current->name = value; \
     } while (0)
 
-#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
+#define more_rbsp_data(var) ((var) = CBS_FUNC(h2645_read_more_rbsp_data)(rw))
 
 #define bit_position(rw)   (get_bits_count(rw))
 #define byte_alignment(rw) (get_bits_count(rw) % 8)
@@ -182,30 +182,30 @@ static int FUNC_H265(name) args
 
 #define ub(width, name) do { \
         uint32_t value = current->name; \
-        CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
                                            value)); \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
                                     SUBSCRIPTS(subs, __VA_ARGS__), \
                                     value, range_min, range_max)); \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_ue_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_se_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
@@ -320,7 +320,7 @@ static int cbs_h265_split_fragment(CodedBitstreamContext 
*ctx,
                        i, nb_nals, nal_unit_type);
                 return err;
             }
-            err = ff_cbs_h2645_fragment_add_nals(ctx, frag, 
&h2645->read_packet);
+            err = CBS_FUNC(h2645_fragment_add_nals)(ctx, frag, 
&h2645->read_packet);
             if (err < 0)
                 return err;
         }
@@ -336,7 +336,7 @@ static int cbs_h265_split_fragment(CodedBitstreamContext 
*ctx,
         if (err < 0)
             return err;
 
-        err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
+        err = CBS_FUNC(h2645_fragment_add_nals)(ctx, frag, 
&h2645->read_packet);
         if (err < 0)
             return err;
     }
@@ -351,7 +351,7 @@ static int cbs_h265_replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
     CodedBitstreamH265Context *priv = ctx->priv_data; \
     H265Raw## ps_name *ps_var = unit->content; \
     unsigned int id = ps_var->id_element; \
-    int err = ff_cbs_make_unit_refcounted(ctx, unit); \
+    int err = CBS_FUNC(make_unit_refcounted)(ctx, unit); \
     if (err < 0) \
         return err; \
     if (priv->ps_var[id] == priv->active_ ## ps_var) \
@@ -375,7 +375,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
     if (err < 0)
         return err;
 
-    err = ff_cbs_alloc_unit_content(ctx, unit);
+    err = CBS_FUNC(alloc_unit_content)(ctx, unit);
     if (err < 0)
         return err;
 
@@ -445,7 +445,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
             if (err < 0)
                 return err;
 
-            if (!ff_cbs_h2645_read_more_rbsp_data(&gbc))
+            if (!CBS_FUNC(h2645_read_more_rbsp_data)(&gbc))
                 return AVERROR_INVALIDDATA;
 
             pos = get_bits_count(&gbc);
@@ -567,7 +567,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext 
*ctx,
                 return err;
 
             if (slice->data) {
-                err = ff_cbs_h2645_write_slice_data(ctx, pbc, slice->data,
+                err = CBS_FUNC(h2645_write_slice_data)(ctx, pbc, slice->data,
                                                  slice->data_size,
                                                  slice->data_bit_start);
                 if (err < 0)
@@ -721,7 +721,7 @@ static av_cold void cbs_h265_close(CodedBitstreamContext 
*ctx)
 static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
 {
     H265RawSEI *sei = content;
-    ff_cbs_sei_free_message_list(&sei->message_list);
+    CBS_FUNC(sei_free_message_list)(&sei->message_list);
 }
 
 static CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = {
@@ -761,7 +761,7 @@ static CodedBitstreamUnitTypeDescriptor 
cbs_h265_unit_types[] = {
     .read  = cbs_ ## codec ## _read_  ## name ## _internal, \
     .write = cbs_ ## codec ## _write_ ## name ## _internal
 
-const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[] = {
+const SEIMessageTypeDescriptor CBS_FUNC(sei_h265_types)[] = {
     {
         SEI_TYPE_BUFFERING_PERIOD,
         1, 0,
@@ -831,7 +831,7 @@ const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[] = {
     SEI_MESSAGE_TYPE_END
 };
 
-const CodedBitstreamType ff_cbs_type_h265 = {
+const CodedBitstreamType CBS_FUNC(type_h265) = {
     .codec_id          = AV_CODEC_ID_HEVC,
 
     .priv_data_size    = sizeof(CodedBitstreamH265Context),
@@ -842,7 +842,7 @@ const CodedBitstreamType ff_cbs_type_h265 = {
     .read_unit         = &cbs_h265_read_nal_unit,
     .write_unit        = &cbs_h265_write_nal_unit,
     .discarded_unit    = &cbs_h265_discarded_nal_unit,
-    .assemble_fragment = &ff_cbs_h2645_assemble_fragment,
+    .assemble_fragment = &CBS_FUNC(h2645_assemble_fragment),
 
     .flush             = &cbs_h265_flush,
     .close             = &cbs_h265_close,
diff --git a/libavcodec/cbs_h265_syntax_template.c 
b/libavcodec/cbs_h265_syntax_template.c
index cf4758fd1ef..33bd6f59486 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -67,7 +67,7 @@ static int FUNC(extension_data)(CodedBitstreamContext *ctx, 
RWContext *rw,
     GetBitContext start;
     uint8_t bit;
     start = *rw;
-    for (k = 0; ff_cbs_h2645_read_more_rbsp_data(rw); k++)
+    for (k = 0; CBS_FUNC(h2645_read_more_rbsp_data(rw)); k++)
         skip_bits(rw, 1);
     current->bit_length = k;
     if (k > 0) {
@@ -1912,7 +1912,7 @@ SEI_FUNC(sei_buffering_period, (CodedBitstreamContext 
*ctx, RWContext *rw,
 
 #ifdef READ
     end_pos = get_bits_count(rw);
-    if (ff_cbs_h2645_payload_extension_present(rw, sei->payload_size,
+    if (CBS_FUNC(h2645_payload_extension_present)(rw, sei->payload_size,
                                            end_pos - start_pos))
         flag(use_alt_cpb_params_flag);
     else
diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c
index 4f04b9ff83d..843e8d2fa7d 100644
--- a/libavcodec/cbs_sei.c
+++ b/libavcodec/cbs_sei.c
@@ -26,7 +26,7 @@
 #include "libavutil/refstruct.h"
 
 #define HEADER(name) do { \
-        ff_cbs_trace_header(ctx, name); \
+        CBS_FUNC(trace_header)(ctx, name); \
     } while (0)
 
 #define CHECK(call) do { \
@@ -37,10 +37,10 @@
 
 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
-#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## 
name
-#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
+#define FUNC_NAME2_EXPORT(prefix, rw, codec, name) ff_ ## prefix ## _ ## codec 
## _ ## rw ## _ ## name
+#define FUNC_NAME1_EXPORT(prefix, rw, codec, name) FUNC_NAME2_EXPORT(prefix, 
rw, codec, name)
 #define FUNC_SEI(name)  FUNC_NAME1(READWRITE, sei,  name)
-#define FUNC_SEI_EXPORT(name)  FUNC_NAME1_EXPORT(READWRITE, sei,  name)
+#define FUNC_SEI_EXPORT(name)  FUNC_NAME1_EXPORT(CBS_PREFIX, READWRITE, sei,  
name)
 
 #define SEI_FUNC(name, args) \
 static int FUNC_SEI(name) args;  \
@@ -93,34 +93,34 @@ static int FUNC_SEI(name) args
 
 #define ub(width, name) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, #name, \
                                           &value)); \
         current->name = value; \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
                                    SUBSCRIPTS(subs, __VA_ARGS__), \
                                    &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_ue_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value; \
-        CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(read_se_golomb)(ctx, rw, #name, \
                                  SUBSCRIPTS(subs, __VA_ARGS__), \
                                  &value, range_min, range_max)); \
         var = value; \
@@ -131,7 +131,7 @@ static int FUNC_SEI(name) args
         current->name = value; \
     } while (0)
 
-#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
+#define more_rbsp_data(var) ((var) = CBS_FUNC(h2645_read_more_rbsp_data)(rw))
 
 #define bit_position(rw)   (get_bits_count(rw))
 #define byte_alignment(rw) (get_bits_count(rw) % 8)
@@ -170,30 +170,30 @@ static int FUNC_SEI(name) args
 
 #define ub(width, name) do { \
         uint32_t value = current->name; \
-        CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
                                            value)); \
     } while (0)
 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
                                     SUBSCRIPTS(subs, __VA_ARGS__), \
                                     value, range_min, range_max)); \
     } while (0)
 #define xue(name, var, range_min, range_max, subs, ...) do { \
         uint32_t value = var; \
-        CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_ue_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
 #define xse(name, var, range_min, range_max, subs, ...) do { \
         int32_t value = var; \
-        CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
+        CHECK(CBS_FUNC(write_se_golomb)(ctx, rw, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), \
                                   value, range_min, range_max)); \
     } while (0)
@@ -237,7 +237,7 @@ static void 
cbs_free_user_data_unregistered(AVRefStructOpaque unused, void *obj)
     av_refstruct_unref(&udu->data_ref);
 }
 
-int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
+int CBS_FUNC(sei_alloc_message_payload)(SEIRawMessage *message,
                                      const SEIMessageTypeDescriptor *desc)
 {
     void (*free_func)(AVRefStructOpaque, void*);
@@ -263,7 +263,7 @@ int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
     return 0;
 }
 
-int ff_cbs_sei_list_add(SEIRawMessageList *list)
+int CBS_FUNC(sei_list_add)(SEIRawMessageList *list)
 {
     void *ptr;
     int old_count = list->nb_messages_allocated;
@@ -285,7 +285,7 @@ int ff_cbs_sei_list_add(SEIRawMessageList *list)
     return 0;
 }
 
-void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
+void CBS_FUNC(sei_free_message_list)(SEIRawMessageList *list)
 {
     for (int i = 0; i < list->nb_messages; i++) {
         SEIRawMessage *message = &list->messages[i];
@@ -368,14 +368,14 @@ static int cbs_sei_get_unit(CodedBitstreamContext *ctx,
         }
     }
 
-    err = ff_cbs_insert_unit_content(au, position, sei_type,
+    err = CBS_FUNC(insert_unit_content)(au, position, sei_type,
                                      NULL, NULL);
     if (err < 0)
         return err;
     unit = &au->units[position];
     unit->type = sei_type;
 
-    err = ff_cbs_alloc_unit_content(ctx, unit);
+    err = CBS_FUNC(alloc_unit_content)(ctx, unit);
     if (err < 0)
         return err;
 
@@ -461,7 +461,7 @@ static int cbs_sei_get_message_list(CodedBitstreamContext 
*ctx,
     return 0;
 }
 
-int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
+int CBS_FUNC(sei_add_message)(CodedBitstreamContext *ctx,
                            CodedBitstreamFragment *au,
                            int prefix,
                            uint32_t     payload_type,
@@ -474,7 +474,7 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
     SEIRawMessage *message;
     int err;
 
-    desc = ff_cbs_sei_find_type(ctx, payload_type);
+    desc = CBS_FUNC(sei_find_type)(ctx, payload_type);
     if (!desc)
         return AVERROR(EINVAL);
 
@@ -489,7 +489,7 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
         return err;
 
     // Add a new message to the message list.
-    err = ff_cbs_sei_list_add(list);
+    err = CBS_FUNC(sei_list_add)(list);
     if (err < 0)
         return err;
 
@@ -508,7 +508,7 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_sei_find_message(CodedBitstreamContext *ctx,
+int CBS_FUNC(sei_find_message)(CodedBitstreamContext *ctx,
                             CodedBitstreamFragment *au,
                             uint32_t payload_type,
                             SEIRawMessage **iter)
@@ -561,7 +561,7 @@ static void cbs_sei_delete_message(SEIRawMessageList *list,
     }
 }
 
-void ff_cbs_sei_delete_message_type(CodedBitstreamContext *ctx,
+void CBS_FUNC(sei_delete_message_type)(CodedBitstreamContext *ctx,
                                     CodedBitstreamFragment *au,
                                     uint32_t payload_type)
 {
@@ -667,7 +667,7 @@ static const SEIMessageTypeDescriptor cbs_sei_h274_types[] 
= {
     SEI_MESSAGE_TYPE_END,
 };
 
-const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext 
*ctx,
+const SEIMessageTypeDescriptor *CBS_FUNC(sei_find_type)(CodedBitstreamContext 
*ctx,
                                                      int payload_type)
 {
     const SEIMessageTypeDescriptor *codec_list = NULL;
@@ -676,12 +676,12 @@ const SEIMessageTypeDescriptor 
*ff_cbs_sei_find_type(CodedBitstreamContext *ctx,
     switch (ctx->codec->codec_id) {
 #if CBS_H264
     case AV_CODEC_ID_H264:
-        codec_list = ff_cbs_sei_h264_types;
+        codec_list = CBS_FUNC(sei_h264_types);
         break;
 #endif
 #if CBS_H265
     case AV_CODEC_ID_H265:
-        codec_list = ff_cbs_sei_h265_types;
+        codec_list = CBS_FUNC(sei_h265_types);
         break;
 #endif
     case AV_CODEC_ID_H266:
diff --git a/libavcodec/cbs_sei.h b/libavcodec/cbs_sei.h
index e3e30971040..384f8226aa8 100644
--- a/libavcodec/cbs_sei.h
+++ b/libavcodec/cbs_sei.h
@@ -202,21 +202,21 @@ typedef struct SEIMessageTypeDescriptor {
 #define SEI_MESSAGE_TYPE_END { .type = -1 }
 
 
-extern const SEIMessageTypeDescriptor ff_cbs_sei_h264_types[];
-extern const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[];
+extern const SEIMessageTypeDescriptor CBS_FUNC(sei_h264_types)[];
+extern const SEIMessageTypeDescriptor CBS_FUNC(sei_h265_types)[];
 
 /**
  * Find the type descriptor for the given payload type.
  *
  * Returns NULL if the payload type is not known.
  */
-const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext 
*ctx,
+const SEIMessageTypeDescriptor *CBS_FUNC(sei_find_type)(CodedBitstreamContext 
*ctx,
                                                      int payload_type);
 
 /**
  * Allocate a new payload for the given SEI message.
  */
-int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
+int CBS_FUNC(sei_alloc_message_payload)(SEIRawMessage *message,
                                      const SEIMessageTypeDescriptor *desc);
 
 /**
@@ -224,12 +224,12 @@ int ff_cbs_sei_alloc_message_payload(SEIRawMessage 
*message,
  *
  * The new message is in place nb_messages - 1.
  */
-int ff_cbs_sei_list_add(SEIRawMessageList *list);
+int CBS_FUNC(sei_list_add)(SEIRawMessageList *list);
 
 /**
  * Free all SEI messages in a message list.
  */
-void ff_cbs_sei_free_message_list(SEIRawMessageList *list);
+void CBS_FUNC(sei_free_message_list)(SEIRawMessageList *list);
 
 /**
  * Add an SEI message to an access unit.
@@ -241,7 +241,7 @@ void ff_cbs_sei_free_message_list(SEIRawMessageList *list);
  * This function creates a new reference to payload_ref in this case.
  * If payload_ref is NULL, the new message will not be reference counted.
  */
-int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
+int CBS_FUNC(sei_add_message)(CodedBitstreamContext *ctx,
                            CodedBitstreamFragment *au,
                            int prefix,
                            uint32_t     payload_type,
@@ -254,7 +254,7 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
  * Set message to NULL in the first call.  Returns 0 while more messages
  * are available, AVERROR(ENOENT) when all messages have been found.
  */
-int ff_cbs_sei_find_message(CodedBitstreamContext *ctx,
+int CBS_FUNC(sei_find_message)(CodedBitstreamContext *ctx,
                             CodedBitstreamFragment *au,
                             uint32_t payload_type,
                             SEIRawMessage **message);
@@ -262,17 +262,17 @@ int ff_cbs_sei_find_message(CodedBitstreamContext *ctx,
 /**
  * Delete all messages with the given payload type from an access unit.
  */
-void ff_cbs_sei_delete_message_type(CodedBitstreamContext *ctx,
+void CBS_FUNC(sei_delete_message_type)(CodedBitstreamContext *ctx,
                                     CodedBitstreamFragment *au,
                                     uint32_t payload_type);
 
-int ff_cbs_sei_read_message_list(CodedBitstreamContext *ctx, struct 
GetBitContext *rw,
+int CBS_FUNC(sei_read_message_list)(CodedBitstreamContext *ctx, struct 
GetBitContext *rw,
                                  SEIRawMessageList *current, int prefix);
-int ff_cbs_sei_write_message_list(CodedBitstreamContext *ctx, struct 
PutBitContext *rw,
+int CBS_FUNC(sei_write_message_list)(CodedBitstreamContext *ctx, struct 
PutBitContext *rw,
                                   SEIRawMessageList *current, int prefix);
-int ff_cbs_sei_read_message(CodedBitstreamContext *ctx, struct GetBitContext 
*rw,
+int CBS_FUNC(sei_read_message)(CodedBitstreamContext *ctx, struct 
GetBitContext *rw,
                             SEIRawMessage *current);
-int ff_cbs_sei_write_message(CodedBitstreamContext *ctx, struct PutBitContext 
*rw,
+int CBS_FUNC(sei_write_message)(CodedBitstreamContext *ctx, struct 
PutBitContext *rw,
                              SEIRawMessage *current);
 
 #endif /* AVCODEC_CBS_SEI_H */
diff --git a/libavcodec/cbs_sei_syntax_template.c 
b/libavcodec/cbs_sei_syntax_template.c
index 4fc3061728c..7ef99bea7d4 100644
--- a/libavcodec/cbs_sei_syntax_template.c
+++ b/libavcodec/cbs_sei_syntax_template.c
@@ -340,7 +340,7 @@ int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
     const SEIMessageTypeDescriptor *desc;
     int err, i;
 
-    desc = ff_cbs_sei_find_type(ctx, current->payload_type);
+    desc = CBS_FUNC(sei_find_type)(ctx, current->payload_type);
     if (desc) {
         SEIMessageState state = {
             .payload_type      = current->payload_type,
@@ -350,7 +350,7 @@ int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
         int start_position, current_position, bits_written;
 
 #ifdef READ
-        CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
+        CHECK(CBS_FUNC(sei_alloc_message_payload)(current, desc));
 #endif
 
         start_position = bit_position(rw);
@@ -461,7 +461,7 @@ int FUNC(message_list)(CodedBitstreamContext *ctx, 
RWContext *rw,
                             get_bits_count(rw) + 8 * payload_size));
         skip_bits_long(&payload_gbc, get_bits_count(rw));
 
-        CHECK(ff_cbs_sei_list_add(current));
+        CHECK(CBS_FUNC(sei_list_add)(current));
         message = &current->messages[k];
 
         message->payload_type = payload_type;
@@ -471,7 +471,7 @@ int FUNC(message_list)(CodedBitstreamContext *ctx, 
RWContext *rw,
 
         skip_bits_long(rw, 8 * payload_size);
 
-        if (!ff_cbs_h2645_read_more_rbsp_data(rw))
+        if (!CBS_FUNC(h2645_read_more_rbsp_data)(rw))
             break;
     }
 #else
-- 
2.54.1


>From 33028cbe79fe53c29910c45d637c768d5911785e Mon Sep 17 00:00:00 2001
From: Olivier Ayache <[email protected]>
Date: Thu, 19 Nov 2026 19:17:33 +0100
Subject: [PATCH 3/3] avformat/cbs: Update Makefile & header file

---
 libavformat/Makefile | 2 ++
 libavformat/cbs.h    | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 0da209b17ed..b027324d0a3 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -47,6 +47,8 @@ include $(SRC_PATH)/libavformat/ogg/Makefile
 include $(SRC_PATH)/libavformat/vorbis/comment/Makefile
 OBJS-$(CONFIG_CBS_APV_LAVF)              += cbs_apv.o cbs.o
 OBJS-$(CONFIG_CBS_AV1_LAVF)              += cbs_av1.o cbs.o
+OBJS-$(CONFIG_CBS_H264_LAVF)             += cbs_h264.o cbs_h2645.o cbs_sei.o 
cbs.o 
+OBJS-$(CONFIG_CBS_H265_LAVF)             += cbs_h265.o cbs_h2645.o cbs_sei.o 
cbs.o
 OBJS-$(CONFIG_ISO_MEDIA)                 += isom.o
 OBJS-$(CONFIG_ISO_WRITER)                += avc.o hevc.o vvc.o
 OBJS-$(CONFIG_IAMFDEC)                   += iamf_reader.o iamf_parse.o iamf.o
diff --git a/libavformat/cbs.h b/libavformat/cbs.h
index e4c0f33f6a3..12a46adee4b 100644
--- a/libavformat/cbs.h
+++ b/libavformat/cbs.h
@@ -22,12 +22,12 @@
 #include "config.h"
 
 #define CBS_PREFIX lavf_cbs
-#define CBS_WRITE 0
+#define CBS_WRITE (CONFIG_CBS_H264_LAVF || CONFIG_CBS_H265_LAVF)
 #define CBS_TRACE 0
 #define CBS_APV CONFIG_CBS_APV_LAVF
 #define CBS_AV1 CONFIG_CBS_AV1_LAVF
-#define CBS_H264 0
-#define CBS_H265 0
+#define CBS_H264 CONFIG_CBS_H264_LAVF
+#define CBS_H265 CONFIG_CBS_H265_LAVF
 #define CBS_H266 0
 #define CBS_JPEG 0
 #define CBS_LCEVC 0
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to