Index: /branches/SHM-5.0-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-5.0-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 578)
+++ /branches/SHM-5.0-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 579)
@@ -1181,4 +1181,7 @@
   for(i = 1; i < vps->getNumOutputLayerSets(); i++)
   {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
     Int layerSetId = vps->getOutputLayerSetIdx(i);
 
@@ -1191,5 +1194,9 @@
 
       Int maxNumReorderPics = -1;
+#if CHANGE_NUMSUBDPB_IDX
+      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#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
@@ -1208,5 +1215,9 @@
                                       // 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) );
+#if CHANGE_NUMSUBDPB_IDX
+        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) && !checkFlagInner[j]; k++)  // If checkFlagInner[j] is true, break and signal the values
+#else
         for(Int k = 0; k < vps->getNumSubDpbs(i) && !checkFlagInner[j]; k++)  // If checkFlagInner[j] is true, break and signal the values
+#endif
         {
           checkFlagInner[j] |= ( vps->getMaxVpsDecPicBufferingMinus1(i, k, j - 1) != vps->getMaxVpsDecPicBufferingMinus1(i, k, j) );
Index: /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 578)
+++ /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 579)
@@ -2186,4 +2186,13 @@
 {
   // Derive number of sub-DPBs
+#if CHANGE_NUMSUBDPB_IDX
+  // For layer set 0
+  setNumSubDpbs(0, 1);
+  // For other layer sets
+  for( Int i = 1; i < getNumLayerSets(); i++)
+  {
+    setNumSubDpbs( i, getNumLayersInIdList( i ) );
+  }
+#else
   // For output layer set 0
   setNumSubDpbs(0, 1);
@@ -2193,4 +2202,5 @@
     setNumSubDpbs( i, getNumLayersInIdList( getOutputLayerSetIdx(i)) );
   }
+#endif
 }
 #endif
Index: /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 578)
+++ /branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 579)
@@ -652,5 +652,9 @@
   Int     m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
   Int     m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+#if CHANGE_NUMSUBDPB_IDX
+  Int     m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
+#else
   Int     m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
+#endif
 #endif
 
Index: /branches/SHM-5.0-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-5.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 578)
+++ /branches/SHM-5.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 579)
@@ -56,4 +56,5 @@
 #define DISCARDABLE_PIC_RPS              1      ///< JCTVC-P0130: Inter-layer RPS and temporal RPS should not contain picture with discardable_flag equal to 1
 #define VPS_EXTN_UEV_CODING              1      ///< JCTVC-P0306: Code some syntax elements as ue(v), and remove some syntax elements that duplicate behaviour
+#define CHANGE_NUMSUBDPB_IDX             1      ///< Change index of NumSubDpb from output layer set to layer set, to be more aligned with the Spec
 #define O0109_O0199_FLAGS_TO_VUI         1      ///< JCTVC-O0109, O0199: move single_layer_for_non_irap_flag and higher_layer_flag to vps_vui
 #define O0109_VIEW_ID_LEN                1      ///< JCTVC-O0109: view_id_len_minus1 to view_id_len, and add constraint (1<<view_id_len) is greater than or equal to NumViews
Index: /branches/SHM-5.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-5.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 578)
+++ /branches/SHM-5.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 579)
@@ -1590,4 +1590,7 @@
   for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
   {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
     for(Int j = 0; j < vps->getMaxTLayers(); j++)
@@ -1610,5 +1613,9 @@
       if( vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is present
       {
+#if CHANGE_NUMSUBDPB_IDX
+        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#else
         for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+#endif
         {
           READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
Index: /branches/SHM-5.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-5.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 578)
+++ /branches/SHM-5.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 579)
@@ -1218,4 +1218,7 @@
   for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
   {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
     WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]");  
     for(Int j = 0; j < vps->getMaxTLayers(); j++)
@@ -1227,5 +1230,9 @@
       if( vps->getSubLayerDpbInfoPresentFlag(i, j) )
       {
+#if CHANGE_NUMSUBDPB_IDX
+        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#else
         for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+#endif
         {
           WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" ); 
