summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-05 22:57:56 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-11-01 20:10:20 +0100
commitfd2e65871c6fdc79cba5e3eef877a81ec83d57c6 (patch)
tree3f5b4c3213eef692e3868bf0894685c8d17eaa65 /libavcodec
parent736b510fcc386df89a403a3ed11c4d1dec599cd1 (diff)
avcodec/hevcdec: Use RefStruct-pool API instead of AVBufferPool API
It involves less allocations and therefore has the nice property that deriving a reference from a reference can't fail, simplifying hevc_ref_frame(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/hevc_refs.c16
-rw-r--r--libavcodec/hevcdec.c25
-rw-r--r--libavcodec/hevcdec.h10
3 files changed, 16 insertions, 35 deletions
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 10fdeaf7ff..54e3d40e1c 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -42,13 +42,11 @@ void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
av_frame_unref(frame->frame_grain);
frame->needs_fg = 0;
- av_buffer_unref(&frame->tab_mvf_buf);
- frame->tab_mvf = NULL;
+ ff_refstruct_unref(&frame->tab_mvf);
ff_refstruct_unref(&frame->rpl);
frame->nb_rpl_elems = 0;
- av_buffer_unref(&frame->rpl_tab_buf);
- frame->rpl_tab = NULL;
+ ff_refstruct_unref(&frame->rpl_tab);
frame->refPicList = NULL;
ff_refstruct_unref(&frame->hwaccel_picture_private);
@@ -99,15 +97,13 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
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)
+ frame->tab_mvf = ff_refstruct_pool_get(s->tab_mvf_pool);
+ if (!frame->tab_mvf)
goto fail;
- frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data;
- frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool);
- if (!frame->rpl_tab_buf)
+ frame->rpl_tab = ff_refstruct_pool_get(s->rpl_tab_pool);
+ if (!frame->rpl_tab)
goto fail;
- 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] = frame->rpl;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index b267f6ebcf..3ce845dddb 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -86,8 +86,8 @@ static void pic_arrays_free(HEVCContext *s)
av_freep(&s->sh.size);
av_freep(&s->sh.offset);
- av_buffer_pool_uninit(&s->tab_mvf_pool);
- av_buffer_pool_uninit(&s->rpl_tab_pool);
+ ff_refstruct_pool_uninit(&s->tab_mvf_pool);
+ ff_refstruct_pool_uninit(&s->rpl_tab_pool);
}
/* allocate arrays that depend on frame dimensions */
@@ -133,10 +133,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
if (!s->horizontal_bs || !s->vertical_bs)
goto fail;
- s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField),
- av_buffer_allocz);
- s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),
- av_buffer_allocz);
+ s->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
+ s->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
if (!s->tab_mvf_pool || !s->rpl_tab_pool)
goto fail;
@@ -3404,16 +3402,8 @@ static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src)
dst->needs_fg = 1;
}
- dst->tab_mvf_buf = av_buffer_ref(src->tab_mvf_buf);
- if (!dst->tab_mvf_buf)
- goto fail;
- dst->tab_mvf = src->tab_mvf;
-
- dst->rpl_tab_buf = av_buffer_ref(src->rpl_tab_buf);
- if (!dst->rpl_tab_buf)
- goto fail;
- dst->rpl_tab = src->rpl_tab;
-
+ dst->tab_mvf = ff_refstruct_ref(src->tab_mvf);
+ dst->rpl_tab = ff_refstruct_ref(src->rpl_tab);
dst->rpl = ff_refstruct_ref(src->rpl);
dst->nb_rpl_elems = src->nb_rpl_elems;
@@ -3426,9 +3416,6 @@ static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src)
src->hwaccel_picture_private);
return 0;
-fail:
- ff_hevc_unref_frame(dst, ~0);
- return AVERROR(ENOMEM);
}
static av_cold int hevc_decode_free(AVCodecContext *avctx)
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 6ef7d4f60f..c697119891 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -408,14 +408,12 @@ typedef struct HEVCFrame {
AVFrame *frame_grain;
ThreadFrame tf;
int needs_fg; /* 1 if grain needs to be applied by the decoder */
- MvField *tab_mvf;
+ MvField *tab_mvf; ///< RefStruct reference
RefPicList *refPicList;
- RefPicListTab **rpl_tab;
+ RefPicListTab **rpl_tab; ///< RefStruct reference
int ctb_count;
int poc;
- AVBufferRef *tab_mvf_buf;
- AVBufferRef *rpl_tab_buf;
RefPicListTab *rpl; ///< RefStruct reference
int nb_rpl_elems;
@@ -516,8 +514,8 @@ typedef struct HEVCContext {
HEVCSEI sei;
struct AVMD5 *md5_ctx;
- AVBufferPool *tab_mvf_pool;
- AVBufferPool *rpl_tab_pool;
+ struct FFRefStructPool *tab_mvf_pool;
+ struct FFRefStructPool *rpl_tab_pool;
///< candidate references for the current frame
RefPicList rps[5];