diff mbox series

[FFmpeg-devel,v2,1/2] avcodec/hevcdec: skip generating missing refs in foll lists

Message ID 9c14fe0c-ba79-9136-227a-26bfdcdf562e@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] avcodec/hevcdec: skip generating missing refs in foll lists | 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

Xiaolei Yu April 16, 2022, 8:31 a.m. UTC
Missing refs shall be generated only when they are actually used.

Without this change a sequence of a BLA picture and an associated RASL picture
would still be decoded without complaints if the RASL picture is mislabeled
as RADL.
---
 libavcodec/hevc_refs.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fe18ca2b1d..84a21991c7 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -378,9 +378,6 @@  static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb)
         }
     }
 
-    if (s->nal_unit_type != HEVC_NAL_CRA_NUT && !IS_BLA(s))
-        av_log(s->avctx, AV_LOG_ERROR,
-               "Could not find ref with POC %d\n", poc);
     return NULL;
 }
 
@@ -426,7 +423,7 @@  static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
 
 /* add a reference with the given poc to the list and mark it as used in DPB */
 static int add_candidate_ref(HEVCContext *s, RefPicList *list,
-                             int poc, int ref_flag, uint8_t use_msb)
+                             int poc, int ref_flag, uint8_t use_msb, enum RPSType rps_type)
 {
     HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
 
@@ -434,6 +431,15 @@  static int add_candidate_ref(HEVCContext *s, RefPicList *list,
         return AVERROR_INVALIDDATA;
 
     if (!ref) {
+        int allow_missing = !(rps_type == ST_CURR_BEF || rps_type == ST_CURR_AFT ||
+                              rps_type == LT_CURR);
+
+        /* skip generating missing refs in foll lists as they are not used by current frame */
+        if (allow_missing)
+            return 0;
+
+        av_log(s->avctx, AV_LOG_ERROR, "Could not find ref with POC %d\n", poc);
+
         ref = generate_missing_ref(s, poc);
         if (!ref)
             return AVERROR(ENOMEM);
@@ -484,7 +490,7 @@  int ff_hevc_frame_rps(HEVCContext *s)
         else
             list = ST_CURR_AFT;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1);
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1, list);
         if (ret < 0)
             goto fail;
     }
@@ -494,7 +500,8 @@  int ff_hevc_frame_rps(HEVCContext *s)
         int poc  = long_rps->poc[i];
         int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]);
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i],
+                                list);
         if (ret < 0)
             goto fail;
     }