changeset 4047:e51ecfcabcaa

lookahead: fix crash for I frame cost estimation
author Deepthi Devaki <deepthidevaki@multicorewareinc.com>
date Thu, 19 Sep 2013 14:44:28 +0530
parents eea9154229a0
children 12db8e96402b
files source/encoder/slicetype.cpp
diffstat 1 files changed, 32 insertions(+-), 30 deletions(-) [+]
line wrap: on
line diff
--- a/source/encoder/slicetype.cpp	Thu Sep 19 09:17:03 2013 +0530
+++ b/source/encoder/slicetype.cpp	Thu Sep 19 14:44:28 2013 +0530
@@ -360,44 +360,46 @@ void Lookahead::estimateCUCost(int cux, 
     mvmax.x = (uint16_t)((widthInCU - cux - 1) * cuSize + 8);
     mvmax.y = (uint16_t)((heightInCU - cuy - 1) * cuSize + 8);
 
-    for (int i = 0; i < 1 + bBidir; i++)
+    if (p0 != p1)
     {
-        if (!bDoSearch[i])
+        for (int i = 0; i < 1 + bBidir; i++)
         {
-            /* Use previously calculated cost */
-            COPY2_IF_LT(bcost, *fenc_costs[i], listused, i + 1);
-            continue;
-        }
-        int numc = 0;
-        MV mvc[4], mvp;
-        MV *fenc_mv = fenc_mvs[i];
+            if (!bDoSearch[i])
+            {
+                /* Use previously calculated cost */
+                COPY2_IF_LT(bcost, *fenc_costs[i], listused, i + 1);
+                continue;
+            }
+            int numc = 0;
+            MV mvc[4], mvp;
+            MV *fenc_mv = fenc_mvs[i];
 
-        /* Reverse-order MV prediction. */
-        mvc[0] = 0;
-        mvc[2] = 0;
+            /* Reverse-order MV prediction. */
+            mvc[0] = 0;
+            mvc[2] = 0;
 #define MVC(mv) mvc[numc++] = mv;
-        if (cux < widthInCU - 1)
-            MVC(fenc_mv[1]);
-        if (cuy < heightInCU - 1)
-        {
-            MVC(fenc_mv[widthInCU]);
-            if (cux > 0)
-                MVC(fenc_mv[widthInCU - 1]);
             if (cux < widthInCU - 1)
-                MVC(fenc_mv[widthInCU + 1]);
-        }
+                MVC(fenc_mv[1]);
+            if (cuy < heightInCU - 1)
+            {
+                MVC(fenc_mv[widthInCU]);
+                if (cux > 0)
+                    MVC(fenc_mv[widthInCU - 1]);
+                if (cux < widthInCU - 1)
+                    MVC(fenc_mv[widthInCU + 1]);
+            }
 #undef MVC
-        if (numc <= 1)
-            mvp = mvc[0];
-        else
-        {
-            x265_median_mv(mvp, mvc[0], mvc[1], mvc[2]);
+            if (numc <= 1)
+                mvp = mvc[0];
+            else
+            {
+                x265_median_mv(mvp, mvc[0], mvc[1], mvc[2]);
+            }
+
+            *fenc_costs[i] = me.motionEstimate(i ? fref1 : fref0, mvmin, mvmax, mvp, numc, mvc, merange, *fenc_mvs[i]);
+            COPY2_IF_LT(bcost, *fenc_costs[i], listused, i + 1);
         }
-
-        *fenc_costs[i] = me.motionEstimate(i ? fref1 : fref0, mvmin, mvmax, mvp, numc, mvc, merange, *fenc_mvs[i]);
-        COPY2_IF_LT(bcost, *fenc_costs[i], listused, i + 1);
     }
-
     if (!fenc->bIntraCalculated)
     {
         int nLog2SizeMinus2 = g_convertToBit[cuSize]; // partition size