From c05ae25700d4d44f6196b23a7ae13d7451006895 Mon Sep 17 00:00:00 2001
From: Yao-Jen Chang <yjchang@qti.qualcomm.com>
Date: Mon, 6 Jul 2020 11:45:45 -0700
Subject: [PATCH] JVET-S0221: Fix bugs, resolve conflict, and add one check at
 configure

---
 source/App/EncoderApp/EncAppCfg.cpp | 11 +++++++++++
 source/Lib/CommonLib/TypeDef.h      |  2 +-
 source/Lib/DecoderLib/VLCReader.cpp |  8 ++++----
 source/Lib/EncoderLib/VLCWriter.cpp |  8 ++++----
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index c6da6cf15..970b78140 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1615,6 +1615,17 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
     CHECK(m_resChangeInClvsEnabled, "resolution change in CLVS and subpictures cannot be enabled together");
   }
 
+#if JVET_S0221_NUM_VB_CHECK
+  if (m_virtualBoundariesPresentFlag)
+  {
+    if (m_iSourceWidth <= 8)
+      CHECK(m_numVerVirtualBoundaries != 0, "The number of vertical virtual boundaries shall be 0 when the picture width is less than or equal to 8");
+
+    if (m_iSourceHeight <= 8)
+      CHECK(m_numHorVirtualBoundaries != 0, "The number of horizontal virtual boundaries shall be 0 when the picture height is less than or equal to 8");
+  }
+#endif
+
   if (m_cfgSubpictureLevelInfoSEI.m_enabled)
   {
     CHECK (m_numSubPics != m_cfgSubpictureLevelInfoSEI.m_numSubpictures, "NumSubPics must be equal to SEISubpicLevelInfoNumSubpics" );
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 587c845f5..28a9f8858 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -53,7 +53,7 @@
 
 //########### place macros to be removed in next cycle below this line ###############
 
-#define JVET_R0042_SUBPIC_CHECK                           1 // JVET_R0042: SubPicture types related constraints
+#define JVET_S0221_NUM_VB_CHECK                           1 // JVET_S0221: Constraints on the number of virtual boundaries
 
 
 //########### place macros to be be kept below this line ###############
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index a526534e5..5e750dd58 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -1873,7 +1873,7 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
 #if JVET_S0221_NUM_VB_CHECK
     if (pcSPS->getMaxPicWidthInLumaSamples() <= 8)
     {
-      CHECK(pcSPS->getNumVerVirtualBoundaries() == 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
+      CHECK(pcSPS->getNumVerVirtualBoundaries() != 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
     }
 #endif
     for( unsigned i = 0; i < pcSPS->getNumVerVirtualBoundaries(); i++ )
@@ -1884,7 +1884,7 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
 #if JVET_S0221_NUM_VB_CHECK
     if (pcSPS->getMaxPicHeightInLumaSamples() <= 8)
     {
-      CHECK(pcSPS->getNumHorVirtualBoundaries() == 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
+      CHECK(pcSPS->getNumHorVirtualBoundaries() != 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
     }
 #endif
     for( unsigned i = 0; i < pcSPS->getNumHorVirtualBoundaries(); i++ )
@@ -2594,7 +2594,7 @@ void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManag
 #if JVET_S0221_NUM_VB_CHECK
       if (pps->getPicWidthInLumaSamples() <= 8)
       {
-        CHECK(picHeader->getNumVerVirtualBoundaries() == 0, "PH: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
+        CHECK(picHeader->getNumVerVirtualBoundaries() != 0, "PH: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < picHeader->getNumVerVirtualBoundaries(); i++ )
@@ -2605,7 +2605,7 @@ void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManag
 #if JVET_S0221_NUM_VB_CHECK
       if (pps->getPicHeightInLumaSamples() <= 8)
       {
-        CHECK(picHeader->getNumHorVirtualBoundaries() == 0, "PH: When picture width is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
+        CHECK(picHeader->getNumHorVirtualBoundaries() != 0, "PH: When picture width is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < picHeader->getNumHorVirtualBoundaries(); i++ )
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 79f8ac65a..71f55c30f 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -1139,7 +1139,7 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
 #if JVET_S0221_NUM_VB_CHECK
       if (pcSPS->getMaxPicWidthInLumaSamples() <= 8)
       {
-        CHECK(pcSPS->getNumVerVirtualBoundaries() == 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
+        CHECK(pcSPS->getNumVerVirtualBoundaries() != 0, "SPS: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < pcSPS->getNumVerVirtualBoundaries(); i++ )
@@ -1150,7 +1150,7 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
 #if JVET_S0221_NUM_VB_CHECK
       if (pcSPS->getMaxPicHeightInLumaSamples() <= 8)
       {
-        CHECK(pcSPS->getNumHorVirtualBoundaries() == 0, "SPS: When picture height is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
+        CHECK(pcSPS->getNumHorVirtualBoundaries() != 0, "SPS: When picture height is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < pcSPS->getNumHorVirtualBoundaries(); i++ )
@@ -1595,7 +1595,7 @@ void HLSWriter::codePictureHeader( PicHeader* picHeader, bool writeRbspTrailingB
 #if JVET_S0221_NUM_VB_CHECK
       if (pps->getPicWidthInLumaSamples() <= 8)
       {
-        CHECK(picHeader->getNumVerVirtualBoundaries() == 0, "PH: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
+        CHECK(picHeader->getNumVerVirtualBoundaries() != 0, "PH: When picture width is less than or equal to 8, the number of vertical virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < picHeader->getNumVerVirtualBoundaries(); i++ )
@@ -1606,7 +1606,7 @@ void HLSWriter::codePictureHeader( PicHeader* picHeader, bool writeRbspTrailingB
 #if JVET_S0221_NUM_VB_CHECK
       if (pps->getPicHeightInLumaSamples() <= 8)
       {
-        CHECK(picHeader->getNumHorVirtualBoundaries() == 0, "PH: When picture width is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
+        CHECK(picHeader->getNumHorVirtualBoundaries() != 0, "PH: When picture width is less than or equal to 8, the number of horizontal virtual boundaries shall be equal to 0");
       }
 #endif
       for( unsigned i = 0; i < picHeader->getNumHorVirtualBoundaries(); i++ )
-- 
GitLab