Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 566)
@@ -144,4 +144,7 @@
 #if H_3D_VSP
   m_piVSPFlag            = NULL;
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir             = NULL;
+#endif
 #endif
 #if H_3D_ARP
@@ -187,4 +190,7 @@
 #if H_3D_VSP
     m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
+#if MTK_VSP_FIX_E0172
+    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
+#endif
 #endif
     m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
@@ -336,4 +342,7 @@
 #if H_3D_VSP
     if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
+#if MTK_VSP_FIX_E0172
+    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
+#endif
 #endif
     if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
@@ -532,4 +541,7 @@
 #if H_3D_VSP
     m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
+#if MTK_VSP_FIX_E0172
+    m_piVSPDir  [ui] = pcFrom->m_piVSPDir[ui];
+#endif
 #endif
     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
@@ -571,4 +583,7 @@
 #if H_3D_VSP
     memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
+#if MTK_VSP_FIX_E0172
+    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
+#endif
 #endif
     memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
@@ -743,4 +758,7 @@
 #if H_3D_VSP
       m_piVSPFlag[ui] = 0;
+#if MTK_VSP_FIX_E0172
+      m_piVSPDir  [ui] = 0;
+#endif
 #endif
       m_puhLumaIntraDir[ui] = DC_IDX;
@@ -835,4 +853,7 @@
 #if H_3D_VSP
   memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
+#if MTK_VSP_FIX_E0172
+  memset( m_piVSPDir  ,         0, sizeInChar );
+#endif
 #endif
   memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
@@ -922,4 +943,7 @@
 #if H_3D_VSP
       m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
+#if MTK_VSP_FIX_E0172
+      m_piVSPDir[ui]=pcCU->m_piVSPDir[uiPartOffset+ui];
+#endif
 #endif
       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
@@ -1064,4 +1088,7 @@
 #if H_3D_VSP
   m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
+#endif
 #endif
 
@@ -1211,4 +1238,7 @@
 #if H_3D_VSP
   m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
+#if MTK_VSP_FIX_E0172
+  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
+#endif
 #endif
 
@@ -1258,4 +1288,7 @@
 #if H_3D_VSP
   memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
+#if MTK_VSP_FIX_E0172
+  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          sizeInChar );
+#endif
 #endif
   memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
@@ -1378,4 +1411,7 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
+#if MTK_VSP_FIX_E0172
+  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,          sizeInChar );
+#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
@@ -1486,4 +1522,7 @@
 #if H_3D_VSP
   memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
+#if MTK_VSP_FIX_E0172
+  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          sizeInChar );
+#endif
 #endif
   memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
@@ -2489,4 +2528,10 @@
   setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
 }
+#if MTK_VSP_FIX_E0172
+Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
+}
+#endif
 #endif
 Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
@@ -2941,6 +2986,11 @@
  *   false: otherwise
  */
+#if MTK_VSP_FIX_E0172
+inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+                                    Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir )
+#else
 inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                                      Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
+#endif
 {
   if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
@@ -2957,5 +3007,9 @@
   Int  iRefListIdY = 0;
   Int  i;
-
+#if MTK_VSP_FIX_E0172
+  Int currViewId = m_pcSlice->getViewId();
+  Int derivedViewId = -1;
+  Int otherViewId = -1;
+#endif
   for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
   {
@@ -2968,4 +3022,8 @@
         refViewAvailFlag = true;
         predFlag[iRefListIdX] = 1;
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = iRefListIdX;
+        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId(); 
+#endif
         iRefListIdY = 1 - iRefListIdX;
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
@@ -2988,5 +3046,22 @@
         refViewAvailFlag = true;
         predFlag[iRefListIdY] = 1;
+#if MTK_VSP_FIX_E0172
+        TComMv  cMv = pDInfo->m_acDoNBDV;
+        otherViewId = m_pcSlice->getRefPic( eRefPicList, i)->getViewId();
+        Int iScale = xGetDistScaleFactor( currViewId, otherViewId, currViewId, derivedViewId );
+        if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
+        {
+          cMv = cMv.scaleMv( iScale );
+        }
+        else
+        {
+
+          cMv = cMv;
+        }
+        clipMv( cMv );
+        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( cMv, i );
+#else
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
+#endif
 #if H_3D_NBDV
         pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
@@ -3021,4 +3096,7 @@
 #if H_3D_VSP
       , Int* vspFlag
+#if MTK_VSP_FIX_E0172
+      , Int* vspDir
+#endif
 #endif
       , Int& numValidMergeCand, Int mrgCandIdx
@@ -3210,5 +3288,12 @@
 #if H_3D_VSP
       if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
+#if MTK_VSP_FIX_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -3278,5 +3363,12 @@
 #if H_3D_VSP
       if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
+#if MTK_VSP_FIX_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -3324,5 +3416,12 @@
 #if H_3D_VSP
     if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
+#if MTK_VSP_FIX_E0172
+    {
+#endif
       vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_E0172
+      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
+    }
+#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -3390,5 +3489,9 @@
 
 #if H_3D_VSP
+#if MTK_VSP_FIX_E0172
+  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
+#else
   if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
+#endif
     return;
   // early termination
@@ -3421,5 +3524,12 @@
 #if H_3D_VSP
     if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
+#if MTK_VSP_FIX_E0172
+    {
+#endif
       vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_E0172
+      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
+    }
+#endif
 #endif
     if ( mrgCandIdx == iCount )
@@ -3461,5 +3571,12 @@
 #if H_3D_VSP
       if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
+#if MTK_VSP_FIX_E0172
+      {
+#endif
         vspFlag[iCount] = 1;
+#if MTK_VSP_FIX_E0172
+        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
+      }
+#endif
 #endif
       if ( mrgCandIdx == iCount )
@@ -4914,8 +5031,16 @@
         Bool bCheck = false; 
         if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
+#if MTK_NBDV_TN_FIX_E0172
+          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+#else
           bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+#endif
 
         if (curPosition == 1 )
+#if MTK_NBDV_TN_FIX_E0172
+          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+#else
           bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+#endif
 
         if( bCheck )
@@ -5021,5 +5146,7 @@
           pDInfo->m_acNBDV = cDispVec;
           pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
+#if !MTK_DVMCP_FIX_E0172
           assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
+#endif
 #if H_3D_NBDV_REF
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
@@ -5145,5 +5272,9 @@
           paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
           //Notes from QC: DvMCP is implemented in a way that doesn�t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
+#if MTK_DVMCP_FIX_E0172
+          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
+#else  
           paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
+#endif
           paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
           paIDVInfo->m_bFound                        = true; 
@@ -5210,6 +5341,9 @@
   }
 }
-
+#if MTK_NBDV_TN_FIX_E0172
+Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
+#else
 Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
+#endif
 {
 
@@ -5245,4 +5379,8 @@
     else 
     {
+#if MTK_NBDV_TN_FIX_E0172
+      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
+      {
+#endif
       rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
       rcMv.setIDVFlag(0);
@@ -5250,4 +5388,7 @@
       iStartViewIdx   = iColViewIdx   ;
       return true;    
+#if MTK_NBDV_TN_FIX_E0172
+      }
+#endif
     }
   }
@@ -5328,4 +5469,7 @@
                 cMv.setIDVHor    (cDv.getHor());                  
                 cMv.setIDVVer    (cDv.getVer());  
+#if MTK_DVMCP_FIX_E0172
+                cMv.setIDVVId    (iViewIndex); 
+#endif
 #endif
                 clipMv( cMv );
@@ -5348,5 +5492,9 @@
     for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
     {
+#if MTK_DIVMC_FIX_E0172
+      if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
+#else
       if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
+#endif
       {
         abPdmAvailable[ iRefListId+2 ] = true;
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.h	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComDataCU.h	(revision 566)
@@ -197,4 +197,7 @@
   Char*         m_piVSPFlag;          ///< array of VSP flags to indicate whehter a block uses VSP or not
                                       ///< 0: non-VSP; 1: VSP
+#if MTK_VSP_FIX_E0172
+  Char*         m_piVSPDir;           ///< 0: LIST0; 1: LIST1
+#endif
 #endif
 #if H_3D_ARP
@@ -246,6 +249,11 @@
   Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
 #if H_3D_VSP
+#if MTK_VSP_FIX_E0172
+  Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
+                             Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir );
+#else
   Bool          xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
                              Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag );
+#endif
 #endif
 
@@ -473,5 +481,9 @@
 #endif
   );
+#if MTK_NBDV_TN_FIX_E0172
+  Bool          xGetColDisMV      ( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
+#else
   Bool          xGetColDisMV      ( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
+#endif
   Bool          getDisMvpCandNBDV ( DisInfo* pDInfo
 #if H_3D_NBDV_REF
@@ -632,4 +644,7 @@
 #if H_3D_VSP
                                             , Int* vspFlag
+#if MTK_VSP_FIX_E0172
+                                            , Int* vspDir
+#endif
 #endif
                                             , Int& numValidMergeCand, Int mrgCandIdx = -1 );
@@ -639,4 +654,10 @@
   Void          setVSPFlag        ( UInt uiIdx, Int n )     { m_piVSPFlag[uiIdx] = n;      }
   Void          setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#if MTK_VSP_FIX_E0172
+  Char*         getVSPDir          ()                        { return m_piVSPDir;                           }
+  Char          getVSPDir          ( UInt uiIdx )            { return m_piVSPDir[uiIdx];                  }
+  Void          setVSPDir          ( UInt uiIdx, Int n )     { m_piVSPDir[uiIdx] = n;  }
+  Void          setVSPDirSubParts  ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
 #endif
   Void          deriveLeftRightTopIdxGeneral  ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComMv.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComMv.h	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComMv.h	(revision 566)
@@ -58,4 +58,7 @@
   Short m_iIDVHor;    
   Short m_iIDVVer;   
+#if MTK_DVMCP_FIX_E0172
+  Short m_iIDVVId;  //view index of the IDV
+#endif
 #endif
 public:
@@ -72,4 +75,7 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
+#if MTK_DVMCP_FIX_E0172
+  , m_iIDVVId(0) 
+#endif
 #endif
   {
@@ -83,4 +89,7 @@
   , m_iIDVHor(0)
   , m_iIDVVer(0)
+#if MTK_DVMCP_FIX_E0172
+  , m_iIDVVId(0) 
+#endif
 #endif
   {
@@ -97,4 +106,7 @@
  #if H_3D_NBDV
    m_bIDV = false; m_iIDVHor = m_iIDVVer = 0;
+#if MTK_DVMCP_FIX_E0172
+   m_iIDVVId = 0; 
+#endif
 #endif
   }
@@ -103,4 +115,7 @@
   Void   setIDVVer  (Short i)                    {m_iIDVVer = i;}
   Void   setIDVFlag (Bool b )                    {m_bIDV    = b;}
+#if MTK_DVMCP_FIX_E0172
+  Void   setIDVVId  (Short i)                    {m_iIDVVId = i;}
+#endif
 #endif
   // ------------------------------------------------------------------------------------------------------------------
@@ -116,4 +131,7 @@
   Short getIDVVer () const { return m_iIDVVer;       }
   Bool  getIDVFlag() const { return m_bIDV;          }
+#if MTK_DVMCP_FIX_E0172
+  Short getIDVVId () const { return m_iIDVVId;       }
+#endif
 #endif
   // ------------------------------------------------------------------------------------------------------------------
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.cpp	(revision 566)
@@ -655,3 +655,58 @@
 }
 #endif
+#if MTK_NBDV_TN_FIX_E0172
+Void TComPic::checkTemporalIVRef()
+{
+  TComSlice* currSlice = getSlice(getCurrSliceIdx());
+  const Int numCandPics = this->getNumDdvCandPics();
+  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
+  {
+    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
+    Int        curCandPicRefIdx = 0;
+    if( curCandPic == 0 ) 
+    { 
+      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1-currSlice->getColFromL0Flag() : 0);
+      curCandPicRefIdx = currSlice->getColRefIdx();
+    }
+    else                 
+    {
+      eCurRefPicList   = this->getRapRefList();
+      curCandPicRefIdx = this->getRapRefIdx();
+    }
+    TComPic* pcCandColPic = currSlice->getRefPic( eCurRefPicList, curCandPicRefIdx);
+    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0);// currently only support single slice
+
+    if(!pcCandColSlice->isIntra())
+    {
+      for( Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2: 1); iColRefDir ++ )
+      {
+        for( Int iColRefIdx =0; iColRefIdx < pcCandColSlice->getNumRefIdx(( RefPicList )iColRefDir ); iColRefIdx++)
+        {
+          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
+          Int iColViewIdx    = pcCandColSlice->getViewIndex();
+          Int iColRefViewIdx = pcCandColSlice->getRefPic( ( RefPicList )iColRefDir, iColRefIdx)->getViewIndex();
+          if(iColViewIdx == iColRefViewIdx)
+            continue;
+
+          for(Int iCurrRefDir = 0;(iCurrRefDir < (currSlice->isInterB() ? 2: 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false ); iCurrRefDir++)
+          {
+            for( Int iCurrRefIdx =0; iCurrRefIdx < currSlice->getNumRefIdx(( RefPicList )iCurrRefDir ); iCurrRefIdx++)
+            {
+              if( currSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx )->getViewIndex() == iColRefViewIdx )
+              {  
+                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
+                break;
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
+{
+  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
+}
+#endif
 //! \}
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.h	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPic.h	(revision 566)
@@ -104,4 +104,7 @@
   Int         m_iNumDdvCandPics;
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+  Bool        m_abTIVRINCurrRL  [2][2][MAX_NUM_REF]; //whether an inter-view reference picture with the same view index of the inter-view reference picture of temporal reference picture of current picture exists in current reference picture lists
+#endif
 public:
   TComPic();
@@ -215,4 +218,8 @@
   RefPicList    getRapRefList()                        {return m_eRapRefList;       }
 #endif
+#if MTK_NBDV_TN_FIX_E0172
+  Void      checkTemporalIVRef();
+  Bool      isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
+#endif
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 566)
@@ -697,5 +697,12 @@
 {
   // Get depth reference
+#if MTK_VSP_FIX_E0172 
+  Int vspDir = pcCU->getVSPDir( uiPartAddr );
+  RefPicList privateRefPicList = (vspDir == 0) ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
+  Int privateRefIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
+  Int depthRefViewIdx = pcCU->getSlice()->getRefPic(privateRefPicList, privateRefIdx)->getViewIndex();
+#else
   Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
+#endif
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
   assert(pRefPicBaseDepth != NULL);
@@ -716,5 +723,9 @@
 
   // Do compensation
+#if MTK_VSP_FIX_E0172 
+  TComMv cDv  = pcCU->getCUMvField( privateRefPicList )->getMv( uiPartAddr );
+#else
   TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
+#endif
   pcCU->clipMv(cDv);
   UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TypeDef.h	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibCommon/TypeDef.h	(revision 566)
@@ -101,4 +101,11 @@
                                               // MERL_D0166: Reference view selection in NBDV & Bi-VSP
                                               // MERL_C0152: Basic VSP
+#define MTK_RVS_BUGFIX_E0172              1  // Bug fix for issues caused by reference view selection, JCT3V-E0172
+#if MTK_RVS_BUGFIX_E0172
+#define MTK_DVMCP_FIX_E0172                  1 // fix the mismatch between software and WD for DV derivation from DVMCP blocks, issue 2 in JCT3V-E0172
+#define MTK_VSP_FIX_E0172                    1 // fix the issues related to VSP merge candidate, issue 3, 4 in JCT3V-E0172
+#define MTK_DIVMC_FIX_E0172                  1 // fix the issue of derivation of disparity inter-view merge candidate, issue 5 in JCT3V-E0172
+#define MTK_NBDV_TN_FIX_E0172                1 // fix the issue of DV derivation from the temporal neighboring blocks, issue 7 in JCT3V-E0172
+#endif
 #endif
 #define H_3D_VSP                          1   // View synthesis prediction
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecCu.cpp	(revision 566)
@@ -366,6 +366,12 @@
     Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
     memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
-
+#if MTK_VSP_FIX_E0172
+    Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+    memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand, uiMergeIndex );
+    pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
+#else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
+#endif
     pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
 #else
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 566)
@@ -243,5 +243,12 @@
           Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
           memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_E0172
+          Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+          memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir, numValidMergeCand );
+          pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#else
           pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand );
+#endif
           pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
 #else
@@ -258,5 +265,12 @@
         Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
         memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_E0172
+        Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+        memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, vspDir,numValidMergeCand, uiMergeIndex );
+        pcCU->setVSPDirSubParts( vspDir[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
+#else
         pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, vspFlag, numValidMergeCand, uiMergeIndex );
+#endif
         pcCU->setVSPFlagSubParts( vspFlag[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
 #else
@@ -291,5 +305,9 @@
       }
     }
+#if MTK_VSP_FIX_E0172
+    if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) && (pcCU->getVSPFlag(uiSubPartIdx) == false))
+#else
     if ( (pcCU->getInterDir(uiSubPartIdx) == 3) && pcSubCU->isBipredRestriction(uiPartIdx) )
+#endif
     {
       pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( TComMv(0,0), ePartSize, uiSubPartIdx, uiDepth, uiPartIdx);
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecGop.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecGop.cpp	(revision 566)
@@ -159,4 +159,10 @@
   }
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+  if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
+  {
+    rpcPic->checkTemporalIVRef();
+  }
+#endif
 #if H_3D
   pcSlice->setDepthToDisparityLUTs(); 
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncCu.cpp	(revision 566)
@@ -1615,5 +1615,11 @@
   Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
   memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_E0172
+  Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+  memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand );
+#else
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand );
+#endif
 #else
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
@@ -1683,4 +1689,7 @@
 #if H_3D_VSP
           rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
+#if MTK_VSP_FIX_E0172
+          rpcTempCU->setVSPDirSubParts( vspDir[uiMergeCand], 0, 0, uhDepth );
+#endif
 #endif
           rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 566)
@@ -1078,4 +1078,10 @@
 #endif
 #endif
+#if MTK_NBDV_TN_FIX_E0172 
+      if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
+      {
+        pcPic->checkTemporalIVRef();
+      }
+#endif
     while(nextCUAddr<uiRealEndAddress) // determine slice boundaries
     {
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 566)
@@ -3550,4 +3550,7 @@
 #if H_3D_VSP
                                  , Int* vspFlag
+#if MTK_VSP_FIX_E0172
+                                 , Int* vspDir
+#endif
 #endif
                                  , Int& numValidMergeCand
@@ -3569,4 +3572,7 @@
 #if H_3D_VSP
                                    , vspFlag
+#if MTK_VSP_FIX_E0172
+                                   , vspDir
+#endif
 #endif
                                    , numValidMergeCand
@@ -3580,9 +3586,16 @@
 #if H_3D_VSP
                                  , vspFlag
+#if MTK_VSP_FIX_E0172
+                                 , vspDir
+#endif
 #endif
                                  , numValidMergeCand
                                  );
   }
+#if MTK_VSP_FIX_E0172
+  xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours,vspFlag, numValidMergeCand );
+#else
   xRestrictBipredMergeCand( pcCU, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
+#endif
 
   ruiCost = MAX_UINT;
@@ -3600,4 +3613,7 @@
 #if H_3D_VSP
       pcCU->setVSPFlagSubParts( vspFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+#if MTK_VSP_FIX_E0172
+      pcCU->setVSPDirSubParts( vspDir[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+#endif
 #endif
 
@@ -3629,5 +3645,9 @@
  * \returns Void
  */
+#if MTK_VSP_FIX_E0172
+Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int* vspFlag, Int numValidMergeCand )
+#else
 Void TEncSearch::xRestrictBipredMergeCand( TComDataCU* pcCU, UInt puIdx, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, Int numValidMergeCand )
+#endif
 {
   if ( pcCU->isBipredRestriction(puIdx) )
@@ -3635,5 +3655,9 @@
     for( UInt mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand )
     {
+#if MTK_VSP_FIX_E0172
+      if ( (interDirNeighbours[mergeCand] == 3) && (vspFlag[mergeCand] == false) )
+#else
       if ( interDirNeighbours[mergeCand] == 3 )
+#endif
       {
         interDirNeighbours[mergeCand] = 1;
@@ -3758,4 +3782,7 @@
 #if H_3D_VSP
     pcCU->setVSPFlagSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
+#if MTK_VSP_FIX_E0172
+    pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
+#endif
 #endif
     
@@ -4250,4 +4277,8 @@
       Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
       memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#if MTK_VSP_FIX_E0172
+      Int vspDir[MRG_MAX_NUM_CANDS_MEM];
+      memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
+#endif
 #endif
 
@@ -4255,4 +4286,7 @@
 #if H_3D_VSP
                       , vspFlag
+#if MTK_VSP_FIX_E0172
+                      , vspDir
+#endif
 #endif
                       , numValidMergeCand
@@ -4265,4 +4299,7 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts( vspFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MTK_VSP_FIX_E0172
+        pcCU->setVSPDirSubParts( vspDir[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
 #endif
         pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
@@ -4287,4 +4324,7 @@
 #if H_3D_VSP
         pcCU->setVSPFlagSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MTK_VSP_FIX_E0172
+        pcCU->setVSPDirSubParts ( 0,             uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
 #endif
         {
Index: /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.h	(revision 565)
+++ /branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibEncoder/TEncSearch.h	(revision 566)
@@ -415,4 +415,7 @@
 #if H_3D_VSP
                                   , Int* vspFlag
+#if MTK_VSP_FIX_E0172
+                                  , Int* vspDir
+#endif
 #endif
                                   , Int& numValidMergeCand
@@ -423,4 +426,7 @@
                                     TComMvField*    mvFieldNeighbours, 
                                     UChar*          interDirNeighbours, 
+#if MTK_VSP_FIX_E0172
+                                    Int* vspFlag,
+#endif
                                     Int             numValidMergeCand );
 
