65 if (cbs_type_table[i]->codec_id == codec_id) {
66 type = cbs_type_table[i];
126 for (i = 0; i < frag->
nb_units; i++)
142 for (i = 0; i < frag->
nb_units; i++) {
158 "Decomposition unimplemented for unit %d " 159 "(type %"PRIu32
").\n", i, frag->
units[i].
type);
160 }
else if (err < 0) {
162 "(type %"PRIu32
").\n", i, frag->
units[i].
type);
176 memset(frag, 0,
sizeof(*frag));
205 memcpy(frag->
data, data, size);
206 memset(frag->
data + size, 0,
218 memset(frag, 0,
sizeof(*frag));
247 memset(frag, 0,
sizeof(*frag));
266 for (i = 0; i < frag->
nb_units; i++) {
278 "(type %"PRIu32
").\n", i, unit->
type);
355 const char *
name,
const char *bits,
358 size_t name_len, bits_len;
364 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
366 name_len = strlen(name);
367 bits_len = strlen(bits);
369 if (name_len + bits_len > 60)
375 position, name, pad, bits, value);
379 int width,
const char *
name, uint32_t *write_to,
380 uint32_t range_min, uint32_t range_max)
389 "%s: bitstream ended.\n", name);
401 for (i = 0; i <
width; i++)
402 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
408 if (value < range_min || value > range_max) {
410 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
411 name, value, range_min, range_max);
421 uint32_t range_min, uint32_t range_max)
425 if (value < range_min || value > range_max) {
427 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
428 name, value, range_min, range_max);
438 for (i = 0; i <
width; i++)
439 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
504 memcpy(units, frag->
units, position *
sizeof(*units));
505 if (position < frag->nb_units)
506 memcpy(units + position + 1, frag->
units + position,
507 (frag->
nb_units - position) *
sizeof(*units));
509 memset(units + position, 0,
sizeof(*units));
531 av_assert0(position >= 0 && position <= frag->nb_units);
547 unit = &frag->
units[position];
568 av_assert0(position >= 0 && position <= frag->nb_units);
583 unit = &frag->
units[position];
596 if (position < 0 || position >= frag->
nb_units)
607 memmove(frag->
units + position,
608 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_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.
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.
#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.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static const CodedBitstreamType * cbs_type_table[]
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value, uint32_t range_min, uint32_t range_max)
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)
#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.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
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.
static int get_bits_left(GetBitContext *gb)
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)
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
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
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.
int ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
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.
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)
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...
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *name, const char *bits, int64_t value)
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
If data is reference counted, 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
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
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
If data is reference counted, a reference to the buffer containing data.
This structure stores compressed data.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to, uint32_t range_min, uint32_t range_max)