[FFmpeg-devel] [PATCH 21/42] lavc/hevcdec: move HEVCContext.{tab_mvf, rpl_tab}_pool to HEVCLayerContext

Anton Khirnov anton at khirnov.net
Tue Aug 27 18:05:01 EEST 2024


pic_arrays_{init,free}() no longer access HEVCContext
---
 libavcodec/hevc/hevcdec.c | 24 ++++++++++++------------
 libavcodec/hevc/hevcdec.h |  6 +++---
 libavcodec/hevc/refs.c    |  4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2e31928e99..c4e3debae1 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -66,7 +66,7 @@ static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3,
  */
 
 /* free everything allocated  by pic_arrays_init() */
-static void pic_arrays_free(HEVCContext *s, HEVCLayerContext *l)
+static void pic_arrays_free(HEVCLayerContext *l)
 {
     av_freep(&l->sao);
     av_freep(&l->deblock);
@@ -85,12 +85,12 @@ static void pic_arrays_free(HEVCContext *s, HEVCLayerContext *l)
     av_freep(&l->horizontal_bs);
     av_freep(&l->vertical_bs);
 
-    ff_refstruct_pool_uninit(&s->tab_mvf_pool);
-    ff_refstruct_pool_uninit(&s->rpl_tab_pool);
+    ff_refstruct_pool_uninit(&l->tab_mvf_pool);
+    ff_refstruct_pool_uninit(&l->rpl_tab_pool);
 }
 
 /* allocate arrays that depend on frame dimensions */
-static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
+static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
 {
     int log2_min_cb_size = sps->log2_min_cb_size;
     int width            = sps->width;
@@ -132,15 +132,15 @@ static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *s
     if (!l->horizontal_bs || !l->vertical_bs)
         goto fail;
 
-    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)
+    l->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
+    l->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count   * sizeof(RefPicListTab), 0);
+    if (!l->tab_mvf_pool || !l->rpl_tab_pool)
         goto fail;
 
     return 0;
 
 fail:
-    pic_arrays_free(s, l);
+    pic_arrays_free(l);
     return AVERROR(ENOMEM);
 }
 
@@ -531,14 +531,14 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
 {
     int ret, i;
 
-    pic_arrays_free(s, l);
+    pic_arrays_free(l);
     s->ps.sps = NULL;
     ff_refstruct_unref(&s->vps);
 
     if (!sps)
         return 0;
 
-    ret = pic_arrays_init(s, l, sps);
+    ret = pic_arrays_init(l, sps);
     if (ret < 0)
         goto fail;
 
@@ -576,7 +576,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
     return 0;
 
 fail:
-    pic_arrays_free(s, l);
+    pic_arrays_free(l);
     for (i = 0; i < 3; i++) {
         av_freep(&s->sao_pixel_buffer_h[i]);
         av_freep(&s->sao_pixel_buffer_v[i]);
@@ -3529,7 +3529,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
     int i;
 
     for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++)
-        pic_arrays_free(s, &s->layers[i]);
+        pic_arrays_free(&s->layers[i]);
 
     ff_refstruct_unref(&s->vps);
     ff_refstruct_unref(&s->pps);
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 426b7968b0..1a43c3662c 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -465,6 +465,9 @@ typedef struct HEVCLayerContext {
 
     uint8_t                *horizontal_bs;
     uint8_t                *vertical_bs;
+
+    struct FFRefStructPool *tab_mvf_pool;
+    struct FFRefStructPool *rpl_tab_pool;
 } HEVCLayerContext;
 
 typedef struct HEVCContext {
@@ -489,9 +492,6 @@ typedef struct HEVCContext {
     HEVCSEI sei;
     struct AVMD5 *md5_ctx;
 
-    struct FFRefStructPool *tab_mvf_pool;
-    struct FFRefStructPool *rpl_tab_pool;
-
     ///< candidate references for the current frame
     RefPicList rps[5];
 
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 4d123d6d8d..7b8dff4f55 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -95,11 +95,11 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
             goto fail;
         frame->nb_rpl_elems = s->pkt.nb_nals;
 
-        frame->tab_mvf = ff_refstruct_pool_get(s->tab_mvf_pool);
+        frame->tab_mvf = ff_refstruct_pool_get(l->tab_mvf_pool);
         if (!frame->tab_mvf)
             goto fail;
 
-        frame->rpl_tab = ff_refstruct_pool_get(s->rpl_tab_pool);
+        frame->rpl_tab = ff_refstruct_pool_get(l->rpl_tab_pool);
         if (!frame->rpl_tab)
             goto fail;
         frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
-- 
2.43.0



More information about the ffmpeg-devel mailing list