Go to the documentation of this file.
115 ctx->log_ctx = log_ctx;
118 if (
type->priv_data_size) {
124 if (
type->priv_class) {
130 ctx->decompose_unit_types =
NULL;
132 ctx->trace_enable = 0;
142 if (
ctx->codec->flush)
153 if (
ctx->codec->close)
180 for (
i = 0;
i < frag->nb_units;
i++)
187 frag->data_bit_padding = 0;
195 frag->nb_units_allocated = 0;
207 if (
ctx->decompose_unit_types) {
208 for (j = 0; j <
ctx->nb_decompose_unit_types; j++) {
209 if (
ctx->decompose_unit_types[j] == unit->
type)
212 if (j >=
ctx->nb_decompose_unit_types)
221 err =
ctx->codec->read_unit(
ctx, unit);
224 "Decomposition unimplemented for unit %d "
225 "(type %"PRIu32
").\n",
i, unit->
type);
226 }
else if (err ==
AVERROR(EAGAIN)) {
228 "Skipping decomposition of unit %d "
229 "(type %"PRIu32
").\n",
i, unit->
type);
232 }
else if (err < 0) {
234 "(type %"PRIu32
").\n",
i, unit->
type);
297 par->extradata_size, 1);
306 avctx->extradata_size, 1);
321 size_t side_data_size;
322 const uint8_t *side_data =
327 side_data, side_data_size, 1);
369 if (!
ctx->write_buffer) {
371 ctx->write_buffer_size = 1024 * 1024;
373 reallocate_and_try_again:
377 "sufficiently large write buffer (last attempt "
385 ret =
ctx->codec->write_unit(
ctx, unit, &pbc);
389 if (
ctx->write_buffer_size == INT_MAX / 8)
391 ctx->write_buffer_size =
FFMIN(2 *
ctx->write_buffer_size, INT_MAX / 8);
392 goto reallocate_and_try_again;
422 for (
i = 0;
i < frag->nb_units;
i++) {
434 "(type %"PRIu32
").\n",
i, unit->
type);
443 err =
ctx->codec->assemble_fragment(
ctx, frag);
464 par->extradata_size = 0;
466 if (!frag->data_size)
469 par->extradata =
av_malloc(frag->data_size +
474 memcpy(par->extradata, frag->data, frag->data_size);
475 memset(par->extradata + frag->data_size, 0,
477 par->extradata_size = frag->data_size;
512 if (!
ctx->trace_enable)
521 const char *str,
const int *subscripts,
528 size_t name_len, bits_len;
529 int pad, subs,
i, j, k, n;
537 for (
i = 0;
i < length;
i++)
541 subs = subscripts ? subscripts[0] : 0;
543 for (
i = j = 0; str[
i];) {
550 for (++
i; str[
i] && str[
i] !=
']';
i++);
553 while (str[
i] && str[
i] !=
']')
554 name[j++] = str[
i++];
559 name[j++] = str[
i++];
566 name_len = strlen(
name);
569 if (name_len + bits_len > 60)
574 av_log(
ctx->log_ctx,
ctx->trace_level,
"%-10d %s%*s = %"PRId64
"\n",
581 const char *str,
const int *subscripts,
615 const int *subscripts,
628 "%s: bitstream ended.\n",
name);
636 if (value < range_min || value > range_max) {
638 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
649 const int *subscripts, uint32_t *write_to,
650 uint32_t range_min, uint32_t range_max)
653 write_to, range_min, range_max);
657 int width,
const char *
name, uint32_t *write_to)
660 write_to, 0, UINT32_MAX);
667 const int *subscripts, uint32_t
value,
668 uint32_t range_min, uint32_t range_max)
674 if (value < range_min || value > range_max) {
676 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
702 const int *subscripts,
int32_t *write_to,
713 "%s: bitstream ended.\n",
name);
721 if (value < range_min || value > range_max) {
723 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
743 if (value < range_min || value > range_max) {
745 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
770 if (position < frag->nb_units)
771 memmove(units + position + 1, units + position,
772 (frag->
nb_units - position) *
sizeof(*units));
781 memcpy(units, frag->
units, position *
sizeof(*units));
783 if (position < frag->nb_units)
784 memcpy(units + position + 1, frag->
units + position,
785 (frag->
nb_units - position) *
sizeof(*units));
788 memset(units + position, 0,
sizeof(*units));
790 if (units != frag->
units) {
810 position = frag->nb_units;
811 av_assert0(position >= 0 && position <= frag->nb_units);
822 unit = &frag->units[position];
832 uint8_t *
data,
size_t data_size,
840 av_assert0(position >= 0 && position <= frag->nb_units);
858 unit = &frag->
units[position];
869 uint8_t *
data,
size_t data_size,
873 data, data_size, data_buf,
880 av_assert0(0 <= position && position < frag->nb_units
881 &&
"Unit to be deleted not in fragment.");
887 if (frag->nb_units > 0)
888 memmove(frag->units + position,
889 frag->units + position + 1,
890 (frag->nb_units - position) *
sizeof(*frag->units));
897 for (
int i = 0;
i <
desc->type.ref.nb_offsets;
i++) {
898 void **ptr = (
void**)((
char*)content +
desc->type.ref.offsets[
i]);
910 if (!
ctx->codec->unit_types)
915 if (
desc->nb_unit_types == 0)
918 if (unit->
type >=
desc->unit_type.range.start &&
919 unit->
type <=
desc->unit_type.range.end)
922 for (j = 0; j <
desc->nb_unit_types; j++) {
923 if (
desc->unit_type.list[j] == unit->
type)
936 ?
desc->type.complex.content_free
945 av_assert0(!unit->content && !unit->content_ref);
952 if (!unit->content_ref)
954 unit->content = unit->content_ref;
974 for (
int i = 0;
i <
desc->type.ref.nb_offsets;
i++) {
975 void **ptr = (
void**)(
copy +
desc->type.ref.offsets[
i]);
980 for (
i = 0;
i <
desc->type.ref.nb_offsets;
i++) {
981 const uint8_t *
const *src_ptr = (
const uint8_t*
const*)(
src +
desc->type.ref.offsets[
i]);
983 uint8_t **copy_ptr = (uint8_t**)(
copy +
desc->type.ref.offsets[
i]);
1029 switch (
desc->content_type) {
1035 if (!
desc->type.complex.content_clone)
1037 err =
desc->type.complex.content_clone(&new_content, unit);
1056 if (unit->content_ref)
1064 void *
ref = unit->content_ref;
1083 if (!
ctx->codec->discarded_unit)
1086 for (
int i = frag->nb_units - 1;
i >= 0;
i--) {
1087 if (
ctx->codec->discarded_unit(
ctx, &frag->units[
i],
skip)) {
int CBS_FUNC() make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit writable so that internal fields can be modified.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
int CBS_FUNC() 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 * content_ref
If content is reference counted, a RefStruct reference backing content.
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
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
void CBS_FUNC() delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
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 int put_bytes_output(const PutBitContext *s)
This struct describes the properties of an encoded stream.
@ 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...
uint8_t * data
The data buffer.
RefStruct is an API for creating reference-counted objects with minimal overhead.
int CBS_FUNC() read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
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 init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int get_bits_count(const GetBitContext *s)
int CBS_FUNC() read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
int CBS_FUNC() append_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Add a new unit to a fragment with the given data bitstream.
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Context structure for coded bitstream operations.
void CBS_FUNC() trace_read_log(void *trace_context, GetBitContext *gbc, int length, const char *str, const int *subscripts, int64_t value)
Helper function for read tracing which formats the syntax element and logs the result.
static av_const unsigned zero_extend(unsigned val, unsigned bits)
void CBS_FUNC() discard_units(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, enum AVDiscard skip, int flags)
Discard units accroding to 'skip'.
#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.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Coded bitstream unit structure.
int CBS_FUNC() 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)
int av_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
int CBS_FUNC() write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
static av_always_inline int 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)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
static int put_bits_left(PutBitContext *s)
void av_opt_free(void *obj)
Free all allocated objects in obj.
static void * cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
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
int CBS_FUNC() alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int CBS_FUNC() insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
Coded bitstream fragment structure, combining one or more units.
size_t data_size
The number of bytes in the bitstream.
void * av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
static int cbs_insert_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf, int position)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
int CBS_FUNC() 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)
static void put_bits63(PutBitContext *s, int n, uint64_t value)
Write up to 63 bits into a bitstream.
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
#define MAX_UINT_BITS(length)
#define CBS_TRACE_WRITE_END()
av_cold int CBS_FUNC() init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
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 CBS_FUNC() write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
static unsigned int get_bits1(GetBitContext *s)
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
av_cold void CBS_FUNC() close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
static int cbs_clone_noncomplex_unit_content(void **clonep, const CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
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 CBS_FUNC() read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
enum AVCodecID CBS_FUNC(all_codec_ids)[]
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 void copy(const float *p1, float *p2, const int length)
av_cold void CBS_FUNC() flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
int CBS_FUNC() write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
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.
int CBS_FUNC() make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
@ CBS_CONTENT_TYPE_COMPLEX
void CBS_FUNC() trace_header(CodedBitstreamContext *ctx, const char *name)
static const uint8_t header[24]
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
static int cbs_write_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
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)
int CBS_FUNC() 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.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
void CBS_FUNC() trace_write_log(void *trace_context, PutBitContext *pbc, int length, const char *str, const int *subscripts, int64_t value)
Helper function for write tracing which formats the syntax element and logs the result.
#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
int CBS_FUNC() 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)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void cbs_default_free_unit_content(AVRefStructOpaque opaque, void *content)
int nb_units_allocated
Number of allocated units.
static const CodedBitstreamType *const cbs_type_table[]
#define AV_INPUT_BUFFER_PADDING_SIZE
static int cbs_clone_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
main external API structure.
@ DISCARD_FLAG_KEEP_NON_VCL
keep non-vcl units even if the picture has been dropped.
int CBS_FUNC() read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVBufferRef *buf, 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 ref[MAX_W *MAX_W]
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
int CBS_FUNC() 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)
av_cold void CBS_FUNC() fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
A reference to a data buffer.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
void CBS_FUNC() 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...
This structure stores compressed data.
int CBS_FUNC() write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVBufferRef * data_ref
A reference to the buffer containing data.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define CBS_TRACE_READ_START()
void * priv_data
Format private data.
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
int nb_units
Number of units in this fragment.
static int cbs_read_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVBufferRef *buf, const uint8_t *data, size_t size, int header)
#define CBS_TRACE_READ_END()
#define CBS_TRACE_WRITE_START()