Index: /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 474)
@@ -1872,4 +1872,24 @@
 #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 )
 {
Index: /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 474)
@@ -492,4 +492,7 @@
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
Index: /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 474)
@@ -250,4 +250,9 @@
 #endif
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  m_disableILP = xCheckTileSetConstraint(rpcCU);
+  m_pcPredSearch->setDisableILP(m_disableILP);
+#endif
+
   // analysis of CU
   xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 );
@@ -261,4 +266,8 @@
     }
   }
+#endif
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  xVerifyTileSetConstraint(rpcCU);
 #endif
 }
@@ -731,5 +740,9 @@
         }
 #if (ENCODER_FAST_MODE)
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      if(pcPic->getLayerId() > 0 && !m_disableILP)
+#else
       if(pcPic->getLayerId() > 0)
+#endif
       {
         for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
@@ -1381,4 +1394,8 @@
       Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
       if(bZeroMVILR)
+      {
+#endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      if (!(rpcTempCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP))
       {
 #endif
@@ -1426,8 +1443,11 @@
           }
         }
+      }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      }
+#endif
 #if REF_IDX_ME_ZEROMV 
-        }
-#endif
-      }
+      }
+#endif
   }
 
@@ -1808,4 +1828,70 @@
 }
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU )
+{
+  Bool disableILP = false;
+
+  if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0)
+  {
+    if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 2)
+    {
+      disableILP = true;
+    }
+    if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 1)
+    {
+      Int currCUaddr = rpcCU->getAddr();
+      Int frameWitdhInCU  = rpcCU->getPic()->getPicSym()->getFrameWidthInCU();
+      Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCU();
+      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
+      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
+      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
+      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
+      Int currTileSetIdx  = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr);
+      // Check if CU is at tile set boundary
+      if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) ||
+           (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
+           (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
+           (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
+           (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) ||
+           (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
+           (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
+           (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
+      {
+        disableILP = true;  // Disable ILP in tile set boundary CU
+      }
+    }
+  }
+
+  return disableILP;
+}
+
+Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU )
+{
+  if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0 &&
+      m_disableILP)
+  {
+    UInt numPartitions = rpcCU->getPic()->getNumPartInCU();
+    for (UInt i = 0; i < numPartitions; i++)
+    {
+      if (!rpcCU->isIntra(i))
+      {
+        for (UInt refList = 0; refList < 2; refList++)
+        {
+          if (rpcCU->getInterDir(i) & (1<<refList))
+          {
+            TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList));
+            if (mvField->getRefIdx(i) >= 0)
+            {
+              assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getLayerId())));
+            }
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
 /** Collect ARL statistics from one LCU
  * \param pcCU
Index: /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 474)
@@ -108,4 +108,7 @@
   Int                     m_temporalSAD;
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool                    m_disableILP;
+#endif
 public:
   /// copy parameters from encoder class
@@ -171,4 +174,9 @@
 #endif
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool xCheckTileSetConstraint( TComDataCU*& rpcCU );
+  Void xVerifyTileSetConstraint( TComDataCU*& rpcCU );
+#endif
+
 #if AMP_ENC_SPEEDUP 
 #if AMP_MRG
Index: /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 474)
@@ -3092,4 +3092,8 @@
     {
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    if (!(pcCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP))
+    {
+#endif
       UInt uiCostCand = MAX_UINT;
       UInt uiBitsCand = 0;
@@ -3115,4 +3119,7 @@
         uiMergeIndex = uiMergeCand;
       }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    }
+#endif
 #if REF_IDX_ME_ZEROMV
     }
@@ -3221,38 +3228,4 @@
   Int numValidMergeCand = 0 ;
 
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-  Bool disableILP = false;
-  if (pcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && pcCU->getPic()->getPicSym()->getTileSetIdxMap(pcCU->getAddr()) >= 0)
-  {
-    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 2)
-    {
-      disableILP = true;
-    }
-    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 1)
-    {
-      Int currCUaddr = pcCU->getAddr();
-      Int frameWitdhInCU  = pcCU->getPic()->getPicSym()->getFrameWidthInCU();
-      Int frameHeightInCU = pcCU->getPic()->getPicSym()->getFrameHeightInCU();
-      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
-      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
-      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
-      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
-      Int currTileSetIdx  = pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr);
-      // Check if CU is at tile set boundary
-      if ( (leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-1) != currTileSetIdx) ||
-           (leftCUExists && aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
-           (aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
-           (aboveCUExists && rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
-           (rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+1) != currTileSetIdx) ||
-           (rightCUExists && belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
-           (belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
-           (belowCUExists && leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
-      {
-        disableILP = true;  // Disable ILP in tile set boundary CU
-      }
-    }
-  }
-#endif
-
   for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
   {
@@ -3305,5 +3278,5 @@
       {
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && disableILP)
+        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && m_disableILP)
         {
           continue;
@@ -3529,5 +3502,5 @@
         }
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-        if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+        if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP)
         {
           testIter = false;
@@ -3550,5 +3523,5 @@
           }
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-          if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+          if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP)
           {
             testRefIdx = false;
Index: /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 473)
+++ /branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 474)
@@ -129,5 +129,9 @@
   // UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS];
   UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1]; //th array bounds
-  
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool            m_disableILP;
+#endif
+
 public:
   TEncSearch();
@@ -220,4 +224,9 @@
   Void xEncPCM    (TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrg, Pel* piPCM, Pel* piPred, Pel* piResi, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType eText);
   Void IPCMSearch (TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv );
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void setDisableILP(Bool a) {m_disableILP = a;}
+#endif
+
 protected:
   
