<div dir="ltr">This commit causes compile error. missed commenting out a debug stmt. Resending the patch..</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 16, 2013 at 11:25 PM, <span dir="ltr"><<a href="mailto:aarthi@multicorewareinc.com" target="_blank">aarthi@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Aarthi Thirumalai<<a href="mailto:aarthi@multicorewareinc.com">aarthi@multicorewareinc.com</a>><br>
# Date 1381946053 -19800<br>
# Wed Oct 16 23:24:13 2013 +0530<br>
# Node ID 3b38eece9db42008f5c8fd582f9236cc7a0dceeb<br>
# Parent 46cdbe43d903c23169593f70c28b5d32d8f397e9<br>
rc: implement Adaptive Quantization.<br>
<br>
added functions to compute AC Energy per CU for all planes,<br>
calculate qpAqOffset for each CU<br>
<br>
diff -r 46cdbe43d903 -r 3b38eece9db4 source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Wed Oct 16 23:18:08 2013 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Wed Oct 16 23:24:13 2013 +0530<br>
@@ -50,6 +50,79 @@<br>
return 0.85 * pow(2.0, (qp - 12.0) / 6.0);<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>
+{<br>
+ uint32_t sum = (uint32_t)sum_ssd;<br>
+ uint32_t ssd = (uint32_t)(sum_ssd >> 32);<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 b_chroma)<br>
+{<br>
+ int blockStride = FENC_STRIDE >> 2;<br>
+<br>
+ if( b_chroma )<br>
+ {<br>
+ ALIGN_VAR_16( pixel, pix[16 * 16] );<br>
+ primitives.blockcpy_pp(8, 8, pix, blockStride, src, srcStride);<br>
+ return acEnergyVar(primitives.var[PARTITION_8x8](pix, blockStride), 6);<br>
+ }<br>
+ else<br>
+ return acEnergyVar(primitives.var[PARTITION_16x16](src, srcStride), 8);<br>
+}<br>
+<br>
+/* Find the total AC energy of each CU in all planes */<br>
+ double RateControl::acEnergyCu(TComPic* pic , uint32_t cuAddr)<br>
+{<br>
+ uint32_t var = 0;<br>
+ double avgQp = 0;<br>
+ pixel* srcLuma = pic->getPicYuvOrg()->getLumaAddr(cuAddr);<br>
+ pixel* srcCb = pic->getPicYuvOrg()->getCbAddr(cuAddr);<br>
+ pixel* srcCr = pic->getPicYuvOrg()->getCrAddr(cuAddr);<br>
+ UInt blockWidth = g_maxCUWidth >> 2;<br>
+ UInt blockHeight = g_maxCUHeight >> 2;<br>
+ UInt frameStride = pic->getPicYuvOrg()->getStride();<br>
+ UInt cStride = pic->getPicYuvOrg()->getCStride();<br>
+<br>
+ // Calculate Qp offset for each 16x16 block in the CU and average them over entire CU<br>
+ for (UInt h = 0, cnt = 0; h < g_maxCUHeight; h += blockHeight)<br>
+ for (UInt w = 0 ;w < g_maxCUWidth ; w += blockWidth, cnt++)<br>
+ {<br>
+ UInt blockOffsetLuma = w + (h * frameStride);<br>
+ UInt blockOffsetChroma = (w >> 1) + ((h >> 1) * cStride);<br>
+ var = acEnergyPlane(srcLuma + blockOffsetLuma, frameStride, 0);<br>
+ var += acEnergyPlane(srcCb + blockOffsetChroma, cStride, 1);<br>
+ var += acEnergyPlane(srcCr + blockOffsetChroma, cStride, 1);<br>
+ avgQp += cfg->param.rc.aqStrength * (X265_LOG2(X265_MAX(var, 1)) - (14.427f));<br>
+ fprintf(fp2,"\n cuAddr : %d , energy : %d ",cuAddr,var);<br>
+ }<br>
+ avgQp /= 16;<br>
+ x265_emms();<br>
+ return avgQp;<br>
+}<br>
+<br>
+void RateControl::calcAdaptiveQuantFrame(TComPic *pic)<br>
+{<br>
+ double strength;<br>
+ /* Actual adaptive quantization */<br>
+ if (cfg->param.rc.aqMode)<br>
+ {<br>
+ strength = cfg->param.rc.aqStrength * 1.0397f;<br>
+ int maxRows = pic->getPicSym()->getFrameHeightInCU();<br>
+ int maxCols = pic->getPicSym()->getFrameWidthInCU();<br>
+ for (int cu_y = 0; cu_y < maxRows; cu_y++)<br>
+ for (int cu_x = 0; cu_x < maxCols; cu_x++)<br>
+ {<br>
+ double qp_adj;<br>
+ int cu_xy = maxCols * cu_y + cu_x;<br>
+ qp_adj = acEnergyCu(pic, cu_xy);<br>
+ pic->m_qpAqOffset[cu_xy] = qp_adj;<br>
+ }<br>
+ }<br>
+}<br>
+<br>
RateControl::RateControl(TEncCfg * _cfg)<br>
{<br>
this->cfg = _cfg;<br>
diff -r 46cdbe43d903 -r 3b38eece9db4 source/encoder/ratecontrol.h<br>
--- a/source/encoder/ratecontrol.h Wed Oct 16 23:18:08 2013 +0530<br>
+++ b/source/encoder/ratecontrol.h Wed Oct 16 23:24:13 2013 +0530<br>
@@ -80,7 +80,7 @@<br>
<br>
// to be called for each frame to process RateCOntrol and set QP<br>
void rateControlStart(TComPic* pic, Lookahead *, RateControlEntry* rce);<br>
-<br>
+ void calcAdaptiveQuantFrame(TComPic *pic);<br>
int rateControlEnd(int64_t bits, RateControlEntry* rce);<br>
<br>
protected:<br>
@@ -88,6 +88,7 @@<br>
double getQScale(RateControlEntry *rce, double rateFactor);<br>
double rateEstimateQscale(RateControlEntry *rce); // main logic for calculating QP based on ABR<br>
void accumPQpUpdate();<br>
+ double acEnergyCu(TComPic* pic , uint32_t cuAddr);<br>
};<br>
}<br>
<br>
</blockquote></div><br></div>