From 337d7f3718c858458144281d8980b8ce0684e0d4 Mon Sep 17 00:00:00 2001
From: Xiang Li <xlxiangli@tencent.com>
Date: Mon, 25 Oct 2021 14:51:26 -0700
Subject: [PATCH] remove macro JVET_S0154_ASPECT9_AND_S0158_ASPECT4

---
 .../BitstreamExtractorApp.cpp                 | 111 ------------------
 .../BitstreamExtractorApp.h                   |   8 --
 source/Lib/CommonLib/TypeDef.h                |   1 -
 3 files changed, 120 deletions(-)

diff --git a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp
index a7912aa06..06b210656 100644
--- a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp
+++ b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp
@@ -172,7 +172,6 @@ bool BitstreamExtractorApp::xCheckSliceSubpicture(InputNALUnit &nalu, int target
 }
 #endif
 
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
 bool BitstreamExtractorApp::xCheckSEIFiller(SEIMessages SEIs, int targetSubPicId, bool &rmAllFillerInSubpicExt, bool lastSliceWritten)
 {
   for (auto sei : SEIs)
@@ -195,78 +194,6 @@ bool BitstreamExtractorApp::xCheckSEIFiller(SEIMessages SEIs, int targetSubPicId
   }
   return true;
 }
-#else
-bool BitstreamExtractorApp::xCheckSeiSubpicture(SEIMessages SEIs, int targetSubPicId, bool &rmAllFillerInSubpicExt, bool lastSliceWritten, bool isVclNalUnitRemoved)
-{
-  bool isWriteSeiNalUnitToStream = true;
-
-  for (auto sei : SEIs)
-  {
-    if (sei->payloadType() == SEI::SUBPICTURE_LEVEL_INFO)
-    {
-      SEISubpicureLevelInfo *seiSLI = (SEISubpicureLevelInfo *)sei;
-      if (!seiSLI->m_cbrConstraintFlag)
-      {
-        rmAllFillerInSubpicExt = true;
-      }
-    }
-  }
-  for (auto sei : SEIs)
-  {
-    if (sei->payloadType() == SEI::FILLER_PAYLOAD)
-    {
-      isWriteSeiNalUnitToStream = rmAllFillerInSubpicExt ? false : lastSliceWritten;
-      break;
-    }
-  }
-
-  if (isWriteSeiNalUnitToStream)
-  {
-    for (auto sei : SEIs)
-    {
-      if (sei->payloadType() == SEI::SCALABLE_NESTING)
-      {
-        SEIScalableNesting *seiNesting = (SEIScalableNesting *)sei;
-        if (seiNesting->m_snOlsFlag == 1)
-        {
-          bool targetSubpicFound = false;
-          for (uint32_t i = 0; i < seiNesting->m_snNumSubpics; i++)
-          {
-            if (seiNesting->m_snSubpicId[i] == targetSubPicId)
-            {
-              targetSubpicFound = true;
-              break;
-            }
-          }
-          isWriteSeiNalUnitToStream &= targetSubpicFound;
-        }
-      }
-      if (!isWriteSeiNalUnitToStream)
-      {
-        break;
-      }
-    }
-  }
-
-  if (isWriteSeiNalUnitToStream && isVclNalUnitRemoved)
-  {
-    for (auto sei : SEIs)
-    {
-      if (sei->payloadType() == SEI::SCALABLE_NESTING)
-      {
-        SEIScalableNesting *seiNesting = (SEIScalableNesting *)sei;
-        if (!seiNesting->m_snSubpicFlag)
-        {
-          isWriteSeiNalUnitToStream = false;
-          break;
-        }
-      }
-    }
-  }
-
-  return isWriteSeiNalUnitToStream;
-}
-#endif
 
 void BitstreamExtractorApp::xRewriteSPS (SPS &targetSPS, const SPS &sourceSPS, SubPic &subPic)
 {
@@ -545,11 +472,7 @@ bool BitstreamExtractorApp::xCheckNumSubLayers(InputNALUnit &nalu, VPS *vps)
   return retval;
 }
 
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
 bool BitstreamExtractorApp::xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit& nalu, std::ostream& out, int subpicId, VPS *vps)
-#else
-bool BitstreamExtractorApp::xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit& nalu, std::ostream& out, int subpicId)
-#endif
 {
   SEIMessages scalableNestingSEIs = getSeisByType(SEIs, SEI::SCALABLE_NESTING);
   if (scalableNestingSEIs.size())
@@ -566,20 +489,16 @@ bool BitstreamExtractorApp::xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit
     }
     if (std::find(sei->m_snSubpicId.begin(), sei->m_snSubpicId.end(), subpicId) != sei->m_snSubpicId.end())
     {
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
       // C.7 step 7.c
       if (sei->m_snOlsFlag || vps->getNumLayersInOls(m_targetOlsIdx) == 1)
       {
-#endif
         // applies to target subpicture -> extract
         OutputNALUnit outNalu( nalu.m_nalUnitType, nalu.m_nuhLayerId, nalu.m_temporalId );
         m_seiWriter.writeSEImessages(outNalu.m_Bitstream, sei->m_nestedSEIs, m_hrd, false, nalu.m_temporalId);
         NALUnitEBSP naluWithHeader(outNalu);
         writeAnnexBNalUnit(out, naluWithHeader, true);
         return false;
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
       }
-#endif
     }
     else
     {
@@ -598,7 +517,6 @@ bool BitstreamExtractorApp::xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit
 }
 
 
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
 bool BitstreamExtractorApp::xIsTargetOlsIncludeAllVclLayers()
 {
   std::ifstream bitstreamFileIn(m_bitstreamFileNameIn.c_str(), std::ifstream::in | std::ifstream::binary);
@@ -676,7 +594,6 @@ bool BitstreamExtractorApp::xIsTargetOlsIncludeAllVclLayers()
   }
   return true;
 }
-#endif
 
 uint32_t BitstreamExtractorApp::decode()
 {
@@ -709,9 +626,7 @@ uint32_t BitstreamExtractorApp::decode()
   bool isMultiSubpicLayer[MAX_VPS_LAYERS] = { false };
   bool rmAllFillerInSubpicExt[MAX_VPS_LAYERS] = { false };
 
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
   bool targetOlsIncludeAllVclLayers = xIsTargetOlsIncludeAllVclLayers();
-#endif
 
   while (!!bitstreamFileIn)
   {
@@ -945,7 +860,6 @@ uint32_t BitstreamExtractorApp::decode()
                 }
                 writeInpuNalUnitToStream &= targetOlsIdxInNestingAppliedOls;
               }
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
               // C.6 step 9.c
               if (writeInpuNalUnitToStream && !targetOlsIncludeAllVclLayers && !seiNesting->m_snSubpicFlag)
               {
@@ -958,42 +872,23 @@ uint32_t BitstreamExtractorApp::decode()
                   writeInpuNalUnitToStream = false;
                 }
               }
-#endif
             }
             // remove unqualified timing related SEI
             if (sei->payloadType() == SEI::BUFFERING_PERIOD || (m_removeTimingSEI && sei->payloadType() == SEI::PICTURE_TIMING) || sei->payloadType() == SEI::DECODING_UNIT_INFO || sei->payloadType() == SEI::SUBPICTURE_LEVEL_INFO)
             {
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
               writeInpuNalUnitToStream &= targetOlsIncludeAllVclLayers;
-#else
-              bool targetOlsIdxGreaterThanZero = m_targetOlsIdx > 0;
-              writeInpuNalUnitToStream &= !targetOlsIdxGreaterThanZero;
-#endif
             }
           }
-#if !JVET_S0154_ASPECT9_AND_S0158_ASPECT4
-          if (m_subPicIdx >= 0 && writeInpuNalUnitToStream)
-          {
-            writeInpuNalUnitToStream = xCheckSeiSubpicture(SEIs, subpicIdTarget[nalu.m_nuhLayerId], rmAllFillerInSubpicExt[nalu.m_nuhLayerId], lastSliceWritten, isVclNalUnitRemoved[nalu.m_nuhLayerId]);
-          }
-#endif
           if (m_vpsId == -1)
           {
             delete vps;
           }
         }
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
         writeInpuNalUnitToStream &= xCheckSEIFiller(SEIs, subpicIdTarget[nalu.m_nuhLayerId], rmAllFillerInSubpicExt[nalu.m_nuhLayerId], lastSliceWritten);
         if (writeInpuNalUnitToStream && isVclNalUnitRemoved[nalu.m_nuhLayerId] && m_subPicIdx >= 0)
         {
           writeInpuNalUnitToStream &= xCheckSEIsSubPicture(SEIs, nalu, bitstreamFileOut, subpicIdTarget[nalu.m_nuhLayerId], vps);
         }
-#else
-        if (m_subPicIdx >= 0)
-        {
-          writeInpuNalUnitToStream &= xCheckSEIsSubPicture(SEIs, nalu, bitstreamFileOut, subpicIdTarget[nalu.m_nuhLayerId]);
-        }
-#endif
       }
 
 #if JVET_R0107_BITSTREAM_EXTACTION
@@ -1003,15 +898,9 @@ uint32_t BitstreamExtractorApp::decode()
          slice = xParseSliceHeader(nalu);
       }
 #endif
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
       if (isMultiSubpicLayer[nalu.m_nuhLayerId] && writeInpuNalUnitToStream)
       {
         if (m_subPicIdx >= 0 && nalu.isSlice())
-#else
-      if (m_subPicIdx >= 0 && isMultiSubpicLayer[nalu.m_nuhLayerId] && writeInpuNalUnitToStream)
-      {
-        if (nalu.isSlice())
-#endif
         {
           writeInpuNalUnitToStream = xCheckSliceSubpicture(slice, subpicIdTarget[nalu.m_nuhLayerId]);
           if (!writeInpuNalUnitToStream)
diff --git a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.h b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.h
index 996348d1e..5cbdbc8ed 100644
--- a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.h
+++ b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.h
@@ -65,11 +65,7 @@ protected:
   void xPrintSubPicInfo (PPS *pps);
   void xRewriteSPS (SPS &targetSPS, const SPS &sourceSPS, SubPic &subPic);
   void xRewritePPS (PPS &targetPPS, const PPS &sourcePPS, const SPS &sourceSPS, SubPic &subPic);
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
   bool xCheckSEIFiller(SEIMessages SEIs, int targetSubPicId, bool &rmAllFillerInSubpicExt, bool lastSliceWritten);
-#else
-  bool xCheckSeiSubpicture(SEIMessages SEIs, int targetSubPicId, bool &rmAllFillerInSubpicExt, bool lastSliceWritten, bool isVclNalUnitRemoved);
-#endif
 
 #if JVET_R0107_BITSTREAM_EXTACTION
   Slice xParseSliceHeader(InputNALUnit &nalu);
@@ -78,12 +74,8 @@ protected:
   bool xCheckSliceSubpicture(InputNALUnit &nalu, int subPicId);
 #endif
   void xReadPicHeader(InputNALUnit &nalu);
-#if JVET_S0154_ASPECT9_AND_S0158_ASPECT4
   bool xIsTargetOlsIncludeAllVclLayers();
   bool xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit& nalu, std::ostream& out, int subpicId, VPS *vps);
-#else
-  bool xCheckSEIsSubPicture(SEIMessages& SEIs, InputNALUnit& nalu, std::ostream& out, int subpicId);
-#endif
 
   void xSetSPSUpdated(int spsId)   { return m_updatedSPSList.push_back(spsId); }
   bool xIsSPSUpdate(int spsId)     { return (std::find(m_updatedSPSList.begin(),m_updatedSPSList.end(), spsId) != m_updatedSPSList.end()); }
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index d6494313c..cd39c0d44 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -64,7 +64,6 @@
 
 
 
-#define JVET_S0154_ASPECT9_AND_S0158_ASPECT4              1 // JVET-S0154 #9:  In the subpicture sub-bitstream extraction process, insert SEI NAL units to directly contain those SEI messages that were scalable-nested HRD-related SEI messages that apply to the output bitstream, and remove their original container SEI NAL units from the output bitstream. When the target OLS includes only one layer, apply the same for scalable-nested non-HRD-related SEI messages.
                                                             // JVET-S0158 #4c: Insert SEI NAL units to directly contain those SEI messages that were scalable-nested HRD-related SEI messages that apply to the output bitstream, and remove their original container SEI NAL units from the output bitstream. When the target OLS includes only one layer, apply the same for scalable-nested non-HRD-related SEI messages.
 
 #define JVET_S0117_VB                                     1 // sub-picture extraction VB rewriting
-- 
GitLab