[x265] [PATCH] rd: move lambda and analysis qp init to rdcost.h
Steve Borho
steve at borho.org
Tue Sep 30 09:58:00 CEST 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1412063812 18000
# Tue Sep 30 02:56:52 2014 -0500
# Node ID 235633705d320293456e79307bd861ce2bf45f28
# Parent a92f41aa59aa6f7643afb133621cf1ef9bbcbf2f
rd: move lambda and analysis qp init to rdcost.h
This will make it possible for Search instances to copy QP data between each
other
diff -r a92f41aa59aa -r 235633705d32 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Tue Sep 30 02:20:47 2014 -0500
+++ b/source/encoder/frameencoder.cpp Tue Sep 30 02:56:52 2014 -0500
@@ -624,12 +624,13 @@
Entropy& rowCoder = m_param->bEnableWavefront ? m_rows[row].rdEntropyCoders[0][CI_CURR_BEST] :
m_rows[0].rdEntropyCoders[0][CI_CURR_BEST];
// setup thread-local data
+ Slice *slice = m_frame->m_picSym->m_slice;
TComPicYuv* fenc = m_frame->getPicYuvOrg();
tld.analysis.m_quant.m_nr = m_nr;
tld.analysis.m_me.setSourcePlane(fenc->getLumaAddr(), fenc->getStride());
tld.analysis.m_log = &tld.analysis.m_sliceTypeLog[m_frame->m_picSym->m_slice->m_sliceType];
tld.analysis.m_rdEntropyCoders = curRow.rdEntropyCoders;
- setLambda(m_frame->m_picSym->m_slice->m_sliceQp, tld);
+ tld.analysis.setQP(slice, slice->m_sliceQp);
int64_t startTime = x265_mdate();
assert(m_frame->getPicSym()->getFrameWidthInCU() == m_numCols);
@@ -664,7 +665,7 @@
if (m_param->rc.aqMode || bIsVbv)
{
int qp = calcQpForCu(cuAddr, cu->m_baseQp);
- setLambda(qp, tld);
+ tld.analysis.setQP(slice, qp);
qp = Clip3(QP_MIN, QP_MAX_SPEC, qp);
cu->setQPSubParts(char(qp), 0, 0);
if (m_param->rc.aqMode)
@@ -879,25 +880,6 @@
curRow.busy = false;
}
-void FrameEncoder::setLambda(int qp, ThreadLocalData &tld)
-{
- Slice* slice = m_frame->m_picSym->m_slice;
- int qpCb = Clip3(0, QP_MAX_MAX, qp + slice->m_pps->chromaCbQpOffset);
- int qpCr = Clip3(0, QP_MAX_MAX, qp + slice->m_pps->chromaCrQpOffset);
- qp = Clip3(0, QP_MAX_MAX, qp);
-
- tld.analysis.m_me.setQP(qp);
- tld.analysis.m_rdCost.setLambda(x265_lambda2_tab[qp], x265_lambda_tab[qp]);
-
- int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
- uint16_t lambdaOffset = tld.analysis.m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
- tld.analysis.m_rdCost.setCbDistortionWeight(lambdaOffset);
-
- chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
- lambdaOffset = tld.analysis.m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
- tld.analysis.m_rdCost.setCrDistortionWeight(lambdaOffset);
-}
-
/* DCT-domain noise reduction / adaptive deadzone from libavcodec */
void FrameEncoder::noiseReductionUpdate()
{
diff -r a92f41aa59aa -r 235633705d32 source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h Tue Sep 30 02:20:47 2014 -0500
+++ b/source/encoder/frameencoder.h Tue Sep 30 02:56:52 2014 -0500
@@ -164,7 +164,6 @@
void encodeSlice();
void threadMain();
- void setLambda(int qp, ThreadLocalData& tld);
int calcQpForCu(uint32_t cuAddr, double baseQp);
void noiseReductionUpdate();
diff -r a92f41aa59aa -r 235633705d32 source/encoder/rdcost.h
--- a/source/encoder/rdcost.h Tue Sep 30 02:20:47 2014 -0500
+++ b/source/encoder/rdcost.h Tue Sep 30 02:56:52 2014 -0500
@@ -25,6 +25,7 @@
#define X265_RDCOST_H
#include "common.h"
+#include "slice.h"
namespace x265 {
// private namespace
@@ -39,11 +40,29 @@
uint64_t m_cbDistortionWeight;
uint64_t m_crDistortionWeight;
uint32_t m_psyRd;
+ int m_qp;
void setPsyRdScale(double scale) { m_psyRd = (uint32_t)floor(256.0 * scale * 0.33); }
void setCbDistortionWeight(uint16_t weightFix8) { m_cbDistortionWeight = weightFix8; }
void setCrDistortionWeight(uint16_t weightFix8) { m_crDistortionWeight = weightFix8; }
+ void setQP(Slice *slice, int qp)
+ {
+ m_qp = qp;
+
+ setLambda(x265_lambda2_tab[qp], x265_lambda_tab[qp]);
+
+ int qpCb = Clip3(QP_MIN, QP_MAX_MAX, qp + slice->m_pps->chromaCbQpOffset);
+ int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
+ uint16_t lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
+ setCbDistortionWeight(lambdaOffset);
+
+ int qpCr = Clip3(QP_MIN, QP_MAX_MAX, qp + slice->m_pps->chromaCrQpOffset);
+ chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
+ lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
+ setCrDistortionWeight(lambdaOffset);
+ }
+
void setLambda(double lambda2, double lambda)
{
m_lambda2 = (uint64_t)floor(256.0 * lambda2);
diff -r a92f41aa59aa -r 235633705d32 source/encoder/search.cpp
--- a/source/encoder/search.cpp Tue Sep 30 02:20:47 2014 -0500
+++ b/source/encoder/search.cpp Tue Sep 30 02:56:52 2014 -0500
@@ -109,6 +109,12 @@
return false;
}
+void Search::setQP(Slice *slice, int qp)
+{
+ m_me.setQP(qp);
+ m_rdCost.setQP(slice, qp);
+}
+
void Search::xEncSubdivCbfQTChroma(TComDataCU* cu, uint32_t trDepth, uint32_t absPartIdx, uint32_t absPartIdxStep, uint32_t width, uint32_t height)
{
uint32_t fullDepth = cu->getDepth(0) + trDepth;
diff -r a92f41aa59aa -r 235633705d32 source/encoder/search.h
--- a/source/encoder/search.h Tue Sep 30 02:20:47 2014 -0500
+++ b/source/encoder/search.h Tue Sep 30 02:56:52 2014 -0500
@@ -79,6 +79,7 @@
~Search();
bool initSearch(x265_param *param, ScalingList& scalingList);
+ void setQP(Slice* slice, int qp);
void estIntraPredQT(TComDataCU* cu, TComYuv* fencYuv, TComYuv* predYuv, ShortYuv* resiYuv, TComYuv* reconYuv, uint32_t depthRange[2]);
void sharedEstIntraPredQT(TComDataCU* cu, TComYuv* fencYuv, TComYuv* predYuv, ShortYuv* resiYuv, TComYuv* reconYuv, uint32_t depthRange[2], uint8_t* sharedModes);
More information about the x265-devel
mailing list