[x265] [PATCH] no-rdo: made TOPSKIP Macro as CLI option

sumalatha at multicorewareinc.com sumalatha at multicorewareinc.com
Thu Nov 28 12:57:45 CET 2013


# HG changeset patch
# User Sumalatha Polureddy
# Date 1385639857 -19800
# Node ID bebef81f10563d404ddb03ce0d7f53dae2013664
# Parent  2ba6c26c9febdc8c57d3014c0cf98d4897d3992d
no-rdo: made TOPSKIP Macro as CLI option

--topskip will enable topskip
--no-topskip will disable topskip

diff -r 2ba6c26c9feb -r bebef81f1056 source/common/common.cpp
--- a/source/common/common.cpp	Thu Nov 28 15:04:04 2013 +0530
+++ b/source/common/common.cpp	Thu Nov 28 17:27:37 2013 +0530
@@ -647,6 +647,7 @@
     TOOLOPT(param->bEnableCbfFastMode, "cfm");
     TOOLOPT(param->bEnableConstrainedIntra, "cip");
     TOOLOPT(param->bEnableEarlySkip, "esd");
+    TOOLOPT(param->bEnableTopSkip, "topskip");
     fprintf(stderr, "rd=%d ", param->rdLevel);
 
     TOOLOPT(param->bEnableLoopFilter, "lft");
@@ -722,6 +723,7 @@
     OPT("amp") p->bEnableAMP = bvalue;
     OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value);
     OPT("early-skip") p->bEnableEarlySkip = bvalue;
+    OPT("topskip") p->bEnableTopSkip = bvalue;
     OPT("fast-cbf") p->bEnableCbfFastMode = bvalue;
     OPT("rdpenalty") p->rdPenalty = atoi(value);
     OPT("tskip") p->bEnableTransformSkip = bvalue;
@@ -800,6 +802,7 @@
     BOOL(p->bEnableAMP, "amp");
     s += sprintf(s, " max-merge=%d", p->maxNumMergeCand);
     BOOL(p->bEnableEarlySkip, "early-skip");
+    BOOL(p->bEnableTopSkip, "topskip");
     BOOL(p->bEnableCbfFastMode, "fast-cbf");
     s += sprintf(s, " rdpenalty=%d", p->rdPenalty);
     BOOL(p->bEnableTransformSkip, "tskip");
diff -r 2ba6c26c9feb -r bebef81f1056 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Thu Nov 28 15:04:04 2013 +0530
+++ b/source/encoder/compress.cpp	Thu Nov 28 17:27:37 2013 +0530
@@ -27,7 +27,6 @@
 /* Lambda Partition Select adjusts the threshold value for Early Exit in No-RDO flow */
 #define LAMBDA_PARTITION_SELECT     0.9
 #define EARLY_EXIT                  1
-#define TOPSKIP                     1
 
 using namespace x265;
 
@@ -345,51 +344,50 @@
 
     // We need to split, so don't try these modes.
     TComYuv* tempYuv = NULL;
-#if TOPSKIP
-    TComDataCU* colocated0 = outTempCU->getCUColocated(REF_PIC_LIST_0);
-    TComDataCU* colocated1 = outTempCU->getCUColocated(REF_PIC_LIST_1);
-    char currentQP = outTempCU->getQP(0);
-    char previousQP = colocated0->getQP(0);
-    UChar delta = 0, minDepth0 = 4, minDepth1 = 4;
-    if (depth == 0)
+    if (m_cfg->param.bEnableTopSkip)
     {
-        double sum0 = 0;
-        double sum1 = 0;
-        double avgDepth0 = 0;
-        double avgDepth1 = 0;
-        double avgDepth = 0;
-        for (uint32_t i = 0; i < outTempCU->getTotalNumPart(); i = i + 4)
+        TComDataCU* colocated0 = outTempCU->getCUColocated(REF_PIC_LIST_0);
+        TComDataCU* colocated1 = outTempCU->getCUColocated(REF_PIC_LIST_1);
+        char currentQP = outTempCU->getQP(0);
+        char previousQP = colocated0->getQP(0);
+        UChar delta = 0, minDepth0 = 4, minDepth1 = 4;
+        if (depth == 0)
         {
-            if (colocated0 && colocated0->getDepth(i) < minDepth0)
-                minDepth0 = colocated0->getDepth(i);
-            if (colocated1 && colocated1->getDepth(i) < minDepth1)
-                minDepth1 = colocated1->getDepth(i);
-            if (colocated0)
-                sum0 += (colocated0->getDepth(i) * 4);
-            if (colocated1)
-                sum1 += (colocated1->getDepth(i) * 4);
+            double sum0 = 0;
+            double sum1 = 0;
+            double avgDepth0 = 0;
+            double avgDepth1 = 0;
+            double avgDepth = 0;
+            for (uint32_t i = 0; i < outTempCU->getTotalNumPart(); i = i + 4)
+            {
+                if (colocated0 && colocated0->getDepth(i) < minDepth0)
+                    minDepth0 = colocated0->getDepth(i);
+                if (colocated1 && colocated1->getDepth(i) < minDepth1)
+                    minDepth1 = colocated1->getDepth(i);
+                if (colocated0)
+                    sum0 += (colocated0->getDepth(i) * 4);
+                if (colocated1)
+                    sum1 += (colocated1->getDepth(i) * 4);
+            }
+
+            avgDepth0 = sum0 / outTempCU->getTotalNumPart();
+            avgDepth1 = sum1 / outTempCU->getTotalNumPart();
+            avgDepth = (avgDepth0 + avgDepth1) / 2;
+
+            if (minDepth1 < minDepth0)
+                minDepth = minDepth1;
+            else
+                minDepth = minDepth0;
+
+            if (((currentQP - previousQP) < 0) || (((currentQP - previousQP) >= 0) && ((avgDepth - minDepth) > 0.5)))
+                delta = 0;
+            else
+                delta = 1;
+            if (minDepth > 0)
+                minDepth = minDepth - delta;
         }
-
-        avgDepth0 = sum0 / outTempCU->getTotalNumPart();
-        avgDepth1 = sum1 / outTempCU->getTotalNumPart();
-        avgDepth = (avgDepth0 + avgDepth1) / 2;
-
-        if (minDepth1 < minDepth0)
-            minDepth = minDepth1;
-        else
-            minDepth = minDepth0;
-
-        if (((currentQP - previousQP) < 0) || (((currentQP - previousQP) >= 0) && ((avgDepth - minDepth) > 0.5)))
-            delta = 0;
-        else
-            delta = 1;
-        if (minDepth > 0)
-            minDepth = minDepth - delta;
-    }
-#endif // if TOPSKIP
-#if TOPSKIP
-    if (!(depth < minDepth)) //topskip
-#endif
+    } // if TOPSKIP
+    if (!m_cfg->param.bEnableTopSkip || (m_cfg->param.bEnableTopSkip && (!(depth < minDepth))))
     {
         m_log->cntTotalCu[depth]++;
         if (!bSliceEnd && bInsidePicture)
@@ -544,6 +542,7 @@
             m_addSADDepth++;
         }
     }
+
 #if CU_STAT_LOGFILE
     if (outBestCU)
     {
@@ -559,63 +558,62 @@
 #if EARLY_EXIT // turn ON this to enable early exit
         // early exit when the RD cost of best mode at depth n is less than the sum of avgerage of RD cost of the neighbour
         // CU's(above, aboveleft, aboveright, left, colocated) and avg cost of that CU at depth "n"  with weightage for each quantity
-#if TOPSKIP
-        if (outBestCU != 0 && !(depth < minDepth)) //topskip
-#else
-        if (outBestCU != 0)
-#endif
+        if (!m_cfg->param.bEnableTopSkip || (m_cfg->param.bEnableTopSkip &&(!(depth < minDepth)) ))
         {
-            uint64_t totalCostNeigh = 0, totalCostCU = 0, totalCountCU = 0;
-            double avgCost = 0;
-            uint64_t totalCountNeigh = 0;
-            TComDataCU* above = outTempCU->getCUAbove();
-            TComDataCU* aboveLeft = outTempCU->getCUAboveLeft();
-            TComDataCU* aboveRight = outTempCU->getCUAboveRight();
-            TComDataCU* left = outTempCU->getCULeft();
-            TComDataCU* rootCU = outTempCU->getPic()->getPicSym()->getCU(outTempCU->getAddr());
+            if (outBestCU != 0)
+            {
+                uint64_t totalCostNeigh = 0, totalCostCU = 0, totalCountCU = 0;
+                double avgCost = 0;
+                uint64_t totalCountNeigh = 0;
+                TComDataCU* above = outTempCU->getCUAbove();
+                TComDataCU* aboveLeft = outTempCU->getCUAboveLeft();
+                TComDataCU* aboveRight = outTempCU->getCUAboveRight();
+                TComDataCU* left = outTempCU->getCULeft();
+                TComDataCU* rootCU = outTempCU->getPic()->getPicSym()->getCU(outTempCU->getAddr());
 
-            totalCostCU += rootCU->m_avgCost[depth] * rootCU->m_count[depth];
-            totalCountCU += rootCU->m_count[depth];
-            if (above)
-            {
-                totalCostNeigh += above->m_avgCost[depth] * above->m_count[depth];
-                totalCountNeigh += above->m_count[depth];
-            }
-            if (aboveLeft)
-            {
-                totalCostNeigh += aboveLeft->m_avgCost[depth] * aboveLeft->m_count[depth];
-                totalCountNeigh += aboveLeft->m_count[depth];
-            }
-            if (aboveRight)
-            {
-                totalCostNeigh += aboveRight->m_avgCost[depth] * aboveRight->m_count[depth];
-                totalCountNeigh += aboveRight->m_count[depth];
-            }
-            if (left)
-            {
-                totalCostNeigh += left->m_avgCost[depth] * left->m_count[depth];
-                totalCountNeigh += left->m_count[depth];
-            }
+                totalCostCU += rootCU->m_avgCost[depth] * rootCU->m_count[depth];
+                totalCountCU += rootCU->m_count[depth];
+                if (above)
+                {
+                    totalCostNeigh += above->m_avgCost[depth] * above->m_count[depth];
+                    totalCountNeigh += above->m_count[depth];
+                }
+                if (aboveLeft)
+                {
+                    totalCostNeigh += aboveLeft->m_avgCost[depth] * aboveLeft->m_count[depth];
+                    totalCountNeigh += aboveLeft->m_count[depth];
+                }
+                if (aboveRight)
+                {
+                    totalCostNeigh += aboveRight->m_avgCost[depth] * aboveRight->m_count[depth];
+                    totalCountNeigh += aboveRight->m_count[depth];
+                }
+                if (left)
+                {
+                    totalCostNeigh += left->m_avgCost[depth] * left->m_count[depth];
+                    totalCountNeigh += left->m_count[depth];
+                }
 
-            //giving 60% weight to all CU's and 40% weight to neighbour CU's
-            if (totalCountNeigh + totalCountCU)
-                avgCost = ((0.6 * totalCostCU) + (0.4 * totalCostNeigh)) / ((0.6 * totalCountCU) + (0.4 * totalCountNeigh));
+                //giving 60% weight to all CU's and 40% weight to neighbour CU's
+                if (totalCountNeigh + totalCountCU)
+                    avgCost = ((0.6 * totalCostCU) + (0.4 * totalCostNeigh)) / ((0.6 * totalCountCU) + (0.4 * totalCountNeigh));
 
-            float lambda = 1.0f;
+                float lambda = 1.0f;
 
-            if (outBestCU->m_totalCost < lambda * avgCost && avgCost != 0 && depth != 0)
-            {
-                m_entropyCoder->resetBits();
-                m_entropyCoder->encodeSplitFlag(outBestCU, 0, depth, true);
-                outBestCU->m_totalBits += m_entropyCoder->getNumberOfWrittenBits();        // split bits
-                outBestCU->m_totalCost  = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
-                /* Copy Best data to Picture for next partition prediction. */
-                outBestCU->copyToPic((UChar)depth);
+                if (outBestCU->m_totalCost < lambda * avgCost && avgCost != 0 && depth != 0)
+                {
+                    m_entropyCoder->resetBits();
+                    m_entropyCoder->encodeSplitFlag(outBestCU, 0, depth, true);
+                    outBestCU->m_totalBits += m_entropyCoder->getNumberOfWrittenBits();        // split bits
+                    outBestCU->m_totalCost  = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
+                    /* Copy Best data to Picture for next partition prediction. */
+                    outBestCU->copyToPic((UChar)depth);
 
-                /* Copy Yuv data to picture Yuv */
-                xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
-                m_log->cntTotalCu[depth]--;
-                return;
+                    /* Copy Yuv data to picture Yuv */
+                    xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
+                    m_log->cntTotalCu[depth]--;
+                    return;
+                }
             }
         }
 #endif // if EARLY_EXIT
diff -r 2ba6c26c9feb -r bebef81f1056 source/x265.cpp
--- a/source/x265.cpp	Thu Nov 28 15:04:04 2013 +0530
+++ b/source/x265.cpp	Thu Nov 28 17:27:37 2013 +0530
@@ -102,6 +102,8 @@
     { "amp",                  no_argument, NULL, 0 },
     { "no-early-skip",        no_argument, NULL, 0 },
     { "early-skip",           no_argument, NULL, 0 },
+    { "no-topskip",           no_argument, NULL, 0 },
+    { "topskip",              no_argument, NULL, 0 },
     { "no-fast-cbf",          no_argument, NULL, 0 },
     { "fast-cbf",             no_argument, NULL, 0 },
     { "no-tskip",             no_argument, NULL, 0 },
@@ -291,6 +293,7 @@
     H0("   --[no-]amp                    Enable asymmetric motion partitions, requires --rect. Default %s\n", OPT(param->bEnableAMP));
     H0("   --max-merge                   Maximum number of merge candidates. Default %d\n", param->maxNumMergeCand);
     H0("   --[no-]early-skip             Enable early SKIP detection. Default %s\n", OPT(param->bEnableEarlySkip));
+    H0("   --[no-]topskip                Enable TOP SKIP detection. Default %s\n", OPT(param->bEnableTopSkip));
     H0("   --[no-]fast-cbf               Enable Cbf fast mode. Default %s\n", OPT(param->bEnableCbfFastMode));
     H0("\nSpatial / intra options:\n");
     H0("   --rdpenalty                   penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum. Default %d\n", param->rdPenalty);
diff -r 2ba6c26c9feb -r bebef81f1056 source/x265.h
--- a/source/x265.h	Thu Nov 28 15:04:04 2013 +0530
+++ b/source/x265.h	Thu Nov 28 17:27:37 2013 +0530
@@ -496,6 +496,12 @@
      * skip blocks. Default is disabled */
     int       bEnableEarlySkip;
 
+    /* Enable top skip decisions (set the starting depth from which the 
+     * partitioning should happen for particular CU. The starting depth for 
+     * particular CU in present frame is selected form the previous frame's 
+     * colocated CU minimum depth*/
+    int       bEnableTopSkip;
+
     /* Apply an optional penalty to the estimated cost of 32x32 intra blocks in
      * non-intra slices. 0 is disabled, 1 enables a small penalty, and 2 enables
      * a full penalty. This favors inter-coding and its low bitrate over


More information about the x265-devel mailing list