Index: branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 866)
+++ branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 867)
@@ -112,4 +112,14 @@
 , m_interLayerPredEnabledFlag     (false)
 , m_numInterLayerRefPicsMinus1    (0)
+#if H_MV_HLS_7_POC_P0041
+, m_sliceSegmentHeaderExtensionLength (0)
+, m_pocResetIdc                       (0)
+, m_pocResetPeriodId                  (0)
+, m_fullPocResetFlag                  (false)
+, m_pocLsbVal                         (0)
+, m_pocMsbValPresentFlag              (false)
+, m_pocMsbVal                         (0)
+, m_pocMsbValRequiredFlag         ( false )
+#endif
 #if H_3D_IC
 , m_bApplyIC                      ( false )
Index: branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 866)
+++ branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 867)
@@ -2240,5 +2240,5 @@
   Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
 
-#if H_MV_HLS7_GEN
+#if H_MV_HLS_7_POC_P0041
   Int        m_sliceSegmentHeaderExtensionLength;
   Int        m_pocResetIdc;
@@ -2248,4 +2248,5 @@
   Bool       m_pocMsbValPresentFlag;
   Int        m_pocMsbVal;
+  Bool       m_pocMsbValRequiredFlag;
 #endif
 
@@ -2596,5 +2597,5 @@
   Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; } 
 
-#if H_MV_HLS7_GEN
+#if H_MV_HLS_7_POC_P0041
   Void setSliceSegmentHeaderExtensionLength( Int  val ) { m_sliceSegmentHeaderExtensionLength = val; } 
   Int  getSliceSegmentHeaderExtensionLength(  ) { return m_sliceSegmentHeaderExtensionLength; } 
@@ -2618,4 +2619,19 @@
   Int  getPocMsbVal(  ) { return m_pocMsbVal; } 
 
+  Bool getPocMsbValRequiredFlag() { return m_pocMsbValRequiredFlag; }
+  Void setPocMsbValRequiredFlag(Bool x) { m_pocMsbValRequiredFlag = x; }
+
+  UInt getPocLsbValLen() { return getSPS()->getBitsForPOC(); }; //log2_max_pic_order_cnt_lsb_minus4 + 4  
+
+  Bool TComSlice::getBlaPicFlag       ()
+  {
+    return  getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP;
+  }
+  Bool TComSlice::getCraPicFlag       ()
+  {
+    return getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
+  }
 #endif
 
@@ -2638,8 +2654,4 @@
   TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
 
-#if H_MV_HLS7_GEN
-  Bool     getPocMsbValRequiredFlag( )        { return   }; 
-  UInt     getPocLsbValLen()                  { return getSPS->getBitsForPOC(); }; //log2_max_pic_order_cnt_lsb_minus4 + 4  
-#endif
 #endif
 #if MTK_DDD_G0063
Index: branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 866)
+++ branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 867)
@@ -2733,5 +2733,5 @@
   if(pps->getSliceHeaderExtensionPresentFlag())
   {
-#if !H_MV_HLS7_GEN    
+#if !H_MV_HLS_7_POC_P0041    
     READ_UVLC(uiCode,"slice_header_extension_length");
     for(Int i=0; i<uiCode; i++)
@@ -2750,8 +2750,17 @@
       READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
     }
+    else
+    {
+      rpcSlice->setPocResetIdc( 0 );
+    }
 
     if( rpcSlice->getPocResetIdc() !=  0 )
     {
       READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
+    }
+    else
+    {
+      // TODO Copy poc_reset_period from earlier picture
+      rpcSlice->setPocResetPeriodId( 0 );
     }
     
@@ -2762,8 +2771,25 @@
     }          
 
-    if( !rpcSlice->getPocMsbValRequiredFlag() &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
+    // Derive the value of PocMsbValRequiredFlag
+    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
+                                          /* || TODO related to vps_poc_lsb_aligned_flag */
+                                          );
+
+    if( !rpcSlice->getPocMsbValRequiredFlag() /* TODO &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     {
       READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
     }
+    else
+    {
+      if( rpcSlice->getPocMsbValRequiredFlag() )
+      {
+        rpcSlice->setPocMsbValPresentFlag( true );
+      }
+      else
+      {
+        rpcSlice->setPocMsbValPresentFlag( false );
+      }
+    }
+
     
     if( rpcSlice->getPocMsbValPresentFlag() )
@@ -2772,9 +2798,9 @@
     }
 
-    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 );
+    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
     {
      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
     }
-    assert( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
+    assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
 #else
     READ_UVLC( uiCode, "slice_header_extension_length" );
@@ -2787,4 +2813,5 @@
 #endif
 #endif
+  }
 
 
Index: branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 866)
+++ branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 867)
@@ -2247,5 +2247,5 @@
 #endif
 
-#if !H_MV_HLS7_GEN
+#if !H_MV_HLS_7_POC_P0041
 #if PPS_FIX_DEPTH
   if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag() || pcSlice->getIsDepth() )
@@ -2258,5 +2258,5 @@
 #endif
 
-#if H_MV_HLS7_GEN
+#if H_MV_HLS_7_POC_P0041
 #if !H_MV
   if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
@@ -2267,4 +2267,63 @@
   if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
   {
+    // Derive the value of PocMsbValRequiredFlag
+    pcSlice->setPocMsbValRequiredFlag( pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag()
+                                          /* || related to vps_poc_lsb_aligned_flag */
+                                          );
+
+    // Determine value of SH extension length.
+    Int shExtnLengthInBit = 0;
+    if (pcSlice->getPPS()->getPocResetInfoPresentFlag())
+    {
+      shExtnLengthInBit += 2;
+    }
+    if (pcSlice->getPocResetIdc() > 0)
+    {
+      shExtnLengthInBit += 6;
+    }
+    if (pcSlice->getPocResetIdc() == 3)
+    {
+      shExtnLengthInBit += (pcSlice->getSPS()->getBitsForPOC() + 1);
+    }
+
+
+    if( !pcSlice->getPocMsbValRequiredFlag() /* TODO &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
+    {
+      shExtnLengthInBit++;    // For poc_msb_val_present_flag
+    }
+    else
+    {
+      if( pcSlice->getPocMsbValRequiredFlag() )
+      {
+        pcSlice->setPocMsbValPresentFlag( true );
+      }
+      else
+      {
+        pcSlice->setPocMsbValPresentFlag( false );
+      }
+    }
+
+    if( pcSlice->getPocMsbValPresentFlag() )
+    {
+      Int iMaxPOClsb = 1<< pcSlice->getSPS()->getBitsForPOC();
+
+      UInt lengthVal = 1;
+      UInt tempVal = pcSlice->getPocMsbVal() + 1;
+      assert ( tempVal );
+      while( 1 != tempVal )
+      {
+        tempVal >>= 1;
+        lengthVal += 2;
+      }
+      shExtnLengthInBit += lengthVal;
+    }
+    Int shExtnAdditionalBits = 0;
+    if(shExtnLengthInBit % 8 != 0)
+    {
+      shExtnAdditionalBits = 8 - (shExtnLengthInBit % 8);
+    }
+    pcSlice->setSliceSegmentHeaderExtensionLength((shExtnLengthInBit + shExtnAdditionalBits) / 8);
+     
+
     WRITE_UVLC( pcSlice->getSliceSegmentHeaderExtensionLength( ), "slice_segment_header_extension_length" );
     UInt posFollSliceSegHeaderExtLen = m_pcBitIf->getNumberOfWrittenBits();
@@ -2273,4 +2332,8 @@
       WRITE_CODE( pcSlice->getPocResetIdc( ), 2, "poc_reset_idc" );
     }
+    else
+    {
+      assert( pcSlice->getPocResetIdc( ) == 0 );
+    }
 
     if( pcSlice->getPocResetIdc() !=  0 )
@@ -2282,8 +2345,8 @@
     {
       WRITE_FLAG( pcSlice->getFullPocResetFlag( ) ? 1 : 0 , "full_poc_reset_flag" );
-      WRITE_CODE( pcSlice->getPocLsbVal( ), getPocLsbValLen ), "poc_lsb_val" );
+      WRITE_CODE( pcSlice->getPocLsbVal( ), pcSlice->getPocLsbValLen() , "poc_lsb_val" );
     }              
     
-    if( !pcSlice->getPocMsbValRequiredFlag() &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
+    if( !pcSlice->getPocMsbValRequiredFlag() /* TODO &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     {
       WRITE_FLAG( pcSlice->getPocMsbValPresentFlag( ) ? 1 : 0 , "poc_msb_val_present_flag" );
@@ -2294,13 +2357,13 @@
       WRITE_UVLC( pcSlice->getPocMsbVal( ), "poc_msb_val" );
     }
-
-    while( ( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) < pcSlice->getSliceSegmentHeaderExtensionLength() * 8 ); 
+    
+    while( ( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) < pcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
     {
       WRITE_FLAG( 0, "slice_segment_header_extension_data_bit" );
     }
 
-    assert( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) == pcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
+    assert( ( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) == pcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
+  }
 #endif 
-
 #endif
 }
