[x265] [PATCH] cabac: cleanup TEncBinCoderCABACCounter to reduce C++ feature

Min Chen chenm003 at 163.com
Sun Oct 13 05:06:13 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1381633565 -28800
# Node ID 40c806406d719e3c3253538c089df99228b9f2d6
# Parent  aef52403ed5ae19395b03157ddc49efcde234c17
cabac: cleanup TEncBinCoderCABACCounter to reduce C++ feature

diff -r aef52403ed5a -r 40c806406d71 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	Sun Oct 13 11:06:05 2013 +0800
@@ -43,10 +43,11 @@
 //! \ingroup TLibEncoder
 //! \{
 
-TEncBinCABAC::TEncBinCABAC()
+TEncBinCABAC::TEncBinCABAC(bool isCounter)
     : m_pcTComBitIf(0)
     , m_binCountIncrement(0)
     , m_fracBits(0)
+    , bIsCounter(isCounter)
 {}
 
 TEncBinCABAC::~TEncBinCABAC()
@@ -73,6 +74,14 @@
 
 void TEncBinCABAC::finish()
 {
+    if (bIsCounter)
+    {
+        // 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 (bIsCounter)
+        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 (bIsCounter)
+    {
+        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 (bIsCounter)
+    {
+        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 (bIsCounter)
+    {
+        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 (bIsCounter)
+    {
+        m_fracBits += ContextModel::getEntropyBitsTrm(binValue);
+        return;
+    }
+
     m_uiRange -= 2;
     if (binValue)
     {
diff -r aef52403ed5a -r 40c806406d71 source/Lib/TLibEncoder/TEncBinCoderCABAC.h
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.h	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.h	Sun Oct 13 11:06:05 2013 +0800
@@ -50,7 +50,7 @@
 {
 public:
 
-    TEncBinCABAC();
+    TEncBinCABAC(bool isCounter = false);
     virtual ~TEncBinCABAC();
 
     void  init(TComBitIf* pcTComBitIf);
@@ -98,6 +98,7 @@
     UInt                m_uiBinsCoded;
     int                 m_binCountIncrement;
     UInt64              m_fracBits;
+    bool                bIsCounter;
 };
 }
 //! \}
diff -r aef52403ed5a -r 40c806406d71 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Sun Oct 13 11:06:05 2013 +0800
@@ -497,16 +497,16 @@
 
     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(true);
             m_rdSbacCoders[d][ciIdx]->init(m_binCoderCABAC[d][ciIdx]);
         }
     }
diff -r aef52403ed5a -r 40c806406d71 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	Sun Oct 13 11:06:05 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 aef52403ed5a -r 40c806406d71 source/Lib/TLibEncoder/TEncSbac.h
--- a/source/Lib/TLibEncoder/TEncSbac.h	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSbac.h	Sun Oct 13 11:06:05 2013 +0800
@@ -45,7 +45,6 @@
 #include "TEncEntropy.h"
 #include "TEncBinCoder.h"
 #include "TEncBinCoderCABAC.h"
-#include "TEncBinCoderCABACCounter.h"
 
 namespace x265 {
 // private namespace
diff -r aef52403ed5a -r 40c806406d71 source/encoder/CMakeLists.txt
--- a/source/encoder/CMakeLists.txt	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/encoder/CMakeLists.txt	Sun Oct 13 11:06:05 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 aef52403ed5a -r 40c806406d71 source/encoder/cturow.cpp
--- a/source/encoder/cturow.cpp	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/encoder/cturow.cpp	Sun Oct 13 11:06:05 2013 +0800
@@ -36,17 +36,17 @@
     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(true);
             m_rdSbacCoders[depth][ciIdx]->init(m_binCodersCABAC[depth][ciIdx]);
         }
     }
diff -r aef52403ed5a -r 40c806406d71 source/encoder/cturow.h
--- a/source/encoder/cturow.h	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/encoder/cturow.h	Sun Oct 13 11:06:05 2013 +0800
@@ -44,12 +44,13 @@
 class CTURow
 {
 public:
+    CTURow() : m_rdGoOnBinCodersCABAC(true) {}
 
     TEncSbac               m_sbacCoder;
     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 +58,7 @@
     TEncCu                 m_cuCoder;
     TComTrQuant            m_trQuant;
     TEncSbac            ***m_rdSbacCoders;
-    TEncBinCABACCounter ***m_binCodersCABAC;
+    TEncBinCABAC        ***m_binCodersCABAC;
 
     void create(Encoder* top);
 
diff -r aef52403ed5a -r 40c806406d71 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/encoder/framefilter.cpp	Sun Oct 13 11:06:05 2013 +0800
@@ -35,6 +35,7 @@
 FrameFilter::FrameFilter()
     : m_cfg(NULL)
     , m_pic(NULL)
+    , m_rdGoOnBinCodersCABAC(true)
 {
 }
 
@@ -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 aef52403ed5a -r 40c806406d71 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Sat Oct 12 13:40:55 2013 +0530
+++ b/source/encoder/framefilter.h	Sun Oct 13 11:06:05 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