<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 25, 2018 at 6:15 PM <<a href="mailto:ashok@multicorewareinc.com">ashok@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Ashok Kumar Mishra <<a href="mailto:ashok@multicorewareinc.com" target="_blank">ashok@multicorewareinc.com</a>><br>
# Date 1537871551 -19800<br>
# Tue Sep 25 16:02:31 2018 +0530<br>
# Node ID e5434c75d9ba2a327a06d74bbc93523cf5c81b80<br>
# Parent bbad4e55b51a938dd4ce1375e0cb4dd4f59a5f27<br>
Cleanup<br>
<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/common/frame.cpp<br>
--- a/source/common/frame.cpp Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/common/frame.cpp Tue Sep 25 16:02:31 2018 +0530<br>
@@ -94,7 +94,7 @@<br>
CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);<br>
}<br>
<br>
- if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) && m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode || !!param->bAQMotion, param->rc.qgSize))<br>
+ if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) && m_lowres.create(param, m_fencPic, param->rc.qgSize))<br>
{<br>
X265_CHECK((m_reconColCount == NULL), "m_reconColCount was initialized");<br>
m_numRows = (m_fencPic->m_picHeight + param->maxCUSize - 1) / param->maxCUSize;<br>
@@ -103,11 +103,8 @@<br>
<br>
if (quantOffsets)<br>
{<br>
- int32_t cuCount;<br>
- if (param->rc.qgSize == 8)<br>
- cuCount = m_lowres.maxBlocksInRowFullRes * m_lowres.maxBlocksInColFullRes;<br>
- else<br>
- cuCount = m_lowres.maxBlocksInRow * m_lowres.maxBlocksInCol;<br>
+ int32_t cuCount = (param->rc.qgSize == 8) ? m_lowres.maxBlocksInRowFullRes * m_lowres.maxBlocksInColFullRes :<br>
+ m_lowres.maxBlocksInRow * m_lowres.maxBlocksInCol;<br>
m_quantOffsets = new float[cuCount];<br>
}<br>
return true;<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/common/lowres.cpp<br>
--- a/source/common/lowres.cpp Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/common/lowres.cpp Tue Sep 25 16:02:31 2018 +0530<br>
@@ -27,10 +27,10 @@<br>
<br>
using namespace X265_NS;<br>
<br>
-bool Lowres::create(PicYuv *origPic, int _bframes, bool bAQEnabled, uint32_t qgSize)<br>
+bool Lowres::create(x265_param* param, PicYuv *origPic, uint32_t qgSize)<br>
{<br>
isLowres = true;<br>
- bframes = _bframes;<br>
+ bframes = param->bframes;<br>
width = origPic->m_picWidth / 2;<br>
lines = origPic->m_picHeight / 2;<br>
lumaStride = width + 2 * origPic->m_lumaMarginX;<br>
@@ -41,11 +41,7 @@<br>
maxBlocksInRowFullRes = maxBlocksInRow * 2;<br>
maxBlocksInColFullRes = maxBlocksInCol * 2;<br>
int cuCount = maxBlocksInRow * maxBlocksInCol;<br>
- int cuCountFullRes;<br>
- if (qgSize == 8)<br>
- cuCountFullRes = maxBlocksInRowFullRes * maxBlocksInColFullRes;<br>
- else<br>
- cuCountFullRes = cuCount;<br>
+ int cuCountFullRes = (qgSize > 8) ? cuCount : cuCount << 2;<br>
<br>
/* rounding the width to multiple of lowres CU size */<br>
width = maxBlocksInRow * X265_LOWRES_CU_SIZE;<br>
@@ -53,7 +49,7 @@<br>
<br>
size_t planesize = lumaStride * (lines + 2 * origPic->m_lumaMarginY);<br>
size_t padoffset = lumaStride * origPic->m_lumaMarginY + origPic->m_lumaMarginX;<br>
- if (bAQEnabled)<br>
+ if (!!param->rc.aqMode)<br>
{<br>
CHECKED_MALLOC_ZERO(qpAqOffset, double, cuCountFullRes);<br>
CHECKED_MALLOC_ZERO(invQscaleFactor, int, cuCountFullRes);<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/common/lowres.h<br>
--- a/source/common/lowres.h Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/common/lowres.h Tue Sep 25 16:02:31 2018 +0530<br>
@@ -152,14 +152,12 @@<br>
uint32_t* blockVariance;<br>
uint64_t wp_ssd[3]; // This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame<br>
uint64_t wp_sum[3];<br>
- uint64_t frameVariance;<br>
<br>
/* cutree intermediate data */<br>
uint16_t* propagateCost;<br>
double weightedCostDelta[X265_BFRAME_MAX + 2];<br>
ReferencePlanes weightedRef[X265_BFRAME_MAX + 2];<br>
-<br>
- bool create(PicYuv *origPic, int _bframes, bool bAqEnabled, uint32_t qgSize);<br>
+ bool create(x265_param* param, PicYuv *origPic, uint32_t qgSize);<br>
void destroy();<br>
void init(PicYuv *origPic, int poc);<br>
};<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/analysis.cpp<br>
--- a/source/encoder/analysis.cpp Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/encoder/analysis.cpp Tue Sep 25 16:02:31 2018 +0530<br>
@@ -3357,13 +3357,13 @@<br>
primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCbAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC,<br>
predU, predYuv.m_csize);<br>
<br>
- if (cu.m_cbf[2][0])<br>
- {<br>
- bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr] + reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;<br>
- bool predValign = predYuv.getChromaAddrOffset(absPartIdx) % 64 == 0;<br>
- primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign && predValign && (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 == 0) &&<br>
- (resiYuv.m_csize % 64 == 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV, resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);<br>
- }<br>
+ if (cu.m_cbf[2][0])<br>
+ {<br>
+ bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr] + reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;<br>
+ bool predValign = predYuv.getChromaAddrOffset(absPartIdx) % 64 == 0;<br>
+ primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign && predValign && (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 == 0) &&<br>
+ (resiYuv.m_csize % 64 == 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV, resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);<br>
+ }<br>
else<br>
primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC,<br>
predV, predYuv.m_csize);<br>
@@ -3568,18 +3568,12 @@<br>
qp += distortionData->offset[ctu.m_cuAddr];<br>
}<br>
<br>
- int loopIncr;<br>
- if (m_param->rc.qgSize == 8)<br>
- loopIncr = 8;<br>
- else<br>
- loopIncr = 16;<br>
+ int loopIncr = (m_param->rc.qgSize == 8) ? 8 : 16;<br>
+<br>
/* Use cuTree offsets if cuTree enabled and frame is referenced, else use AQ offsets */<br>
bool isReferenced = IS_REFERENCED(m_frame);<br>
- double *qpoffs;<br>
- if (complexCheck)<br>
- qpoffs = m_frame->m_lowres.qpAqOffset;<br>
- else<br>
- qpoffs = (isReferenced && m_param->rc.cuTree) ? m_frame->m_lowres.qpCuTreeOffset : m_frame->m_lowres.qpAqOffset;<br>
+ double *qpoffs = (isReferenced && m_param->rc.cuTree && !complexCheck) ? m_frame->m_lowres.qpCuTreeOffset :<br>
+ m_frame->m_lowres.qpAqOffset;<br>
if (qpoffs)<br>
{<br>
uint32_t width = m_frame->m_fencPic->m_picWidth;<br>
@@ -3590,13 +3584,11 @@<br>
uint32_t blockSize = m_param->maxCUSize >> cuGeom.depth;<br>
double qp_offset = 0;<br>
uint32_t cnt = 0;<br>
- uint32_t idx;<br>
-<br>
for (uint32_t block_yy = block_y; block_yy < block_y + blockSize && block_yy < height; block_yy += loopIncr)<br>
{<br>
for (uint32_t block_xx = block_x; block_xx < block_x + blockSize && block_xx < width; block_xx += loopIncr)<br>
{<br>
- idx = ((block_yy / loopIncr) * (maxCols)) + (block_xx / loopIncr);<br>
+ uint32_t idx = ((block_yy / loopIncr) * (maxCols)) + (block_xx / loopIncr);<br>
qp_offset += qpoffs[idx];<br>
cnt++;<br>
}<br>
@@ -3609,10 +3601,7 @@<br>
int32_t offset = (int32_t)(qp_offset * 100 + .5);<br>
double threshold = (1 - ((x265_ADAPT_RD_STRENGTH - m_param->dynamicRd) * 0.5));<br>
int32_t max_threshold = (int32_t)(threshold * 100 + .5);<br>
- if (offset < max_threshold)<br>
- return 1;<br>
- else<br>
- return 0;<br>
+ return (offset < max_threshold);<br>
}<br>
}<br>
<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Tue Sep 25 16:02:31 2018 +0530<br>
@@ -2803,12 +2803,8 @@<br>
/* called to write out the rate control frame stats info in multipass encodes */<br>
int RateControl::writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce)<br>
{<br>
- FrameData& curEncData = *curFrame->m_encData;<br>
- int ncu;<br>
- if (m_param->rc.qgSize == 8)<br>
- ncu = m_ncu * 4;<br>
- else<br>
- ncu = m_ncu;<br>
+ FrameData& curEncData = *curFrame->m_encData; <br>
+ int ncu = (m_param->rc.qgSize == 8) ? m_ncu * 4 : m_ncu;<br>
char cType = rce->sliceType == I_SLICE ? (curFrame->m_lowres.sliceType == X265_TYPE_IDR ? 'I' : 'i')<br>
: rce->sliceType == P_SLICE ? 'P'<br>
: IS_REFERENCED(curFrame) ? 'B' : 'b';<br>
diff -r bbad4e55b51a -r e5434c75d9ba source/encoder/slicetype.cpp<br>
--- a/source/encoder/slicetype.cpp Tue Sep 18 16:34:04 2018 +0530<br>
+++ b/source/encoder/slicetype.cpp Tue Sep 25 16:02:31 2018 +0530<br>
@@ -150,20 +150,14 @@<br>
curFrame->m_lowres.wp_sum[y] = 0;<br>
}<br>
<br>
- /* Calculate Qp offset for each 16x16 or 8x8 block in the frame */<br>
- int blockXY = 0;<br>
- int blockX = 0, blockY = 0;<br>
- double strength = 0.f;<br>
+ /* Calculate Qp offset for each 16x16 or 8x8 block in the frame */ <br>
if ((param->rc.aqMode == X265_AQ_NONE || param->rc.aqStrength == 0) || (param->rc.bStatRead && param->rc.cuTree && IS_REFERENCED(curFrame)))<br>
{<br>
- /* Need to init it anyways for CU tree */<br>
- int cuCount = blockCount;<br>
-<br>
if (param->rc.aqMode && param->rc.aqStrength == 0)<br>
{<br>
if (quantOffsets)<br>
{<br>
- for (int cuxy = 0; cuxy < cuCount; cuxy++)<br>
+ for (int cuxy = 0; cuxy < blockCount; cuxy++)<br>
{<br>
curFrame->m_lowres.qpCuTreeOffset[cuxy] = curFrame->m_lowres.qpAqOffset[cuxy] = quantOffsets[cuxy];<br>
curFrame->m_lowres.invQscaleFactor[cuxy] = x265_exp2fix8(curFrame->m_lowres.qpCuTreeOffset[cuxy]);<br>
@@ -171,60 +165,55 @@<br>
}<br>
else<br>
{<br>
- memset(curFrame->m_lowres.qpCuTreeOffset, 0, cuCount * sizeof(double));<br>
- memset(curFrame->m_lowres.qpAqOffset, 0, cuCount * sizeof(double));<br>
- for (int cuxy = 0; cuxy < cuCount; cuxy++)<br>
- curFrame->m_lowres.invQscaleFactor[cuxy] = 256;<br>
+ memset(curFrame->m_lowres.qpCuTreeOffset, 0, blockCount * sizeof(double));<br>
+ memset(curFrame->m_lowres.qpAqOffset, 0, blockCount * sizeof(double));<br>
+ for (int cuxy = 0; cuxy < blockCount; cuxy++)<br>
+ curFrame->m_lowres.invQscaleFactor[cuxy] = 256;<br>
}<br>
}<br>
<br>
/* Need variance data for weighted prediction and dynamic refinement*/<br>
if (param->bEnableWeightedPred || param->bEnableWeightedBiPred)<br>
- { <br>
- for (blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
- for (blockX = 0; blockX < maxCol; blockX += loopIncr) <br>
+ {<br>
+ for (int blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
+ for (int blockX = 0; blockX < maxCol; blockX += loopIncr) <br>
acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize); <br>
}<br>
}<br>
else<br>
{<br>
- blockXY = 0;<br>
- double avg_adj_pow2 = 0, avg_adj = 0, qp_adj = 0;<br>
- double bias_strength = 0.f;<br>
+ int blockXY = 0;<br>
+ double avg_adj_pow2 = 0.f, avg_adj = 0.f, qp_adj = 0.f;<br>
+ double bias_strength = 0.f, strength = 0.f;<br>
if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE || param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED)<br>
{<br>
- double bit_depth_correction = 1.f / (1 << (2*(X265_DEPTH-8)));<br>
- curFrame->m_lowres.frameVariance = 0;<br>
- uint64_t rowVariance = 0;<br>
- for (blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
- {<br>
- rowVariance = 0;<br>
- for (blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
+ double bit_depth_correction = 1.f / (1 << (2*(X265_DEPTH-8))); <br>
+ <br>
+ for (int blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
+ { <br>
+ for (int blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
{<br>
- uint32_t energy = acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize);<br>
- rowVariance += energy;<br>
+ uint32_t energy = acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize); <br>
qp_adj = pow(energy * bit_depth_correction + 1, 0.1);<br>
curFrame->m_lowres.qpCuTreeOffset[blockXY] = qp_adj;<br>
avg_adj += qp_adj;<br>
avg_adj_pow2 += qp_adj * qp_adj;<br>
blockXY++;<br>
}<br>
- curFrame->m_lowres.frameVariance += (rowVariance / maxCol);<br>
}<br>
- curFrame->m_lowres.frameVariance /= maxRow;<br>
avg_adj /= blockCount;<br>
avg_adj_pow2 /= blockCount;<br>
strength = param->rc.aqStrength * avg_adj;<br>
- avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - (modeTwoConst)) / avg_adj;<br>
+ avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - modeTwoConst) / avg_adj;<br>
bias_strength = param->rc.aqStrength;<br>
}<br>
else<br>
strength = param->rc.aqStrength * 1.0397f;<br>
<br>
blockXY = 0;<br>
- for (blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
+ for (int blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
{<br>
- for (blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
+ for (int blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
{<br>
if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED)<br>
{<br>
@@ -310,9 +299,9 @@<br>
<br>
if (param->bDynamicRefine)<br>
{<br>
- blockXY = 0;<br>
- for (blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
- for (blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
+ int blockXY = 0;<br>
+ for (int blockY = 0; blockY < maxRow; blockY += loopIncr)<br>
+ for (int blockX = 0; blockX < maxCol; blockX += loopIncr)<br>
{<br>
curFrame->m_lowres.blockVariance[blockXY] = acEnergyCu(curFrame, blockX, blockY, param->internalCsp, param->rc.qgSize);<br>
blockXY++;<br></blockquote><div><br></div><div>Pushed to default. </div></div></div>