From 6128480f86d92167e32abcb24e8ee34f2ac20b10 Mon Sep 17 00:00:00 2001
From: Yong He <yonghe@qti.qualcomm.com>
Date: Tue, 14 Feb 2023 16:34:04 -0800
Subject: [PATCH] remove number of SEI messages variables

---
 source/App/EncoderApp/EncApp.cpp     |  6 ++--
 source/App/EncoderApp/EncAppCfg.cpp  | 42 +++++++++++++++-------------
 source/App/EncoderApp/EncAppCfg.h    |  4 ++-
 source/Lib/EncoderLib/EncCfg.h       |  9 ++++--
 source/Lib/EncoderLib/SEIEncoder.cpp | 30 ++++++++++++--------
 5 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index 85bafeee38..909533b69e 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -1306,12 +1306,14 @@ void EncApp::xInitLibCfg( int layerIdx )
   m_cEncLib.setPoSEIEnabled                                      (m_poSEIEnabled);
   m_cEncLib.setPoSEIPayloadType                                  (m_poSEIPayloadType);
   m_cEncLib.setPoSEIProcessingOrder                              (m_poSEIProcessingOrder);
-  m_cEncLib.setPoSEINumofSeiMessages                             (m_numofSEIMessages);
-
 #if JVET_AC0058_SEI
   m_cEncLib.setPoSEIPrefixByte                                   (m_poSEIPrefixByte);
+#else  
+  m_cEncLib.setPoSEINumofSeiMessages                             (m_numofSEIMessages);
 #endif
 
+
+
   m_cEncLib.setPostFilterHintSEIEnabled(m_postFilterHintSEIEnabled);
   m_cEncLib.setPostFilterHintSEICancelFlag(m_postFilterHintSEICancelFlag);
   m_cEncLib.setPostFilterHintSEIPersistenceFlag(m_postFilterHintSEIPersistenceFlag);
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 46e10d97a7..f6931ba33d 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -3420,27 +3420,24 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   {
     assert(cfg_poSEIPayloadType.values.size() > 1);
     assert(cfg_poSEIProcessingOrder.values.size() == cfg_poSEIPayloadType.values.size());
-    m_numofSEIMessages = (uint32_t)cfg_poSEIPayloadType.values.size();
-    m_poSEIPayloadType.resize(m_numofSEIMessages);
-    m_poSEIProcessingOrder.resize(m_numofSEIMessages);
 #if JVET_AC0058_SEI
-    m_poSEIPrefixByte.resize(m_numofSEIMessages);
+    m_poSEIPayloadType.resize((uint32_t) cfg_poSEIPayloadType.values.size());
+    m_poSEIProcessingOrder.resize((uint32_t) cfg_poSEIPayloadType.values.size());
+    m_poSEIPrefixByte.resize((uint32_t) cfg_poSEIPayloadType.values.size());
     uint16_t prefixByteIdx = 0;
-#endif
-    for (uint32_t i = 0; i < m_numofSEIMessages; i++)
+    for (uint32_t i = 0; i < (uint32_t) cfg_poSEIPayloadType.values.size(); i++)
     {
-      m_poSEIPayloadType[i]  = cfg_poSEIPayloadType.values[i];
-      m_poSEIProcessingOrder[i] = (uint16_t)cfg_poSEIProcessingOrder.values[i];
-#if JVET_AC0058_SEI
-      if (m_poSEIPayloadType[i] == (uint16_t)SEI::PayloadType::USER_DATA_REGISTERED_ITU_T_T35)
+      m_poSEIPayloadType[i]     = cfg_poSEIPayloadType.values[i];
+      m_poSEIProcessingOrder[i] = (uint16_t) cfg_poSEIProcessingOrder.values[i];
+      if (m_poSEIPayloadType[i] == (uint16_t) SEI::PayloadType::USER_DATA_REGISTERED_ITU_T_T35)
       {
         m_poSEIPrefixByte[i].resize(cfg_poSEINumofPrefixByte.values[i]);
         for (uint32_t j = 0; j < cfg_poSEINumofPrefixByte.values[i]; j++)
         {
-          m_poSEIPrefixByte[i][j] = (uint8_t)cfg_poSEIPrefixByte.values[prefixByteIdx++];
+          m_poSEIPrefixByte[i][j] = (uint8_t) cfg_poSEIPrefixByte.values[prefixByteIdx++];
         }
       }
-      //Error check, to avoid same PayloadType and same prefix bytes when present with different PayloadOrder
+      // Error check, to avoid same PayloadType and same prefix bytes when present with different PayloadOrder
       for (uint32_t j = 0; j < i; j++)
       {
         auto payloadType = SEI::PayloadType(cfg_poSEIPayloadType.values[i]);
@@ -3450,9 +3447,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
           {
             if (m_poSEIPayloadType[j] == m_poSEIPayloadType[i])
             {
-              auto numofPrefixBytes =
-                std::min(cfg_poSEINumofPrefixByte.values[i], cfg_poSEINumofPrefixByte.values[j]);
-              if (std::equal(m_poSEIPrefixByte[i].begin() + 1, m_poSEIPrefixByte[i].begin() + numofPrefixBytes - 1, m_poSEIPrefixByte[j].begin()))
+              auto numofPrefixBytes = std::min(cfg_poSEINumofPrefixByte.values[i], cfg_poSEINumofPrefixByte.values[j]);
+              if (std::equal(m_poSEIPrefixByte[i].begin() + 1, m_poSEIPrefixByte[i].begin() + numofPrefixBytes - 1,
+                             m_poSEIPrefixByte[j].begin()))
               {
                 assert(m_poSEIProcessingOrder[j] == m_poSEIProcessingOrder[i]);
               }
@@ -3460,7 +3457,18 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
           }
         }
       }
+    }
+    // Error check, to avoid all SEI messages share the same PayloadOrder
+    assert(!std::equal(cfg_poSEIProcessingOrder.values.begin() + 1, cfg_poSEIProcessingOrder.values.end(),
+                       cfg_poSEIProcessingOrder.values.begin()));
 #else
+    m_numofSEIMessages = (uint32_t)cfg_poSEIPayloadType.values.size();
+    m_poSEIPayloadType.resize(m_numofSEIMessages);
+    m_poSEIProcessingOrder.resize(m_numofSEIMessages);
+    for (uint32_t i = 0; i < m_numofSEIMessages; i++)
+    {
+      m_poSEIPayloadType[i]  = cfg_poSEIPayloadType.values[i];
+      m_poSEIProcessingOrder[i] = (uint16_t)cfg_poSEIProcessingOrder.values[i];
       //Error check, to avoid same PayloadType with different PayloadOrder
       for (uint32_t j = 0; j < i; j++)
       {
@@ -3469,11 +3477,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
           assert(m_poSEIProcessingOrder[j]== m_poSEIProcessingOrder[i]);
         }
       }
-#endif
     }
-#if JVET_AC0058_SEI
-    //Error check, to avoid all SEI messages share the same PayloadOrder 
-    assert(!std::equal(cfg_poSEIProcessingOrder.values.begin() + 1, cfg_poSEIProcessingOrder.values.end(), cfg_poSEIProcessingOrder.values.begin()));
 #endif
     assert(m_poSEIPayloadType.size() > 0);
     assert(m_poSEIProcessingOrder.size() == m_poSEIPayloadType.size());
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index 9612180016..60bb0edaf6 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -780,11 +780,13 @@ protected:
   bool                  m_poSEIEnabled;
   std::vector<uint16_t> m_poSEIPayloadType;
   std::vector<uint16_t>  m_poSEIProcessingOrder;
-  uint32_t              m_numofSEIMessages;
 #if JVET_AC0058_SEI
   std::vector<std::vector<uint8_t>> m_poSEIPrefixByte;
+#else
+  uint32_t m_numofSEIMessages;
 #endif
 
+
   bool                 m_postFilterHintSEIEnabled;
   bool                 m_postFilterHintSEICancelFlag;
   bool                 m_postFilterHintSEIPersistenceFlag;
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index e98f58bea1..4fa8ee9e05 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -861,10 +861,11 @@ protected:
   bool                  m_poSEIEnabled;
   std::vector<uint16_t> m_poSEIPayloadType;
   std::vector<uint16_t>  m_poSEIProcessingOrder;
-  uint32_t              m_numofSEIMessages;
 #if JVET_AC0058_SEI
   //std::vector<uint16_t> m_poSEINumofPrefixByte;
   std::vector<std::vector<uint8_t>>  m_poSEIPrefixByte;
+#else
+  uint32_t              m_numofSEIMessages;
 #endif
   bool                 m_postFilterHintSEIEnabled;
   bool                 m_postFilterHintSEICancelFlag;
@@ -2483,11 +2484,13 @@ public:
   uint16_t getPoSEIPayloadType(uint16_t idx)                   const { return m_poSEIPayloadType[idx]; }
   void     setPoSEIProcessingOrder(const std::vector<uint16_t>& b) { m_poSEIProcessingOrder = b; }
   uint16_t  getPoSEIProcessingOrder(uint16_t idx)              const { return m_poSEIProcessingOrder[idx]; }
-  void     setPoSEINumofSeiMessages(uint32_t i)                      { m_numofSEIMessages = i; }
-  uint32_t getPoSEINumofSeiMessages()                          const { return m_numofSEIMessages; }
 #if JVET_AC0058_SEI
+  uint32_t getPoSEIPayloadTypeSize()                           const { return (uint32_t)m_poSEIPayloadType.size(); }
   void     setPoSEIPrefixByte(const std::vector<std::vector<uint8_t>>& b) { m_poSEIPrefixByte = b; }
   std::vector<uint8_t>  getPoSEIPrefixByte(uint16_t idx)       const { return m_poSEIPrefixByte[idx]; }
+#else
+  uint32_t getPoSEINumofSeiMessages()                          const { return m_numofSEIMessages; }
+  void     setPoSEINumofSeiMessages(uint32_t i)                      { m_numofSEIMessages = i; }
 #endif
   void     setPostFilterHintSEIEnabled(bool b) { m_postFilterHintSEIEnabled = b; }
   bool     getPostFilterHintSEIEnabled() { return m_postFilterHintSEIEnabled; }
diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp
index 1e4876daaf..43bc6e443c 100644
--- a/source/Lib/EncoderLib/SEIEncoder.cpp
+++ b/source/Lib/EncoderLib/SEIEncoder.cpp
@@ -611,27 +611,33 @@ void SEIEncoder::initSEIProcessingOrderInfo(SEIProcessingOrderInfo *seiProcessin
   assert(m_isInitialized);
   assert(seiProcessingOrderInfo != nullptr);
 
-  uint32_t numSEIMessages = m_pcCfg->getPoSEINumofSeiMessages();
+
 #if JVET_AC0058_SEI
-  seiProcessingOrderInfo->m_posPrefixByte.resize(numSEIMessages);
+  seiProcessingOrderInfo->m_posPrefixByte.resize(m_pcCfg->getPoSEIPayloadTypeSize());
+  seiProcessingOrderInfo->m_posEnabled          = m_pcCfg->getPoSEIEnabled();
+  seiProcessingOrderInfo->m_posPayloadType.resize(m_pcCfg->getPoSEIPayloadTypeSize());
+  seiProcessingOrderInfo->m_posProcessingOrder.resize(m_pcCfg->getPoSEIPayloadTypeSize());
+  for (uint32_t i = 0; i < m_pcCfg->getPoSEIPayloadTypeSize(); i++)
+  {
+    seiProcessingOrderInfo->m_posPayloadType[i]     = m_pcCfg->getPoSEIPayloadType(i);
+    seiProcessingOrderInfo->m_posProcessingOrder[i] = m_pcCfg->getPoSEIProcessingOrder(i);
+    if (seiProcessingOrderInfo->m_posPayloadType[i] == (uint16_t) SEI::PayloadType::USER_DATA_REGISTERED_ITU_T_T35)
+    {
+      seiProcessingOrderInfo->m_posPrefixByte[i] = m_pcCfg->getPoSEIPrefixByte(i);
+    }
+  }
 #else  
+  uint32_t numSEIMessages = m_pcCfg->getPoSEINumofSeiMessages();
   seiProcessingOrderInfo->m_posNumofSeiMessages = numSEIMessages;
-#endif
   seiProcessingOrderInfo->m_posEnabled          = m_pcCfg->getPoSEIEnabled();
-
   seiProcessingOrderInfo->m_posPayloadType.resize(numSEIMessages);
   seiProcessingOrderInfo->m_posProcessingOrder.resize(numSEIMessages);
-
-  for (uint32_t i = 0; i < numSEIMessages; i++) {
+  for (uint32_t i = 0; i < numSEIMessages; i++) 
+  {
     seiProcessingOrderInfo->m_posPayloadType[i]     = m_pcCfg->getPoSEIPayloadType(i);
     seiProcessingOrderInfo->m_posProcessingOrder[i] = m_pcCfg->getPoSEIProcessingOrder(i);
-#if JVET_AC0058_SEI
-    if (seiProcessingOrderInfo->m_posPayloadType[i] == (uint16_t)SEI::PayloadType::USER_DATA_REGISTERED_ITU_T_T35)
-    {
-      seiProcessingOrderInfo->m_posPrefixByte[i] = m_pcCfg->getPoSEIPrefixByte(i);
-    }
-#endif
   }
+#endif
 }
 
 void SEIEncoder::initSEIPostFilterHint(SEIPostFilterHint *seiPostFilterHint)
-- 
GitLab