Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1587)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1588)
@@ -1487,5 +1487,5 @@
     Bool pocResettingFlag = false;
 
-    if( pcSlice->getPocResetIdc() != 0 )
+    if( pcSlice->getPocResetIdc() )
     {
       if( pcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
@@ -1511,5 +1511,5 @@
     {
       // 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 ) )        
+      if( ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == 2) && m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() >= 0 && ( pocCurr % m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() == 0 ) )        
       {
         m_pcEncTop->setPocAdjustmentValue( pocCurr );
@@ -3922,19 +3922,18 @@
   if( slice->getSliceIdx() == 0 ) // First slice - compute, copy for other slices
   {
-    Int needReset = false;
-    Int resetDueToBL = false;
+    Bool needReset = false, 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 )
-        )
+      if( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() > 0 && pocCurr && m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshInterval() >= 0 && ( 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) )
+        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;
@@ -3949,10 +3948,9 @@
     {
       // 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++)
+      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 && ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
+
+        for( Int j = 0; j < slice->getVPS()->getMaxLayers(); j++ )
         {
           if( j == i )
@@ -3961,7 +3959,5 @@
           }
 
-          Bool idrOtherPicFlag = ( (m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshType() == 2) 
-            && ( pocCurr % m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
-            );
+          Bool idrOtherPicFlag = m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshType() == 2 && pocCurr && m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() >= 0 && ( pocCurr % m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
 
           if( idrFlag != idrOtherPicFlag )
@@ -3973,4 +3969,5 @@
       }
     }
+
     if( needReset )
     {
@@ -3997,8 +3994,8 @@
 
       // 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
+      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 ;
+        m_lastPocPeriodId = periodId == m_lastPocPeriodId ? (periodId + 1) % 64 : periodId;
 
         for( UInt i = 0; i < m_pcCfg->getNumLayer(); i++ )
