diff mbox series

[FFmpeg-devel,v3,7/8] lavc/hevc: Update reference list for SCC

Message ID 20201207125545.621159-8-linjie.justin.fu@gmail.com
State New
Headers show
Series HEVC native support for Screen content coding
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Linjie Fu Dec. 7, 2020, 12:55 p.m. UTC
Screen Content Coding allows non-intra slice in an IDR frame, and would
mark the current decoded picture as "used for long-term reference", no
matter TwoVersionsOfCurrDecPicFlag(8.1.3), hence some previous restricts
are not suitable any more.

Constructe RefPicListTemp and RefPicList according to 8-8/9/10.

Add a check for native decoder to quit while self-referencing is detected,
since it's not supported yet.

Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
---
 libavcodec/hevc_refs.c | 27 +++++++++++++++++++++++++--
 libavcodec/hevcdec.c   |  6 +++++-
 2 files changed, 30 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 4f6d985ae6..ba32e232bb 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -301,7 +301,7 @@  int ff_hevc_slice_rpl(HEVCContext *s)
         return ret;
 
     if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
-          s->rps[LT_CURR].nb_refs)) {
+          s->rps[LT_CURR].nb_refs) && !s->ps.pps->pps_curr_pic_ref_enabled_flag) {
         av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n");
         return AVERROR_INVALIDDATA;
     }
@@ -328,6 +328,12 @@  int ff_hevc_slice_rpl(HEVCContext *s)
                     rpl_tmp.nb_refs++;
                 }
             }
+            // Construct RefPicList0, RefPicList1 (8-8, 8-10)
+            if (s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+                rpl_tmp.ref[rpl_tmp.nb_refs]            = s->ref;
+                rpl_tmp.isLongTerm[rpl_tmp.nb_refs]     = 1;
+                rpl_tmp.nb_refs++;
+            }
         }
 
         /* reorder the references if necessary */
@@ -350,6 +356,12 @@  int ff_hevc_slice_rpl(HEVCContext *s)
             rpl->nb_refs = FFMIN(rpl->nb_refs, sh->nb_refs[list_idx]);
         }
 
+        // 8-9
+        if (s->ps.pps->pps_curr_pic_ref_enabled_flag && sh->slice_type == HEVC_SLICE_P &&
+            !sh->rpl_modification_flag[list_idx] && rpl_tmp.nb_refs > sh->nb_refs[L0]) {
+            rpl->ref[sh->nb_refs[L0]] = s->ref;
+        }
+
         if (sh->collocated_list == list_idx &&
             sh->collocated_ref_idx < rpl->nb_refs)
             s->ref->collocated_ref = rpl->ref[sh->collocated_ref_idx];
@@ -423,7 +435,8 @@  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->ref && !s->ps.pps->pps_curr_pic_ref_enabled_flag) ||
+        list->nb_refs >= HEVC_MAX_REFS)
         return AVERROR_INVALIDDATA;
 
     if (!ref) {
@@ -492,6 +505,12 @@  int ff_hevc_frame_rps(HEVCContext *s)
             goto fail;
     }
 
+    if (s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+        ret = add_candidate_ref(s, &rps[LT_FOLL], s->poc, HEVC_FRAME_FLAG_LONG_REF, 1);
+        if (ret < 0)
+            goto fail;
+    }
+
 fail:
     /* release any frames that are now unused */
     for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++)
@@ -518,5 +537,9 @@  int ff_hevc_frame_nb_refs(const HEVCContext *s)
         for (i = 0; i < long_rps->nb_refs; i++)
             ret += !!long_rps->used[i];
     }
+
+    if (s->ps.pps->pps_curr_pic_ref_enabled_flag)
+        ret++;
+
     return ret;
 }
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 6a029b270e..e1d469658c 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -637,7 +637,8 @@  static int hls_slice_header(HEVCContext *s)
                    sh->slice_type);
             return AVERROR_INVALIDDATA;
         }
-        if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I) {
+        if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
+            s->ps.sps->ptl.general_ptl.profile_idc != FF_PROFILE_HEVC_SCC) {
             av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
             return AVERROR_INVALIDDATA;
         }
@@ -752,6 +753,9 @@  static int hls_slice_header(HEVCContext *s)
             if (!nb_refs) {
                 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
                 return AVERROR_INVALIDDATA;
+            } else if (s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+                av_log(s->avctx, AV_LOG_ERROR, "Self refs for a frame is not supprted yet.\n");
+                return AVERROR_INVALIDDATA;
             }
 
             if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) {