Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/cbs: allow fine tunning selection of features
Date: Sun, 23 Mar 2025 10:42:31 -0300
Message-ID: <20250323134232.1397-1-jamrial@gmail.com> (raw)
In-Reply-To: <GV1SPRMB00367FABE3D06BEE02D86F938FDA2@GV1SPRMB0036.EURP250.PROD.OUTLOOK.COM>

Core framework and AV1 only for now.
This will be useful in an upcoming commit, where CBS will be utilized by
a module outside libavcodec.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs.c                     | 142 +++++++++++++++------------
 libavcodec/cbs.h                     |  53 +++++-----
 libavcodec/cbs_av1.c                 |  91 ++++++++++++++---
 libavcodec/cbs_av1.h                 |  15 +++
 libavcodec/cbs_av1_syntax_template.c |   6 ++
 libavcodec/cbs_internal.h            |  78 ++++++++++++---
 6 files changed, 269 insertions(+), 116 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 01dd916d81..ba1034a72e 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -18,8 +18,6 @@
 
 #include <string.h>
 
-#include "config.h"
-
 #include "libavutil/avassert.h"
 #include "libavutil/buffer.h"
 #include "libavutil/common.h"
@@ -33,61 +31,61 @@
 
 
 static const CodedBitstreamType *const cbs_type_table[] = {
-#if CONFIG_CBS_AV1
-    &ff_cbs_type_av1,
+#if CBS_AV1
+    &CBS_FUNC(type_av1),
 #endif
-#if CONFIG_CBS_H264
-    &ff_cbs_type_h264,
+#if CBS_H264
+    &CBS_FUNC(type_h264),
 #endif
-#if CONFIG_CBS_H265
-    &ff_cbs_type_h265,
+#if CBS_H265
+    &CBS_FUNC(type_h265),
 #endif
-#if CONFIG_CBS_H266
-    &ff_cbs_type_h266,
+#if CBS_H266
+    &CBS_FUNC(type_h266),
 #endif
-#if CONFIG_CBS_JPEG
-    &ff_cbs_type_jpeg,
+#if CBS_JPEG
+    &CBS_FUNC(type_jpeg),
 #endif
-#if CONFIG_CBS_MPEG2
-    &ff_cbs_type_mpeg2,
+#if CBS_MPEG2
+    &CBS_FUNC(type_mpeg2),
 #endif
-#if CONFIG_CBS_VP8
-    &ff_cbs_type_vp8,
+#if CBS_VP8
+    &CBS_FUNC(type_vp8),
 #endif
-#if CONFIG_CBS_VP9
-    &ff_cbs_type_vp9,
+#if CBS_VP9
+    &CBS_FUNC(type_vp9),
 #endif
 };
 
-const enum AVCodecID ff_cbs_all_codec_ids[] = {
-#if CONFIG_CBS_AV1
+const enum AVCodecID CBS_FUNC(all_codec_ids)[] = {
+#if CBS_AV1
     AV_CODEC_ID_AV1,
 #endif
-#if CONFIG_CBS_H264
+#if CBS_H264
     AV_CODEC_ID_H264,
 #endif
-#if CONFIG_CBS_H265
+#if CBS_H265
     AV_CODEC_ID_H265,
 #endif
-#if CONFIG_CBS_H266
+#if CBS_H266
     AV_CODEC_ID_H266,
 #endif
-#if CONFIG_CBS_JPEG
+#if CBS_JPEG
     AV_CODEC_ID_MJPEG,
 #endif
-#if CONFIG_CBS_MPEG2
+#if CBS_MPEG2
     AV_CODEC_ID_MPEG2VIDEO,
 #endif
-#if CONFIG_CBS_VP8
+#if CBS_VP8
     AV_CODEC_ID_VP8,
 #endif
-#if CONFIG_CBS_VP9
+#if CBS_VP9
     AV_CODEC_ID_VP9,
 #endif
     AV_CODEC_ID_NONE
 };
 
-av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
+av_cold int CBS_FUNC(init)(CodedBitstreamContext **ctx_ptr,
                         enum AVCodecID codec_id, void *log_ctx)
 {
     CodedBitstreamContext *ctx;
@@ -133,13 +131,13 @@ av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
     return 0;
 }
 
-av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
+av_cold void CBS_FUNC(flush)(CodedBitstreamContext *ctx)
 {
     if (ctx->codec->flush)
         ctx->codec->flush(ctx);
 }
 
-av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
+av_cold void CBS_FUNC(close)(CodedBitstreamContext **ctx_ptr)
 {
     CodedBitstreamContext *ctx = *ctx_ptr;
 
@@ -169,7 +167,7 @@ static void cbs_unit_uninit(CodedBitstreamUnit *unit)
     unit->data_bit_padding = 0;
 }
 
-void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
+void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag)
 {
     int i;
 
@@ -183,14 +181,15 @@ void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
     frag->data_bit_padding = 0;
 }
 
-av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
+av_cold void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag)
 {
-    ff_cbs_fragment_reset(frag);
+    CBS_FUNC(fragment_reset)(frag);
 
     av_freep(&frag->units);
     frag->nb_units_allocated = 0;
 }
 
+#if CBS_READ
 static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
                                      CodedBitstreamFragment *frag)
 {
@@ -283,7 +282,7 @@ static int cbs_read_data(CodedBitstreamContext *ctx,
     return cbs_read_fragment_content(ctx, frag);
 }
 
-int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
                           CodedBitstreamFragment *frag,
                           const AVCodecParameters *par)
 {
@@ -292,7 +291,7 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
                          par->extradata_size, 1);
 }
 
-int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
                                      CodedBitstreamFragment *frag,
                                      const AVCodecContext *avctx)
 {
@@ -301,7 +300,7 @@ int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
                          avctx->extradata_size, 1);
 }
 
-int ff_cbs_read_packet(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
                        CodedBitstreamFragment *frag,
                        const AVPacket *pkt)
 {
@@ -309,7 +308,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx,
                          pkt->data, pkt->size, 0);
 }
 
-int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
                                  CodedBitstreamFragment *frag,
                                  const AVPacket *pkt)
 {
@@ -322,14 +321,16 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
                          side_data, side_data_size, 1);
 }
 
-int ff_cbs_read(CodedBitstreamContext *ctx,
+int CBS_FUNC(read)(CodedBitstreamContext *ctx,
                 CodedBitstreamFragment *frag,
                 const uint8_t *data, size_t size)
 {
     return cbs_read_data(ctx, frag, NULL,
                          data, size, 0);
 }
+#endif
 
+#if CBS_WRITE
 /**
  * Allocate a new internal data buffer of the given size in the unit.
  *
@@ -406,7 +407,7 @@ static int cbs_write_unit_data(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
                                CodedBitstreamFragment *frag)
 {
     int err, i;
@@ -442,13 +443,13 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
                            AVCodecParameters *par,
                            CodedBitstreamFragment *frag)
 {
     int err;
 
-    err = ff_cbs_write_fragment_data(ctx, frag);
+    err = CBS_FUNC(write_fragment_data)(ctx, frag);
     if (err < 0)
         return err;
 
@@ -471,14 +472,14 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_write_packet(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
                         AVPacket *pkt,
                         CodedBitstreamFragment *frag)
 {
     AVBufferRef *buf;
     int err;
 
-    err = ff_cbs_write_fragment_data(ctx, frag);
+    err = CBS_FUNC(write_fragment_data)(ctx, frag);
     if (err < 0)
         return err;
 
@@ -494,22 +495,26 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx,
 
     return 0;
 }
+#endif
 
 
-void ff_cbs_trace_header(CodedBitstreamContext *ctx,
+void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
                          const char *name)
 {
+#if CBS_TRACE
     if (!ctx->trace_enable)
         return;
 
     av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
+#endif
 }
 
-void ff_cbs_trace_read_log(void *trace_context,
+void CBS_FUNC(trace_read_log)(void *trace_context,
                            GetBitContext *gbc, int length,
                            const char *str, const int *subscripts,
                            int64_t value)
 {
+#if CBS_TRACE
     CodedBitstreamContext *ctx = trace_context;
     char name[256];
     char bits[256];
@@ -561,13 +566,15 @@ void ff_cbs_trace_read_log(void *trace_context,
 
     av_log(ctx->log_ctx, ctx->trace_level, "%-10d  %s%*s = %"PRId64"\n",
            position, name, pad, bits, value);
+#endif
 }
 
-void ff_cbs_trace_write_log(void *trace_context,
+void CBS_FUNC(trace_write_log)(void *trace_context,
                             PutBitContext *pbc, int length,
                             const char *str, const int *subscripts,
                             int64_t value)
 {
+#if CBS_TRACE
     CodedBitstreamContext *ctx = trace_context;
 
     // Ensure that the syntax element is written to the output buffer,
@@ -590,9 +597,11 @@ void ff_cbs_trace_write_log(void *trace_context,
 
     skip_bits_long(&gbc, position - length);
 
-    ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value);
+    CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
+#endif
 }
 
+#if CBS_READ
 static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
                                               GetBitContext *gbc,
                                               int width, const char *name,
@@ -628,7 +637,7 @@ static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                          int width, const char *name,
                          const int *subscripts, uint32_t *write_to,
                          uint32_t range_min, uint32_t range_max)
@@ -637,14 +646,16 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
                              write_to, range_min, range_max);
 }
 
-int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                                 int width, const char *name, uint32_t *write_to)
 {
     return cbs_read_unsigned(ctx, gbc, width, name, NULL,
                              write_to, 0, UINT32_MAX);
 }
+#endif
 
-int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
+#if CBS_WRITE
+int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                           int width, const char *name,
                           const int *subscripts, uint32_t value,
                           uint32_t range_min, uint32_t range_max)
@@ -673,14 +684,16 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
     return 0;
 }
 
-int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                  int width, const char *name, uint32_t value)
 {
-    return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
+    return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
                                  value, 0, MAX_UINT_BITS(width));
 }
+#endif
 
-int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
+#if CBS_READ
+int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                        int width, const char *name,
                        const int *subscripts, int32_t *write_to,
                        int32_t range_min, int32_t range_max)
@@ -711,8 +724,10 @@ int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
     *write_to = value;
     return 0;
 }
+#endif
 
-int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
+#if CBS_WRITE
+int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                         int width, const char *name,
                         const int *subscripts, int32_t value,
                         int32_t range_min, int32_t range_max)
@@ -740,6 +755,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
     return 0;
 }
+#endif
 
 
 static int cbs_insert_unit(CodedBitstreamFragment *frag,
@@ -780,7 +796,7 @@ static int cbs_insert_unit(CodedBitstreamFragment *frag,
     return 0;
 }
 
-int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
+int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
                                int position,
                                CodedBitstreamUnitType type,
                                void *content,
@@ -847,7 +863,7 @@ static int cbs_insert_unit_data(CodedBitstreamFragment *frag,
     return 0;
 }
 
-int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
+int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
                             CodedBitstreamUnitType type,
                             uint8_t *data, size_t data_size,
                             AVBufferRef *data_buf)
@@ -857,7 +873,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
                                 frag->nb_units);
 }
 
-void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
+void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
                         int position)
 {
     av_assert0(0 <= position && position < frag->nb_units
@@ -920,7 +936,7 @@ static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
                                             : cbs_default_free_unit_content);
 }
 
-int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
+int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
                               CodedBitstreamUnit *unit)
 {
     const CodedBitstreamUnitTypeDescriptor *desc;
@@ -1032,7 +1048,7 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
+int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
                                 CodedBitstreamUnit *unit)
 {
     av_assert0(unit->content);
@@ -1041,7 +1057,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
     return cbs_clone_unit_content(ctx, unit);
 }
 
-int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
                               CodedBitstreamUnit *unit)
 {
     void *ref = unit->content_ref;
@@ -1058,7 +1074,7 @@ int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
     return 0;
 }
 
-void ff_cbs_discard_units(CodedBitstreamContext *ctx,
+void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
                           CodedBitstreamFragment *frag,
                           enum AVDiscard skip,
                           int flags)
@@ -1070,11 +1086,11 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx,
         if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
             // discard all units
             if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
-                ff_cbs_fragment_free(frag);
+                CBS_FUNC(fragment_free)(frag);
                 return;
             }
 
-            ff_cbs_delete_unit(frag, i);
+            CBS_FUNC(delete_unit)(frag, i);
         }
     }
 }
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index d479b1ac2d..47818d5c12 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -29,6 +29,13 @@
 #include "defs.h"
 #include "packet.h"
 
+#ifndef CBS_PREFIX
+#define CBS_PREFIX cbs
+#endif
+
+#define CBS_FUNC_PREFIX_NAME(prefix, name) ff_ ## prefix ## _ ## name
+#define CBS_FUNC_NAME(prefix, name) CBS_FUNC_PREFIX_NAME(prefix, name)
+#define CBS_FUNC(name) CBS_FUNC_NAME(CBS_PREFIX, name)
 
 /*
  * This defines a framework for converting between a coded bitstream
@@ -294,24 +301,24 @@ typedef struct CodedBitstreamContext {
  *
  * Terminated by AV_CODEC_ID_NONE.
  */
-extern const enum AVCodecID ff_cbs_all_codec_ids[];
+extern const enum AVCodecID CBS_FUNC(all_codec_ids)[];
 
 
 /**
  * Create and initialise a new context for the given codec.
  */
-int ff_cbs_init(CodedBitstreamContext **ctx,
+int CBS_FUNC(init)(CodedBitstreamContext **ctx,
                 enum AVCodecID codec_id, void *log_ctx);
 
 /**
  * Reset all internal state in a context.
  */
-void ff_cbs_flush(CodedBitstreamContext *ctx);
+void CBS_FUNC(flush)(CodedBitstreamContext *ctx);
 
 /**
  * Close a context and free all internal state.
  */
-void ff_cbs_close(CodedBitstreamContext **ctx);
+void CBS_FUNC(close)(CodedBitstreamContext **ctx);
 
 
 /**
@@ -325,7 +332,7 @@ void ff_cbs_close(CodedBitstreamContext **ctx);
  * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
  * before use.
  */
-int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
                           CodedBitstreamFragment *frag,
                           const AVCodecParameters *par);
 
@@ -336,11 +343,11 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
  * This acts identical to ff_cbs_read_extradata() for the case where
  * you already have a codec context.
  */
-int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
                                      CodedBitstreamFragment *frag,
                                      const struct AVCodecContext *avctx);
 
-int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
                                  CodedBitstreamFragment *frag,
                                  const AVPacket *pkt);
 
@@ -355,7 +362,7 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
  * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
  * before use.
  */
-int ff_cbs_read_packet(CodedBitstreamContext *ctx,
+int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
                        CodedBitstreamFragment *frag,
                        const AVPacket *pkt);
 
@@ -370,7 +377,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx,
  * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
  * before use.
  */
-int ff_cbs_read(CodedBitstreamContext *ctx,
+int CBS_FUNC(read)(CodedBitstreamContext *ctx,
                 CodedBitstreamFragment *frag,
                 const uint8_t *data, size_t size);
 
@@ -387,7 +394,7 @@ int ff_cbs_read(CodedBitstreamContext *ctx,
  * with any persistent data from the fragment which may be required to
  * write following fragments (e.g. parameter sets).
  */
-int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
                                CodedBitstreamFragment *frag);
 
 /**
@@ -396,7 +403,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
  * Modifies context and fragment as ff_cbs_write_fragment_data does and
  * replaces any existing extradata in the structure.
  */
-int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
                            AVCodecParameters *par,
                            CodedBitstreamFragment *frag);
 
@@ -410,7 +417,7 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
  * fragment; other fields are not touched.  On failure, the packet is not
  * touched at all.
  */
-int ff_cbs_write_packet(CodedBitstreamContext *ctx,
+int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
                         AVPacket *pkt,
                         CodedBitstreamFragment *frag);
 
@@ -419,20 +426,20 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx,
  * Free the units contained in a fragment as well as the fragment's
  * own data buffer, but not the units array itself.
  */
-void ff_cbs_fragment_reset(CodedBitstreamFragment *frag);
+void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag);
 
 /**
  * Free the units array of a fragment in addition to what
  * ff_cbs_fragment_reset does.
  */
-void ff_cbs_fragment_free(CodedBitstreamFragment *frag);
+void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag);
 
 /**
  * Allocate a new internal content buffer matching the type of the unit.
  *
  * The content will be zeroed.
  */
-int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
+int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
                               CodedBitstreamUnit *unit);
 
 /**
@@ -443,7 +450,7 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
  * The content structure continues to be owned by the caller if
  * content_ref is not supplied.
  */
-int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
+int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
                                int position,
                                CodedBitstreamUnitType type,
                                void *content,
@@ -456,7 +463,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
  * av_malloc() and will on success become owned by the unit after this
  * call or freed on error.
  */
-int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
+int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
                             CodedBitstreamUnitType type,
                             uint8_t *data, size_t data_size,
                             AVBufferRef *data_buf);
@@ -466,7 +473,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
  *
  * Requires position to be >= 0 and < frag->nb_units.
  */
-void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
+void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
                         int position);
 
 
@@ -479,7 +486,7 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
  * It is not valid to call this function on a unit which does not have
  * decomposed content.
  */
-int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
+int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
                                 CodedBitstreamUnit *unit);
 
 /**
@@ -495,7 +502,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
  * It is not valid to call this function on a unit which does not have
  * decomposed content.
  */
-int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
                               CodedBitstreamUnit *unit);
 
 enum CbsDiscardFlags {
@@ -510,7 +517,7 @@ enum CbsDiscardFlags {
 /**
  * Discard units accroding to 'skip'.
  */
-void ff_cbs_discard_units(CodedBitstreamContext *ctx,
+void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
                           CodedBitstreamFragment *frag,
                           enum AVDiscard skip,
                           int flags);
@@ -522,7 +529,7 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx,
  *
  * Trace context should be set to the CodedBitstreamContext.
  */
-void ff_cbs_trace_read_log(void *trace_context,
+void CBS_FUNC(trace_read_log)(void *trace_context,
                            struct GetBitContext *gbc, int length,
                            const char *str, const int *subscripts,
                            int64_t value);
@@ -533,7 +540,7 @@ void ff_cbs_trace_read_log(void *trace_context,
  *
  * Trace context should be set to the CodedBitstreamContext.
  */
-void ff_cbs_trace_write_log(void *trace_context,
+void CBS_FUNC(trace_write_log)(void *trace_context,
                             struct PutBitContext *pbc, int length,
                             const char *str, const int *subscripts,
                             int64_t value);
diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index d7862a2e48..4f31476fae 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -27,6 +27,7 @@
 #include "libavutil/refstruct.h"
 
 
+#if CBS_READ
 static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
                              const char *name, uint32_t *write_to,
                              uint32_t range_min, uint32_t range_max)
@@ -84,7 +85,9 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
     *write_to = value;
     return 0;
 }
+#endif
 
+#if CBS_WRITE
 static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
                               const char *name, uint32_t value,
                               uint32_t range_min, uint32_t range_max)
@@ -115,7 +118,9 @@ static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
     return 0;
 }
+#endif
 
+#if CBS_READ
 static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
                                const char *name, uint64_t *write_to)
 {
@@ -146,7 +151,9 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
     *write_to = value;
     return 0;
 }
+#endif
 
+#if CBS_WRITE
 static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                 const char *name, uint64_t value, int fixed_length)
 {
@@ -182,7 +189,9 @@ static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
     return 0;
 }
+#endif
 
+#if CBS_READ
 static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
                            uint32_t n, const char *name,
                            const int *subscripts, uint32_t *write_to)
@@ -220,7 +229,9 @@ static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
     *write_to = value;
     return 0;
 }
+#endif
 
+#if CBS_WRITE
 static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
                             uint32_t n, const char *name,
                             const int *subscripts, uint32_t value)
@@ -256,7 +267,9 @@ static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
     return 0;
 }
+#endif
 
+#if CBS_READ
 static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
                                   uint32_t range_min, uint32_t range_max,
                                   const char *name, uint32_t *write_to)
@@ -284,7 +297,9 @@ static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc
     *write_to = value;
     return 0;
 }
+#endif
 
+#if CBS_WRITE
 static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                    uint32_t range_min, uint32_t range_max,
                                    const char *name, uint32_t value)
@@ -315,7 +330,9 @@ static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pb
 
     return 0;
 }
+#endif
 
+#if CBS_READ
 static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
                                uint32_t range_max, const char *name,
                                const int *subscripts, uint32_t *write_to)
@@ -342,7 +359,7 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
     }
 
     if (len < max_len) {
-        err = ff_cbs_read_simple_unsigned(ctx, gbc, range_bits,
+        err = CBS_FUNC(read_simple_unsigned)(ctx, gbc, range_bits,
                                           "subexp_bits", &value);
         if (err < 0)
             return err;
@@ -360,7 +377,9 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
     *write_to = value;
     return err;
 }
+#endif
 
+#if CBS_WRITE
 static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                 uint32_t range_max, const char *name,
                                 const int *subscripts, uint32_t value)
@@ -402,7 +421,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
         return err;
 
     if (len < max_len) {
-        err = ff_cbs_write_simple_unsigned(ctx, pbc, range_bits,
+        err = CBS_FUNC(write_simple_unsigned)(ctx, pbc, range_bits,
                                            "subexp_bits",
                                            value - range_offset);
         if (err < 0)
@@ -420,6 +439,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
 
     return err;
 }
+#endif
 
 
 static int cbs_av1_tile_log2(int blksize, int target)
@@ -441,7 +461,7 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq,
     return diff;
 }
 
-static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
+static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 {
     GetBitContext tmp = *gbc;
     size_t size = 0;
@@ -454,7 +474,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 
 
 #define HEADER(name) do { \
-        ff_cbs_trace_header(ctx, name); \
+        CBS_FUNC(trace_header)(ctx, name); \
     } while (0)
 
 #define CHECK(call) do { \
@@ -469,6 +489,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 
 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
 
+#if CBS_READ
 #define fc(width, name, range_min, range_max) \
         xf(width, name, current->name, range_min, range_max, 0, )
 #define flag(name) fb(1, name)
@@ -496,14 +517,14 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 
 #define fb(width, name) do { \
         uint32_t value; \
-        CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, \
+        CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, \
                                           #name, &value)); \
         current->name = value; \
     } while (0)
 
 #define xf(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; \
@@ -511,7 +532,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 
 #define xsu(width, name, var, 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, \
                                  MIN_INT_BITS(width), \
                                  MAX_INT_BITS(width))); \
@@ -584,25 +605,27 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 #undef leb128
 #undef infer
 #undef byte_alignment
+#endif // CBS_READ
 
 
+#if CBS_WRITE
 #define WRITE
 #define READWRITE write
 #define RWContext PutBitContext
 
 #define fb(width, name) do { \
-        CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
                                            current->name)); \
     } while (0)
 
 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
-        CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
                                     SUBSCRIPTS(subs, __VA_ARGS__), \
                                     var, range_min, range_max)); \
     } while (0)
 
 #define xsu(width, name, var, subs, ...) do { \
-        CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
+        CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
                                   SUBSCRIPTS(subs, __VA_ARGS__), var, \
                                   MIN_INT_BITS(width), \
                                   MAX_INT_BITS(width))); \
@@ -668,12 +691,13 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
 #undef leb128
 #undef infer
 #undef byte_alignment
-
+#endif // CBS_WRITE
 
 static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
                                   CodedBitstreamFragment *frag,
                                   int header)
 {
+#if CBS_READ
     GetBitContext gbc;
     uint8_t *data;
     size_t size;
@@ -763,7 +787,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
             goto fail;
         }
 
-        err = ff_cbs_append_unit_data(frag, obu_header.obu_type,
+        err = CBS_FUNC(append_unit_data)(frag, obu_header.obu_type,
                                       data, obu_length, frag->data_ref);
         if (err < 0)
             goto fail;
@@ -777,8 +801,12 @@ success:
 fail:
     ctx->trace_enable = trace;
     return err;
+#else
+    return AVERROR(ENOSYS);
+#endif
 }
 
+#if CBS_READ
 static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
                                  CodedBitstreamUnit *unit,
                                  GetBitContext *gbc,
@@ -805,16 +833,18 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
 
     return 0;
 }
+#endif
 
 static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
                              CodedBitstreamUnit *unit)
 {
+#if CBS_READ
     CodedBitstreamAV1Context *priv = ctx->priv_data;
     AV1RawOBU *obu;
     GetBitContext gbc;
     int err, start_pos, end_pos;
 
-    err = ff_cbs_alloc_unit_content(ctx, unit);
+    err = CBS_FUNC(alloc_unit_content)(ctx, unit);
     if (err < 0)
         return err;
     obu = unit->content;
@@ -931,6 +961,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
                 return err;
         }
         break;
+#if CBS_OBU_TILE_LIST
     case AV1_OBU_TILE_LIST:
         {
             err = cbs_av1_read_tile_list_obu(ctx, &gbc,
@@ -946,6 +977,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
                 return err;
         }
         break;
+#endif
+#if CBS_OBU_METADATA
     case AV1_OBU_METADATA:
         {
             err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
@@ -953,6 +986,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
                 return err;
         }
         break;
+#endif
+#if CBS_OBU_PADDING
     case AV1_OBU_PADDING:
         {
             err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
@@ -960,6 +995,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
                 return err;
         }
         break;
+#endif
     default:
         return AVERROR(ENOSYS);
     }
@@ -982,12 +1018,16 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
     }
 
     return 0;
+#else
+    return AVERROR(ENOSYS);
+#endif
 }
 
 static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
                              CodedBitstreamUnit *unit,
                              PutBitContext *pbc)
 {
+#if CBS_WRITE
     CodedBitstreamAV1Context *priv = ctx->priv_data;
     AV1RawOBU *obu = unit->content;
     PutBitContext pbc_tmp;
@@ -1044,7 +1084,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
             av_refstruct_unref(&priv->sequence_header_ref);
             priv->sequence_header = NULL;
 
-            err = ff_cbs_make_unit_refcounted(ctx, unit);
+            err = CBS_FUNC(make_unit_refcounted)(ctx, unit);
             if (err < 0)
                 goto error;
 
@@ -1087,6 +1127,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
             td = &tile_group->tile_data;
         }
         break;
+#if CBS_OBU_TILE_LIST
     case AV1_OBU_TILE_LIST:
         {
             err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list);
@@ -1096,6 +1137,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
             td = &obu->obu.tile_list.tile_data;
         }
         break;
+#endif
+#if CBS_OBU_METADATA
     case AV1_OBU_METADATA:
         {
             err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
@@ -1103,6 +1146,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
                 goto error;
         }
         break;
+#endif
+#if CBS_OBU_PADDING
     case AV1_OBU_PADDING:
         {
             err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
@@ -1110,6 +1155,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
                 goto error;
         }
         break;
+#endif
     default:
         err = AVERROR(ENOSYS);
         goto error;
@@ -1182,11 +1228,15 @@ error:
     av_buffer_unref(&av1ctx.frame_header_ref);
 
     return err;
+#else
+    return AVERROR(ENOSYS);
+#endif
 }
 
 static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
                                      CodedBitstreamFragment *frag)
 {
+#if CBS_WRITE
     size_t size, pos;
     int i;
 
@@ -1210,6 +1260,9 @@ static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
     frag->data_size = size;
 
     return 0;
+#else
+    return AVERROR(ENOSYS);
+#endif
 }
 
 static void cbs_av1_flush(CodedBitstreamContext *ctx)
@@ -1234,6 +1287,7 @@ static void cbs_av1_close(CodedBitstreamContext *ctx)
     av_buffer_unref(&priv->frame_header_ref);
 }
 
+#if CBS_OBU_METADATA
 static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
 {
     AV1RawOBU *obu = content;
@@ -1255,6 +1309,7 @@ static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
         av_buffer_unref(&md->metadata.unknown.payload_ref);
     }
 }
+#endif
 
 static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
     CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER,        AV1RawOBU),
@@ -1284,13 +1339,19 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
                             offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) }
         },
     },
+#if CBS_OBU_TILE_LIST
     CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST,  AV1RawOBU,
                                obu.tile_list.tile_data.data),
+#endif
+#if CBS_OBU_PADDING
     CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING,    AV1RawOBU,
                                obu.padding.payload),
+#endif
 
+#if CBS_OBU_METADATA
     CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
                           &cbs_av1_free_metadata),
+#endif
 
     CBS_UNIT_TYPE_END_OF_LIST
 };
@@ -1311,7 +1372,7 @@ static const AVClass cbs_av1_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-const CodedBitstreamType ff_cbs_type_av1 = {
+const CodedBitstreamType CBS_FUNC(type_av1) = {
     .codec_id          = AV_CODEC_ID_AV1,
 
     .priv_class        = &cbs_av1_class,
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 62c7720142..0c73e12c84 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -25,6 +25,15 @@
 #include "av1.h"
 #include "cbs.h"
 
+#ifndef CBS_OBU_METADATA
+#define CBS_OBU_METADATA 1
+#endif
+#ifndef CBS_OBU_TILE_LIST
+#define CBS_OBU_TILE_LIST 1
+#endif
+#ifndef CBS_OBU_PADDING
+#define CBS_OBU_PADDING 1
+#endif
 
 typedef struct AV1RawOBUHeader {
     uint8_t obu_forbidden_bit;
@@ -411,9 +420,15 @@ typedef struct AV1RawOBU {
         AV1RawFrameHeader    frame_header;
         AV1RawFrame          frame;
         AV1RawTileGroup      tile_group;
+#if CBS_OBU_TILE_LIST
         AV1RawTileList       tile_list;
+#endif
+#if CBS_OBU_METADATA
         AV1RawMetadata       metadata;
+#endif
+#if CBS_OBU_PADDING
         AV1RawPadding        padding;
+#endif
     } obu;
 } AV1RawOBU;
 
diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
index 62a83945ec..b594bfd22b 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1868,6 +1868,7 @@ static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+#if CBS_OBU_TILE_LIST
 static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
                                AV1RawTileList *current)
 {
@@ -1882,7 +1883,9 @@ static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
 
     return 0;
 }
+#endif
 
+#if CBS_OBU_METADATA
 static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw,
                                   AV1RawMetadataHDRCLL *current)
 {
@@ -2101,7 +2104,9 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
 
     return 0;
 }
+#endif
 
+#if CBS_OBU_PADDING
 static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
                              AV1RawPadding *current)
 {
@@ -2125,3 +2130,4 @@ static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
 
     return 0;
 }
+#endif
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 80cad2b162..1ed1f04c15 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -22,6 +22,8 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "config.h"
+
 #include "libavutil/log.h"
 
 #include "cbs.h"
@@ -30,6 +32,40 @@
 #include "put_bits.h"
 #include "libavutil/refstruct.h"
 
+#ifndef CBS_READ
+#define CBS_READ 1
+#endif
+#ifndef CBS_WRITE
+#define CBS_WRITE 1
+#endif
+#ifndef CBS_TRACE
+#define CBS_TRACE 1
+#endif
+
+#ifndef CBS_AV1
+#define CBS_AV1 CONFIG_CBS_AV1
+#endif
+#ifndef CBS_H264
+#define CBS_H264 CONFIG_CBS_H264
+#endif
+#ifndef CBS_H265
+#define CBS_H265 CONFIG_CBS_H265
+#endif
+#ifndef CBS_H266
+#define CBS_H266 CONFIG_CBS_H266
+#endif
+#ifndef CBS_JPEG
+#define CBS_JPEG CONFIG_CBS_JPEG
+#endif
+#ifndef CBS_MPEG2
+#define CBS_MPEG2 CONFIG_CBS_MPEG2
+#endif
+#ifndef CBS_VP8
+#define CBS_VP8 CONFIG_CBS_VP8
+#endif
+#ifndef CBS_VP9
+#define CBS_VP9 CONFIG_CBS_VP9
+#endif
 
 enum CBSContentType {
     // Unit content may contain some references to other structures, but all
@@ -155,7 +191,7 @@ typedef struct CodedBitstreamType {
 
 // Helper functions for trace output.
 
-void ff_cbs_trace_header(CodedBitstreamContext *ctx,
+void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
                          const char *name);
 
 
@@ -165,28 +201,28 @@ void ff_cbs_trace_header(CodedBitstreamContext *ctx,
 // (i.e. only limited by the amount of bits used) and they lack
 // the ability to use subscripts.
 
-int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                          int width, const char *name,
                          const int *subscripts, uint32_t *write_to,
                          uint32_t range_min, uint32_t range_max);
 
-int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                                 int width, const char *name, uint32_t *write_to);
 
-int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                           int width, const char *name,
                           const int *subscripts, uint32_t value,
                           uint32_t range_min, uint32_t range_max);
 
-int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                                  int width, const char *name, uint32_t value);
 
-int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
+int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
                        int width, const char *name,
                        const int *subscripts, int32_t *write_to,
                        int32_t range_min, int32_t range_max);
 
-int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
+int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
                         int width, const char *name,
                         const int *subscripts, int32_t value,
                         int32_t range_min, int32_t range_max);
@@ -204,6 +240,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
 
 
+#if CBS_TRACE
 // Start of a syntax element during read tracing.
 #define CBS_TRACE_READ_START() \
     GetBitContext trace_start; \
@@ -284,6 +321,17 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
         } \
     } while (0)
 
+#else // CBS_TRACE
+#define CBS_TRACE_READ_START() do { } while (0)
+#define CBS_TRACE_READ_END() do { } while (0)
+#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() do { } while (0)
+#define CBS_TRACE_READ_END_VALUE_ONLY() do { } while (0)
+#define CBS_TRACE_WRITE_START() do { } while (0)
+#define CBS_TRACE_WRITE_END() do { } while (0)
+#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() do { } while (0)
+#define CBS_TRACE_WRITE_END_VALUE_ONLY() do { } while (0)
+#endif // CBS_TRACE
+
 #define TYPE_LIST(...) { __VA_ARGS__ }
 #define CBS_UNIT_TYPE_POD(type_, structure) { \
         .nb_unit_types  = 1, \
@@ -335,14 +383,14 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
 
 
-extern const CodedBitstreamType ff_cbs_type_av1;
-extern const CodedBitstreamType ff_cbs_type_h264;
-extern const CodedBitstreamType ff_cbs_type_h265;
-extern const CodedBitstreamType ff_cbs_type_h266;
-extern const CodedBitstreamType ff_cbs_type_jpeg;
-extern const CodedBitstreamType ff_cbs_type_mpeg2;
-extern const CodedBitstreamType ff_cbs_type_vp8;
-extern const CodedBitstreamType ff_cbs_type_vp9;
+extern const CodedBitstreamType CBS_FUNC(type_av1);
+extern const CodedBitstreamType CBS_FUNC(type_h264);
+extern const CodedBitstreamType CBS_FUNC(type_h265);
+extern const CodedBitstreamType CBS_FUNC(type_h266);
+extern const CodedBitstreamType CBS_FUNC(type_jpeg);
+extern const CodedBitstreamType CBS_FUNC(type_mpeg2);
+extern const CodedBitstreamType CBS_FUNC(type_vp8);
+extern const CodedBitstreamType CBS_FUNC(type_vp9);
 
 
 #endif /* AVCODEC_CBS_INTERNAL_H */
-- 
2.48.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-03-23 13:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 17:01 [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_av1: also store a pointer to the start of the tile group data James Almer
2025-03-20 17:01 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenccenc: add support for CENC AV1 encryption James Almer
2025-03-21  2:55   ` Andreas Rheinhardt
2025-03-21  3:30     ` James Almer
2025-03-21  3:52       ` Andreas Rheinhardt
2025-03-21 12:50         ` James Almer
2025-03-21 19:42         ` [FFmpeg-devel] [PATCH 2/3] avcodec/cbs: allow fine tunning selection of features James Almer
2025-03-21 19:42           ` [FFmpeg-devel] [PATCH v2 3/3] avformat/movenccenc: add support for CENC AV1 encryption James Almer
2025-03-22 14:25           ` [FFmpeg-devel] [PATCH 2/3] avcodec/cbs: allow fine tunning selection of features Andreas Rheinhardt
2025-03-22 22:56             ` James Almer
2025-03-23 13:42             ` James Almer [this message]
2025-03-23 13:42             ` [FFmpeg-devel] [PATCH v3 2/2] avformat/movenccenc: add support for CENC AV1 encryption James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250323134232.1397-1-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git