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++)
160 for (i = 0; i < frag->
nb_units; i++) {
180 "Decomposition unimplemented for unit %d "
181 "(type %"PRIu32
").\n", i, unit->
type);
182 }
else if (err < 0) {
184 "(type %"PRIu32
").\n", i, unit->
type);
206 memcpy(frag->
data, data, size);
207 memset(frag->
data + size, 0,
219 memset(frag, 0,
sizeof(*frag));
239 memset(frag, 0,
sizeof(*frag));
268 memset(frag, 0,
sizeof(*frag));
287 for (i = 0; i < frag->
nb_units; i++) {
299 "(type %"PRIu32
").\n", i, unit->
type);
377 const char *str,
const int *subscripts,
378 const char *bits, int64_t
value)
381 size_t name_len, bits_len;
382 int pad, subs, i, j, k,
n;
387 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
389 subs = subscripts ? subscripts[0] : 0;
391 for (i = j = 0; str[i];) {
395 k =
snprintf(name + j,
sizeof(name) - j,
"[%d", subscripts[n]);
398 for (++i; str[i] && str[i] !=
']'; i++);
401 while (str[i] && str[i] !=
']')
402 name[j++] = str[i++];
407 name[j++] = str[i++];
414 name_len = strlen(name);
415 bits_len = strlen(bits);
417 if (name_len + bits_len > 60)
423 position, name, pad, bits, value);
428 const int *subscripts, uint32_t *write_to,
429 uint32_t range_min, uint32_t range_max)
438 "%s: bitstream ended.\n", name);
450 for (i = 0; i <
width; i++)
451 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
460 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
461 name, value, range_min, range_max);
471 const int *subscripts, uint32_t
value,
472 uint32_t range_min, uint32_t range_max)
478 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
479 name, value, range_min, range_max);
489 for (i = 0; i <
width; i++)
490 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
494 name, subscripts, bits, value);
556 memcpy(units, frag->
units, position *
sizeof(*units));
557 if (position < frag->nb_units)
558 memcpy(units + position + 1, frag->
units + position,
559 (frag->
nb_units - position) *
sizeof(*units));
561 memset(units + position, 0,
sizeof(*units));
583 av_assert0(position >= 0 && position <= frag->nb_units);
599 unit = &frag->
units[position];
620 av_assert0(position >= 0 && position <= frag->nb_units);
635 unit = &frag->
units[position];
648 if (position < 0 || position >= frag->
nb_units)
659 memmove(frag->
units + position,
660 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...
ptrdiff_t const GLvoid * data
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)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
This struct describes the properties of an encoded stream.
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.
#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[]
void(* close)(CodedBitstreamContext *ctx)
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 ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
static int put_bits_left(PutBitContext *s)
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
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().
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.
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
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(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
GLsizei GLboolean const GLfloat * value
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.
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)
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.
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 * priv_data
Internal codec-specific data.
A reference to a data buffer.
common internal and external API 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
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
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).
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)