[x265] [PATCH] psy-rd: implement psy-rd in rdlevel=4,3 and 2

sumalatha at multicorewareinc.com sumalatha at multicorewareinc.com
Wed Jun 25 11:37:29 CEST 2014


# HG changeset patch
# User Sumalatha Polureddy<sumalatha at multicorewareinc.com>
# Date 1403689018 -19800
# Node ID 6ef75d4d64dc98194a1c90a952ce14677bfbcb78
# Parent  613bfe5cd169c3accb4646891f904735ba21290d
psy-rd: implement psy-rd in rdlevel=4,3 and 2

diff -r 613bfe5cd169 -r 6ef75d4d64dc source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Tue Jun 24 16:39:42 2014 +0530
+++ b/source/encoder/compress.cpp	Wed Jun 25 15:06:58 2014 +0530
@@ -72,7 +72,17 @@
     m_rdGoOnSbacCoder->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
 
     cu->m_totalBits = m_entropyCoder->getNumberOfWrittenBits();
-    cu->m_totalRDCost = m_rdCost->calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
+    if (m_rdCost->psyRdEnabled())
+    {
+        int part = g_convertToBit[cu->getCUSize(0)];
+        cu->m_psyEnergy = m_rdCost->psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+            m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
+        cu->m_totalPsyCost = m_rdCost->calcPsyRdCost(cu->m_totalDistortion, cu->m_totalBits, cu->m_psyEnergy);
+    }
+    else
+    {
+        cu->m_totalRDCost = m_rdCost->calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
+    }
 }
 
 void TEncCu::xComputeCostIntraInInter(TComDataCU* cu, PartSize partSize)
@@ -321,7 +331,9 @@
             //Encode with residue
             m_search->encodeResAndCalcRdInterCU(outTempCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], false, true);
 
-            if (outTempCU->m_totalRDCost < outBestCU->m_totalRDCost)    //Choose best from no-residue mode and residue mode
+            uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+            uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+            if (tempCost < bestCost) //Choose best from no-residue mode and residue mode
             {
                 TComDataCU* tmp = outTempCU;
                 outTempCU = outBestCU;
@@ -485,7 +497,9 @@
 
                     m_search->encodeResAndCalcRdInterCU(outBestCU, m_origYuv[depth], m_bestPredYuv[depth], m_tmpResiYuv[depth],
                                                         m_bestResiYuv[depth], m_bestRecoYuv[depth], false, true);
-                    if (m_bestMergeCU[depth]->m_totalRDCost < outBestCU->m_totalRDCost)
+                    uint64_t bestMergeCost = m_rdCost->psyRdEnabled() ? m_bestMergeCU[depth]->m_totalPsyCost : m_bestMergeCU[depth]->m_totalRDCost;
+                    uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                    if (bestMergeCost < bestCost)
                     {
                         outBestCU = m_bestMergeCU[depth];
                         tempYuv = m_modePredYuv[3][depth];
@@ -512,12 +526,21 @@
                     if (bdoIntra)
                     {
                         xComputeCostIntraInInter(m_intraInInterCU[depth], SIZE_2Nx2N);
+                        uint64_t intraInInterCost, bestCost;
                         if (m_param->rdLevel > 2)
                         {
                             xEncodeIntraInInter(m_intraInInterCU[depth], m_origYuv[depth], m_modePredYuv[5][depth],
                                                 m_tmpResiYuv[depth],  m_tmpRecoYuv[depth]);
+                            intraInInterCost = m_rdCost->psyRdEnabled() ? m_intraInInterCU[depth]->m_totalPsyCost : m_intraInInterCU[depth]->m_totalRDCost;
+                            bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                         }
-                        if (m_intraInInterCU[depth]->m_totalRDCost < outBestCU->m_totalRDCost)
+                        else
+                        {
+                            intraInInterCost = m_intraInInterCU[depth]->m_totalRDCost;
+                            bestCost = outBestCU->m_totalRDCost;
+
+                        }
+                        if (intraInInterCost < bestCost)
                         {
                             outBestCU = m_intraInInterCU[depth];
                             tempYuv = m_modePredYuv[5][depth];
@@ -625,7 +648,15 @@
                 m_entropyCoder->resetBits();
                 m_entropyCoder->encodeSplitFlag(outBestCU, 0, depth);
                 outBestCU->m_totalBits += m_entropyCoder->getNumberOfWrittenBits(); // split bits
-                outBestCU->m_totalRDCost  = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
+                if (m_rdCost->psyRdEnabled())
+                {
+                    outBestCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits,
+                        outBestCU->m_psyEnergy);
+                }
+                else
+                {
+                    outBestCU->m_totalRDCost = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
+                }
             }
 
             // copy original YUV samples to PCM buffer
@@ -682,8 +713,13 @@
             uint64_t avgCost = 0;
             if (totalCountNeigh + totalCountCU)
                 avgCost = ((3 * totalCostCU) + (2 * totalCostNeigh)) / ((3 * totalCountCU) + (2 * totalCountNeigh));
+            uint64_t bestavgCost = 0;
+            if (m_param->rdLevel > 1)
+                bestavgCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+            else
+                bestavgCost = outBestCU->m_totalRDCost;
 
-            if (outBestCU->m_totalRDCost < avgCost && avgCost != 0 && depth != 0)
+            if (bestavgCost < avgCost && avgCost != 0 && depth != 0)
             {
                 /* Copy Best data to Picture for next partition prediction. */
                 outBestCU->copyToPic((uint8_t)depth);
@@ -720,7 +756,11 @@
 #if EARLY_EXIT
                 if (subBestPartCU->getPredictionMode(0) != MODE_INTRA)
                 {
-                    uint64_t tempavgCost = subBestPartCU->m_totalRDCost;
+                    uint64_t tempavgCost = 0;
+                    if (m_param->rdLevel > 1)
+                        tempavgCost = m_rdCost->psyRdEnabled() ? subBestPartCU->m_totalPsyCost : subBestPartCU->m_totalRDCost;
+                    else
+                        tempavgCost = subBestPartCU->m_totalRDCost;
                     TComDataCU* rootCU = pic->getPicSym()->getCU(outTempCU->getAddr());
                     uint64_t temp = rootCU->m_avgCost[depth + 1] * rootCU->m_count[depth + 1];
                     rootCU->m_count[depth + 1] += 1;
@@ -751,7 +791,17 @@
             }
         }
         if (m_param->rdLevel > 1)
-            outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+        {
+            if (m_rdCost->psyRdEnabled())
+            {
+                outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits,
+                    outTempCU->m_psyEnergy);
+            }
+            else
+            {
+                outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+            }
+        }
         else
             outTempCU->m_totalRDCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
@@ -790,14 +840,16 @@
 #if EARLY_EXIT
             if (depth == 0)
             {
-                uint64_t tempavgCost = outBestCU->m_totalRDCost;
+                uint64_t tempavgCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                 TComDataCU* rootCU = pic->getPicSym()->getCU(outTempCU->getAddr());
                 uint64_t temp = rootCU->m_avgCost[depth] * rootCU->m_count[depth];
                 rootCU->m_count[depth] += 1;
                 rootCU->m_avgCost[depth] = (temp + tempavgCost) / rootCU->m_count[depth];
             }
 #endif
-            if (outTempCU->m_totalRDCost < outBestCU->m_totalRDCost)
+            uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+            uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost; 
+            if (tempCost < bestCost)
             {
                 outBestCU = outTempCU;
                 tempYuv = m_tmpRecoYuv[depth];
diff -r 613bfe5cd169 -r 6ef75d4d64dc source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Jun 24 16:39:42 2014 +0530
+++ b/source/encoder/encoder.cpp	Wed Jun 25 15:06:58 2014 +0530
@@ -1263,8 +1263,8 @@
         p->bBPyramid = 0;
     }
 
-    // psy-rd is not yet supported in RD levels below 5
-    if (p->rdLevel < 5)
+    // psy-rd is not supported in RD levels below 2
+    if (p->rdLevel < 2)
         p->psyRd = 0.0;
 
     /* In 444, chroma gets twice as much resolution, so halve quality when psy-rd is enabled */
@@ -1275,7 +1275,7 @@
     }
 
     // disable RDOQ if psy-rd is enabled; until we make it psy-aware
-    m_bEnableRDOQ = p->psyRd == 0.0 && p->rdLevel >= 4;
+    m_bEnableRDOQ = p->psyRd == 0.0 && p->rdLevel >= 1;
 
     if (p->bLossless)
     {


More information about the x265-devel mailing list