[x265] [PATCH] compress: insert check for merge MV candidates

deepthi at multicorewareinc.com deepthi at multicorewareinc.com
Tue Jan 28 11:56:46 CET 2014


# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1390906174 -19800
# Node ID 7d81cdb5836a7672478e803ff8f66cbc0140cfae
# Parent  3568c1b19947f8641504c69bca6ab859ed11825e
compress: insert check for merge MV candidates.

diff -r 3568c1b19947 -r 7d81cdb5836a source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Tue Jan 28 01:49:03 2014 -0600
+++ b/source/encoder/compress.cpp	Tue Jan 28 16:19:34 2014 +0530
@@ -236,76 +236,89 @@
     outBestCU->setMergeFlagSubParts(true, 0, 0, depth);
 
     int part = g_convertToBit[outTempCU->getWidth(0)];
-    int bestMergeCand = 0;
+    int bestMergeCand = -1;
     uint32_t bitsCand = 0;
+
     for (int mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand)
     {
-        // set MC parameters, interprets depth relative to LCU level
-        outTempCU->setMergeIndexSubParts(mergeCand, 0, 0, depth);
-        outTempCU->setInterDirSubParts(interDirNeighbours[mergeCand], 0, 0, depth);
-        outTempCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField(mvFieldNeighbours[0 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to rpcTempCU level
-        outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to rpcTempCU level
+        if ( mvFieldNeighbours[0 + 2 * mergeCand].mv.y < (m_cfg->param.searchRange+1) * 4
+          && mvFieldNeighbours[1 + 2 * mergeCand].mv.y < (m_cfg->param.searchRange+1) * 4)
+        {
+            // set MC parameters, interprets depth relative to LCU level
+            outTempCU->setMergeIndexSubParts(mergeCand, 0, 0, depth);
+            outTempCU->setInterDirSubParts(interDirNeighbours[mergeCand], 0, 0, depth);
+            outTempCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField(mvFieldNeighbours[0 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to rpcTempCU level
+            outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to rpcTempCU level
 
-        // do MC only for Luma part
-        m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, -1, true, false);
-        bitsCand = mergeCand + 1;
-        if (mergeCand == (int)m_cfg->param.maxNumMergeCand - 1)
-        {
-            bitsCand--;
-        }
-        outTempCU->m_totalBits = bitsCand;
-        outTempCU->m_totalDistortion = primitives.sa8d[part](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
-                                                             m_tmpPredYuv[depth]->getLumaAddr(), m_tmpPredYuv[depth]->getStride());
-        outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+            // do MC only for Luma part
+            m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, -1, true, false);
+            bitsCand = mergeCand + 1;
+            if (mergeCand == (int)m_cfg->param.maxNumMergeCand - 1)
+            {
+                bitsCand--;
+            }
+            outTempCU->m_totalBits = bitsCand;
+            outTempCU->m_totalDistortion = primitives.sa8d[part](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+                                                                 m_tmpPredYuv[depth]->getLumaAddr(), m_tmpPredYuv[depth]->getStride());
+            outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
-        if (outTempCU->m_totalCost < outBestCU->m_totalCost)
-        {
-            bestMergeCand = mergeCand;
-            TComDataCU* tmp = outTempCU;
-            outTempCU = outBestCU;
-            outBestCU = tmp;
-            // Change Prediction data
-            TComYuv* yuv = bestPredYuv;
-            bestPredYuv = m_tmpPredYuv[depth];
-            m_tmpPredYuv[depth] = yuv;
+            if (outTempCU->m_totalCost < outBestCU->m_totalCost)
+            {
+                bestMergeCand = mergeCand;
+                TComDataCU* tmp = outTempCU;
+                outTempCU = outBestCU;
+                outBestCU = tmp;
+                // Change Prediction data
+                TComYuv* yuv = bestPredYuv;
+                bestPredYuv = m_tmpPredYuv[depth];
+                m_tmpPredYuv[depth] = yuv;
+            }
         }
     }
+    
+    if (bestMergeCand < 0)
+    {
+        outBestCU->setMergeFlagSubParts(false, 0, 0, depth);
+        outBestCU->initEstData(depth, outBestCU->getQP(0));
+    }
+    else
+    {
+        outTempCU->setMergeIndexSubParts(bestMergeCand, 0, 0, depth);
+        outTempCU->setInterDirSubParts(interDirNeighbours[bestMergeCand], 0, 0, depth);
+        outTempCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField(mvFieldNeighbours[0 + 2 * bestMergeCand], SIZE_2Nx2N, 0, 0);
+        outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * bestMergeCand], SIZE_2Nx2N, 0, 0);
+        outTempCU->m_totalBits = outBestCU->m_totalBits;
+        outTempCU->m_totalDistortion = outBestCU->m_totalDistortion;
+        outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+        if (m_cfg->param.rdLevel > 2)
+        {
+            //calculate the motion compensation for chroma for the best mode selected
+            int numPart = outBestCU->getNumPartInter();
+            for (int partIdx = 0; partIdx < numPart; partIdx++)
+            {
+                m_search->motionCompensation(outBestCU, bestPredYuv, REF_PIC_LIST_X, partIdx, false, true);
+            }
 
-    outTempCU->setMergeIndexSubParts(bestMergeCand, 0, 0, depth);
-    outTempCU->setInterDirSubParts(interDirNeighbours[bestMergeCand], 0, 0, depth);
-    outTempCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField(mvFieldNeighbours[0 + 2 * bestMergeCand], SIZE_2Nx2N, 0, 0);
-    outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * bestMergeCand], SIZE_2Nx2N, 0, 0);
-    outTempCU->m_totalBits = outBestCU->m_totalBits;
-    outTempCU->m_totalDistortion = outBestCU->m_totalDistortion;
-    outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-    if (m_cfg->param.rdLevel > 2)
-    {
-        //calculate the motion compensation for chroma for the best mode selected
-        int numPart = outBestCU->getNumPartInter();
-        for (int partIdx = 0; partIdx < numPart; partIdx++)
-        {
-            m_search->motionCompensation(outBestCU, bestPredYuv, REF_PIC_LIST_X, partIdx, false, true);
-        }
+            //No-residue mode
+            m_search->encodeResAndCalcRdInterCU(outBestCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], true);
 
-        //No-residue mode
-        m_search->encodeResAndCalcRdInterCU(outBestCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], true);
-
-        TComYuv* yuv = yuvReconBest;
-        yuvReconBest = m_tmpRecoYuv[depth];
-        m_tmpRecoYuv[depth] = yuv;
-
-        //Encode with residue
-        m_search->encodeResAndCalcRdInterCU(outTempCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], false);
-
-        if (outTempCU->m_totalCost < outBestCU->m_totalCost)    //Choose best from no-residue mode and residue mode
-        {
-            TComDataCU* tmp = outTempCU;
-            outTempCU = outBestCU;
-            outBestCU = tmp;
-
-            yuv = yuvReconBest;
+            TComYuv* yuv = yuvReconBest;
             yuvReconBest = m_tmpRecoYuv[depth];
             m_tmpRecoYuv[depth] = yuv;
+
+            //Encode with residue
+            m_search->encodeResAndCalcRdInterCU(outTempCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], false);
+
+            if (outTempCU->m_totalCost < outBestCU->m_totalCost)    //Choose best from no-residue mode and residue mode
+            {
+                TComDataCU* tmp = outTempCU;
+                outTempCU = outBestCU;
+                outBestCU = tmp;
+
+                yuv = yuvReconBest;
+                yuvReconBest = m_tmpRecoYuv[depth];
+                m_tmpRecoYuv[depth] = yuv;
+            }
         }
     }
     x265_emms();


More information about the x265-devel mailing list