Index: /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 798)
@@ -191,5 +191,4 @@
     InputNALUnit nalu;
     byteStreamNALUnit(bytestream, nalUnit, stats);
-
     // call actual decoding function
     Bool bNewPicture = false;
@@ -215,5 +214,9 @@
       {
         bNewPicture = m_acTDecTop[nalu.m_layerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_layerId], curLayerId, bNewPOC);
+#if POC_RESET_IDC_DECODER
+        if ( (bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 3) || (m_acTDecTop[nalu.m_layerId].getParseIdc() == 0) )
+#else
         if (bNewPicture)
+#endif
         {
           bitstreamFile.clear();
@@ -225,8 +228,22 @@
           bytestream.reset();
         }
-      }
-    }
-
+#if POC_RESET_IDC_DECODER
+        else if(m_acTDecTop[nalu.m_layerId].getParseIdc() == 1) 
+        {
+          bitstreamFile.clear();
+          // This is before third parse of the NAL unit, and 
+          // location points to correct beginning of the NALU
+          bitstreamFile.seekg(location);
+          bytestream.reset();
+        }
+#endif
+      }
+    }
+
+#if POC_RESET_IDC_DECODER
+    if ((bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 3) || (m_acTDecTop[nalu.m_layerId].getParseIdc() == 0) || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
+#else
     if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
+#endif
     {
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
@@ -245,4 +262,11 @@
     }
 
+#if POC_RESET_IDC_DECODER
+    if( bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() == 0 )
+    {
+      outputAllPictures( nalu.m_layerId, true );
+    }
+#endif
+
     if( pcListPic )
     {
@@ -269,5 +293,11 @@
         flushAllPictures( nalu.m_layerId, outputPicturesFlag );       
       }
+
+#if POC_RESET_IDC_DECODER
+      if( bNewPicture && m_acTDecTop[nalu.m_layerId].getParseIdc() != 0 )
+      // New picture, slice header parsed but picture not decoded
+#else
       if( bNewPicture ) // New picture, slice header parsed but picture not decoded
+#endif
       {
 #if NO_OUTPUT_OF_PRIOR_PICS
@@ -1504,4 +1534,7 @@
                             , std::vector<Int> *listOfPocsPositionInEachLayer
                             , DpbStatus &dpbStatus
+#if POC_RESET_IDC_DECODER
+                            , Bool notOutputCurrAu
+#endif
                             )
 {
@@ -1528,20 +1561,26 @@
           vps = pic->getSlice(0)->getVPS();
         }
-
-        std::vector<Int>::iterator it;
-        if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
-        {
-          it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
-          if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
+#if POC_RESET_IDC_DECODER
+        if( !(pic->isCurrAu() && notOutputCurrAu ) )
+        {
+#endif
+          std::vector<Int>::iterator it;
+          if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
           {
-            listOfPocs.push_back( pic->getPOC() );
+            it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
+            if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
+            {
+              listOfPocs.push_back( pic->getPOC() );
+            }
+            listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
+            listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
           }
-          listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
-          listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
-        }
-        if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
-        {
-          dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
-        }
+          if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
+          {
+            dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
+          }
+#if POC_RESET_IDC_DECODER
+        }
+#endif
       }
       iterPic++;
@@ -1569,7 +1608,28 @@
   }
   assert( dpbStatus.m_numAUsNotDisplayed != -1 );
-
-
 }  
+
+#if POC_RESET_IDC_DECODER
+Void TAppDecTop::outputAllPictures(Int layerId, Bool notOutputCurrPic)
+{
+  { // All pictures in the DPB in that layer are to be output; this means other pictures would also be output
+    std::vector<Int>  listOfPocs;
+    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+    DpbStatus dpbStatus;
+
+    // Find the status of the DPB
+    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus, notOutputCurrPic);
+
+    if( listOfPocs.size() )
+    {
+      while( listOfPocsInEachLayer[layerId].size() )    // As long as there picture in the layer to be output
+      {
+        bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+      }
+    }
+  }
+}
+#endif
 #endif
 //! \}
Index: /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 797)
+++ /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 798)
@@ -107,8 +107,14 @@
 
   Void xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerID, Int &pocLastDisplay, DpbStatus &dpbStatus);
+#if POC_RESET_IDC_DECODER
+  Void outputAllPictures(Int layerId, Bool notOutputCurrAu);
+#endif
   Void xFindDPBStatus( std::vector<Int> &listOfPocs
                             , std::vector<Int> *listOfPocsInEachLayer
                             , std::vector<Int> *listOfPocsPositionInEachLayer
                             , DpbStatus &dpbStatus
+#if POC_RESET_IDC_DECODER
+                            , Bool notOutputCurrAu = true
+#endif
                             );
 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h	(revision 798)
@@ -92,5 +92,7 @@
   Int                   m_nFrameBit;
 #endif
-
+#if POC_RESET_IDC_DECODER
+  Bool                  m_currAuFlag;
+#endif
 public:
   TComPic();
@@ -223,4 +225,8 @@
   Int   getFrameBit()         { return m_nFrameBit; }
 #endif
+#if POC_RESET_IDC_DECODER
+  Bool isCurrAu() { return m_currAuFlag; }
+  Void setCurrAuFlag(Bool x) {m_currAuFlag = x; }
+#endif
 };// END CLASS DEFINITION TComPic
 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 798)
@@ -125,4 +125,7 @@
 , m_pocMsbValPresentFlag          ( false )
 #endif
+#if POC_RESET_IDC_DECODER
+, m_picOrderCntLsb (0)
+#endif
 #endif //SVC_EXTENSION
 {
@@ -200,4 +203,16 @@
   m_numEntryPointOffsets = 0;
   m_enableTMVPFlag = true;
+#if POC_RESET_IDC_SIGNALLING
+  m_pocResetIdc                   = 0;
+  m_pocResetPeriodId              = 0;
+  m_fullPocResetFlag              = false;
+  m_pocLsbVal                     = 0;
+  m_pocMsbVal                     = 0;
+  m_pocMsbValRequiredFlag         = false;
+  m_pocMsbValPresentFlag          = false;
+#endif
+#if POC_RESET_IDC_DECODER
+  m_picOrderCntLsb = 0;
+#endif
 }
 
@@ -223,5 +238,47 @@
 }
 #endif
-
+#if POC_RESET_IDC_DECODER
+Bool TComSlice::getRaslPicFlag      ()
+{
+  return  getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R
+  || getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N;
+}
+Bool TComSlice::getRadlPicFlag      ()
+{
+  return  getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
+  || getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N;
+}
+#endif
+#if POC_RESET_IDC_ENCODER
+Void TComSlice::decrementRefPocValues(Int const decrementValue)
+{
+  for(Int listNum = 0; listNum < 2; listNum++)
+  {
+    RefPicList dpbPicSliceList = (listNum == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+    for(Int listIdx = 0; listIdx < getNumRefIdx( dpbPicSliceList ); listIdx++)
+    {
+      setRefPOC( getRefPOC(dpbPicSliceList, listIdx) - decrementValue, 
+                  dpbPicSliceList,
+                  listIdx
+                  );
+    }
+  }
+}
+Int TComSlice::getCurrMsb( Int currLsb, Int prevLsb, Int prevMsb, Int maxLsbVal )
+{
+  if( prevLsb - currLsb >= (maxLsbVal >> 1) )
+  {
+    return prevMsb + maxLsbVal;
+  }
+  else if( currLsb - prevLsb > (maxLsbVal >> 1) )
+  {
+    return prevMsb - maxLsbVal;
+  }
+  else
+  {
+    return prevMsb;
+  }
+}
+#endif
 /**
  - allocate table to contain substream sizes to be written to the slice header.
@@ -279,5 +336,9 @@
   while ( iterPic != rcListPic.end() )
   {
+#if POC_RESET_IDC_ENCODER
+    if( (pcPic->getPOC() == poc) && (pcPic->getSlice(0)->isReferenced()) )
+#else
     if(pcPic->getPOC() == poc)
+#endif
     {
       break;
@@ -293,5 +354,5 @@
     pcPic = *(iterPic);
   }
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_DECODER
   assert( pcPic->getSlice(0)->isReferenced() );
 #endif
@@ -1087,6 +1148,16 @@
       rpcPic->setCurrSliceIdx(0);
 #if NO_CLRAS_OUTPUT_FLAG
+#if POC_RESET_IDC_ENCODER
       if (noClrasOutputFlag)
       {
+        rpcPic->getSlice(0)->setReferenced(false);  // all layers // TODO. This does not mark all layers
+      }
+      else
+      {
+        if (rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
+      }
+#else
+      if (noClrasOutputFlag)
+      {
         if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);  // all layers
       }
@@ -1095,4 +1166,5 @@
         if (rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
       }
+#endif
 #else
       if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
@@ -1100,4 +1172,7 @@
       iterPic++;
     }
+#if POC_RESET_IDC_ENCODER
+    this->getPic()->getSlice(0)->setReferenced(true);   // Mark the current picture back as refererced.
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -1328,6 +1403,9 @@
 }
 
-
+#if POC_RESET_IDC_ENCODER
+Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic, Bool usePocBeforeReset)
+#else
 Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
+#endif
 {
   TComPic* rpcPic;
@@ -1418,5 +1496,16 @@
          nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
       {
+#if POC_RESET_IDC_ENCODER
+        if( usePocBeforeReset )
+        {
+          assert(rpcPic->getSlice(0)->getPocValueBeforeReset() < this->getPocValueBeforeReset());
+        }
+        else
+        {
+          assert(rpcPic->getPOC() < this->getPOC());
+        }
+#else
         assert(rpcPic->getPOC() < this->getPOC());
+#endif
       }
     }
@@ -1436,5 +1525,16 @@
           if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
           {
+#if POC_RESET_IDC_ENCODER
+            if( usePocBeforeReset )
+            {
+              assert(rpcPic->getSlice(0)->getPocValueBeforeReset() < this->getPocValueBeforeReset());
+            }
+            else
+            {
+              assert(rpcPic->getPOC() < this->getPOC());
+            }
+#else
             assert(rpcPic->getPOC() < this->getPOC());
+#endif
           }
         }
@@ -1453,5 +1553,16 @@
         // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
         // rpcPic would violate the constraint if it was a trailing picture
+#if POC_RESET_IDC_ENCODER
+        if( usePocBeforeReset )
+        {
+          assert(rpcPic->getPOC() <= this->getAssociatedIrapPocBeforeReset());
+        }
+        else
+        {
+          assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+        }
+#else
         assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
+#endif
       }
     }
@@ -1759,5 +1870,9 @@
     if(isAvailable == 0)    
     {            
+#if UNAVAILABLE_PIC_BUGFIX
+#if 0
       if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
+#endif
+#endif
       {
         if(!pReferencePictureSet->getUsed(i) )
@@ -1780,5 +1895,9 @@
       }
 #if ALLOW_RECOVERY_POINT_AS_RAP
+#if UNAVAILABLE_PIC_BUGFIX
+      if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+#else
       else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+#endif
       {
         atLeastOneUnabledByRecoveryPoint = 1;
@@ -3761,6 +3880,10 @@
     return false;
   }        
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_DECODER
+#if POC_RESET_IDC_DECODER
+  TComPic* pic = xGetRefPic( rcListPic, getPOC() );
+#else
   TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
+#endif
 
   if( pic )
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 798)
@@ -1968,4 +1968,8 @@
   Int         m_iLastIDR;
   Int         m_iAssociatedIRAP;
+#if POC_RESET_IDC_ENCODER
+  Int                     m_associatedIrapPocBeforeReset;
+#endif
+
   NalUnitType m_iAssociatedIRAPType;
   static Int  m_prevTid0POC;
@@ -2094,4 +2098,10 @@
   Bool        m_pocMsbValPresentFlag;
 #endif
+#if POC_RESET_IDC_ENCODER
+  Int         m_pocValueBeforeReset;
+#endif
+#if POC_RESET_IDC_DECODER
+  Int         m_picOrderCntLsb;
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   Int        m_nCGSOverWritePPS;  // for optimization, not output to bitstream
@@ -2139,4 +2149,8 @@
     Void     adjustPrevTid0POC      (Int adj)             { m_prevTid0POC=m_prevTid0POC-adj; }
 #endif
+#if POC_RESET_IDC_DECODER
+  Void      setPrevTid0POC( Int x ) { m_prevTid0POC = x; }
+#endif
+
   TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
   Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
@@ -2144,4 +2158,9 @@
   Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
   Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
+#if POC_RESET_IDC_ENCODER
+  Void setAssociatedIrapPocBeforeReset(Int x) { m_associatedIrapPocBeforeReset = x; }
+  Int  getAssociatedIrapPocBeforeReset(     ) { return m_associatedIrapPocBeforeReset; }
+#endif
+
   Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
   NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
@@ -2253,5 +2272,9 @@
   Void setTLayerInfo( UInt uiTLayer );
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
+#if POC_RESET_IDC_ENCODER
+  Void checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic, Bool usePocBeforeReset = false);
+#else
   Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
+#endif
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -2451,4 +2474,18 @@
   Bool      getCraPicFlag       ();
 #endif
+#if POC_RESET_IDC_DECODER
+  Bool      getRaslPicFlag      ();
+  Bool      getRadlPicFlag      ();
+  Int       getPicOrderCntLsb() { return m_picOrderCntLsb; }
+  Void      setPicOrderCntLsb(Int x) { m_picOrderCntLsb = x; }
+#endif
+
+#if POC_RESET_IDC_ENCODER
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ;   }
+  Void      decrementRefPocValues(Int const decrementValue);
+  Int       getCurrMsb( Int currLsb, Int prevLsb, Int prevMsb, Int maxLsbVal );
+#endif
+
 
 #endif //SVC_EXTENSION
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 798)
@@ -97,8 +97,12 @@
 #define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
 #endif
-#define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
+#define POC_RESET_FLAG                   0      ///< JCTVC-N0244: POC reset flag for  layer pictures.
 #define POC_RESET_IDC                    1      ///< JCTVC-P0041: Include poc_reset_idc and related derivation - eventually will replace POC_RESET_FLAG
 #if POC_RESET_IDC
 #define POC_RESET_IDC_SIGNALLING         1      ///< JCTVC-P0041: Include signalling for poc_reset related syntax elements
+#define POC_RESET_IDC_ENCODER            1      ///< JCTVC-P0041: Include support of enabling POC reset at the encoder
+#define POC_RESET_IDC_DECODER            1      ///< JCTVC-P0041: Include support of enabling POC reset at the decoder
+#define ALIGN_IRAP_BUGFIX               1
+#define UNAVAILABLE_PIC_BUGFIX          1
 #endif
 #define POC_MSB_VAL_PRESENT_FLAG_SEM     1      ///< JCTVC-Q0146: Inference of poc_msb_val_present_flag
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 798)
@@ -2616,4 +2616,7 @@
     {
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
+#if POC_RESET_IDC_DECODER
+      rpcSlice->setPicOrderCntLsb( uiCode );
+#endif
 #if SHM_FIX7
       iPOClsb = uiCode;
@@ -2650,4 +2653,10 @@
 #if SHM_FIX7
       }
+#endif
+#if POC_RESET_IDC_DECODER
+    else
+    {
+      rpcSlice->setPicOrderCntLsb( 0 );
+    }
 #endif
       if( !rpcSlice->getIdrPicFlag() )
@@ -3342,8 +3351,12 @@
     }
 
+#if !POC_RESET_IDC_DECODER
     Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
+#endif
     if( rpcSlice->getPocMsbValPresentFlag() )
     {
       READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
+
+#if !POC_RESET_IDC_DECODER
       // Update POC of the slice based on this MSB val
       Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
@@ -3353,4 +3366,5 @@
     {
       rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
+#endif
     }
 
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 798)
@@ -96,4 +96,9 @@
   m_subDpbIdx = -1;
 #endif
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+  m_lastPocPeriodId = -1;
+  m_prevPicOrderCnt = 0;
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   m_pColorMappedPic = NULL;
@@ -1104,12 +1109,211 @@
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
+  {
+    m_parseIdc++; // Proceed to POC decoding and RPS derivation
+  }
+  
+  if( m_parseIdc == 2 )
+  {
+    bNewPOC = false;
+  }
+
+  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
+  {
+  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
+  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice 
+  // does not invoke the output twice
+  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
+    // Update CurrAU marking
+    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
+    {
+      markAllPicsAsNoCurrAu();
+    }
+
+    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
+    {
+      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
+      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
+        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
+      {
+        setLastPocPeriodId(pocResetPeriodId);
+        m_parseIdc = 0;
+      }
+    }
+    else
+    {
+      m_parseIdc = 3; // Proceed to decoding POC and RPS
+    }  
+  }
+#endif
 
 #if ALIGNED_BUMPING
+#if POC_RESET_IDC_DECODER
+  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
+  if( m_parseIdc == 1 )
+  {
+
+    // Invoke output of pictures if the current picture is a POC reset picture
+    bNewPOC = true;
+    /* Include reset of all POCs in the layer */
+
+  // 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 - will be done later
+  // 4. update value of POCLastDisplay
+      
+  //Do the reset stuff here
+    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    Int pocLsbVal;
+    if( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
+    }
+    else
+    {
+      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
+    }
+
+    Int pocMsbDelta = 0;
+    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
+    {
+      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else
+    {
+      //This MSB derivation can be made into one function. Item to do next.
+      Int prevPoc     = this->getPrevPicOrderCnt();
+      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
+      Int prevPocMsb  = prevPoc - prevPocLsb;
+
+      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
+    }
+
+    Int pocLsbDelta;
+    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
+    {
+      pocLsbDelta = pocLsbVal;
+    }
+    else
+    {
+      pocLsbDelta = 0; 
+    }
+
+    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
+
+    //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() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
+      {
+        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+        {
+
+          TComSlice *slice = dpbPic->getSlice(i);
+          TComReferencePictureSet *rps = slice->getRPS();
+          slice->setPOC( slice->getPOC() - deltaPocVal );
+
+          // 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) - deltaPocVal );
+          }
+          // 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) - deltaPocVal, list, j);
+            }
+          }
+        }
+      }
+      iterPic++;
+    }
+    // Update the value of pocCRA
+    m_pocCRA -= deltaPocVal;
+
+    // Update value of POCLastDisplay
+    iPOCLastDisplay -= deltaPocVal;
+  }
+  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
+
+  if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
+  {
+    // Set poc for current slice
+    if( m_apcSlicePilot->getPocResetIdc() == 1 )
+    {        
+      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
+    }
+    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
+    {
+      m_apcSlicePilot->setPOC( 0 );
+    }
+    else 
+    {
+      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
+      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+    }
+  }
+  else if (m_parseIdc == 3)
+  {
+    Int picOrderCntMsb = 0;
+    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
+    {
+      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else if( m_apcSlicePilot->getIdrPicFlag() )
+    {
+      picOrderCntMsb = 0;
+    }
+    else
+    {
+      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
+      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
+      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
+    }
+    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+  }
+
+  if( m_parseIdc == 1 || m_parseIdc == 3)
+  {
+    // Adjust prevPicOrderCnt
+    if(    !m_apcSlicePilot->getRaslPicFlag() 
+        && !m_apcSlicePilot->getRadlPicFlag()
+        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
+        && ( nalu.m_temporalId == 0 )
+        && !m_apcSlicePilot->getDiscardableFlag() )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
+    }
+    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
+                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
+    }
+#else
   if (bNewPOC || m_layerId!=m_uiPrevLayerId)
   {
+#endif
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
+#else
   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
+#endif
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
@@ -1119,6 +1323,10 @@
   }
 
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+#endif
+
   // actual decoding starts here
-  xActivateParameterSets();
+    xActivateParameterSets();
 
 #if REPN_FORMAT_IN_VPS
@@ -1201,5 +1409,4 @@
   }
 #endif
-
   // Alignment of TSA and STSA pictures across AU
   if( m_apcSlicePilot->getLayerId() > 0 )
@@ -1401,4 +1608,8 @@
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
+
+#if POC_RESET_IDC_DECODER
+  pcPic->setCurrAuFlag( true );
+#endif
 
     Bool isField = false;
@@ -2505,5 +2716,20 @@
 }
 #endif
-
+#if POC_RESET_IDC_DECODER
+Void TDecTop::markAllPicsAsNoCurrAu()
+{
+  for(Int i = 0; i < MAX_LAYERS; i++)
+  {
+    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
+    TComList<TComPic*>::iterator  iterPic = listPic->begin();
+    while ( iterPic != listPic->end() )
+    {
+      TComPic *pcPic = *(iterPic);
+      pcPic->setCurrAuFlag( false );
+      iterPic++;
+    }
+  }
+}
+#endif
 #if Q0048_CGS_3D_ASYMLUT
 Void TDecTop::initAsymLut(TComSlice *pcSlice)
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 798)
@@ -204,4 +204,9 @@
   Bool                    m_firstPicInLayerDecodedFlag;
 #endif
+#if POC_RESET_IDC_DECODER
+  Int                     m_parseIdc;
+  Int                     m_lastPocPeriodId;
+  Int                     m_prevPicOrderCnt;
+#endif
 #if RESOLUTION_BASED_DPB
   Int                     m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
@@ -244,4 +249,15 @@
 #if EARLY_REF_PIC_MARKING
   Void earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdList);
+#endif
+#if POC_RESET_IDC_DECODER
+  Int getParseIdc() { return m_parseIdc;}
+  Void        setParseIdc(Int x) { m_parseIdc = x;}
+  Void        markAllPicsAsNoCurrAu();
+
+  Int   getLastPocPeriodId() { return m_lastPocPeriodId; }
+  Void  setLastPocPeriodId(Int x)    { m_lastPocPeriodId = x; }
+
+  Int   getPrevPicOrderCnt() { return m_prevPicOrderCnt; }
+  Void  setPrevPicOrderCnt(Int const x) { m_prevPicOrderCnt = x; }
 #endif
   UInt      getLayerId            () { return m_layerId;              }
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 798)
@@ -998,7 +998,7 @@
   {
     WRITE_UVLC( vps->getNumAddLayerSets(), "num_add_layer_sets" );
-    for (Int i = 0; i < vps->getNumAddLayerSets(); i++)
-    {
-      for (Int j = 1; j < vps->getNumIndependentLayers(); j++)
+    for (i = 0; i < vps->getNumAddLayerSets(); i++)
+    {
+      for (j = 1; j < vps->getNumIndependentLayers(); j++)
       {
         int len = 1;
@@ -1828,5 +1828,17 @@
       }
 #else
+#if POC_RESET_IDC_ENCODER
+      Int picOrderCntLSB;
+      if( pcSlice->getPocResetIdc() == 2 )  // i.e. the LSB is reset
+      {
+        picOrderCntLSB = pcSlice->getPicOrderCntLsb();  // This will be the LSB value w.r.t to the previous POC reset period.
+      }
+      else
+      {
+        picOrderCntLSB = (pcSlice->getPOC() + (1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+      }
+#else
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+#endif
 #endif
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
@@ -2300,4 +2312,5 @@
 {
   Int tmpBitsBeforeWriting = getNumberOfWrittenBits();
+  Int maxPocLsb = 1 << slice->getSPS()->getBitsForPOC();
   if(slice->getPPS()->getSliceHeaderExtensionPresentFlag())
   {
@@ -2342,5 +2355,5 @@
     {
       UInt lengthVal = 1;
-      UInt tempVal = slice->getPocMsbVal() + 1;
+      UInt tempVal = (slice->getPocMsbVal() / maxPocLsb) + 1;
       assert ( tempVal );
       while( 1 != tempVal )
@@ -2379,5 +2392,6 @@
     if( slice->getPocMsbValPresentFlag() )
     {
-      WRITE_UVLC( slice->getPocMsbVal(),                                      "poc_msb_val" );
+      assert( slice->getPocMsbVal() % maxPocLsb == 0 );
+      WRITE_UVLC( slice->getPocMsbVal() / maxPocLsb,                                      "poc_msb_val" );
     }
     for (Int i = 0; i < shExtnAdditionalBits; i++)
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 798)
@@ -92,4 +92,8 @@
   m_bRefreshPending     = 0;
   m_pocCRA            = 0;
+#if POC_RESET_IDC_ENCODER
+  m_pocCraWithoutReset = 0;
+  m_associatedIrapPocBeforeReset = 0;
+#endif
   m_numLongTermRefPicSPS = 0;
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
@@ -108,4 +112,7 @@
   m_temp = NULL;
   m_pColorMappedPic = NULL;
+#endif
+#if POC_RESET_IDC_ENCODER
+  m_lastPocPeriodId = -1;
 #endif
 #endif //SVC_EXTENSION
@@ -903,4 +910,34 @@
     }
 #endif
+#if POC_RESET_IDC_ENCODER
+    pcSlice->setPocValueBeforeReset( pocCurr );
+    // Check if the current picture is to be assigned as a reset picture
+    determinePocResetIdc(pocCurr, pcSlice);
+
+    // If reset, do the following steps:
+    if( pcSlice->getPocResetIdc() )
+    {
+      updatePocValuesOfPics(pocCurr, pcSlice);
+    }
+    else
+    {
+      // Check the base layer picture is IDR. If so, just set current POC equal to 0 (alignment of POC)
+      if( ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2) && ( pocCurr % m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() == 0 ) )        
+      {
+        m_pcEncTop->setPocAdjustmentValue( pocCurr );
+      }
+      // else
+      {
+        // Just subtract POC by the current cumulative POC delta
+        pcSlice->setPOC( pocCurr - m_pcEncTop->getPocAdjustmentValue() );
+      }
+
+      Int maxPocLsb = 1 << pcSlice->getSPS()->getBitsForPOC();
+      pcSlice->setPocMsbVal( pcSlice->getPOC() - ( pcSlice->getPOC() & (maxPocLsb-1) ) );
+    }
+    // Update the POC of current picture, pictures in the DPB, including references inside the reference pictures
+
+#endif
+
 #if O0149_CROSS_LAYER_BLA_FLAG
     if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
@@ -1225,5 +1262,9 @@
         else
         {
+#if ALIGN_IRAP_BUGFIX
+#if 0
           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+#endif
+#endif
         }
       }
@@ -1272,8 +1313,14 @@
     {
       m_associatedIRAPType = pcSlice->getNalUnitType();
+#if POC_RESET_IDC_ENCODER
+      m_associatedIRAPPOC = pcSlice->getPOC();
+      m_associatedIrapPocBeforeReset = pocCurr;
+#else
       m_associatedIRAPPOC = pocCurr;
+#endif
     }
     pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
     pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
+    pcSlice->setAssociatedIrapPocBeforeReset(m_associatedIrapPocBeforeReset);
 #endif
 #endif
@@ -1283,4 +1330,8 @@
 #else
     pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
+#endif
+#if POC_RESET_IDC_ENCODER
+    // m_pocCRA may have been update here; update m_pocCraWithoutReset
+    m_pocCraWithoutReset = m_pocCRA + m_pcEncTop->getPocAdjustmentValue();
 #endif
     m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
@@ -1320,5 +1371,9 @@
 #endif
 #if ALIGNED_BUMPING
+#if POC_RESET_IDC_ENCODER
+    pcSlice->checkLeadingPictureRestrictions(rcListPic, true);
+#else
     pcSlice->checkLeadingPictureRestrictions(rcListPic);
+#endif
 #endif
     pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
@@ -1513,5 +1568,5 @@
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
 #else
@@ -1853,5 +1908,5 @@
 
       Int sliceQP = m_pcCfg->getInitialQP();
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
 #else
@@ -2385,5 +2440,5 @@
       }
       pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pocCurr - m_totalCoded;
 #else
@@ -2513,5 +2568,5 @@
       SEIRecoveryPoint sei_recovery_point;
       sei_recovery_point.m_recoveryPocCnt    = 0;
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
       sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false);
 #else
@@ -3268,4 +3323,197 @@
 #endif
 }
+
+#if POC_RESET_IDC_ENCODER
+Void TEncGOP::determinePocResetIdc(Int const pocCurr, TComSlice *const slice)
+{
+  // If one picture in the AU is IDR, and another picture is not IDR, set the poc_reset_idc to 1 or 2
+  // If BL picture in the AU is IDR, and another picture is not IDR, set the poc_reset_idc to 2
+  // If BL picture is IRAP, and another picture is non-IRAP, then the poc_reset_idc is equal to 1 or 2.
+  if( slice->getSliceIdx() == 0 ) // First slice - compute, copy for other slices
+  {
+    Int needReset = false;
+    Int resetDueToBL = false;
+    if( slice->getVPS()->getMaxLayers() > 1 )
+    {
+      // If IRAP is refreshed in this access unit for base layer
+      if( (m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 1 || m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2)
+        && ( pocCurr % m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+        )
+      {
+        // Check if the IRAP refresh interval of any layer does not match that of the base layer
+        for(Int i = 1; i < slice->getVPS()->getMaxLayers(); i++)
+        {
+          Bool refreshIntervalFlag = ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
+          Bool refreshTypeFlag     = ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() );
+          if( !(refreshIntervalFlag && refreshTypeFlag) )
+          {
+            needReset = true;
+            resetDueToBL = true;
+            break;
+          }
+        }
+      }
+    }
+    
+    if( !needReset )// No need reset due to base layer IRAP
+    {
+      // Check if EL IDRs results in POC Reset
+      for(Int i = 1; i < slice->getVPS()->getMaxLayers() && !needReset; i++)
+      {
+        Bool idrFlag = ( (m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                        && ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+                        );
+        for(Int j = 0; j < slice->getVPS()->getMaxLayers(); j++)
+        {
+          if( j == i )
+          {
+            continue;
+          }
+          Bool idrOtherPicFlag = ( (m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                                  && ( pocCurr % m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+                                  );
+
+          if( idrFlag != idrOtherPicFlag )
+          {
+            needReset = true;
+            break;
+          }
+        }
+      }
+    }
+    if( needReset )
+    {
+      if( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2 )  // BL IDR refresh, assuming BL picture present
+      {
+        if( resetDueToBL )
+        {
+          slice->setPocResetIdc( 2 ); // Full reset needed
+        }
+        else
+        {
+          slice->setPocResetIdc( 1 ); // Due to IDR in EL
+        }
+      }
+      else
+      {
+        slice->setPocResetIdc( 1 ); // Only MSB reset
+      }
+
+      // Start a new POC reset period
+      if (m_layerId == 0)   // Assuming BL picture is always present at encoder; for other AU structures, need to change this
+      {
+        Int periodId = rand() % 64;
+        m_lastPocPeriodId = (periodId == m_lastPocPeriodId) ? (periodId + 1) % 64 : periodId ;
+      }
+      else
+      {
+        m_lastPocPeriodId = m_ppcTEncTop[0]->getGOPEncoder()->getLastPocPeriodId();
+      }
+      slice->setPocResetPeriodId(m_lastPocPeriodId);
+    }
+    else
+    {
+      slice->setPocResetIdc( 0 );
+    }
+  }
+}
+
+Void TEncGOP::updatePocValuesOfPics(Int const pocCurr, TComSlice *const slice)
+{
+
+  Int pocAdjustValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+
+  // New POC reset period
+  Int maxPocLsb, pocLsbVal, pocMsbDelta, pocLsbDelta, deltaPocVal;
+
+  maxPocLsb   = 1 << slice->getSPS()->getBitsForPOC();
+  pocLsbVal   = (slice->getPocResetIdc() == 3)
+                ? slice->getPocLsbVal()
+                : pocAdjustValue % maxPocLsb; 
+  pocMsbDelta = pocAdjustValue - pocLsbVal;
+  pocLsbDelta = (slice->getPocResetIdc() == 2 || ( slice->getPocResetIdc() == 3 && slice->getFullPocResetFlag() )) 
+                ? pocLsbVal 
+                : 0; 
+  deltaPocVal = pocMsbDelta  + pocLsbDelta;
+  
+  // Decrement value of associatedIrapPoc of the TEncGop object
+  this->m_associatedIRAPPOC -= deltaPocVal;
+
+  // Decrememnt the value of m_pocCRA
+  this->m_pocCRA -= deltaPocVal;
+
+  // Iterate through all pictures in the DPB
+  TComList<TComPic*>::iterator  iterPic = getListPic()->begin();  
+  while( iterPic != getListPic()->end() )
+  {
+    TComPic *dpbPic = *iterPic;
+    
+    if( dpbPic->getReconMark() )
+    {
+      for(Int i = dpbPic->getNumAllocatedSlice() - 1; i >= 0; i--)
+      {
+        TComSlice *dpbPicSlice = dpbPic->getSlice( i );
+        TComReferencePictureSet *dpbPicRps = dpbPicSlice->getRPS();
+
+        // Decrement POC of slice
+        dpbPicSlice->setPOC( dpbPicSlice->getPOC() - deltaPocVal );
+
+        // Decrement POC value stored in the RPS of each such slice
+        for( Int j = dpbPicRps->getNumberOfPictures() - 1; j >= 0; j-- )
+        {
+          dpbPicRps->setPOC( j, dpbPicRps->getPOC(j) - deltaPocVal );
+        }
+
+        // Decrement value of refPOC
+        dpbPicSlice->decrementRefPocValues( deltaPocVal );
+
+        // Update value of associatedIrapPoc of each slice
+        dpbPicSlice->setAssociatedIRAPPOC( dpbPicSlice->getAssociatedIRAPPOC() - deltaPocVal );
+      }
+    }
+    iterPic++;
+  }
+  
+  // Actual POC value before reset
+  Int adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+
+  // Set MSB value before reset
+  Int tempLsbVal = adjustedPocValue & (maxPocLsb - 1);
+  slice->setPocMsbVal( adjustedPocValue - tempLsbVal);
+
+  // Set LSB value before reset - this is needed in the case of resetIdc = 2
+  slice->setPicOrderCntLsb( tempLsbVal );
+
+  // Cumulative delta
+  m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + deltaPocVal );
+
+  // New LSB value, after reset
+  adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
+  Int newLsbVal = adjustedPocValue & (maxPocLsb - 1);
+
+  // Set value of POC current picture after RESET
+  if( slice->getPocResetIdc() == 1 )
+  {
+    slice->setPOC( newLsbVal );
+  }
+  else if( slice->getPocResetIdc() == 2 )
+  {
+    slice->setPOC( 0 );
+  }
+  else if( slice->getPocResetIdc() == 3 )
+  {
+    Int picOrderCntMsb = slice->getCurrMsb( newLsbVal, 
+                                        slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 
+                                        0,
+                                        maxPocLsb );
+    slice->setPOC( picOrderCntMsb + newLsbVal );
+  }
+  else
+  {
+    assert(0);
+  }
+}
+#endif
+
 
 #if !SVC_EXTENSION
@@ -3716,9 +3964,17 @@
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
       {
+#if POC_RESET_IDC_ENCODER
+        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+#else
         printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+#endif
       }
       else
       {
+#if POC_RESET_IDC_ENCODER
+        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
+#else
         printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
+#endif
       }
 #endif
@@ -3947,7 +4203,14 @@
     }
   }
+
+#if POC_RESET_IDC_ENCODER
+  if(m_pocCraWithoutReset > 0 && this->m_associatedIRAPType == NAL_UNIT_CODED_SLICE_CRA)
+  {
+    if(pocCurr < m_pocCraWithoutReset)
+#else
   if(m_pocCRA>0)
   {
     if(pocCurr<m_pocCRA)
+#endif
     {
       // All leading pictures are being marked as TFD pictures here since current encoder uses all 
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 798)
@@ -113,4 +113,8 @@
   Bool                    m_bRefreshPending;
   Int                     m_pocCRA;
+#if POC_RESET_IDC_ENCODER
+  Int                     m_pocCraWithoutReset;
+  Int                     m_associatedIrapPocBeforeReset;
+#endif
   std::vector<Int>        m_storedStartCUAddrForEncodingSlice;
   std::vector<Int>        m_storedStartCUAddrForEncodingSliceSegment;
@@ -152,4 +156,7 @@
   Int   **m_temp;
 #endif
+#if POC_RESET_IDC_ENCODER
+  Int   m_lastPocPeriodId;
+#endif
 #endif
   
@@ -170,4 +177,13 @@
 #else
   Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
+#endif
+#if POC_RESET_IDC_ENCODER
+  Void  determinePocResetIdc( Int const pocCurr, TComSlice *const slice);
+  Int   getIntraRefreshInterval()  { return m_pcCfg->getIntraPeriod(); }
+  Int   getIntraRefreshType()      { return m_pcCfg->getDecodingRefreshType(); }
+  // Int   getIntraRefreshInterval ()  { return (m_pcCfg) ? m_pcCfg->getIntraPeriod() : 0;  }
+  Int   getLastPocPeriodId()      { return m_lastPocPeriodId; }
+  Void  setLastPocPeriodId(Int x) { m_lastPocPeriodId = x;    }
+  Void  updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice);
 #endif
   Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 798)
@@ -89,5 +89,5 @@
 #endif
   m_numScaledRefLayerOffsets = 0;
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   m_pocAdjustmentValue     = 0;
 #endif
@@ -1208,4 +1208,9 @@
   m_cPPS.setCGSFlag( m_nCGSFlag );
 #endif
+#if POC_RESET_IDC_ENCODER
+  m_cPPS.setPocResetInfoPresentFlag( true );
+  m_cPPS.setExtensionFlag( true );
+  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
+#endif
 #endif //SVC_EXTENSION
 }
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 797)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 798)
@@ -142,5 +142,5 @@
   Bool                    m_vertPhasePositionEnableFlag[MAX_LAYERS];
 #endif
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   Int                     m_pocAdjustmentValue;
 #endif
@@ -257,5 +257,5 @@
   TEncTop*  getRefLayerEnc(UInt refLayerIdc);
 #endif
-#if POC_RESET_FLAG
+#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
   Int       getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
   Void      setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
