From cadb82eac69dc18701beb855a96317c0a1f746cd Mon Sep 17 00:00:00 2001
From: vdrugeon <virginie.drugeon@eu.panasonic.com>
Date: Thu, 27 Aug 2020 15:56:38 +0000
Subject: [PATCH] JVET-S0097: set default values in VPS

Set default values when the bitstream does not contain any VPS
---
 source/Lib/CommonLib/TypeDef.h   |  2 ++
 source/Lib/DecoderLib/DecLib.cpp | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index b0cd204e3d..ffa67a5935 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -67,6 +67,8 @@
 #define JVET_S_SUB_PROFILE                                1 // Move signalling of ptl_num_sub_profiles
 
 #define JVET_R0324_REORDER                                1 // Reordering of syntax elements JVET-R0324/JVET-R2001-v2
+ 
+#define JVET_S0097_VPS_default_values                     1 // JVET-S0097: infer values of variables in VPS when not present
 
 #define JVET_S0219_ASPECT2_CHANGE_ORDER_APS_PARAMS_TYPE   1 // JVET-S0219 aspect2: change the order to put the aps_params_type before the aps_adaptation_parameter_set_id.
 
diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp
index 2f3b8d5380..c9e219b134 100644
--- a/source/Lib/DecoderLib/DecLib.cpp
+++ b/source/Lib/DecoderLib/DecLib.cpp
@@ -1534,6 +1534,20 @@ void DecLib::xActivateParameterSets( const InputNALUnit nalu )
 
     // update the stored VPS to the actually referred to VPS
     m_vps = m_parameterSetManager.getVPS(sps->getVPSId());
+#if JVET_S0097_VPS_default_values
+    if(sps->getVPSId() == 0)
+    {
+      //No VPS in bitstream: set defaults values of variables in VPS to the ones signalled in SPS
+      m_vps->setMaxSubLayers( sps->getMaxTLayers() );
+      m_vps->setLayerId( 0, sps->getLayerId() );
+      m_vps->deriveOutputLayerSets(); 
+    }
+    else
+    {
+      //VPS in the bitstream: check that SPS and VPS signalling are compatible
+      CHECK(sps->getMaxTLayers() > m_vps->getMaxSubLayers(), "The SPS signals more temporal sub-layers than allowed by the VPS");
+    }
+#endif
 
     m_parameterSetManager.getApsMap()->clearActive();
     for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++)
-- 
GitLab