avcodec/cbs: Use RefStruct-API for unit content

This avoids allocations and error checks etc. as well
as duplicate pointer lists in the CodedBitstreamFooContexts.
It also avoids casting const away for use as opaque,
as the RefStruct API supports const opaques.

The fact that some of the units are not refcounted
(i.e. they are sometimes part of an encoding context
like VAAPIEncodeH264Context) meant that CodedBitstreamUnit
still contains two pointers, one to the content
and another ownership pointer, replacing the AVBufferRef* pointer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2022-08-04 11:59:16 +02:00
parent 56dd585146
commit 3e9b8d14e5
12 changed files with 129 additions and 215 deletions
+3 -7
View File
@@ -1074,17 +1074,13 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
ub(4, sps_seq_parameter_set_id);
ub(4, sps_video_parameter_set_id);
if (current->sps_video_parameter_set_id == 0 && !h266->vps_ref[0]) {
H266RawVPS *vps;
AVBufferRef *ref = av_buffer_allocz(sizeof(H266RawVPS));
if (!ref) {
if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
H266RawVPS *vps = ff_refstruct_allocz(sizeof(*vps));
if (!vps)
return AVERROR(ENOMEM);
}
vps = (H266RawVPS *) ref->data;
vps->vps_max_layers_minus1 = 0;
vps->vps_independent_layer_flag[0] = 1;
vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
h266->vps_ref[0] = ref;
h266->vps[0] = vps;
}