Go to the documentation of this file.
33 const char *
name, uint32_t *write_to,
34 uint32_t range_min, uint32_t range_max)
36 uint32_t zeroes, bits_value,
value;
44 "%s: bitstream ended.\n",
name);
63 "%s uvlc code: considered invalid due to conflicting "
64 "standard and reference decoder behaviour.\n",
name);
69 "%s: bitstream ended.\n",
name);
74 value = bits_value + (UINT32_C(1) << zeroes) - 1;
79 if (value < range_min || value > range_max) {
81 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
94 uint32_t range_min, uint32_t range_max)
101 if (value < range_min || value > range_max) {
103 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
109 v =
value - (1
U << zeroes) + 1;
126 const char *
name, uint64_t *write_to)
135 for (
i = 0;
i < 8;
i++) {
138 "%s: bitstream ended.\n",
name);
142 value |= (uint64_t)(
byte & 0x7f) << (
i * 7);
147 if (
value > UINT32_MAX)
159 const char *
name, uint64_t
value,
int fixed_length)
169 if (fixed_length <
len) {
171 "fixed length size field (%d > %d).\n",
178 for (
i = 0;
i <
len;
i++) {
182 byte =
value >> (7 *
i) & 0x7f;
197 uint32_t n,
const char *
name,
198 const int *subscripts, uint32_t *write_to)
200 uint32_t m, v, extra_bit,
value;
212 "%s: bitstream ended.\n",
name);
225 value = (v << 1) - m + extra_bit;
237 uint32_t n,
const char *
name,
238 const int *subscripts, uint32_t
value)
240 uint32_t
w, m, v, extra_bit;
246 "%"PRIu32
", but must be in [0,%"PRIu32
"].\n",
261 v = m + ((
value - m) >> 1);
262 extra_bit = (
value - m) & 1;
275 uint32_t range_min, uint32_t range_max,
276 const char *
name, uint32_t *write_to)
282 av_assert0(range_min <= range_max && range_max - range_min < 32);
287 "%s: bitstream ended.\n",
name);
305 uint32_t range_min, uint32_t range_max,
312 av_assert0(range_min <= range_max && range_max - range_min < 32);
313 if (value < range_min || value > range_max) {
315 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
320 if (
value == range_max)
321 len = range_max - range_min;
338 uint32_t range_max,
const char *
name,
339 const int *subscripts, uint32_t *write_to)
341 uint32_t
value, max_len,
len, range_offset, range_bits;
347 max_len =
av_log2(range_max - 1) - 3;
350 "subexp_more_bits", &
len);
355 range_bits = 2 +
len;
356 range_offset = 1 << range_bits;
364 "subexp_bits", &
value);
374 value += range_offset;
385 uint32_t range_max,
const char *
name,
386 const int *subscripts, uint32_t
value)
389 uint32_t max_len,
len, range_offset, range_bits;
393 if (
value > range_max) {
395 "%"PRIu32
", but must be in [0,%"PRIu32
"].\n",
401 max_len =
av_log2(range_max - 1) - 3;
409 len = range_bits - 2;
416 range_offset = 1 << range_bits;
420 "subexp_more_bits",
len);
427 value - range_offset);
433 "subexp_final_bits",
NULL,
434 value - range_offset);
449 for (k = 0; (blksize << k) < target; k++);
454 unsigned int a,
unsigned int b)
456 unsigned int diff, m;
477 #define HEADER(name) do { \
478 CBS_FUNC(trace_header)(ctx, name); \
481 #define CHECK(call) do { \
487 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
488 #define FUNC_AV1(rw, name) FUNC_NAME(rw, av1, name)
489 #define FUNC(name) FUNC_AV1(READWRITE, name)
491 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
494 #define fc(width, name, range_min, range_max) \
495 xf(width, name, current->name, range_min, range_max, 0, )
496 #define flag(name) fb(1, name)
497 #define su(width, name) \
498 xsu(width, name, current->name, 0, )
500 #define fbs(width, name, subs, ...) \
501 xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
502 #define fcs(width, name, range_min, range_max, subs, ...) \
503 xf(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
504 #define flags(name, subs, ...) \
505 xf(1, name, current->name, 0, 1, subs, __VA_ARGS__)
506 #define sus(width, name, subs, ...) \
507 xsu(width, name, current->name, subs, __VA_ARGS__)
509 #define fixed(width, name, value) do { \
510 av_unused uint32_t fixed_value = value; \
511 xf(width, name, fixed_value, value, value, 0, ); \
516 #define READWRITE read
517 #define RWContext GetBitContext
519 #define fb(width, name) do { \
521 CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, \
523 current->name = value; \
526 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
528 CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
529 SUBSCRIPTS(subs, __VA_ARGS__), \
530 &value, range_min, range_max)); \
534 #define xsu(width, name, var, subs, ...) do { \
536 CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
537 SUBSCRIPTS(subs, __VA_ARGS__), &value, \
538 MIN_INT_BITS(width), \
539 MAX_INT_BITS(width))); \
543 #define uvlc(name, range_min, range_max) do { \
545 CHECK(cbs_av1_read_uvlc(ctx, rw, #name, \
546 &value, range_min, range_max)); \
547 current->name = value; \
550 #define ns(max_value, name, subs, ...) do { \
552 CHECK(cbs_av1_read_ns(ctx, rw, max_value, #name, \
553 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
554 current->name = value; \
557 #define increment(name, min, max) do { \
559 CHECK(cbs_av1_read_increment(ctx, rw, min, max, #name, &value)); \
560 current->name = value; \
563 #define subexp(name, max, subs, ...) do { \
565 CHECK(cbs_av1_read_subexp(ctx, rw, max, #name, \
566 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
567 current->name = value; \
570 #define delta_q(name) do { \
571 uint8_t delta_coded; \
573 xf(1, name.delta_coded, delta_coded, 0, 1, 0, ); \
575 xsu(1 + 6, name.delta_q, delta_q, 0, ); \
578 current->name = delta_q; \
581 #define leb128(name) do { \
583 CHECK(cbs_av1_read_leb128(ctx, rw, #name, &value)); \
584 current->name = value; \
587 #define infer(name, value) do { \
588 current->name = value; \
591 #define byte_alignment(rw) (get_bits_count(rw) % 8)
608 #undef byte_alignment
614 #define READWRITE write
615 #define RWContext PutBitContext
617 #define fb(width, name) do { \
618 CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
622 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
623 CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
624 SUBSCRIPTS(subs, __VA_ARGS__), \
625 var, range_min, range_max)); \
628 #define xsu(width, name, var, subs, ...) do { \
629 CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
630 SUBSCRIPTS(subs, __VA_ARGS__), var, \
631 MIN_INT_BITS(width), \
632 MAX_INT_BITS(width))); \
635 #define uvlc(name, range_min, range_max) do { \
636 CHECK(cbs_av1_write_uvlc(ctx, rw, #name, current->name, \
637 range_min, range_max)); \
640 #define ns(max_value, name, subs, ...) do { \
641 CHECK(cbs_av1_write_ns(ctx, rw, max_value, #name, \
642 SUBSCRIPTS(subs, __VA_ARGS__), \
646 #define increment(name, min, max) do { \
647 CHECK(cbs_av1_write_increment(ctx, rw, min, max, #name, \
651 #define subexp(name, max, subs, ...) do { \
652 CHECK(cbs_av1_write_subexp(ctx, rw, max, #name, \
653 SUBSCRIPTS(subs, __VA_ARGS__), \
657 #define delta_q(name) do { \
658 xf(1, name.delta_coded, current->name != 0, 0, 1, 0, ); \
660 xsu(1 + 6, name.delta_q, current->name, 0, ); \
663 #define leb128(name) do { \
664 CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name, 0)); \
667 #define infer(name, value) do { \
668 if (current->name != (value)) { \
669 av_log(ctx->log_ctx, AV_LOG_ERROR, \
670 "%s does not match inferred value: " \
671 "%"PRId64", but should be %"PRId64".\n", \
672 #name, (int64_t)current->name, (int64_t)(value)); \
673 return AVERROR_INVALIDDATA; \
677 #define byte_alignment(rw) (put_bits_count(rw) % 8)
694 #undef byte_alignment
709 trace =
ctx->trace_enable;
710 ctx->trace_enable = 0;
715 if (INT_MAX / 8 <
size) {
725 int config_record_version =
data[0] & 0x7f;
727 if (config_record_version != 1) {
729 "Unknown version %d of AV1CodecConfigurationRecord "
731 config_record_version);
739 "Undersized AV1CodecConfigurationRecord v%d found!\n",
740 config_record_version);
781 obu_length =
pos / 8 + obu_size;
783 if (
size < obu_length) {
785 "%"PRIu64
", but only %"SIZE_SPECIFIER" bytes remaining in fragment.\n",
803 ctx->trace_enable = trace;
815 uint8_t **
data,
size_t *data_size)
822 "any data in tile group (%d bits read).\n",
pos);
846 int err, start_pos, end_pos;
857 err = cbs_av1_read_obu_header(
ctx, &gbc, &obu->
header);
883 int in_temporal_layer =
885 int in_spatial_layer =
887 if (!in_temporal_layer || !in_spatial_layer) {
896 err = cbs_av1_read_sequence_header_obu(
ctx, &gbc,
906 "Must not be higher than %u.\n",
919 err = cbs_av1_read_temporal_delimiter_obu(
ctx, &gbc);
927 err = cbs_av1_read_frame_header_obu(
ctx, &gbc,
937 err = cbs_av1_read_frame_obu(
ctx, &gbc, &obu->
obu.
frame,
953 err = cbs_av1_read_tile_group_obu(
ctx, &gbc, tile_group);
965 #if CBS_AV1_OBU_TILE_LIST
968 err = cbs_av1_read_tile_list_obu(
ctx, &gbc,
982 #if CBS_AV1_OBU_METADATA
991 #if CBS_AV1_OBU_PADDING
994 err = cbs_av1_read_padding_obu(
ctx, &gbc, &obu->
obu.
padding);
1011 int nb_bits = obu->
obu_size * 8 + start_pos - end_pos;
1016 err = cbs_av1_read_trailing_bits(
ctx, &gbc, nb_bits);
1037 int err, start_pos, end_pos, data_pos;
1058 err = cbs_av1_write_obu_header(
ctx, pbc, &obu->
header);
1080 err = cbs_av1_write_sequence_header_obu(
ctx, pbc,
1098 err = cbs_av1_write_temporal_delimiter_obu(
ctx, pbc);
1106 err = cbs_av1_write_frame_header_obu(
ctx, pbc,
1124 err = cbs_av1_write_tile_group_obu(
ctx, pbc, tile_group);
1131 #if CBS_AV1_OBU_TILE_LIST
1142 #if CBS_AV1_OBU_METADATA
1151 #if CBS_AV1_OBU_PADDING
1154 err = cbs_av1_write_padding_obu(
ctx, pbc, &obu->
obu.
padding);
1166 header_size = (end_pos - start_pos + 7) / 8;
1169 }
else if (header_size > 0) {
1171 err = cbs_av1_write_trailing_bits(
ctx, pbc, 8 - end_pos % 8);
1175 obu->
obu_size = header_size = (end_pos - start_pos + 7) / 8;
1208 memmove(pbc->
buf + data_pos,
1209 pbc->
buf + start_pos, header_size);
1217 memcpy(pbc->
buf + data_pos + header_size,
1277 memset(priv->
ref, 0,
sizeof(priv->
ref));
1291 #if CBS_AV1_OBU_METADATA
1300 switch (
md->metadata_type) {
1343 #if CBS_AV1_OBU_TILE_LIST
1347 #if CBS_AV1_OBU_PADDING
1352 #if CBS_AV1_OBU_METADATA
1360 #define OFFSET(x) offsetof(CodedBitstreamAV1Context, x)
1362 {
"operating_point",
"Set operating point to select layers to parse from a scalable bitstream",
1364 {
"fixed_obu_size_length",
"Set fixed length of the obu_size field",
static void error(const char *err)
static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
#define AV_LOG_WARNING
Something somehow does not look correct.
void * content_ref
If content is reference counted, a RefStruct reference backing content.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
@ AV1_OBU_REDUNDANT_FRAME_HEADER
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
uint8_t * data
The data buffer.
RefStruct is an API for creating reference-counted objects with minimal overhead.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
void * content
Pointer to the decomposed form of this unit.
static int get_bits_count(const GetBitContext *s)
int CBS_FUNC() read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
int CBS_FUNC() append_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Add a new unit to a fragment with the given data bitstream.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Context structure for coded bitstream operations.
AVBufferRef * frame_header_ref
static av_cold void cbs_av1_close(CodedBitstreamContext *ctx)
static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, uint64_t *write_to)
CodedBitstreamUnitType type
Codec-specific type of this unit.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
@ AV1_OBU_TEMPORAL_DELIMITER
static int cbs_av1_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Coded bitstream unit structure.
static av_cold void close(AVCodecParserContext *s)
static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t value)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int CBS_FUNC() write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
static int FUNC() obu_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawOBUHeader *current)
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
#define CBS_TRACE_WRITE_END_VALUE_ONLY()
static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]
static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t n, const char *name, const int *subscripts, uint32_t value)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
static int put_bits_left(PutBitContext *s)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int CBS_FUNC() alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
@ AV1_METADATA_TYPE_HDR_CLL
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Coded bitstream fragment structure, combining one or more units.
static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint32_t value, uint32_t range_min, uint32_t range_max)
size_t data_size
The number of bytes in the bitstream.
static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, GetBitContext *gbc, AVBufferRef **data_ref, uint8_t **data, size_t *data_size)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_cold void cbs_av1_flush(CodedBitstreamContext *ctx)
#define CBS_TRACE_WRITE_END()
static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t n, const char *name, const int *subscripts, uint32_t *write_to)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define CBS_TRACE_READ_END_NO_SUBSCRIPTS()
const char * av_default_item_name(void *ptr)
Return the context name.
static unsigned int get_bits1(GetBitContext *s)
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
void(* flush)(AVBSFContext *ctx)
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)
#define CBS_TRACE_READ_END_VALUE_ONLY()
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
const CodedBitstreamType CBS_FUNC(type_av1)
AV1RawSequenceHeader sequence_header
uint8_t * data
Pointer to the bitstream form of this fragment.
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)
@ AV1_OBU_SEQUENCE_HEADER
int CBS_FUNC() make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
static const uint8_t header[24]
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define CBS_UNIT_TYPE_POD(type_, structure)
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
AV1RawFrameHeader frame_header
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS()
AVBufferRef * data_ref
A reference to the buffer containing data.
#define i(width, name, range_min, range_max)
static int put_bits_count(PutBitContext *s)
@ AV1_METADATA_TYPE_HDR_MDCV
static int cbs_av1_tile_log2(int blksize, int target)
static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
AV1RawTileGroup tile_group
static const AVClass cbs_av1_class
@ AV1_METADATA_TYPE_ITUT_T35
#define CBS_UNIT_TYPE_END_OF_LIST
static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_INPUT_BUFFER_PADDING_SIZE
@ AV1_METADATA_TYPE_TIMECODE
AV1RawSequenceHeader * sequence_header
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int cbs_av1_write_obu(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t value)
@ AV1_METADATA_TYPE_SCALABILITY
static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint64_t value, int fixed_length)
A reference to a data buffer.
AV1RawTileGroup tile_group
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
@ AV1_MAX_OPERATING_POINTS
AV1RawOBU * sequence_header_ref
A RefStruct reference backing sequence_header.
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
static const AVOption cbs_av1_options[]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t *write_to)
AVBufferRef * data_ref
A reference to the buffer containing data.
static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
int fixed_obu_size_length
#define CBS_TRACE_READ_START()
void * priv_data
Format private data.
int nb_units
Number of units in this fragment.
#define CBS_TRACE_READ_END()
#define CBS_TRACE_WRITE_START()