diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 8d6e3c3442..504197e06d 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -839,12 +839,10 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, static void cbs_default_free_unit_content(void *opaque, uint8_t *data) { const CodedBitstreamUnitTypeDescriptor *desc = opaque; - if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) { - int i; - for (i = 0; i < desc->type.ref.nb_offsets; i++) { - void **ptr = (void**)(data + desc->type.ref.offsets[i]); - av_buffer_unref((AVBufferRef**)(ptr + 1)); - } + + for (int i = 0; i < desc->type.ref.nb_offsets; i++) { + void **ptr = (void**)(data + desc->type.ref.offsets[i]); + av_buffer_unref((AVBufferRef**)(ptr + 1)); } av_free(data); } @@ -981,14 +979,6 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx, return AVERROR(ENOSYS); 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: err = cbs_clone_internal_refs_unit_content(&ref, unit, desc); break; diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 5ccba3c901..045df91744 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -31,9 +31,7 @@ enum CBSContentType { - // Unit content is a simple structure. - CBS_CONTENT_TYPE_POD, - // Unit content contains some references to other structures, but all + // Unit content may contain some references to other structures, but all // managed via buffer reference counting. The descriptor defines the // structure offsets of every buffer reference. CBS_CONTENT_TYPE_INTERNAL_REFS, @@ -78,9 +76,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor { size_t content_size; union { + // This union's state is determined by content_type: + // ref for CBS_CONTENT_TYPE_INTERNAL_REFS, + // complex for CBS_CONTENT_TYPE_COMPLEX. struct { - // Number of entries in the ref_offsets array. Only nonzero - // if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS. + // Number of entries in the ref_offsets array. + // May be zero, then the structure is POD-like. int nb_offsets; // The structure must contain two adjacent elements: // 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 TYPE_LIST(...) { __VA_ARGS__ } -#define CBS_UNIT_TYPE_POD(type, structure) { \ +#define CBS_UNIT_TYPE_POD(type_, structure) { \ .nb_unit_types = 1, \ - .unit_type.list = { type }, \ - .content_type = CBS_CONTENT_TYPE_POD, \ + .unit_type.list = { type_ }, \ + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \ .content_size = sizeof(structure), \ + .type.ref = { .nb_offsets = 0 }, \ } #define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \ .nb_unit_types = CBS_UNIT_TYPE_RANGE, \ .unit_type.range.start = range_start, \ .unit_type.range.end = range_end, \ - .content_type = CBS_CONTENT_TYPE_POD, \ + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \ .content_size = sizeof(structure), \ + .type.ref = { .nb_offsets = 0 }, \ } #define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \