Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 547)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 588)
@@ -148,5 +148,5 @@
 #endif
 #if OUTPUT_LAYER_SET_INDEX  
-  this->getCommonDecoderParams()->setOutputLayerSetIdx( olsIdx       );
+  this->getCommonDecoderParams()->setTargetOutputLayerSetIdx( olsIdx       );
   this->getCommonDecoderParams()->setTargetLayerId    ( m_tgtLayerId );
 #endif
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 547)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 588)
@@ -81,5 +81,5 @@
   }
 #if SVC_EXTENSION
-  for( Int i = 0; i < m_tgtLayerId; i++ )
+  for( Int i = 0; i <= m_tgtLayerId; i++ )
   {
     if( m_pchReconFile[i] )
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 547)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 588)
@@ -80,7 +80,4 @@
   {
     m_acLayerCfg[layer].setAppEncCfg(this);
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-    m_ilSampleOnlyPred[layer] = 0;
-#endif
   }
   memset( m_scalabilityMask, 0, sizeof(m_scalabilityMask) );
@@ -146,5 +143,4 @@
 {
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -152,27 +148,15 @@
     {
       delete [] m_acLayerCfg[layer].m_samplePredRefLayerIds;
-    }
-  }
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
+      m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
+    }
     if( m_acLayerCfg[layer].m_numMotionPredRefLayers > 0 )
     {
       delete [] m_acLayerCfg[layer].m_motionPredRefLayerIds;
-    }
-  }
-#else
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
-    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
-    {
-      delete [] m_acLayerCfg[layer].m_refLayerIds;
-    }
-  }
-#endif
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
+      m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
+    }
     if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
     {
       delete [] m_acLayerCfg[layer].m_predLayerIds;
+      m_acLayerCfg[layer].m_predLayerIds = NULL;
     }
   }
@@ -383,5 +367,4 @@
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   Int*    cfg_numSamplePredRefLayers  [MAX_LAYERS];
   string  cfg_samplePredRefLayerIds   [MAX_LAYERS];
@@ -390,9 +373,4 @@
   string  cfg_motionPredRefLayerIds   [MAX_LAYERS];
   string* cfg_motionPredRefLayerIdsPtr[MAX_LAYERS];
-#else
-  Int*    cfg_numDirectRefLayers [MAX_LAYERS];
-  string  cfg_refLayerIds        [MAX_LAYERS];
-  string* cfg_refLayerIdsPtr     [MAX_LAYERS];
-#endif
   Int*    cfg_numActiveRefLayers [MAX_LAYERS];
   string  cfg_predLayerIds       [MAX_LAYERS];
@@ -462,13 +440,8 @@
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
     cfg_numSamplePredRefLayers  [layer] = &m_acLayerCfg[layer].m_numSamplePredRefLayers;
     cfg_samplePredRefLayerIdsPtr[layer] = &cfg_samplePredRefLayerIds[layer];
     cfg_numMotionPredRefLayers  [layer] = &m_acLayerCfg[layer].m_numMotionPredRefLayers;
     cfg_motionPredRefLayerIdsPtr[layer] = &cfg_motionPredRefLayerIds[layer];
-#else
-    cfg_numDirectRefLayers  [layer] = &m_acLayerCfg[layer].m_numDirectRefLayers;
-    cfg_refLayerIdsPtr      [layer]  = &cfg_refLayerIds[layer];
-#endif
     cfg_numActiveRefLayers  [layer] = &m_acLayerCfg[layer].m_numActiveRefLayers;
     cfg_predLayerIdsPtr     [layer]  = &cfg_predLayerIds[layer];
@@ -551,13 +524,8 @@
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   ("NumSamplePredRefLayers%d",cfg_numSamplePredRefLayers, -1, MAX_LAYERS, "Number of sample prediction reference layers")
   ("SamplePredRefLayerIds%d", cfg_samplePredRefLayerIdsPtr, string(""), MAX_LAYERS, "sample pred reference layer IDs")
   ("NumMotionPredRefLayers%d",cfg_numMotionPredRefLayers, -1, MAX_LAYERS, "Number of motion prediction reference layers")
   ("MotionPredRefLayerIds%d", cfg_motionPredRefLayerIdsPtr, string(""), MAX_LAYERS, "motion pred reference layer IDs")
-#else
-  ("NumDirectRefLayers%d",    cfg_numDirectRefLayers, -1, MAX_LAYERS, "Number of direct reference layers")
-  ("RefLayerIds%d",           cfg_refLayerIdsPtr, string(""), MAX_LAYERS, "direct reference layer IDs")
-#endif
   ("NumActiveRefLayers%d",    cfg_numActiveRefLayers, -1, MAX_LAYERS, "Number of active reference layers")
   ("PredLayerIds%d",          cfg_predLayerIdsPtr, string(""), MAX_LAYERS, "inter-layer prediction layer IDs")
@@ -619,5 +587,8 @@
 #endif
 #if N0147_IRAP_ALIGN_FLAG
-    ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" )  
+  ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" )  
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+  ("InterLayerWeightedPred", m_useInterLayerWeightedPred, false, "enable IL WP parameters estimation at encoder" )  
 #endif
 #if AVC_BASE
@@ -629,7 +600,4 @@
 #endif
   ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-  ("IlSampleOnlyPred%d",       m_ilSampleOnlyPred, 0, MAX_LAYERS, "Set inter_layer_sample_pred_only_flag for all slices")
-#endif
 #else //SVC_EXTENSION
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
@@ -956,6 +924,6 @@
   ("SEIGradualDecodingRefreshInfo",  m_gradualDecodingRefreshInfoEnabled,      0, "Control generation of gradual decoding refresh information SEI message")
   ("SEIDecodingUnitInfo",             m_decodingUnitInfoSEIEnabled,                       0, "Control generation of decoding unit information SEI message.")
-#if M0043_LAYERS_PRESENT_SEI
-  ("SEILayersPresent",               m_layersPresentSEIEnabled,                0, "Control generation of layers present SEI message")
+#if LAYERS_NOT_PRESENT_SEI
+  ("SEILayersNotPresent",            m_layersNotPresentSEIEnabled,             0, "Control generation of layers not present SEI message")
 #endif
   ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
@@ -1190,5 +1158,4 @@
   }
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1253,37 +1220,5 @@
     }
   }
-#else
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
-    Char* pRefLayerIds = cfg_refLayerIds[layer].empty() ? NULL: strdup(cfg_refLayerIds[layer].c_str());
-    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
-    {
-      char *refLayerId;
-      int  i=0;
-      m_acLayerCfg[layer].m_refLayerIds = new Int[m_acLayerCfg[layer].m_numDirectRefLayers];
-      refLayerId = strtok(pRefLayerIds, " ,-");
-      while(refLayerId != NULL)
-      {
-        if( i >= m_acLayerCfg[layer].m_numDirectRefLayers )
-        {
-          printf( "NumDirectRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
-          exit( EXIT_FAILURE );
-        }
-        *( m_acLayerCfg[layer].m_refLayerIds + i ) = atoi( refLayerId );
-        refLayerId = strtok(NULL, " ,-");
-        i++;
-      }
-      if( i < m_acLayerCfg[layer].m_numDirectRefLayers )
-      {
-        printf( "NumDirectRefLayers: The width of some columns is not defined.\n" );
-        exit( EXIT_FAILURE );
-      }
-    }
-    else
-    {
-      m_acLayerCfg[layer].m_refLayerIds = NULL;
-    }
-  }
-#endif
+
 #if AUXILIARY_PICTURES
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
@@ -2231,5 +2166,4 @@
   }
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   xConfirmPara( (m_acLayerCfg[0].m_numSamplePredRefLayers != 0) && (m_acLayerCfg[0].m_numSamplePredRefLayers != -1), "Layer 0 cannot have any reference layers" );
   // NOTE: m_numSamplePredRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
@@ -2254,22 +2188,9 @@
     }
   }
-#else
-  xConfirmPara( (m_acLayerCfg[0].m_numDirectRefLayers != 0) && (m_acLayerCfg[0].m_numDirectRefLayers != -1), "Layer 0 cannot have any reference layers" );
-  // NOTE: m_numDirectRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
-  for(Int layer = 1; layer < MAX_LAYERS; layer++)
-  {
-    xConfirmPara(m_acLayerCfg[layer].m_numDirectRefLayers > layer, "Cannot reference more layers than before current layer");
-    for(Int i = 0; i < m_acLayerCfg[layer].m_numDirectRefLayers; i++)
-    {
-      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] > layer, "Cannot reference higher layers");
-      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] == layer, "Cannot reference the current layer itself");
-    }
-  }
-#endif
+
   xConfirmPara( (m_acLayerCfg[0].m_numActiveRefLayers != 0) && (m_acLayerCfg[0].m_numActiveRefLayers != -1), "Layer 0 cannot have any active reference layers" );
   // NOTE: m_numActiveRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
   for(Int layer = 1; layer < MAX_LAYERS; layer++)
   {
-#if M0457_PREDICTION_INDICATIONS
     Bool predEnabledFlag[MAX_LAYERS];
     for (Int refLayer = 0; refLayer < layer; refLayer++)
@@ -2295,13 +2216,6 @@
       xConfirmPara(m_acLayerCfg[layer].m_predLayerIds[i] >= numDirectRefLayers, "Cannot reference higher layers");
     }
-#else
-    xConfirmPara(m_acLayerCfg[layer].m_numActiveRefLayers > m_acLayerCfg[layer].m_numDirectRefLayers, "Cannot reference more layers than NumDirectRefLayers");
-    for(Int i = 0; i < m_acLayerCfg[layer].m_numActiveRefLayers; i++)
-    {
-      xConfirmPara(m_acLayerCfg[layer].m_predLayerIds[i] >= m_acLayerCfg[layer].m_numDirectRefLayers, "Cannot reference higher layers");
-    }
-#endif
-  }
-#endif
+  }
+#endif //VPS_EXTN_DIRECT_REF_LAYERS
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   if (m_adaptiveResolutionChange > 0)
@@ -2435,4 +2349,7 @@
 #if N0147_IRAP_ALIGN_FLAG
   printf("Cross layer IRAP alignment    : %d\n", m_crossLayerIrapAlignFlag );
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+  printf("InterLayerWeightedPred        : %d\n", m_useInterLayerWeightedPred );
 #endif
   for(UInt layer=0; layer<m_numLayers; layer++)
@@ -2581,5 +2498,4 @@
   printf("O0194_DIFFERENT_BITDEPTH_EL_BL: %d ", O0194_DIFFERENT_BITDEPTH_EL_BL);
   printf("O0194_JOINT_US_BITSHIFT: %d ", O0194_JOINT_US_BITSHIFT);
-  printf("O0194_WEIGHTED_PREDICTION_CGS: %d ",O0194_WEIGHTED_PREDICTION_CGS);
 #else
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 547)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 588)
@@ -72,7 +72,4 @@
 #if AVC_SYNTAX
   Char*     m_BLSyntaxFile;                                   ///< input syntax file
-#endif
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-  Int       m_ilSampleOnlyPred[ MAX_LAYERS ];
 #endif
 #if N0120_MAX_TID_REF_CFG
@@ -283,6 +280,6 @@
   Int       m_gradualDecodingRefreshInfoEnabled;
   Int       m_decodingUnitInfoSEIEnabled;
-#if M0043_LAYERS_PRESENT_SEI
-  Int       m_layersPresentSEIEnabled;
+#if LAYERS_NOT_PRESENT_SEI
+  Int       m_layersNotPresentSEIEnabled;
 #endif
   Int       m_SOPDescriptionSEIEnabled;
@@ -384,14 +381,17 @@
 #endif
 #if O0215_PHASE_ALIGNMENT
-  Bool m_phaseAlignFlag;
+  Bool      m_phaseAlignFlag;
 #endif
 #if O0223_PICTURE_TYPES_ALIGN_FLAG
-  Bool m_crossLayerPictureTypeAlignFlag;
+  Bool      m_crossLayerPictureTypeAlignFlag;
 #endif
 #if N0147_IRAP_ALIGN_FLAG
-  Bool m_crossLayerIrapAlignFlag;
+  Bool      m_crossLayerIrapAlignFlag;
 #endif
 #if O0149_CROSS_LAYER_BLA_FLAG
-  bool      m_crossLayerBLAFlag;
+  Bool      m_crossLayerBLAFlag;
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+  Bool      m_useInterLayerWeightedPred;
 #endif
 public:
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 547)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 588)
@@ -48,13 +48,8 @@
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   Int       *m_samplePredRefLayerIds;
   Int       m_numSamplePredRefLayers;
   Int       *m_motionPredRefLayerIds;
   Int       m_numMotionPredRefLayers;
-#else
-  Int       *m_refLayerIds;
-  Int       m_numDirectRefLayers;
-#endif
   Int       *m_predLayerIds;
   Int       m_numActiveRefLayers;
@@ -153,5 +148,4 @@
   Int*    getdQPs()                   {return m_aidQP;            }
 #if VPS_EXTN_DIRECT_REF_LAYERS
-#if M0457_PREDICTION_INDICATIONS
   Int     getNumSamplePredRefLayers()    {return m_numSamplePredRefLayers;   }
   Int*    getSamplePredRefLayerIds()     {return m_samplePredRefLayerIds;    }
@@ -160,9 +154,4 @@
   Int*    getMotionPredRefLayerIds()     {return m_motionPredRefLayerIds;    }
   Int     getMotionPredRefLayerId(Int i) {return m_motionPredRefLayerIds[i]; }
-#else
-  Int     getNumDirectRefLayers()     {return m_numDirectRefLayers;}
-  Int*    getRefLayerIds()            {return m_refLayerIds;      }
-  Int     getRefLayerId(Int i)        {return m_refLayerIds[i];   }
-#endif
 
   Int     getNumActiveRefLayers()     {return m_numActiveRefLayers;}
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 547)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 588)
@@ -177,4 +177,5 @@
   delete [] mapIdxToLayer;
 #endif
+
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
@@ -190,4 +191,8 @@
     g_bitDepthYLayer[layer] = g_bitDepthY;
     g_bitDepthCLayer[layer] = g_bitDepthC;
+
+#if O0194_WEIGHTED_PREDICTION_CGS
+    m_acTEncTop[layer].setInterLayerWeightedPredFlag( m_useInterLayerWeightedPred );
+#endif
 #endif
     //m_acTEncTop[layer].setVPS(&vps);
@@ -209,18 +214,7 @@
 #if REF_IDX_MFM
 #if AVC_BASE
-#if M0457_PREDICTION_INDICATIONS
     m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
 #else
-    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ));
-#endif
-#else
-#if M0457_PREDICTION_INDICATIONS
     m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_acLayerCfg[layer].getNumMotionPredRefLayers() > 0 ) );
-#else
-    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : true);
-#endif
-#endif
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-    m_acTEncTop[layer].setIlSampleOnlyPred( layer == 0 ? 0 : m_ilSampleOnlyPred[layer] );
 #endif
 #endif
@@ -261,5 +255,4 @@
     if(layer)
     {
-#if M0457_PREDICTION_INDICATIONS
       for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
       {
@@ -309,27 +302,8 @@
       }
       m_acTEncTop[layer].setNumDirectRefLayers(numDirectRefLayers);
-#else
-      if(m_acLayerCfg[layer].getNumDirectRefLayers() == -1)
-      {
-        // Not included in the configuration file; assume that each layer depends on previous layer
-        m_acTEncTop[layer].setNumDirectRefLayers       (1);      // One ref. layer
-        m_acTEncTop[layer].setRefLayerId               (0, layer - 1);   // Previous layer
-      }
-      else
-      {
-        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );
-        for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
-        {
-          m_acTEncTop[layer].setRefLayerId             ( i, m_acLayerCfg[layer].getRefLayerId(i));
-        }
-      }
-#endif
+
       if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
       {
-#if M0457_PREDICTION_INDICATIONS
         m_acTEncTop[layer].setNumActiveRefLayers( m_acTEncTop[layer].getNumDirectRefLayers() );
-#else
-        m_acTEncTop[layer].setNumActiveRefLayers( m_acLayerCfg[layer].getNumDirectRefLayers() );
-#endif
         for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
         {
@@ -346,5 +320,5 @@
       }
     }
-#endif
+#endif //VPS_EXTN_DIRECT_REF_LAYERS
     //===== Slice ========
 
@@ -426,5 +400,5 @@
     m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
 #if O0194_WEIGHTED_PREDICTION_CGS
-    if (layer!=0)
+    if( layer != 0 && m_useInterLayerWeightedPred )
     {
       // Enable weighted prediction for enhancement layer
@@ -514,6 +488,6 @@
     m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
     m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
-#if M0043_LAYERS_PRESENT_SEI
-    m_acTEncTop[layer].setLayersPresentSEIEnabled( m_layersPresentSEIEnabled );
+#if LAYERS_NOT_PRESENT_SEI
+    m_acTEncTop[layer].setLayersNotPresentSEIEnabled( m_layersNotPresentSEIEnabled );
 #endif
     m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
@@ -828,6 +802,6 @@
   m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
   m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
-#if M0043_LAYERS_PRESENT_SEI
-  m_cTEncTop.setLayersPresentSEIEnabled( m_layersPresentSEIEnabled );
+#if LAYERS_NOT_PRESENT_SEI
+  m_cTEncTop.setLayersNotPresentSEIEnabled( m_layersNotPresentSEIEnabled );
 #endif
   m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
@@ -1171,8 +1145,12 @@
   vps->setNumOutputLayerSets(vps->getNumLayerSets());
   vps->setNumProfileTierLevel(vps->getNumLayerSets());
+#if P0295_DEFAULT_OUT_LAYER_IDC
+  vps->setDefaultTargetOutputLayerIdc(1);
+#else
 #if O0109_DEFAULT_ONE_OUT_LAYER_IDC
   vps->setDefaultOneTargetOutputLayerIdc(1);
 #else
   vps->setDefaultOneTargetOutputLayerFlag(true);
+#endif
 #endif
   for(i = 1; i < vps->getNumLayerSets(); i++)
@@ -1199,52 +1177,47 @@
   vps->deriveLayerIdListVariables();
 #endif
+#if RESOLUTION_BASED_DPB
+  vps->assignSubDpbIndices();
+#else
   vps->deriveNumberOfSubDpbs();
+#endif
   // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
   for(i = 1; i < vps->getNumOutputLayerSets(); i++)
   {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
     Int layerSetId = vps->getOutputLayerSetIdx(i);
 
-    // For each output layer set, set the DPB size for each layer and the reorder/latency value the maximum for all layers
-    Bool checkFlagOuter = false;      // Used to calculate sub_layer_flag_info_present_flag
-    Bool checkFlagInner[MAX_TLAYER];  // Used to calculate sub_layer_dpb_info_present_flag
-
     for(Int j = 0; j < vps->getMaxTLayers(); j++)
     {
 
       Int maxNumReorderPics = -1;
+#if CHANGE_NUMSUBDPB_IDX
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
+#else
+      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#endif
+#else
       for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+#endif
       {
         Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
+#if RESOLUTION_BASED_DPB
+        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
+        // at the encoder, modify below
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j );
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
+#else
         vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+#endif
         maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
       }
       vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
-      
-      if( j == 0 )  // checkFlagInner[0] is always 1
-      {
-        checkFlagInner[j] = true;     // Always signal sub-layer DPB information for the first sub-layer
-      }
-      else
-      {
-        checkFlagInner[j] = false;    // Initialize to be false. If the values of the current sub-layers matches with the earlier sub-layer, 
-                                      // then will be continue to be false - i.e. the j-th sub-layer DPB info is not signaled
-        checkFlagInner[j] |= ( maxNumReorderPics != vps->getMaxVpsNumReorderPics(i, j - 1) );
-        for(Int k = 0; k < vps->getNumSubDpbs(i) && !checkFlagInner[j]; k++)  // If checkFlagInner[j] is true, break and signal the values
-        {
-          checkFlagInner[j] |= ( vps->getMaxVpsDecPicBufferingMinus1(i, k, j - 1) != vps->getMaxVpsDecPicBufferingMinus1(i, k, j) );
-        }
-      }
-      // If checkFlagInner[j] = true, then some value needs to be signalled for the j-th sub-layer
-      vps->setSubLayerDpbInfoPresentFlag( i, j, checkFlagInner[j] );
-    }
-    for(Int j = 1; j < vps->getMaxTLayers(); j++) // Check if DPB info of any of non-zero sub-layers is signaled. If so set flag to one
-    {
-      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )
-      {
-        checkFlagOuter = true;
-        break;
-      }
-    }
-    vps->setSubLayerFlagInfoPresentFlag( i, checkFlagOuter );
+      vps->determineSubDpbInfoFlags();
+    }
   }
 #endif
@@ -1274,5 +1247,5 @@
       vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
     }
-#if M0457_PREDICTION_INDICATIONS
+    // prediction indications
     vps->setDirectDepTypeLen(2); // sample and motion types are encoded
     for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
@@ -1301,5 +1274,4 @@
       }
     }
-#endif
   }
 
@@ -1318,7 +1290,5 @@
 #endif
 #endif
-#if JCTVC_M0458_INTERLAYER_RPS_SIG
     vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
-#endif
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
     for(i = 1; i< vps->getMaxLayers(); i++)
@@ -1361,8 +1331,10 @@
   vps->setHigherLayerIrapSkipFlag(m_skipPictureAtArcSwitch);
 #endif
+#if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
 #if !VPS_EXTN_OFFSET_CALC
 #if VPS_EXTN_OFFSET
   // to be updated according to the current semantics
   vps->setExtensionOffset( 0xffff );
+#endif
 #endif
 #endif
@@ -1653,4 +1625,15 @@
     if(iTotalNumEncoded)
     {
+#if P0130_EOB
+      if( bEos )
+      {
+        OutputNALUnit nalu(NAL_UNIT_EOB);
+        nalu.m_layerId = 0;
+
+        AccessUnit& accessUnit = outputAccessUnits.back();
+        nalu.m_temporalId = accessUnit.front()->m_temporalId;
+        accessUnit.push_back(new NALUnitEBSP(nalu));
+      }
+#endif
       xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
       outputAccessUnits.clear();
