avcodec/cbs: Remove CBS_CONTENT_TYPE_POD

It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS
with nb_offsets equal to zero.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-10-19 16:35:47 +02:00
parent ff3c708686
commit 543ef831a8
2 changed files with 16 additions and 23 deletions

View File

@ -839,12 +839,10 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
static void cbs_default_free_unit_content(void *opaque, uint8_t *data) static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
{ {
const CodedBitstreamUnitTypeDescriptor *desc = opaque; const CodedBitstreamUnitTypeDescriptor *desc = opaque;
if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
int i; for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
for (i = 0; i < desc->type.ref.nb_offsets; i++) { void **ptr = (void**)(data + desc->type.ref.offsets[i]);
void **ptr = (void**)(data + desc->type.ref.offsets[i]); av_buffer_unref((AVBufferRef**)(ptr + 1));
av_buffer_unref((AVBufferRef**)(ptr + 1));
}
} }
av_free(data); av_free(data);
} }
@ -981,14 +979,6 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
switch (desc->content_type) { switch (desc->content_type) {
case CBS_CONTENT_TYPE_POD:
ref = av_buffer_alloc(desc->content_size);
if (!ref)
return AVERROR(ENOMEM);
memcpy(ref->data, unit->content, desc->content_size);
err = 0;
break;
case CBS_CONTENT_TYPE_INTERNAL_REFS: case CBS_CONTENT_TYPE_INTERNAL_REFS:
err = cbs_clone_internal_refs_unit_content(&ref, unit, desc); err = cbs_clone_internal_refs_unit_content(&ref, unit, desc);
break; break;

View File

@ -31,9 +31,7 @@
enum CBSContentType { enum CBSContentType {
// Unit content is a simple structure. // Unit content may contain some references to other structures, but all
CBS_CONTENT_TYPE_POD,
// Unit content contains some references to other structures, but all
// managed via buffer reference counting. The descriptor defines the // managed via buffer reference counting. The descriptor defines the
// structure offsets of every buffer reference. // structure offsets of every buffer reference.
CBS_CONTENT_TYPE_INTERNAL_REFS, CBS_CONTENT_TYPE_INTERNAL_REFS,
@ -78,9 +76,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
size_t content_size; size_t content_size;
union { union {
// This union's state is determined by content_type:
// ref for CBS_CONTENT_TYPE_INTERNAL_REFS,
// complex for CBS_CONTENT_TYPE_COMPLEX.
struct { struct {
// Number of entries in the ref_offsets array. Only nonzero // Number of entries in the ref_offsets array.
// if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS. // May be zero, then the structure is POD-like.
int nb_offsets; int nb_offsets;
// The structure must contain two adjacent elements: // The structure must contain two adjacent elements:
// type *field; // type *field;
@ -191,18 +192,20 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1))) #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
#define TYPE_LIST(...) { __VA_ARGS__ } #define TYPE_LIST(...) { __VA_ARGS__ }
#define CBS_UNIT_TYPE_POD(type, structure) { \ #define CBS_UNIT_TYPE_POD(type_, structure) { \
.nb_unit_types = 1, \ .nb_unit_types = 1, \
.unit_type.list = { type }, \ .unit_type.list = { type_ }, \
.content_type = CBS_CONTENT_TYPE_POD, \ .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
.content_size = sizeof(structure), \ .content_size = sizeof(structure), \
.type.ref = { .nb_offsets = 0 }, \
} }
#define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \ #define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
.nb_unit_types = CBS_UNIT_TYPE_RANGE, \ .nb_unit_types = CBS_UNIT_TYPE_RANGE, \
.unit_type.range.start = range_start, \ .unit_type.range.start = range_start, \
.unit_type.range.end = range_end, \ .unit_type.range.end = range_end, \
.content_type = CBS_CONTENT_TYPE_POD, \ .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
.content_size = sizeof(structure), \ .content_size = sizeof(structure), \
.type.ref = { .nb_offsets = 0 }, \
} }
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \ #define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \