From 96fa65f69e14bb5e679f7e13782276202420aaf1 Mon Sep 17 00:00:00 2001
From: eeehey <yonghe@qti.qualcomm.com>
Date: Wed, 6 May 2020 20:47:16 -0700
Subject: [PATCH] JVET-R0267 RPL constraint for IDR picture

---
 source/Lib/CommonLib/Slice.cpp | 11 ++++++++---
 source/Lib/CommonLib/TypeDef.h |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp
index 3c0e837e7..102964eaf 100644
--- a/source/Lib/CommonLib/Slice.cpp
+++ b/source/Lib/CommonLib/Slice.cpp
@@ -663,11 +663,16 @@ void Slice::checkRPL(const ReferencePictureList* pRPL0, const ReferencePictureLi
     }
     refPicDecodingOrderNumber = pcRefPic->getDecodingOrderNumber();
 
-    // Checking this: "When the current picture is a CRA picture, there shall be no entry in RefPicList[0] or RefPicList[1]
-    // that precedes, in output order or decoding order, any preceding IRAP picture in decoding order (when present)"
+    // Checking this: "When the current picture follows an IRAP picture having the same value of nuh_layer_id in both decoding order 
+    // and output order, there shall be no picture referred to by an active entry in RefPicList[ 0 ] or RefPicList[ 1 ] that 
+    // precedes that IRAP picture in output order or decoding order."
+#if JVET_R0267_IDR_RPL
+    if (m_eNalUnitType == NAL_UNIT_CODED_SLICE_CRA || m_eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP )
+#else
     if (m_eNalUnitType == NAL_UNIT_CODED_SLICE_CRA)
+#endif
     {
-      CHECK(refPicPOC < irapPOC || refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "CRA picture detected that violate the rule that no entry in RefPicList[] shall precede, in output order or decoding order, any preceding IRAP picture in decoding order (when present).");
+      CHECK(refPicPOC < irapPOC || refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "IRAP picture detected that violate the rule that no entry in RefPicList[] shall precede, in output order or decoding order, any preceding IRAP picture in decoding order (when present).");
     }
 
     // Checking this: "When the current picture is a trailing picture that follows in both decoding orderand output order one
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index b03001080..94af9968d 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -51,6 +51,8 @@
 #include <cassert>
 
 //########### place macros to be removed in next cycle below this line ###############
+#define JVET_R0267_IDR_RPL                                1 // JVET-R0267: Add RPL constraint for IDR picture
+
 #define JVET_R0330_CRS_CLIP_REM                           1 // JVET-R0330: Remove redundant clipping in chroma residual scaling factor derivation
 
 #define JVET_R0059_RPL_CLEANUP                            1 // JVET-R0059 aspect 2: Condition the signalling of ltrp_in_header_flag[ listIdx ][ rplsIdx ].
-- 
GitLab