[x265] [PATCH] cabac: cleanup TEncBinCoderCABACCounter to reduce C++ feature
Min Chen
chenm003 at 163.com
Sat Oct 12 10:10:34 CEST 2013
# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1381565425 -28800
# Node ID e5778c8db6af3cc61e1affc600324a93df57a11b
# Parent 9a02765f182e9da2924113f7e712abf3ea22759f
cabac: cleanup TEncBinCoderCABACCounter to reduce C++ feature
diff -r 9a02765f182e -r e5778c8db6af source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp Fri Oct 11 23:41:41 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp Sat Oct 12 16:10:25 2013 +0800
@@ -47,6 +47,7 @@
: m_pcTComBitIf(0)
, m_binCountIncrement(0)
, m_fracBits(0)
+ , m_isCounter(false)
{}
TEncBinCABAC::~TEncBinCABAC()
@@ -73,6 +74,14 @@
void TEncBinCABAC::finish()
{
+ if (m_isCounter)
+ {
+ // TODO: why write 0 bits?
+ m_pcTComBitIf->write(0, UInt(m_fracBits >> 15));
+ m_fracBits &= 32767;
+ assert(0);
+ }
+
if (m_uiLow >> (32 - m_bitsLeft))
{
//assert( m_numBufferedBytes > 0 );
@@ -166,7 +175,10 @@
UInt TEncBinCABAC::getNumWrittenBits()
{
- return m_pcTComBitIf->getNumberOfWrittenBits() + 8 * m_numBufferedBytes + 23 - m_bitsLeft;
+ if (m_isCounter)
+ return m_pcTComBitIf->getNumberOfWrittenBits() + UInt(m_fracBits >> 15);
+ else
+ return m_pcTComBitIf->getNumberOfWrittenBits() + 8 * m_numBufferedBytes + 23 - m_bitsLeft;
}
/**
@@ -186,6 +198,12 @@
DTRACE_CABAC_T("\n")
}
m_uiBinsCoded += m_binCountIncrement;
+ if (m_isCounter)
+ {
+ m_fracBits += rcCtxModel.getEntropyBits(binValue);
+ rcCtxModel.update(binValue);
+ return;
+ }
rcCtxModel.setBinsCoded(1);
UInt uiLPS = g_lpsTable[rcCtxModel.getState()][(m_uiRange >> 6) & 3];
@@ -230,6 +248,11 @@
DTRACE_CABAC_T("\n")
}
m_uiBinsCoded += m_binCountIncrement;
+ if (m_isCounter)
+ {
+ m_fracBits += 32768;
+ return;
+ }
m_uiLow <<= 1;
if (binValue)
{
@@ -249,6 +272,11 @@
void TEncBinCABAC::encodeBinsEP(UInt binValues, int numBins)
{
m_uiBinsCoded += numBins & - m_binCountIncrement;
+ if (m_isCounter)
+ {
+ m_fracBits += 32768 * numBins;
+ return;
+ }
for (int i = 0; i < numBins; i++)
{
@@ -285,6 +313,12 @@
void TEncBinCABAC::encodeBinTrm(UInt binValue)
{
m_uiBinsCoded += m_binCountIncrement;
+ if (m_isCounter)
+ {
+ m_fracBits += ContextModel::getEntropyBitsTrm(binValue);
+ return;
+ }
+
m_uiRange -= 2;
if (binValue)
{
diff -r 9a02765f182e -r e5778c8db6af source/Lib/TLibEncoder/TEncBinCoderCABAC.h
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.h Fri Oct 11 23:41:41 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.h Sat Oct 12 16:10:25 2013 +0800
@@ -98,6 +98,7 @@
UInt m_uiBinsCoded;
int m_binCountIncrement;
UInt64 m_fracBits;
+ bool m_isCounter;
};
}
//! \}
diff -r 9a02765f182e -r e5778c8db6af source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp Fri Oct 11 23:41:41 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp Sat Oct 12 16:10:25 2013 +0800
@@ -497,16 +497,17 @@
int maxDepth = 4;
m_rdSbacCoders = new TEncSbac * *[maxDepth + 1];
- m_binCoderCABAC = new TEncBinCABACCounter * *[maxDepth + 1];
+ m_binCoderCABAC = new TEncBinCABAC * *[maxDepth + 1];
for (int d = 0; d < maxDepth + 1; d++)
{
m_rdSbacCoders[d] = new TEncSbac*[CI_NUM];
- m_binCoderCABAC[d] = new TEncBinCABACCounter*[CI_NUM];
+ m_binCoderCABAC[d] = new TEncBinCABAC*[CI_NUM];
for (int ciIdx = 0; ciIdx < CI_NUM; ciIdx++)
{
m_rdSbacCoders[d][ciIdx] = new TEncSbac;
- m_binCoderCABAC[d][ciIdx] = new TEncBinCABACCounter;
+ m_binCoderCABAC[d][ciIdx] = new TEncBinCABAC;
+ m_binCoderCABAC[d][ciIdx]->m_isCounter = true;
m_rdSbacCoders[d][ciIdx]->init(m_binCoderCABAC[d][ciIdx]);
}
}
diff -r 9a02765f182e -r e5778c8db6af source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h Fri Oct 11 23:41:41 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h Sat Oct 12 16:10:25 2013 +0800
@@ -63,7 +63,7 @@
TEncEntropy* m_entropyCoder;
TEncSbac*** m_rdSbacCoders; ///< for CABAC
TEncSbac* m_rdGoOnSbacCoder;
- TEncBinCABACCounter*** m_binCoderCABAC; ///< temporal CABAC state storage for RD computation
+ TEncBinCABAC*** m_binCoderCABAC; ///< temporal CABAC state storage for RD computation
Int64 ***m_count; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
Int64 ***m_offset; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
diff -r 9a02765f182e -r e5778c8db6af source/Lib/TLibEncoder/TEncSbac.h
--- a/source/Lib/TLibEncoder/TEncSbac.h Fri Oct 11 23:41:41 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncSbac.h Sat Oct 12 16:10:25 2013 +0800
@@ -45,7 +45,6 @@
#include "TEncEntropy.h"
#include "TEncBinCoder.h"
#include "TEncBinCoderCABAC.h"
-#include "TEncBinCoderCABACCounter.h"
namespace x265 {
// private namespace
diff -r 9a02765f182e -r e5778c8db6af source/encoder/CMakeLists.txt
--- a/source/encoder/CMakeLists.txt Fri Oct 11 23:41:41 2013 -0500
+++ b/source/encoder/CMakeLists.txt Sat Oct 12 16:10:25 2013 +0800
@@ -17,7 +17,6 @@
../Lib/TLibEncoder/TEncAnalyze.h
../Lib/TLibEncoder/TEncBinCoder.h
../Lib/TLibEncoder/TEncBinCoderCABAC.h
- ../Lib/TLibEncoder/TEncBinCoderCABACCounter.h
../Lib/TLibEncoder/TEncCavlc.h
../Lib/TLibEncoder/TEncCfg.h
../Lib/TLibEncoder/TEncCu.h
@@ -31,7 +30,6 @@
../Lib/TLibEncoder/SEIwrite.cpp
../Lib/TLibEncoder/SyntaxElementWriter.cpp
../Lib/TLibEncoder/TEncBinCoderCABAC.cpp
- ../Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp
../Lib/TLibEncoder/TEncCavlc.cpp
../Lib/TLibEncoder/TEncCu.cpp
../Lib/TLibEncoder/TEncEntropy.cpp
diff -r 9a02765f182e -r e5778c8db6af source/encoder/cturow.cpp
--- a/source/encoder/cturow.cpp Fri Oct 11 23:41:41 2013 -0500
+++ b/source/encoder/cturow.cpp Sat Oct 12 16:10:25 2013 +0800
@@ -31,22 +31,24 @@
void CTURow::create(Encoder* top)
{
+ m_rdGoOnBinCodersCABAC.m_isCounter = true;
m_rdGoOnSbacCoder.init(&m_rdGoOnBinCodersCABAC);
m_sbacCoder.init(&m_binCoderCABAC);
m_trQuant.init(1 << top->getQuadtreeTULog2MaxSize(), top->param.bEnableRDOQ, top->param.bEnableRDOQTS, top->param.bEnableTSkipFast);
m_rdSbacCoders = new TEncSbac **[g_maxCUDepth + 1];
- m_binCodersCABAC = new TEncBinCABACCounter **[g_maxCUDepth + 1];
+ m_binCodersCABAC = new TEncBinCABAC **[g_maxCUDepth + 1];
for (UInt depth = 0; depth < g_maxCUDepth + 1; depth++)
{
m_rdSbacCoders[depth] = new TEncSbac*[CI_NUM];
- m_binCodersCABAC[depth] = new TEncBinCABACCounter*[CI_NUM];
+ m_binCodersCABAC[depth] = new TEncBinCABAC*[CI_NUM];
for (int ciIdx = 0; ciIdx < CI_NUM; ciIdx++)
{
m_rdSbacCoders[depth][ciIdx] = new TEncSbac;
- m_binCodersCABAC[depth][ciIdx] = new TEncBinCABACCounter;
+ m_binCodersCABAC[depth][ciIdx] = new TEncBinCABAC;
+ m_binCodersCABAC[depth][ciIdx]->m_isCounter = true;
m_rdSbacCoders[depth][ciIdx]->init(m_binCodersCABAC[depth][ciIdx]);
}
}
diff -r 9a02765f182e -r e5778c8db6af source/encoder/cturow.h
--- a/source/encoder/cturow.h Fri Oct 11 23:41:41 2013 -0500
+++ b/source/encoder/cturow.h Sat Oct 12 16:10:25 2013 +0800
@@ -49,7 +49,7 @@
TEncSbac m_rdGoOnSbacCoder;
TEncSbac m_bufferSbacCoder;
TEncBinCABAC m_binCoderCABAC;
- TEncBinCABACCounter m_rdGoOnBinCodersCABAC;
+ TEncBinCABAC m_rdGoOnBinCodersCABAC;
TComBitCounter m_bitCounter;
TComRdCost m_rdCost;
TEncEntropy m_entropyCoder;
@@ -57,7 +57,7 @@
TEncCu m_cuCoder;
TComTrQuant m_trQuant;
TEncSbac ***m_rdSbacCoders;
- TEncBinCABACCounter ***m_binCodersCABAC;
+ TEncBinCABAC ***m_binCodersCABAC;
void create(Encoder* top);
diff -r 9a02765f182e -r e5778c8db6af source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp Fri Oct 11 23:41:41 2013 -0500
+++ b/source/encoder/framefilter.cpp Sat Oct 12 16:10:25 2013 +0800
@@ -82,6 +82,7 @@
m_saoRowDelay = m_cfg->param.bEnableLoopFilter ? 1 : 0;
m_loopFilter.setCfg(pic->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag());
+ m_rdGoOnBinCodersCABAC.m_isCounter = true;
m_rdGoOnSbacCoder.init(&m_rdGoOnBinCodersCABAC);
m_entropyCoder.setEntropyCoder(&m_rdGoOnSbacCoder, pic->getSlice());
m_entropyCoder.setBitstream(&m_bitCounter);
@@ -128,7 +129,7 @@
if (row == 0 && m_cfg->param.bEnableSAO)
{
// NOTE: not need, seems HM's bug, I want to keep output exact matched.
- m_rdGoOnBinCodersCABAC.m_fracBits = ((TEncBinCABACCounter*)((TEncSbac*)m_rdGoOnSbacCoderRow0->m_pcBinIf))->m_fracBits;
+ m_rdGoOnBinCodersCABAC.m_fracBits = ((TEncBinCABAC*)((TEncSbac*)m_rdGoOnSbacCoderRow0->m_pcBinIf))->m_fracBits;
m_sao.startSaoEnc(m_pic, &m_entropyCoder, &m_rdGoOnSbacCoder);
}
diff -r 9a02765f182e -r e5778c8db6af source/encoder/framefilter.h
--- a/source/encoder/framefilter.h Fri Oct 11 23:41:41 2013 -0500
+++ b/source/encoder/framefilter.h Sat Oct 12 16:10:25 2013 +0800
@@ -69,7 +69,7 @@
// SAO
TEncEntropy m_entropyCoder;
TEncSbac m_rdGoOnSbacCoder;
- TEncBinCABACCounter m_rdGoOnBinCodersCABAC;
+ TEncBinCABAC m_rdGoOnBinCodersCABAC;
TComBitCounter m_bitCounter;
TEncSbac* m_rdGoOnSbacCoderRow0; // for bitstream exact only, depends on HM's bug
};
More information about the x265-devel
mailing list