Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 772)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 773)
@@ -733,4 +733,10 @@
 //    m_cprmsPresentFlag = new Bool   [ getNumHrdParameters() ];
   }
+#endif
+#if HRD_BPB
+    Int getBspHrdParamBufferCpbCntMinus1(UInt i, UInt sl)
+    {
+        return m_bspHrd->getCpbCntMinus1(sl);
+    }
 #endif
 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 772)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 773)
@@ -263,4 +263,5 @@
 #define BITRATE_PICRATE_SIGNALLING       1      ///< JCTVC-Q0102 Proposal 3 signal bitrate, picrate only up to the maximum temporal sub-layers in the corresponding layer set
 #define LAYER_DECPICBUFF_PARAM           1      ///< JCTVC-Q0102 Proposal 2 infer value from layer DPB param
+#define HRD_BPB                         1      ///< JCTVC-Q0101 Bitstream Partition Buffering Proposals
 #if VIEW_ID_RELATED_SIGNALING
 /// scalability types
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 772)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 773)
@@ -1209,14 +1209,53 @@
     UInt lsIdx = nestingSei.m_nestingOpIdx[h];
     READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
-    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
-    {
+#if HRD_BPB
+      Int chkPart=0;
+#endif
+      UInt i;
+    for (i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
+    {
+#if HRD_BPB
+        UInt nl=0; UInt j;
+    for (j = 0 ; j < sei.m_vpsMaxLayers; j++)
+      {
+          if (sei.m_layerIdIncludedFlag[lsIdx][j])
+              nl++;
+      }
+    for (j = 0; j < nl; j++)
+      {
+#else
       for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
       {
         if (sei.m_layerIdIncludedFlag[lsIdx][j])
         {
+#endif
           READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
         }
-      }
-    }
+#if !HRD_BPB
+      }
+#endif
+#if HRD_BPB
+        chkPart+=sei.m_seiLayerInBspFlag[lsIdx][i][j];
+#endif
+    }
+#if HRD_BPB
+      assert(chkPart<=1);
+#endif
+#if HRD_BPB
+      if(sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]==0)
+      {
+          Int chkPartition1=0; Int chkPartition2=0;
+          for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+          {
+              if( sei.m_layerIdIncludedFlag[lsIdx][j] )
+              {
+                  chkPartition1+=sei.m_seiLayerInBspFlag[lsIdx][i][j];
+                  chkPartition2++;
+              }
+          }
+          assert(chkPartition1!=chkPartition2);
+      }
+#endif
+      
     READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
     for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
@@ -1225,5 +1264,12 @@
       {
         READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+          assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1);
+#endif
         READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+          assert(uiCode <=  sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 ));
+#endif
+
       }
     }
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 772)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 773)
@@ -2310,4 +2310,7 @@
       {
         READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
+#if HRD_BPB
+          Int chkPart=0;
+#endif
         for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
         {
@@ -2319,5 +2322,26 @@
             }
           }
-        }
+#if HRD_BPB
+            chkPart+=vps->getLayerInBspFlag(h, i, j);
+#endif
+        }
+#if HRD_BPB
+          assert(chkPart<=1);
+#endif
+#if HRD_BPB
+          if(vps->getNumBitstreamPartitions(h)==1)
+          {
+              Int chkPartition1=0; Int chkPartition2=0;
+              for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+              {
+                  if( vps->getLayerIdIncludedFlag(h, j) )
+                  {
+                      chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
+                      chkPartition2++;
+                  }
+              }
+              assert(chkPartition1!=chkPartition2);
+          }
+#endif
         if (vps->getNumBitstreamPartitions(h))
         {
@@ -2332,5 +2356,12 @@
             {
               READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
+#if HRD_BPB
+                assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
+#endif
+                
               READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
+#if HRD_BPB
+                assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
+#endif
             }
           }
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 772)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 773)
@@ -893,11 +893,24 @@
     for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
     {
+#if HRD_BPB
+        UInt nl=0;
+     for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+     {
+            if (sei.m_layerIdIncludedFlag[lsIdx][j])
+                nl++;
+     }
+     for (UInt j = 0; j < nl; j++)
+     {
+#else
       for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
       {
         if (sei.m_layerIdIncludedFlag[lsIdx][j])
         {
+#endif
           WRITE_FLAG( sei.m_seiLayerInBspFlag[lsIdx][i][j], "sei_layer_in_bsp_flag[lsIdx][i][j]" );
         }
-      }
+#if !HRD_BPB
+      }
+#endif
     }
     WRITE_UVLC( sei.m_seiNumBspSchedCombinationsMinus1[lsIdx], "sei_num_bsp_sched_combinations_minus1[i]");
