Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 411)
@@ -71,4 +71,7 @@
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
+#if POC_RESET_FLAG
+, m_bPocResetFlag                 ( false )
+#endif
 #if SH_DISCARDABLE_FLAG
 , m_bDiscardableFlag              ( false )
@@ -269,4 +272,7 @@
     pcPic = *(iterPic);
   }
+#if POC_RESET_FLAG
+    assert( pcPic->getSlice(0)->isReferenced() );
+#endif
   return  pcPic;
 }
@@ -2768,5 +2774,16 @@
     return;
   }        
+#if POC_RESET_FLAG
+  if( this->getPocResetFlag() )
+  {
+    setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, 0)); 
+  }
+  else
+  {
+    setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
+  }
+#else
   setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
+#endif
 }
 #endif 
@@ -2782,5 +2799,5 @@
     //set reference picture POC of each ILP reference 
     Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
-    assert(thePoc >= 0); 
+    assert(thePoc >= 0);
     assert(thePoc == pcRefPicBL->getPOC());
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 411)
@@ -1568,8 +1568,11 @@
   Bool        m_bRefenced;
   
+#if POC_RESET_FLAG
+  Bool        m_bPocResetFlag;
+  Int         m_pocValueBeforeReset;
+#endif  
 #if SH_DISCARDABLE_FLAG
   Bool        m_bDiscardableFlag;
 #endif
-
   // access channel
   TComVPS*    m_pcVPS;
@@ -1730,4 +1733,10 @@
 #endif
 
+#if POC_RESET_FLAG
+  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag; }
+  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b; }
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ; }
+#endif
 #if SH_DISCARDABLE_FLAG
   Bool      getDiscardableFlag  ()                              { return m_bDiscardableFlag; }
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 411)
@@ -49,4 +49,5 @@
 #define VPS_NUH_LAYER_ID                 1      ///< N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
 #if SVC_EXTENSION
+#define POC_RESET_FLAG                1         ///< N0244: POC reset flag for  layer pictures.
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
 #define REPN_FORMAT_IN_VPS               1      ///< N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 411)
@@ -1439,5 +1439,21 @@
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
-
+#if POC_RESET_FLAG
+    Int i = 0; 
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > i)
+    {
+      READ_FLAG(uiCode, "poc_reset_flag");      rpcSlice->setPocResetFlag( uiCode ? true : false );
+      i++;
+    }
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > i)
+    {
+      READ_FLAG(uiCode, "discardable_flag"); // ignored
+      i++;
+    }
+    for (; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+    {
+      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
+    }
+#else
 #if SH_DISCARDABLE_FLAG
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
@@ -1454,4 +1470,5 @@
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
+#endif
 #endif
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 411)
@@ -647,5 +647,9 @@
 
 #if SVC_EXTENSION
+#if POC_RESET_FLAG
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
+#else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
+#endif
 #else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
@@ -780,4 +784,64 @@
   }
   m_bFirstSliceInSequence = false;
+#if POC_RESET_FLAG
+  // This operation would do the following:
+  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
+  // 2. Update the value of m_pocCRA.
+  // 3. Reset the POC values at the decoder for the current picture to be zero.
+  // 4. update value of POCLastDisplay
+  if( m_apcSlicePilot->getPocResetFlag() )
+  {
+    if( m_apcSlicePilot->getSliceIdx() == 0 )
+    {
+      Int pocAdjustValue = m_apcSlicePilot->getPOC();
+
+      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
+      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin();  
+
+      // Iterate through all picture in DPB
+      while( iterPic != m_cListPic.end() )
+      {
+        TComPic *dpbPic = *iterPic;
+        // Check if the picture pointed to by iterPic is either used for reference or
+        // needed for output, are in the same layer, and not the current picture.
+        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
+              && ( dpbPic->getReconMark() ) 
+          )
+        {
+          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+          {
+
+            TComSlice *slice = dpbPic->getSlice(i);
+            TComReferencePictureSet *rps = slice->getRPS();
+            slice->setPOC( slice->getPOC() - pocAdjustValue );
+
+            // Also adjust the POC value stored in the RPS of each such slice
+            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+            {
+              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
+            }
+            // Also adjust the value of refPOC
+            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+            {
+              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+              {
+                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
+              }
+            }
+          }
+        }
+        iterPic++;
+      }
+      // Update the value of pocCRA
+      m_pocCRA -= pocAdjustValue;
+      // Update value of POCLastDisplay
+      iPOCLastDisplay -= pocAdjustValue;
+    }
+    // Reset current poc for current slice and RPS
+    m_apcSlicePilot->setPOC( 0 );
+  }
+#endif
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 411)
@@ -229,5 +229,9 @@
   Void      xActivateParameterSets();
 #if SVC_EXTENSION
+#if POC_RESET_FLAG
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
+#endif
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 411)
@@ -1105,4 +1105,23 @@
   {
 
+#if POC_RESET_FLAG
+    Int i = 0;
+    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > i )
+    {
+      WRITE_FLAG( pcSlice->getPocResetFlag(), "poc_reset_flag" );
+      i++;
+    }
+    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > i )
+    {
+      assert(!!"discardable_flag");
+      WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag");
+      i++;
+    }
+    for ( ; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+    {
+      assert(!!"slice_reserved_undetermined_flag[]");
+      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
+    }
+#else
 #if SH_DISCARDABLE_FLAG
     if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
@@ -1122,4 +1141,5 @@
       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     }
+#endif
 #endif
 
@@ -1143,5 +1163,17 @@
     if( !pcSlice->getIdrPicFlag() )
     {
+#if POC_RESET_FLAG
+      Int picOrderCntLSB;
+      if( !pcSlice->getPocResetFlag() )
+      {
+        picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
+      }
+      else
+      {
+        picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
+      }
+#else
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
+#endif
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
       TComReferencePictureSet* rps = pcSlice->getRPS();
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 411)
@@ -503,5 +503,68 @@
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
 #endif
-
+#if POC_RESET_FLAG
+    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
+    {
+      // Subtract POC adjustment value until now.
+      pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() );
+    }
+    else
+    {
+      // Check if this is the first slice in the picture
+      // In the encoder, the POC values are copied along with copySliceInfo, so we only need
+      // to do this for the first slice.
+      Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue();
+      if( pcSlice->getSliceIdx() == 0 )
+      {
+        TComList<TComPic*>::iterator  iterPic = rcListPic.begin();  
+
+        // Iterate through all picture in DPB
+        while( iterPic != rcListPic.end() )
+        {              
+          TComPic *dpbPic = *iterPic;
+          if( dpbPic->getPOC() == pocCurr )
+          {
+            if( dpbPic->getReconMark() )
+            {
+              assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) );
+            }
+          }
+          // Check if the picture pointed to by iterPic is either used for reference or
+          // needed for output, are in the same layer, and not the current picture.
+          if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+              && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() )
+              && ( dpbPic->getReconMark() ) 
+            )
+          {
+            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+            {
+              TComSlice *slice = dpbPic->getSlice(i);
+              TComReferencePictureSet *rps = slice->getRPS();
+              slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue );
+
+              // Also adjust the POC value stored in the RPS of each such slice
+              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+              {
+                rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
+              }
+              // Also adjust the value of refPOC
+              for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+              {
+                RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+                for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+                {
+                  slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
+                }
+              }
+            }
+          }
+          iterPic++;
+        }
+        m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
+      }
+      pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
+      pcSlice->setPOC( 0 );
+    }
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
     if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
@@ -810,5 +873,9 @@
     {
 #if RESTR_CHK
+#if POC_RESET_FLAG
+      if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+#else
       if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
+#endif
       {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -1065,5 +1132,9 @@
 
       Int sliceQP = m_pcCfg->getInitialQP();
+#if POC_RESET_FLAG
+      if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
+#else
       if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
+#endif
       {
         Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
@@ -1510,5 +1581,9 @@
       }
       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
+#if POC_RESET_FLAG
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
+#else
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
+#endif
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
       pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
@@ -1615,5 +1690,9 @@
       SEIRecoveryPoint sei_recovery_point;
       sei_recovery_point.m_recoveryPocCnt    = 0;
+#if POC_RESET_FLAG
+      sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false);
+#else
       sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false);
+#endif
       sei_recovery_point.m_brokenLinkFlag    = false;
 
@@ -1751,5 +1830,7 @@
           tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
 #endif
+
           m_pcEntropyCoder->encodeSliceHeader(pcSlice);
+
 #if RATE_CONTROL_LAMBDA_DOMAIN
           actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 411)
@@ -92,4 +92,7 @@
 #endif
 #endif
+#if POC_RESET_FLAG
+  m_pocAdjustmentValue     = 0;
+#endif
 }
 
@@ -898,4 +901,7 @@
   m_cPPS.setSPSId         ( m_iSPSIdCnt         );
 #endif
+#if POC_RESET_FLAG
+  m_cPPS.setNumExtraSliceHeaderBits( 2 );
+#endif
 }
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 410)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 411)
@@ -144,4 +144,7 @@
 #endif
 #endif
+#if POC_RESET_FLAG
+  Int                     m_pocAdjustmentValue;
+#endif
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -243,4 +246,8 @@
 
   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
+#if POC_RESET_FLAG
+  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
+  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
+#endif
 };
 
