From df48aba7d3314f137fdeb417e3af255138efc439 Mon Sep 17 00:00:00 2001
From: Frank Bossen <fbossen@gmail.com>
Date: Wed, 5 Aug 2020 07:47:38 -0400
Subject: [PATCH] Fix #1292: don't check profile/level constraints if none
 defined

---
 source/Lib/CommonLib/ProfileLevelTier.cpp |  4 ++-
 source/Lib/CommonLib/ProfileLevelTier.h   |  2 +-
 source/Lib/DecoderLib/DecLib.cpp          | 34 +++++++++++++++++------
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/source/Lib/CommonLib/ProfileLevelTier.cpp b/source/Lib/CommonLib/ProfileLevelTier.cpp
index d224cbe79..26655578a 100644
--- a/source/Lib/CommonLib/ProfileLevelTier.cpp
+++ b/source/Lib/CommonLib/ProfileLevelTier.cpp
@@ -142,6 +142,8 @@ ProfileLevelTierFeatures::extractPTLInformation(const SPS &sps)
 {
   const ProfileTierLevel &spsPtl =*(sps.getProfileTierLevel());
 
+  m_pProfile = nullptr;
+  m_pLevelTier = nullptr;
   m_tier = spsPtl.getTierFlag();
 
   // Identify the profile from the profile Idc, and possibly other constraints.
@@ -161,7 +163,7 @@ ProfileLevelTierFeatures::extractPTLInformation(const SPS &sps)
     }
   }
 
-  if (m_pProfile != 0)
+  if (m_pProfile != nullptr)
   {
     // Now identify the level:
     const LevelTierFeatures *pLTF = m_pProfile->pLevelTiersListInfo;
diff --git a/source/Lib/CommonLib/ProfileLevelTier.h b/source/Lib/CommonLib/ProfileLevelTier.h
index a7ca27730..907a9f3d1 100644
--- a/source/Lib/CommonLib/ProfileLevelTier.h
+++ b/source/Lib/CommonLib/ProfileLevelTier.h
@@ -96,7 +96,7 @@ class ProfileLevelTierFeatures
     const LevelTierFeatures *m_pLevelTier;
     Level::Tier              m_tier;
   public:
-    ProfileLevelTierFeatures() : m_pProfile(0), m_pLevelTier(0), m_tier(Level::MAIN) { }
+    ProfileLevelTierFeatures() : m_pProfile(nullptr), m_pLevelTier(nullptr), m_tier(Level::MAIN) {}
 
     void extractPTLInformation(const SPS &sps);
 
diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp
index f6ad8a5df..dd7ab3755 100644
--- a/source/Lib/DecoderLib/DecLib.cpp
+++ b/source/Lib/DecoderLib/DecLib.cpp
@@ -1936,16 +1936,34 @@ void DecLib::xCheckParameterSetConstraints(const int layerId)
   }
 
 #if JVET_S0156_LEVEL_DEFINITION
-  ProfileLevelTierFeatures ptlFeature;
-  ptlFeature.extractPTLInformation(*sps);
-  CHECK(pps->getNumTileColumns() > ptlFeature.getLevelTierFeatures()->maxTileCols, "Num tile columns signaled in PPS exceed level limits");
-  CHECK(pps->getNumTiles() > ptlFeature.getLevelTierFeatures()->maxTilesPerAu, "Num tiles signaled in PPS exceed level limits");
+  ProfileLevelTierFeatures ptlFeatures;
+  ptlFeatures.extractPTLInformation(*sps);
 #if JVET_S_PROFILES
-  CHECK(sps->getBitDepth(CHANNEL_TYPE_LUMA) > ptlFeature.getProfileFeatures()->maxBitDepth,
-        "Bit depth exceed profile limit");
-  CHECK(sps->getChromaFormatIdc() > ptlFeature.getProfileFeatures()->maxChromaFormat,
-        "Chroma format exceed profile limit");
+  const ProfileFeatures *profileFeatures = ptlFeatures.getProfileFeatures();
+  if (profileFeatures != nullptr)
+  {
+    CHECK(sps->getBitDepth(CHANNEL_TYPE_LUMA) > profileFeatures->maxBitDepth, "Bit depth exceeds profile limit");
+    CHECK(sps->getChromaFormatIdc() > profileFeatures->maxChromaFormat, "Chroma format exceeds profile limit");
+  }
+  else
+  {
+    CHECK(sps->getProfileTierLevel()->getProfileIdc() != Profile::NONE, "Unknown profile");
+    msg(WARNING, "Warning: Profile set to none or unknown value\n");
+  }
 #endif
+  const LevelTierFeatures *levelTierFeatures = ptlFeatures.getLevelTierFeatures();
+  if (levelTierFeatures != nullptr)
+  {
+    CHECK(pps->getNumTileColumns() > levelTierFeatures->maxTileCols,
+          "Number of tile columns signaled in PPS exceeds level limit");
+    CHECK(pps->getNumTiles() > levelTierFeatures->maxTilesPerAu, "Number of tiles signaled in PPS exceeds level limit");
+  }
+  else if (profileFeatures != nullptr)
+  {
+    CHECK(sps->getProfileTierLevel()->getLevelIdc() == Level::LEVEL15_5, "Cannot use level 15.5 with given profile");
+    CHECK(sps->getProfileTierLevel()->getLevelIdc() != Level::NONE, "Unknown level");
+    msg(WARNING, "Warning: Level set to none, invalid or unknown value\n");
+  }
 #endif
 }
 
-- 
GitLab