Go to the documentation of this file.
97 ctx->log_ctx = log_ctx;
100 if (
type->priv_data_size) {
106 if (
type->priv_class) {
112 ctx->decompose_unit_types =
NULL;
114 ctx->trace_enable = 0;
123 if (
ctx->codec->flush)
134 if (
ctx->codec->close)
187 if (
ctx->decompose_unit_types) {
188 for (j = 0; j <
ctx->nb_decompose_unit_types; j++) {
189 if (
ctx->decompose_unit_types[j] == unit->
type)
192 if (j >=
ctx->nb_decompose_unit_types)
201 err =
ctx->codec->read_unit(
ctx, unit);
204 "Decomposition unimplemented for unit %d "
205 "(type %"PRIu32
").\n",
i, unit->
type);
206 }
else if (err ==
AVERROR(EAGAIN)) {
208 "Skipping decomposition of unit %d "
209 "(type %"PRIu32
").\n",
i, unit->
type);
212 }
else if (err < 0) {
214 "(type %"PRIu32
").\n",
i, unit->
type);
301 size_t side_data_size;
302 const uint8_t *side_data =
307 side_data, side_data_size, 1);
346 if (!
ctx->write_buffer) {
348 ctx->write_buffer_size = 1024 * 1024;
350 reallocate_and_try_again:
354 "sufficiently large write buffer (last attempt "
362 ret =
ctx->codec->write_unit(
ctx, unit, &pbc);
366 if (
ctx->write_buffer_size == INT_MAX / 8)
368 ctx->write_buffer_size =
FFMIN(2 *
ctx->write_buffer_size, INT_MAX / 8);
369 goto reallocate_and_try_again;
411 "(type %"PRIu32
").\n",
i, unit->
type);
420 err =
ctx->codec->assemble_fragment(
ctx, frag);
483 if (!
ctx->trace_enable)
490 const char *
str,
const int *subscripts,
494 size_t name_len, bits_len;
495 int pad, subs,
i, j, k, n;
497 if (!
ctx->trace_enable)
502 subs = subscripts ? subscripts[0] : 0;
504 for (
i = j = 0;
str[
i];) {
527 name_len = strlen(
name);
528 bits_len = strlen(
bits);
530 if (name_len + bits_len > 60)
535 av_log(
ctx->log_ctx,
ctx->trace_level,
"%-10d %s%*s = %"PRId64
"\n",
541 const int *subscripts, uint32_t *write_to,
542 uint32_t range_min, uint32_t range_max)
551 "%s: bitstream ended.\n",
name);
555 if (
ctx->trace_enable)
560 if (
ctx->trace_enable) {
571 if (value < range_min || value > range_max) {
573 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
584 const int *subscripts, uint32_t
value,
585 uint32_t range_min, uint32_t range_max)
589 if (value < range_min || value > range_max) {
591 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
599 if (
ctx->trace_enable) {
620 const int *subscripts,
int32_t *write_to,
630 "%s: bitstream ended.\n",
name);
634 if (
ctx->trace_enable)
639 if (
ctx->trace_enable) {
650 if (value < range_min || value > range_max) {
652 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
668 if (value < range_min || value > range_max) {
670 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
678 if (
ctx->trace_enable) {
700 void (*free)(
void *opaque, uint8_t *
data))
726 if (position < frag->nb_units)
727 memmove(units + position + 1, units + position,
728 (frag->
nb_units - position) *
sizeof(*units));
737 memcpy(units, frag->
units, position *
sizeof(*units));
739 if (position < frag->nb_units)
740 memcpy(units + position + 1, frag->
units + position,
741 (frag->
nb_units - position) *
sizeof(*units));
744 memset(units + position, 0,
sizeof(*units));
746 if (units != frag->
units) {
768 av_assert0(position >= 0 && position <= frag->nb_units);
784 unit = &frag->
units[position];
795 uint8_t *
data,
size_t data_size,
804 av_assert0(position >= 0 && position <= frag->nb_units);
822 unit = &frag->
units[position];
834 av_assert0(0 <= position && position < frag->nb_units
835 &&
"Unit to be deleted not in fragment.");
842 memmove(frag->
units + position,
843 frag->
units + position + 1,
852 for (
i = 0;
i <
desc->nb_ref_offsets;
i++) {
853 void **ptr = (
void**)(
data +
desc->ref_offsets[
i]);
867 if (!
ctx->codec->unit_types)
872 if (
desc->nb_unit_types == 0)
875 if (unit->
type >=
desc->unit_type_range_start &&
876 unit->
type <=
desc->unit_type_range_end)
879 for (j = 0; j <
desc->nb_unit_types; j++) {
880 if (
desc->unit_types[j] == unit->
type)
905 desc->content_free ?
desc->content_free
921 uint8_t **src_ptr, **copy_ptr;
932 for (
i = 0;
i <
desc->nb_ref_offsets;
i++) {
933 src_ptr = (uint8_t**)(
src +
desc->ref_offsets[
i]);
935 copy_ptr = (uint8_t**)(
copy +
desc->ref_offsets[
i]);
953 *src_ptr < (*src_buf)->data + (*src_buf)->size);
960 *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
964 desc->content_free ?
desc->content_free :
975 for (--
i;
i >= 0;
i--)
999 switch (
desc->content_type) {
1013 if (!
desc->content_clone)
1015 err =
desc->content_clone(&
ref, unit);
1050 switch (
desc->content_type) {
1060 if (!
desc->content_clone)
1062 err =
desc->content_clone(&
ref, unit);
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
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
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.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
static int put_bytes_output(const PutBitContext *s)
This struct describes the properties of an encoded stream.
uint8_t * data
The data buffer.
static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
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 int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
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)
int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
static int cbs_read_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, AVBufferRef *buf, const uint8_t *data, size_t size, int header)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const CodedBitstreamType ff_cbs_type_vp9
void ff_cbs_fragment_reset(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.
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
#define AV_LOG_VERBOSE
Detailed information.
CodedBitstreamUnitType type
Codec-specific type of this unit.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Coded bitstream unit structure.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
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)
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
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.
@ CBS_CONTENT_TYPE_INTERNAL_REFS
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_make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit writable so that internal fields can be modified.
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
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
#define FF_ARRAY_ELEMS(a)
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.
int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static const CodedBitstreamType *const cbs_type_table[]
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
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).
void av_opt_free(void *obj)
Free all allocated objects in obj.
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVCodecID
Identify the syntax and semantics of the bitstream.
int extradata_size
Size of the extradata content in bytes.
static int cbs_clone_unit_content(AVBufferRef **clone_ref, CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
static void copy(const float *p1, float *p2, const int length)
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
@ CBS_CONTENT_TYPE_COMPLEX
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
static const uint8_t header[24]
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)
int ff_cbs_insert_unit_data(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.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
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_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
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)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#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_make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
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.
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
int av_buffer_is_writable(const AVBufferRef *buf)
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
main external API structure.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
static int cbs_alloc_unit_data(CodedBitstreamUnit *unit, size_t size)
Allocate a new internal data buffer of the given size in the unit.
static int ref[MAX_W *MAX_W]
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.
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.
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.