[x265] cleanup AMVP related

Satoshi Nakagawa nakagawa424 at oki.com
Tue Feb 11 05:06:21 CET 2014


# HG changeset patch
# User Satoshi Nakagawa <nakagawa424 at oki.com>
# Date 1392091414 -32400
#      Tue Feb 11 13:03:34 2014 +0900
# Node ID 116349aead02244e875bc180d016372545ca16ed
# Parent  d002f45eee16a00c6b077a40e4ff111a7e4ff8fb
cleanup AMVP related

diff -r d002f45eee16 -r 116349aead02 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Mon Feb 10 19:27:33 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Tue Feb 11 13:03:34 2014 +0900
@@ -2309,7 +2309,6 @@
  */
 void TComDataCU::fillMvpCand(uint32_t partIdx, uint32_t partAddr, int picList, int refIdx, AMVPInfo* info)
 {
-    MV mvp;
     bool bAddedSmvp = false;
 
     info->m_num = 0;
@@ -2320,7 +2319,6 @@
 
     //-- Get Spatial MV
     uint32_t partIdxLT, partIdxRT, partIdxLB;
-    uint32_t numPartInCUWidth = m_pic->getNumPartInWidth();
     bool bAdded = false;
 
     deriveLeftRightTopIdx(partIdx, partIdxLT, partIdxRT);
@@ -2364,10 +2362,8 @@
     {
         xAddMVPCand(info, picList, refIdx, partIdxLT, MD_ABOVE_LEFT);
     }
-    bAdded = bAddedSmvp;
-    if (info->m_num == 2) bAdded = true;
-
-    if (!bAdded)
+
+    if (!bAddedSmvp)
     {
         bAdded = xAddMVPCandOrder(info, picList, refIdx, partIdxRT, MD_ABOVE_RIGHT);
         if (!bAdded)
@@ -2387,6 +2383,10 @@
         {
             info->m_num = 1;
         }
+        else
+        {
+            return;
+        }
     }
 
     if (getSlice()->getEnableTMVPFlag())
@@ -2397,23 +2397,22 @@
         uint32_t partIdxRB;
         uint32_t absPartIdx;
         uint32_t absPartAddr;
-        int lcuIdx;
 
         deriveRightBottomIdx(partIdx, partIdxRB);
         absPartAddr = m_absIdxInLCU + partAddr;
 
         //----  co-located RightBottom Temporal Predictor (H) ---//
         absPartIdx = g_zscanToRaster[partIdxRB];
+        int lcuIdx = -1;
         if ((m_pic->getCU(m_cuAddr)->getCUPelX() + g_rasterToPelX[absPartIdx] + m_pic->getMinCUWidth()) >= m_slice->getSPS()->getPicWidthInLumaSamples())  // image boundary check
         {
-            lcuIdx = -1;
         }
         else if ((m_pic->getCU(m_cuAddr)->getCUPelY() + g_rasterToPelY[absPartIdx] + m_pic->getMinCUHeight()) >= m_slice->getSPS()->getPicHeightInLumaSamples())
         {
-            lcuIdx = -1;
         }
         else
         {
+            uint32_t numPartInCUWidth = m_pic->getNumPartInWidth();
             if ((absPartIdx % numPartInCUWidth < numPartInCUWidth - 1) &&        // is not at the last column of LCU
                 (absPartIdx / numPartInCUWidth < m_pic->getNumPartInHeight() - 1)) // is not at the last row    of LCU
             {
@@ -2423,7 +2422,6 @@
             else if (absPartIdx % numPartInCUWidth < numPartInCUWidth - 1)       // is not at the last column of LCU But is last row of LCU
             {
                 absPartAddr = g_rasterToZscan[(absPartIdx + numPartInCUWidth + 1) % m_pic->getNumPartInCU()];
-                lcuIdx      = -1;
             }
             else if (absPartIdx / numPartInCUWidth < m_pic->getNumPartInHeight() - 1) // is not at the last row of LCU But is last column of LCU
             {
@@ -2433,7 +2431,6 @@
             else //is the right bottom corner of LCU
             {
                 absPartAddr = 0;
-                lcuIdx      = -1;
             }
         }
         if (lcuIdx >= 0 && xGetColMVP(picList, lcuIdx, absPartAddr, colmv, refIdxCol))
@@ -2453,10 +2450,6 @@
         //----  co-located RightBottom Temporal Predictor  ---//
     }
 
-    if (info->m_num > AMVP_MAX_NUM_CANDS)
-    {
-        info->m_num = AMVP_MAX_NUM_CANDS;
-    }
     while (info->m_num < AMVP_MAX_NUM_CANDS)
     {
         info->m_mvCand[info->m_num] = 0;
diff -r d002f45eee16 -r 116349aead02 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Mon Feb 10 19:27:33 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Tue Feb 11 13:03:34 2014 +0900
@@ -134,18 +134,6 @@
         }
     }
 
-    // initialize motion cost
-    for (int num = 0; num < AMVP_MAX_NUM_CANDS + 1; num++)
-    {
-        for (int idx = 0; idx < AMVP_MAX_NUM_CANDS; idx++)
-        {
-            if (idx < num)
-                m_mvpIdxCost[idx][num] = xGetMvpIdxBits(idx, num);
-            else
-                m_mvpIdxCost[idx][num] = MAX_INT;
-        }
-    }
-
     initTempBuff(cfg->param.internalCsp);
 
     m_tempPel = new Pel[g_maxCUWidth * g_maxCUHeight];
@@ -2562,7 +2550,7 @@
                     xEstimateMvPredAMVP(cu, partIdx, list, idx, mvPred[list][idx], &amvpInfo[list][idx], &biPDistTemp);
                     mvpIdx[list][idx] = cu->getMVPIdx(list, partAddr);
 
-                    bitsTemp += m_mvpIdxCost[mvpIdx[list][idx]][AMVP_MAX_NUM_CANDS];
+                    bitsTemp += MVP_IDX_BITS;
                     int merange = m_adaptiveRange[list][idx];
                     MV& mvp = mvPred[list][idx];
                     MV& outmv = mvTemp[list][idx];
@@ -2831,25 +2819,13 @@
     cu->fillMvpCand(partIdx, partAddr, list, refIdx, amvpInfo);
 
     bestMv = amvpInfo->m_mvCand[0];
-    if (amvpInfo->m_num <= 1)
+
+    m_predTempYuv.clear();
+
+    //-- Check Minimum Cost.
+    for (i = 0; i < AMVP_MAX_NUM_CANDS; i++)
     {
-        mvPred = bestMv;
-
-        cu->setMVPIdxSubParts(bestIdx, list, partAddr, partIdx, cu->getDepth(partAddr));
-
-        if (cu->getSlice()->getMvdL1ZeroFlag() && list == REF_PIC_LIST_1)
-        {
-            (*distBiP) = xGetTemplateCost(cu, partAddr, &m_predTempYuv, mvPred, 0, AMVP_MAX_NUM_CANDS, list, refIdx, roiWidth, roiHeight);
-        }
-        return;
-    }
-
-    m_predTempYuv.clear();
-
-    //-- Check Minimum Cost.
-    for (i = 0; i < amvpInfo->m_num; i++)
-    {
-        uint32_t cost = xGetTemplateCost(cu, partAddr, &m_predTempYuv, amvpInfo->m_mvCand[i], i, AMVP_MAX_NUM_CANDS, list, refIdx, roiWidth, roiHeight);
+        uint32_t cost = xGetTemplateCost(cu, partAddr, &m_predTempYuv, amvpInfo->m_mvCand[i], list, refIdx, roiWidth, roiHeight);
         if (bestCost > cost)
         {
             bestCost = cost;
@@ -2945,20 +2921,19 @@
 void TEncSearch::xCheckBestMVP(AMVPInfo* amvpInfo, MV mv, MV& mvPred, int& outMvpIdx, uint32_t& outBits, uint32_t& outCost)
 {
     assert(amvpInfo->m_mvCand[outMvpIdx] == mvPred);
-    if (amvpInfo->m_num < 2) return;
 
     m_me.setMVP(mvPred);
     int bestMvpIdx = outMvpIdx;
-    int mvBitsOrig = m_me.bitcost(mv) + m_mvpIdxCost[outMvpIdx][AMVP_MAX_NUM_CANDS];
+    int mvBitsOrig = m_me.bitcost(mv) + MVP_IDX_BITS;
     int bestMvBits = mvBitsOrig;
 
-    for (int mvpIdx = 0; mvpIdx < amvpInfo->m_num; mvpIdx++)
+    for (int mvpIdx = 0; mvpIdx < AMVP_MAX_NUM_CANDS; mvpIdx++)
     {
         if (mvpIdx == outMvpIdx)
             continue;
 
         m_me.setMVP(amvpInfo->m_mvCand[mvpIdx]);
-        int mvbits = m_me.bitcost(mv) + m_mvpIdxCost[mvpIdx][AMVP_MAX_NUM_CANDS];
+        int mvbits = m_me.bitcost(mv) + MVP_IDX_BITS;
 
         if (mvbits < bestMvBits)
         {
@@ -2978,8 +2953,8 @@
     }
 }
 
-uint32_t TEncSearch::xGetTemplateCost(TComDataCU* cu, uint32_t partAddr, TComYuv* templateCand, MV mvCand, int mvpIdx,
-                                      int mvpCandCount, int list, int refIdx, int sizex, int sizey)
+uint32_t TEncSearch::xGetTemplateCost(TComDataCU* cu, uint32_t partAddr, TComYuv* templateCand, MV mvCand,
+                                      int list, int refIdx, int sizex, int sizey)
 {
     // TODO: does it clip with m_referenceRowsAvailable?
     cu->clipMv(mvCand);
@@ -2990,7 +2965,7 @@
     // calc distortion
     uint32_t cost = m_me.bufSAD(templateCand->getLumaAddr(partAddr), templateCand->getStride());
     x265_emms();
-    return m_rdCost->calcRdSADCost(cost, m_mvpIdxCost[mvpIdx][mvpCandCount]);
+    return m_rdCost->calcRdSADCost(cost, MVP_IDX_BITS);
 }
 
 void TEncSearch::xSetSearchRange(TComDataCU* cu, MV mvp, int merange, MV& mvmin, MV& mvmax)
diff -r d002f45eee16 -r 116349aead02 source/Lib/TLibEncoder/TEncSearch.h
--- a/source/Lib/TLibEncoder/TEncSearch.h	Mon Feb 10 19:27:33 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncSearch.h	Tue Feb 11 13:03:34 2014 +0900
@@ -53,6 +53,8 @@
 #include "bitcost.h"
 #include "motion.h"
 
+#define MVP_IDX_BITS 1
+
 //! \ingroup TLibEncoder
 //! \{
 
@@ -106,9 +108,6 @@
     TComYuv         m_tmpYuvPred; // to avoid constant memory allocation/deallocation in xGetInterPredictionError()
     Pel*            m_tempPel;    // avoid mallocs in xEstimateResidualQT
 
-    // AMVP cost of a given mvp index for a given mvp candidate count
-    uint32_t        m_mvpIdxCost[AMVP_MAX_NUM_CANDS + 1][AMVP_MAX_NUM_CANDS + 1];
-
     // Color space parameters
     int             m_hChromaShift;
     int             m_vChromaShift;
@@ -227,8 +226,8 @@
     void xCheckBestMVP(AMVPInfo* amvpInfo, MV cMv, MV& mvPred, int& mvpIdx,
                        uint32_t& outBits, uint32_t& outCost);
 
-    uint32_t xGetTemplateCost(TComDataCU* cu, uint32_t partAddr, TComYuv* templateCand, MV mvCand, int mvpIdx,
-                              int mvpCandCount, int picList, int refIdx, int sizex, int sizey);
+    uint32_t xGetTemplateCost(TComDataCU* cu, uint32_t partAddr, TComYuv* templateCand, MV mvCand,
+                              int picList, int refIdx, int sizex, int sizey);
 
     uint32_t xGetMvpIdxBits(int idx, int num);
     void xGetBlkBits(PartSize cuMode, bool bPSlice, int partIdx, uint32_t lastMode, uint32_t blockBit[3]);


More information about the x265-devel mailing list