55#define HEADER(name) do { \
56 CBS_FUNC(trace_header)(ctx, name); \
59#define CHECK(call) do { \
65#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
68#define u(width, name, range_min, range_max) \
69 xu(width, name, current->name, range_min, range_max, 0, )
70#define us(width, name, range_min, range_max, subs, ...) \
71 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
72#define ubs(width, name, subs, ...) \
73 xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
75#define fixed(width, name, value) do { \
76 av_unused uint32_t fixed_value = value; \
77 xu(width, name, fixed_value, value, value, 0, ); \
84#define RWContext GetBitContext
85#define FUNC(name) cbs_apv_read_ ## name
87#define ub(width, name) do { \
89 CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, #name, \
91 current->name = value; \
93#define xu(width, name, var, range_min, range_max, subs, ...) do { \
95 CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
96 SUBSCRIPTS(subs, __VA_ARGS__), \
97 &value, range_min, range_max)); \
101#define infer(name, value) do { \
102 current->name = value; \
105#define byte_alignment(rw) (get_bits_count(rw) % 8)
121#define READWRITE write
122#define RWContext PutBitContext
123#define FUNC(name) cbs_apv_write_ ## name
125#define ub(width, name) do { \
126 uint32_t value = current->name; \
127 CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
130#define xu(width, name, var, range_min, range_max, subs, ...) do { \
131 uint32_t value = var; \
132 CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
133 SUBSCRIPTS(subs, __VA_ARGS__), \
134 value, range_min, range_max)); \
137#define infer(name, value) do { \
138 if (current->name != (value)) { \
139 av_log(ctx->log_ctx, AV_LOG_ERROR, \
140 "%s does not match inferred value: " \
141 "%"PRId64", but should be %"PRId64".\n", \
142 #name, (int64_t)current->name, (int64_t)(value)); \
143 return AVERROR_INVALIDDATA; \
147#define byte_alignment(rw) (put_bits_count(rw) % 8)
183 trace =
ctx->trace_enable;
184 ctx->trace_enable = 0;
189 "Invalid APV access unit: bad signature %08x.\n",
204 "fragment too short (%zu bytes).\n",
213 "pbu_size too small (%"PRIu32
" bytes).\n",
222 if (pbu_size >
size) {
224 "pbu_size too large (%"PRIu32
" bytes).\n",
249 ctx->trace_enable = trace;
271 switch (unit->
type) {
280 err = cbs_apv_read_frame(
ctx, &gbc,
frame);
288 if (!
frame->tile_data_ref)
294 err = cbs_apv_read_au_info(
ctx, &gbc, unit->
content);
301 err = cbs_apv_read_metadata(
ctx, &gbc, unit->
content);
308 err = cbs_apv_read_filler(
ctx, &gbc, unit->
content);
330 switch (unit->
type) {
339 err = cbs_apv_write_frame(
ctx, pbc,
frame);
346 err = cbs_apv_write_au_info(
ctx, pbc, unit->
content);
353 err = cbs_apv_write_metadata(
ctx, pbc, unit->
content);
360 err = cbs_apv_write_filler(
ctx, pbc, unit->
content);
415 for (
int i = 0;
i <
md->metadata_count;
i++) {
446 .offsets = { offsetof(
APVRawFrame, tile_data_ref) -
static AVFormatContext * ctx
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int FUNC pbu_header(CodedBitstreamContext *ctx, RWContext *rw, APVRawPBUHeader *current)
#define i(width, name, range_min, range_max)
#define CBS_UNIT_TYPE_POD(type_, structure)
#define CBS_UNIT_TYPE_END_OF_LIST
@ CBS_CONTENT_TYPE_INTERNAL_REFS
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const char signature[]
@ APV_PBU_NON_PRIMARY_FRAME
@ APV_PBU_ACCESS_UNIT_INFORMATION
@ APV_METADATA_USER_DEFINED
int CBS_FUNC alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
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 void cbs_apv_derive_tile_info(CodedBitstreamContext *ctx, const APVRawFrameHeader *fh)
static int cbs_apv_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static int cbs_apv_get_num_comp(const APVRawFrameHeader *fh)
static int cbs_apv_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int cbs_apv_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static CodedBitstreamUnitTypeDescriptor cbs_apv_unit_types[]
static void cbs_apv_free_metadata(AVRefStructOpaque unused, void *content)
static int cbs_apv_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Memory handling functions.
static const uint8_t header[24]
uint8_t chroma_format_idc
uint32_t tile_width_in_mbs
uint32_t tile_height_in_mbs
uint8_t * data
The data buffer.
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
size_t data_size
The number of bytes in the bitstream.
uint8_t * data
Pointer to the bitstream form of this fragment.
AVBufferRef * data_ref
A reference to the buffer containing data.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
AVBufferRef * data_ref
A reference to the buffer containing data.
RefStruct is an API for creating reference-counted objects with minimal overhead.