[FFmpeg-devel] [PATCH 39/42] avcodec/hevcdec: Move collocated_ref to HEVCContext
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Tue Sep 19 22:57:31 EEST 2023
Only the collocated_ref of the current frame (i.e. HEVCContext.ref)
is ever used*, so move it to HEVCContext directly after ref.
*: This goes so far that collocated_ref was not even synced across
threads in case of frame-threading.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavcodec/hevc_mvs.c | 2 +-
libavcodec/hevc_refs.c | 5 ++---
libavcodec/hevcdec.c | 6 +++---
libavcodec/hevcdec.h | 2 +-
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c
index c231797a57..0a8cc2c43d 100644
--- a/libavcodec/hevc_mvs.c
+++ b/libavcodec/hevc_mvs.c
@@ -227,7 +227,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
int availableFlagLXCol = 0;
int colPic;
- const HEVCFrame *ref = s->ref->collocated_ref;
+ const HEVCFrame *ref = s->collocated_ref;
if (!ref) {
memset(mvLXCol, 0, sizeof(*mvLXCol));
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fa53b273c7..9cdc4233df 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -49,8 +49,6 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags)
ff_refstruct_unref(&frame->rpl_tab);
frame->refPicList = NULL;
- frame->collocated_ref = NULL;
-
ff_refstruct_unref(&frame->hwaccel_picture_private);
}
}
@@ -152,6 +150,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
*frame = ref->frame;
s->ref = ref;
+ s->collocated_ref = NULL;
if (s->sh.pic_output_flag)
ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF;
@@ -383,7 +382,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
if (sh->collocated_list == list_idx &&
sh->collocated_ref_idx < rpl->nb_refs)
- s->ref->collocated_ref = rpl->ref[sh->collocated_ref_idx];
+ s->collocated_ref = rpl->ref[sh->collocated_ref_idx];
}
return 0;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index c8067a736e..a476a7c7ce 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2910,7 +2910,7 @@ static int hevc_frame_start(HEVCContext *s)
fail:
if (s->ref)
ff_hevc_unref_frame(s, s->ref, ~0);
- s->ref = NULL;
+ s->ref = s->collocated_ref = NULL;
return ret;
}
@@ -3131,7 +3131,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 = NULL;
+ s->ref = s->collocated_ref = NULL;
s->last_eos = s->eos;
s->eos = 0;
s->overlap = 0;
@@ -3339,7 +3339,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
if (sd && sd_size > 0)
ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd);
- s->ref = NULL;
+ s->ref = s->collocated_ref = NULL;
ret = decode_nal_units(s, avpkt->data, avpkt->size);
if (ret < 0)
return ret;
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index edf2f188cf..bed8716f99 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -413,7 +413,6 @@ typedef struct HEVCFrame {
RefPicListTab **rpl_tab; ///< RefStruct reference
int ctb_count;
int poc;
- struct HEVCFrame *collocated_ref;
RefPicListTab *rpl; ///< RefStruct reference
int nb_rpl_elems;
@@ -527,6 +526,7 @@ typedef struct HEVCContext {
enum HEVCNALUnitType nal_unit_type;
int temporal_id; ///< temporal_id_plus1 - 1
HEVCFrame *ref;
+ HEVCFrame *collocated_ref;
HEVCFrame DPB[32];
int poc;
int pocTid0;
--
2.34.1
More information about the ffmpeg-devel
mailing list