Go to the documentation of this file.
31 const char *
name, uint32_t *write_to,
32 uint32_t range_min, uint32_t range_max)
34 uint32_t zeroes, bits_value,
value;
42 "%s: bitstream ended.\n",
name);
59 "%s: bitstream ended.\n",
name);
64 value = bits_value + (UINT32_C(1) << zeroes) - 1;
69 if (value < range_min || value > range_max) {
71 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
82 uint32_t range_min, uint32_t range_max)
89 if (value < range_min || value > range_max) {
91 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
97 v =
value - (1
U << zeroes) + 1;
112 const char *
name, uint64_t *write_to)
121 for (
i = 0;
i < 8;
i++) {
124 "%s: bitstream ended.\n",
name);
128 value |= (uint64_t)(
byte & 0x7f) << (
i * 7);
133 if (
value > UINT32_MAX)
143 const char *
name, uint64_t
value,
int fixed_length)
153 if (fixed_length <
len) {
155 "fixed length size field (%d > %d).\n",
162 for (
i = 0;
i <
len;
i++) {
166 byte =
value >> (7 *
i) & 0x7f;
179 uint32_t n,
const char *
name,
180 const int *subscripts, uint32_t *write_to)
182 uint32_t m, v, extra_bit,
value;
194 "%s: bitstream ended.\n",
name);
207 value = (v << 1) - m + extra_bit;
217 uint32_t n,
const char *
name,
218 const int *subscripts, uint32_t
value)
220 uint32_t
w, m, v, extra_bit;
226 "%"PRIu32
", but must be in [0,%"PRIu32
"].\n",
241 v = m + ((
value - m) >> 1);
242 extra_bit = (
value - m) & 1;
253 uint32_t range_min, uint32_t range_max,
254 const char *
name, uint32_t *write_to)
260 av_assert0(range_min <= range_max && range_max - range_min < 32);
265 "%s: bitstream ended.\n",
name);
281 uint32_t range_min, uint32_t range_max,
288 av_assert0(range_min <= range_max && range_max - range_min < 32);
289 if (value < range_min || value > range_max) {
291 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
296 if (
value == range_max)
297 len = range_max - range_min;
312 uint32_t range_max,
const char *
name,
313 const int *subscripts, uint32_t *write_to)
315 uint32_t
value, max_len,
len, range_offset, range_bits;
321 max_len =
av_log2(range_max - 1) - 3;
324 "subexp_more_bits", &
len);
329 range_bits = 2 +
len;
330 range_offset = 1 << range_bits;
338 "subexp_bits", &
value);
348 value += range_offset;
357 uint32_t range_max,
const char *
name,
358 const int *subscripts, uint32_t
value)
361 uint32_t max_len,
len, range_offset, range_bits;
365 if (
value > range_max) {
367 "%"PRIu32
", but must be in [0,%"PRIu32
"].\n",
373 max_len =
av_log2(range_max - 1) - 3;
381 len = range_bits - 2;
388 range_offset = 1 << range_bits;
392 "subexp_more_bits",
len);
399 value - range_offset);
405 "subexp_final_bits",
NULL,
406 value - range_offset);
420 for (k = 0; (blksize << k) < target; k++);
425 unsigned int a,
unsigned int b)
427 unsigned int diff, m;
448 #define HEADER(name) do { \
449 ff_cbs_trace_header(ctx, name); \
452 #define CHECK(call) do { \
458 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
459 #define FUNC_AV1(rw, name) FUNC_NAME(rw, av1, name)
460 #define FUNC(name) FUNC_AV1(READWRITE, name)
462 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
464 #define fc(width, name, range_min, range_max) \
465 xf(width, name, current->name, range_min, range_max, 0, )
466 #define flag(name) fb(1, name)
467 #define su(width, name) \
468 xsu(width, name, current->name, 0, )
470 #define fbs(width, name, subs, ...) \
471 xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
472 #define fcs(width, name, range_min, range_max, subs, ...) \
473 xf(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
474 #define flags(name, subs, ...) \
475 xf(1, name, current->name, 0, 1, subs, __VA_ARGS__)
476 #define sus(width, name, subs, ...) \
477 xsu(width, name, current->name, subs, __VA_ARGS__)
479 #define fixed(width, name, value) do { \
480 av_unused uint32_t fixed_value = value; \
481 xf(width, name, fixed_value, value, value, 0, ); \
486 #define READWRITE read
487 #define RWContext GetBitContext
489 #define fb(width, name) do { \
491 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, \
493 current->name = value; \
496 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
498 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
499 SUBSCRIPTS(subs, __VA_ARGS__), \
500 &value, range_min, range_max)); \
504 #define xsu(width, name, var, subs, ...) do { \
506 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
507 SUBSCRIPTS(subs, __VA_ARGS__), &value, \
508 MIN_INT_BITS(width), \
509 MAX_INT_BITS(width))); \
513 #define uvlc(name, range_min, range_max) do { \
515 CHECK(cbs_av1_read_uvlc(ctx, rw, #name, \
516 &value, range_min, range_max)); \
517 current->name = value; \
520 #define ns(max_value, name, subs, ...) do { \
522 CHECK(cbs_av1_read_ns(ctx, rw, max_value, #name, \
523 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
524 current->name = value; \
527 #define increment(name, min, max) do { \
529 CHECK(cbs_av1_read_increment(ctx, rw, min, max, #name, &value)); \
530 current->name = value; \
533 #define subexp(name, max, subs, ...) do { \
535 CHECK(cbs_av1_read_subexp(ctx, rw, max, #name, \
536 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
537 current->name = value; \
540 #define delta_q(name) do { \
541 uint8_t delta_coded; \
543 xf(1, name.delta_coded, delta_coded, 0, 1, 0, ); \
545 xsu(1 + 6, name.delta_q, delta_q, 0, ); \
548 current->name = delta_q; \
551 #define leb128(name) do { \
553 CHECK(cbs_av1_read_leb128(ctx, rw, #name, &value)); \
554 current->name = value; \
557 #define infer(name, value) do { \
558 current->name = value; \
561 #define byte_alignment(rw) (get_bits_count(rw) % 8)
578 #undef byte_alignment
582 #define READWRITE write
583 #define RWContext PutBitContext
585 #define fb(width, name) do { \
586 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
590 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
591 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
592 SUBSCRIPTS(subs, __VA_ARGS__), \
593 var, range_min, range_max)); \
596 #define xsu(width, name, var, subs, ...) do { \
597 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
598 SUBSCRIPTS(subs, __VA_ARGS__), var, \
599 MIN_INT_BITS(width), \
600 MAX_INT_BITS(width))); \
603 #define uvlc(name, range_min, range_max) do { \
604 CHECK(cbs_av1_write_uvlc(ctx, rw, #name, current->name, \
605 range_min, range_max)); \
608 #define ns(max_value, name, subs, ...) do { \
609 CHECK(cbs_av1_write_ns(ctx, rw, max_value, #name, \
610 SUBSCRIPTS(subs, __VA_ARGS__), \
614 #define increment(name, min, max) do { \
615 CHECK(cbs_av1_write_increment(ctx, rw, min, max, #name, \
619 #define subexp(name, max, subs, ...) do { \
620 CHECK(cbs_av1_write_subexp(ctx, rw, max, #name, \
621 SUBSCRIPTS(subs, __VA_ARGS__), \
625 #define delta_q(name) do { \
626 xf(1, name.delta_coded, current->name != 0, 0, 1, 0, ); \
628 xsu(1 + 6, name.delta_q, current->name, 0, ); \
631 #define leb128(name) do { \
632 CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name, 0)); \
635 #define infer(name, value) do { \
636 if (current->name != (value)) { \
637 av_log(ctx->log_ctx, AV_LOG_ERROR, \
638 "%s does not match inferred value: " \
639 "%"PRId64", but should be %"PRId64".\n", \
640 #name, (int64_t)current->name, (int64_t)(value)); \
641 return AVERROR_INVALIDDATA; \
645 #define byte_alignment(rw) (put_bits_count(rw) % 8)
662 #undef byte_alignment
676 trace =
ctx->trace_enable;
677 ctx->trace_enable = 0;
682 if (INT_MAX / 8 <
size) {
692 int config_record_version =
data[0] & 0x7f;
694 if (config_record_version != 1) {
696 "Unknown version %d of AV1CodecConfigurationRecord "
698 config_record_version);
706 "Undersized AV1CodecConfigurationRecord v%d found!\n",
707 config_record_version);
728 err = cbs_av1_read_obu_header(
ctx, &gbc, &
header);
732 if (
header.obu_has_size_field) {
743 obu_size =
size - 1 -
header.obu_extension_flag;
748 obu_length =
pos / 8 + obu_size;
750 if (
size < obu_length) {
752 "%"PRIu64
", but only %"SIZE_SPECIFIER" bytes remaining in fragment.\n",
770 ctx->trace_enable = trace;
784 "any data in tile group (%d bits read).\n",
pos);
806 int err, start_pos, end_pos;
817 err = cbs_av1_read_obu_header(
ctx, &gbc, &obu->
header);
843 int in_temporal_layer =
845 int in_spatial_layer =
847 if (!in_temporal_layer || !in_spatial_layer) {
856 err = cbs_av1_read_sequence_header_obu(
ctx, &gbc,
866 "Must not be higher than %u.\n",
879 err = cbs_av1_read_temporal_delimiter_obu(
ctx, &gbc);
887 err = cbs_av1_read_frame_header_obu(
ctx, &gbc,
898 err = cbs_av1_read_tile_group_obu(
ctx, &gbc,
911 err = cbs_av1_read_frame_obu(
ctx, &gbc, &obu->
obu.
frame,
924 err = cbs_av1_read_tile_list_obu(
ctx, &gbc,
944 err = cbs_av1_read_padding_obu(
ctx, &gbc, &obu->
obu.
padding);
960 int nb_bits = obu->
obu_size * 8 + start_pos - end_pos;
965 err = cbs_av1_read_trailing_bits(
ctx, &gbc, nb_bits);
982 int err, start_pos, end_pos, data_pos;
1003 err = cbs_av1_write_obu_header(
ctx, pbc, &obu->
header);
1025 err = cbs_av1_write_sequence_header_obu(
ctx, pbc,
1043 err = cbs_av1_write_temporal_delimiter_obu(
ctx, pbc);
1051 err = cbs_av1_write_frame_header_obu(
ctx, pbc,
1062 err = cbs_av1_write_tile_group_obu(
ctx, pbc,
1097 err = cbs_av1_write_padding_obu(
ctx, pbc, &obu->
obu.
padding);
1108 header_size = (end_pos - start_pos + 7) / 8;
1111 }
else if (header_size > 0) {
1113 err = cbs_av1_write_trailing_bits(
ctx, pbc, 8 - end_pos % 8);
1117 obu->
obu_size = header_size = (end_pos - start_pos + 7) / 8;
1150 memmove(pbc->
buf + data_pos,
1151 pbc->
buf + start_pos, header_size);
1159 memcpy(pbc->
buf + data_pos + header_size,
1160 td->data,
td->data_size);
1212 memset(priv->
ref, 0,
sizeof(priv->
ref));
1234 switch (
md->metadata_type) {
1269 #define OFFSET(x) offsetof(CodedBitstreamAV1Context, x)
1271 {
"operating_point",
"Set operating point to select layers to parse from a scalable bitstream",
1273 {
"fixed_obu_size_length",
"Set fixed length of the obu_size field",
static void error(const char *err)
#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 const AVClass cbs_av1_class
static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[]
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
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.
static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t value)
@ AV1_METADATA_TYPE_ITUT_T35
void(* close)(CodedBitstreamContext *ctx)
uint8_t * data
The data buffer.
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)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
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)
Context structure for coded bitstream operations.
AVBufferRef * frame_header_ref
static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, uint64_t *write_to)
static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t n, const char *name, const int *subscripts, uint32_t *write_to)
CodedBitstreamUnitType type
Codec-specific type of this unit.
RefStruct is an API for creating reference-counted objects with minimal overhead.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
@ AV1_OBU_TEMPORAL_DELIMITER
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Coded bitstream unit structure.
static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t *write_to)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
#define CBS_TRACE_WRITE_END_VALUE_ONLY()
AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]
@ AV1_METADATA_TYPE_HDR_MDCV
static int put_bits_left(PutBitContext *s)
static void cbs_av1_close(CodedBitstreamContext *ctx)
@ AV1_MAX_OPERATING_POINTS
const CodedBitstreamType ff_cbs_type_av1
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
static int cbs_av1_write_obu(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
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.
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)
Coded bitstream fragment structure, combining one or more units.
size_t data_size
The number of bytes in the bitstream.
static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, GetBitContext *gbc, AV1RawTileData *td)
static void cbs_av1_free_metadata(FFRefStructOpaque unused, void *content)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint32_t value, uint32_t range_min, uint32_t range_max)
int ff_cbs_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.
#define MAX_UINT_BITS(length)
#define CBS_TRACE_WRITE_END()
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
#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.
static int cbs_av1_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
static const AVOption cbs_av1_options[]
#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).
static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t value)
int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
#define CBS_TRACE_READ_END_VALUE_ONLY()
@ AV1_METADATA_TYPE_SCALABILITY
static void cbs_av1_flush(CodedBitstreamContext *ctx)
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
AV1RawSequenceHeader sequence_header
uint8_t * data
Pointer to the bitstream form of this fragment.
@ AV1_OBU_SEQUENCE_HEADER
const CodedBitstreamUnitTypeDescriptor * unit_types
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)
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
static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static int cbs_av1_tile_log2(int blksize, int target)
#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)
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int put_bits_count(PutBitContext *s)
static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint64_t value, int fixed_length)
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
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
AV1RawTileGroup tile_group
#define CBS_UNIT_TYPE_END_OF_LIST
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
#define AV_INPUT_BUFFER_PADDING_SIZE
static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
AV1RawSequenceHeader * sequence_header
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
void(* flush)(AVBSFContext *ctx)
AV1RawTileGroup tile_group
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t n, const char *name, const int *subscripts, uint32_t value)
@ AV1_METADATA_TYPE_TIMECODE
AV1RawOBU * sequence_header_ref
A RefStruct reference backing sequence_header.
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
@ AV1_METADATA_TYPE_HDR_CLL
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVBufferRef * data_ref
A reference to the buffer containing data.
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
int fixed_obu_size_length
#define CBS_TRACE_READ_START()
void * priv_data
Format private data.
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
int nb_units
Number of units in this fragment.
#define CBS_TRACE_READ_END()
#define CBS_TRACE_WRITE_START()