[x265] [PATCH] Slicetype: recalculate the frame cost without re-running lookahead for cutree

Gopu Govindaswamy gopu at multicorewareinc.com
Fri Dec 13 10:47:16 CET 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1386928026 -19800
# Node ID 3247897e88112137f95d73afabba7c03298f198d
# Parent  033a65692b6aa5270736b8efb4a3e6af3afe95da
Slicetype: recalculate the frame cost without re-running lookahead for cutree

diff -r 033a65692b6a -r 3247897e8811 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Dec 12 13:53:33 2013 -0600
+++ b/source/encoder/slicetype.cpp	Fri Dec 13 15:17:06 2013 +0530
@@ -218,7 +218,14 @@
         return -1;
     }
 
+    if (cfg->param.rc.cuTree)
+    {
+        pic->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);
+        return pic->m_lowres.satdCost;
+    }
+
     estimateFrameCost(p0, p1, b, false);
+
     if (cfg->param.rc.aqMode)
         pic->m_lowres.satdCost = pic->m_lowres.costEstAq[b - p0][p1 - b];
     else
@@ -919,7 +926,7 @@
 
     if (!framecnt)
     {
-        if (cfg->param.rc.cuTree && cfg->param.rc.aqMode)
+        if (cfg->param.rc.cuTree)
             cuTree(frames, 0, bKeyframe);
         return;
     }
@@ -1053,7 +1060,7 @@
         num_bframes = 0;
     }
 
-    if (cfg->param.rc.cuTree && cfg->param.rc.aqMode)
+    if (cfg->param.rc.cuTree)
         cuTree(frames, X265_MIN(num_frames, cfg->param.keyframeMax), bKeyframe);
 
     // if (!cfg->param.bIntraRefresh)
@@ -1509,3 +1516,32 @@
         dst[i] = (int)(propagateAmount * propagateNum / propagateDenom + 0.5);
     }
 }
+
+/* If MB-tree changes the quantizers, we need to recalculate the frame cost without
+ * re-running lookahead. */
+int Lookahead::frameCostRecalculate(Lowres** Frames, int p0, int p1, int b)
+{
+    int score = 0;
+    int *row_satd = Frames[b]->rowSatds[b-p0][p1-b]; 
+    double *qp_offset = (Frames[0]->sliceType == X265_TYPE_B) ? Frames[b]->qpAqOffset : Frames[b]->qpOffset;
+    x265_emms();
+    for (int cuy = heightInCU - 1; cuy >= 0; cuy--)
+    {
+        row_satd[cuy] = 0;
+        for (int cux = widthInCU - 1; cux >= 0; cux-- )
+        {
+            int cuxy = cux + cuy * widthInCU;
+            int cuCost = Frames[b]->lowresCosts[b-p0][p1-b][cuxy] & LOWRES_COST_MASK;
+            double qp_adj = qp_offset[cuxy];
+            cuCost = (cuCost * x265_exp2fix8(qp_adj) + 128) >> 8;
+            row_satd[cuy ] += cuCost;
+            if( (cuy > 0 && cuy < heightInCU - 1 &&
+                 cux > 0 && cux < widthInCU - 1) ||
+                 widthInCU <= 2 || heightInCU <= 2 )
+            {
+                score += cuCost;
+            }
+        }
+    }
+    return score;
+}
diff -r 033a65692b6a -r 3247897e8811 source/encoder/slicetype.h
--- a/source/encoder/slicetype.h	Thu Dec 12 13:53:33 2013 -0600
+++ b/source/encoder/slicetype.h	Fri Dec 13 15:17:06 2013 +0530
@@ -123,6 +123,7 @@
     void estimateCUPropagate(Lowres **Frames, double average_duration, int p0, int p1, int b, int referenced);
     void estimateCUPropagateCost(int *dst, uint16_t *propagateIn, int32_t *intraCosts, uint16_t *interCosts, int32_t *invQscales, double *fpsFactor, int len);
     void cuTreeFinish(Lowres *Frame, double averageDuration, int ref0Distance);
+    int frameCostRecalculate(Lowres **Frames, int p0, int p1, int b);
 };
 }
 


More information about the x265-devel mailing list