[x265] [PATCH] slicetype: added slicetype_frame_cost

gopu at multicorewareinc.com gopu at multicorewareinc.com
Thu Aug 8 09:11:05 CEST 2013


# HG changeset patch
# User ggopu
# Date 1375945854 -19800
# Node ID b1ea06d6fa0546bf0821074346b38d2d7c8ef652
# Parent  490eaf380f1bdb7da6574543e539101432264a5a
slicetype: added slicetype_frame_cost

diff -r 490eaf380f1b -r b1ea06d6fa05 source/common/lookahead.h
--- a/source/common/lookahead.h	Thu Aug 08 12:32:01 2013 +0530
+++ b/source/common/lookahead.h	Thu Aug 08 12:40:54 2013 +0530
@@ -20,10 +20,13 @@
  * This program is also available under a commercial proprietary license.
  * For more information, contact us at licensing at multicorewareinc.com.
  *****************************************************************************/
+#ifndef _LOOKAHEAD_
+#define _LOOKAHEAD_
 
 #include "x265.h"
 #include "common.h"
 #include "mv.h"
+#include "reference.h"
 
 namespace x265 {
 class ReferencePlanes;
@@ -45,6 +48,8 @@
     uint16_t(*lowresCosts[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]);
     int      *lowresMvCosts[2][X265_BFRAME_MAX + 1];
     MV       *lowresMvs[2][X265_BFRAME_MAX + 1];
+    int      cuWidth;
+    int      cuHeight;
 };
 
 struct Lookahead
@@ -59,3 +64,4 @@
 };
 
 }
+#endif // ifndef _LOOKAHEAD_
diff -r 490eaf380f1b -r b1ea06d6fa05 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Aug 08 12:32:01 2013 +0530
+++ b/source/encoder/slicetype.cpp	Thu Aug 08 12:40:54 2013 +0530
@@ -32,17 +32,102 @@
 // taking any of the threading changes because we will eventually use the x265
 // thread pool and wavefront processing.
 
-#include "common/common.h"
-#include "macroblock.h"
-#include "me.h"
+#include "x265.h"
+#include "lookahead.h"
+#include "primitives.h"
 
+#define NUM_MBS \
+    (fenc->cuWidth > 2 && fenc->cuHeight > 2 ? \
+     (fenc->cuWidth - 2) * (fenc->cuHeight - 2) : \
+     fenc->cuWidth * fenc->cuHeight)
+
+int slicetype_frame_cost(x265::LookaheadFrame **frames, int p0, int p1, int b, int bIntraPenalty);
+
+int slicetype_frame_cost(x265::LookaheadFrame **frames, int p0, int p1, int b, int bIntraPenalty)
+{
+    int score = 0;
+    int do_search[2];
+
+    x265::LookaheadFrame *fenc;
+
+    fenc = frames[b];
+
+    if (fenc->costEst[b - p0][p1 - b] >= 0 && fenc->rowSatds[b - p0][p1 - b][0] != -1)
+        score = fenc->costEst[b - p0][p1 - b];
+    else
+    {
+        int dist_scale_factor = 128;
+        x265::MV *we = fenc->lowresMvs[0][b - p0 - 1];
+        int *row_satd = fenc->rowSatds[b - p0][p1 - b];
+
+        /* For each list, check to see whether we have lowres motion-searched this reference frame before. */
+        do_search[0] = b != p0 && fenc->lowresMvs[0][b - p0 - 1][0].x == 0x7FFF;
+        do_search[1] = b != p1 && fenc->lowresMvs[1][p1 - b - 1][0].x == 0x7FFF;
+
+        if (do_search[0])
+        {
+            fenc->lowresMvs[0][b - p0 - 1][0] = 0;
+        }
+
+        if (do_search[1]) fenc->lowresMvs[1][p1 - b - 1][0] = 0;
+
+        if (p1 != p0)
+            dist_scale_factor = (((b - p0) << 8) + ((p1 - p0) >> 1)) / (p1 - p0);
+
+        fenc->costEst[b - p0][p1 - b] = 0;
+        fenc->costEst[b - p0][p1 - b] = 0;
+
+        /* Lowres lookahead goes backwards because the MVs are used as predictors in the main encode.
+        * This considerably improves MV prediction overall. */
+
+        /* The edge mbs seem to reduce the predictive quality of the
+        * whole frame's score, but are needed for a spatial distribution. */
+
+        if (fenc->cuWidth <= 2 || fenc->cuHeight <= 2)
+        {
+            for (int i = fenc->cuWidth - 1; i >= 0; i--)
+            {
+                row_satd[i] = 0;
+            }
+
+            for (int j = fenc->cuHeight - 1; j >= 0; j--)
+            {
+                //slicetype_cu_cost(frames, p0, p1, b, dist_scale_factor, do_search);
+            }
+        }
+        else
+        {
+            for (int i = fenc->cuWidth - 1; i >= 0; i--)
+            {
+                for (int j = fenc->cuHeight - 1; j >= 0; j--)
+                {
+                    //slicetype_cu_cost(frames, p0, p1, b, dist_scale_factor, do_search);
+                }
+            }
+        }
+
+        score = fenc->costEst[b - p0][p1 - b];
+
+        if (b != p1)
+            score = (uint64_t)score * 100 / (120) + 0;
+
+        fenc->costEst[b - p0][p1 - b] = score;
+        x265_emms();
+    }
+
+    if (bIntraPenalty)
+    {
+        // arbitrary penalty for I-blocks after B-frames
+        int nmb = NUM_MBS;
+        score += (uint64_t)score * fenc->intraMbs[b - p0] / (nmb * 8);
+    }
+    return score;
+}
+
+#if 0
 // Indexed by pic_struct values
 static const uint8_t delta_tfi_divisor[10] = { 0, 2, 1, 1, 2, 2, 3, 3, 4, 6 };
 
-static int x264_slicetype_frame_cost(x264_t *h, x264_mb_analysis_t *a,
-                                     x264_frame_t **frames, int p0, int p1, int b,
-                                     int b_intra_penalty);
-
 static void x264_lowres_context_init(x264_t *h, x264_mb_analysis_t *a)
 {
     a->i_qp = X264_LOOKAHEAD_QP;
@@ -1624,3 +1709,5 @@
             h->sps->vui.i_num_units_in_tick / h->sps->vui.i_time_scale;
     }
 }
+
+#endif // if 0


More information about the x265-devel mailing list