[x265] [PATCH 4 of 4] entropy: clarify the SBac's bit counting mode
Steve Borho
steve at borho.org
Fri Jul 11 02:30:32 CEST 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1405038586 18000
# Thu Jul 10 19:29:46 2014 -0500
# Node ID e3e077965c39a56a24e09189652e1de3c5a0e3ea
# Parent e658be3fe5a3cdcdb1b3ac21c6b795b5d01c69a0
entropy: clarify the SBac's bit counting mode
The SBac class has always had the ability to be a bit counter without any other
external data structures. With this change, the SBac defaults to being a bit
counting SBac until it is given a Bitstream object to write into. The class
no longer accepts a BitCounter object, since it would only add more overhead
to the bit counting.
TEncCu no longer needs o be told whether it is writing into a bit counting
SBac or not, it can ask the SBac to find out.
The BitCounting class is only used for SEI writing, and may disappear in order
to remove the vtable from the critical path of entropy coding.
diff -r e658be3fe5a3 -r e3e077965c39 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp Thu Jul 10 17:52:35 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncCu.cpp Thu Jul 10 19:29:46 2014 -0500
@@ -75,7 +75,6 @@
m_rdCost = NULL;
m_sbacCoder = NULL;
m_rdSbacCoders = NULL;
- m_bBitCounting = false;
}
/**
@@ -422,13 +421,12 @@
/** \param cu pointer of CU data class
*/
-void TEncCu::encodeCU(TComDataCU* cu, bool bIsCounting)
+void TEncCu::encodeCU(TComDataCU* cu)
{
if (cu->getSlice()->getPPS()->getUseDQP())
m_bEncodeDQP = true;
// Encode CU data
- m_bBitCounting = bIsCounting;
xEncodeCU(cu, 0, 0, false);
}
@@ -1072,19 +1070,15 @@
}
int numberOfWrittenBits = 0;
- if (m_bBitCounting)
- {
+ if (m_sbacCoder->isBitCounter())
numberOfWrittenBits = m_sbacCoder->getNumberOfWrittenBits();
- }
if (granularityBoundary)
{
slice->setSliceBits((uint32_t)(slice->getSliceBits() + numberOfWrittenBits));
slice->setSliceSegmentBits(slice->getSliceSegmentBits() + numberOfWrittenBits);
- if (m_bBitCounting)
- {
+ if (m_sbacCoder->isBitCounter())
m_sbacCoder->resetBits();
- }
}
}
diff -r e658be3fe5a3 -r e3e077965c39 source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h Thu Jul 10 17:52:35 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncCu.h Thu Jul 10 19:29:46 2014 -0500
@@ -120,7 +120,6 @@
TComTrQuant* m_trQuant;
RDCost* m_rdCost;
SBac* m_sbacCoder;
- bool m_bBitCounting;
// RD SBac pointers
SBac (*m_rdSbacCoders)[CI_NUM];
@@ -139,7 +138,7 @@
bool create(uint8_t totalDepth, uint32_t maxWidth);
void destroy();
void compressCU(TComDataCU* cu);
- void encodeCU(TComDataCU* cu, bool bIsCounting);
+ void encodeCU(TComDataCU* cu);
protected:
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/cturow.cpp
--- a/source/encoder/cturow.cpp Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/cturow.cpp Thu Jul 10 19:29:46 2014 -0500
@@ -72,17 +72,13 @@
tld.m_cuCoder.m_sbacCoder = &m_sbacCoder;
tld.m_cuCoder.m_rdSbacCoders = m_rdSbacCoders;
- BitCounter bc;
- m_sbacCoder.setBitstream(&bc);
-
tld.m_cuCoder.compressCU(cu); // Does all the CU analysis
tld.m_search.m_sbacCoder = &m_rdSbacCoders[0][CI_CURR_BEST];
tld.m_cuCoder.m_sbacCoder = &m_rdSbacCoders[0][CI_CURR_BEST];
- m_rdSbacCoders[0][CI_CURR_BEST].setBitstream(&bc);
- bc.resetBits();
+ m_rdSbacCoders[0][CI_CURR_BEST].resetBits();
- tld.m_cuCoder.encodeCU(cu, true); // Count bits
+ tld.m_cuCoder.encodeCU(cu);
if (bSaveSBac)
// Save CABAC state for next row
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/cturow.h
--- a/source/encoder/cturow.h Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/cturow.h Thu Jul 10 19:29:46 2014 -0500
@@ -72,14 +72,6 @@
double m_pCuCnt;
double m_skipCuCnt;
- CTURow()
- {
- m_sbacCoder.m_bIsCounter = true;
- for (uint32_t depth = 0; depth < g_maxCUDepth + 1; depth++)
- for (int ciIdx = 0; ciIdx < CI_NUM; ciIdx++)
- m_rdSbacCoders[depth][ciIdx].m_bIsCounter = true;
- }
-
void init(TComSlice *slice)
{
m_active = 0;
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/entropy.cpp Thu Jul 10 19:29:46 2014 -0500
@@ -63,7 +63,6 @@
SBac::SBac()
: m_fracBits(0)
- , m_bIsCounter(false)
{
memset(m_contextModels, 0, sizeof(m_contextModels));
}
@@ -2503,14 +2502,6 @@
void SBac::finish()
{
- if (m_bIsCounter)
- {
- // TODO: why write 0 bits?
- m_bitIf->write(0, uint32_t(m_fracBits >> 15));
- m_fracBits &= 32767;
- X265_CHECK(0, "should not get here\n");
- }
-
if (m_low >> (21 + m_bitsLeft))
{
m_bitIf->writeByte(m_bufferedByte + 1);
@@ -2563,7 +2554,8 @@
m_numBufferedBytes = 0;
m_bufferedByte = 0xff;
m_fracBits &= 32767;
- m_bitIf->resetBits();
+ if (m_bitIf)
+ m_bitIf->resetBits();
}
/** Encode bin */
@@ -2573,7 +2565,7 @@
ctxModel.m_state = sbacNext(mstate, binValue);
- if (m_bIsCounter)
+ if (!m_bitIf)
{
m_fracBits += sbacGetEntropyBits(mstate, binValue);
return;
@@ -2619,7 +2611,7 @@
/** Encode equiprobable bin */
void SBac::encodeBinEP(uint32_t binValue)
{
- if (m_bIsCounter)
+ if (!m_bitIf)
{
m_fracBits += 32768;
return;
@@ -2636,7 +2628,7 @@
/** Encode equiprobable bins */
void SBac::encodeBinsEP(uint32_t binValues, int numBins)
{
- if (m_bIsCounter)
+ if (!m_bitIf)
{
m_fracBits += 32768 * numBins;
return;
@@ -2666,7 +2658,7 @@
/** Encode terminating bin */
void SBac::encodeBinTrm(uint32_t binValue)
{
- if (m_bIsCounter)
+ if (!m_bitIf)
{
m_fracBits += sbacGetEntropyBitsTrm(binValue);
return;
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/entropy.h
--- a/source/encoder/entropy.h Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/entropy.h Thu Jul 10 19:29:46 2014 -0500
@@ -98,15 +98,15 @@
int m_numBufferedBytes;
int m_bitsLeft;
uint64_t m_fracBits;
- bool m_bIsCounter;
SBac();
- void setBitstream(BitInterface* p) { m_bitIf = p; }
+ void setBitstream(Bitstream* p) { m_bitIf = p; }
+ bool isBitCounter() const { return !m_bitIf; }
uint32_t getNumberOfWrittenBits()
{
- X265_CHECK(m_bIsCounter && !m_bitIf->getNumberOfWrittenBits(), "counter mode expected\n");
+ X265_CHECK(!m_bitIf, "bit counting mode expected\n");
return uint32_t(m_fracBits >> 15);
}
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/frameencoder.cpp Thu Jul 10 19:29:46 2014 -0500
@@ -661,7 +661,7 @@
// final coding (bitstream generation) for this CU
m_tld.m_search.m_sbacCoder = &m_sbacCoder;
m_tld.m_cuCoder.m_sbacCoder = &m_sbacCoder;
- m_tld.m_cuCoder.encodeCU(cu, false);
+ m_tld.m_cuCoder.encodeCU(cu);
// load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
m_rows[subStrm].m_rowEntropyCoder.load(m_sbacCoder);
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/framefilter.cpp Thu Jul 10 19:29:46 2014 -0500
@@ -39,7 +39,6 @@
, m_frame(NULL)
, m_ssimBuf(NULL)
{
- m_sbacCoder.m_bIsCounter = true;
}
void FrameFilter::destroy()
@@ -90,7 +89,6 @@
m_pic = pic;
m_saoRowDelay = m_param->bEnableLoopFilter ? 1 : 0;
- m_sbacCoder.setBitstream(&m_bitCounter);
m_sbacCoder.zeroFract();
if (m_param->bEnableSAO)
diff -r e658be3fe5a3 -r e3e077965c39 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h Thu Jul 10 17:52:35 2014 -0500
+++ b/source/encoder/framefilter.h Thu Jul 10 19:29:46 2014 -0500
@@ -72,7 +72,6 @@
// SAO
SBac m_sbacCoder;
- BitCounter m_bitCounter;
SBac* m_sbacCoderRow0; // to mimic HM behavior
/* Temp storage for ssim computation that doesn't need repeated malloc */
More information about the x265-devel
mailing list