[x265] [PATCH 1 of 2] entropy: add methods to estimate CU mode decision costs
Steve Borho
steve at borho.org
Thu Dec 11 21:55:47 CET 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1418327554 21600
# Thu Dec 11 13:52:34 2014 -0600
# Node ID a0bf346f31760598e327c218ef2b81c5cfad3f55
# Parent ae50be4c3a6e725e1b3400faf3bfcd109ebfc1e8
entropy: add methods to estimate CU mode decision costs
diff -r ae50be4c3a6e -r a0bf346f3176 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp Wed Dec 10 23:55:42 2014 -0600
+++ b/source/encoder/entropy.cpp Thu Dec 11 13:52:34 2014 -0600
@@ -587,6 +587,54 @@
finishCU(ctu, absPartIdx, depth);
}
+/* Return bit count of signaling inter mode */
+uint32_t Entropy::bitsInterMode(const CUData& cu, uint32_t absPartIdx, uint32_t depth) const
+{
+ uint32_t bits;
+ bits = bitsCodeBin(0, m_contextState[OFF_SKIP_FLAG_CTX + cu.getCtxSkipFlag(absPartIdx)]); /* not skip */
+ bits += bitsCodeBin(0, m_contextState[OFF_PRED_MODE_CTX]); /* inter */
+ PartSize partSize = (PartSize)cu.m_partSize[absPartIdx];
+ switch (partSize)
+ {
+ case SIZE_2Nx2N:
+ bits += bitsCodeBin(1, m_contextState[OFF_PART_SIZE_CTX]);
+ break;
+
+ case SIZE_2NxN:
+ case SIZE_2NxnU:
+ case SIZE_2NxnD:
+ bits += bitsCodeBin(0, m_contextState[OFF_PART_SIZE_CTX + 0]);
+ bits += bitsCodeBin(1, m_contextState[OFF_PART_SIZE_CTX + 1]);
+ if (cu.m_slice->m_sps->maxAMPDepth > depth)
+ {
+ bits += bitsCodeBin((partSize == SIZE_2NxN) ? 1 : 0, m_contextState[OFF_PART_SIZE_CTX + 3]);
+ if (partSize != SIZE_2NxN)
+ bits++; // encodeBinEP((partSize == SIZE_2NxnU ? 0 : 1));
+ }
+ break;
+
+ case SIZE_Nx2N:
+ case SIZE_nLx2N:
+ case SIZE_nRx2N:
+ bits += bitsCodeBin(0, m_contextState[OFF_PART_SIZE_CTX + 0]);
+ bits += bitsCodeBin(0, m_contextState[OFF_PART_SIZE_CTX + 1]);
+ if (depth == g_maxCUDepth && !(cu.m_log2CUSize[absPartIdx] == 3))
+ bits += bitsCodeBin(1, m_contextState[OFF_PART_SIZE_CTX + 2]);
+ if (cu.m_slice->m_sps->maxAMPDepth > depth)
+ {
+ bits += bitsCodeBin((partSize == SIZE_Nx2N) ? 1 : 0, m_contextState[OFF_PART_SIZE_CTX + 3]);
+ if (partSize != SIZE_Nx2N)
+ bits++; // encodeBinEP((partSize == SIZE_nLx2N ? 0 : 1));
+ }
+ break;
+ default:
+ X265_CHECK(0, "invalid CU partition\n");
+ break;
+ }
+
+ return bits;
+}
+
/* finish encoding a cu and handle end-of-slice conditions */
void Entropy::finishCU(const CUData& ctu, uint32_t absPartIdx, uint32_t depth)
{
diff -r ae50be4c3a6e -r a0bf346f3176 source/encoder/entropy.h
--- a/source/encoder/entropy.h Wed Dec 10 23:55:42 2014 -0600
+++ b/source/encoder/entropy.h Thu Dec 11 13:52:34 2014 -0600
@@ -192,6 +192,12 @@
inline uint32_t bitsIntraModeNonMPM() const { return bitsCodeBin(0, m_contextState[OFF_ADI_CTX]) + 5; }
inline uint32_t bitsIntraModeMPM(const uint32_t preds[3], uint32_t dir) const { return bitsCodeBin(1, m_contextState[OFF_ADI_CTX]) + (dir == preds[0] ? 1 : 2); }
inline uint32_t estimateCbfBits(uint32_t cbf, TextType ttype, uint32_t tuDepth) const { return bitsCodeBin(cbf, m_contextState[OFF_QT_CBF_CTX + ctxCbf[ttype][tuDepth]]); }
+ uint32_t bitsInterMode(const CUData& cu, uint32_t absPartIdx, uint32_t depth) const;
+ uint32_t bitsIntraMode(const CUData& cu, uint32_t absPartIdx) const
+ {
+ return bitsCodeBin(0, m_contextState[OFF_SKIP_FLAG_CTX + cu.getCtxSkipFlag(absPartIdx)]) + /* not skip */
+ bitsCodeBin(1, m_contextState[OFF_PRED_MODE_CTX]); /* intra */
+ }
/* these functions are only used to estimate the bits when cbf is 0 and will never be called when writing the bistream. */
inline void codeQtRootCbfZero() { encodeBin(0, m_contextState[OFF_QT_ROOT_CBF_CTX]); }
More information about the x265-devel
mailing list