Go to the documentation of this file.
95 ctx->log_ctx = log_ctx;
98 if (
type->priv_data_size) {
106 ctx->decompose_unit_types =
NULL;
108 ctx->trace_enable = 0;
122 if (
ctx->codec &&
ctx->codec->close)
174 if (
ctx->decompose_unit_types) {
175 for (j = 0; j <
ctx->nb_decompose_unit_types; j++) {
176 if (
ctx->decompose_unit_types[j] == unit->
type)
179 if (j >=
ctx->nb_decompose_unit_types)
188 err =
ctx->codec->read_unit(
ctx, unit);
191 "Decomposition unimplemented for unit %d "
192 "(type %"PRIu32
").\n",
i, unit->
type);
193 }
else if (err < 0) {
195 "(type %"PRIu32
").\n",
i, unit->
type);
235 err =
ctx->codec->split_fragment(
ctx, frag, 1);
262 err =
ctx->codec->split_fragment(
ctx, frag, 0);
279 err =
ctx->codec->split_fragment(
ctx, frag, 0);
292 if (!
ctx->write_buffer) {
294 ctx->write_buffer_size = 1024 * 1024;
296 reallocate_and_try_again:
300 "sufficiently large write buffer (last attempt "
308 ret =
ctx->codec->write_unit(
ctx, unit, &pbc);
312 if (
ctx->write_buffer_size == INT_MAX / 8)
314 ctx->write_buffer_size =
FFMIN(2 *
ctx->write_buffer_size, INT_MAX / 8);
315 goto reallocate_and_try_again;
357 "(type %"PRIu32
").\n",
i, unit->
type);
366 err =
ctx->codec->assemble_fragment(
ctx, frag);
429 if (!
ctx->trace_enable)
436 const char *str,
const int *subscripts,
440 size_t name_len, bits_len;
441 int pad, subs,
i, j, k,
n;
443 if (!
ctx->trace_enable)
448 subs = subscripts ? subscripts[0] : 0;
450 for (
i = j = 0; str[
i];) {
457 for (++
i; str[
i] && str[
i] !=
']';
i++);
460 while (str[
i] && str[
i] !=
']')
461 name[j++] = str[
i++];
466 name[j++] = str[
i++];
473 name_len = strlen(
name);
474 bits_len = strlen(
bits);
476 if (name_len + bits_len > 60)
481 av_log(
ctx->log_ctx,
ctx->trace_level,
"%-10d %s%*s = %"PRId64
"\n",
487 const int *subscripts, uint32_t *write_to,
488 uint32_t range_min, uint32_t range_max)
497 "%s: bitstream ended.\n",
name);
501 if (
ctx->trace_enable)
506 if (
ctx->trace_enable) {
517 if (value < range_min || value > range_max) {
519 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
530 const int *subscripts, uint32_t
value,
531 uint32_t range_min, uint32_t range_max)
535 if (value < range_min || value > range_max) {
537 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
545 if (
ctx->trace_enable) {
566 const int *subscripts,
int32_t *write_to,
576 "%s: bitstream ended.\n",
name);
580 if (
ctx->trace_enable)
585 if (
ctx->trace_enable) {
596 if (value < range_min || value > range_max) {
598 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
614 if (value < range_min || value > range_max) {
616 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
624 if (
ctx->trace_enable) {
692 if (position < frag->nb_units)
693 memmove(units + position + 1, units + position,
694 (frag->
nb_units - position) *
sizeof(*units));
703 memcpy(units, frag->
units, position *
sizeof(*units));
705 if (position < frag->nb_units)
706 memcpy(units + position + 1, frag->
units + position,
707 (frag->
nb_units - position) *
sizeof(*units));
710 memset(units + position, 0,
sizeof(*units));
712 if (units != frag->
units) {
735 av_assert0(position >= 0 && position <= frag->nb_units);
751 unit = &frag->
units[position];
772 av_assert0(position >= 0 && position <= frag->nb_units);
787 unit = &frag->
units[position];
800 av_assert0(0 <= position && position < frag->nb_units
801 &&
"Unit to be deleted not in fragment.");
808 memmove(frag->
units + position,
809 frag->
units + position + 1,
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
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 cbs_unit_uninit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static const CodedBitstreamType * cbs_type_table[]
This struct describes the properties of an encoded stream.
uint8_t * data
The data buffer.
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...
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 void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int get_bits_count(const GetBitContext *s)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const CodedBitstreamType ff_cbs_type_vp9
Context structure for coded bitstream operations.
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
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.
#define AV_LOG_VERBOSE
Detailed information.
static int cbs_insert_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
CodedBitstreamUnitType type
Codec-specific type of this unit.
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.
Coded bitstream unit structure.
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)
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
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.
static int put_bits_left(PutBitContext *s)
const CodedBitstreamType ff_cbs_type_av1
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
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
static int cbs_write_unit_data(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_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.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const CodedBitstreamType ff_cbs_type_mpeg2
Coded bitstream fragment structure, combining one or more units.
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
size_t data_size
The number of bytes in the bitstream.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
AVCodecID
Identify the syntax and semantics of the bitstream.
int extradata_size
Size of the extradata content in bytes.
uint8_t * data
Pointer to the bitstream form of this fragment.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
const CodedBitstreamType ff_cbs_type_jpeg
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)
static int cbs_fill_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
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)
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
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)
#define av_malloc_array(a, b)
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
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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)
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
int nb_units_allocated
Number of allocated units.
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
#define AV_INPUT_BUFFER_PADDING_SIZE
#define FF_ARRAY_ELEMS(a)
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.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
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...
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
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.
A reference to a data buffer.
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.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
This structure stores compressed data.
const CodedBitstreamType ff_cbs_type_h264
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVBufferRef * data_ref
A reference to the buffer containing data.
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
const CodedBitstreamType ff_cbs_type_h265
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void * priv_data
Format private data.
int nb_units
Number of units in this fragment.