Index: /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 652)
@@ -257,5 +257,5 @@
       Bool outputPicturesFlag = true;  
 #if NO_OUTPUT_OF_PRIOR_PICS
-      if( m_acTDecTop[nalu.m_layerId].getNoOutputOfPriorPicsFlags() )
+      if( m_acTDecTop[nalu.m_layerId].getNoOutputPriorPicsFlag() )
       {
         outputPicturesFlag = false;
@@ -449,4 +449,12 @@
       loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
     }
+#if !FIX_WRITING_OUTPUT
+#if SETTING_NO_OUT_PIC_PRIOR
+    if (bNewPicture && m_cTDecTop.getNoOutputPriorPicsFlag())
+    {
+      m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+    }
+#endif
+#endif
 
     if( pcListPic )
@@ -460,4 +468,18 @@
         openedReconFile = true;
       }
+#if FIX_WRITING_OUTPUT
+      // write reconstruction to file
+      if( bNewPicture )
+      {
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+      }
+#if SETTING_NO_OUT_PIC_PRIOR
+      if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() )
+      {
+        m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+        m_cTDecTop.setNoOutputPriorPicsFlag (false);
+      }
+#endif
+#endif
       if ( bNewPicture &&
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
@@ -471,8 +493,16 @@
       if (nalu.m_nalUnitType == NAL_UNIT_EOS)
       {
+#if FIX_OUTPUT_EOS
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+#else
         xFlushOutput( pcListPic );        
-      }
-      // write reconstruction to file
+#endif
+      }
+      // write reconstruction to file -- for additional bumping as defined in C.5.2.3
+#if FIX_WRITING_OUTPUT
+      if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31)
+#else
       if(bNewPicture)
+#endif
       {
         xWriteOutput( pcListPic, nalu.m_temporalId );
@@ -586,4 +616,24 @@
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
   Int numPicsNotYetDisplayed = 0;
+  Int dpbFullness = 0;
+#if SVC_EXTENSION
+TComSPS* activeSPS = m_acTDecTop[layerId].getActiveSPS();
+#else
+  TComSPS* activeSPS = m_cTDecTop.getActiveSPS();
+#endif
+  UInt numReorderPicsHighestTid;
+  UInt maxDecPicBufferingHighestTid;
+  UInt maxNrSublayers = activeSPS->getMaxTLayers();
+
+  if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers)
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1);
+    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); 
+  }
+  else
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer);
+    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); 
+  }
 
   while (iterPic != pcListPic->end())
@@ -597,4 +647,9 @@
     {
       numPicsNotYetDisplayed++;
+      dpbFullness++;
+    }
+    else if(pcPic->getSlice( 0 )->isReferenced())
+    {
+      dpbFullness++;
     }
     iterPic++;
@@ -619,9 +674,13 @@
 
 #if SVC_EXTENSION
-      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
-        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0)))
-#else
-      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
-        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
+      if( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
+        (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&        
+        (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0) )
+#else
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
+          (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
+          (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
+          (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0))
 #endif
       {
@@ -720,13 +779,19 @@
 
 #if SVC_EXTENSION
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
-#else
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+      if( pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId] &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) )
+#else
+      if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
 #endif
       {
         // write to file
         numPicsNotYetDisplayed--;
-#if SVC_EXTENSION
-        if ( m_pchReconFile[layerId] )
+        if(pcPic->getSlice(0)->isReferenced() == false)
+        {
+          dpbFullness--;
+        }
+#if SVC_EXTENSION
+        if( m_pchReconFile[layerId] )
         {
           const Window &conf = pcPic->getConformanceWindow();
Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 652)
@@ -710,5 +710,9 @@
   ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR 3:RecPointSEI)")
+#else
   ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
+#endif
   ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
   // motion options
@@ -905,4 +909,6 @@
   ("SEIToneMapCameraIsoSpeedIdc",                     m_cameraIsoSpeedIdc,                        0, "Indicates the camera ISO speed for daylight illumination")
   ("SEIToneMapCameraIsoSpeedValue",                   m_cameraIsoSpeedValue,                    400, "Specifies the camera ISO speed for daylight illumination of Extended_ISO")
+  ("SEIToneMapExposureIndexIdc",                      m_exposureIndexIdc,                         0, "Indicates the exposure index setting of the camera")
+  ("SEIToneMapExposureIndexValue",                    m_exposureIndexValue,                     400, "Specifies the exposure index setting of the cameran of Extended_ISO")
   ("SEIToneMapExposureCompensationValueSignFlag",     m_exposureCompensationValueSignFlag,        0, "Specifies the sign of ExposureCompensationValue")
   ("SEIToneMapExposureCompensationValueNumerator",    m_exposureCompensationValueNumerator,       0, "Specifies the numerator of ExposureCompensationValue")
@@ -1587,5 +1593,13 @@
   xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 3,                   "Decoding Refresh Type must be comprised between 0 and 3 included" );
+  if(m_iDecodingRefreshType == 3)
+  {
+    xConfirmPara( !m_recoveryPointSEIEnabled,                                               "When using RecoveryPointSEI messages as RA points, recoveryPointSEI must be enabled" );
+  }
+#else
   xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#endif
 #if !SVC_EXTENSION
   xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
@@ -2160,4 +2174,5 @@
     xConfirmPara( m_toneMapModelId < 0 || m_toneMapModelId > 4 , "SEIToneMapModelId must be in rage 0 to 4");
     xConfirmPara( m_cameraIsoSpeedValue == 0, "SEIToneMapCameraIsoSpeedValue shall not be equal to 0");
+    xConfirmPara( m_exposureIndexValue  == 0, "SEIToneMapExposureIndexValue shall not be equal to 0");
     xConfirmPara( m_extendedRangeWhiteLevel < 100, "SEIToneMapExtendedRangeWhiteLevel should be greater than or equal to 100");
     xConfirmPara( m_nominalBlackLevelLumaCodeValue >= m_nominalWhiteLevelLumaCodeValue, "SEIToneMapNominalWhiteLevelLumaCodeValue shall be greater than SEIToneMapNominalBlackLevelLumaCodeValue");
Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 651)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 652)
@@ -255,4 +255,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
Index: /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 652)
@@ -767,4 +767,6 @@
   m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
   m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
+  m_cTEncTop.setTMISEIExposureIndexIdc                    ( m_exposureIndexIdc );
+  m_cTEncTop.setTMISEIExposureIndexValue                  ( m_exposureIndexValue );
   m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
   m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/CommonDef.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/CommonDef.h	(revision 652)
@@ -60,5 +60,5 @@
 #define NV_VERSION        "5.1 (HM-13.0)"                 ///< Current software version
 #else
-#define NV_VERSION        "13.0"                ///< Current software version
+#define NV_VERSION        "14.0"                ///< Current software version
 #endif
 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/SEI.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/SEI.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/SEI.h	(revision 652)
@@ -142,6 +142,6 @@
   SEIActiveParameterSets() 
     : activeVPSId            (0)
-    , m_fullRandomAccessFlag (false)
-    , m_noParamSetUpdateFlag (false)
+    , m_selfContainedCvsFlag (false)
+    , m_noParameterSetUpdateFlag (false)
     , numSpsIdsMinus1        (0)
   {}
@@ -149,8 +149,8 @@
 
   Int activeVPSId; 
-  Bool m_fullRandomAccessFlag;
-  Bool m_noParamSetUpdateFlag;
+  Bool m_selfContainedCvsFlag;
+  Bool m_noParameterSetUpdateFlag;
   Int numSpsIdsMinus1;
-  std::vector<Int> activeSeqParamSetId; 
+  std::vector<Int> activeSeqParameterSetId; 
 };
 
@@ -393,4 +393,6 @@
   Int    m_cameraIsoSpeedIdc;
   Int    m_cameraIsoSpeedValue;
+  Int    m_exposureIndexIdc;
+  Int    m_exposureIndexValue;
   Int    m_exposureCompensationValueSignFlag;
   Int    m_exposureCompensationValueNumerator;
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 652)
@@ -1690,68 +1690,4 @@
 }
 
-
-#if FAST_INTRA_SHVC
-/** generate limited set of remaining modes
-*\param   uiAbsPartIdx
-*\param   uiIntraDirPred  pointer to the array for MPM storage
-*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
-*/
-Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
-{
-  // check BL mode
-  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
-  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
-  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
-
-  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
-  {
-    return( NUM_INTRA_MODE-1 );
-  }
-
-  // compute set of enabled modes g_reducedSetIntraModes[...]
-  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
-  Int nbModes;
-  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
-  {
-    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
-    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
-  }
-
-  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
-  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
-  {
-    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
-    authorizedMode[ iColBaseDir ] = 0;
-  }
-
-  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
-  if ( iRefMode > 1 )    //add neighboring modes of refMode
-  {
-    UInt Left  = iRefMode;
-    UInt Right = iRefMode;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      Left = ((Left + 29) % 32) + 2;
-      Right = ((Right - 1 ) % 32) + 2;
-      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
-      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
-    }
-  }
-  else      //add pre-defined modes
-  {
-    Int  idx = 0;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      UInt mode = g_predefSetIntraModes[idx++];
-      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
-    }
-  }
-
-  fullSetOfModes = 0;
-  return ( nbModes );
-}
-#endif
-
-
 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
 {
@@ -1809,67 +1745,4 @@
   return log2MinTUSizeInCU;
 }
-
-#if REF_IDX_ME_ZEROMV
-Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkZeroMVILR = true;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
-    }
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
-    }
-  }
-
-  return checkZeroMVILR;
-}
-
-Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
-{
-  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
-  assert(eRefPicList == REF_PIC_LIST_1);
-
-  Bool checkZeroMVILR = true;
-
-  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
-  {
-    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
-    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
-    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
-  }
-
-  return checkZeroMVILR;
-}
-#endif
-
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkILR = false;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
-  }
-
-  return checkILR;
-}
-#endif
 
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
@@ -2168,5 +2041,5 @@
 }
 
-UChar TComDataCU::getNumPartInter()
+UChar TComDataCU::getNumPartitions()
 {
   UChar iNumPart = 0;
@@ -3680,4 +3553,130 @@
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
 }
+
+#if FAST_INTRA_SHVC
+/** generate limited set of remaining modes
+*\param   uiAbsPartIdx
+*\param   uiIntraDirPred  pointer to the array for MPM storage
+*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
+*/
+Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
+{
+  // check BL mode
+  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
+  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
+
+  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
+  {
+    return( NUM_INTRA_MODE-1 );
+  }
+
+  // compute set of enabled modes g_reducedSetIntraModes[...]
+  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+  Int nbModes;
+  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
+  {
+    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
+    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
+  }
+
+  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
+  {
+    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
+    authorizedMode[ iColBaseDir ] = 0;
+  }
+
+  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
+  if ( iRefMode > 1 )    //add neighboring modes of refMode
+  {
+    UInt Left  = iRefMode;
+    UInt Right = iRefMode;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      Left = ((Left + 29) % 32) + 2;
+      Right = ((Right - 1 ) % 32) + 2;
+      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
+      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
+    }
+  }
+  else      //add pre-defined modes
+  {
+    Int  idx = 0;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      UInt mode = g_predefSetIntraModes[idx++];
+      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
+    }
+  }
+
+  fullSetOfModes = 0;
+  return ( nbModes );
+}
+#endif
+
+#if REF_IDX_ME_ZEROMV
+Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkZeroMVILR = true;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+    }
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+    }
+  }
+
+  return checkZeroMVILR;
+}
+
+Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
+{
+  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
+  assert(eRefPicList == REF_PIC_LIST_1);
+
+  Bool checkZeroMVILR = true;
+
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
+  {
+    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
+    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
+    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+#endif
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkILR = false;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
+  }
+
+  return checkILR;
+}
+#endif
+
 #endif //SVC_EXTENSION
 //! \}
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 652)
@@ -352,5 +352,5 @@
   
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
-  UChar         getNumPartInter       ();
+  UChar         getNumPartitions       ();
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
   
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComMotionInfo.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComMotionInfo.h	(revision 652)
@@ -141,9 +141,4 @@
   Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
 
-#if AVC_SYNTAX
-  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
-  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
-#endif
-
   Void setNumPartition( Int iNumPart )
   {
@@ -159,4 +154,9 @@
   
   Void compress(Char* pePredMode, Int scale); 
+
+#if AVC_SYNTAX
+  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
+  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
+#endif
 
 #if REF_IDX_MFM
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComPic.h	(revision 652)
@@ -115,4 +115,5 @@
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
+
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 652)
@@ -447,5 +447,5 @@
   }
 
-  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
   {
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 652)
@@ -112,6 +112,7 @@
     m_offsetClipTable[compIdx] = NULL;
   }
+#if !SAO_SGN_FUNC
   m_signTable = NULL; 
-
+#endif
   
   m_lineBufWidth = 0;
@@ -169,5 +170,8 @@
   }
 
+#if !SAO_SGN_FUNC
   //look-up table for clipping
+  Int overallMaxSampleValue=0;
+#endif
   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
   {
@@ -179,4 +183,7 @@
     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
 #endif
+#if !SAO_SGN_FUNC
+    if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue;
+#endif
 
     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
@@ -194,18 +201,17 @@
       *(offsetClipPtr -k -1 )              = 0;
     }
-    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
-    {
-      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
-      m_sign = &(m_signTable[maxSampleValue-1]);
-
-      m_sign[0] = 0;
-      for(Int k=1; k< maxSampleValue; k++)
-      {
-        m_sign[k] = 1;
-        m_sign[-k]= -1;
-      }
-    }
-  }  
-
+  }
+
+#if !SAO_SGN_FUNC
+  m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ];
+  m_sign = &(m_signTable[overallMaxSampleValue-1]);
+
+  m_sign[0] = 0;
+  for(Int k=1; k< overallMaxSampleValue; k++)
+  {
+    m_sign[k] = 1;
+    m_sign[-k]= -1;
+  }
+#endif
 }
 
@@ -226,8 +232,10 @@
     }
   }
+#if !SAO_SGN_FUNC
   if( m_signTable )
   {
     delete[] m_signTable; m_signTable = NULL;
   }
+#endif
 }
 
@@ -406,8 +414,16 @@
       for (y=0; y< height; y++)
       {
+#if SAO_SGN_FUNC
+        signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
         signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
         for (x=startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 
+#else
           signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
           edgeType =  signRight + signLeft;
           signLeft  = -signRight;
@@ -437,5 +453,9 @@
       for (x=0; x< width; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
         signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
       }
 
@@ -447,5 +467,9 @@
         for (x=0; x< width; x++)
         {
+#if SAO_SGN_FUNC
+          signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
+#else
           signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
           edgeType = signDown + signUpLine[x];
           signUpLine[x]= -signDown;
@@ -474,5 +498,9 @@
       for (x=startX; x< endX+1; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
+#endif
       }
 
@@ -483,5 +511,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType  =  sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1];
+#else
         edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -497,5 +529,9 @@
         for (x=startX; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
@@ -503,5 +539,9 @@
           signDownLine[x+1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
         signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
         signTmpLine  = signUpLine;
@@ -519,5 +559,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType =  sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x];
+#else
         edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
@@ -537,5 +581,9 @@
       for (x=startX-1; x< endX; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
       }
 
@@ -547,5 +595,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1];
+#else
         edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -560,10 +612,18 @@
         for(x= startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
           signUpLine[x-1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
         signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
         srcLine  += srcStride;
         resLine += resStride;
@@ -576,5 +636,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x];
+#else
         edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 652)
@@ -56,4 +56,10 @@
 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
 #endif
+#if SAO_SGN_FUNC
+template <typename T> int sgn(T val) 
+{
+  return (T(0) < val) - (val < T(0));
+}
+#endif
 
 class TComSampleAdaptiveOffset
@@ -88,5 +94,7 @@
   UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step  
   Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
+#if !SAO_SGN_FUNC
   Short* m_sign; //sign table for fast operation
+#endif
   TComPicYuv*   m_tempPicYuv; //temporary buffer
   Int m_picWidth;
@@ -105,5 +113,7 @@
   Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
   Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
+#if !SAO_SGN_FUNC
   Short* m_signTable;
+#endif
 #if SVC_EXTENSION
   UInt m_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 652)
@@ -75,4 +75,9 @@
 , m_pcPic                         ( NULL )
 , m_colFromL0Flag                 ( 1 )
+#if SETTING_NO_OUT_PIC_PRIOR
+, m_noOutputPriorPicsFlag         ( false )
+, m_noRaslOutputFlag              ( false )
+, m_handleCraAsBlaFlag            ( false )
+#endif
 , m_colRefIdx                     ( 0 )
 , m_uiTLayer                      ( 0 )
@@ -111,9 +116,4 @@
 , m_bCrossLayerBLAFlag            ( false )
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-, m_noOutputOfPriorPicsFlag       ( false )
-, m_noRaslOutputFlag              ( false )
-, m_handleCraAsBlaFlag            ( false )
-#endif
 #if POC_RESET_IDC_SIGNALLING
 , m_pocResetIdc                   ( 0 )
@@ -596,10 +596,10 @@
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
 #if SVC_EXTENSION    // inter-layer prediction is allowed for BLA, CRA pictures of nuh_layer_id>0
-    // – If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // - If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag() && getLayerId()==0)
 #else
-    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
 #endif
@@ -1051,7 +1051,31 @@
       pocCRA = pocCurr;
     }
+#if EFFICIENT_FIELD_IRAP
+    bRefreshPending = true;
+#endif
   }
   else // CRA or No DR
   {
+#if EFFICIENT_FIELD_IRAP
+    if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+    {
+      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending 
+      {
+        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
+        while (iterPic != rcListPic.end())
+        {
+          rpcPic = *(iterPic);
+          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
+          {
+            rpcPic->getSlice(0)->setReferenced(false);
+          }
+          iterPic++;
+        }
+        bRefreshPending = false; 
+      }
+    }
+    else
+    {
+#endif
     if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending 
     {
@@ -1068,4 +1092,7 @@
       bRefreshPending = false; 
     }
+#if EFFICIENT_FIELD_IRAP
+    }
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     {
@@ -1323,5 +1350,9 @@
     // in decoding order shall precede the IRAP picture in output order.
     // (Note that any picture following in output order would be present in the DPB)
+#if !SETTING_NO_OUT_PIC_PRIOR
     if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+#else
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
+#endif
     {
       if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
@@ -1502,6 +1533,14 @@
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
-{
+#endif
+{
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int atLeastOneUnabledByRecoveryPoint = 0;
+  Int atLeastOneFlushedByPreviousIDR = 0;
+#endif
   TComPic* rpcPic;
   Int i, isAvailable;
@@ -1524,5 +1563,16 @@
         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1534,5 +1584,16 @@
         if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1557,7 +1618,20 @@
         if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
           rpcPic->setIsLongTerm(1);
           break;
+        }
+#else
+          isAvailable = 1;
+          rpcPic->setIsLongTerm(1);
+          break;
+#endif
         }
       }
@@ -1587,4 +1661,14 @@
         }
       }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
     }
   }  
@@ -1602,5 +1686,16 @@
       if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
       {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+        {
+          isAvailable = 0;
+        }
+        else
+        {
         isAvailable = 1;
+      }
+#else
+        isAvailable = 1;
+#endif
       }
     }
@@ -1629,6 +1724,22 @@
         }
       }
-    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
+    }
+    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
+  {
+    return -1;
   }    
+#endif
   if(atLeastOneLost)
   {
@@ -1647,5 +1758,9 @@
 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
+#endif
 {
   TComPic* rpcPic;
@@ -1673,4 +1788,7 @@
         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
+#endif
         if(pcRPS->getDeltaPOC(k) < 0)
         {
@@ -1685,4 +1803,24 @@
     }
   }
+#if EFFICIENT_FIELD_IRAP
+  Bool useNewRPS = false;
+  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS. 
+  if(m_pcPic->isField())
+  {
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while ( iterPic != rcListPic.end())
+    {
+      rpcPic = *(iterPic++);
+      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
+      {
+        pcRPS->setDeltaPOC(k, 1);
+        pcRPS->setUsed(k, true);
+        nrOfPositivePictures++;
+        k ++;
+        useNewRPS = true;
+      }
+    }
+  }
+#endif
   pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
   pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
@@ -1691,5 +1829,9 @@
   // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
   // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
-  if (!pReferencePictureSet->getInterRPSPrediction())
+  if (!pReferencePictureSet->getInterRPSPrediction()
+#if EFFICIENT_FIELD_IRAP
+    || useNewRPS
+#endif
+    )
   {
     pcRPS->setInterRPSPrediction(false);
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 652)
@@ -231,5 +231,5 @@
 {
   ProfileTierLevel m_generalPTL;
-  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 ( = 6 )
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
   Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
   Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
@@ -1963,4 +1963,10 @@
   UInt        m_colFromL0Flag;  // collocated picture from List0 flag
   
+#if SETTING_NO_OUT_PIC_PRIOR
+  Bool        m_noOutputPriorPicsFlag;
+  Bool        m_noRaslOutputFlag;
+  Bool        m_handleCraAsBlaFlag;
+#endif
+  
   UInt        m_colRefIdx;
   UInt        m_maxNumMergeCand;
@@ -2029,9 +2035,4 @@
 #if O0149_CROSS_LAYER_BLA_FLAG
   Bool        m_bCrossLayerBLAFlag;
-#endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool        m_noOutputOfPriorPicsFlag;
-  Bool        m_noRaslOutputFlag;
-  Bool        m_handleCraAsBlaFlag;
 #endif
 #if POC_RESET_IDC_SIGNALLING
@@ -2130,8 +2131,4 @@
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool      getBlaPicFlag       ();
-  Bool      getCraPicFlag       ();
-#endif
   Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
@@ -2203,9 +2200,25 @@
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
-  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
-  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+#else
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#endif
 
   Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
   UInt getMaxNumMergeCand               ()                  { return m_maxNumMergeCand;                   }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+  Void setNoOutputPriorPicsFlag         ( Bool val )        { m_noOutputPriorPicsFlag = val;                    }
+  Bool getNoOutputPriorPicsFlag         ()                  { return m_noOutputPriorPicsFlag;                   }
+
+  Void setNoRaslOutputFlag              ( Bool val )        { m_noRaslOutputFlag = val;                    }
+  Bool getNoRaslOutputFlag              ()                  { return m_noRaslOutputFlag;                   }
+
+  Void setHandleCraAsBlaFlag            ( Bool val )        { m_handleCraAsBlaFlag = val;                    }
+  Bool getHandleCraAsBlaFlag            ()                  { return m_handleCraAsBlaFlag;                   }
+#endif
 
   Void setSliceMode                     ( UInt uiMode )     { m_sliceMode = uiMode;                     }
@@ -2360,15 +2373,4 @@
 
   Void setILRPic(TComPic **pcIlpPic);
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Void setNoOutputOfPriorPicsFlag(const Bool x)   { m_noOutputOfPriorPicsFlag = x;    }
-  Bool getNoOutputOfPriorPicsFlag()               { return m_noOutputOfPriorPicsFlag; }
-
-  Void setNoRaslOutputFlag    ( const Bool val )   { m_noRaslOutputFlag = val;  }
-  Bool getNoRaslOutputFlag    ()                   { return m_noRaslOutputFlag; }
-
-  Void setHandleCraAsBlaFlag  ( const Bool val )   { m_handleCraAsBlaFlag = val;  }
-  Bool getHandleCraAsBlaFlag  ()                   { return m_handleCraAsBlaFlag; }
-
-#endif
 #if POC_RESET_IDC_SIGNALLING
   Int       getPocResetIdc       ()                              { return m_pocResetIdc;       }
@@ -2388,4 +2390,9 @@
 #endif
 
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Bool      getBlaPicFlag       ();
+  Bool      getCraPicFlag       ();
+#endif
+
 #endif //SVC_EXTENSION
 protected:
Index: /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 652)
@@ -264,8 +264,22 @@
 //! \ingroup TLibCommon
 //! \{
+#define HARMONIZE_GOP_FIRST_FIELD_COUPLE  1
+#define FIX_FIELD_DEPTH                 1
+#define EFFICIENT_FIELD_IRAP            1
+#define ALLOW_RECOVERY_POINT_AS_RAP     1
 #define BUGFIX_INTRAPERIOD 1
 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
 
+#define SAO_SGN_FUNC 1
+
 #define FIX1172 1 ///< fix ticket #1172
+
+#define SETTING_PIC_OUTPUT_MARK     1
+#define SETTING_NO_OUT_PIC_PRIOR    1
+#define FIX_EMPTY_PAYLOAD_NAL       1
+#define FIX_WRITING_OUTPUT          1
+#define FIX_OUTPUT_EOS              1
+
+#define FIX_POC_CRA_NORASL_OUTPUT   1
 
 #define MAX_NUM_PICS_IN_SOP           1024
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/AnnexBread.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/AnnexBread.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/AnnexBread.h	(revision 652)
@@ -65,5 +65,5 @@
   , m_Input(istream)
   {
-    istream.exceptions(std::istream::eofbit);
+    istream.exceptions(std::istream::eofbit | std::istream::badbit);
   }
 
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 652)
@@ -518,21 +518,16 @@
 {
   UInt val; 
-  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
-  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
-  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
+  READ_CODE(4, val, "active_video_parameter_set_id");   sei.activeVPSId = val; 
+  READ_FLAG(   val, "self_contained_cvs_flag");         sei.m_selfContainedCvsFlag = val ? true : false;
+  READ_FLAG(   val, "no_parameter_set_update_flag");    sei.m_noParameterSetUpdateFlag = val ? true : false;
   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
 
-  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
+  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
   for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
   {
-    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val; 
-  }
-
-  UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 
-  
-  while(uibits--)
-  {
-    READ_FLAG(val, "alignment_bit");
-  }
+    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
+  }
+
+  xParseByteAlign();
 }
 
@@ -812,8 +807,13 @@
     case 4:
       {
-        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
-        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
+        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedIdc = val;
+        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
         {
           READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
+        }
+        READ_CODE( 8, val, "exposure_index_idc" );                       sei.m_exposureIndexIdc = val;
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          READ_CODE( 32,   val,   "exposure_index_value" );              sei.m_exposureIndexValue = val;
         }
         READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 652)
@@ -681,9 +681,9 @@
     for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     {
-      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
+      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
       pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-      READ_UVLC ( uiCode, "sps_num_reorder_pics" );
+      READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
       pcSPS->setNumReorderPics(uiCode, i);
-      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
+      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
       pcSPS->setMaxLatencyIncrease( uiCode, i );
 
@@ -887,5 +887,5 @@
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
 #endif
-  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode <= 6);
+  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode+1 <= MAX_TLAYER);
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
@@ -2102,8 +2102,9 @@
   if( rpcSlice->getRapPicFlag())
   {
-#if !NO_OUTPUT_OF_PRIOR_PICS
-    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
-#else
-    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  rpcSlice->setNoOutputOfPriorPicsFlag( uiCode ? true : false );
+    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
+#if SETTING_NO_OUT_PIC_PRIOR
+    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
+#else
+    rpcSlice->setNoOutputPicPrior( false );
 #endif
   }
@@ -2305,5 +2306,5 @@
         else
         {
-          uiCode = 0;
+          uiCode = 0;       
         }
         *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 652)
@@ -715,5 +715,5 @@
 {
   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
-  UInt  uiNumPart     = pcCU->getNumPartInter();
+  UInt  uiNumPart     = pcCU->getNumPartitions();
   UInt  uiNumQParts   = pcCU->getTotalNumPart() >> 2;
   
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 652)
@@ -248,5 +248,9 @@
   }
 
+#if SETTING_PIC_OUTPUT_MARK
+  rpcPic->setOutputMark(rpcPic->getSlice(0)->getPicOutputFlag() ? true : false);
+#else
   rpcPic->setOutputMark(true);
+#endif
   rpcPic->setReconMark(true);
 }
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 652)
@@ -79,9 +79,13 @@
   m_prevSliceSkipped = false;
   m_skippedPOC = 0;
-#if NO_CLRAS_OUTPUT_FLAG
-  m_noClrasOutputFlag          = false;
+#if SETTING_NO_OUT_PIC_PRIOR
+  m_bFirstSliceInBitstream  = true;
+  m_lastPOCNoOutputPriorPics = -1;
+  m_craNoRaslOutputFlag = false;
+  m_isNoOutputPriorPics = false;
+#endif
+#if NO_CLRAS_OUTPUT_FLAG  
   m_layerInitializedFlag       = false;
-  m_firstPicInLayerDecodedFlag = false;
-  m_noOutputOfPriorPicsFlags   = false;
+  m_firstPicInLayerDecodedFlag = false;  
   m_bRefreshPending            = false;
 #endif
@@ -503,5 +507,4 @@
 
   // Execute Deblock + Cleanup
-
   m_cGopDecoder.filterPicture(pcPic);
 
@@ -517,4 +520,22 @@
   return;
 }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
+{
+  if (!rpcListPic || !m_isNoOutputPriorPics) return;
+
+  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
+
+  while (iterPic != rpcListPic->end())
+  {
+    TComPic*& pcPicTmp = *(iterPic++);
+    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
+    {
+      pcPicTmp->setOutputMark(false);
+    }
+  }
+}
+#endif
 
 #if EARLY_REF_PIC_MARKING
@@ -843,9 +864,4 @@
   TComPic*&   pcPic         = m_pcPic;
 #if SVC_EXTENSION
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  Bool bFirstSliceInSeq;
-#endif
-#endif
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
 #if OUTPUT_LAYER_SET_INDEX
@@ -900,18 +916,57 @@
   m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
 
-#if NO_OUTPUT_OF_PRIOR_PICS
-  // Infer the value of NoOutputOfPriorPicsFlag
-  if( m_apcSlicePilot->getRapPicFlag() )
-  {
-    if ( m_apcSlicePilot->getBlaPicFlag() || m_apcSlicePilot->getIdrPicFlag()  || 
-        (m_apcSlicePilot->getCraPicFlag() && m_bFirstSliceInSequence) ||
-        (m_apcSlicePilot->getCraPicFlag() && m_apcSlicePilot->getHandleCraAsBlaFlag()))
-    {
-      m_apcSlicePilot->setNoRaslOutputFlag( true );
+#if SETTING_NO_OUT_PIC_PRIOR
+  //For inference of NoOutputOfPriorPicsFlag
+  if (m_apcSlicePilot->getRapPicFlag())
+  {
+    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
+        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
+    {
+      m_apcSlicePilot->setNoRaslOutputFlag(true);
+    }
+    //the inference for NoOutputPriorPicsFlag
+    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
+    {
+      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+      {
+        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
+      }
     }
     else
     {
-      m_apcSlicePilot->setNoRaslOutputFlag( false );
-    }
+      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
+    }
+
+    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+    {
+      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
+    }
+  }
+  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
+  {
+    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
+    m_isNoOutputPriorPics = true;
+  }
+  else
+  {
+    m_isNoOutputPriorPics = false;
+  }
+
+  //For inference of PicOutputFlag
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
+  {
+    if ( m_craNoRaslOutputFlag )
+    {
+      m_apcSlicePilot->setPicOutputFlag(false);
+    }
+  }
+#endif
+
+#if FIX_POC_CRA_NORASL_OUTPUT
+  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
+  {
+    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
   }
 #endif
@@ -975,9 +1030,9 @@
     if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
     {
-      this->setNoOutputOfPriorPicsFlags( true );
+      this->setNoOutputPriorPicsFlag( true );
     }
     else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
     {
-      this->setNoOutputOfPriorPicsFlags( m_apcSlicePilot->getNoOutputOfPriorPicsFlag() );
+      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
     }
     else
@@ -985,5 +1040,5 @@
       if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
       {
-        this->setNoOutputOfPriorPicsFlags( true );
+        this->setNoOutputPriorPicsFlag( true );
       }
     }
@@ -1006,5 +1061,5 @@
 #else
   //we should only get a different poc for a new picture (with CTU address==0)
-  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
+  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
   {
     printf ("Warning, the first slice of a picture might have been lost!\n");
@@ -1050,10 +1105,8 @@
 #endif
   }
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  bFirstSliceInSeq = m_bFirstSliceInSequence;
-#endif
-#endif
   m_bFirstSliceInSequence = false;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  m_bFirstSliceInBitstream  = false;
+#endif
 #if POC_RESET_FLAG
   // This operation would do the following:
@@ -1216,50 +1269,5 @@
 #endif
 
-#if !NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-    if (m_layerId == 0 &&
-        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
-      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
-    {
-      if (bFirstSliceInSeq)
-      {
-        setNoClrasOutputFlag(true);
-      }
-      else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
-      {
-        setNoClrasOutputFlag(true);
-      }
-#if O0149_CROSS_LAYER_BLA_FLAG
-      else if ((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
-               m_apcSlicePilot->getCrossLayerBLAFlag())
-      {
-        setNoClrasOutputFlag(true);
-      }
-#endif
-      else
-      {
-        setNoClrasOutputFlag(false);
-      }
-      if (getNoClrasOutputFlag())
-      {
-        for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
-        {
-          m_ppcTDecTop[i]->setLayerInitializedFlag(false);
-          m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
-        }
-      }
-    }
-#endif
-
-#if NO_CLRAS_OUTPUT_FLAG
-    m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
-#endif
-#else
+#if NO_OUTPUT_OF_PRIOR_PICS
     if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
     {
@@ -1273,8 +1281,8 @@
     // Buffer initialize for prediction.
     m_cPrediction.initTempBuff();
-#if !ALIGNED_BUMPING
+#if ALIGNED_BUMPING
+    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
+#else
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
-#else
-    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
 #endif
     //  Get a new picture buffer
@@ -1809,6 +1817,6 @@
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
       m_parameterSetManagerDecoder.applyPrefetchedPS();
-      assert(seiAps->activeSeqParamSetId.size()>0);
-      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParamSetId[0] ) )
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
@@ -1837,6 +1845,6 @@
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
       m_parameterSetManagerDecoder.applyPrefetchedPS();
-      assert(seiAps->activeSeqParamSetId.size()>0);
-      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
@@ -1997,4 +2005,6 @@
       return false;
       
+    case NAL_UNIT_FILLER_DATA:
+      return false;
       
     case NAL_UNIT_RESERVED_VCL_N10:
@@ -2017,5 +2027,4 @@
     case NAL_UNIT_RESERVED_VCL31:
       
-    case NAL_UNIT_FILLER_DATA:
     case NAL_UNIT_RESERVED_NVCL41:
     case NAL_UNIT_RESERVED_NVCL42:
Index: /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 652)
@@ -104,4 +104,10 @@
   Bool                    m_prevSliceSkipped;
   Int                     m_skippedPOC;
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Bool                    m_bFirstSliceInBitstream;
+  Int                     m_lastPOCNoOutputPriorPics;
+  Bool                    m_isNoOutputPriorPics;
+  Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
+#endif
 
 #if SVC_EXTENSION
@@ -136,15 +142,12 @@
 #endif
 
-#if NO_CLRAS_OUTPUT_FLAG
-  Bool                    m_noClrasOutputFlag;
+#if NO_CLRAS_OUTPUT_FLAG  
   Bool                    m_layerInitializedFlag;
   Bool                    m_firstPicInLayerDecodedFlag;
-  Bool                    m_noOutputOfPriorPicsFlags;
-
-  Bool                   m_bRefreshPending;
+  Bool                    m_bRefreshPending;
 #endif
 #if RESOLUTION_BASED_DPB
-  Int                    m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
-                                          // When new VPS is activated, this should be re-initialized to -1
+  Int                     m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
+                                           // When new VPS is activated, this should be re-initialized to -1
 #endif
 public:
@@ -166,5 +169,15 @@
   Void  deletePicBuffer();
 
+  
+  TComSPS* getActiveSPS() { return m_parameterSetManagerDecoder.getActiveSPS(); }
+
+
   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
+#if SETTING_NO_OUT_PIC_PRIOR  
+  Void  checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic);
+  Bool  getNoOutputPriorPicsFlag ()         { return m_isNoOutputPriorPics; }
+  Void  setNoOutputPriorPicsFlag (Bool val) { m_isNoOutputPriorPics = val; }
+#endif
+
 #if SVC_EXTENSION
 #if EARLY_REF_PIC_MARKING
@@ -239,10 +252,4 @@
   fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-#if NO_CLRAS_OUTPUT_FLAG
-  Bool getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
-  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
-#endif
-#endif
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
@@ -265,14 +272,10 @@
 
 #if NO_CLRAS_OUTPUT_FLAG
-  Int  getNoClrasOutputFlag()                { return m_noClrasOutputFlag;}
-  Void setNoClrasOutputFlag(Bool x)          { m_noClrasOutputFlag = x;   }
+  Int  getNoClrasOutputFlag()                { return m_craNoRaslOutputFlag;}
+  Void setNoClrasOutputFlag(Bool x)          { m_craNoRaslOutputFlag = x;   }
   Int  getLayerInitializedFlag()             { return m_layerInitializedFlag;}
   Void setLayerInitializedFlag(Bool x)       { m_layerInitializedFlag = x;   }
   Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
   Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
-#if !NO_OUTPUT_OF_PRIOR_PICS
-  Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
-  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
-#endif
 #endif
 };// END CLASS DEFINITION TDecTop
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/AnnexBwrite.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/AnnexBwrite.h	(revision 652)
@@ -58,5 +58,5 @@
 
     static const Char start_code_prefix[] = {0,0,0,1};
-    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
+    if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_VPS || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
     {
       /* From AVC, When any of the following conditions are fulfilled, the
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/NALwrite.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/NALwrite.cpp	(revision 652)
@@ -91,7 +91,8 @@
   vector<uint8_t>& rbsp   = nalu.m_Bitstream.getFIFO();
 
-#if P0130_EOB
-  if (rbsp.size() == 0) return;
-#endif
+  if (rbsp.size() == 0)
+  {
+    return;
+  }
 
   for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 652)
@@ -333,27 +333,16 @@
 Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
 {
-  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
-  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
-  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
+  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
+  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
+  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
   WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
 
-  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));
-
-  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
-  {
-    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
-  }
-
-  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
-  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8;  
-  if(uiAlignedBits) 
-  {
-    WRITE_FLAG(1, "alignment_bit" );
-    uiAlignedBits--; 
-    while(uiAlignedBits--)
-    {
-      WRITE_FLAG(0, "alignment_bit" );
-    }
-  }
+  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));
+
+  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
+  {
+    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
+  }
+  xWriteByteAlign();
 }
 
@@ -550,4 +539,9 @@
         {
           WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
+        }
+        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
+        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
+        {
+          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
         }
         WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
@@ -633,4 +627,5 @@
     for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
     {
+      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
       WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
       WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 652)
@@ -1612,6 +1612,6 @@
   if ( pcSlice->getRapPicFlag() )
   {
-#if NO_OUTPUT_OF_PRIOR_PICS
-    WRITE_FLAG( pcSlice->getNoOutputOfPriorPicsFlag(), "no_output_of_prior_pics_flag" );
+#if SETTING_NO_OUT_PIC_PRIOR
+    WRITE_FLAG( pcSlice->getNoOutputPriorPicsFlag() ? 1 : 0, "no_output_of_prior_pics_flag" );
 #else
     WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 652)
@@ -235,4 +235,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
@@ -639,4 +641,8 @@
   Void  setTMISEICameraIsoSpeedValue(Int b)                  {  m_cameraIsoSpeedValue = b;  }
   Int   getTMISEICameraIsoSpeedValue()                       {  return m_cameraIsoSpeedValue;  }
+  Void  setTMISEIExposureIndexIdc(Int b)                     {  m_exposureIndexIdc = b;  }
+  Int   getTMISEIExposurIndexIdc()                           {  return m_exposureIndexIdc;  }
+  Void  setTMISEIExposureIndexValue(Int b)                   {  m_exposureIndexValue = b;  }
+  Int   getTMISEIExposurIndexValue()                         {  return m_exposureIndexValue;  }
   Void  setTMISEIExposureCompensationValueSignFlag(Int b)    {  m_exposureCompensationValueSignFlag = b;  }
   Int   getTMISEIExposureCompensationValueSignFlag()         {  return m_exposureCompensationValueSignFlag;  }
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 652)
@@ -75,4 +75,7 @@
   m_iNumPicCoded        = 0; //Niko
   m_bFirst              = true;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  m_iLastRecoveryPicPOC = 0;
+#endif
   
   m_pcCfg               = NULL;
@@ -163,12 +166,11 @@
   SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); 
   seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); 
-  seiActiveParameterSets->m_fullRandomAccessFlag = false;
-  seiActiveParameterSets->m_noParamSetUpdateFlag = false;
+  seiActiveParameterSets->m_selfContainedCvsFlag = false;
+  seiActiveParameterSets->m_noParameterSetUpdateFlag = false;
   seiActiveParameterSets->numSpsIdsMinus1 = 0;
-  seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
-  seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId();
+  seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
+  seiActiveParameterSets->activeSeqParameterSetId[0] = sps->getSPSId();
   return seiActiveParameterSets;
 }
-
 
 SEIFramePacking* TEncGOP::xCreateSEIFramePacking()
@@ -271,4 +273,7 @@
        seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue();
        assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 );
+       seiToneMappingInfo->m_exposureIndexIdc = m_pcCfg->getTMISEIExposurIndexIdc();
+       seiToneMappingInfo->m_exposureIndexValue = m_pcCfg->getTMISEIExposurIndexValue();
+       assert( seiToneMappingInfo->m_exposureIndexValue !=0 );
        seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag();
        seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator();
@@ -435,4 +440,54 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+#if EFFICIENT_FIELD_IRAP
+  Int IRAPGOPid = -1;
+  Bool IRAPtoReorder = false;
+  Bool swapIRAPForward = false;
+  if(isField)
+  {
+    Int pocCurr;
+#if SVC_EXTENSION
+    for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
+#else
+    for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
+#endif    
+    {
+      // determine actual POC
+      if(iPOCLast == 0) //case first frame or first top field
+      {
+        pocCurr=0;
+      }
+      else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
+      {
+        pocCurr = 1;
+      }
+      else
+      {
+        pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
+      }
+
+      // check if POC corresponds to IRAP
+      NalUnitType tmpUnitType = getNalUnitType(pocCurr, m_iLastIDR, isField);
+      if(tmpUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && tmpUnitType <= NAL_UNIT_CODED_SLICE_CRA) // if picture is an IRAP
+      {
+        if(pocCurr%2 == 0 && iGOPid < m_iGopSize-1 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid+1).m_POC-1)
+        { // if top field and following picture in enc order is associated bottom field
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = true; 
+          break;
+        }
+        if(pocCurr%2 != 0 && iGOPid > 0 && m_pcCfg->getGOPEntry(iGOPid).m_POC == m_pcCfg->getGOPEntry(iGOPid-1).m_POC+1)
+        {
+          // if picture is an IRAP remember to process it first
+          IRAPGOPid = iGOPid;
+          IRAPtoReorder = true;
+          swapIRAPForward = false; 
+          break;
+        }
+      }
+    }
+  }
+#endif
 #if SVC_EXTENSION
   for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ )
@@ -441,4 +496,31 @@
 #endif
   {
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+        }
+        else if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+      }
+    }
+#endif
     UInt uiColDir = 1;
     //-- For time output for each slice
@@ -510,4 +592,33 @@
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPtoReorder)
+      {
+        if(swapIRAPForward)
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid +1;
+            IRAPtoReorder = false;
+          }
+          else if(iGOPid == IRAPGOPid +1)
+          {
+            iGOPid --;
+          }
+        }
+        else
+        {
+          if(iGOPid == IRAPGOPid)
+          {
+            iGOPid = IRAPGOPid -1;
+          }
+          else if(iGOPid == IRAPGOPid -1)
+          {
+            iGOPid = IRAPGOPid;
+            IRAPtoReorder = false;
+          }
+        }
+      }
+#endif
       continue;
     }
@@ -932,12 +1043,5 @@
     }
 
-    // Do decoding refresh marking if any 
-#if NO_CLRAS_OUTPUT_FLAG
-    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
-#else
-    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
-#endif
-    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
-    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
 #if FIX1172
     if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
@@ -954,9 +1058,46 @@
     pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
 #endif
-
+#endif
+    // Do decoding refresh marking if any 
+#if NO_CLRAS_OUTPUT_FLAG
+    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
+#else
+    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
+#endif
+    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
+    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
+#if EFFICIENT_FIELD_IRAP
+#else
+#if FIX1172
+    if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
+      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )  // IRAP picture
+    {
+      m_associatedIRAPType = pcSlice->getNalUnitType();
+      m_associatedIRAPPOC = pocCurr;
+    }
+    pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
+    pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
+#endif
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false, m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3) != 0) || (pcSlice->isIRAP()) 
+#if EFFICIENT_FIELD_IRAP
+      || (isField && pcSlice->getAssociatedIRAPType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getAssociatedIRAPType() <= NAL_UNIT_CODED_SLICE_CRA && pcSlice->getAssociatedIRAPPOC() == pcSlice->getPOC()+1)
+#endif
+      )
+    {
+      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP(), m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3);
+    }
+#else
     if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     {
       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
     }
+#endif
 #if ALIGNED_BUMPING
     pcSlice->checkLeadingPictureRestrictions(rcListPic);
@@ -1849,7 +1990,14 @@
       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
-      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
-#else
-      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pocCurr - m_totalCoded;
+#else
+      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(pcSlice->getSPS()->getMaxTLayers()-1) + pcSlice->getPOC() - m_totalCoded;
+#endif
+#if EFFICIENT_FIELD_IRAP
+      if(IRAPGOPid > 0 && IRAPGOPid < m_iGopSize)
+      {
+        // if pictures have been swapped there is likely one more picture delay on their tid. Very rough approximation
+        pictureTimingSEI.m_picDpbOutputDelay ++;
+      }
 #endif
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
@@ -1975,4 +2123,10 @@
 #endif
       sei_recovery_point.m_brokenLinkFlag    = false;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      if(m_pcCfg->getDecodingRefreshType() == 3)
+      {
+        m_iLastRecoveryPicPOC = pocCurr;
+      }
+#endif
 
 #if O0164_MULTI_LAYER_HRD
@@ -2110,4 +2264,23 @@
           }
           m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+
+#if SETTING_NO_OUT_PIC_PRIOR
+          if (pcSlice->isIRAP())
+          {
+            if (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP)
+            {
+              pcSlice->setNoRaslOutputFlag(true);
+            }
+            //the inference for NoOutputPriorPicsFlag
+            if (!m_bFirst && pcSlice->isIRAP() && pcSlice->getNoRaslOutputFlag())
+            {
+              if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
+              {
+                pcSlice->setNoOutputPriorPicsFlag(true);
+              }
+            }
+          }
+#endif
+
           tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
           m_pcEntropyCoder->encodeSliceHeader(pcSlice);
@@ -2657,4 +2830,34 @@
 
       delete[] pcSubstreamsOut;
+
+#if EFFICIENT_FIELD_IRAP
+    if(IRAPtoReorder)
+    {
+      if(swapIRAPForward)
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid +1;
+          IRAPtoReorder = false;
+        }
+        else if(iGOPid == IRAPGOPid +1)
+        {
+          iGOPid --;
+        }
+      }
+      else
+      {
+        if(iGOPid == IRAPGOPid)
+        {
+          iGOPid = IRAPGOPid -1;
+        }
+        else if(iGOPid == IRAPGOPid -1)
+        {
+          iGOPid = IRAPGOPid;
+          IRAPtoReorder = false;
+        }
+      }
+    }
+#endif
   }
   delete pcBitstreamRedirect;
@@ -2918,5 +3121,7 @@
     case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
     case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
+    case NAL_UNIT_CODED_SLICE_RADL_N:     return "RADL_N";
     case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
+    case NAL_UNIT_CODED_SLICE_RASL_N:     return "RASL_N";
     case NAL_UNIT_VPS:                    return "VPS";
     case NAL_UNIT_SPS:                    return "SPS";
@@ -3316,5 +3521,17 @@
     return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
   }
+#if EFFICIENT_FIELD_IRAP
+  if(isField && pocCurr == 1)
+  {
+    // to avoid the picture becoming an IRAP
+    return NAL_UNIT_CODED_SLICE_TRAIL_R;
+  }
+#endif
+
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() != 3 && (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#else
   if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
+#endif
   {
     if (m_pcCfg->getDecodingRefreshType() == 1)
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 652)
@@ -82,4 +82,7 @@
   Int                     m_iNumPicCoded;
   Bool                    m_bFirst;
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int                     m_iLastRecoveryPicPOC;
+#endif
   
   //  Access channel
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 652)
@@ -952,8 +952,16 @@
         for (y=0; y<endY; y++)
         {
+#if SAO_SGN_FUNC
+          signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
           signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
             signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
             edgeType  =  signRight + signLeft;
             signLeft  = -signRight;
@@ -975,8 +983,16 @@
             for(y=0; y<skipLinesB[typeIdx]; y++)
             {
+#if SAO_SGN_FUNC
+              signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
               signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
+#else
                 signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
                 edgeType  =  signRight + signLeft;
                 signLeft  = -signRight;
@@ -1026,5 +1042,9 @@
 #endif
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
           signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
         }
 
@@ -1040,5 +1060,9 @@
 #endif
           {
+#if SAO_SGN_FUNC
+            signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]); 
+#else
             signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
             edgeType  = signDown + signUpLine[x];
             signUpLine[x]= -signDown;
@@ -1065,5 +1089,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1108,5 +1136,9 @@
         for (x=startX; x<endX+1; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
+#endif
         }
 
@@ -1122,5 +1154,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1137,5 +1173,9 @@
           for (x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
             diff [edgeType] += (orgLine[x] - srcLine[x]);
@@ -1144,5 +1184,9 @@
             signDownLine[x+1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
           signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
           signTmpLine  = signUpLine;
@@ -1168,5 +1212,9 @@
               for (x=startX; x< endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
@@ -1206,5 +1254,9 @@
         for (x=startX-1; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
         }
 
@@ -1225,5 +1277,9 @@
         for(x=firstLineStartX; x<firstLineEndX; x++)
         {
+#if SAO_SGN_FUNC
+          edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1];
+#else
           edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
+#endif
           diff [edgeType] += (orgLine[x] - srcLine[x]);
           count[edgeType] ++;
@@ -1240,5 +1296,9 @@
           for(x=startX; x<endX; x++)
           {
+#if SAO_SGN_FUNC
+            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
             edgeType = signDown + signUpLine[x];
 
@@ -1248,5 +1308,9 @@
             signUpLine[x-1] = -signDown; 
           }
+#if SAO_SGN_FUNC
+          signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
           signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
           srcLine  += srcStride;
           orgLine  += orgStride;
@@ -1267,5 +1331,9 @@
               for (x=startX; x<endX; x++)
               {
+#if SAO_SGN_FUNC
+                edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]);
+#else
                 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
+#endif
                 diff [edgeType] += (orgLine[x] - srcLine[x]);
                 count[edgeType] ++;
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 652)
@@ -95,7 +95,4 @@
   Void  codeSliceHeader         ( TComSlice* pcSlice );
   Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
-#if POC_RESET_IDC_SIGNALLING
-  Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow );
-#endif
   Void  codeTerminatingBit      ( UInt uilsLast      );
   Void  codeSliceFinish         ();
@@ -108,4 +105,7 @@
 
 #if SVC_EXTENSION
+#if POC_RESET_IDC_SIGNALLING
+  Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow );
+#endif
   Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal);
   Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 652)
@@ -2398,5 +2398,5 @@
 {
   UInt    uiDepth        = pcCU->getDepth(0);
-  UInt    uiNumPU        = pcCU->getNumPartInter();
+  UInt    uiNumPU        = pcCU->getNumPartitions();
   UInt    uiInitTrDepth  = pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1;
   UInt    uiWidth        = pcCU->getWidth (0) >> uiInitTrDepth;
@@ -3130,5 +3130,5 @@
   TComMv        cMvTemp[2][33];
   
-  Int           iNumPart    = pcCU->getNumPartInter();
+  Int           iNumPart    = pcCU->getNumPartitions();
   Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
   
@@ -4612,14 +4612,5 @@
     
     m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-#if 0 // check
-    {
-      m_pcEntropyCoder->resetBits();
-      m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) );
-      const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits();
-      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
-      if( uiBitsForCoeff != uiBits )
-        assert( 0 );
-    }
-#endif
+    
     uiBits = 0;
     {
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 652)
@@ -225,5 +225,17 @@
   Int depth;
   {
+#if FIX_FIELD_DEPTH    
+    Int poc = rpcSlice->getPOC();
+    if(isField)
+    {
+      poc = (poc/2)%(m_pcCfg->getGOPSize()/2);
+    }
+    else
+    {
+      poc = poc%m_pcCfg->getGOPSize();   
+    }
+#else
     Int poc = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
+#endif
     if ( poc == 0 )
     {
@@ -248,4 +260,17 @@
       }
     }
+#if FIX_FIELD_DEPTH  
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+    if(poc != 0)
+    {
+#endif
+    if(isField && rpcSlice->getPOC()%2 == 1)
+    {
+      depth ++;
+    }
+#if HARMONIZE_GOP_FIRST_FIELD_COUPLE
+  }
+#endif
+#endif
   }
 
@@ -254,5 +279,23 @@
 
   eSliceType=B_SLICE;
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0             || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+  else
+  {
   eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif
 
   rpcSlice->setSliceType    ( eSliceType );
@@ -423,5 +466,25 @@
 #if HB_LAMBDA_FOR_LDC
   // restore original slice type
+  
+#if EFFICIENT_FIELD_IRAP
+  if(!(isField && pocLast == 1))
+  {
+#endif // EFFICIENT_FIELD_IRAP
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(m_pcCfg->getDecodingRefreshType() == 3)
+  {
+    eSliceType = (pocLast == 0 || (pocCurr)           % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+
+  }
+  else
+  {
   eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+  }
+#else
+  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
+#if EFFICIENT_FIELD_IRAP
+  }
+#endif // EFFICIENT_FIELD_IRAP
 
 #if SVC_EXTENSION
@@ -544,5 +607,7 @@
   // store lambda
   slice->setSliceQp( sliceQP );
+#if ADAPTIVE_QP_SELECTION
   slice->setSliceQpBase ( sliceQP );
+#endif
   m_pcRdCost ->setLambda( lambda );
   // for RDO
@@ -1041,5 +1106,7 @@
 
       m_pcRateCtrl->setRCQP( estQP );
+#if ADAPTIVE_QP_SELECTION
       pcCU->getSlice()->setSliceQpBase( estQP );
+#endif
     }
 
Index: /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 651)
+++ /branches/SHM-6-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 652)
@@ -273,5 +273,5 @@
 
   /// encode several number of pictures until end-of-sequence
-  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
+  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff);
 
