From 7a2dc6ef3f4a037205c308201f4252ff92a0254e Mon Sep 17 00:00:00 2001
From: rickxu <lidong.xu@intel.com>
Date: Wed, 12 Jun 2019 09:46:11 +0800
Subject: [PATCH] N0276: add the subprofile syntax

---
 doc/software-manual.tex             | 6 ++++++
 source/App/EncoderApp/EncApp.cpp    | 3 +++
 source/App/EncoderApp/EncAppCfg.cpp | 3 +++
 source/App/EncoderApp/EncAppCfg.h   | 3 +++
 source/Lib/CommonLib/Slice.cpp      | 6 ++++++
 source/Lib/CommonLib/Slice.h        | 8 ++++++++
 source/Lib/DecoderLib/VLCReader.cpp | 3 +++
 source/Lib/EncoderLib/EncCfg.h      | 6 ++++++
 source/Lib/EncoderLib/EncLib.cpp    | 6 ++++++
 source/Lib/EncoderLib/VLCWriter.cpp | 4 ++++
 10 files changed, 48 insertions(+)

diff --git a/doc/software-manual.tex b/doc/software-manual.tex
index 27957a7f0..a2d25b91f 100644
--- a/doc/software-manual.tex
+++ b/doc/software-manual.tex
@@ -983,6 +983,12 @@ Valid values are: main, high.
 NB: There is currently only limited validation that the encoder configuration complies with the profile, level and tier constraints.
 \\
 
+\Option{SubProfile} &
+%\ShortOption{\None} &
+\Default{0} &
+Indicates interoperability metadata registered as specified by X Recommendation ITU-T T.35.
+\\
+
 \Option{EnableDecodingParameterSet} &
 %\ShortOption{\None} &
 \Default{false} &
diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index 0ef331086..bfa865126 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -88,6 +88,9 @@ void EncApp::xInitLibCfg()
 #endif
   m_cEncLib.setProfile                                           ( m_profile);
   m_cEncLib.setLevel                                             ( m_levelTier, m_level);
+#if JVET_N0276_CONSTRAINT_FLAGS
+  m_cEncLib.setSubProfile                                        ( m_subProfile );
+#endif
   m_cEncLib.setProgressiveSourceFlag                             ( m_progressiveSourceFlag);
   m_cEncLib.setInterlacedSourceFlag                              ( m_interlacedSourceFlag);
   m_cEncLib.setNonPackedConstraintFlag                           ( m_nonPackedConstraintFlag);
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index d2e1baac1..ccfd68e26 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -861,6 +861,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   ("Profile",                                         extendedProfile,                                   NONE, "Profile name to use for encoding. Use main (for main), main10 (for main10), main-still-picture, main-RExt (for Range Extensions profile), any of the RExt specific profile names, or none")
   ("Level",                                           m_level,                                    Level::NONE, "Level limit to be used, eg 5.1, or none")
   ("Tier",                                            m_levelTier,                                Level::MAIN, "Tier to use for interpretation of --Level (main or high only)")
+#if JVET_N0276_CONSTRAINT_FLAGS
+  ("SubProfile",                                      m_subProfile,                                        0u, "Sub-profile idc")
+#endif
   ("EnableDecodingParameterSet",                      m_decodingParameterSetEnabled,                    false, "Enables writing of Decoding Parameter Set")
   ("MaxBitDepthConstraint",                           m_bitDepthConstraint,                                0u, "Bit depth to use for profile-constraint for RExt profiles. 0=automatically choose based upon other parameters")
   ("MaxChromaFormatConstraint",                       tmpConstraintChromaFormat,                            0, "Chroma-format to use for the profile-constraint for RExt profiles. 0=automatically choose based upon other parameters")
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index ca9e4ebd1..3845bb4c0 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -166,6 +166,9 @@ protected:
   Profile::Name m_profile;
   Level::Tier   m_levelTier;
   Level::Name   m_level;
+#if JVET_N0276_CONSTRAINT_FLAGS
+  uint32_t      m_subProfile;
+#endif
   uint32_t          m_bitDepthConstraint;
   ChromaFormat  m_chromaFormatConstraint;
   bool          m_intraConstraintFlag;
diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp
index e043b54ec..503a0780b 100644
--- a/source/Lib/CommonLib/Slice.cpp
+++ b/source/Lib/CommonLib/Slice.cpp
@@ -2752,6 +2752,9 @@ ProfileTierLevel::ProfileTierLevel()
   : m_profileSpace    (0)
   , m_tierFlag        (Level::MAIN)
   , m_profileIdc      (Profile::NONE)
+#if JVET_N0276_CONSTRAINT_FLAGS
+  , m_subProfileIdc   (0)
+#endif
   , m_levelIdc        (Level::NONE)
   , m_progressiveSourceFlag  (false)
   , m_interlacedSourceFlag   (false)
@@ -2770,6 +2773,9 @@ PTL::PTL()
 ProfileTierLevel::ProfileTierLevel()
   : m_tierFlag        (Level::MAIN)
   , m_profileIdc      (Profile::NONE)
+#if JVET_N0276_CONSTRAINT_FLAGS
+  , m_subProfileIdc   (0)
+#endif
   , m_levelIdc        (Level::NONE)
 {
   ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index dbf268b56..978d223b4 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -402,6 +402,9 @@ class ProfileTierLevel
   Profile::Name     m_profileIdc;
 #if !JVET_M0101_HLS
   bool              m_profileCompatibilityFlag[32];
+#endif
+#if JVET_N0276_CONSTRAINT_FLAGS
+  uint32_t          m_subProfileIdc;
 #endif
   Level::Name       m_levelIdc;
 
@@ -434,6 +437,11 @@ public:
   Profile::Name getProfileIdc() const                       { return m_profileIdc;                  }
   void          setProfileIdc(Profile::Name x)              { m_profileIdc = x;                     }
 
+#if JVET_N0276_CONSTRAINT_FLAGS
+  uint32_t      getSubProfileIdc() const                    { return m_subProfileIdc;               }
+  void          setSubProfileIdc(uint32_t x)                { m_subProfileIdc = x;                  }
+#endif
+
 #if !JVET_M0101_HLS
   bool          getProfileCompatibilityFlag(int i) const    { return m_profileCompatibilityFlag[i]; }
   void          setProfileCompatibilityFlag(int i, bool x)  { m_profileCompatibilityFlag[i] = x;    }
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index bf9f08289..b4c43fb88 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -2557,6 +2557,9 @@ void HLSyntaxReader::parseProfileTierLevel(ProfileTierLevel *ptl, int maxNumSubL
   uint32_t symbol;
   READ_CODE(7 , symbol,   "general_profile_idc"              ); ptl->setProfileIdc  (Profile::Name(symbol));
   READ_FLAG(    symbol,   "general_tier_flag"                ); ptl->setTierFlag    (symbol ? Level::HIGH : Level::MAIN);
+#if JVET_N0276_CONSTRAINT_FLAGS
+  READ_CODE(24 , symbol,   "general_sub_profile_idc"         ); ptl->setSubProfileIdc  (symbol);
+#endif
 
   parseConstraintInfo( ptl->getConstraintInfo() );
 
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index 1274fb042..68134e2c6 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -208,6 +208,9 @@ protected:
   Profile::Name m_profile;
   Level::Tier   m_levelTier;
   Level::Name   m_level;
+#if JVET_N0276_CONSTRAINT_FLAGS
+  uint32_t      m_subProfile;
+#endif
   bool m_progressiveSourceFlag;
   bool m_interlacedSourceFlag;
   bool m_nonPackedConstraintFlag;
@@ -704,6 +707,9 @@ public:
 
   void setProfile(Profile::Name profile) { m_profile = profile; }
   void setLevel(Level::Tier tier, Level::Name level) { m_levelTier = tier; m_level = level; }
+#if JVET_N0276_CONSTRAINT_FLAGS
+  void setSubProfile(uint32_t subProfile) { m_subProfile = subProfile; }
+#endif
 
   bool      getIntraOnlyConstraintFlag() const { return m_bIntraOnlyConstraintFlag; }
   void      setIntraOnlyConstraintFlag(bool bVal) { m_bIntraOnlyConstraintFlag = bVal; }
diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index 2b1f40655..4dea49e55 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -951,6 +951,9 @@ void EncLib::xInitSPS(SPS &sps)
   profileTierLevel.setLevelIdc                    (m_level);
   profileTierLevel.setTierFlag                    (m_levelTier);
   profileTierLevel.setProfileIdc                  (m_profile);
+#if JVET_N0276_CONSTRAINT_FLAGS
+  profileTierLevel.setSubProfileIdc               (m_subProfile);
+#endif
   profileTierLevel.setProfileCompatibilityFlag    (m_profile, 1);
   profileTierLevel.setProgressiveSourceFlag       (m_progressiveSourceFlag);
   profileTierLevel.setInterlacedSourceFlag        (m_interlacedSourceFlag);
@@ -1026,6 +1029,9 @@ void EncLib::xInitSPS(SPS &sps)
   profileTierLevel->setLevelIdc                    (m_level);
   profileTierLevel->setTierFlag                    (m_levelTier);
   profileTierLevel->setProfileIdc                  (m_profile);
+#if JVET_N0276_CONSTRAINT_FLAGS
+  profileTierLevel->setSubProfileIdc               (m_subProfile);
+#endif
 
 #endif
   /* XXX: should Main be marked as compatible with still picture? */
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 94a3729fa..b57fbc86c 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -1813,6 +1813,9 @@ void  HLSWriter::codeProfileTierLevel    ( const ProfileTierLevel* ptl, int maxN
 {
   WRITE_CODE( int(ptl->getProfileIdc()), 7 ,   "general_profile_idc"                     );
   WRITE_FLAG( ptl->getTierFlag()==Level::HIGH, "general_tier_flag"                       );
+#if JVET_N0276_CONSTRAINT_FLAGS
+  WRITE_CODE( ptl->getSubProfileIdc(), 24,      "general_sub_profile_idc"                );
+#endif
 
   codeConstraintInfo(ptl->getConstraintInfo());
 
@@ -1884,6 +1887,7 @@ void HLSWriter::codeProfileTier( const ProfileTierLevel* ptl, const bool /*bIsSu
 {
   WRITE_CODE( ptl->getProfileSpace(), 2 ,      PTL_TRACE_TEXT("profile_space"                   ));
   WRITE_FLAG( ptl->getTierFlag()==Level::HIGH, PTL_TRACE_TEXT("tier_flag"                       ));
+
   WRITE_CODE( int(ptl->getProfileIdc()), 5 ,   PTL_TRACE_TEXT("profile_idc"                     ));
   for(int j = 0; j < 32; j++)
   {
-- 
GitLab