From 31b54dfc85d7c2be696ad86af0dd26549170bebb Mon Sep 17 00:00:00 2001
From: Frank Bossen <fbossen@gmail.com>
Date: Sun, 2 Aug 2020 10:50:07 -0400
Subject: [PATCH] Reodering of syntax elements in PH

During integration of JVET-R0324, mvd_l1_zero_flag was moved down
in the syntax table (see JVET-R2001-v2). This change had not been
reflected in the !1563.
---
 source/Lib/CommonLib/TypeDef.h      |  2 ++
 source/Lib/DecoderLib/VLCReader.cpp | 23 +++++++++++++++++++----
 source/Lib/EncoderLib/VLCWriter.cpp | 19 +++++++++++++++----
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 7e3312b5a..fa69969ea 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -62,6 +62,8 @@
 
 #define JVET_S_SUB_PROFILE                                1 // Move signalling of ptl_num_sub_profiles
 
+#define JVET_R0324_REORDER                                1 // Reordering of syntax elements JVET-R0324/JVET-R2001-v2
+
 #define JVET_S0219_ASPECT2_CHANGE_ORDER_APS_PARAMS_TYPE   1 // JVET-S0219 aspect2: change the order to put the aps_params_type before the aps_adaptation_parameter_set_id.
 
 #define JVET_R0270                                        1 // JVET-S0270: Treating picture with mixed RASL and RADL slices as RASL picture
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index e730abf42..0fe347385 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -3266,7 +3266,8 @@ void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManag
       picHeader->setPicColFromL0Flag(0);
     }
 
-  // mvd L1 zero flag
+#if !JVET_R0324_REORDER
+    // mvd L1 zero flag
     if (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0)
     {
       READ_FLAG(uiCode, "pic_mvd_l1_zero_flag");
@@ -3276,9 +3277,10 @@ void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManag
       uiCode = 1;
     }
     picHeader->setMvdL1ZeroFlag( uiCode != 0 );
+#endif
 
-  // merge candidate list size
-  // subblock merge candidate list size
+    // merge candidate list size
+    // subblock merge candidate list size
     if ( sps->getUseAffine() )
     {
       picHeader->setMaxNumAffineMergeCand(sps->getMaxNumAffineMergeCand());
@@ -3299,7 +3301,20 @@ void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManag
       picHeader->setDisFracMMVD(false);
     }
 
-  // picture level BDOF disable flags
+#if JVET_R0324_REORDER
+    // mvd L1 zero flag
+    if (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0)
+    {
+      READ_FLAG(uiCode, "ph_mvd_l1_zero_flag");
+    }
+    else
+    {
+      uiCode = 1;
+    }
+    picHeader->setMvdL1ZeroFlag(uiCode != 0);
+#endif
+
+    // picture level BDOF disable flags
     if (sps->getBdofControlPresentFlag() && (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0))
     {
       READ_FLAG(uiCode, "ph_disable_bdof_flag");  picHeader->setDisBdofFlag(uiCode != 0);
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 9a15dec97..0c29c2535 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -2038,13 +2038,16 @@ WRITE_FLAG(picHeader->getGdrOrIrapPicFlag(), "gdr_or_irap_pic_flag");
       picHeader->setEnableTMVPFlag(false);
     }
 
-  // mvd L1 zero flag
+#if !JVET_R0324_REORDER
+    // mvd L1 zero flag
     if (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0)
     {
       WRITE_FLAG(picHeader->getMvdL1ZeroFlag(), "pic_mvd_l1_zero_flag");
     }
-  // merge candidate list size
-  // subblock merge candidate list size
+#endif
+
+    // merge candidate list size
+    // subblock merge candidate list size
     if ( sps->getUseAffine() )
     {
       picHeader->setMaxNumAffineMergeCand(sps->getMaxNumAffineMergeCand());
@@ -2064,7 +2067,15 @@ WRITE_FLAG(picHeader->getGdrOrIrapPicFlag(), "gdr_or_irap_pic_flag");
       picHeader->setDisFracMMVD(false);
     }
 
-  // picture level BDOF disable flags
+#if JVET_R0324_REORDER
+    // mvd L1 zero flag
+    if (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0)
+    {
+      WRITE_FLAG(picHeader->getMvdL1ZeroFlag(), "ph_mvd_l1_zero_flag");
+    }
+#endif
+
+    // picture level BDOF disable flags
     if (sps->getBdofControlPresentFlag() && (!pps->getRplInfoInPhFlag() || picHeader->getRPL(1)->getNumRefEntries() > 0))
     {
       WRITE_FLAG(picHeader->getDisBdofFlag(), "ph_disable_bdof_flag");
-- 
GitLab