diff mbox series

[FFmpeg-devel,06/11] lavc/hevcdec: rename HEVCContext.ref to cur_frame

Message ID 20240531174804.17572-6-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/11] lavc/hevcdec: move handling of byte alignment at the end of slice header | expand

Checks

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

Commit Message

Anton Khirnov May 31, 2024, 5:47 p.m. UTC
Since it stores a pointer to the current frame.
---
 libavcodec/dxva2_hevc.c        | 12 +++---
 libavcodec/hevc_filter.c       | 34 ++++++++---------
 libavcodec/hevc_mvs.c          | 20 +++++-----
 libavcodec/hevc_refs.c         | 18 ++++-----
 libavcodec/hevcdec.c           | 68 +++++++++++++++++-----------------
 libavcodec/hevcdec.h           |  2 +-
 libavcodec/hevcpred_template.c |  2 +-
 libavcodec/nvdec_hevc.c        |  6 +--
 libavcodec/vaapi_hevc.c        | 18 ++++-----
 libavcodec/vdpau_hevc.c        | 10 ++---
 libavcodec/vulkan_hevc.c       |  6 +--
 11 files changed, 98 insertions(+), 98 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index b500d7917a..2d6c2f812f 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -61,7 +61,7 @@  void ff_dxva2_hevc_fill_picture_parameters(const AVCodecContext *avctx, AVDXVACo
                                     DXVA_PicParams_HEVC *pp)
 {
     const HEVCContext *h = avctx->priv_data;
-    const HEVCFrame *current_picture = h->ref;
+    const HEVCFrame *current_picture = h->cur_frame;
     const HEVCSPS *sps = h->ps.sps;
     const HEVCPPS *pps = h->ps.pps;
     int i, j;
@@ -245,7 +245,7 @@  static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
 {
     const HEVCContext *h = avctx->priv_data;
     AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
-    const HEVCFrame *current_picture = h->ref;
+    const HEVCFrame *current_picture = h->cur_frame;
     struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
     DXVA_Slice_HEVC_Short *slice = NULL;
     void     *dxva_data_ptr;
@@ -364,7 +364,7 @@  static int dxva2_hevc_start_frame(AVCodecContext *avctx,
 {
     const HEVCContext *h = avctx->priv_data;
     AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
-    struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private;
+    struct hevc_dxva2_picture_context *ctx_pic = h->cur_frame->hwaccel_picture_private;
 
     if (!DXVA_CONTEXT_VALID(avctx, ctx))
         return -1;
@@ -387,7 +387,7 @@  static int dxva2_hevc_decode_slice(AVCodecContext *avctx,
                                    uint32_t size)
 {
     const HEVCContext *h = avctx->priv_data;
-    const HEVCFrame *current_picture = h->ref;
+    const HEVCFrame *current_picture = h->cur_frame;
     struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
     unsigned position;
 
@@ -408,14 +408,14 @@  static int dxva2_hevc_decode_slice(AVCodecContext *avctx,
 static int dxva2_hevc_end_frame(AVCodecContext *avctx)
 {
     HEVCContext *h = avctx->priv_data;
-    struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private;
+    struct hevc_dxva2_picture_context *ctx_pic = h->cur_frame->hwaccel_picture_private;
     int scale = ctx_pic->pp.dwCodingParamToolFlags & 1;
     int ret;
 
     if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
         return -1;
 
-    ret = ff_dxva2_common_end_frame(avctx, h->ref->frame,
+    ret = ff_dxva2_common_end_frame(avctx, h->cur_frame->frame,
                                     &ctx_pic->pp, sizeof(ctx_pic->pp),
                                     scale ? &ctx_pic->qm : NULL, scale ? sizeof(ctx_pic->qm) : 0,
                                     commit_bitstream_and_slice_buffer);
diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c
index 6bc3019147..0ba419a7b8 100644
--- a/libavcodec/hevc_filter.c
+++ b/libavcodec/hevc_filter.c
@@ -661,8 +661,8 @@  static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv
 {
     if (curr->pred_flag == PF_BI &&  neigh->pred_flag == PF_BI) {
         // same L0 and L1
-        if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]]  &&
-            s->ref->refPicList[0].list[curr->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]] &&
+        if (s->cur_frame->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]]  &&
+            s->cur_frame->refPicList[0].list[curr->ref_idx[0]] == s->cur_frame->refPicList[1].list[curr->ref_idx[1]] &&
             neigh_refPicList[0].list[neigh->ref_idx[0]] == neigh_refPicList[1].list[neigh->ref_idx[1]]) {
             if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
                  FFABS(neigh->mv[1].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 4) &&
@@ -671,15 +671,15 @@  static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv
                 return 1;
             else
                 return 0;
-        } else if (neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
-                   neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
+        } else if (neigh_refPicList[0].list[neigh->ref_idx[0]] == s->cur_frame->refPicList[0].list[curr->ref_idx[0]] &&
+                   neigh_refPicList[1].list[neigh->ref_idx[1]] == s->cur_frame->refPicList[1].list[curr->ref_idx[1]]) {
             if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
                 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 4)
                 return 1;
             else
                 return 0;
-        } else if (neigh_refPicList[1].list[neigh->ref_idx[1]] == s->ref->refPicList[0].list[curr->ref_idx[0]] &&
-                   neigh_refPicList[0].list[neigh->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]]) {
+        } else if (neigh_refPicList[1].list[neigh->ref_idx[1]] == s->cur_frame->refPicList[0].list[curr->ref_idx[0]] &&
+                   neigh_refPicList[0].list[neigh->ref_idx[0]] == s->cur_frame->refPicList[1].list[curr->ref_idx[1]]) {
             if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 4 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 4 ||
                 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 4 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 4)
                 return 1;
@@ -694,10 +694,10 @@  static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv
 
         if (curr->pred_flag & 1) {
             A     = curr->mv[0];
-            ref_A = s->ref->refPicList[0].list[curr->ref_idx[0]];
+            ref_A = s->cur_frame->refPicList[0].list[curr->ref_idx[0]];
         } else {
             A     = curr->mv[1];
-            ref_A = s->ref->refPicList[1].list[curr->ref_idx[1]];
+            ref_A = s->cur_frame->refPicList[1].list[curr->ref_idx[1]];
         }
 
         if (neigh->pred_flag & 1) {
@@ -724,7 +724,7 @@  void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
                                            int log2_trafo_size)
 {
     const HEVCContext *s = lc->parent;
-    const MvField *tab_mvf = s->ref->tab_mvf;
+    const MvField *tab_mvf = s->cur_frame->tab_mvf;
     int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
     int log2_min_tu_size = s->ps.sps->log2_min_tb_size;
     int min_pu_width     = s->ps.sps->min_pu_width;
@@ -746,8 +746,8 @@  void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
 
     if (boundary_upper) {
         const RefPicList *rpl_top = (lc->boundary_flags & BOUNDARY_UPPER_SLICE) ?
-                                    ff_hevc_get_ref_list(s, s->ref, x0, y0 - 1) :
-                                    s->ref->refPicList;
+                                    ff_hevc_get_ref_list(s, s->cur_frame, x0, y0 - 1) :
+                                    s->cur_frame->refPicList;
         int yp_pu = (y0 - 1) >> log2_min_pu_size;
         int yq_pu =  y0      >> log2_min_pu_size;
         int yp_tu = (y0 - 1) >> log2_min_tu_size;
@@ -784,8 +784,8 @@  void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
 
     if (boundary_left) {
         const RefPicList *rpl_left = (lc->boundary_flags & BOUNDARY_LEFT_SLICE) ?
-                                     ff_hevc_get_ref_list(s, s->ref, x0 - 1, y0) :
-                                     s->ref->refPicList;
+                                     ff_hevc_get_ref_list(s, s->cur_frame, x0 - 1, y0) :
+                                     s->cur_frame->refPicList;
         int xp_pu = (x0 - 1) >> log2_min_pu_size;
         int xq_pu =  x0      >> log2_min_pu_size;
         int xp_tu = (x0 - 1) >> log2_min_tu_size;
@@ -810,7 +810,7 @@  void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
     }
 
     if (log2_trafo_size > log2_min_pu_size && !is_intra) {
-        const RefPicList *rpl = s->ref->refPicList;
+        const RefPicList *rpl = s->cur_frame->refPicList;
 
         // bs for TU internal horizontal PU boundaries
         for (j = 8; j < (1 << log2_trafo_size); j += 8) {
@@ -874,15 +874,15 @@  void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size)
         if (y && x_end) {
             sao_filter_CTB(lc, s, x, y - ctb_size);
             if (s->threads_type & FF_THREAD_FRAME )
-                ff_progress_frame_report(&s->ref->tf, y);
+                ff_progress_frame_report(&s->cur_frame->tf, y);
         }
         if (x_end && y_end) {
             sao_filter_CTB(lc, s, x , y);
             if (s->threads_type & FF_THREAD_FRAME )
-                ff_progress_frame_report(&s->ref->tf, y + ctb_size);
+                ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size);
         }
     } else if (s->threads_type & FF_THREAD_FRAME && x_end)
-        ff_progress_frame_report(&s->ref->tf, y + ctb_size - 4);
+        ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size - 4);
 }
 
 void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size)
diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c
index 5591919e2e..b56f0bece5 100644
--- a/libavcodec/hevc_mvs.c
+++ b/libavcodec/hevc_mvs.c
@@ -165,7 +165,7 @@  static int derive_temporal_colocated_mvs(const HEVCContext *s, MvField temp_col,
                                          int refIdxLx, Mv *mvLXCol, int X,
                                          int colPic, const RefPicList *refPicList_col)
 {
-    const RefPicList *refPicList = s->ref->refPicList;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
 
     if (temp_col.pred_flag == PF_INTRA)
         return 0;
@@ -291,8 +291,8 @@  static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
                                             int merge_idx,
                                             struct MvField mergecandlist[])
 {
-    const RefPicList *refPicList = s->ref->refPicList;
-    const MvField *tab_mvf       = s->ref->tab_mvf;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
+    const MvField *tab_mvf       = s->cur_frame->tab_mvf;
 
     const int min_pu_width = s->ps.sps->min_pu_width;
 
@@ -514,8 +514,8 @@  static av_always_inline void dist_scale(const HEVCContext *s, Mv *mv,
                                         int min_pu_width, int x, int y,
                                         int elist, int ref_idx_curr, int ref_idx)
 {
-    const RefPicList *refPicList = s->ref->refPicList;
-    const MvField *tab_mvf       = s->ref->tab_mvf;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
+    const MvField *tab_mvf       = s->cur_frame->tab_mvf;
     int ref_pic_elist      = refPicList[elist].list[TAB_MVF(x, y).ref_idx[elist]];
     int ref_pic_curr       = refPicList[ref_idx_curr].list[ref_idx];
 
@@ -530,10 +530,10 @@  static av_always_inline void dist_scale(const HEVCContext *s, Mv *mv,
 static int mv_mp_mode_mx(const HEVCContext *s, int x, int y, int pred_flag_index,
                          Mv *mv, int ref_idx_curr, int ref_idx)
 {
-    const MvField *tab_mvf = s->ref->tab_mvf;
+    const MvField *tab_mvf = s->cur_frame->tab_mvf;
     int min_pu_width = s->ps.sps->min_pu_width;
 
-    const RefPicList *refPicList = s->ref->refPicList;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
 
     if (((TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) &&
         refPicList[pred_flag_index].list[TAB_MVF(x, y).ref_idx[pred_flag_index]] == refPicList[ref_idx_curr].list[ref_idx]) {
@@ -546,10 +546,10 @@  static int mv_mp_mode_mx(const HEVCContext *s, int x, int y, int pred_flag_index
 static int mv_mp_mode_mx_lt(const HEVCContext *s, int x, int y, int pred_flag_index,
                             Mv *mv, int ref_idx_curr, int ref_idx)
 {
-    const MvField *tab_mvf = s->ref->tab_mvf;
+    const MvField *tab_mvf = s->cur_frame->tab_mvf;
     int min_pu_width = s->ps.sps->min_pu_width;
 
-    const RefPicList *refPicList = s->ref->refPicList;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
 
     if ((TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) {
         int currIsLongTerm     = refPicList[ref_idx_curr].isLongTerm[ref_idx];
@@ -586,7 +586,7 @@  void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
                               int mvp_lx_flag, int LX)
 {
     const HEVCContext *const s = lc->parent;
-    const MvField *const tab_mvf = s->ref->tab_mvf;
+    const MvField *const tab_mvf = s->cur_frame->tab_mvf;
     int isScaledFlag_L0 = 0;
     int availableFlagLXA0 = 1;
     int availableFlagLXB0 = 1;
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index d6dc2f9e0a..ca4b2b8bfd 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -144,7 +144,7 @@  int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
         return AVERROR(ENOMEM);
 
     *frame = ref->frame;
-    s->ref = ref;
+    s->cur_frame = ref;
     s->collocated_ref = NULL;
 
     if (s->sh.pic_output_flag)
@@ -282,7 +282,7 @@  void ff_hevc_bump_frame(HEVCContext *s)
 
 static int init_slice_rpl(HEVCContext *s)
 {
-    HEVCFrame *frame = s->ref;
+    HEVCFrame *frame = s->cur_frame;
     int ctb_count    = frame->ctb_count;
     int ctb_addr_ts  = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
     int i;
@@ -318,7 +318,7 @@  int ff_hevc_slice_rpl(HEVCContext *s)
 
     for (list_idx = 0; list_idx < nb_list; list_idx++) {
         RefPicList  rpl_tmp = { { 0 } };
-        RefPicList *rpl     = &s->ref->refPicList[list_idx];
+        RefPicList *rpl     = &s->cur_frame->refPicList[list_idx];
 
         /* The order of the elements is
          * ST_CURR_BEF - ST_CURR_AFT - LT_CURR for the L0 and
@@ -340,8 +340,8 @@  int ff_hevc_slice_rpl(HEVCContext *s)
             }
             // Construct RefPicList0, RefPicList1 (8-8, 8-10)
             if (s->ps.pps->pps_curr_pic_ref_enabled_flag && rpl_tmp.nb_refs < HEVC_MAX_REFS) {
-                rpl_tmp.list[rpl_tmp.nb_refs]           = s->ref->poc;
-                rpl_tmp.ref[rpl_tmp.nb_refs]            = s->ref;
+                rpl_tmp.list[rpl_tmp.nb_refs]           = s->cur_frame->poc;
+                rpl_tmp.ref[rpl_tmp.nb_refs]            = s->cur_frame;
                 rpl_tmp.isLongTerm[rpl_tmp.nb_refs]     = 1;
                 rpl_tmp.nb_refs++;
             }
@@ -371,8 +371,8 @@  int ff_hevc_slice_rpl(HEVCContext *s)
         if (s->ps.pps->pps_curr_pic_ref_enabled_flag &&
             !sh->rpl_modification_flag[list_idx] &&
             rpl_tmp.nb_refs > sh->nb_refs[L0]) {
-            rpl->list[sh->nb_refs[L0] - 1] = s->ref->poc;
-            rpl->ref[sh->nb_refs[L0] - 1]  = s->ref;
+            rpl->list[sh->nb_refs[L0] - 1] = s->cur_frame->poc;
+            rpl->ref[sh->nb_refs[L0] - 1]  = s->cur_frame;
         }
 
         if (sh->collocated_list == list_idx &&
@@ -448,7 +448,7 @@  static int add_candidate_ref(HEVCContext *s, RefPicList *list,
 {
     HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
 
-    if (ref == s->ref || list->nb_refs >= HEVC_MAX_REFS)
+    if (ref == s->cur_frame || list->nb_refs >= HEVC_MAX_REFS)
         return AVERROR_INVALIDDATA;
 
     if (!ref) {
@@ -483,7 +483,7 @@  int ff_hevc_frame_rps(HEVCContext *s)
     for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
         HEVCFrame *frame = &s->DPB[i];
 
-        if (frame == s->ref)
+        if (frame == s->cur_frame)
             continue;
 
         mark_ref(frame, 0);
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 75d0ed613a..39c23b532d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -600,7 +600,7 @@  static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
 
     // Coded parameters
     sh->first_slice_in_pic_flag = get_bits1(gb);
-    if (s->ref && sh->first_slice_in_pic_flag) {
+    if (s->cur_frame && sh->first_slice_in_pic_flag) {
         av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
         return 1; // This slice will be skipped later, do not corrupt state
     }
@@ -1935,8 +1935,8 @@  static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
 
     int min_pu_width = s->ps.sps->min_pu_width;
 
-    MvField *tab_mvf = s->ref->tab_mvf;
-    const RefPicList *refPicList = s->ref->refPicList;
+    MvField *tab_mvf = s->cur_frame->tab_mvf;
+    const RefPicList *refPicList = s->cur_frame->refPicList;
     const HEVCFrame *ref0 = NULL, *ref1 = NULL;
     uint8_t *dst0 = POS(0, x0, y0);
     uint8_t *dst1 = POS(1, x0, y0);
@@ -2066,7 +2066,7 @@  static int luma_intra_pred_mode(HEVCLocalContext *lc, int x0, int y0, int pu_siz
 
     int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size);
 
-    MvField *tab_mvf = s->ref->tab_mvf;
+    MvField *tab_mvf = s->cur_frame->tab_mvf;
     int intra_pred_mode;
     int candidate[3];
     int i, j;
@@ -2221,7 +2221,7 @@  static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
     int pb_size          = 1 << log2_cb_size;
     int size_in_pus      = pb_size >> s->ps.sps->log2_min_pu_size;
     int min_pu_width     = s->ps.sps->min_pu_width;
-    MvField *tab_mvf     = s->ref->tab_mvf;
+    MvField *tab_mvf     = s->cur_frame->tab_mvf;
     int x_pu             = x0 >> s->ps.sps->log2_min_pu_size;
     int y_pu             = y0 >> s->ps.sps->log2_min_pu_size;
     int j, k;
@@ -2780,7 +2780,7 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
 
 static int set_side_data(HEVCContext *s)
 {
-    AVFrame *out = s->ref->frame;
+    AVFrame *out = s->cur_frame->frame;
     int ret;
 
     // Decrement the mastering display and content light level flag when IRAP
@@ -2797,7 +2797,7 @@  static int set_side_data(HEVCContext *s)
     ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
                                 &s->ps.sps->vui.common,
                                 s->ps.sps->bit_depth, s->ps.sps->bit_depth_chroma,
-                                s->ref->poc /* no poc_offset in HEVC */);
+                                s->cur_frame->poc /* no poc_offset in HEVC */);
     if (ret < 0)
         return ret;
 
@@ -2896,12 +2896,12 @@  static int hevc_frame_start(HEVCContext *s)
     }
 
     if (IS_IRAP(s))
-        s->ref->frame->flags |= AV_FRAME_FLAG_KEY;
+        s->cur_frame->frame->flags |= AV_FRAME_FLAG_KEY;
     else
-        s->ref->frame->flags &= ~AV_FRAME_FLAG_KEY;
+        s->cur_frame->frame->flags &= ~AV_FRAME_FLAG_KEY;
 
-    s->ref->needs_fg = (s->sei.common.film_grain_characteristics.present ||
-                        s->sei.common.aom_film_grain.enable) &&
+    s->cur_frame->needs_fg = (s->sei.common.film_grain_characteristics.present ||
+                              s->sei.common.aom_film_grain.enable) &&
         !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
         !s->avctx->hwaccel;
 
@@ -2909,21 +2909,21 @@  static int hevc_frame_start(HEVCContext *s)
     if (ret < 0)
         goto fail;
 
-    if (s->ref->needs_fg &&
+    if (s->cur_frame->needs_fg &&
         (s->sei.common.film_grain_characteristics.present &&
          !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id,
-                                              s->ref->frame->format)
-         || !av_film_grain_params_select(s->ref->frame))) {
+                                              s->cur_frame->frame->format) ||
+         !av_film_grain_params_select(s->cur_frame->frame))) {
         av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
                     "Unsupported film grain parameters. Ignoring film grain.\n");
-        s->ref->needs_fg = 0;
+        s->cur_frame->needs_fg = 0;
     }
 
-    if (s->ref->needs_fg) {
-        s->ref->frame_grain->format = s->ref->frame->format;
-        s->ref->frame_grain->width = s->ref->frame->width;
-        s->ref->frame_grain->height = s->ref->frame->height;
-        if ((ret = ff_thread_get_buffer(s->avctx, s->ref->frame_grain, 0)) < 0)
+    if (s->cur_frame->needs_fg) {
+        s->cur_frame->frame_grain->format = s->cur_frame->frame->format;
+        s->cur_frame->frame_grain->width  = s->cur_frame->frame->width;
+        s->cur_frame->frame_grain->height = s->cur_frame->frame->height;
+        if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
             goto fail;
     }
 
@@ -2943,15 +2943,15 @@  static int hevc_frame_start(HEVCContext *s)
     return 0;
 
 fail:
-    if (s->ref)
-        ff_hevc_unref_frame(s->ref, ~0);
-    s->ref = s->collocated_ref = NULL;
+    if (s->cur_frame)
+        ff_hevc_unref_frame(s->cur_frame, ~0);
+    s->cur_frame = s->collocated_ref = NULL;
     return ret;
 }
 
 static int hevc_frame_end(HEVCContext *s)
 {
-    HEVCFrame *out = s->ref;
+    HEVCFrame *out = s->cur_frame;
     const AVFilmGrainParams *fgp;
     av_unused int ret;
 
@@ -3086,7 +3086,7 @@  static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
             ret = hevc_frame_start(s);
             if (ret < 0)
                 return ret;
-        } else if (!s->ref) {
+        } else if (!s->cur_frame) {
             av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
             goto fail;
         }
@@ -3169,7 +3169,7 @@  static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
     int i, ret = 0;
     int eos_at_start = 1;
 
-    s->ref = s->collocated_ref = NULL;
+    s->cur_frame = s->collocated_ref = NULL;
     s->last_eos = s->eos;
     s->eos = 0;
     s->overlap = 0;
@@ -3248,8 +3248,8 @@  static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
     }
 
 fail:
-    if (s->ref && s->threads_type == FF_THREAD_FRAME)
-        ff_progress_frame_report(&s->ref->tf, INT_MAX);
+    if (s->cur_frame && s->threads_type == FF_THREAD_FRAME)
+        ff_progress_frame_report(&s->cur_frame->tf, INT_MAX);
 
     return ret;
 }
@@ -3384,25 +3384,25 @@  static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                    old, s->dovi_ctx.cfg.dv_profile);
     }
 
-    s->ref = s->collocated_ref = NULL;
+    s->cur_frame = s->collocated_ref = NULL;
     ret    = decode_nal_units(s, avpkt->data, avpkt->size);
     if (ret < 0)
         return ret;
 
     if (avctx->hwaccel) {
-        if (s->ref && (ret = FF_HW_SIMPLE_CALL(avctx, end_frame)) < 0) {
+        if (s->cur_frame && (ret = FF_HW_SIMPLE_CALL(avctx, end_frame)) < 0) {
             av_log(avctx, AV_LOG_ERROR,
                    "hardware accelerator failed to decode picture\n");
-            ff_hevc_unref_frame(s->ref, ~0);
+            ff_hevc_unref_frame(s->cur_frame, ~0);
             return ret;
         }
     } else {
         /* verify the SEI checksum */
-        if (avctx->err_recognition & AV_EF_CRCCHECK && s->ref && s->is_decoded &&
+        if (avctx->err_recognition & AV_EF_CRCCHECK && s->cur_frame && s->is_decoded &&
             s->sei.picture_hash.is_md5) {
-            ret = verify_md5(s, s->ref->frame);
+            ret = verify_md5(s, s->cur_frame->frame);
             if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
-                ff_hevc_unref_frame(s->ref, ~0);
+                ff_hevc_unref_frame(s->cur_frame, ~0);
                 return ret;
             }
         }
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 6957cd1091..0e44a72174 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -481,7 +481,7 @@  typedef struct HEVCContext {
     DBParams *deblock;
     enum HEVCNALUnitType nal_unit_type;
     int temporal_id;  ///< temporal_id_plus1 - 1
-    HEVCFrame *ref;
+    HEVCFrame *cur_frame;
     HEVCFrame *collocated_ref;
     HEVCFrame DPB[32];
     int poc;
diff --git a/libavcodec/hevcpred_template.c b/libavcodec/hevcpred_template.c
index 9082a816e0..4e96ac3423 100644
--- a/libavcodec/hevcpred_template.c
+++ b/libavcodec/hevcpred_template.c
@@ -33,7 +33,7 @@  static av_always_inline void FUNC(intra_pred)(HEVCLocalContext *lc, int x0, int
 #define PU(x) \
     ((x) >> s->ps.sps->log2_min_pu_size)
 #define MVF(x, y) \
-    (s->ref->tab_mvf[(x) + (y) * min_pu_width])
+    (s->cur_frame->tab_mvf[(x) + (y) * min_pu_width])
 #define MVF_PU(x, y) \
     MVF(PU(x0 + ((x) * (1 << hshift))), PU(y0 + ((y) * (1 << vshift))))
 #define IS_INTRA(x, y) \
diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c
index 3d704666d0..57d5ea17b1 100644
--- a/libavcodec/nvdec_hevc.c
+++ b/libavcodec/nvdec_hevc.c
@@ -84,11 +84,11 @@  static int nvdec_hevc_start_frame(AVCodecContext *avctx,
 
     int i, j, dpb_size, ret;
 
-    ret = ff_nvdec_start_frame(avctx, s->ref->frame);
+    ret = ff_nvdec_start_frame(avctx, s->cur_frame->frame);
     if (ret < 0)
         return ret;
 
-    fdd = (FrameDecodeData*)s->ref->frame->private_ref->data;
+    fdd = (FrameDecodeData*)s->cur_frame->frame->private_ref->data;
     cf  = (NVDECFrame*)fdd->hwaccel_priv;
 
     *pp = (CUVIDPICPARAMS) {
@@ -191,7 +191,7 @@  static int nvdec_hevc_start_frame(AVCodecContext *avctx,
             .NumPocStCurrBefore                           = s->rps[ST_CURR_BEF].nb_refs,
             .NumPocStCurrAfter                            = s->rps[ST_CURR_AFT].nb_refs,
             .NumPocLtCurr                                 = s->rps[LT_CURR].nb_refs,
-            .CurrPicOrderCntVal                           = s->ref->poc,
+            .CurrPicOrderCntVal                           = s->cur_frame->poc,
         },
     };
 
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index f0a0f295d9..8ff226b980 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -71,7 +71,7 @@  static void fill_vaapi_pic(VAPictureHEVC *va_pic, const HEVCFrame *pic, int rps_
 static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
 {
     VASurfaceID pic_surf = ff_vaapi_get_surface_id(pic->frame);
-    const HEVCFrame *current_picture = h->ref;
+    const HEVCFrame *current_picture = h->cur_frame;
     int i;
 
     for (i = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) {
@@ -97,7 +97,7 @@  static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
 
 static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameterBufferHEVC *pp)
 {
-    const HEVCFrame *current_picture = h->ref;
+    const HEVCFrame *current_picture = h->cur_frame;
     int i, j, rps_type;
 
     for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); i++) {
@@ -124,7 +124,7 @@  static int vaapi_hevc_start_frame(AVCodecContext          *avctx,
                                   av_unused uint32_t       size)
 {
     const HEVCContext        *h = avctx->priv_data;
-    VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
+    VAAPIDecodePictureHEVC *pic = h->cur_frame->hwaccel_picture_private;
     const HEVCSPS          *sps = h->ps.sps;
     const HEVCPPS          *pps = h->ps.pps;
 
@@ -137,7 +137,7 @@  static int vaapi_hevc_start_frame(AVCodecContext          *avctx,
 
     VAPictureParameterBufferHEVC *pic_param = (VAPictureParameterBufferHEVC *)&pic->pic_param;
 
-    pic->pic.output_surface = ff_vaapi_get_surface_id(h->ref->frame);
+    pic->pic.output_surface = ff_vaapi_get_surface_id(h->cur_frame->frame);
 
     *pic_param = (VAPictureParameterBufferHEVC) {
         .pic_width_in_luma_samples                    = sps->width,
@@ -206,7 +206,7 @@  static int vaapi_hevc_start_frame(AVCodecContext          *avctx,
         },
     };
 
-    fill_vaapi_pic(&pic_param->CurrPic, h->ref, 0);
+    fill_vaapi_pic(&pic_param->CurrPic, h->cur_frame, 0);
     fill_vaapi_reference_frames(h, pic_param);
 
     if (pps->tiles_enabled_flag) {
@@ -343,7 +343,7 @@  fail:
 static int vaapi_hevc_end_frame(AVCodecContext *avctx)
 {
     const HEVCContext        *h = avctx->priv_data;
-    VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
+    VAAPIDecodePictureHEVC *pic = h->cur_frame->hwaccel_picture_private;
     VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC *)&pic->last_slice_param;
     int ret;
 
@@ -435,7 +435,7 @@  static void fill_pred_weight_table(AVCodecContext *avctx,
 
 static uint8_t get_ref_pic_index(const HEVCContext *h, const HEVCFrame *frame)
 {
-    VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
+    VAAPIDecodePictureHEVC *pic = h->cur_frame->hwaccel_picture_private;
     VAPictureParameterBufferHEVC *pp = (VAPictureParameterBufferHEVC *)&pic->pic_param;
     uint8_t i;
 
@@ -458,7 +458,7 @@  static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 {
     const HEVCContext        *h = avctx->priv_data;
     const SliceHeader       *sh = &h->sh;
-    VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
+    VAAPIDecodePictureHEVC *pic = h->cur_frame->hwaccel_picture_private;
     VASliceParameterBufferHEVC *last_slice_param = (VASliceParameterBufferHEVC *)&pic->last_slice_param;
 
     int slice_param_size = avctx->profile >= AV_PROFILE_HEVC_REXT ?
@@ -515,7 +515,7 @@  static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
     memset(last_slice_param->RefPicList, 0xFF, sizeof(last_slice_param->RefPicList));
 
     for (list_idx = 0; list_idx < nb_list; list_idx++) {
-        RefPicList *rpl = &h->ref->refPicList[list_idx];
+        RefPicList *rpl = &h->cur_frame->refPicList[list_idx];
 
         for (i = 0; i < rpl->nb_refs; i++)
             last_slice_param->RefPicList[list_idx][i] = get_ref_pic_index(h, rpl->ref[i]);
diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c
index b029f9c42e..acee077cfa 100644
--- a/libavcodec/vdpau_hevc.c
+++ b/libavcodec/vdpau_hevc.c
@@ -35,7 +35,7 @@  static int vdpau_hevc_start_frame(AVCodecContext *avctx,
                                   const uint8_t *buffer, uint32_t size)
 {
     HEVCContext *h = avctx->priv_data;
-    HEVCFrame *pic = h->ref;
+    HEVCFrame *pic = h->cur_frame;
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
 
     VdpPictureInfoHEVC *info = &pic_ctx->info.hevc;
@@ -238,7 +238,7 @@  static int vdpau_hevc_start_frame(AVCodecContext *avctx,
     }
     for (size_t i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
         const HEVCFrame *frame = &h->DPB[i];
-        if (frame != h->ref && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF |
+        if (frame != h->cur_frame && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF |
                                                 HEVC_FRAME_FLAG_SHORT_REF))) {
             if (j > 15) {
                 av_log(avctx, AV_LOG_WARNING,
@@ -403,7 +403,7 @@  static int vdpau_hevc_decode_slice(AVCodecContext *avctx,
                                    const uint8_t *buffer, uint32_t size)
 {
     HEVCContext *h = avctx->priv_data;
-    struct vdpau_picture_context *pic_ctx = h->ref->hwaccel_picture_private;
+    struct vdpau_picture_context *pic_ctx = h->cur_frame->hwaccel_picture_private;
     int val;
 
     val = ff_vdpau_add_buffer(pic_ctx, start_code_prefix, 3);
@@ -420,10 +420,10 @@  static int vdpau_hevc_decode_slice(AVCodecContext *avctx,
 static int vdpau_hevc_end_frame(AVCodecContext *avctx)
 {
     HEVCContext *h = avctx->priv_data;
-    struct vdpau_picture_context *pic_ctx = h->ref->hwaccel_picture_private;
+    struct vdpau_picture_context *pic_ctx = h->cur_frame->hwaccel_picture_private;
     int val;
 
-    val = ff_vdpau_common_end_frame(avctx, h->ref->frame, pic_ctx);
+    val = ff_vdpau_common_end_frame(avctx, h->cur_frame->frame, pic_ctx);
     if (val < 0)
         return val;
 
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index 5583f56285..1a12f14652 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -731,7 +731,7 @@  static int vk_hevc_start_frame(AVCodecContext          *avctx,
 {
     int err;
     HEVCContext *h = avctx->priv_data;
-    HEVCFrame *pic = h->ref;
+    HEVCFrame *pic = h->cur_frame;
     FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
     HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
     FFVulkanDecodePicture *vp = &hp->vp;
@@ -851,7 +851,7 @@  static int vk_hevc_decode_slice(AVCodecContext *avctx,
                                 uint32_t        size)
 {
     const HEVCContext *h = avctx->priv_data;
-    HEVCVulkanDecodePicture *hp = h->ref->hwaccel_picture_private;
+    HEVCVulkanDecodePicture *hp = h->cur_frame->hwaccel_picture_private;
     FFVulkanDecodePicture *vp = &hp->vp;
 
     int err = ff_vk_decode_add_slice(avctx, vp, data, size, 1,
@@ -867,7 +867,7 @@  static int vk_hevc_end_frame(AVCodecContext *avctx)
 {
     const HEVCContext *h = avctx->priv_data;
     FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
-    HEVCFrame *pic = h->ref;
+    HEVCFrame *pic = h->cur_frame;
     HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
     FFVulkanDecodePicture *vp = &hp->vp;
     FFVulkanDecodePicture *rvp[HEVC_MAX_REFS] = { 0 };