From 8202426cae87c42aa6e340739a4c9e19f4d8be9b Mon Sep 17 00:00:00 2001
From: Seungwook Hong <seungwook.hong@nokia.com>
Date: Thu, 11 Mar 2021 16:23:50 -0800
Subject: [PATCH] JVET-U0097: Made change to comply with coding convension and
 update software manual

---
 doc/software-manual.tex                       | 49 +++++++------------
 source/App/EncoderApp/EncApp.cpp              |  2 +-
 source/App/EncoderApp/EncAppCfg.cpp           |  6 +--
 source/App/EncoderApp/EncAppCfg.h             |  2 +-
 source/Lib/CommonLib/Slice.h                  |  4 +-
 .../Lib/CommonLib/dtrace_blockstatistics.cpp  |  6 ---
 source/Lib/DecoderLib/VLCReader.cpp           |  6 +--
 source/Lib/DecoderLib/VLCReader.h             |  6 +--
 source/Lib/EncoderLib/EncCfg.h                | 24 ++++-----
 source/Lib/EncoderLib/EncCu.cpp               |  8 +--
 source/Lib/EncoderLib/EncGOP.cpp              | 12 ++---
 source/Lib/EncoderLib/EncModeCtrl.cpp         | 10 ++--
 12 files changed, 60 insertions(+), 75 deletions(-)

diff --git a/doc/software-manual.tex b/doc/software-manual.tex
index 473457e53..ff5547dfe 100644
--- a/doc/software-manual.tex
+++ b/doc/software-manual.tex
@@ -2206,11 +2206,11 @@ Defines the periodicity for inter slices that use the slice-level chroma QP offs
 Defines the slice-level QP offset to be used for intra slices, or once every 'SliceChromaQPOffsetPeriodicity' pictures.
 \\
 
-\Option{MaxCuDQPSubdiv (-dqd)} &
+\Option{MaxCuDQPDepth (-dqd)} &
 %\ShortOption{\None} &
 \Default{0} &
-Defines maximum CTU subdivision level defining luma Quantization Groups. A quantization group contains at most one luma QP delta (carried by the first coded TU), and all CUs inside a QG share the same luma QP predictor.
-"Sbudivision level" means how many times the number of samples of the CTU is divided by two, e.g. a binary split increases subdiv by 1 and a quad split increases subdiv by 2.
+Defines maximum depth of a minimum CuDQP for sub-LCU-level delta QP.
+MaxCuDQPDepth shall be greater than or equal to SliceGranularity.
 \\
 
 \Option{RDOQ} &
@@ -2330,26 +2330,10 @@ Specifies whether scaling matrices are disabled to blocks when the colour space
 Indicates if the designated colour space of scaling matrices is equal to the original colour space.
 \\
 
-\Option{MaxCuChromaQpOffsetSubdiv} &
+\Option{MaxCUChromaQpAdjustmentDepth} &
 %\ShortOption{\None} &
-\Default{0} &
-Specifies the maximum subdiv for CU chroma QP adjustment. Has no effect if CbQpOffsetList, etc. are left empty.
-\\
-
-\Option{SliceCuChromaQpOffsetEnabled} &
-%\ShortOption{\None} &
-\Default{true} &
-Specifies whether CU chroma QP adjustment is enabled at slice level. Has no effect if CbQpOffsetList, etc. are left empty.
-\\
-
-\Option{CbQpOffsetList}%
-\Option{CrQpOffsetList}%
-\Option{CbCrQpOffsetList} &
-%\ShortOption{\None} &
-\Default{\NotSet} &
-Comma-separated value lists specifying the Cb/Cr/CbCr QP offsets for each chroma QP adjustment index. Each list shall be the same length.
-CbCrQpOffsetList may be omitted whereas CbQpOffsetList and CrQpOffsetList are specified, in which case it is filled with zeros.
-Note that when CbCrQpOffset and CbCrQpOffsetList values are all zero, pps_joint_cbcr_qp_offset_present_flag will be automatically set to zero.
+\Default{-1} &
+Specifies the maximum depth for CU chroma QP adjustment; if negative, CU chroma QP adjustment is disabled.
 \\
 
 \end{OptionTableNoShorthand}
@@ -3199,6 +3183,7 @@ Specifies poc number of first GDR
 %\ShortOption{\None} &
 \Default{-1} &
 <<<<<<< HEAD
+<<<<<<< HEAD
 Specifies number of frames between GDR picture to the next GDR picture
 \\
 
@@ -3211,27 +3196,29 @@ Specifies number of of frames from GDR picture to the recovery point picture (no
 \Option{GdrNoHash} &
 =======
 Specifies GDR period (note: ph_recovery_poc_cnt will be (GDR period - 1)) 
+=======
+Specifies number of frames between GDR picture to the next GDR picture
+>>>>>>> JVET-U0097: Made change to comply with coding convension and update software manual
 \\
 
-\Option{GdrFrequency} &
+\Option{GdrInterval} &
 %\ShortOption{\None} &
 \Default{-1} &
-Specifies the number of frames before the next GDR picture (e.g. a multiple of GDR period)
-\\
-
-\Option{StartWithGDR} &
-%\ShortOption{\None} &
-\Default{false} &
-Specifies if first picture of the bitstream should start with GDR picture 
+Specifies number of of frames from GDR picture to the recovery point picture (note: ph_recovery_poc_cnt will be (GDR Inteval - 1)) 
 \\
 
+<<<<<<< HEAD
 \Option{NoHashforGDR} &
 >>>>>>> JVET-U0097:Updated Software-manual, Enable/Disable GDR without recompiling
+=======
+\Option{GdrNoHash} &
+>>>>>>> JVET-U0097: Made change to comply with coding convension and update software manual
 %\ShortOption{\None} &
 \Default{true} &
 Specifies not to generate picture hash SEI for GDR/recovering pictures 
 \\
 
+<<<<<<< HEAD
 <<<<<<< HEAD
 =======
 \Option{GdrPicOutput} &
@@ -3240,6 +3227,8 @@ Specifies not to generate picture hash SEI for GDR/recovering pictures
 Specifies if ph_pic_output_flag should be signaled  
 \\
 >>>>>>> JVET-U0097:Updated Software-manual, Enable/Disable GDR without recompiling
+=======
+>>>>>>> JVET-U0097: Made change to comply with coding convension and update software manual
 \end{OptionTableNoShorthand}
 
 
diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index aa4c1d8b0..4a0c55cb1 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -526,7 +526,7 @@ void EncApp::xInitLibCfg()
   m_cEncLib.setGdrPeriod                                         ( m_gdrPeriod );
   m_cEncLib.setGdrPocStart                                       ( m_gdrPocStart );
   m_cEncLib.setGdrInterval                                       ( m_gdrInterval);  
-  m_cEncLib.setNoHashForGdr                                      ( m_bNoHashForGdr );  
+  m_cEncLib.setGdrNoHash                                         ( m_gdrNoHash );  
 #endif
   m_cEncLib.setDecodingRefreshType                               ( m_iDecodingRefreshType );
   m_cEncLib.setGOPSize                                           ( m_iGOPSize );
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 446157a46..198d45738 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1009,9 +1009,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
 #if GDR_ENABLED
   ("GdrEnabled",                                      m_gdrEnabled,                                     false, "GDR enabled")
   ("GdrPocStart",                                     m_gdrPocStart,                                       -1, "GDR poc start")
-  ("GdrPeriod",                                       m_gdrPeriod,                                         -1, "GDR period")
-  ("GdrInterval",                                     m_gdrInterval,                                      -1, "GDR freqency")  
-  ("NoHashforGDR",                                    m_bNoHashForGdr,                                   true, "No Hash for GDR")  
+  ("GdrPeriod",                                       m_gdrPeriod,                                         -1, "Number of frames between GDR picture to the next GDR picture")
+  ("GdrInterval",                                     m_gdrInterval,                                       -1, "Number of frames from GDR picture to the recovery point picture")  
+  ("GdrNoHash",                                       m_gdrNoHash,                                       true, "Do not generate decode picture hash SEI messages for GDR and recovering pictures")  
 #endif
   ("DecodingRefreshType,-dr",                         m_iDecodingRefreshType,                               0, "Intra refresh type (0:none 1:CRA 2:IDR 3:RecPointSEI)")
   ("GOPSize,g",                                       m_iGOPSize,                                           1, "GOP size of temporal structure")
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index d70c8c8f4..6942f34e2 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -223,7 +223,7 @@ protected:
   int       m_gdrPocStart;
   int       m_gdrPeriod;
   int       m_gdrInterval;  
-  bool      m_bNoHashForGdr;  
+  bool      m_gdrNoHash;  
 #endif
   int       m_iDecodingRefreshType;                           ///< random access type
   int       m_iGOPSize;                                       ///< GOP size of hierarchical structure
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index e47f8f385..613c04535 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -2423,8 +2423,8 @@ public:
   void                        setGdrPicFlag( bool b )                                   { m_gdrPicFlag = b;                                                                            }
   bool                        getGdrPicFlag() const                                     { return m_gdrPicFlag;                                                                         }
 #if GDR_ENABLED
-  void                        setInGdrInterval(bool b)                                    { m_inGdrInterval = b;                                                                            }
-  bool                        getInGdrInterval() const                                    { return m_inGdrInterval;                                                                         }  
+  void                        setInGdrInterval(bool b)                                  { m_inGdrInterval = b;                                                                         }
+  bool                        getInGdrInterval() const                                  { return m_inGdrInterval;                                                                      }  
 #endif
   void                        setRecoveryPocCnt( uint32_t u )                           { m_recoveryPocCnt = u;                                                                        }
   uint32_t                    getRecoveryPocCnt() const                                 { return m_recoveryPocCnt;                                                                     }
diff --git a/source/Lib/CommonLib/dtrace_blockstatistics.cpp b/source/Lib/CommonLib/dtrace_blockstatistics.cpp
index 526925d7e..d92ae1e17 100644
--- a/source/Lib/CommonLib/dtrace_blockstatistics.cpp
+++ b/source/Lib/CommonLib/dtrace_blockstatistics.cpp
@@ -909,12 +909,6 @@ void writeAllData(const CodingStructure& cs, const UnitArea& ctuArea)
           }
         }
         break;
-#if GDR_ENABLED
-      case MODE_IBC:
-      case MODE_PLT:
-        // note: not implemented yet
-        break;
-#endif
       default:
         THROW( "Invalid prediction mode" );
         break;
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 5861aa59d..db237dc43 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -4336,17 +4336,17 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, PicHeader* picHeader, Par
     }
   }
 #if GDR_ENABLED
-  int cur_poc = pcSlice->getPOC();
+  int curPoc = pcSlice->getPOC();
 
   if (picHeader->getGdrPicFlag())
   {
-    setLastGdrPoc(cur_poc);
+    setLastGdrPoc(curPoc);
     setLastGdrRecoveryPocCnt(pcSlice->getPicHeader()->getRecoveryPocCnt());
   }
 
   int recovery_poc_cnt = getLastGdrRecoveryPocCnt();
 
-  if (getLastGdrPoc() > 0 && (getLastGdrPoc() <= cur_poc) && (cur_poc < (getLastGdrPoc() + recovery_poc_cnt))) 
+  if (getLastGdrPoc() > 0 && (getLastGdrPoc() <= curPoc) && (curPoc < (getLastGdrPoc() + recovery_poc_cnt))) 
   {
     picHeader->setInGdrInterval(true);
   }  
diff --git a/source/Lib/DecoderLib/VLCReader.h b/source/Lib/DecoderLib/VLCReader.h
index a8db110a5..7442b2500 100644
--- a/source/Lib/DecoderLib/VLCReader.h
+++ b/source/Lib/DecoderLib/VLCReader.h
@@ -148,7 +148,7 @@ class HLSyntaxReader : public VLCReader
 {
 #if GDR_ENABLED
   int m_lastGdrPoc;
-  int m_last_gdr_recovery_poc_cnt;
+  int m_lastGdrRecoveryPocCnt;
 #endif
 
 public:
@@ -163,8 +163,8 @@ public:
 #if GDR_ENABLED
   void setLastGdrPoc(int poc) { m_lastGdrPoc = poc;  }
   int  getLastGdrPoc()        { return m_lastGdrPoc; }
-  void setLastGdrRecoveryPocCnt(int recovery_poc_cnt) { m_last_gdr_recovery_poc_cnt = recovery_poc_cnt; }
-  int  getLastGdrRecoveryPocCnt()                     { return m_last_gdr_recovery_poc_cnt; }
+  void setLastGdrRecoveryPocCnt(int recovery_poc_cnt) { m_lastGdrRecoveryPocCnt = recovery_poc_cnt; }
+  int  getLastGdrRecoveryPocCnt()                     { return m_lastGdrRecoveryPocCnt; }
 #endif
   void  setBitstream        ( InputBitstream* p )   { m_pcBitstream = p; }
   void  parseOPI            ( OPI* opi );
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index 85babab6d..97ad53f85 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -307,7 +307,7 @@ protected:
   unsigned  m_gdrPocStart;
   unsigned  m_gdrPeriod;
   int       m_gdrInterval;  
-  bool      m_bNoHashForGdr;  
+  bool      m_gdrNoHash;  
 #endif
   bool      m_useSplitConsOverride;
   unsigned  m_uiMinQT[3]; //0: I slice; 1: P/B slice, 2: I slice chroma
@@ -1004,17 +1004,17 @@ public:
   void      setMaxBTSizes                   ( unsigned* maxBT)   { m_uiMaxBT[0] = maxBT[0]; m_uiMaxBT[1] = maxBT[1]; m_uiMaxBT[2] = maxBT[2]; }
   void      setMaxTTSizes                   ( unsigned* maxTT)   { m_uiMaxTT[0] = maxTT[0]; m_uiMaxTT[1] = maxTT[1]; m_uiMaxTT[2] = maxTT[2]; }
 #if GDR_ENABLED
-  void      setGdrEnabled(bool b)       { m_gdrEnabled = b;    }
-  void      setGdrPeriod(unsigned  u)   { m_gdrPeriod   = u;   }
-  void      setGdrPocStart(unsigned  u) { m_gdrPocStart = u;   }
-  void      setGdrInterval(int i)       { m_gdrInterval = i;   }  
-  void      setNoHashForGdr(bool b)     { m_bNoHashForGdr = b; }    
-
-  bool      getGdrEnabled()             { return m_gdrEnabled;    }
-  unsigned  getGdrPeriod()              { return m_gdrPeriod;     }
-  unsigned  getGdrPocStart()            { return m_gdrPocStart;   }
-  int       getGdrInterval()            { return m_gdrInterval;   }  
-  bool      getNoHashForGdr()           { return m_bNoHashForGdr; }  
+  void      setGdrEnabled(bool b)       { m_gdrEnabled  = b; }
+  void      setGdrPeriod(unsigned u)    { m_gdrPeriod   = u; }
+  void      setGdrPocStart(unsigned u)  { m_gdrPocStart = u; }
+  void      setGdrInterval(int i)       { m_gdrInterval = i; }  
+  void      setGdrNoHash(bool b)        { m_gdrNoHash   = b; }    
+
+  bool      getGdrEnabled()             { return m_gdrEnabled;  }
+  unsigned  getGdrPeriod()              { return m_gdrPeriod;   }
+  unsigned  getGdrPocStart()            { return m_gdrPocStart; }
+  int       getGdrInterval()            { return m_gdrInterval; }  
+  bool      getGdrNoHash()              { return m_gdrNoHash;   }  
 #endif
   void      setMaxMTTHierarchyDepth         ( unsigned uiMaxMTTHierarchyDepth, unsigned uiMaxMTTHierarchyDepthI, unsigned uiMaxMTTHierarchyDepthIChroma )
                                                              { m_uiMaxMTTHierarchyDepth = uiMaxMTTHierarchyDepth; m_uiMaxMTTHierarchyDepthI = uiMaxMTTHierarchyDepthI; m_uiMaxMTTHierarchyDepthIChroma = uiMaxMTTHierarchyDepthIChroma; }
diff --git a/source/Lib/EncoderLib/EncCu.cpp b/source/Lib/EncoderLib/EncCu.cpp
index 3a07c00f7..6976aa7aa 100644
--- a/source/Lib/EncoderLib/EncCu.cpp
+++ b/source/Lib/EncoderLib/EncCu.cpp
@@ -558,10 +558,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
 #if GDR_ENABLED 
   if (m_pcEncCfg->getGdrEnabled())
   {
-    bool isCurGdrPicture = slice.getPicHeader()->getInGdrInterval();
+    bool isInGdrInterval = slice.getPicHeader()->getInGdrInterval();
 
     // 1.0 applicable to inter picture only  
-    if (isCurGdrPicture)
+    if (isInGdrInterval)
     {
       int gdrPocStart = m_pcEncCfg->getGdrPocStart();
       int gdrInterval = m_pcEncCfg->getGdrInterval();
@@ -597,8 +597,8 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
         begGdrX = m1 * n1 + m2 * (gdrPoc - n1);
         endGdrX = begGdrX + m2;
         if (picWidth <= endGdrX)
-        {
-          endGdrX = picWidth;
+        {          
+          begGdrX = picWidth;
           endGdrX = picWidth;
         }
       }
diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp
index 7a7b32473..b920abdc9 100644
--- a/source/Lib/EncoderLib/EncGOP.cpp
+++ b/source/Lib/EncoderLib/EncGOP.cpp
@@ -2164,7 +2164,7 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic,
     }
     pcSlice->setTLayer(m_pcCfg->getGOPEntry(iGOPid).m_temporalId);
 #if GDR_ENABLED
-    if (pocCurr >= m_pcCfg->getGdrPocStart() && ((pocCurr - m_pcCfg->getGdrPocStart()) % m_pcCfg->getGdrPeriod() == 0)) 
+    if (m_pcCfg->getGdrEnabled() && pocCurr >= m_pcCfg->getGdrPocStart() && ((pocCurr - m_pcCfg->getGdrPocStart()) % m_pcCfg->getGdrPeriod() == 0))
     {
       pcSlice->setSliceType(B_SLICE);
     }
@@ -3612,7 +3612,7 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic,
       std::string digestStr;
 #if GDR_ENABLED
       // note : generate hash sei only for non-gdr pictures
-      bool genHash = !(m_pcCfg->getNoHashForGdr() && pcSlice->getPicHeader()->getInGdrInterval());
+      bool genHash = !(m_pcCfg->getGdrNoHash() && pcSlice->getPicHeader()->getInGdrInterval());      
       if (m_pcCfg->getDecodedPictureHashSEIType() != HASHTYPE_NONE && genHash)
 #else
       if (m_pcCfg->getDecodedPictureHashSEIType()!=HASHTYPE_NONE)
@@ -3658,7 +3658,7 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic,
       xWriteTrailingSEIMessages(trailingSeiMessages, accessUnit, pcSlice->getTLayer());
 
 #if GDR_ENABLED
-      if (!(m_pcCfg->getNoHashForGdr() && pcSlice->getPicHeader()->getInGdrInterval())) 
+      if (!(m_pcCfg->getGdrNoHash() && pcSlice->getPicHeader()->getInGdrInterval())) 
       {
           printHash(m_pcCfg->getDecodedPictureHashSEIType(), digestStr);
       }
@@ -5087,7 +5087,7 @@ NalUnitType EncGOP::getNalUnitType(int pocCurr, int lastIDR, bool isField)
   }
 
 #if GDR_ENABLED    
-  if (m_pcCfg->getDecodingRefreshType() == 3 && (pocCurr >= m_pcCfg->getGdrPocStart()))
+  if (m_pcCfg->getGdrEnabled() && m_pcCfg->getDecodingRefreshType() == 3 && (pocCurr >= m_pcCfg->getGdrPocStart()))
   {    
     int m = pocCurr - m_pcCfg->getGdrPocStart();
     int n = m_pcCfg->getGdrPeriod();
@@ -5138,8 +5138,8 @@ NalUnitType EncGOP::getNalUnitType(int pocCurr, int lastIDR, bool isField)
     }
   }
 #if GDR_ENABLED    
-  if (pocCurr >= m_pcCfg->getGdrPocStart() && ((pocCurr - m_pcCfg->getGdrPocStart()) % m_pcCfg->getGdrPeriod() == 0))
-    return NAL_UNIT_CODED_SLICE_TRAIL;
+  if (m_pcCfg->getGdrEnabled() && pocCurr >= m_pcCfg->getGdrPocStart() && ((pocCurr - m_pcCfg->getGdrPocStart()) % m_pcCfg->getGdrPeriod() == 0))
+    return NAL_UNIT_CODED_SLICE_GDR;
   else
     return NAL_UNIT_CODED_SLICE_TRAIL;
 #else
diff --git a/source/Lib/EncoderLib/EncModeCtrl.cpp b/source/Lib/EncoderLib/EncModeCtrl.cpp
index 925ee1918..6d51ab5f8 100644
--- a/source/Lib/EncoderLib/EncModeCtrl.cpp
+++ b/source/Lib/EncoderLib/EncModeCtrl.cpp
@@ -1269,15 +1269,17 @@ bool EncModeCtrlMTnoRQT::tryMode( const EncTestMode& encTestmode, const CodingSt
   ComprCUCtx& cuECtx = m_ComprCUCtxList.back();
 
   // Fast checks, partitioning depended
-#if GDR_ENABLED 
-  if (!m_encCfg.getGdrEnabled())
+  if (cuECtx.isHashPerfectMatch && encTestmode.type != ETM_MERGE_SKIP && encTestmode.type != ETM_INTER_ME && encTestmode.type != ETM_AFFINE && encTestmode.type != ETM_MERGE_GEO)
   {
-    if (cuECtx.isHashPerfectMatch && encTestmode.type != ETM_MERGE_SKIP && encTestmode.type != ETM_INTER_ME && encTestmode.type != ETM_AFFINE && encTestmode.type != ETM_MERGE_GEO)
+#if GDR_ENABLED // disable hash perfect match when GDR is on
+    if (!m_encCfg.getGdrEnabled())
     {
       return false;
     }
-  }
+#else
+    return false;
 #endif
+  }
 
   // if early skip detected, skip all modes checking but the splits
   if( cuECtx.earlySkip && m_pcEncCfg->getUseEarlySkipDetection() && !isModeSplit( encTestmode ) && !( isModeInter( encTestmode ) ) )
-- 
GitLab