84 if (cbs_type_table[i]->codec_id == codec_id) {
85 type = cbs_type_table[
i];
160 for (i = 0; i < frag->
nb_units; i++)
183 for (i = 0; i < frag->
nb_units; i++) {
203 "Decomposition unimplemented for unit %d " 204 "(type %"PRIu32
").\n", i, unit->
type);
205 }
else if (err ==
AVERROR(EAGAIN)) {
207 "Skipping decomposition of unit %d " 208 "(type %"PRIu32
").\n", i, unit->
type);
211 }
else if (err < 0) {
213 "(type %"PRIu32
").\n", i, unit->
type);
234 memcpy(frag->
data, data, size);
235 memset(frag->
data + size, 0,
314 reallocate_and_try_again:
318 "sufficiently large write buffer (last attempt " 333 goto reallocate_and_try_again;
363 for (i = 0; i < frag->
nb_units; i++) {
375 "(type %"PRIu32
").\n", i, unit->
type);
454 const char *
str,
const int *subscripts,
458 size_t name_len, bits_len;
459 int pad, subs,
i, j, k, n;
464 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
466 subs = subscripts ? subscripts[0] : 0;
468 for (i = j = 0; str[
i];) {
472 k =
snprintf(name + j,
sizeof(name) - j,
"[%d", subscripts[n]);
475 for (++i; str[
i] && str[
i] !=
']'; i++);
478 while (str[i] && str[i] !=
']')
479 name[j++] = str[i++];
484 name[j++] = str[i++];
491 name_len = strlen(name);
492 bits_len = strlen(bits);
494 if (name_len + bits_len > 60)
500 position, name, pad, bits, value);
505 const int *subscripts, uint32_t *write_to,
506 uint32_t range_min, uint32_t range_max)
515 "%s: bitstream ended.\n", name);
527 for (i = 0; i <
width; i++)
528 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
537 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
538 name, value, range_min, range_max);
548 const int *subscripts, uint32_t
value,
549 uint32_t range_min, uint32_t range_max)
555 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
556 name, value, range_min, range_max);
566 for (i = 0; i <
width; i++)
567 bits[i] = value >> (width - i - 1) & 1 ?
'1' :
'0';
571 name, subscripts, bits, value);
584 const int *subscripts,
int32_t *write_to,
594 "%s: bitstream ended.\n", name);
606 for (i = 0; i <
width; i++)
607 bits[i] = value & (1
U << (width - i - 1)) ?
'1' :
'0';
616 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
617 name, value, range_min, range_max);
634 "%"PRId32
", but must be in [%"PRId32
",%"PRId32
"].\n",
635 name, value, range_min, range_max);
645 for (i = 0; i <
width; i++)
646 bits[i] = value & (1
U << (width - i - 1)) ?
'1' :
'0';
650 name, subscripts, bits, value);
707 if (position < frag->nb_units)
708 memmove(units + position + 1, units + position,
709 (frag->
nb_units - position) *
sizeof(*units));
718 memcpy(units, frag->
units, position *
sizeof(*units));
720 if (position < frag->nb_units)
721 memcpy(units + position + 1, frag->
units + position,
722 (frag->
nb_units - position) *
sizeof(*units));
725 memset(units + position, 0,
sizeof(*units));
727 if (units != frag->
units) {
749 av_assert0(position >= 0 && position <= frag->nb_units);
765 unit = &frag->
units[position];
785 av_assert0(position >= 0 && position <= frag->nb_units);
803 unit = &frag->
units[position];
815 av_assert0(0 <= position && position < frag->nb_units
816 &&
"Unit to be deleted not in fragment.");
823 memmove(frag->
units + position,
824 frag->
units + position + 1,
834 void **ptr = (
void**)(data + desc->
ref_offsets[i]);
934 *src_ptr < (*src_buf)->data + (*src_buf)->size);
941 *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
956 for (--i; i >= 0; i--)
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
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.
static void copy(const float *p1, float *p2, const int length)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES]
ptrdiff_t const GLvoid * data
static void put_sbits(PutBitContext *pb, int n, int32_t value)
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.
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
CodedBitstreamUnitType type
Codec-specific type of this unit.
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
#define FF_ARRAY_ELEMS(a)
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.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
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)
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.
#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.
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)
GLsizei GLboolean const GLfloat * value
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t * write_buffer
Write buffer.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
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.
const CodedBitstreamUnitTypeDescriptor * unit_types
static int get_bits_count(const GetBitContext *s)
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)
#define AV_LOG_VERBOSE
Detailed information.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
static const uint8_t header[24]
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
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_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...
int(* content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit)
size_t data_size
The number of bytes in the bitstream.
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int get_bits_left(GetBitContext *gb)
AVCodecID
Identify the syntax and semantics of the bitstream.
void(* flush)(CodedBitstreamContext *ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* close)(CodedBitstreamContext *ctx)
static int put_bits_left(PutBitContext *s)
const CodedBitstreamUnitType unit_type_range_end
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 ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
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
size_t ref_offsets[CBS_MAX_REF_OFFSETS]
const CodedBitstreamType ff_cbs_type_av1
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 av_buffer_is_writable(const AVBufferRef *buf)
static const CodedBitstreamType *const cbs_type_table[]
preferred ID for MPEG-1/2 video decoding
uint8_t * data
Pointer to the bitstream form of this fragment.
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Read the extradata bitstream found in a codec context into a fragment, then split into units and deco...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
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
main external API structure.
uint8_t * data
The data buffer.
int trace_level
Log level to use for trace output.
Describe the class of an AVClass context structure.
Context structure for coded bitstream operations.
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
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.
refcounted data buffer API
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
const CodedBitstreamUnitType * decompose_unit_types
Array of unit types which should be decomposed when reading.
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...
static int cbs_clone_unit_content(AVBufferRef **clone_ref, CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
int nb_units_allocated
Number of allocated units.
void * priv_data
Internal codec-specific data.
A reference to a data buffer.
enum CBSContentType content_type
void av_opt_free(void *obj)
Free all allocated objects in obj.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
common internal and external API header
static int ref[MAX_W *MAX_W]
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
AVBufferRef * data_ref
A reference to the buffer containing data.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
const CodedBitstreamType ff_cbs_type_h265
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
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...
const CodedBitstreamUnitType unit_type_range_start
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
void(* content_free)(void *opaque, uint8_t *data)
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
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.
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
const AVClass * priv_class
int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit, size_t size)
Allocate a new internal data buffer of the given size in the unit.
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
AVBufferRef * data_ref
A reference to the buffer containing data.
const CodedBitstreamType ff_cbs_type_vp9
This structure stores compressed data.
static int cbs_read_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, AVBufferRef *buf, const uint8_t *data, size_t size, int header)
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit writable so that internal fields can be modified.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).