Message ID | 20240321122922.7643-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | 456c8ebe7c7dcd766d36cd0296815d89fd1166b5 |
Headers | show |
Series | [FFmpeg-devel] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS | 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 |
James Almer: > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavcodec/hevc_ps.c | 14 +++++++++++++- > libavcodec/hevc_ps.h | 2 +- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c > index fb997066d9..d29cf9f372 100644 > --- a/libavcodec/hevc_ps.c > +++ b/libavcodec/hevc_ps.c > @@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present, > return 0; > } > > +static void uninit_vps(FFRefStructOpaque opaque, void *obj) > +{ > + HEVCVPS *vps = obj; > + > + av_freep(&vps->hdr); > +} > + > 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); > @@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, > "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters); > goto err; > } > + > + vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); > + if (!vps->hdr) > + goto err; > + > for (i = 0; i < vps->vps_num_hrd_parameters; i++) { > int common_inf_present = 1; > > diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h > index 786c896709..87cea479e9 100644 > --- a/libavcodec/hevc_ps.h > +++ b/libavcodec/hevc_ps.h > @@ -152,7 +152,7 @@ typedef struct PTL { > > typedef struct HEVCVPS { > unsigned int vps_id; > - HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS]; > + HEVCHdrParams *hdr; > > uint8_t vps_temporal_id_nesting_flag; > int vps_max_layers; That's what I had in mind. - Andreas
Hi James, >From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of James >Almer >Sent: Thursday, March 21, 2024 8:29 PM >To: ffmpeg-devel@ffmpeg.org >Subject: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required >HEVCHdrParams within a VPS > >Signed-off-by: James Almer <jamrial@gmail.com> >--- > libavcodec/hevc_ps.c | 14 +++++++++++++- > libavcodec/hevc_ps.h | 2 +- > 2 files changed, 14 insertions(+), 2 deletions(-) > >diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c >index fb997066d9..d29cf9f372 100644 >--- a/libavcodec/hevc_ps.c >+++ b/libavcodec/hevc_ps.c >@@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int >common_inf_present, > return 0; > } > >+static void uninit_vps(FFRefStructOpaque opaque, void *obj) >+{ >+ HEVCVPS *vps = obj; >+ >+ av_freep(&vps->hdr); >+} >+ > 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); >@@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, >AVCodecContext *avctx, > "vps_num_hrd_parameters %d is invalid\n", vps- >>vps_num_hrd_parameters); > goto err; > } >+ >+ vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); >+ if (!vps->hdr) >+ goto err; >+ It looks like this will cause the following !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps)) becomes 0 and furtherly remove_vps is called. Is that expected? Thanks, Tong > for (i = 0; i < vps->vps_num_hrd_parameters; i++) { > int common_inf_present = 1; > >diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h >index 786c896709..87cea479e9 100644 >--- a/libavcodec/hevc_ps.h >+++ b/libavcodec/hevc_ps.h >@@ -152,7 +152,7 @@ typedef struct PTL { > > typedef struct HEVCVPS { > unsigned int vps_id; >- HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS]; >+ HEVCHdrParams *hdr; > > uint8_t vps_temporal_id_nesting_flag; > int vps_max_layers; >-- >2.44.0 > >_______________________________________________ >ffmpeg-devel mailing list >ffmpeg-devel@ffmpeg.org >https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > >To unsubscribe, visit link above, or email >ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index fb997066d9..d29cf9f372 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present, return 0; } +static void uninit_vps(FFRefStructOpaque opaque, void *obj) +{ + HEVCVPS *vps = obj; + + av_freep(&vps->hdr); +} + 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); @@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters); goto err; } + + vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); + if (!vps->hdr) + goto err; + for (i = 0; i < vps->vps_num_hrd_parameters; i++) { int common_inf_present = 1; diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index 786c896709..87cea479e9 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -152,7 +152,7 @@ typedef struct PTL { typedef struct HEVCVPS { unsigned int vps_id; - HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS]; + HEVCHdrParams *hdr; uint8_t vps_temporal_id_nesting_flag; int vps_max_layers;
Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/hevc_ps.c | 14 +++++++++++++- libavcodec/hevc_ps.h | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-)