Message ID | AS8P250MB0744D4EAF95F3F984BA3E5488F2B9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM |
---|---|
State | Accepted |
Commit | 543ef831a8363712dca9c90222ecfc002b42a0c3 |
Headers | show |
Series | [FFmpeg-devel,1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
Andreas Rheinhardt: > It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS > with nb_offsets equal to zero. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > libavcodec/cbs.c | 18 ++++-------------- > libavcodec/cbs_internal.h | 21 ++++++++++++--------- > 2 files changed, 16 insertions(+), 23 deletions(-) > > 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) { \ Will apply this patchset tonight unless there are objections. - Andreas
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) { \
It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS with nb_offsets equal to zero. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/cbs.c | 18 ++++-------------- libavcodec/cbs_internal.h | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 23 deletions(-)