[x265] [PATCH] weightp: fix output inconsistency due to threading in lookahead (fixes #220)

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Mon Jan 4 12:29:18 CET 2016


# HG changeset patch
# User Kavitha Sampath<kavitha at multicorewareinc.com>
# Date 1451581754 -19800
#      Thu Dec 31 22:39:14 2015 +0530
# Node ID d5bb166f383ccfdaa7d7569c9959cb5118eda4bc
# Parent  375ce77b8c35ae332bf51085f6d26044d55ae264
weightp: fix output inconsistency due to threading in lookahead (fixes #220)

diff -r 375ce77b8c35 -r d5bb166f383c source/common/lowres.h
--- a/source/common/lowres.h	Mon Dec 28 16:06:55 2015 -0600
+++ b/source/common/lowres.h	Thu Dec 31 22:39:14 2015 +0530
@@ -151,6 +151,7 @@
     /* cutree intermediate data */
     uint16_t* propagateCost;
     double    weightedCostDelta[X265_BFRAME_MAX + 2];
+    ReferencePlanes weightedRef[X265_BFRAME_MAX + 2];
 
     bool create(PicYuv *origPic, int _bframes, bool bAqEnabled);
     void destroy();
diff -r 375ce77b8c35 -r d5bb166f383c source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Mon Dec 28 16:06:55 2015 -0600
+++ b/source/encoder/slicetype.cpp	Thu Dec 31 22:39:14 2015 +0530
@@ -351,7 +351,7 @@
 
         primitives.weight_pp(ref.buffer[0], wbuffer[0], stride, widthHeight, paddedLines,
             scale, round << correction, denom + correction, offset);
-        src = weightedRef.fpelPlane[0];
+        src = fenc.weightedRef[fenc.frameNum - ref.frameNum].fpelPlane[0];
     }
 
     uint32_t cost = 0;
@@ -373,7 +373,6 @@
 bool LookaheadTLD::allocWeightedRef(Lowres& fenc)
 {
     intptr_t planesize = fenc.buffer[1] - fenc.buffer[0];
-    intptr_t padoffset = fenc.lowresPlane[0] - fenc.buffer[0];
     paddedLines = (int)(planesize / fenc.lumaStride);
 
     wbuffer[0] = X265_MALLOC(pixel, 4 * planesize);
@@ -386,14 +385,6 @@
     else
         return false;
 
-    for (int i = 0; i < 4; i++)
-        weightedRef.lowresPlane[i] = wbuffer[i] + padoffset;
-
-    weightedRef.fpelPlane[0] = weightedRef.lowresPlane[0];
-    weightedRef.lumaStride = fenc.lumaStride;
-    weightedRef.isLowres = true;
-    weightedRef.isWeighted = false;
-
     return true;
 }
 
@@ -411,6 +402,16 @@
             return;
     }
 
+    ReferencePlanes& weightedRef = fenc.weightedRef[deltaIndex];
+    intptr_t padoffset = fenc.lowresPlane[0] - fenc.buffer[0];
+    for (int i = 0; i < 4; i++)
+        weightedRef.lowresPlane[i] = wbuffer[i] + padoffset;
+
+    weightedRef.fpelPlane[0] = weightedRef.lowresPlane[0];
+    weightedRef.lumaStride = fenc.lumaStride;
+    weightedRef.isLowres = true;
+    weightedRef.isWeighted = false;
+
     /* epsilon is chosen to require at least a numerator of 127 (with denominator = 128) */
     float guessScale, fencMean, refMean;
     x265_emms();
@@ -1996,7 +1997,7 @@
         if (bDoSearch[1]) fenc->lowresMvs[1][p1 - b - 1][0].x = 0x7FFE;
 #endif
 
-        tld.weightedRef.isWeighted = false;
+        fenc->weightedRef[b - p0].isWeighted = false;
         if (param->bEnableWeightedPred && bDoSearch[0])
             tld.weightsAnalyse(*m_frames[b], *m_frames[p0]);
 
@@ -2070,7 +2071,7 @@
     Lowres *fref1 = m_frames[p1];
     Lowres *fenc  = m_frames[b];
 
-    ReferencePlanes *wfref0 = tld.weightedRef.isWeighted ? &tld.weightedRef : fref0;
+    ReferencePlanes *wfref0 = fenc->weightedRef[b - p0].isWeighted ? &fenc->weightedRef[b - p0] : fref0;
 
     const int widthInCU = m_lookahead.m_8x8Width;
     const int heightInCU = m_lookahead.m_8x8Height;
diff -r 375ce77b8c35 -r d5bb166f383c source/encoder/slicetype.h
--- a/source/encoder/slicetype.h	Mon Dec 28 16:06:55 2015 -0600
+++ b/source/encoder/slicetype.h	Thu Dec 31 22:39:14 2015 +0530
@@ -45,7 +45,6 @@
 struct LookaheadTLD
 {
     MotionEstimate  me;
-    ReferencePlanes weightedRef;
     pixel*          wbuffer[4];
     int             widthInCU;
     int             heightInCU;


More information about the x265-devel mailing list