[x265] [PATCH] rc: move qp2qscale and qscale2qp function to common
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Mon Mar 10 20:46:37 CET 2014
# HG changeset patch
# User Aarthi Thirumalai
# Date 1394480788 -19800
# Tue Mar 11 01:16:28 2014 +0530
# Node ID 7f4b871d7a0ce7f8aa90b10518fd7edc5bc95261
# Parent f103a68c678c88c9072f6ea286582ec9427a2241
rc: move qp2qscale and qscale2qp function to common
diff -r f103a68c678c -r 7f4b871d7a0c source/common/common.cpp
--- a/source/common/common.cpp Tue Mar 11 01:05:50 2014 +0530
+++ b/source/common/common.cpp Tue Mar 11 01:16:28 2014 +0530
@@ -141,3 +141,15 @@
return -10.0 * log10(inv_ssim);
}
+
+/* The qscale - qp conversion is specified in the standards.
+ * Approx qscale increases by 12% with every qp increment */
+ double x265_qScale2qp(double qScale)
+{
+ return 12.0 + 6.0 * (double)X265_LOG2(qScale / 0.85);
+}
+
+ double x265_qp2qScale(double qp)
+{
+ return 0.85 * pow(2.0, (qp - 12.0) / 6.0);
+}
diff -r f103a68c678c -r 7f4b871d7a0c source/common/common.h
--- a/source/common/common.h Tue Mar 11 01:05:50 2014 +0530
+++ b/source/common/common.h Tue Mar 11 01:16:28 2014 +0530
@@ -152,5 +152,7 @@
void x265_free(void *ptr);
double x265_ssim2dB(double ssim);
+double x265_qScale2qp(double qScale);
+double x265_qp2qScale(double qp);
#endif // ifndef X265_COMMON_H
diff -r f103a68c678c -r 7f4b871d7a0c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Tue Mar 11 01:05:50 2014 +0530
+++ b/source/encoder/ratecontrol.cpp Tue Mar 11 01:16:28 2014 +0530
@@ -30,17 +30,6 @@
using namespace x265;
-/* The qscale - qp conversion is specified in the standards.
- * Approx qscale increases by 12% with every qp increment */
-static inline double qScale2qp(double qScale)
-{
- return 12.0 + 6.0 * (double)X265_LOG2(qScale / 0.85);
-}
-
-static inline double qp2qScale(double qp)
-{
- return 0.85 * pow(2.0, (qp - 12.0) / 6.0);
-}
/* Compute variance to derive AC energy of each block */
static inline uint32_t acEnergyVar(TComPic *pic, uint64_t sum_ssd, int shift, int i)
@@ -230,7 +219,7 @@
double baseCplx = ncu * (param->bframes ? 120 : 80);
double mbtree_offset = param->rc.cuTree ? (1.0 - param->rc.qCompress) * 13.5 : 0;
rateFactorConstant = pow(baseCplx, 1 - qCompress) /
- qp2qScale(param->rc.rfConstant + mbtree_offset);
+ x265_qp2qScale(param->rc.rfConstant + mbtree_offset);
if (param->rc.rfConstantMax)
{
rateFactorMaxIncrement = param->rc.rfConstantMax - param->rc.rfConstant;
@@ -338,9 +327,9 @@
pbOffset = 6.0 * X265_LOG2(param->rc.pbFactor);
for (int i = 0; i < 3; i++)
{
- lastQScaleFor[i] = qp2qScale(param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN);
- lmin[i] = qp2qScale(MIN_QP);
- lmax[i] = qp2qScale(MAX_MAX_QP);
+ lastQScaleFor[i] = x265_qp2qScale(param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN);
+ lmin[i] = x265_qp2qScale(MIN_QP);
+ lmax[i] = x265_qp2qScale(MAX_MAX_QP);
}
if (param->rc.rateControlMode == X265_RC_CQP)
@@ -417,7 +406,7 @@
currentSatd = l->getEstimatedPictureCost(pic) >> (X265_DEPTH - 8);
/* Update rce for use in rate control VBV later */
rce->lastSatd = currentSatd;
- double q = qScale2qp(rateEstimateQscale(pic, rce));
+ double q = x265_qScale2qp(rateEstimateQscale(pic, rce));
q = Clip3((double)MIN_QP, (double)MAX_MAX_QP, q);
qp = int(q + 0.5);
rce->qpaRc = pic->m_avgQpRc = pic->m_avgQpAq = q;
@@ -501,7 +490,7 @@
else
q += pbOffset;
qpNoVbv = q;
- double qScale = qp2qScale(qpNoVbv);
+ double qScale = x265_qp2qScale(qpNoVbv);
rce->frameSizePlanned = predictSize(&predBfromP, qScale, (double)leadingNoBSatd);
rce->frameSizeEstimated = rce->frameSizePlanned;
return qScale;
@@ -564,7 +553,7 @@
if (sliceType == I_SLICE && param->keyframeMax > 1
&& lastNonBPictType != I_SLICE && !isAbrReset)
{
- q = qp2qScale(accumPQp / accumPNorm);
+ q = x265_qp2qScale(accumPQp / accumPNorm);
q /= fabs(param->rc.ipFactor);
}
@@ -573,8 +562,8 @@
double lqmin = 0, lqmax = 0;
if (totalBits == 0 && !isVbv)
{
- lqmin = qp2qScale(ABR_INIT_QP_MIN) / lstep;
- lqmax = qp2qScale(ABR_INIT_QP_MAX) * lstep;
+ lqmin = x265_qp2qScale(ABR_INIT_QP_MIN) / lstep;
+ lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * lstep;
q = Clip3(lqmin, lqmax, q);
}
else if (totalBits > 0 || (isVbv && framesDone > 0))
@@ -591,12 +580,12 @@
else
{
if (qCompress != 1 && framesDone == 0)
- q = qp2qScale(ABR_INIT_QP) / fabs(param->rc.ipFactor);
+ q = x265_qp2qScale(ABR_INIT_QP) / fabs(param->rc.ipFactor);
}
double lmin1 = lmin[sliceType];
double lmax1 = lmax[sliceType];
q = Clip3(lmin1, lmax1, q);
- qpNoVbv = qScale2qp(q);
+ qpNoVbv = x265_qScale2qp(q);
q = clipQscale(pic, q);
@@ -776,7 +765,7 @@
uint32_t rowSatdCostSoFar = 0, totalSatdBits = 0;
encodedBitsSoFar = 0;
- double qScale = qp2qScale(qpVbv);
+ double qScale = x265_qp2qScale(qpVbv);
int picType = pic->getSlice()->getSliceType();
TComPic* refPic = pic->getSlice()->getRefPic(REF_PIC_LIST_0, 0);
int maxRows = pic->getPicSym()->getFrameHeightInCU();
@@ -836,7 +825,7 @@
int RateControl::rowDiagonalVbvRateControl(TComPic* pic, uint32_t row, RateControlEntry* rce, double& qpVbv)
{
- double qScaleVbv = qp2qScale(qpVbv);
+ double qScaleVbv = x265_qp2qScale(qpVbv);
pic->m_rowDiagQp[row] = qpVbv;
pic->m_rowDiagQScale[row] = qScaleVbv;
@@ -1002,7 +991,7 @@
void RateControl::updateVbv(int64_t bits, RateControlEntry* rce)
{
if (rce->lastSatd >= ncu)
- updatePredictor(&pred[rce->sliceType], qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bits);
+ updatePredictor(&pred[rce->sliceType], x265_qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bits);
if (!isVbv)
return;
@@ -1050,12 +1039,12 @@
if (rce->sliceType != B_SLICE)
/* The factor 1.5 is to tune up the actual bits, otherwise the cplxrSum is scaled too low
* to improve short term compensation for next frame. */
- cplxrSum += bits * qp2qScale(rce->qpaRc) / rce->qRceq;
+ cplxrSum += bits * x265_qp2qScale(rce->qpaRc) / rce->qRceq;
else
{
/* Depends on the fact that B-frame's QP is an offset from the following P-frame's.
* Not perfectly accurate with B-refs, but good enough. */
- cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(param->rc.pbFactor));
+ cplxrSum += bits * x265_qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(param->rc.pbFactor));
}
wantedBitsWindow += frameDuration * bitrate;
totalBits += bits;
@@ -1070,7 +1059,7 @@
if (rce->bLastMiniGopBFrame)
{
if (rce->bframes != 0)
- updatePredictor(&predBfromP, qp2qScale(rce->qpaRc), (double)rce->leadingNoBSatd, (double)bframeBits / rce->bframes);
+ updatePredictor(&predBfromP, x265_qp2qScale(rce->qpaRc), (double)rce->leadingNoBSatd, (double)bframeBits / rce->bframes);
bframeBits = 0;
}
}
More information about the x265-devel
mailing list