From bc939d78e26e0b0915a28c9f307e11428ffec3c5 Mon Sep 17 00:00:00 2001
From: Philip Cowan <cowanp@sharplabs.com>
Date: Wed, 8 Apr 2020 00:02:00 +0200
Subject: [PATCH] JVET-Q0217 Proposal 5: Modfications to reference picture
 information signalling

---
 source/Lib/CommonLib/TypeDef.h      | 2 ++
 source/Lib/DecoderLib/VLCReader.cpp | 6 +++++-
 source/Lib/EncoderLib/VLCWriter.cpp | 8 +++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 2d4c84c32..9bb5a7431 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -305,6 +305,8 @@
 
 #define JVET_SUBPIC_LEVEL_CFG                             1  // improved configuration of subpicture level info SEI
 
+#define JVET_Q0217_PROPOSAL5                              1  // JVET-Q0217 Proposal 5: modifications to reference picture information signalling
+
 typedef std::pair<int, bool> TrMode;
 typedef std::pair<int, int>  TrCost;
 
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index c2fc987af..c1123aad4 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -371,7 +371,11 @@ void HLSyntaxReader::parseRefPicList(SPS* sps, ReferencePictureList* rpl)
     if (!isLongTerm)
     {
       READ_UVLC(code, "abs_delta_poc_st[ listIdx ][ rplsIdx ][ i ]");
-      if( !sps->getUseWP() && !sps->getUseWPBiPred() )
+#if JVET_Q0217_PROPOSAL5
+      if ((!sps->getUseWP() && !sps->getUseWPBiPred()) || (ii == 0))
+#else
+      if (!sps->getUseWP() && !sps->getUseWPBiPred())
+#endif
       {
         code++;
       }
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 9b2029ca7..296bfedc7 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -224,9 +224,15 @@ void HLSWriter::xCodeRefPicList( const ReferencePictureList* rpl, bool isLongTer
         prevDelta = rpl->getRefPicIdentifier(ii);
       }
       unsigned int absDeltaValue = (deltaValue < 0) ? 0 - deltaValue : deltaValue;
-      if( isForbiddenZeroDeltaPoc )
+#if JVET_Q0217_PROPOSAL5
+      if (isForbiddenZeroDeltaPoc || ii == 0)
+      {
+        CHECK(!absDeltaValue, "Zero delta POC is not used without WP or is the 0-th entry");
+#else
+      if (isForbiddenZeroDeltaPoc)
       {
         CHECK( !absDeltaValue, "Zero delta POC is not used without WP" );
+#endif
         WRITE_UVLC( absDeltaValue - 1, "abs_delta_poc_st[ listIdx ][ rplsIdx ][ i ]" );
       }
       else
-- 
GitLab