83 if (cbs_type_table[i]->codec_id == codec_id) {
84 type = cbs_type_table[
i];
144 for (i = 0; i < frag->
nb_units; i++)
168 for (i = 0; i < frag->
nb_units; i++) {
188 "Decomposition unimplemented for unit %d " 189 "(type %"PRIu32
").\n", i, unit->
type);
190 }
else if (err < 0) {
192 "(type %"PRIu32
").\n", i, unit->
type);
214 memcpy(frag->
data, data, size);
215 memset(frag->
data + size, 0,
289 for (i = 0; i < frag->
nb_units; i++) {
301 "(type %"PRIu32
").\n", i, unit->
type);
380 const char *str,
const int *subscripts,
384 size_t name_len, bits_len;
385 int pad, subs,
i, j, k,
n;
390 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
392 subs = subscripts ? subscripts[0] : 0;
394 for (i = j = 0; str[
i];) {
398 k =
snprintf(name + j,
sizeof(name) - j,
"[%d", subscripts[n]);
401 for (++i; str[
i] && str[
i] !=
']'; i++);
404 while (str[i] && str[i] !=
']')
405 name[j++] = str[i++];
410 name[j++] = str[i++];
417 name_len = strlen(name);
418 bits_len = strlen(bits);
420 if (name_len + bits_len > 60)
426 position, name, pad, bits, value);
431 const int *subscripts, uint32_t *write_to,
432 uint32_t range_min, uint32_t range_max)
441 "%s: bitstream ended.\n", name);
453 for (i = 0; i <
width; i++)
454 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
461 if (value < range_min || value > range_max) {
463 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
464 name, value, range_min, range_max);
474 const int *subscripts, uint32_t
value,
475 uint32_t range_min, uint32_t range_max)
479 if (value < range_min || value > range_max) {
481 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
482 name, value, range_min, range_max);
492 for (i = 0; i <
width; i++)
493 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
497 name, subscripts, bits, value);
510 const int *subscripts,
int32_t *write_to,
520 "%s: bitstream ended.\n", name);
532 for (i = 0; i <
width; i++)
533 bits[i] = value & (1
U << (width - i - 1)) ?
'1' :
'0';
540 if (value < range_min || value > range_max) {
542 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
543 name, value, range_min, range_max);
558 if (value < range_min || value > range_max) {
560 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
561 name, value, range_min, range_max);
571 for (i = 0; i <
width; i++)
572 bits[i] = value & (1
U << (width - i - 1)) ?
'1' :
'0';
576 name, subscripts, bits, value);
636 if (position < frag->nb_units)
637 memmove(units + position + 1, units + position,
638 (frag->
nb_units - position) *
sizeof(*units));
647 memcpy(units, frag->
units, position *
sizeof(*units));
649 if (position < frag->nb_units)
650 memcpy(units + position + 1, frag->
units + position,
651 (frag->
nb_units - position) *
sizeof(*units));
654 memset(units + position, 0,
sizeof(*units));
656 if (units != frag->
units) {
679 av_assert0(position >= 0 && position <= frag->nb_units);
695 unit = &frag->
units[position];
716 av_assert0(position >= 0 && position <= frag->nb_units);
731 unit = &frag->
units[position];
744 av_assert0(0 <= position && position < frag->nb_units
745 &&
"Unit to be deleted not in fragment.");
752 memmove(frag->
units + position,
753 frag->
units + position + 1,
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
int nb_units
Number of units in this fragment.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
static void cbs_unit_uninit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
void ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
CodedBitstreamUnitType type
Codec-specific type of this unit.
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
This struct describes the properties of an encoded stream.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
int ff_cbs_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)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int trace_enable
Enable trace output during read/write operations.
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
int ff_cbs_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)
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static const CodedBitstreamType * cbs_type_table[]
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
static int get_bits_count(const GetBitContext *s)
int ff_cbs_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)
#define AV_LOG_VERBOSE
Detailed information.
int ff_cbs_alloc_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size)
Allocate a new internal data buffer of the given size in the unit.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
int ff_cbs_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_insert_unit_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Insert a new unit into a fragment with the given data bitstream.
size_t data_size
The number of bytes in the bitstream.
void ff_cbs_fragment_free(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
static int get_bits_left(GetBitContext *gb)
#define i(width, name, range_min, range_max)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* close)(CodedBitstreamContext *ctx)
static int put_bits_left(PutBitContext *s)
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static int put_bits_count(PutBitContext *s)
int extradata_size
Size of the extradata content in bytes.
const CodedBitstreamType ff_cbs_type_mpeg2
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
const CodedBitstreamType ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_av1
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
preferred ID for MPEG-1/2 video decoding
uint8_t * data
Pointer to the bitstream form of this fragment.
#define FF_ARRAY_ELEMS(a)
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
int nb_decompose_unit_types
Length of the decompose_unit_types array.
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Coded bitstream fragment structure, combining one or more units.
const CodedBitstreamType ff_cbs_type_jpeg
uint8_t * data
The data buffer.
int trace_level
Log level to use for trace output.
static int cbs_fill_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
void ff_cbs_fragment_reset(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Context structure for coded bitstream operations.
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
refcounted data buffer API
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
int ff_cbs_read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecParameters *par)
Read the extradata bitstream found in codec parameters into a fragment, then split into units and dec...
int nb_units_allocated
Number of allocated units.
void * priv_data
Internal codec-specific data.
A reference to a data buffer.
common internal and external API header
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
AVBufferRef * data_ref
A reference to the buffer containing data.
static int cbs_insert_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
CodedBitstreamUnitType * decompose_unit_types
Array of unit types which should be decomposed when reading.
const CodedBitstreamType ff_cbs_type_h265
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
const struct CodedBitstreamType * codec
Internal codec-specific hooks.
#define av_malloc_array(a, b)
int ff_cbs_read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Read a bitstream from a memory region into a fragment, then split into units and decompose.
AVBufferRef * data_ref
A reference to the buffer containing data.
const CodedBitstreamType ff_cbs_type_vp9
This structure stores compressed data.
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).