changeset 4756:77db80a67f4e

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.
author Deepthi Devaki <deepthidevaki@multicorewareinc.com>
date Wed, 30 Oct 2013 15:16:59 +0530
parents 74bf8634037c
children e9340727231d
files source/Lib/TLibEncoder/TEncSearch.cpp source/Lib/TLibEncoder/TEncSearch.h source/encoder/compress.cpp
diffstat 3 files changed, 20 insertions(+-), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 @@ uint32_t TEncSearch::xGetInterPrediction
  * \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 @@ void TEncSearch::xMergeEstimation(TComDa
     {
         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 @@ void TEncSearch::xMergeEstimation(TComDa
         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 @@ void TEncSearch::predInterSearch(TComDat
     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 @@ void TEncSearch::predInterSearch(TComDat
 
             // 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 @@ void TEncSearch::predInterSearch(TComDat
 #if CU_STAT_LOGFILE
                 meCost += mrgCost;
 #endif
+                totalmebits += mrgBits;
             }
             else
             {
@@ -2530,11 +2535,18 @@ void TEncSearch::predInterSearch(TComDat
 #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);
 }
 
--- 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 @@ protected:
     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,
--- 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 @@ void TEncCu::xComputeCostInter(TComDataC
     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)