Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.cpp	(revision 237)
@@ -3706,4 +3706,8 @@
   Int iPdmDir[2] = {0, 0};
 #endif
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  getUnifiedMvPredCan(uiPUIdx, REF_PIC_LIST_0, 0, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir, true);
+  Int iPdmInterDir;
+#else
   Int     iPdmInterDir      = cDisInfo.iN==0? 0:getPdmMergeCandidateDisCan ( uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo  
 #if QC_MRG_CANS_B0048
@@ -3711,4 +3715,5 @@
 #endif
     );
+#endif
 #else
   Int     iPdmInterDir      = getPdmMergeCandidate( uiPUIdx, aiPdmRefIdx, acPdmMv );
@@ -4409,8 +4414,16 @@
     UInt uiCurLCUIdx = getAddr();
     xDeriveCenterIdx( eCUMode, uiPUIdx, uiPartIdxCenter );
-    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
+    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+    , 1
+#endif
+    );
     if( bExistMV == false )
     {
-      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx );
+      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+    , 1
+#endif
+    );
     }
     if( bExistMV )
@@ -4427,8 +4440,16 @@
         iRefIdx = 0;
 #endif
-        bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
+        bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx
+#if QC_TMVP_MRG_REFIDX_C0047
+        , 1
+#endif
+        );
         if( bExistMV == false )
         {
-          bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx );
+          bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+        , 1
+#endif  
+        );
         }
         if( bExistMV )
@@ -5921,4 +5942,11 @@
         cDisInfo.m_aVIdxCan[0] = 0;
       }
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+      Int paiPdmRefIdx[4] = {-1, -1, -1, -1};
+      Int iPdmDir[4] = {-1, -1, -1, -1};
+      TComMv cPdmMvPred[2];
+      cPdmMvPred[0].m_bDvMcp = cPdmMvPred[1].m_bDvMcp = false; 
+      if(getUnifiedMvPredCan(uiPartIdx, eRefPicList, iRefIdx, paiPdmRefIdx, cPdmMvPred, &cDisInfo, iPdmDir, false))
+#else
       TComMv  cPdmMvPred;
 #if QC_MULTI_DIS_CAN_A0097
@@ -5927,4 +5955,15 @@
       if( getPdmMvPred( uiPartIdx, eRefPicList, iRefIdx, cPdmMvPred ) )
 #endif
+#endif
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+      {
+        clipMv( cPdmMvPred[0] );
+        pInfo->m_acMvCand[0] = cPdmMvPred[0];
+      }
+      else
+      {
+        pInfo->m_acMvCand[0].set(0,0);
+      }
+#else
       {
         clipMv( cPdmMvPred );
@@ -5935,4 +5974,5 @@
         pInfo->m_acMvCand[0].set(0,0);
       }
+#endif
     }
   }
@@ -6784,5 +6824,10 @@
  * \returns Bool
  */
-Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
+Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+  ,
+  Bool bMRG
+#endif
+)
 {
   UInt uiAbsPartAddr = uiPartUnitIdx;
@@ -6868,6 +6913,29 @@
   if(bIsCurrRefLongTerm != bIsColRefLongTerm) 
   {
+#if QC_TMVP_MRG_REFIDX_C0047
+    cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
+    iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
+    if(bMRG )
+    {
+      Int iUpdRefIdx  = m_pcSlice->getNewRefIdx(eRefPicList);
+      if(iUpdRefIdx > 0 )
+      {
+        riRefIdx = iUpdRefIdx;
+        bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
+        iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
+#if SONY_COLPIC_AVAILABILITY
+        iCurrRefViewOrderIdx = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx();
+#endif
+      }
+      else
+        return false;
+    }else
+    {
+#endif
     assert( ((iColPOC == iColRefPOC)&&(iCurrPOC != iCurrRefPOC))||((iColPOC != iColRefPOC)&&(iCurrPOC == iCurrRefPOC)));
     return false;
+#if QC_TMVP_MRG_REFIDX_C0047
+    }
+#endif
   }
 #endif
@@ -7899,4 +7967,15 @@
 }
 #else
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+Bool
+TComDataCU::getUnifiedMvPredCan(UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  TComDepthMapGenerator* pcDepthMapGenerator = m_pcSlice->getSPS()->getDepthMapGenerator();
+  ROFRS( pcDepthMapGenerator, false );
+  if (pDInfo->iN > 0 && pcDepthMapGenerator->getPdmCandidate(this, uiPartIdx, eRefPicList, iRefIdx, paiPdmRefIdx, pacPdmMv, pDInfo, iPdm, bMerge))
+    return true;
+  return false;
+}
+#else
 Int
 TComDataCU::getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
@@ -7924,5 +8003,5 @@
 }
 #endif
-
+#endif
 
 Bool      
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.h	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDataCU.h	(revision 237)
@@ -281,5 +281,10 @@
 
   Void          deriveRightBottomIdx        ( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxRB );
-  Bool          xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx );
+  Bool          xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx 
+#if QC_TMVP_MRG_REFIDX_C0047
+  ,
+  Bool bMRG = 0
+#endif
+  );
 #if QC_MULTI_DIS_CAN_A0097
   Bool          xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
@@ -544,4 +549,7 @@
   Bool          getPdmMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge = false );
 #else
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  Bool getUnifiedMvPredCan(UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+#else
   Bool          getPdmMvPredDisCan( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge = false );
   Int           getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
@@ -550,4 +558,5 @@
 #endif
   );
+#endif
   Void          getDisMvpCand        ( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo );
 #if LGE_DVMCP_A0126
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 237)
@@ -605,4 +605,198 @@
 
 #if HHI_INTER_VIEW_MOTION_PRED
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+Bool
+TComDepthMapGenerator::getPdmCandidate(TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  AOF  ( m_bCreated && m_bInit );
+  TComSlice*    pcSlice     = pcCU->getSlice ();
+  TComSPS*      pcSPS       = pcSlice->getSPS();
+  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
+
+  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
+  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
+  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
+  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
+  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
+  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
+  if(!bMerge)
+  {
+    ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
+    ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
+    ROTRS(                  bMerge   && !bPdmMerge, false );
+  }
+  else
+    ROTRS( !bPdmMerge, 0 );
+
+#if QC_MRG_CANS_B0048
+  Bool abPdmAvailable[4] = {false, false, false, false};
+#else
+  Bool abPdmAvailable[2] = {false,false};
+#endif
+
+  Int iValid = 0;
+  Int iViewId = 0;
+  for( UInt uiBId = 0; uiBId < m_uiCurrViewId && iValid==0; uiBId++ )
+  {
+    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
+    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
+    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
+    {
+      RefPicList  eRefPicListTest = RefPicList( iRefListId );
+      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
+      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
+      { 
+        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
+          && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId())
+        {
+          iValid=1;
+          iViewId = uiBaseId;
+          break;
+        }
+      }
+    }
+  }
+  if (iValid == 0)
+    return false;
+
+  //--- get base CU/PU and check prediction mode ---
+  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewId );
+  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
+  if(bMerge || !bInterview)
+  {
+#if QC_MULTI_DIS_CAN_A0097
+    Int  iCurrPosX, iCurrPosY;
+    UInt          uiPartAddr;
+    Int           iWidth;
+    Int           iHeight;
+
+    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
+    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
+    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
+    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
+
+    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
+    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
+#else
+    Int  iPrdDepth, iCurrPosX, iCurrPosY;
+    Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
+    AOF( bAvailable );
+    TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
+    Int         iDisparity  = xGetDisparityFromVirtDepth( iViewId, iPrdDepth );
+    Int         iShiftX     = m_uiSubSampExpX + 2;
+    Int         iAddX       = ( 1 << iShiftX ) >> 1;
+    Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
+    Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx );
+#endif 
+    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
+    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP )
+    {
+      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
+      {
+        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
+        if(!bMerge && eCurrRefPicList != eRefPicList)
+          continue;
+        Bool bLoop_stop = false;
+        for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
+        {
+          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
+          TComMvField cBaseMvField;
+          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
+          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
+          if (iBaseRefIdx >= 0)
+          {
+            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
+            if (iBaseRefPOC != pcSlice->getPOC())    
+            {
+              for (Int iPdmRefIdx = (bMerge?0: iRefIdx); iPdmRefIdx < (bMerge? pcSlice->getNumRefIdx( eCurrRefPicList ): (iRefIdx+1)); iPdmRefIdx++)
+              {
+                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
+                {
+                  abPdmAvailable[ uiCurrRefListId ] = true;
+                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
+#if LGE_DVMCP_A0126
+                  if( bMerge )
+                  {
+                    cMv.m_bDvMcp = true;
+                    cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
+                  }
+#endif
+                  pcCU->clipMv( cMv );
+                  if(bMerge)
+                  {
+                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
+                    pacPdmMv      [ uiCurrRefListId ] = cMv;
+                    bLoop_stop = true;
+                    break;
+                  }else
+                  {
+                    pacPdmMv  [0] = cMv;
+                    return true;
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+    if( bMerge )
+      iPdm[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
+  }
+  if(bMerge || bInterview)
+  {
+    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
+    {
+      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
+      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
+      for( Int iPdmRefIdx = (bMerge ? 0: iRefIdx); iPdmRefIdx < (bMerge ? iNumRefPics: (iRefIdx+1) ); iPdmRefIdx++ )
+      {
+        if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
+        {
+#if QC_MRG_CANS_B0048
+          abPdmAvailable[ iRefListId+2 ] = true;
+          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
+#else
+          abPdmAvailable[ iRefListId ] = true;
+          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
+#endif
+#if QC_MULTI_DIS_CAN_A0097
+          TComMv cMv = pDInfo->m_acMvCand[0]; 
+          cMv.setVer(0);
+#else
+          TComMv cMv(iDisparity, 0);
+#endif
+          pcCU->clipMv( cMv );
+#if QC_MRG_CANS_B0048
+          pacPdmMv      [ iRefListId + 2] = cMv;
+#else
+          pacPdmMv      [ iRefListId ] = cMv;
+#endif
+          if(bMerge)
+            break;
+          else
+          {
+            pacPdmMv [0] = cMv;
+            return true;
+          }
+        }
+      }
+    }
+#if QC_MRG_CANS_B0048
+    iPdm[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
+#else
+    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ;
+   }
+#endif
+  }
+  return false;
+}
+#else
 #if QC_MULTI_DIS_CAN_A0097
 Int
@@ -1014,4 +1208,5 @@
   return false;
 }
+#endif
 #endif
 
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.h
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 237)
@@ -152,4 +152,7 @@
 #if HHI_INTER_VIEW_MOTION_PRED
 #if QC_MULTI_DIS_CAN_A0097
+#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
+  Bool getPdmCandidate ( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+#else
   Int   getPdmMergeCandidate ( TComDataCU*   pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo 
 #if QC_MRG_CANS_B0048
@@ -160,4 +163,5 @@
   Bool  getPdmMvPredDisCan    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge );
   Bool  getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge );
+#endif
 #else
   Int   getPdmMergeCandidate  ( TComDataCU*   pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv );
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.cpp	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.cpp	(revision 237)
@@ -199,4 +199,8 @@
   m_numEntryPointOffsets = 0;
 #endif
+#if QC_TMVP_MRG_REFIDX_C0047
+  m_aiNewRefIdx[0]                  = -1;
+  m_aiNewRefIdx[1]                  = -1;
+#endif
 }
 
@@ -419,4 +423,24 @@
     }
   }
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int  iCurrPOC = this->getPOC();
+  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )//just to get one updated ref idx for merge in each L0/L1 direction, if it is not avaialbe, it is still -1 
+  {        
+    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
+        continue;
+
+    Bool bZeroIdxInterViewFlag =  ( this->getRefPic(RefPicList(uiRefListIdx), 0)->getPOC() == iCurrPOC ) ? true : false;
+    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
+    {
+      if ( (bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() != iCurrPOC ) ||
+           (!bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() == iCurrPOC ) )
+      {
+        this->setNewRefIdx(RefPicList(uiRefListIdx),i);
+        break;
+      }
+    }
+  }
+
+#endif
 }
 
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.h	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.h	(revision 237)
@@ -1248,4 +1248,7 @@
 
   Bool        m_bCheckLDC;
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int         m_aiNewRefIdx    [2]; 
+#endif
 
   //  Data
@@ -1654,4 +1657,8 @@
   Void      xSetApplyIC           ();
 #endif
+#if QC_TMVP_MRG_REFIDX_C0047
+  Int       getNewRefIdx        ( RefPicList e )                { return  m_aiNewRefIdx[e];     }
+  Void      setNewRefIdx        ( RefPicList e, Int i )         { m_aiNewRefIdx[e]    = i;      }
+#endif
 
 protected:
Index: /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TypeDef.h	(revision 236)
+++ /branches/HTM-5.1-dev2-Qualcomm/source/Lib/TLibCommon/TypeDef.h	(revision 237)
@@ -67,5 +67,6 @@
 #if FLEX_CODING_ORDER_M23723
   #define DISABLE_FCO_FOR_VSO             0 // Optional compile settings to disable VSO with FCO.
-#endif
+#endif 
+#define   QC_TMVP_MRG_REFIDX_C0047        1 //only enabled when QC_TMVP_IDX_MOD_B0046 is enabled.
 
 ///// ***** PATCHES *********
@@ -81,4 +82,5 @@
 ///// ***** INTERVIEW MOTION VECTOR PREDICTION *********
 #define HHI_INTER_VIEW_MOTION_PRED        1   // inter-view motion parameter prediction
+#define QC_AMVP_MRG_UNIFY_IVCAN_C0051     0
 #define SHARP_INTERVIEW_DECOUPLE_B0111    1   // JCT3V-B0111 decoupling inter-view candidate
 #define QC_MRG_CANS_B0048                 1   // JCT3V-B0048, B0086, B0069
