summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-04 17:33:29 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-07 22:35:56 +0200
commit452089ee23312ceab28baf9f83fb7dff472e7d82 (patch)
treeaf8ca737a93d89a68138d1392e518dc435c74435 /libavcodec
parent6695c0af0e5431e50c5059ad01862e399af6607d (diff)
avcodec/hevcdec: Use RefStruct API for RefPicListTab buffer
Given that the RefStruct API relies on the user to know the size of the objects and does not provide a way to get it, we need to store the number of elements allocated ourselves; but this is actually better than deriving it from the size in bytes. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/hevc_refs.c14
-rw-r--r--libavcodec/hevcdec.c5
-rw-r--r--libavcodec/hevcdec.h3
3 files changed, 12 insertions, 10 deletions
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 8f49704b54..ae464e8e6d 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -45,7 +45,8 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags)
av_buffer_unref(&frame->tab_mvf_buf);
frame->tab_mvf = NULL;
- av_buffer_unref(&frame->rpl_buf);
+ ff_refstruct_unref(&frame->rpl);
+ frame->nb_rpl_elems = 0;
av_buffer_unref(&frame->rpl_tab_buf);
frame->rpl_tab = NULL;
frame->refPicList = NULL;
@@ -95,9 +96,10 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
if (ret < 0)
return NULL;
- frame->rpl_buf = av_buffer_allocz(s->pkt.nb_nals * sizeof(RefPicListTab));
- if (!frame->rpl_buf)
+ frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
+ if (!frame->rpl)
goto fail;
+ frame->nb_rpl_elems = s->pkt.nb_nals;
frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool);
if (!frame->tab_mvf_buf)
@@ -110,7 +112,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data;
frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
for (j = 0; j < frame->ctb_count; j++)
- frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data;
+ frame->rpl_tab[j] = frame->rpl;
if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
@@ -295,11 +297,11 @@ static int init_slice_rpl(HEVCContext *s)
int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
int i;
- if (s->slice_idx >= frame->rpl_buf->size / sizeof(RefPicListTab))
+ if (s->slice_idx >= frame->nb_rpl_elems)
return AVERROR_INVALIDDATA;
for (i = ctb_addr_ts; i < ctb_count; i++)
- frame->rpl_tab[i] = (RefPicListTab *)frame->rpl_buf->data + s->slice_idx;
+ frame->rpl_tab[i] = frame->rpl + s->slice_idx;
frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index bd3463963b..55a958b41d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3414,9 +3414,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src)
goto fail;
dst->rpl_tab = src->rpl_tab;
- dst->rpl_buf = av_buffer_ref(src->rpl_buf);
- if (!dst->rpl_buf)
- goto fail;
+ dst->rpl = ff_refstruct_ref(src->rpl);
+ dst->nb_rpl_elems = src->nb_rpl_elems;
dst->poc = src->poc;
dst->ctb_count = src->ctb_count;
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 187515eba4..3ee8bd4334 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -417,7 +417,8 @@ typedef struct HEVCFrame {
AVBufferRef *tab_mvf_buf;
AVBufferRef *rpl_tab_buf;
- AVBufferRef *rpl_buf;
+ RefPicListTab *rpl; ///< RefStruct reference
+ int nb_rpl_elems;
void *hwaccel_picture_private; ///< RefStruct reference