Skip to content

Commit

Permalink
avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
Browse files Browse the repository at this point in the history
Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
jamrial committed Mar 20, 2024
1 parent edca151 commit 09f93da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions libavcodec/hevc_ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,21 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
return 0;
}

static void uninit_vps(FFRefStructOpaque opaque, void *obj)
{
HEVCVPS *vps = obj;

for (int i = 0; i < vps->vps_num_hrd_parameters; i++)
ff_refstruct_unref(&vps->hdr[i]);
}

int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
HEVCParamSets *ps)
{
int i,j;
int vps_id = 0;
ptrdiff_t nal_size;
HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);

if (!vps)
return AVERROR(ENOMEM);
Expand Down Expand Up @@ -538,12 +546,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
goto err;
}
for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
HEVCHdrParams *hdr = ff_refstruct_allocz(sizeof(*hdr));
int common_inf_present = 1;

if (!hdr)
return AVERROR(ENOMEM);

get_ue_golomb_long(gb); // hrd_layer_set_idx
if (i)
common_inf_present = get_bits1(gb);
decode_hrd(gb, common_inf_present, &vps->hdr[i],

decode_hrd(gb, common_inf_present, hdr,
vps->vps_max_sub_layers);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/hevc_ps.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ typedef struct PTL {

typedef struct HEVCVPS {
unsigned int vps_id;
HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
HEVCHdrParams *hdr[HEVC_MAX_LAYER_SETS];

uint8_t vps_temporal_id_nesting_flag;
int vps_max_layers;
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/vulkan_hevc.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static void set_vps(const HEVCVPS *vps,
HEVCHeaderVPSSet sls[])
{
for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
const HEVCHdrParams *src = &vps->hdr[i];
const HEVCHdrParams *src = vps->hdr[i];

sls_hdr[i] = (StdVideoH265HrdParameters) {
.flags = (StdVideoH265HrdFlags) {
Expand Down

0 comments on commit 09f93da

Please sign in to comment.