[x265] [PATCH 1 of 3] Add optional parameter to setLambdaFromQP and calculateQpForCUSize functions
kavitha at multicorewareinc.com
kavitha at multicorewareinc.com
Wed Nov 11 16:45:15 CET 2015
# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1445610049 -19800
# Fri Oct 23 19:50:49 2015 +0530
# Node ID 8ba2a0efe283b46d6afebe1f06701df259233e14
# Parent 45ea73c63c12c66e5e5e777e80853c8b3cadf101
Add optional parameter to setLambdaFromQP and calculateQpForCUSize functions
Inaddition, the zOrder is no more passed explicitly to compressIntra/InterCU
functions, instead used implicitly from cuGeom. This commit forms groundwork
for QP based RD refinement.
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/common/constants.cpp
--- a/source/common/constants.cpp Fri Nov 06 11:55:27 2015 +0530
+++ b/source/common/constants.cpp Fri Oct 23 19:50:49 2015 +0530
@@ -555,18 +555,6 @@
0x38,
};
-/* Contains how much to increment shared depth buffer for different ctu sizes to get next best depth
- * here, depth 0 = 64x64, depth 1 = 32x32, depth 2 = 16x16 and depth 3 = 8x8
- * if ctu = 64, depth buffer size is 256 combination of depth values 0, 1, 2, 3
- * if ctu = 32, depth buffer size is 64 combination of depth values 1, 2, 3
- * if ctu = 16, depth buffer size is 16 combination of depth values 2, 3 */
-const uint32_t g_depthInc[3][4] =
-{
- { 16, 4, 0, 0},
- { 64, 16, 4, 1},
- {256, 64, 16, 4}
-};
-
/* g_depthScanIdx [y][x] */
const uint32_t g_depthScanIdx[8][8] =
{
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/common/constants.h
--- a/source/common/constants.h Fri Nov 06 11:55:27 2015 +0530
+++ b/source/common/constants.h Fri Oct 23 19:50:49 2015 +0530
@@ -96,7 +96,6 @@
// Intra tables
extern const uint8_t g_intraFilterFlags[NUM_INTRA_MODE];
-extern const uint32_t g_depthInc[3][4];
extern const uint32_t g_depthScanIdx[8][8];
}
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp Fri Nov 06 11:55:27 2015 +0530
+++ b/source/encoder/analysis.cpp Fri Oct 23 19:50:49 2015 +0530
@@ -147,7 +147,6 @@
ProfileCUScope(ctu, totalCTUTime, totalCTUs);
- uint32_t zOrder = 0;
if (m_slice->m_sliceType == I_SLICE)
{
analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame->m_analysisData.intraData;
@@ -158,7 +157,7 @@
memcpy(ctu.m_partSize, &intraDataCTU->partSizes[ctu.m_cuAddr * numPartition], sizeof(char) * numPartition);
memcpy(ctu.m_chromaIntraDir, &intraDataCTU->chromaModes[ctu.m_cuAddr * numPartition], sizeof(uint8_t) * numPartition);
}
- compressIntraCU(ctu, cuGeom, zOrder, qp);
+ compressIntraCU(ctu, cuGeom, qp);
if (m_param->analysisMode == X265_ANALYSIS_SAVE && intraDataCTU)
{
CUData* bestCU = &m_modeDepth[0].bestMode->cu;
@@ -173,7 +172,7 @@
if (m_param->bIntraRefresh && m_slice->m_sliceType == P_SLICE &&
ctu.m_cuPelX / g_maxCUSize >= frame.m_encData->m_pir.pirStartCol
&& ctu.m_cuPelX / g_maxCUSize < frame.m_encData->m_pir.pirEndCol)
- compressIntraCU(ctu, cuGeom, zOrder, qp);
+ compressIntraCU(ctu, cuGeom, qp);
else if (!m_param->rdLevel)
{
/* In RD Level 0/1, copy source pixels into the reconstructed block so
@@ -191,7 +190,7 @@
compressInterCU_rd0_4(ctu, cuGeom, qp);
else
{
- compressInterCU_rd5_6(ctu, cuGeom, zOrder, qp);
+ compressInterCU_rd5_6(ctu, cuGeom, qp);
if (m_param->analysisMode == X265_ANALYSIS_SAVE && m_frame->m_analysisData.interData)
{
CUData* bestCU = &m_modeDepth[0].bestMode->cu;
@@ -229,7 +228,7 @@
}
}
-void Analysis::compressIntraCU(const CUData& parentCTU, const CUGeom& cuGeom, uint32_t& zOrder, int32_t qp)
+void Analysis::compressIntraCU(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp)
{
uint32_t depth = cuGeom.depth;
ModeDepth& md = m_modeDepth[depth];
@@ -306,7 +305,7 @@
if (m_slice->m_pps->bUseDQP && nextDepth <= m_slice->m_pps->maxCuDQPDepth)
nextQP = setLambdaFromQP(parentCTU, calculateQpforCuSize(parentCTU, childGeom));
- compressIntraCU(parentCTU, childGeom, zOrder, nextQP);
+ compressIntraCU(parentCTU, childGeom, nextQP);
// Save best CU and pred data for this sub CU
splitCU->copyPartFrom(nd.bestMode->cu, childGeom, subPartIdx);
@@ -318,7 +317,6 @@
{
/* record the depth of this non-present sub-CU */
splitCU->setEmptyPart(childGeom, subPartIdx);
- zOrder += g_depthInc[g_maxCUDepth - 1][nextDepth];
}
}
nextContext->store(splitPred->contexts);
@@ -1285,7 +1283,7 @@
return splitCUData;
}
-SplitData Analysis::compressInterCU_rd5_6(const CUData& parentCTU, const CUGeom& cuGeom, uint32_t &zOrder, int32_t qp)
+SplitData Analysis::compressInterCU_rd5_6(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp)
{
uint32_t depth = cuGeom.depth;
ModeDepth& md = m_modeDepth[depth];
@@ -1298,7 +1296,7 @@
{
uint8_t* reuseDepth = &m_reuseInterDataCTU->depth[parentCTU.m_cuAddr * parentCTU.m_numPartitions];
uint8_t* reuseModes = &m_reuseInterDataCTU->modes[parentCTU.m_cuAddr * parentCTU.m_numPartitions];
- if (mightNotSplit && depth == reuseDepth[zOrder] && zOrder == cuGeom.absPartIdx && reuseModes[zOrder] == MODE_SKIP)
+ if (mightNotSplit && depth == reuseDepth[cuGeom.absPartIdx] && reuseModes[cuGeom.absPartIdx] == MODE_SKIP)
{
md.pred[PRED_SKIP].cu.initSubCU(parentCTU, cuGeom, qp);
md.pred[PRED_MERGE].cu.initSubCU(parentCTU, cuGeom, qp);
@@ -1310,9 +1308,6 @@
if (mightSplit)
addSplitFlagCost(*md.bestMode, cuGeom.depth);
- // increment zOrder offset to point to next best depth in sharedDepth buffer
- zOrder += g_depthInc[g_maxCUDepth - 1][reuseDepth[zOrder]];
-
mightSplit = false;
mightNotSplit = false;
}
@@ -1363,7 +1358,7 @@
if (m_slice->m_pps->bUseDQP && nextDepth <= m_slice->m_pps->maxCuDQPDepth)
nextQP = setLambdaFromQP(parentCTU, calculateQpforCuSize(parentCTU, childGeom));
- splitData[subPartIdx] = compressInterCU_rd5_6(parentCTU, childGeom, zOrder, nextQP);
+ splitData[subPartIdx] = compressInterCU_rd5_6(parentCTU, childGeom, nextQP);
// Save best CU and pred data for this sub CU
splitIntra |= nd.bestMode->cu.isIntra(0);
@@ -1375,7 +1370,6 @@
else
{
splitCU->setEmptyPart(childGeom, subPartIdx);
- zOrder += g_depthInc[g_maxCUDepth - 1][nextDepth];
}
}
nextContext->store(splitPred->contexts);
@@ -2361,10 +2355,10 @@
return false;
}
-int Analysis::calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom)
+int Analysis::calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom, double baseQp)
{
FrameData& curEncData = *m_frame->m_encData;
- double qp = curEncData.m_cuStat[ctu.m_cuAddr].baseQp;
+ double qp = baseQp < 0 ? curEncData.m_cuStat[ctu.m_cuAddr].baseQp : baseQp;
/* Use cuTree offsets if cuTree enabled and frame is referenced, else use AQ offsets */
bool isReferenced = IS_REFERENCED(m_frame);
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/encoder/analysis.h
--- a/source/encoder/analysis.h Fri Nov 06 11:55:27 2015 +0530
+++ b/source/encoder/analysis.h Fri Oct 23 19:50:49 2015 +0530
@@ -126,12 +126,12 @@
uint32_t m_splitRefIdx[4];
/* full analysis for an I-slice CU */
- void compressIntraCU(const CUData& parentCTU, const CUGeom& cuGeom, uint32_t &zOrder, int32_t qp);
+ void compressIntraCU(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp);
/* full analysis for a P or B slice CU */
uint32_t compressInterCU_dist(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp);
SplitData compressInterCU_rd0_4(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp);
- SplitData compressInterCU_rd5_6(const CUData& parentCTU, const CUGeom& cuGeom, uint32_t &zOrder, int32_t qp);
+ SplitData compressInterCU_rd5_6(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp);
/* measure merge and skip */
void checkMerge2Nx2N_rd0_4(Mode& skip, Mode& merge, const CUGeom& cuGeom);
@@ -156,7 +156,7 @@
/* generate residual and recon pixels for an entire CTU recursively (RD0) */
void encodeResidue(const CUData& parentCTU, const CUGeom& cuGeom);
- int calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom);
+ int calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom, double baseQP = -1);
/* check whether current mode is the new best */
inline void checkBestMode(Mode& mode, uint32_t depth)
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/encoder/search.cpp
--- a/source/encoder/search.cpp Fri Nov 06 11:55:27 2015 +0530
+++ b/source/encoder/search.cpp Fri Oct 23 19:50:49 2015 +0530
@@ -164,12 +164,12 @@
X265_FREE(m_tsRecon);
}
-int Search::setLambdaFromQP(const CUData& ctu, int qp)
+int Search::setLambdaFromQP(const CUData& ctu, int qp, int lambdaQp)
{
X265_CHECK(qp >= QP_MIN && qp <= QP_MAX_MAX, "QP used for lambda is out of range\n");
m_me.setQP(qp);
- m_rdCost.setQP(*m_slice, qp);
+ m_rdCost.setQP(*m_slice, lambdaQp < 0 ? qp : lambdaQp);
int quantQP = x265_clip3(QP_MIN, QP_MAX_SPEC, qp);
m_quant.setQPforQuant(ctu, quantQP);
diff -r 45ea73c63c12 -r 8ba2a0efe283 source/encoder/search.h
--- a/source/encoder/search.h Fri Nov 06 11:55:27 2015 +0530
+++ b/source/encoder/search.h Fri Oct 23 19:50:49 2015 +0530
@@ -280,7 +280,7 @@
~Search();
bool initSearch(const x265_param& param, ScalingList& scalingList);
- int setLambdaFromQP(const CUData& ctu, int qp); /* returns real quant QP in valid spec range */
+ int setLambdaFromQP(const CUData& ctu, int qp, int lambdaQP = -1); /* returns real quant QP in valid spec range */
// mark temp RD entropy contexts as uninitialized; useful for finding loads without stores
void invalidateContexts(int fromDepth);
More information about the x265-devel
mailing list