From 58e56674c163e492270742d8f7f03110bd238a5e Mon Sep 17 00:00:00 2001
From: phil <cowanp@sharplabs.com>
Date: Tue, 21 Jul 2020 08:23:51 -0700
Subject: [PATCH] JVET-S0181: Reference picture list information signalling
 cleanup - signal ltrp_in_slice_header_flag[listIdx][rplsIdx] only when
 num_ref_entries[listIdx][rplsIdx] is greater than 0 in addition to other
 conditions.

---
 source/Lib/CommonLib/TypeDef.h      | 2 ++
 source/Lib/DecoderLib/VLCReader.cpp | 4 ++++
 source/Lib/EncoderLib/VLCWriter.cpp | 4 ++++
 3 files changed, 10 insertions(+)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index ff1501f95..e4b365964 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -111,6 +111,8 @@
                                                             //             Constrain the value of one_subpic_per_pic_constraint_flag, one_slice_per_pic_constraint_flag and no_aps_constraint_flag
                                                             //             Remove all constraints that require GCI fields to be equal to a value that imposes a constraint
 
+#define JVET_S0182_RPL_SIGNALLING                         1 // JVET-S0182: modifications to rpl information signalling
+
 //########### place macros to be be kept below this line ###############
 #define JVET_S0257_DUMP_360SEI_MESSAGE                    1 // Software support of 360 SEI messages
 
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 3ee87217a..b92860af8 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -325,7 +325,11 @@ void HLSyntaxReader::parseRefPicList(SPS* sps, ReferencePictureList* rpl, int rp
   uint32_t numLtrp = 0;
   uint32_t numIlrp = 0;
 
+#if JVET_S0182_RPL_SIGNALLING
+  if (sps->getLongTermRefsPresent() && numRefPic > 0 && rplIdx != -1)
+#else
   if (sps->getLongTermRefsPresent() && rplIdx != -1)
+#endif
   {
     READ_FLAG(code, "ltrp_in_slice_header_flag[ listIdx ][ rplsIdx ]");
     rpl->setLtrpInSliceHeaderFlag(code);
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 6f58f7311..2dfc9b9c3 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -185,7 +185,11 @@ void HLSWriter::xCodeRefPicList( const ReferencePictureList* rpl, bool isLongTer
   uint32_t numRefPic = rpl->getNumberOfShorttermPictures() + rpl->getNumberOfLongtermPictures() + rpl->getNumberOfInterLayerPictures();
   WRITE_UVLC( numRefPic, "num_ref_entries[ listIdx ][ rplsIdx ]" );
 
+#if JVET_S0182_RPL_SIGNALLING
+  if (isLongTermPresent && numRefPic > 0 && rplIdx != -1)
+#else
   if (isLongTermPresent && rplIdx != -1)
+#endif
   {
     WRITE_FLAG(rpl->getLtrpInSliceHeaderFlag(), "ltrp_in_slice_header_flag[ listIdx ][ rplsIdx ]");
   }
-- 
GitLab