History

avcodec/cbs: allow fine tunning selection of features

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.

James Almer committed 1 year ago

Commit 56317041 parent 3e0b38e6 files · +269 −116Browse files

Unified · Split

6 files
  1. libavcodec/cbs.c +79 −63
  2. libavcodec/cbs.h +30 −23
  3. libavcodec/cbs_av1.c +76 −15
  4. libavcodec/cbs_av1.h +15 −0
  5. libavcodec/cbs_av1_syntax_template.c +6 −0
  6. libavcodec/cbs_internal.h +63 −15
libavcodec/cbs.c+79−63
@@ -18,8 +18,6 @@ · 17 unmodified lines
1818
1919 #include <string.h>
2020
21−#include "config.h"
22−
2321 #include "libavutil/avassert.h"
2422 #include "libavutil/buffer.h"
2523 #include "libavutil/common.h"
@@ -33,61 +31,61 @@ · 7 unmodified lines
3331
3432
3533 static const CodedBitstreamType *const cbs_type_table[] = {
36−#if CONFIG_CBS_AV1
37− &ff_cbs_type_av1,
34+#if CBS_AV1
35+ &CBS_FUNC(type_av1),
3836 #endif
39−#if CONFIG_CBS_H264
40− &ff_cbs_type_h264,
37+#if CBS_H264
38+ &CBS_FUNC(type_h264),
4139 #endif
42−#if CONFIG_CBS_H265
43− &ff_cbs_type_h265,
40+#if CBS_H265
41+ &CBS_FUNC(type_h265),
4442 #endif
45−#if CONFIG_CBS_H266
46− &ff_cbs_type_h266,
43+#if CBS_H266
44+ &CBS_FUNC(type_h266),
4745 #endif
48−#if CONFIG_CBS_JPEG
49− &ff_cbs_type_jpeg,
46+#if CBS_JPEG
47+ &CBS_FUNC(type_jpeg),
5048 #endif
51−#if CONFIG_CBS_MPEG2
52− &ff_cbs_type_mpeg2,
49+#if CBS_MPEG2
50+ &CBS_FUNC(type_mpeg2),
5351 #endif
54−#if CONFIG_CBS_VP8
55− &ff_cbs_type_vp8,
52+#if CBS_VP8
53+ &CBS_FUNC(type_vp8),
5654 #endif
57−#if CONFIG_CBS_VP9
58− &ff_cbs_type_vp9,
55+#if CBS_VP9
56+ &CBS_FUNC(type_vp9),
5957 #endif
6058 };
6159
62−const enum AVCodecID ff_cbs_all_codec_ids[] = {
63−#if CONFIG_CBS_AV1
60+const enum AVCodecID CBS_FUNC(all_codec_ids)[] = {
61+#if CBS_AV1
6462 AV_CODEC_ID_AV1,
6563 #endif
66−#if CONFIG_CBS_H264
64+#if CBS_H264
6765 AV_CODEC_ID_H264,
6866 #endif
69−#if CONFIG_CBS_H265
67+#if CBS_H265
7068 AV_CODEC_ID_H265,
7169 #endif
72−#if CONFIG_CBS_H266
70+#if CBS_H266
7371 AV_CODEC_ID_H266,
7472 #endif
75−#if CONFIG_CBS_JPEG
73+#if CBS_JPEG
7674 AV_CODEC_ID_MJPEG,
7775 #endif
78−#if CONFIG_CBS_MPEG2
76+#if CBS_MPEG2
7977 AV_CODEC_ID_MPEG2VIDEO,
8078 #endif
81−#if CONFIG_CBS_VP8
79+#if CBS_VP8
8280 AV_CODEC_ID_VP8,
8381 #endif
84−#if CONFIG_CBS_VP9
82+#if CBS_VP9
8583 AV_CODEC_ID_VP9,
8684 #endif
8785 AV_CODEC_ID_NONE
8886 };
8987
90−av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
88+av_cold int CBS_FUNC(init)(CodedBitstreamContext **ctx_ptr,
9189 enum AVCodecID codec_id, void *log_ctx)
9290 {
9391 CodedBitstreamContext *ctx;
@@ -133,13 +131,13 @@ av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, · 39 unmodified lines
133131 return 0;
134132 }
135133
136−av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
134+av_cold void CBS_FUNC(flush)(CodedBitstreamContext *ctx)
137135 {
138136 if (ctx->codec->flush)
139137 ctx->codec->flush(ctx);
140138 }
141139
142−av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
140+av_cold void CBS_FUNC(close)(CodedBitstreamContext **ctx_ptr)
143141 {
144142 CodedBitstreamContext *ctx = *ctx_ptr;
145143
@@ -169,7 +167,7 @@ static void cbs_unit_uninit(CodedBitstreamUnit *unit) · 23 unmodified lines
169167 unit->data_bit_padding = 0;
170168 }
171169
172−void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
170+void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag)
173171 {
174172 int i;
175173
@@ -183,14 +181,15 @@ void ff_cbs_fragment_reset(CodedBitstreamFragment *frag) · 7 unmodified lines
183181 frag->data_bit_padding = 0;
184182 }
185183
186−av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
184+av_cold void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag)
187185 {
188− ff_cbs_fragment_reset(frag);
186+ CBS_FUNC(fragment_reset)(frag);
189187
190188 av_freep(&frag->units);
191189 frag->nb_units_allocated = 0;
192190 }
193191
192+#if CBS_READ
194193 static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
195194 CodedBitstreamFragment *frag)
196195 {
@@ -283,7 +282,7 @@ static int cbs_read_data(CodedBitstreamContext *ctx, · 86 unmodified lines
283282 return cbs_read_fragment_content(ctx, frag);
284283 }
285284
286−int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
285+int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
287286 CodedBitstreamFragment *frag,
288287 const AVCodecParameters *par)
289288 {
@@ -292,7 +291,7 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx, · 2 unmodified lines
292291 par->extradata_size, 1);
293292 }
294293
295−int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
294+int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
296295 CodedBitstreamFragment *frag,
297296 const AVCodecContext *avctx)
298297 {
@@ -301,7 +300,7 @@ int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, · 2 unmodified lines
301300 avctx->extradata_size, 1);
302301 }
303302
304−int ff_cbs_read_packet(CodedBitstreamContext *ctx,
303+int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
305304 CodedBitstreamFragment *frag,
306305 const AVPacket *pkt)
307306 {
@@ -309,7 +308,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx, · 1 unmodified line
309308 pkt->data, pkt->size, 0);
310309 }
311310
312−int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
311+int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
313312 CodedBitstreamFragment *frag,
314313 const AVPacket *pkt)
315314 {
@@ -322,14 +321,16 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, · 6 unmodified lines
322321 side_data, side_data_size, 1);
323322 }
324323
325−int ff_cbs_read(CodedBitstreamContext *ctx,
324+int CBS_FUNC(read)(CodedBitstreamContext *ctx,
326325 CodedBitstreamFragment *frag,
327326 const uint8_t *data, size_t size)
328327 {
329328 return cbs_read_data(ctx, frag, NULL,
330329 data, size, 0);
331330 }
331+#endif
332332
333+#if CBS_WRITE
333334 /**
334335 * Allocate a new internal data buffer of the given size in the unit.
335336 *
@@ -406,7 +407,7 @@ static int cbs_write_unit_data(CodedBitstreamContext *ctx, · 70 unmodified lines
406407 return 0;
407408 }
408409
409−int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
410+int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
410411 CodedBitstreamFragment *frag)
411412 {
412413 int err, i;
@@ -442,13 +443,13 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, · 29 unmodified lines
442443 return 0;
443444 }
444445
445−int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
446+int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
446447 AVCodecParameters *par,
447448 CodedBitstreamFragment *frag)
448449 {
449450 int err;
450451
451− err = ff_cbs_write_fragment_data(ctx, frag);
452+ err = CBS_FUNC(write_fragment_data)(ctx, frag);
452453 if (err < 0)
453454 return err;
454455
@@ -471,14 +472,14 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, · 16 unmodified lines
471472 return 0;
472473 }
473474
474−int ff_cbs_write_packet(CodedBitstreamContext *ctx,
475+int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
475476 AVPacket *pkt,
476477 CodedBitstreamFragment *frag)
477478 {
478479 AVBufferRef *buf;
479480 int err;
480481
481− err = ff_cbs_write_fragment_data(ctx, frag);
482+ err = CBS_FUNC(write_fragment_data)(ctx, frag);
482483 if (err < 0)
483484 return err;
484485
@@ -494,22 +495,26 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, · 9 unmodified lines
494495
495496 return 0;
496497 }
498+#endif
497499
498500
499−void ff_cbs_trace_header(CodedBitstreamContext *ctx,
501+void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
500502 const char *name)
501503 {
504+#if CBS_TRACE
502505 if (!ctx->trace_enable)
503506 return;
504507
505508 av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
509+#endif
506510 }
507511
508−void ff_cbs_trace_read_log(void *trace_context,
512+void CBS_FUNC(trace_read_log)(void *trace_context,
509513 GetBitContext *gbc, int length,
510514 const char *str, const int *subscripts,
511515 int64_t value)
512516 {
517+#if CBS_TRACE
513518 CodedBitstreamContext *ctx = trace_context;
514519 char name[256];
515520 char bits[256];
@@ -561,13 +566,15 @@ void ff_cbs_trace_read_log(void *trace_context, · 45 unmodified lines
561566
562567 av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
563568 position, name, pad, bits, value);
569+#endif
564570 }
565571
566−void ff_cbs_trace_write_log(void *trace_context,
572+void CBS_FUNC(trace_write_log)(void *trace_context,
567573 PutBitContext *pbc, int length,
568574 const char *str, const int *subscripts,
569575 int64_t value)
570576 {
577+#if CBS_TRACE
571578 CodedBitstreamContext *ctx = trace_context;
572579
573580 // Ensure that the syntax element is written to the output buffer,
@@ -590,9 +597,11 @@ void ff_cbs_trace_write_log(void *trace_context, · 16 unmodified lines
590597
591598 skip_bits_long(&gbc, position - length);
592599
593− ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value);
600+ CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
601+#endif
594602 }
595603
604+#if CBS_READ
596605 static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
597606 GetBitContext *gbc,
598607 int width, const char *name,
@@ -628,7 +637,7 @@ static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx, · 29 unmodified lines
628637 return 0;
629638 }
630639
631−int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
640+int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
632641 int width, const char *name,
633642 const int *subscripts, uint32_t *write_to,
634643 uint32_t range_min, uint32_t range_max)
@@ -637,14 +646,16 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, · 2 unmodified lines
637646 write_to, range_min, range_max);
638647 }
639648
640−int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
649+int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
641650 int width, const char *name, uint32_t *write_to)
642651 {
643652 return cbs_read_unsigned(ctx, gbc, width, name, NULL,
644653 write_to, 0, UINT32_MAX);
645654 }
655+#endif
646656
647−int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
657+#if CBS_WRITE
658+int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
648659 int width, const char *name,
649660 const int *subscripts, uint32_t value,
650661 uint32_t range_min, uint32_t range_max)
@@ -673,14 +684,16 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, · 22 unmodified lines
673684 return 0;
674685 }
675686
676−int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
687+int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
677688 int width, const char *name, uint32_t value)
678689 {
679− return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
690+ return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
680691 value, 0, MAX_UINT_BITS(width));
681692 }
693+#endif
682694
683−int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
695+#if CBS_READ
696+int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
684697 int width, const char *name,
685698 const int *subscripts, int32_t *write_to,
686699 int32_t range_min, int32_t range_max)
@@ -711,8 +724,10 @@ int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, · 24 unmodified lines
711724 *write_to = value;
712725 return 0;
713726 }
727+#endif
714728
715−int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
729+#if CBS_WRITE
730+int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
716731 int width, const char *name,
717732 const int *subscripts, int32_t value,
718733 int32_t range_min, int32_t range_max)
@@ -740,6 +755,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, · 21 unmodified lines
740755
741756 return 0;
742757 }
758+#endif
743759
744760
745761 static int cbs_insert_unit(CodedBitstreamFragment *frag,
@@ -780,7 +796,7 @@ static int cbs_insert_unit(CodedBitstreamFragment *frag, · 34 unmodified lines
780796 return 0;
781797 }
782798
783−int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
799+int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
784800 int position,
785801 CodedBitstreamUnitType type,
786802 void *content,
@@ -847,7 +863,7 @@ static int cbs_insert_unit_data(CodedBitstreamFragment *frag, · 60 unmodified lines
847863 return 0;
848864 }
849865
850−int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
866+int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
851867 CodedBitstreamUnitType type,
852868 uint8_t *data, size_t data_size,
853869 AVBufferRef *data_buf)
@@ -857,7 +873,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag, · 3 unmodified lines
857873 frag->nb_units);
858874 }
859875
860−void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
876+void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
861877 int position)
862878 {
863879 av_assert0(0 <= position && position < frag->nb_units
@@ -920,7 +936,7 @@ static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc) · 56 unmodified lines
920936 : cbs_default_free_unit_content);
921937 }
922938
923−int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
939+int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
924940 CodedBitstreamUnit *unit)
925941 {
926942 const CodedBitstreamUnitTypeDescriptor *desc;
@@ -1032,7 +1048,7 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx, · 105 unmodified lines
10321048 return 0;
10331049 }
10341050
1035−int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
1051+int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
10361052 CodedBitstreamUnit *unit)
10371053 {
10381054 av_assert0(unit->content);
@@ -1041,7 +1057,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, · 2 unmodified lines
10411057 return cbs_clone_unit_content(ctx, unit);
10421058 }
10431059
1044−int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
1060+int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
10451061 CodedBitstreamUnit *unit)
10461062 {
10471063 void *ref = unit->content_ref;
@@ -1058,7 +1074,7 @@ int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, · 10 unmodified lines
10581074 return 0;
10591075 }
10601076
1061−void ff_cbs_discard_units(CodedBitstreamContext *ctx,
1077+void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
10621078 CodedBitstreamFragment *frag,
10631079 enum AVDiscard skip,
10641080 int flags)
@@ -1070,11 +1086,11 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx, · 5 unmodified lines
10701086 if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
10711087 // discard all units
10721088 if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
1073− ff_cbs_fragment_free(frag);
1089+ CBS_FUNC(fragment_free)(frag);
10741090 return;
10751091 }
10761092
1077− ff_cbs_delete_unit(frag, i);
1093+ CBS_FUNC(delete_unit)(frag, i);
10781094 }
10791095 }
10801096 }
libavcodec/cbs.h+30−23
@@ -29,6 +29,13 @@ · 28 unmodified lines
2929 #include "defs.h"
3030 #include "packet.h"
3131
32+#ifndef CBS_PREFIX
33+#define CBS_PREFIX cbs
34+#endif
35+
36+#define CBS_FUNC_PREFIX_NAME(prefix, name) ff_ ## prefix ## _ ## name
37+#define CBS_FUNC_NAME(prefix, name) CBS_FUNC_PREFIX_NAME(prefix, name)
38+#define CBS_FUNC(name) CBS_FUNC_NAME(CBS_PREFIX, name)
3239
3340 /*
3441 * This defines a framework for converting between a coded bitstream
@@ -294,24 +301,24 @@ typedef struct CodedBitstreamContext { · 259 unmodified lines
294301 *
295302 * Terminated by AV_CODEC_ID_NONE.
296303 */
297−extern const enum AVCodecID ff_cbs_all_codec_ids[];
304+extern const enum AVCodecID CBS_FUNC(all_codec_ids)[];
298305
299306
300307 /**
301308 * Create and initialise a new context for the given codec.
302309 */
303−int ff_cbs_init(CodedBitstreamContext **ctx,
310+int CBS_FUNC(init)(CodedBitstreamContext **ctx,
304311 enum AVCodecID codec_id, void *log_ctx);
305312
306313 /**
307314 * Reset all internal state in a context.
308315 */
309−void ff_cbs_flush(CodedBitstreamContext *ctx);
316+void CBS_FUNC(flush)(CodedBitstreamContext *ctx);
310317
311318 /**
312319 * Close a context and free all internal state.
313320 */
314−void ff_cbs_close(CodedBitstreamContext **ctx);
321+void CBS_FUNC(close)(CodedBitstreamContext **ctx);
315322
316323
317324 /**
@@ -325,7 +332,7 @@ void ff_cbs_close(CodedBitstreamContext **ctx); · 7 unmodified lines
325332 * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
326333 * before use.
327334 */
328−int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
335+int CBS_FUNC(read_extradata)(CodedBitstreamContext *ctx,
329336 CodedBitstreamFragment *frag,
330337 const AVCodecParameters *par);
331338
@@ -336,11 +343,11 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx, · 4 unmodified lines
336343 * This acts identical to ff_cbs_read_extradata() for the case where
337344 * you already have a codec context.
338345 */
339−int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
346+int CBS_FUNC(read_extradata_from_codec)(CodedBitstreamContext *ctx,
340347 CodedBitstreamFragment *frag,
341348 const struct AVCodecContext *avctx);
342349
343−int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx,
350+int CBS_FUNC(read_packet_side_data)(CodedBitstreamContext *ctx,
344351 CodedBitstreamFragment *frag,
345352 const AVPacket *pkt);
346353
@@ -355,7 +362,7 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, · 8 unmodified lines
355362 * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
356363 * before use.
357364 */
358−int ff_cbs_read_packet(CodedBitstreamContext *ctx,
365+int CBS_FUNC(read_packet)(CodedBitstreamContext *ctx,
359366 CodedBitstreamFragment *frag,
360367 const AVPacket *pkt);
361368
@@ -370,7 +377,7 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx, · 8 unmodified lines
370377 * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
371378 * before use.
372379 */
373−int ff_cbs_read(CodedBitstreamContext *ctx,
380+int CBS_FUNC(read)(CodedBitstreamContext *ctx,
374381 CodedBitstreamFragment *frag,
375382 const uint8_t *data, size_t size);
376383
@@ -387,7 +394,7 @@ int ff_cbs_read(CodedBitstreamContext *ctx, · 10 unmodified lines
387394 * with any persistent data from the fragment which may be required to
388395 * write following fragments (e.g. parameter sets).
389396 */
390−int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
397+int CBS_FUNC(write_fragment_data)(CodedBitstreamContext *ctx,
391398 CodedBitstreamFragment *frag);
392399
393400 /**
@@ -396,7 +403,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, · 2 unmodified lines
396403 * Modifies context and fragment as ff_cbs_write_fragment_data does and
397404 * replaces any existing extradata in the structure.
398405 */
399−int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
406+int CBS_FUNC(write_extradata)(CodedBitstreamContext *ctx,
400407 AVCodecParameters *par,
401408 CodedBitstreamFragment *frag);
402409
@@ -410,7 +417,7 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, · 7 unmodified lines
410417 * fragment; other fields are not touched. On failure, the packet is not
411418 * touched at all.
412419 */
413−int ff_cbs_write_packet(CodedBitstreamContext *ctx,
420+int CBS_FUNC(write_packet)(CodedBitstreamContext *ctx,
414421 AVPacket *pkt,
415422 CodedBitstreamFragment *frag);
416423
@@ -419,20 +426,20 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, · 2 unmodified lines
419426 * Free the units contained in a fragment as well as the fragment's
420427 * own data buffer, but not the units array itself.
421428 */
422−void ff_cbs_fragment_reset(CodedBitstreamFragment *frag);
429+void CBS_FUNC(fragment_reset)(CodedBitstreamFragment *frag);
423430
424431 /**
425432 * Free the units array of a fragment in addition to what
426433 * ff_cbs_fragment_reset does.
427434 */
428−void ff_cbs_fragment_free(CodedBitstreamFragment *frag);
435+void CBS_FUNC(fragment_free)(CodedBitstreamFragment *frag);
429436
430437 /**
431438 * Allocate a new internal content buffer matching the type of the unit.
432439 *
433440 * The content will be zeroed.
434441 */
435−int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
442+int CBS_FUNC(alloc_unit_content)(CodedBitstreamContext *ctx,
436443 CodedBitstreamUnit *unit);
437444
438445 /**
@@ -443,7 +450,7 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, · 4 unmodified lines
443450 * The content structure continues to be owned by the caller if
444451 * content_ref is not supplied.
445452 */
446−int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
453+int CBS_FUNC(insert_unit_content)(CodedBitstreamFragment *frag,
447454 int position,
448455 CodedBitstreamUnitType type,
449456 void *content,
@@ -456,7 +463,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, · 6 unmodified lines
456463 * av_malloc() and will on success become owned by the unit after this
457464 * call or freed on error.
458465 */
459−int ff_cbs_append_unit_data(CodedBitstreamFragment *frag,
466+int CBS_FUNC(append_unit_data)(CodedBitstreamFragment *frag,
460467 CodedBitstreamUnitType type,
461468 uint8_t *data, size_t data_size,
462469 AVBufferRef *data_buf);
@@ -466,7 +473,7 @@ int ff_cbs_append_unit_data(CodedBitstreamFragment *frag, · 3 unmodified lines
466473 *
467474 * Requires position to be >= 0 and < frag->nb_units.
468475 */
469−void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
476+void CBS_FUNC(delete_unit)(CodedBitstreamFragment *frag,
470477 int position);
471478
472479
@@ -479,7 +486,7 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, · 6 unmodified lines
479486 * It is not valid to call this function on a unit which does not have
480487 * decomposed content.
481488 */
482−int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
489+int CBS_FUNC(make_unit_refcounted)(CodedBitstreamContext *ctx,
483490 CodedBitstreamUnit *unit);
484491
485492 /**
@@ -495,7 +502,7 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, · 9 unmodified lines
495502 * It is not valid to call this function on a unit which does not have
496503 * decomposed content.
497504 */
498−int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
505+int CBS_FUNC(make_unit_writable)(CodedBitstreamContext *ctx,
499506 CodedBitstreamUnit *unit);
500507
501508 enum CbsDiscardFlags {
@@ -510,7 +517,7 @@ enum CbsDiscardFlags { · 8 unmodified lines
510517 /**
511518 * Discard units accroding to 'skip'.
512519 */
513−void ff_cbs_discard_units(CodedBitstreamContext *ctx,
520+void CBS_FUNC(discard_units)(CodedBitstreamContext *ctx,
514521 CodedBitstreamFragment *frag,
515522 enum AVDiscard skip,
516523 int flags);
@@ -522,7 +529,7 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx, · 5 unmodified lines
522529 *
523530 * Trace context should be set to the CodedBitstreamContext.
524531 */
525−void ff_cbs_trace_read_log(void *trace_context,
532+void CBS_FUNC(trace_read_log)(void *trace_context,
526533 struct GetBitContext *gbc, int length,
527534 const char *str, const int *subscripts,
528535 int64_t value);
@@ -533,7 +540,7 @@ void ff_cbs_trace_read_log(void *trace_context, · 4 unmodified lines
533540 *
534541 * Trace context should be set to the CodedBitstreamContext.
535542 */
536−void ff_cbs_trace_write_log(void *trace_context,
543+void CBS_FUNC(trace_write_log)(void *trace_context,
537544 struct PutBitContext *pbc, int length,
538545 const char *str, const int *subscripts,
539546 int64_t value);
libavcodec/cbs_av1.c+76−15
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 #include "libavutil/refstruct.h"
2828
2929
30+#if CBS_READ
3031 static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
3132 const char *name, uint32_t *write_to,
3233 uint32_t range_min, uint32_t range_max)
@@ -84,7 +85,9 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, · 51 unmodified lines
8485 *write_to = value;
8586 return 0;
8687 }
88+#endif
8789
90+#if CBS_WRITE
8891 static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
8992 const char *name, uint32_t value,
9093 uint32_t range_min, uint32_t range_max)
@@ -115,7 +118,9 @@ static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc, · 24 unmodified lines
115118
116119 return 0;
117120 }
121+#endif
118122
123+#if CBS_READ
119124 static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
120125 const char *name, uint64_t *write_to)
121126 {
@@ -146,7 +151,9 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, · 24 unmodified lines
146151 *write_to = value;
147152 return 0;
148153 }
154+#endif
149155
156+#if CBS_WRITE
150157 static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
151158 const char *name, uint64_t value, int fixed_length)
152159 {
@@ -182,7 +189,9 @@ static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, · 29 unmodified lines
182189
183190 return 0;
184191 }
192+#endif
185193
194+#if CBS_READ
186195 static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
187196 uint32_t n, const char *name,
188197 const int *subscripts, uint32_t *write_to)
@@ -220,7 +229,9 @@ static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc, · 31 unmodified lines
220229 *write_to = value;
221230 return 0;
222231 }
232+#endif
223233
234+#if CBS_WRITE
224235 static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
225236 uint32_t n, const char *name,
226237 const int *subscripts, uint32_t value)
@@ -256,7 +267,9 @@ static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc, · 29 unmodified lines
256267
257268 return 0;
258269 }
270+#endif
259271
272+#if CBS_READ
260273 static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
261274 uint32_t range_min, uint32_t range_max,
262275 const char *name, uint32_t *write_to)
@@ -284,7 +297,9 @@ static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc · 21 unmodified lines
284297 *write_to = value;
285298 return 0;
286299 }
300+#endif
287301
302+#if CBS_WRITE
288303 static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
289304 uint32_t range_min, uint32_t range_max,
290305 const char *name, uint32_t value)
@@ -315,7 +330,9 @@ static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pb · 24 unmodified lines
315330
316331 return 0;
317332 }
333+#endif
318334
335+#if CBS_READ
319336 static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
320337 uint32_t range_max, const char *name,
321338 const int *subscripts, uint32_t *write_to)
@@ -342,7 +359,7 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, · 20 unmodified lines
342359 }
343360
344361 if (len < max_len) {
345− err = ff_cbs_read_simple_unsigned(ctx, gbc, range_bits,
362+ err = CBS_FUNC(read_simple_unsigned)(ctx, gbc, range_bits,
346363 "subexp_bits", &value);
347364 if (err < 0)
348365 return err;
@@ -360,7 +377,9 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, · 11 unmodified lines
360377 *write_to = value;
361378 return err;
362379 }
380+#endif
363381
382+#if CBS_WRITE
364383 static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
365384 uint32_t range_max, const char *name,
366385 const int *subscripts, uint32_t value)
@@ -402,7 +421,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, · 35 unmodified lines
402421 return err;
403422
404423 if (len < max_len) {
405− err = ff_cbs_write_simple_unsigned(ctx, pbc, range_bits,
424+ err = CBS_FUNC(write_simple_unsigned)(ctx, pbc, range_bits,
406425 "subexp_bits",
407426 value - range_offset);
408427 if (err < 0)
@@ -420,6 +439,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, · 11 unmodified lines
420439
421440 return err;
422441 }
442+#endif
423443
424444
425445 static int cbs_av1_tile_log2(int blksize, int target)
@@ -441,7 +461,7 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, · 15 unmodified lines
441461 return diff;
442462 }
443463
444−static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
464+static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
445465 {
446466 GetBitContext tmp = *gbc;
447467 size_t size = 0;
@@ -454,7 +474,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 6 unmodified lines
454474
455475
456476 #define HEADER(name) do { \
457− ff_cbs_trace_header(ctx, name); \
477+ CBS_FUNC(trace_header)(ctx, name); \
458478 } while (0)
459479
460480 #define CHECK(call) do { \
@@ -469,6 +489,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 8 unmodified lines
469489
470490 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
471491
492+#if CBS_READ
472493 #define fc(width, name, range_min, range_max) \
473494 xf(width, name, current->name, range_min, range_max, 0, )
474495 #define flag(name) fb(1, name)
@@ -496,14 +517,14 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 21 unmodified lines
496517
497518 #define fb(width, name) do { \
498519 uint32_t value; \
499− CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, \
520+ CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, \
500521 #name, &value)); \
501522 current->name = value; \
502523 } while (0)
503524
504525 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
505526 uint32_t value; \
506− CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
527+ CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
507528 SUBSCRIPTS(subs, __VA_ARGS__), \
508529 &value, range_min, range_max)); \
509530 var = value; \
@@ -511,7 +532,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 1 unmodified line
511532
512533 #define xsu(width, name, var, subs, ...) do { \
513534 int32_t value; \
514− CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
535+ CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
515536 SUBSCRIPTS(subs, __VA_ARGS__), &value, \
516537 MIN_INT_BITS(width), \
517538 MAX_INT_BITS(width))); \
@@ -584,25 +605,27 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 66 unmodified lines
584605 #undef leb128
585606 #undef infer
586607 #undef byte_alignment
608+#endif // CBS_READ
587609
588610
611+#if CBS_WRITE
589612 #define WRITE
590613 #define READWRITE write
591614 #define RWContext PutBitContext
592615
593616 #define fb(width, name) do { \
594− CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
617+ CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
595618 current->name)); \
596619 } while (0)
597620
598621 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
599− CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
622+ CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
600623 SUBSCRIPTS(subs, __VA_ARGS__), \
601624 var, range_min, range_max)); \
602625 } while (0)
603626
604627 #define xsu(width, name, var, subs, ...) do { \
605− CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
628+ CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
606629 SUBSCRIPTS(subs, __VA_ARGS__), var, \
607630 MIN_INT_BITS(width), \
608631 MAX_INT_BITS(width))); \
@@ -668,12 +691,13 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 59 unmodified lines
668691 #undef leb128
669692 #undef infer
670693 #undef byte_alignment
671−
694+#endif // CBS_WRITE
672695
673696 static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
674697 CodedBitstreamFragment *frag,
675698 int header)
676699 {
700+#if CBS_READ
677701 GetBitContext gbc;
678702 uint8_t *data;
679703 size_t size;
@@ -763,7 +787,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, · 83 unmodified lines
763787 goto fail;
764788 }
765789
766− err = ff_cbs_append_unit_data(frag, obu_header.obu_type,
790+ err = CBS_FUNC(append_unit_data)(frag, obu_header.obu_type,
767791 data, obu_length, frag->data_ref);
768792 if (err < 0)
769793 goto fail;
@@ -777,8 +801,12 @@ success: · 7 unmodified lines
777801 fail:
778802 ctx->trace_enable = trace;
779803 return err;
804+#else
805+ return AVERROR(ENOSYS);
806+#endif
780807 }
781808
809+#if CBS_READ
782810 static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
783811 CodedBitstreamUnit *unit,
784812 GetBitContext *gbc,
@@ -805,16 +833,18 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, · 20 unmodified lines
805833
806834 return 0;
807835 }
836+#endif
808837
809838 static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
810839 CodedBitstreamUnit *unit)
811840 {
841+#if CBS_READ
812842 CodedBitstreamAV1Context *priv = ctx->priv_data;
813843 AV1RawOBU *obu;
814844 GetBitContext gbc;
815845 int err, start_pos, end_pos;
816846
817− err = ff_cbs_alloc_unit_content(ctx, unit);
847+ err = CBS_FUNC(alloc_unit_content)(ctx, unit);
818848 if (err < 0)
819849 return err;
820850 obu = unit->content;
@@ -931,6 +961,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, · 110 unmodified lines
931961 return err;
932962 }
933963 break;
964+#if CBS_AV1_OBU_TILE_LIST
934965 case AV1_OBU_TILE_LIST:
935966 {
936967 err = cbs_av1_read_tile_list_obu(ctx, &gbc,
@@ -946,6 +977,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, · 9 unmodified lines
946977 return err;
947978 }
948979 break;
980+#endif
981+#if CBS_AV1_OBU_METADATA
949982 case AV1_OBU_METADATA:
950983 {
951984 err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
@@ -953,6 +986,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, · 1 unmodified line
953986 return err;
954987 }
955988 break;
989+#endif
990+#if CBS_AV1_OBU_PADDING
956991 case AV1_OBU_PADDING:
957992 {
958993 err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
@@ -960,6 +995,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, · 1 unmodified line
960995 return err;
961996 }
962997 break;
998+#endif
963999 default:
9641000 return AVERROR(ENOSYS);
9651001 }
@@ -982,12 +1018,16 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, · 16 unmodified lines
9821018 }
9831019
9841020 return 0;
1021+#else
1022+ return AVERROR(ENOSYS);
1023+#endif
9851024 }
9861025
9871026 static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
9881027 CodedBitstreamUnit *unit,
9891028 PutBitContext *pbc)
9901029 {
1030+#if CBS_WRITE
9911031 CodedBitstreamAV1Context *priv = ctx->priv_data;
9921032 AV1RawOBU *obu = unit->content;
9931033 PutBitContext pbc_tmp;
@@ -1044,7 +1084,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, · 50 unmodified lines
10441084 av_refstruct_unref(&priv->sequence_header_ref);
10451085 priv->sequence_header = NULL;
10461086
1047− err = ff_cbs_make_unit_refcounted(ctx, unit);
1087+ err = CBS_FUNC(make_unit_refcounted)(ctx, unit);
10481088 if (err < 0)
10491089 goto error;
10501090
@@ -1087,6 +1127,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, · 36 unmodified lines
10871127 td = &tile_group->tile_data;
10881128 }
10891129 break;
1130+#if CBS_AV1_OBU_TILE_LIST
10901131 case AV1_OBU_TILE_LIST:
10911132 {
10921133 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, · 3 unmodified lines
10961137 td = &obu->obu.tile_list.tile_data;
10971138 }
10981139 break;
1140+#endif
1141+#if CBS_AV1_OBU_METADATA
10991142 case AV1_OBU_METADATA:
11001143 {
11011144 err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
@@ -1103,6 +1146,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, · 1 unmodified line
11031146 goto error;
11041147 }
11051148 break;
1149+#endif
1150+#if CBS_AV1_OBU_PADDING
11061151 case AV1_OBU_PADDING:
11071152 {
11081153 err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
@@ -1110,6 +1155,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, · 1 unmodified line
11101155 goto error;
11111156 }
11121157 break;
1158+#endif
11131159 default:
11141160 err = AVERROR(ENOSYS);
11151161 goto error;
@@ -1182,11 +1228,15 @@ error: · 66 unmodified lines
11821228 av_buffer_unref(&av1ctx.frame_header_ref);
11831229
11841230 return err;
1231+#else
1232+ return AVERROR(ENOSYS);
1233+#endif
11851234 }
11861235
11871236 static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx,
11881237 CodedBitstreamFragment *frag)
11891238 {
1239+#if CBS_WRITE
11901240 size_t size, pos;
11911241 int i;
11921242
@@ -1210,6 +1260,9 @@ static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, · 17 unmodified lines
12101260 frag->data_size = size;
12111261
12121262 return 0;
1263+#else
1264+ return AVERROR(ENOSYS);
1265+#endif
12131266 }
12141267
12151268 static void cbs_av1_flush(CodedBitstreamContext *ctx)
@@ -1234,6 +1287,7 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) · 18 unmodified lines
12341287 av_buffer_unref(&priv->frame_header_ref);
12351288 }
12361289
1290+#if CBS_AV1_OBU_METADATA
12371291 static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
12381292 {
12391293 AV1RawOBU *obu = content;
@@ -1255,6 +1309,7 @@ static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content) · 15 unmodified lines
12551309 av_buffer_unref(&md->metadata.unknown.payload_ref);
12561310 }
12571311 }
1312+#endif
12581313
12591314 static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
12601315 CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER, AV1RawOBU),
@@ -1284,13 +1339,19 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { · 23 unmodified lines
12841339 offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) }
12851340 },
12861341 },
1342+#if CBS_AV1_OBU_TILE_LIST
12871343 CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU,
12881344 obu.tile_list.tile_data.data),
1345+#endif
1346+#if CBS_AV1_OBU_PADDING
12891347 CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING, AV1RawOBU,
12901348 obu.padding.payload),
1349+#endif
12911350
1351+#if CBS_AV1_OBU_METADATA
12921352 CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
12931353 &cbs_av1_free_metadata),
1354+#endif
12941355
12951356 CBS_UNIT_TYPE_END_OF_LIST
12961357 };
@@ -1311,7 +1372,7 @@ static const AVClass cbs_av1_class = { · 14 unmodified lines
13111372 .version = LIBAVUTIL_VERSION_INT,
13121373 };
13131374
1314−const CodedBitstreamType ff_cbs_type_av1 = {
1375+const CodedBitstreamType CBS_FUNC(type_av1) = {
13151376 .codec_id = AV_CODEC_ID_AV1,
13161377
13171378 .priv_class = &cbs_av1_class,
libavcodec/cbs_av1.h+15−0
@@ -25,6 +25,15 @@ · 24 unmodified lines
2525 #include "av1.h"
2626 #include "cbs.h"
2727
28+#ifndef CBS_AV1_OBU_METADATA
29+#define CBS_AV1_OBU_METADATA 1
30+#endif
31+#ifndef CBS_AV1_OBU_TILE_LIST
32+#define CBS_AV1_OBU_TILE_LIST 1
33+#endif
34+#ifndef CBS_AV1_OBU_PADDING
35+#define CBS_AV1_OBU_PADDING 1
36+#endif
2837
2938 typedef struct AV1RawOBUHeader {
3039 uint8_t obu_forbidden_bit;
@@ -411,9 +420,15 @@ typedef struct AV1RawOBU { · 380 unmodified lines
411420 AV1RawFrameHeader frame_header;
412421 AV1RawFrame frame;
413422 AV1RawTileGroup tile_group;
423+#if CBS_AV1_OBU_TILE_LIST
414424 AV1RawTileList tile_list;
425+#endif
426+#if CBS_AV1_OBU_METADATA
415427 AV1RawMetadata metadata;
428+#endif
429+#if CBS_AV1_OBU_PADDING
416430 AV1RawPadding padding;
431+#endif
417432 } obu;
418433 } AV1RawOBU;
419434
libavcodec/cbs_av1_syntax_template.c+6−0
@@ -1868,6 +1868,7 @@ static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw, · 1867 unmodified lines
18681868 return 0;
18691869 }
18701870
1871+#if CBS_AV1_OBU_TILE_LIST
18711872 static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
18721873 AV1RawTileList *current)
18731874 {
@@ -1882,7 +1883,9 @@ static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw, · 8 unmodified lines
18821883
18831884 return 0;
18841885 }
1886+#endif
18851887
1888+#if CBS_AV1_OBU_METADATA
18861889 static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw,
18871890 AV1RawMetadataHDRCLL *current)
18881891 {
@@ -2101,7 +2104,9 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw, · 212 unmodified lines
21012104
21022105 return 0;
21032106 }
2107+#endif
21042108
2109+#if CBS_AV1_OBU_PADDING
21052110 static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
21062111 AV1RawPadding *current)
21072112 {
@@ -2125,3 +2130,4 @@ static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw, · 17 unmodified lines
21252130
21262131 return 0;
21272132 }
2133+#endif
libavcodec/cbs_internal.h+63−15
@@ -22,6 +22,8 @@ · 21 unmodified lines
2222 #include <stddef.h>
2323 #include <stdint.h>
2424
25+#include "config.h"
26+
2527 #include "libavutil/log.h"
2628
2729 #include "cbs.h"
@@ -30,6 +32,40 @@ · 2 unmodified lines
3032 #include "put_bits.h"
3133 #include "libavutil/refstruct.h"
3234
35+#ifndef CBS_READ
36+#define CBS_READ 1
37+#endif
38+#ifndef CBS_WRITE
39+#define CBS_WRITE 1
40+#endif
41+#ifndef CBS_TRACE
42+#define CBS_TRACE 1
43+#endif
44+
45+#ifndef CBS_AV1
46+#define CBS_AV1 CONFIG_CBS_AV1
47+#endif
48+#ifndef CBS_H264
49+#define CBS_H264 CONFIG_CBS_H264
50+#endif
51+#ifndef CBS_H265
52+#define CBS_H265 CONFIG_CBS_H265
53+#endif
54+#ifndef CBS_H266
55+#define CBS_H266 CONFIG_CBS_H266
56+#endif
57+#ifndef CBS_JPEG
58+#define CBS_JPEG CONFIG_CBS_JPEG
59+#endif
60+#ifndef CBS_MPEG2
61+#define CBS_MPEG2 CONFIG_CBS_MPEG2
62+#endif
63+#ifndef CBS_VP8
64+#define CBS_VP8 CONFIG_CBS_VP8
65+#endif
66+#ifndef CBS_VP9
67+#define CBS_VP9 CONFIG_CBS_VP9
68+#endif
3369
3470 enum CBSContentType {
3571 // Unit content may contain some references to other structures, but all
@@ -155,7 +191,7 @@ typedef struct CodedBitstreamType { · 119 unmodified lines
155191
156192 // Helper functions for trace output.
157193
158−void ff_cbs_trace_header(CodedBitstreamContext *ctx,
194+void CBS_FUNC(trace_header)(CodedBitstreamContext *ctx,
159195 const char *name);
160196
161197
@@ -165,28 +201,28 @@ void ff_cbs_trace_header(CodedBitstreamContext *ctx, · 3 unmodified lines
165201 // (i.e. only limited by the amount of bits used) and they lack
166202 // the ability to use subscripts.
167203
168−int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
204+int CBS_FUNC(read_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
169205 int width, const char *name,
170206 const int *subscripts, uint32_t *write_to,
171207 uint32_t range_min, uint32_t range_max);
172208
173−int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
209+int CBS_FUNC(read_simple_unsigned)(CodedBitstreamContext *ctx, GetBitContext *gbc,
174210 int width, const char *name, uint32_t *write_to);
175211
176−int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
212+int CBS_FUNC(write_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
177213 int width, const char *name,
178214 const int *subscripts, uint32_t value,
179215 uint32_t range_min, uint32_t range_max);
180216
181−int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
217+int CBS_FUNC(write_simple_unsigned)(CodedBitstreamContext *ctx, PutBitContext *pbc,
182218 int width, const char *name, uint32_t value);
183219
184−int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
220+int CBS_FUNC(read_signed)(CodedBitstreamContext *ctx, GetBitContext *gbc,
185221 int width, const char *name,
186222 const int *subscripts, int32_t *write_to,
187223 int32_t range_min, int32_t range_max);
188224
189−int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
225+int CBS_FUNC(write_signed)(CodedBitstreamContext *ctx, PutBitContext *pbc,
190226 int width, const char *name,
191227 const int *subscripts, int32_t value,
192228 int32_t range_min, int32_t range_max);
@@ -204,6 +240,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, · 11 unmodified lines
204240 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
205241
206242
243+#if CBS_TRACE
207244 // Start of a syntax element during read tracing.
208245 #define CBS_TRACE_READ_START() \
209246 GetBitContext trace_start; \
@@ -284,6 +321,17 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, · 74 unmodified lines
284321 } \
285322 } while (0)
286323
324+#else // CBS_TRACE
325+#define CBS_TRACE_READ_START() do { } while (0)
326+#define CBS_TRACE_READ_END() do { } while (0)
327+#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() do { } while (0)
328+#define CBS_TRACE_READ_END_VALUE_ONLY() do { } while (0)
329+#define CBS_TRACE_WRITE_START() do { } while (0)
330+#define CBS_TRACE_WRITE_END() do { } while (0)
331+#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() do { } while (0)
332+#define CBS_TRACE_WRITE_END_VALUE_ONLY() do { } while (0)
333+#endif // CBS_TRACE
334+
287335 #define TYPE_LIST(...) { __VA_ARGS__ }
288336 #define CBS_UNIT_TYPE_POD(type_, structure) { \
289337 .nb_unit_types = 1, \
@@ -335,14 +383,14 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, · 45 unmodified lines
335383 #define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
336384
337385
338−extern const CodedBitstreamType ff_cbs_type_av1;
339−extern const CodedBitstreamType ff_cbs_type_h264;
340−extern const CodedBitstreamType ff_cbs_type_h265;
341−extern const CodedBitstreamType ff_cbs_type_h266;
342−extern const CodedBitstreamType ff_cbs_type_jpeg;
343−extern const CodedBitstreamType ff_cbs_type_mpeg2;
344−extern const CodedBitstreamType ff_cbs_type_vp8;
345−extern const CodedBitstreamType ff_cbs_type_vp9;
386+extern const CodedBitstreamType CBS_FUNC(type_av1);
387+extern const CodedBitstreamType CBS_FUNC(type_h264);
388+extern const CodedBitstreamType CBS_FUNC(type_h265);
389+extern const CodedBitstreamType CBS_FUNC(type_h266);
390+extern const CodedBitstreamType CBS_FUNC(type_jpeg);
391+extern const CodedBitstreamType CBS_FUNC(type_mpeg2);
392+extern const CodedBitstreamType CBS_FUNC(type_vp8);
393+extern const CodedBitstreamType CBS_FUNC(type_vp9);
346394
347395
348396 #endif /* AVCODEC_CBS_INTERNAL_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t