[x265] [PATCH] no-rdo: use bit estimates from ME to calculate RDcost

deepthidevaki at multicorewareinc.com deepthidevaki at multicorewareinc.com
Wed Oct 30 10:47:14 CET 2013


# HG changeset patch
# User Deepthi Devaki <deepthidevaki at multicorewareinc.com>
# Date 1383126419 -19800
# Node ID 77db80a67f4e55f22bc02ed02930a269bfac6b50
# Parent  74bf8634037ce3e673b21738a5ffaf1c14381414
no-rdo: use bit estimates from ME to calculate RDcost.

bits estimated in ME stored in CU and used for calculating rdcost along with distortion. This results in better bitrate with no-rdo, with small drop in PSNR.

diff -r 74bf8634037c -r 77db80a67f4e source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Wed Oct 30 13:44:16 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Wed Oct 30 15:16:59 2013 +0530
@@ -2115,7 +2115,7 @@
  * \param bValid
  * \returns void
  */
-void TEncSearch::xMergeEstimation(TComDataCU* cu, int puIdx, uint32_t& interDir, TComMvField* mvField, uint32_t& mergeIndex, uint32_t& outCost, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, int& numValidMergeCand)
+void TEncSearch::xMergeEstimation(TComDataCU* cu, int puIdx, uint32_t& interDir, TComMvField* mvField, uint32_t& mergeIndex, uint32_t& outCost, uint32_t& outbits, TComMvField* mvFieldNeighbours, UChar* interDirNeighbours, int& numValidMergeCand)
 {
     uint32_t absPartIdx = 0;
     int width = 0;
@@ -2144,7 +2144,7 @@
     {
         uint32_t costCand = MAX_UINT;
         uint32_t bitsCand = 0;
-       
+
         cu->getCUMvField(REF_PIC_LIST_0)->m_mv[absPartIdx] = mvFieldNeighbours[0 + 2 * mergeCand].mv;
         cu->getCUMvField(REF_PIC_LIST_0)->m_refIdx[absPartIdx] = mvFieldNeighbours[0 + 2 * mergeCand].refIdx;
         cu->getCUMvField(REF_PIC_LIST_1)->m_mv[absPartIdx] = mvFieldNeighbours[1 + 2 * mergeCand].mv;
@@ -2160,6 +2160,7 @@
         if (costCand < outCost)
         {
             outCost = costCand;
+            outbits = bitsCand;
             mvField[0] = mvFieldNeighbours[0 + 2 * mergeCand];
             mvField[1] = mvFieldNeighbours[1 + 2 * mergeCand];
             interDir = interDirNeighbours[mergeCand];
@@ -2226,6 +2227,8 @@
     UChar interDirNeighbours[MRG_MAX_NUM_CANDS];
     int numValidMergeCand = 0;
 
+    int totalmebits = 0;
+
     for (int partIdx = 0; partIdx < numPart; partIdx++)
     {
         uint32_t listCost[2] = { MAX_UINT, MAX_UINT };
@@ -2495,7 +2498,8 @@
 
             // find Merge result
             uint32_t mrgCost = MAX_UINT;
-            xMergeEstimation(cu, partIdx, mrgInterDir, mrgMvField, mrgIndex, mrgCost, mvFieldNeighbours, interDirNeighbours, numValidMergeCand);
+            uint32_t mrgBits = 0;
+            xMergeEstimation(cu, partIdx, mrgInterDir, mrgMvField, mrgIndex, mrgCost, mrgBits, mvFieldNeighbours, interDirNeighbours, numValidMergeCand);
             if (mrgCost < meCost)
             {
                 // set Merge result
@@ -2517,6 +2521,7 @@
 #if CU_STAT_LOGFILE
                 meCost += mrgCost;
 #endif
+                totalmebits += mrgBits;
             }
             else
             {
@@ -2530,11 +2535,18 @@
 #if CU_STAT_LOGFILE
                 meCost += meCost;
 #endif
+                totalmebits += mebits;
             }
         }
+        else
+        {
+            totalmebits += mebits;
+        }
         motionCompensation(cu, predYuv, REF_PIC_LIST_X, partIdx, bLuma, bChroma);
     }
 
+    cu->m_totalBits = totalmebits;
+
     setWpScalingDistParam(cu, -1, REF_PIC_LIST_X);
 }
 
diff -r 74bf8634037c -r 77db80a67f4e source/Lib/TLibEncoder/TEncSearch.h
--- a/source/Lib/TLibEncoder/TEncSearch.h	Wed Oct 30 13:44:16 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.h	Wed Oct 30 15:16:59 2013 +0530
@@ -211,7 +211,7 @@
     void xGetBlkBits(PartSize cuMode, bool bPSlice, int partIdx, uint32_t lastMode, uint32_t blockBit[3]);
 
     void xMergeEstimation(TComDataCU* cu, int partIdx, uint32_t& uiInterDir,
-                          TComMvField* pacMvField, uint32_t& mergeIndex, uint32_t& outCost,
+                          TComMvField* pacMvField, uint32_t& mergeIndex, uint32_t& outCost, uint32_t& outbits,
                           TComMvField* mvFieldNeighbors, UChar* interDirNeighbors, int& numValidMergeCand);
 
     void xRestrictBipredMergeCand(TComDataCU* cu, uint32_t puIdx, TComMvField* mvFieldNeighbours,
diff -r 74bf8634037c -r 77db80a67f4e source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Wed Oct 30 13:44:16 2013 +0530
+++ b/source/encoder/compress.cpp	Wed Oct 30 15:16:59 2013 +0530
@@ -223,10 +223,12 @@
     m_tmpResiYuv[depth]->clear();
 
     //do motion compensation only for Luma since luma cost alone is calculated
+    outTempCU->m_totalBits = 0;
     m_search->predInterSearch(outTempCU, outPredYuv, bUseMRG, true, false);
     int part = partitionFromSizes(outTempCU->getWidth(0), outTempCU->getHeight(0));
-    outTempCU->m_totalCost = primitives.sse_pp[part](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
-                                                     outPredYuv->getLumaAddr(), outPredYuv->getStride());
+    uint32_t distortion = primitives.sse_pp[part](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+                                                  outPredYuv->getLumaAddr(), outPredYuv->getStride());
+    outTempCU->m_totalCost = m_rdCost->calcRdCost(distortion, outTempCU->m_totalBits);
 }
 
 void TEncCu::xComputeCostMerge2Nx2N(TComDataCU*& outBestCU, TComDataCU*& outTempCU, bool* earlyDetectionSkip, TComYuv*& bestPredYuv, TComYuv*& yuvReconBest)


More information about the x265-devel mailing list