<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 30, 2013 at 6:01 AM, <span dir="ltr"><<a href="mailto:shazeb@multicorewareinc.com" target="_blank">shazeb@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"># HG changeset patch<br>
# User Shazeb Nawaz Khan <<a href="mailto:shazeb@multicorewareinc.com">shazeb@multicorewareinc.com</a>><br>
# Date 1380285873 -19800<br>
# Fri Sep 27 18:14:33 2013 +0530<br>
</div># Node ID cc94f1a5c6ab1975502f6a0edfc4aa4233733597<br>
# Parent 55edc34e253c14d3eccb83a7d1db43774349ff9a<br>
<div class="im">Generating weighted full-pels in compressCTURows<br>
<br>
We are re-enabling weightP after introduction of frame parallelism. Not yet using the weighted pixels.<br>
<br>
</div>diff -r 55edc34e253c -r cc94f1a5c6ab source/Lib/TLibCommon/TComPicYuv.cpp<br>
--- a/source/Lib/TLibCommon/TComPicYuv.cpp Sat Sep 28 22:54:44 2013 -0500<br>
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp Fri Sep 27 18:14:33 2013 +0530<br>
@@ -250,7 +250,8 @@<br>
else if (mref->isWeighted == false)<br>
return mref;<br>
}<br>
- mref = new MotionReference(this, w);<br>
+ mref = new MotionReference();<br>
+ mref->init(this, w);<br>
mref->m_next = m_refList;<br>
m_refList = mref;<br>
return mref;<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/Lib/TLibCommon/TComWeightPrediction.cpp<br>
--- a/source/Lib/TLibCommon/TComWeightPrediction.cpp Sat Sep 28 22:54:44 2013 -0500<br>
+++ b/source/Lib/TLibCommon/TComWeightPrediction.cpp Fri Sep 27 18:14:33 2013 +0530<br>
@@ -431,7 +431,7 @@<br>
srcStride = srcYuv0->m_width;<br>
dstStride = outDstYuv->getStride();<br>
<br>
- primitives.weightpUni(srcY0, dstY, srcStride, dstStride, width, height, w0, round, shift, offset);<br>
+ primitives.weightpUniShort(srcY0, dstY, srcStride, dstStride, width, height, w0, round, shift, offset, 0);<br>
}<br>
<br>
// Chroma U : --------------------------------------------<br>
@@ -447,7 +447,7 @@<br>
width >>= 1;<br>
height >>= 1;<br>
<br>
- primitives.weightpUni(srcU0, dstU, srcStride, dstStride, width, height, w0, round, shift, offset);<br>
+ primitives.weightpUniShort(srcU0, dstU, srcStride, dstStride, width, height, w0, round, shift, offset, 0);<br>
<br>
// Chroma V : --------------------------------------------<br>
w0 = wp0[2].w;<br>
@@ -455,7 +455,7 @@<br>
shift = wp0[2].shift + shiftNum;<br>
<div class="im"> round = shift ? (1 << (shift - 1)) : 0;<br>
<br>
</div>- primitives.weightpUni(srcV0, dstV, srcStride, dstStride, width, height, w0, round, shift, offset);<br>
+ primitives.weightpUniShort(srcV0, dstV, srcStride, dstStride, width, height, w0, round, shift, offset, 0);<br>
}<br>
<br>
//=======================================================<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/pixel.cpp<br>
--- a/source/common/pixel.cpp Sat Sep 28 22:54:44 2013 -0500<br>
+++ b/source/common/pixel.cpp Fri Sep 27 18:14:33 2013 +0530<br>
@@ -514,17 +514,19 @@<br>
}<br>
}<br>
<br>
-void weightUnidir(short *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset)<br>
+template <typename T><br>
+void weightUnidir(void *srcAbstract, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset, int startHeight)<br>
{<br>
+ T *src = static_cast<T *>(srcAbstract);<br>
int x, y;<br>
- for (y = height - 1; y >= 0; y--)<br>
+ for (y = height - 1; y >= startHeight; y--)<br>
{<br>
<div class="im"> for (x = width - 1; x >= 0; )<br>
</div> {<br>
<div class="im"> // note: luma min width is 4<br>
</div>- dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);<br>
+ dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (uint16_t) (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);<br>
x--;<br>
- dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);<br>
+ dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (uint16_t) (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);<br>
x--;<br>
}<br>
<br>
@@ -842,7 +844,8 @@<br>
p.transpose[3] = transpose<32>;<br>
p.transpose[4] = transpose<64>;<br>
<br>
- p.weightpUni = weightUnidir;<br>
+ p.weightpUniPixel = weightUnidir<pixel>;<br>
+ p.weightpUniShort = weightUnidir<short>;<br>
<br>
p.pixelsub_sp = pixelsub_sp_c;<br>
p.pixeladd_pp = pixeladd_pp_c;<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/primitives.h<br>
--- a/source/common/primitives.h Sat Sep 28 22:54:44 2013 -0500<br>
+++ b/source/common/primitives.h Fri Sep 27 18:14:33 2013 +0530<br>
@@ -228,8 +228,7 @@<br>
typedef void (*filterRowV_N_t)(short *midA, intptr_t midStride, pixel *dstA, pixel *dstB, pixel *dstC, intptr_t dstStride, int width, int height, int marginX, int marginY, int row, int isLastRow);<br>
typedef void (*extendCURowBorder_t)(pixel* txt, intptr_t stride, int width, int height, int marginX);<br>
<br>
-<br>
-typedef void (*weightpUni_t)(short *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset);<br>
+typedef void (*weightpUni_t)(void *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset, int startHeight);<br>
typedef void (*scale_t)(pixel *dst, pixel *src, intptr_t stride);<br>
typedef void (*downscale_t)(pixel *src0, pixel *dstf, pixel *dsth, pixel *dstv, pixel *dstc,<br>
intptr_t src_stride, intptr_t dst_stride, int width, int height);<br>
@@ -286,7 +285,8 @@<br>
calcrecon_t calcrecon[NUM_SQUARE_BLOCKS];<br>
transpose_t transpose[NUM_SQUARE_BLOCKS];<br>
<br>
- weightpUni_t weightpUni;<br>
+ weightpUni_t weightpUniPixel;<br>
+ weightpUni_t weightpUniShort;<br>
pixelsub_sp_t pixelsub_sp;<br>
pixeladd_ss_t pixeladd_ss;<br>
pixeladd_pp_t pixeladd_pp;<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/reference.cpp<br>
--- a/source/common/reference.cpp Sat Sep 28 22:54:44 2013 -0500<br>
<div class="im">+++ b/source/common/reference.cpp Fri Sep 27 18:14:33 2013 +0530<br>
@@ -24,6 +24,7 @@<br>
<br>
#include "TLibCommon/TypeDef.h"<br>
#include "TLibCommon/TComPicYuv.h"<br>
+#include "TLibCommon/TComPic.h"<br>
#include "TLibCommon/TComSlice.h"<br>
#include "primitives.h"<br>
#include "reference.h"<br>
</div>@@ -51,12 +52,17 @@<br>
return false;<br>
}<br>
<br>
-MotionReference::MotionReference(TComPicYuv* pic, wpScalingParam *w)<br>
+MotionReference::MotionReference()<br>
+{}<br>
+<br>
+int MotionReference::init(TComPicYuv* pic, wpScalingParam *w)<br>
{<br>
m_reconPic = pic;<br>
<div class="im"> lumaStride = pic->getStride();<br>
m_startPad = pic->m_lumaMarginY * lumaStride + pic->m_lumaMarginX;<br>
m_next = NULL;<br>
+ isWeighted = false;<br>
</div>+ m_numWeightedRows = 0;<br>
<br>
if (w)<br>
{<br>
@@ -66,17 +72,66 @@<br>
size_t padheight = height + pic->m_lumaMarginY * 2;<br>
<br>
setWeight(*w);<br>
- fpelPlane = (pixel*)X265_MALLOC(pixel, padwidth * padheight) + m_startPad;<br>
+ fpelPlane = (pixel*)X265_MALLOC(pixel, padwidth * padheight);<br>
+ if (fpelPlane) fpelPlane += m_startPad;<br>
+ else return -1;<br></blockquote><div><br></div><div>In this particular situation, the caller could decide to disable WeightP for this frame if the malloc failed, but that would be adding a lot of complication for what is likely a fatal condition. Once one malloc fails there is a high probability the rest will fail so most likely the encode must be stopped.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
}<br>
else<br>
{<br>
/* directly reference the pre-extended integer pel plane */<br>
fpelPlane = pic->m_picBufY + m_startPad;<br>
}<br>
+ return 0;<br>
}<br>
<br>
MotionReference::~MotionReference()<br>
{<br>
if (isWeighted)<br>
<div class="im">- X265_FREE(fpelPlane);<br>
+ X265_FREE(fpelPlane - m_startPad);<br></div></blockquote><div><br></div><div>this is only safe if isWeighted is false if <span style="color:rgb(80,0,80)">fpelPlane </span>allocation failed</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
}<br>
</div>+<br>
+void MotionReference::applyWeight(TComPic* ref, int rows, int numRows)<br>
<div class="im">+{<br>
+ TComPicYuv* pic = ref->getPicYuvRec();<br>
</div><div class="im">+ int marginX = pic->m_lumaMarginX;<br>
+ int marginY = pic->m_lumaMarginY;<br>
+<br>
+ int width = pic->getWidth();<br>
</div>+ int height = ((rows - m_numWeightedRows) * g_maxCUHeight);<br>
+ if (rows == numRows - 1) height = ((pic->getHeight() % g_maxCUHeight) ? (pic->getHeight() % g_maxCUHeight) : g_maxCUHeight);<br>
<div class="im">+<br>
+ size_t dstStride = lumaStride;<br>
+<br>
+ // Computing weighted CU rows<br>
+ int shiftNum = IF_INTERNAL_PREC - X265_DEPTH;<br>
+ shift = shift + shiftNum;<br>
+ round = shift ? (1 << (shift - 1)) : 0;<br>
+<br>
</div>+ primitives.weightpUniPixel((pixel*) pic->getLumaAddr(), fpelPlane, lumaStride, dstStride, width, height, weight, round, shift, offset, m_numWeightedRows * (int)g_maxCUHeight);<br>
<div class="im">+<br>
+ // Extending Left & Right<br>
+ primitives.extendRowBorder(fpelPlane, dstStride, width, height, marginX);<br>
+<br>
+ // Extending Above<br>
</div>+ if (m_numWeightedRows == 0)<br>
<div class="im">+ {<br>
+ pixel *pixY = fpelPlane - marginX;<br>
+<br>
+ for (int y = 0; y < marginY; y++)<br>
+ {<br>
+ memcpy(pixY - (y + 1) * dstStride, pixY, dstStride * sizeof(pixel));<br>
+ }<br>
+ }<br>
+<br>
+ // Extending Bottom<br>
</div>+ if (rows == (numRows - 1))<br>
<div class="im">+ {<br>
+ pixel *pixY = fpelPlane - marginX + (pic->getHeight() - 1) * dstStride;<br>
+<br>
+ for (int y = 0; y < marginY; y++)<br>
+ {<br>
+ memcpy(pixY + (y + 1) * dstStride, pixY, dstStride * sizeof(pixel));<br>
+ }<br>
+ }<br>
</div>+ m_numWeightedRows = rows;<br>
+}<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/reference.h<br>
--- a/source/common/reference.h Sat Sep 28 22:54:44 2013 -0500<br>
<div class="im">+++ b/source/common/reference.h Fri Sep 27 18:14:33 2013 +0530<br>
@@ -30,6 +30,7 @@<br>
// private x265 namespace<br>
<br>
class TComPicYuv;<br>
+class TComPic;<br>
struct WpScalingParam;<br>
typedef WpScalingParam wpScalingParam;<br>
<br>
</div>@@ -56,12 +57,17 @@<br>
{<br>
public:<br>
<br>
- MotionReference(TComPicYuv*, wpScalingParam* w = NULL);<br>
+ MotionReference();<br>
<br>
~MotionReference();<br>
<br>
+ void applyWeight(TComPic* src, int rows, int numRows);<br>
<div class="im">+ void extendRow(TComPic* pic, int row);<br>
</div>+ int init(TComPicYuv*, wpScalingParam* w = NULL);<br>
<div class="im">+<br>
MotionReference *m_next;<br>
TComPicYuv *m_reconPic;<br>
</div>+ int m_numWeightedRows;<br>
<br>
protected:<br>
<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp Sat Sep 28 22:54:44 2013 -0500<br>
<div class="im">+++ b/source/encoder/frameencoder.cpp Fri Sep 27 18:14:33 2013 +0530<br>
</div>@@ -914,6 +914,10 @@<br>
<div class="im"> {<br>
refpic->m_reconRowWait.wait();<br>
}<br>
+ if(slice->getPPS()->getUseWP())<br>
+ {<br>
</div>+ slice->m_mref[list][ref]->applyWeight(refpic, row + refLagRows, m_numRows);<br>
+ }<br>
}<br>
}<br>
<br>
diff -r 55edc34e253c -r cc94f1a5c6ab source/x265opts.h<br>
--- a/source/x265opts.h Sat Sep 28 22:54:44 2013 -0500<br>
<div class=""><div class="h5">+++ b/source/x265opts.h Fri Sep 27 18:14:33 2013 +0530<br>
@@ -69,8 +69,8 @@<br>
OPT("ref", param->maxNumReferences, required_argument, 0, "max number of L0 references to be allowed (1 .. 16)")<br>
// Disabled because weighted uni-prediction was busted by not using<br>
// pre-generated planes in motion compensation<br>
-//OPT("no-weightp", param->bEnableWeightedPred, no_argument, 0, "Disable weighted prediction in P slices")<br>
-//OPT("weightp", param->bEnableWeightedPred, no_argument, 'w', "Enable weighted prediction in P slices")<br>
+OPT("no-weightp", param->bEnableWeightedPred, no_argument, 0, "Disable weighted prediction in P slices")<br>
+OPT("weightp", param->bEnableWeightedPred, no_argument, 'w', "Enable weighted prediction in P slices")<br>
// Disabled because weighted bi prediction is busted<br>
//OPT("no-weightbp", param->bEnableWeightedBiPred, no_argument, 0, "Disable weighted (bidirectional) prediction in B slices")<br>
//OPT("weightbp", param->bEnableWeightedBiPred, no_argument, 0, "Enable weighted (bidirectional) prediction in B slices")<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Steve Borho
</div></div>