19#ifndef AVCODEC_CBS_INTERNAL_H
20#define AVCODEC_CBS_INTERNAL_H
46#define CBS_APV CONFIG_CBS_APV
49#define CBS_AV1 CONFIG_CBS_AV1
52#define CBS_H264 CONFIG_CBS_H264
55#define CBS_H265 CONFIG_CBS_H265
58#define CBS_H266 CONFIG_CBS_H266
61#define CBS_LCEVC CONFIG_CBS_LCEVC
64#define CBS_JPEG CONFIG_CBS_JPEG
67#define CBS_MPEG2 CONFIG_CBS_MPEG2
70#define CBS_VP8 CONFIG_CBS_VP8
73#define CBS_VP9 CONFIG_CBS_VP9
212 const int *subscripts, uint32_t *write_to,
213 uint32_t range_min, uint32_t range_max);
216 int width,
const char *
name, uint32_t *write_to);
220 const int *subscripts, uint32_t
value,
221 uint32_t range_min, uint32_t range_max);
228 const int *subscripts,
int32_t *write_to,
238#define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
242#define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
246#define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
251#define CBS_TRACE_READ_START() \
252 GetBitContext trace_start; \
254 if (ctx->trace_enable) \
255 trace_start = *gbc; \
259#define CBS_TRACE_READ_END() \
261 if (ctx->trace_enable) { \
262 int start_position = get_bits_count(&trace_start); \
263 int end_position = get_bits_count(gbc); \
264 av_assert0(start_position <= end_position); \
265 ctx->trace_read_callback(ctx->trace_context, &trace_start, \
266 end_position - start_position, \
267 name, subscripts, value); \
272#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() \
274 const int *subscripts = NULL; \
275 CBS_TRACE_READ_END(); \
280#define CBS_TRACE_READ_END_VALUE_ONLY() \
282 if (ctx->trace_enable) { \
283 ctx->trace_read_callback(ctx->trace_context, &trace_start, 0, \
284 name, subscripts, value); \
289#define CBS_TRACE_WRITE_START() \
290 int start_position; \
292 if (ctx->trace_enable) \
293 start_position = put_bits_count(pbc);; \
297#define CBS_TRACE_WRITE_END() \
299 if (ctx->trace_enable) { \
300 int end_position = put_bits_count(pbc); \
301 av_assert0(start_position <= end_position); \
302 ctx->trace_write_callback(ctx->trace_context, pbc, \
303 end_position - start_position, \
304 name, subscripts, value); \
309#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() \
311 const int *subscripts = NULL; \
312 CBS_TRACE_WRITE_END(); \
319#define CBS_TRACE_WRITE_END_VALUE_ONLY() \
321 if (ctx->trace_enable) { \
323 init_put_bits(&tmp, pbc->buf, start_position); \
324 skip_put_bits(&tmp, start_position); \
325 ctx->trace_write_callback(ctx->trace_context, &tmp, 0, \
326 name, subscripts, value); \
331#define CBS_TRACE_READ_START() do { } while (0)
332#define CBS_TRACE_READ_END() do { } while (0)
333#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() do { } while (0)
334#define CBS_TRACE_READ_END_VALUE_ONLY() do { } while (0)
335#define CBS_TRACE_WRITE_START() do { } while (0)
336#define CBS_TRACE_WRITE_END() do { } while (0)
337#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() do { } while (0)
338#define CBS_TRACE_WRITE_END_VALUE_ONLY() do { } while (0)
341#define TYPE_LIST(...) { __VA_ARGS__ }
342#define CBS_UNIT_TYPE_POD(type_, structure) { \
343 .nb_unit_types = 1, \
344 .unit_type.list = { type_ }, \
345 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
346 .content_size = sizeof(structure), \
347 .type.ref = { .nb_offsets = 0 }, \
349#define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
350 .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
351 .unit_type.range.start = range_start, \
352 .unit_type.range.end = range_end, \
353 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
354 .content_size = sizeof(structure), \
355 .type.ref = { .nb_offsets = 0 }, \
358#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
359 .nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
360 .unit_type.list = TYPE_LIST types, \
361 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
362 .content_size = sizeof(structure), \
363 .type.ref = { .nb_offsets = 1, \
364 .offsets = { offsetof(structure, ref_field) } }, \
366#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) \
367 CBS_UNIT_TYPES_INTERNAL_REF((type), structure, ref_field)
369#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field) { \
370 .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
371 .unit_type.range.start = range_start, \
372 .unit_type.range.end = range_end, \
373 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
374 .content_size = sizeof(structure), \
375 .type.ref = { .nb_offsets = 1, \
376 .offsets = { offsetof(structure, ref_field) } }, \
379#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func) { \
380 .nb_unit_types = FF_ARRAY_ELEMS((CodedBitstreamUnitType[])TYPE_LIST types), \
381 .unit_type.list = TYPE_LIST types, \
382 .content_type = CBS_CONTENT_TYPE_COMPLEX, \
383 .content_size = sizeof(structure), \
384 .type.complex = { .content_free = free_func }, \
386#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) \
387 CBS_UNIT_TYPES_COMPLEX((type), structure, free_func)
389#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
static AVFormatContext * ctx
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static int32_t BS_FUNC read_signed(BSCTX *bc, unsigned int n)
Return n bits from the buffer as a signed integer.
int CBS_FUNC read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
@ CBS_MAX_LIST_UNIT_TYPES
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)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_COMPLEX
int CBS_FUNC write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
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)
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)
bitstream reader API header.
AVCodecID
Identify the syntax and semantics of the bitstream.
void CBS_FUNC trace_header(CodedBitstreamContext *ctx, const char *name)
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
static const uint8_t header[24]
Describe the class of an AVClass context structure.
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
void(* flush)(CodedBitstreamContext *ctx)
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
void(* close)(CodedBitstreamContext *ctx)
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
CodedBitstreamUnitTypeDescriptor * unit_types
const AVClass * priv_class
int(* discarded_unit)(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
CodedBitstreamUnitType end
struct CodedBitstreamUnitTypeDescriptor::@336047356232222135040315337172251220176367310114::@154103274000131154014101000301131241246261022267 complex
size_t offsets[CBS_MAX_REF_OFFSETS]
CodedBitstreamUnitType start
int(* content_clone)(void **new_content, CodedBitstreamUnit *unit)
enum CBSContentType content_type
CodedBitstreamUnitType list[CBS_MAX_LIST_UNIT_TYPES]
union CodedBitstreamUnitTypeDescriptor::@025053026063241163272070015000137137020146347373 unit_type
void(* content_free)(AVRefStructOpaque opaque, void *content)
Coded bitstream unit structure.
static int ref[MAX_W *MAX_W]
RefStruct is an API for creating reference-counted objects with minimal overhead.