From 381b70e173f9d55a05ef7174f1a3709951dc3ba3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 1 Jun 2024 16:36:16 +0200 Subject: [PATCH] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs() Pass the only things required from it - slice header and PPS - explicitly. Will be useful in the following commits to avoid mofiying HEVCContext in hls_slice_header(). --- libavcodec/hevc/hevcdec.c | 2 +- libavcodec/hevc/hevcdec.h | 2 +- libavcodec/hevc/refs.c | 8 ++++---- libavcodec/nvdec_hevc.c | 2 +- libavcodec/vdpau_hevc.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index bf6e93ba1b..585a066426 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -795,7 +795,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb) sh->rpl_modification_flag[0] = 0; sh->rpl_modification_flag[1] = 0; - nb_refs = ff_hevc_frame_nb_refs(s); + nb_refs = ff_hevc_frame_nb_refs(sh, pps); if (!nb_refs) { av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); return AVERROR_INVALIDDATA; diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index 4b28494366..5eaebd3584 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -614,7 +614,7 @@ int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx); /** * Get the number of candidate references for the current frame. */ -int ff_hevc_frame_nb_refs(const HEVCContext *s); +int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps); int ff_hevc_set_new_ref(HEVCContext *s, int poc); diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index 31fcd49d69..5bd5eab9f1 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -526,12 +526,12 @@ fail: return ret; } -int ff_hevc_frame_nb_refs(const HEVCContext *s) +int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps) { int ret = 0; int i; - const ShortTermRPS *rps = s->sh.short_term_rps; - const LongTermRPS *long_rps = &s->sh.long_term_rps; + const ShortTermRPS *rps = sh->short_term_rps; + const LongTermRPS *long_rps = &sh->long_term_rps; if (rps) { for (i = 0; i < rps->num_negative_pics; i++) @@ -545,7 +545,7 @@ int ff_hevc_frame_nb_refs(const HEVCContext *s) ret += !!long_rps->used[i]; } - if (s->pps->pps_curr_pic_ref_enabled_flag) + if (pps->pps_curr_pic_ref_enabled_flag) ret++; return ret; diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c index 0bebca7568..ce66ddcfb7 100644 --- a/libavcodec/nvdec_hevc.c +++ b/libavcodec/nvdec_hevc.c @@ -187,7 +187,7 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx, .NumBitsForShortTermRPSInSlice = s->sh.short_term_rps ? s->sh.short_term_ref_pic_set_size : 0, .NumDeltaPocsOfRefRpsIdx = s->sh.short_term_rps ? s->sh.short_term_rps->rps_idx_num_delta_pocs : 0, - .NumPocTotalCurr = ff_hevc_frame_nb_refs(s), + .NumPocTotalCurr = ff_hevc_frame_nb_refs(&s->sh, pps), .NumPocStCurrBefore = s->rps[ST_CURR_BEF].nb_refs, .NumPocStCurrAfter = s->rps[ST_CURR_AFT].nb_refs, .NumPocLtCurr = s->rps[LT_CURR].nb_refs, diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c index 3db7ec156a..b9e922ecfc 100644 --- a/libavcodec/vdpau_hevc.c +++ b/libavcodec/vdpau_hevc.c @@ -205,7 +205,7 @@ static int vdpau_hevc_start_frame(AVCodecContext *avctx, } } /* See section 7.4.7.2 of the specification. */ - info->NumPocTotalCurr = ff_hevc_frame_nb_refs(h); + info->NumPocTotalCurr = ff_hevc_frame_nb_refs(&h->sh, pps); if (sh->short_term_ref_pic_set_sps_flag == 0 && sh->short_term_rps) { /* Corresponds to specification field, NumDeltaPocs[RefRpsIdx]. Only applicable when short_term_ref_pic_set_sps_flag == 0.