1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

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>
This commit is contained in:
Andreas Rheinhardt 2022-08-05 22:57:56 +02:00
parent 736b510fcc
commit fd2e65871c
3 changed files with 16 additions and 35 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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];