<div dir="ltr">We have a check inside calcAdaptiveQuantFrame() too!!<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Oct 31, 2013 at 8:59 PM, Steve Borho <span dir="ltr"><<a href="mailto:steve@borho.org" target="_blank">steve@borho.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, Oct 31, 2013 at 7:03 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"># HG changeset patch<br>
# User Shazeb Nawaz Khan <<a href="mailto:shazeb@multicorewareinc.com" target="_blank">shazeb@multicorewareinc.com</a>><br>
# Date 1383220857 -19800<br>
# Thu Oct 31 17:30:57 2013 +0530<br>
# Node ID c2cba0b6736c52ad177afa6a4974dfe2d35f56ef<br>
# Parent 9a0da4e6d9e363e383eae7243f0c64026a5f6d00<br>
Generating sum & ssd values for weightp decision in lookahead<br>
<br>
diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/common/lowres.h<br>
--- a/source/common/lowres.h Thu Oct 31 15:10:34 2013 +0530<br>
+++ b/source/common/lowres.h Thu Oct 31 17:30:57 2013 +0530<br>
@@ -42,6 +42,8 @@<br>
int frameNum; // Presentation frame number<br>
int sliceType; // Slice type decided by lookahead<br>
int leadingBframes; // number of leading B frames for P or I<br>
+ UInt64 m_wp_ssd[3]; // This is different than m_SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame<br>
+ UInt64 m_wp_sum[3];<br>
<br>
bool bIntraCalculated;<br>
bool bScenecut; // Set to false if the frame cannot possibly be part of a real scenecut.<br>
diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Thu Oct 31 15:10:34 2013 +0530<br>
+++ b/source/encoder/encoder.cpp Thu Oct 31 17:30:57 2013 +0530<br>
@@ -217,8 +217,7 @@<br>
<br>
// Encoder holds a reference count until collecting stats<br>
ATOMIC_INC(&pic->m_countRefEncoders);<br>
- if (param.rc.aqMode)<br>
- m_rateControl->calcAdaptiveQuantFrame(pic);<br>
+ m_rateControl->calcAdaptiveQuantFrame(pic);<br></blockquote><div><br></div></div></div><div>should this also be:</div><div><br></div><div> if (param.rc.aqMode || param.bEnableWeightedPred)<br></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><div class="h5">
m_lookahead->addPicture(pic, pic_in->sliceType);<br>
}<br>
<br>
diff -r 9a0da4e6d9e3 -r c2cba0b6736c source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Thu Oct 31 15:10:34 2013 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Thu Oct 31 17:30:57 2013 +0530<br>
@@ -51,16 +51,17 @@<br>
}<br>
<br>
/* Compute variance to derive AC energy of each block */<br>
-static inline uint32_t acEnergyVar(uint64_t sum_ssd, int shift)<br>
+static inline uint32_t acEnergyVar(TComPic *pic, uint64_t sum_ssd, int shift, int i)<br>
{<br>
uint32_t sum = (uint32_t)sum_ssd;<br>
uint32_t ssd = (uint32_t)(sum_ssd >> 32);<br>
-<br>
+ pic->m_lowres.m_wp_sum[i] += sum;<br>
+ pic->m_lowres.m_wp_ssd[i] += ssd;<br>
return ssd - ((uint64_t)sum * sum >> shift);<br>
}<br>
<br>
/* Find the energy of each block in Y/Cb/Cr plane */<br>
-static inline uint32_t acEnergyPlane(pixel* src, int srcStride, int bChroma)<br>
+static inline uint32_t acEnergyPlane(TComPic *pic, pixel* src, int srcStride, int bChroma)<br>
{<br>
int blockStride = FENC_STRIDE >> 3;<br>
<br>
@@ -68,10 +69,10 @@<br>
{<br>
ALIGN_VAR_8(pixel, pix[8 * 8]);<br>
primitives.blockcpy_pp(8, 8, pix, blockStride, src, srcStride);<br>
- return acEnergyVar(primitives.var[LUMA_8x8](pix, blockStride), 6);<br>
+ return acEnergyVar(pic, primitives.var[LUMA_8x8](pix, blockStride), 6, bChroma);<br>
}<br>
else<br>
- return acEnergyVar(primitives.var[LUMA_16x16](src, srcStride), 8);<br>
+ return acEnergyVar(pic, primitives.var[LUMA_16x16](src, srcStride), 8, bChroma);<br>
}<br>
<br>
/* Find the total AC energy of each block in all planes */<br>
@@ -86,9 +87,9 @@<br>
int cStride = pic->getPicYuvOrg()->getCStride();<br>
uint32_t blockOffsetLuma = block_x + (block_y * frameStride);<br>
uint32_t blockOffsetChroma = (block_x >> 1) + ((block_y >> 1) * cStride);<br>
- var = acEnergyPlane(srcLuma + blockOffsetLuma, frameStride, 0);<br>
- var += acEnergyPlane(srcCb + blockOffsetChroma, cStride, 1);<br>
- var += acEnergyPlane(srcCr + blockOffsetChroma, cStride, 1);<br>
+ var = acEnergyPlane(pic, srcLuma + blockOffsetLuma, frameStride, 0);<br>
+ var += acEnergyPlane(pic, srcCb + blockOffsetChroma, cStride, 1);<br>
+ var += acEnergyPlane(pic, srcCr + blockOffsetChroma, cStride, 2);<br>
avgQp = strength * (X265_LOG2( X265_MAX(var, 1) ) - 14.427f);<br>
x265_emms();<br>
return avgQp;<br>
@@ -97,23 +98,38 @@<br>
void RateControl::calcAdaptiveQuantFrame(TComPic *pic)<br>
{<br>
/* Actual adaptive quantization */<br>
- if (cfg->param.rc.aqMode)<br>
+ if (cfg->param.rc.aqMode || cfg->param.bEnableWeightedPred)<br>
{<br>
uint32_t blockWidth = g_maxCUWidth >> 2;<br>
uint32_t blockHeight = g_maxCUHeight >> 2;<br>
double qp_adj = 0;<br>
int block_xy = 0;<br>
+ int block_x = 0, block_y = 0;<br>
int maxCol = pic->getPicYuvOrg()->getWidth();<br>
int maxRow = pic->getPicYuvOrg()->getHeight();<br>
/* Calculate Qp offset for each 16x16 block in the frame */<br>
- for (int block_y = 0; block_y < maxRow; block_y += blockHeight)<br>
+ for (block_y = 0; block_y < maxRow; block_y += blockHeight)<br>
{<br>
- for (int block_x = 0; block_x < maxCol; block_x += blockWidth)<br>
+ for (block_x = 0; block_x < maxCol; block_x += blockWidth)<br>
{<br>
qp_adj = acEnergyCu(pic, block_x, block_y);<br>
- pic->m_lowres.m_qpAqOffset[block_xy] = qp_adj;<br>
- pic->m_lowres.m_invQscaleFactor[block_xy] = x265_exp2fix8(qp_adj);<br>
- block_xy++;<br>
+ if (cfg->param.rc.aqMode)<br>
+ {<br>
+ pic->m_lowres.m_qpAqOffset[block_xy] = qp_adj;<br>
+ pic->m_lowres.m_invQscaleFactor[block_xy] = x265_exp2fix8(qp_adj);<br>
+ block_xy++;<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ if (cfg->param.bEnableWeightedPred)<br>
+ {<br>
+ for(int i=0; i < 3; i++)<br>
+ {<br>
+ UInt64 sum, ssd;<br>
+ sum = pic->m_lowres.m_wp_sum[i];<br>
+ ssd = pic->m_lowres.m_wp_ssd[i];<br>
+ pic->m_lowres.m_wp_ssd[i] = ssd - (sum*sum + (block_x * block_y) / 2 ) / (block_x * block_y);<br>
}<br>
}<br>
}<br></div></div>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">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><span class="HOEnZb"><font color="#888888"><br>
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Steve Borho
</font></span></div></div>
<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>
<br></blockquote></div><br></div>