[x265] [PATCH] Changed the mode selection based on SSE cost for no-rdo path

sumalatha at multicorewareinc.com sumalatha at multicorewareinc.com
Tue Jul 9 13:24:03 CEST 2013


# HG changeset patch
# User sumalatha
# Date 1373366579 -19800
# Node ID 81f9fbd222b41556edded655c6b570eb624420b4
# Parent  a5c300785b8ff4191bd2fb04addeeb89b2612117
Changed the mode selection based on SSE cost for no-rdo path

diff -r a5c300785b8f -r 81f9fbd222b4 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Tue Jul 09 00:25:00 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Tue Jul 09 16:12:59 2013 +0530
@@ -504,7 +504,7 @@
 #if CU_STAT_LOGFILE
     totalCU++;
     if (pcCu->getSlice()->getSliceType() != I_SLICE)
-        fprintf(fp1, "CU number : %d \n", totalCU);
+        fprintf(fp1, "\n CU number : %d ", totalCU);
 #endif
     //printf("compressCU[%2d]: Best=0x%08X, Temp=0x%08X\n", omp_get_thread_num(), m_ppcBestCU[0], m_ppcTempCU[0]);
 
@@ -522,7 +522,7 @@
         xCompressIntraCU(m_ppcBestCU[0], m_ppcTempCU[0], NULL, 0);
     else
     {
-        if(!m_pcEncCfg->getUseRDO())
+        if (!m_pcEncCfg->getUseRDO())
         {
             TComDataCU* rpcBestCU = NULL;
 
@@ -1668,11 +1668,12 @@
     //PPAScopeEvent(TEncCU_xCheckRDCostIntra + uiDepth);
     UInt uiDepth = rpcTempCU->getDepth(0);
     UInt uiPreCalcDistC = 0;
+
     rpcTempCU->setSkipFlagSubParts(false, 0, uiDepth);
     rpcTempCU->setPartSizeSubParts(eSize, 0, uiDepth);
     rpcTempCU->setPredModeSubParts(MODE_INTRA, 0, uiDepth);
     rpcTempCU->setCUTransquantBypassSubParts(m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth);
-    
+
     m_pcPredSearch->estIntraPredQT(rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, true);
 
     m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU());
@@ -1749,11 +1750,11 @@
 
     rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
     rpcTempCU->getTotalBins() = ((TEncBinCABAC*)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
-    if(!m_pcEncCfg->getUseRDO())
+    if (!m_pcEncCfg->getUseRDO())
     {
         UInt partEnum = PartitionFromSizes(rpcTempCU->getWidth(0), rpcTempCU->getHeight(0));
-        UInt SATD = primitives.satd[partEnum]((pixel *)m_ppcOrigYuv[uiDepth]->getLumaAddr(), m_ppcOrigYuv[uiDepth]->getStride(),
-                                            (pixel *)m_ppcPredYuvTemp[uiDepth]->getLumaAddr(), m_ppcPredYuvTemp[uiDepth]->getStride());
+        UInt SATD = primitives.satd[partEnum]((pixel*)m_ppcOrigYuv[uiDepth]->getLumaAddr(), m_ppcOrigYuv[uiDepth]->getStride(),
+                                              (pixel*)m_ppcPredYuvTemp[uiDepth]->getLumaAddr(), m_ppcPredYuvTemp[uiDepth]->getStride());
         x265_emms();
         rpcTempCU->getTotalDistortion() = SATD;
     }
diff -r a5c300785b8f -r 81f9fbd222b4 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Tue Jul 09 00:25:00 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Tue Jul 09 16:12:59 2013 +0530
@@ -49,7 +49,6 @@
 #if CU_STAT_LOGFILE
 extern FILE *fp1;
 extern bool mergeFlag;
-UInt64      meCost;
 #endif
 DECLARE_CYCLE_COUNTER(ME);
 
@@ -2875,8 +2874,7 @@
     TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
     UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
     Int numValidMergeCand = 0;
-    if (!m_pcEncCfg->getUseRDO())
-        pcCU->getTotalCost() = 0;
+  
 
     for (Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++)
     {
@@ -3270,9 +3268,7 @@
 
                 uiMEBits = uiBits[1];
             }
-#if CU_STAT_LOGFILE
-            meCost += uiCost[0];
-#endif
+
         } // end if bTestNormalMC
 
         if (pcCU->getPartitionSize(uiPartAddr) != SIZE_2Nx2N)
@@ -3319,9 +3315,7 @@
                 pcCU->setMVPNumSubParts(-1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
                 pcCU->setMVPIdxSubParts(-1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
                 pcCU->setMVPNumSubParts(-1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
-#if CU_STAT_LOGFILE
-                meCost += uiMRGCost;
-#endif
+
                 if (!m_pcEncCfg->getUseRDO())
                     pcCU->getTotalCost() += uiMRGCost;
             }
@@ -3334,18 +3328,11 @@
                     pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField(cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx);
                     pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx);
                 }
-#if CU_STAT_LOGFILE
-                meCost += uiMECost;
-#endif
-                if (!m_pcEncCfg->getUseRDO())
-                    pcCU->getTotalCost() += uiMECost;
+
+                
             }
         }
-        else
-        {
-            if (!m_pcEncCfg->getUseRDO())
-                pcCU->getTotalCost() += uiCostTemp;
-        }
+       
         motionCompensation(pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx);
     }
 
diff -r a5c300785b8f -r 81f9fbd222b4 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Tue Jul 09 00:25:00 2013 -0500
+++ b/source/encoder/compress.cpp	Tue Jul 09 16:12:59 2013 +0530
@@ -217,18 +217,6 @@
 
     // set context models
     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
-
-    // determine residual for partition
-    //UInt   uiPUDistY = 0;
-    //UInt   uiPUDistC = 0;
-    //UInt64 dPUCost   = 0;
-    //m_pcPredSearch->xRecurIntraCodingQT(pcCU, uiInitTrDepth, uiPartOffset, true, m_ppcOrigYuv[uiDepth], m_ppcPredYuvMode[index][uiDepth], m_ppcResiYuvTemp[uiDepth], uiPUDistY, uiPUDistC, false, dPUCost);
-
-    //UInt partEnum = PartitionFromSizes(pcCU->getWidth(0), pcCU->getHeight(0));
-    // UInt SATD = primitives.satd[partEnum]((pixel*)m_ppcOrigYuv[uiDepth]->getLumaAddr(), m_ppcOrigYuv[uiDepth]->getStride(),
-    // (pixel*)m_ppcPredYuvMode[index][uiDepth]->getLumaAddr(),  m_ppcPredYuvMode[index][uiDepth]->getStride());
-
-    // pcCU->getTotalCost() = SATD;
 }
 
 /** check RD costs for a CU block encoded with merge
@@ -273,15 +261,9 @@
         // do MC
         m_pcPredSearch->motionCompensation(rpcTempCU, m_ppcPredYuvMode[4][uhDepth]);
 
-        /*Todo: Fix the satd cost estimates. Why is merge being chosen in high motion areas: estimated distortion is too low?*/
+        /*Find the merge candidate using SSE distortion and assigning the distortion to the cost */
 
-        m_pcPredSearch->encodeResAndCalcRdInterCU(rpcTempCU,
-                                                  m_ppcOrigYuv[uhDepth],
-                                                  tmpPredYuv,
-                                                  m_ppcResiYuvTemp[uhDepth],
-                                                  m_ppcResiYuvBest[uhDepth],
-                                                  m_ppcRecoYuvTemp[uhDepth],
-                                                  (true));
+        rpcTempCU->getTotalCost() = primitives.sse_pp[PartitionFromSizes(rpcTempCU->getWidth(0), rpcTempCU->getHeight(0))]((pixel*)m_ppcOrigYuv[uhDepth]->getLumaAddr(), (intptr_t)m_ppcOrigYuv[uhDepth]->getStride(), (pixel*)tmpPredYuv->getLumaAddr(), tmpPredYuv->getStride());
 
         Int orgQP = rpcTempCU->getQP(0);
 
@@ -303,10 +285,6 @@
         rpcTempCU->initEstData(uhDepth, orgQP);
     }
 
-    me_merge.setSourcePU(0, rpcBestCU->getWidth(0), rpcBestCU->getHeight(0));
-
-    rpcBestCU->getTotalCost() = me_merge.bufSATD((pixel*)bestPredYuv->getLumaAddr(),
-                                                 bestPredYuv->getStride());
     x265_emms();
 }
 
@@ -327,6 +305,8 @@
     m_ppcResiYuvTemp[uhDepth]->clear();
 
     m_pcPredSearch->predInterSearch(rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvMode[Index][uhDepth], bUseMRG);
+    //calc the distortion from SSE and assigning to the cost
+    rpcTempCU->getTotalCost() = primitives.sse_pp[PartitionFromSizes(rpcTempCU->getWidth(0), rpcTempCU->getHeight(0))]((pixel*)m_ppcOrigYuv[uhDepth]->getLumaAddr(), (intptr_t)m_ppcOrigYuv[uhDepth]->getStride(), (pixel*)m_ppcPredYuvMode[Index][uhDepth]->getLumaAddr(),  m_ppcPredYuvMode[Index][uhDepth]->getStride());
 }
 
 Void TEncCu::xCompressInterCU(TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, TComDataCU*& pcCU, UInt uiDepth, UInt PartitionIndex)
@@ -389,15 +369,12 @@
         }
 
         /*Compute  Merge Cost  */
-#if 1
-
         xComputeCostMerge2Nx2N(m_MergeBestCU[uiDepth], m_MergeCU[uiDepth], m_ppcPredYuvMode[3][uiDepth], m_ppcPredYuvMode[4][uiDepth]);
         rpcBestCU = m_MergeBestCU[uiDepth];
         YuvTemp = m_ppcPredYuvMode[3][uiDepth];
         m_ppcPredYuvMode[3][uiDepth] = m_ppcPredYuvBest[uiDepth];
         m_ppcPredYuvBest[uiDepth] = YuvTemp;
 
-#endif
         /*Compute 2Nx2N mode costs*/
         xComputeCostInter(m_InterCU_2Nx2N[uiDepth], SIZE_2Nx2N, 0);
 
@@ -443,11 +420,10 @@
             m_ppcPredYuvBest[uiDepth] = YuvTemp;
         }
 
-        if (m_MergeBestCU[uiDepth] != rpcBestCU)
-            m_pcPredSearch->encodeResAndCalcRdInterCU(rpcBestCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvBest[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcResiYuvBest[uiDepth], m_ppcRecoYuvBest[uiDepth], false);
+        m_pcPredSearch->encodeResAndCalcRdInterCU(rpcBestCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvBest[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcResiYuvBest[uiDepth], m_ppcRecoYuvBest[uiDepth], false);
 
         /*compute intra cost */
-#if 1
+
         if (rpcBestCU->getCbf(0, TEXT_LUMA) != 0   ||
             rpcBestCU->getCbf(0, TEXT_CHROMA_U) != 0   ||
             rpcBestCU->getCbf(0, TEXT_CHROMA_V) != 0)
@@ -467,7 +443,6 @@
                 m_ppcRecoYuvTemp[uiDepth] = tmpPic;
             }
         }
-#endif // if 1
 
         /* Disable recursive analysis for whole CUs temporarily*/
         if ((rpcBestCU != 0) && (rpcBestCU->isSkipped(0)))
@@ -496,9 +471,15 @@
 #if CU_STAT_LOGFILE
     if (rpcBestCU)
     {
-        fprintf(fp1, "\n Width : %d ,Inter 2Nx2N_Merge : %d , 2Nx2N : %d , 2NxN : %d, Nx2N : %d , intra : %d", rpcBestCU->getWidth(0), m_MergeBestCU[uiDepth]->getTotalCost(), m_InterCU_2Nx2N[uiDepth]->getTotalCost(), m_InterCU_2NxN[uiDepth]->getTotalCost(), m_InterCU_Nx2N[uiDepth]->getTotalCost(), m_IntrainInterCU[uiDepth]->getTotalCost());
+        fprintf(fp1, "\n Width : %d ,Inter 2Nx2N_Merge : %d , 2Nx2N : %d , 2NxN : %d, Nx2N : %d ", rpcBestCU->getWidth(0), m_MergeBestCU[uiDepth]->getTotalCost(), m_InterCU_2Nx2N[uiDepth]->getTotalCost(), m_InterCU_2NxN[uiDepth]->getTotalCost(), m_InterCU_Nx2N[uiDepth]->getTotalCost());
+        if (rpcBestCU->getCbf(0, TEXT_LUMA) != 0   ||
+            rpcBestCU->getCbf(0, TEXT_CHROMA_U) != 0   ||
+            rpcBestCU->getCbf(0, TEXT_CHROMA_V) != 0)
+        {
+            fprintf(fp1, ", intra : %d", m_IntrainInterCU[uiDepth]->getTotalCost());
+        }
     }
-#endif
+#endif // if CU_STAT_LOGFILE
 
 // further split
     if (bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: july_9_hevc_new.patch
Type: text/x-patch
Size: 10988 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20130709/24c582d9/attachment.bin>


More information about the x265-devel mailing list