From dbb918df3656028c609507af1ade9ffee5e523e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabrice=20Le=20L=C3=A9annec?= <fabricel@xiaomi.com>
Date: Wed, 27 Jul 2022 23:46:30 +0000
Subject: [PATCH] JVET-AA0098: new config file for class A random access QP 22
 CTC

---
 cfg/per-class/classA_randomaccess.cfg |  1 +
 source/App/EncoderApp/EncAppCfg.cpp   | 23 ++++++++++++++++++++++-
 source/Lib/CommonLib/TypeDef.h        |  3 +++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/cfg/per-class/classA_randomaccess.cfg b/cfg/per-class/classA_randomaccess.cfg
index 891dfa12e..cbb53ba24 100644
--- a/cfg/per-class/classA_randomaccess.cfg
+++ b/cfg/per-class/classA_randomaccess.cfg
@@ -10,4 +10,5 @@ MaxTTLumaISlice: 128
 MaxTTChromaISlice: 128
 MaxTTNonISlice: 128
 MaxMTTHierarchyDepthByTid: 333322
+MaxMTTHierarchyDepthByTidOverrideByQP: 22 333222
 QpOutValCb: 17 23 35 40
\ No newline at end of file
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index bb33a5d92..a78e951a6 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -713,6 +713,10 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   SMultiValueInput<Level::Name>  cfg_sliRefLevels(Level::NONE, Level::LEVEL15_5,  0, 8);
 #endif
 
+#if JVET_AA0098_MTT_DEPTH_TID_BY_QP
+  std::string sMaxMTTHierarchyDepthByTidOverrideByQP;
+#endif
+
   int warnUnknowParameter = 0;
 
 #if ENABLE_TRACING
@@ -980,6 +984,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   ("MaxMTTHierarchyDepth",                            m_uiMaxMTTHierarchyDepth,                            3u, "MaxMTTHierarchyDepth")
 #if JVET_X0144_MAX_MTT_DEPTH_TID
   ("MaxMTTHierarchyDepthByTid",                       m_sMaxMTTHierarchyDepthByTid,          string("333333"), "MaxMTTHierarchyDepthByTid")
+#if JVET_AA0098_MTT_DEPTH_TID_BY_QP
+  ("MaxMTTHierarchyDepthByTidOverrideByQP",           sMaxMTTHierarchyDepthByTidOverrideByQP, string("22 333333"), "MaxMTTHierarchyDepthByTidOverrideByQP")
+#endif
 #endif
   ("MaxMTTHierarchyDepthI",                           m_uiMaxMTTHierarchyDepthI,                           3u, "MaxMTTHierarchyDepthI")
   ("MaxMTTHierarchyDepthISliceL",                     m_uiMaxMTTHierarchyDepthI,                           3u, "MaxMTTHierarchyDepthISliceL")
@@ -3151,7 +3158,20 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
 #endif
 
 #if JVET_X0144_MAX_MTT_DEPTH_TID
-  CHECK( m_sMaxMTTHierarchyDepthByTid.size() > MAX_TLAYER, "MaxMTTHierarchyDepthByTid is greater than MAX_TLAYER" );
+#if JVET_AA0098_MTT_DEPTH_TID_BY_QP
+  std::istringstream iss(sMaxMTTHierarchyDepthByTidOverrideByQP);
+  std::string        sQp;
+  std::string        sMaxMttDepthByTidOverride;
+  getline(iss, sQp, ' ');
+  getline(iss, sMaxMttDepthByTidOverride, ' ');
+  int overriddenQP = std::stoi(sQp);
+  if (m_iQP == overriddenQP)
+  {
+    m_sMaxMTTHierarchyDepthByTid = sMaxMttDepthByTidOverride;
+  }
+#endif
+
+  CHECK(m_sMaxMTTHierarchyDepthByTid.size() > MAX_TLAYER, "MaxMTTHierarchyDepthByTid is greater than MAX_TLAYER");
 
   for( int i = 0; i < (int)m_sMaxMTTHierarchyDepthByTid.size(); i++ )
   {
@@ -3159,6 +3179,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
     m_maxMTTHierarchyDepthByTid[i] = std::stoul( m_sMaxMTTHierarchyDepthByTid.substr( i, 1 ) );
   }
 
+
   for( int i = (int)m_sMaxMTTHierarchyDepthByTid.size(); i < MAX_TLAYER; i++ )
   {
     m_maxMTTHierarchyDepthByTid[i] = m_uiMaxMTTHierarchyDepth;
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 5657f5076..cb3922769 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -67,6 +67,9 @@
 
 // Software optimization
 #define JVET_X0144_MAX_MTT_DEPTH_TID                      1 // JVET-X0144: max MTT hierarchy depth set by temporal ID
+#if JVET_X0144_MAX_MTT_DEPTH_TID
+#define JVET_AA0098_MTT_DEPTH_TID_BY_QP                    1
+#endif
 #define JVET_X0049_BDMVR_SW_OPT                           1 // JVET-X0049: software optimization for BDMVR (lossless)
 #define INTRA_TRANS_ENC_OPT                               1 // JVET-Y0141: Software optimization, including TIMD/DIMD/MTS/LFNS encoder fast algorithm, SIMD implementation and CM initial value retraining 
 #define JVET_AA0129_INTERHASH_OBMCOFF_RD                  1 // JVET-AA0129: improved encoder RDO of inter-hash based ME considering OBMC off
-- 
GitLab