[x265] [PATCH 1 of 3] bring SyntaxElementWriter into common/, remove trace file macros

Steve Borho steve at borho.org
Thu Jul 10 23:43:59 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1405018759 18000
#      Thu Jul 10 13:59:19 2014 -0500
# Node ID 64dc40d52519b0bcb19c04cf14d510243ff846fb
# Parent  cbfe2ac89d418f7cf9cc53ad31b7eb2c06fbcb85
bring SyntaxElementWriter into common/, remove trace file macros

File tracing has been essentially broken since frame parallelism was introduced
(not to mention multiple encoder instances in a process) and is going to be
soon even more impossible when the second encodeCU() pass is removed. It's best
to remove this old HM feature so people don't get stuck trying to use it.

Stream analyzers like Parabola and Elecard are now mature enough that these
trace files are not very helpful. If you *really* want the old style trace
file, enable tracing in the HM decoder and decode your bitstream with it.

I left the strings in the WRITE_* macros in place because they make those calls
reasonably self-documenting. The compiler will throw them away harmlessly.

diff -r cbfe2ac89d41 -r 64dc40d52519 source/Lib/TLibCommon/TComRom.cpp
--- a/source/Lib/TLibCommon/TComRom.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComRom.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -459,21 +459,8 @@
 const uint8_t g_chroma422IntraAngleMappingTable[36] =
 { 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31, DM_CHROMA_IDX };
 
-// ====================================================================================================================
-// Misc.
-// ====================================================================================================================
-
 uint8_t g_convertToBit[MAX_CU_SIZE + 1];
 
-#if ENC_DEC_TRACE
-FILE*  g_hTrace = NULL;
-const bool g_bEncDecTraceEnable  = true;
-const bool g_bEncDecTraceDisable = false;
-bool   g_HLSTraceEnable = true;
-bool   g_bJustDoIt = false;
-uint64_t g_nSymbolCounter = 0;
-#endif
-
 // ====================================================================================================================
 // Scanning order & context model mapping
 // ====================================================================================================================
diff -r cbfe2ac89d41 -r 64dc40d52519 source/Lib/TLibCommon/TComRom.h
--- a/source/Lib/TLibCommon/TComRom.h	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/Lib/TLibCommon/TComRom.h	Thu Jul 10 13:59:19 2014 -0500
@@ -157,40 +157,6 @@
 
 extern uint8_t g_convertToBit[MAX_CU_SIZE + 1]; // from width to log2(width)-2
 
-#ifndef ENC_DEC_TRACE
-# define ENC_DEC_TRACE 0
-#endif
-
-#if ENC_DEC_TRACE
-extern FILE*  g_hTrace;
-extern bool   g_bJustDoIt;
-extern const bool g_bEncDecTraceEnable;
-extern const bool g_bEncDecTraceDisable;
-extern bool   g_HLSTraceEnable;
-extern uint64_t g_nSymbolCounter;
-
-#define COUNTER_START    1
-#define COUNTER_END      0 //( uint64_t(1) << 63 )
-
-#define DTRACE_CABAC_F(x)     if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "%f", x);
-#define DTRACE_CABAC_V(x)     if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "%d", x);
-#define DTRACE_CABAC_VL(x)    if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "%ld", x);
-#define DTRACE_CABAC_T(x)     if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "%s", x);
-#define DTRACE_CABAC_X(x)     if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "%x", x);
-#define DTRACE_CABAC_R(x, y)  if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, x,    y);
-#define DTRACE_CABAC_N        if ((g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END) || g_bJustDoIt) fprintf(g_hTrace, "\n");
-#else // if ENC_DEC_TRACE
-
-#define DTRACE_CABAC_F(x)
-#define DTRACE_CABAC_V(x)
-#define DTRACE_CABAC_VL(x)
-#define DTRACE_CABAC_T(x)
-#define DTRACE_CABAC_X(x)
-#define DTRACE_CABAC_R(x, y)
-#define DTRACE_CABAC_N
-
-#endif // if ENC_DEC_TRACE
-
 #define SCALING_LIST_NUM 6         ///< list number for quantization matrix
 #define SCALING_LIST_NUM_32x32 2   ///< list number for quantization matrix 32x32
 #define SCALING_LIST_REM_NUM 6     ///< remainder of QP/6
diff -r cbfe2ac89d41 -r 64dc40d52519 source/Lib/TLibEncoder/SyntaxElementWriter.cpp
--- a/source/Lib/TLibEncoder/SyntaxElementWriter.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
- *    be used to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** \file     SyntaxElementWriter.cpp
-    \brief    CAVLC encoder class
-*/
-
-#include "common.h"
-#include "SyntaxElementWriter.h"
-
-using namespace x265;
-
-//! \ingroup TLibEncoder
-//! \{
-
-#if ENC_DEC_TRACE
-
-void  SyntaxElementWriter::xWriteCodeTr(uint32_t value, uint32_t  length, const char *symbolName)
-{
-    xWriteCode(value, length);
-    if (g_HLSTraceEnable)
-    {
-        fprintf(g_hTrace, "%8ld  ", g_nSymbolCounter++);
-        if (length < 10)
-        {
-            fprintf(g_hTrace, "%-50s u(%d)  : %d\n", symbolName, length, value);
-        }
-        else
-        {
-            fprintf(g_hTrace, "%-50s u(%d) : %d\n", symbolName, length, value);
-        }
-    }
-}
-
-void  SyntaxElementWriter::xWriteUvlcTr(uint32_t value, const char *symbolName)
-{
-    xWriteUvlc(value);
-    if (g_HLSTraceEnable)
-    {
-        fprintf(g_hTrace, "%8ld  ", g_nSymbolCounter++);
-        fprintf(g_hTrace, "%-50s ue(v) : %d\n", symbolName, value);
-    }
-}
-
-void  SyntaxElementWriter::xWriteSvlcTr(int value, const char *symbolName)
-{
-    xWriteSvlc(value);
-    if (g_HLSTraceEnable)
-    {
-        fprintf(g_hTrace, "%8ld  ", g_nSymbolCounter++);
-        fprintf(g_hTrace, "%-50s se(v) : %d\n", symbolName, value);
-    }
-}
-
-void  SyntaxElementWriter::xWriteFlagTr(uint32_t value, const char *symbolName)
-{
-    xWriteFlag(value);
-    if (g_HLSTraceEnable)
-    {
-        fprintf(g_hTrace, "%8ld  ", g_nSymbolCounter++);
-        fprintf(g_hTrace, "%-50s u(1)  : %d\n", symbolName, value);
-    }
-}
-
-#endif // if ENC_DEC_TRACE
-
-void SyntaxElementWriter::xWriteCode(uint32_t code, uint32_t len)
-{
-    X265_CHECK(len, "wrote zero length code\n");
-    m_bitIf->write(code, len);
-}
-
-void SyntaxElementWriter::xWriteUvlc(uint32_t code)
-{
-    uint32_t len = 1;
-    uint32_t temp = ++code;
-
-    X265_CHECK(temp, "writing -1 code\n");
-
-    while (1 != temp)
-    {
-        temp >>= 1;
-        len += 2;
-    }
-
-    // Take care of cases where len > 32
-    m_bitIf->write(0, len >> 1);
-    m_bitIf->write(code, (len + 1) >> 1);
-}
-
-inline uint32_t toUInt(int val)
-{
-    return (val <= 0) ? -val << 1 : (val << 1) - 1;
-}
-
-void SyntaxElementWriter::xWriteSvlc(int code)
-{
-    uint32_t ucode = toUInt(code);
-
-    xWriteUvlc(ucode);
-}
-
-void SyntaxElementWriter::xWriteFlag(uint32_t code)
-{
-    m_bitIf->write(code, 1);
-}
-
-//! \}
diff -r cbfe2ac89d41 -r 64dc40d52519 source/Lib/TLibEncoder/SyntaxElementWriter.h
--- a/source/Lib/TLibEncoder/SyntaxElementWriter.h	Thu Jul 10 01:33:35 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
- *    be used to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** \file     SyntaxElementWriter.h
-    \brief    CAVLC encoder class (header)
-*/
-
-#ifndef X265_SYNTAXELEMENTWRITER_H
-#define X265_SYNTAXELEMENTWRITER_H
-
-#include "common.h"
-#include "bitstream.h"
-#include "TLibCommon/TComRom.h"
-
-//! \ingroup TLibEncoder
-//! \{
-
-#if ENC_DEC_TRACE
-
-#define WRITE_CODE(value, length, name)    xWriteCodeTr(value, length, name)
-#define WRITE_UVLC(value,         name)    xWriteUvlcTr(value,         name)
-#define WRITE_SVLC(value,         name)    xWriteSvlcTr(value,         name)
-#define WRITE_FLAG(value,         name)    xWriteFlagTr(value,         name)
-
-#else
-
-#define WRITE_CODE(value, length, name)     xWriteCode(value, length)
-#define WRITE_UVLC(value,         name)     xWriteUvlc(value)
-#define WRITE_SVLC(value,         name)     xWriteSvlc(value)
-#define WRITE_FLAG(value,         name)     xWriteFlag(value)
-
-#endif // if ENC_DEC_TRACE
-
-namespace x265 {
-// private namespace
-
-class SyntaxElementWriter
-{
-protected:
-
-    BitInterface* m_bitIf;
-
-    SyntaxElementWriter()
-        : m_bitIf(NULL)
-    {}
-
-    void  setBitstream(BitInterface* p)  { m_bitIf = p; }
-
-    void  xWriteCode(uint32_t code, uint32_t len);
-    void  xWriteUvlc(uint32_t code);
-    void  xWriteSvlc(int code);
-    void  xWriteFlag(uint32_t code);
-
-#if ENC_DEC_TRACE
-    void  xWriteCodeTr(uint32_t value, uint32_t  length, const char *symbolName);
-    void  xWriteUvlcTr(uint32_t value,                   const char *symbolName);
-    void  xWriteSvlcTr(int value,                        const char *symbolName);
-    void  xWriteFlagTr(uint32_t value,                   const char *symbolName);
-#endif
-};
-}
-//! \}
-
-#endif // ifndef X265_SYNTAXELEMENTWRITER_H
diff -r cbfe2ac89d41 -r 64dc40d52519 source/common/bitstream.cpp
--- a/source/common/bitstream.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/common/bitstream.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -105,3 +105,39 @@
     write(1, 1);
     writeAlignZero();
 }
+
+void SyntaxElementWriter::writeCode(uint32_t code, uint32_t length)
+{
+    X265_CHECK(length, "wrote zero length code\n");
+    m_bitIf->write(code, length);
+}
+
+void SyntaxElementWriter::writeUvlc(uint32_t code)
+{
+    uint32_t length = 1;
+    uint32_t temp = ++code;
+
+    X265_CHECK(temp, "writing -1 code, will cause infinite loop\n");
+
+    while (1 != temp)
+    {
+        temp >>= 1;
+        length += 2;
+    }
+
+    // Take care of cases where length > 32
+    m_bitIf->write(0, length >> 1);
+    m_bitIf->write(code, (length + 1) >> 1);
+}
+
+void SyntaxElementWriter::writeSvlc(int32_t code)
+{
+    uint32_t ucode = (code <= 0) ? -code << 1 : (code << 1) - 1;
+
+    writeUvlc(ucode);
+}
+
+void SyntaxElementWriter::writeFlag(uint32_t code)
+{
+    m_bitIf->write(code, 1);
+}
diff -r cbfe2ac89d41 -r 64dc40d52519 source/common/bitstream.h
--- a/source/common/bitstream.h	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/common/bitstream.h	Thu Jul 10 13:59:19 2014 -0500
@@ -133,6 +133,25 @@
         return bitSize[tmp >> 8] + 16;
 }
 
+#define WRITE_CODE(code, length, name) writeCode(code, length)
+#define WRITE_UVLC(code,         name) writeUvlc(code)
+#define WRITE_SVLC(code,         name) writeSvlc(code)
+#define WRITE_FLAG(code,         name) writeFlag(code)
+
+class SyntaxElementWriter
+{
+public:
+
+    BitInterface* m_bitIf;
+
+    SyntaxElementWriter() : m_bitIf(NULL) {}
+
+    void writeCode(uint32_t code, uint32_t length);
+    void writeUvlc(uint32_t code);
+    void writeSvlc(int32_t code);
+    void writeFlag(uint32_t code);
+};
+
 }
 
 #endif // ifndef X265_BITSTREAM_H
diff -r cbfe2ac89d41 -r 64dc40d52519 source/encoder/CMakeLists.txt
--- a/source/encoder/CMakeLists.txt	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/CMakeLists.txt	Thu Jul 10 13:59:19 2014 -0500
@@ -1,11 +1,9 @@
 # vim: syntax=cmake
 set(LIBENCODER_HDR
-    ../Lib/TLibEncoder/SyntaxElementWriter.h
     ../Lib/TLibEncoder/TEncCu.h
     ../Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
     ../Lib/TLibEncoder/TEncSearch.h)
 set(LIBENCODER_SRC
-    ../Lib/TLibEncoder/SyntaxElementWriter.cpp
     ../Lib/TLibEncoder/TEncCu.cpp
     ../Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
     ../Lib/TLibEncoder/TEncSearch.cpp)
diff -r cbfe2ac89d41 -r 64dc40d52519 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/encoder.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -73,19 +73,10 @@
     m_outputCount = 0;
     m_csvfpt = NULL;
     m_param = NULL;
-
-#if ENC_DEC_TRACE
-    g_hTrace = fopen("TraceEnc.txt", "wb");
-    g_bJustDoIt = g_bEncDecTraceDisable;
-    g_nSymbolCounter = 0;
-#endif
 }
 
 Encoder::~Encoder()
 {
-#if ENC_DEC_TRACE
-    fclose(g_hTrace);
-#endif
 }
 
 void Encoder::create()
diff -r cbfe2ac89d41 -r 64dc40d52519 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/entropy.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -180,23 +180,12 @@
     }
     else
     {
-        DTRACE_CABAC_VL(g_nSymbolCounter++);
-        DTRACE_CABAC_T("\tTrIdx: abspart=");
-        DTRACE_CABAC_V(absPartIdx);
-        DTRACE_CABAC_T("\tdepth=");
-        DTRACE_CABAC_V(depth);
-        DTRACE_CABAC_T("\ttrdepth=");
-        DTRACE_CABAC_V(cu->getTransformIdx(absPartIdx));
-        DTRACE_CABAC_T("\n");
-
         if (cu->getPredictionMode(absPartIdx) != MODE_INTRA && depth == cu->getDepth(absPartIdx) && !cu->getCbf(absPartIdx, TEXT_CHROMA_U, 0) && !cu->getCbf(absPartIdx, TEXT_CHROMA_V, 0))
         {
             X265_CHECK(cu->getCbf(absPartIdx, TEXT_LUMA, 0), "CBF should have been set\n");
         }
         else
-        {
             codeQtCbf(cu, absPartIdx, TEXT_LUMA, cu->getTransformIdx(absPartIdx));
-        }
 
         if (cbfY || cbfU || cbfV)
         {
@@ -341,14 +330,7 @@
     uint32_t lumaOffset   = absPartIdx << cu->getPic()->getLog2UnitSize() * 2;
     uint32_t chromaOffset = lumaOffset >> (cu->getHorzChromaShift() + cu->getVertChromaShift());
 
-    if (cu->isIntra(absPartIdx))
-    {
-        DTRACE_CABAC_VL(g_nSymbolCounter++)
-        DTRACE_CABAC_T("\tdecodeTransformIdx()\tCUDepth=")
-        DTRACE_CABAC_V(depth)
-        DTRACE_CABAC_T("\n")
-    }
-    else
+    if (!cu->isIntra(absPartIdx))
     {
         if (!(cu->getMergeFlag(absPartIdx) && cu->getPartitionSize(absPartIdx) == SIZE_2Nx2N))
             codeQtRootCbf(cu, absPartIdx);
@@ -716,10 +698,6 @@
 
 void SBac::codeSPS(TComSPS* sps, TComScalingList *scalingList)
 {
-#if ENC_DEC_TRACE
-    fprintf(g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", sps->getSPSId());
-#endif
-
     WRITE_CODE(sps->getVPSId(),          4,       "sps_video_parameter_set_id");
     WRITE_CODE(sps->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1");
     WRITE_FLAG(sps->getTemporalIdNestingFlag() ? 1 : 0, "sps_temporal_id_nesting_flag");
@@ -813,10 +791,6 @@
 
 void SBac::codePPS(TComPPS* pps, TComScalingList* scalingList)
 {
-#if ENC_DEC_TRACE
-    fprintf(g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pps->getPPSId());
-#endif
-
     WRITE_UVLC(pps->getPPSId(),                            "pps_pic_parameter_set_id");
     WRITE_UVLC(pps->getSPSId(),                            "pps_seq_parameter_set_id");
     WRITE_FLAG(0,                                          "dependent_slice_segments_enabled_flag");
@@ -870,9 +844,6 @@
 
 void SBac::codeVUI(TComVUI *vui, TComSPS* sps)
 {
-#if ENC_DEC_TRACE
-    fprintf(g_hTrace, "----------- vui_parameters -----------\n");
-#endif
     WRITE_FLAG(vui->getAspectRatioInfoPresentFlag(),  "aspect_ratio_info_present_flag");
     if (vui->getAspectRatioInfoPresentFlag())
     {
@@ -1273,10 +1244,6 @@
 
 void SBac::codeSliceHeader(TComSlice* slice)
 {
-#if ENC_DEC_TRACE
-    fprintf(g_hTrace, "=========== Slice ===========\n");
-#endif
-
     //calculate number of bits required for slice address
     int maxSliceSegmentAddress = slice->getPic()->getNumCUsInFrame();
     int bitsSliceSegmentAddress = 0;
@@ -1790,13 +1757,6 @@
     uint32_t ctxSkip = cu->getCtxSkipFlag(absPartIdx);
 
     encodeBin(symbol, m_contextModels[OFF_SKIP_FLAG_CTX + ctxSkip]);
-    DTRACE_CABAC_VL(g_nSymbolCounter++);
-    DTRACE_CABAC_T("\tSkipFlag");
-    DTRACE_CABAC_T("\tuiCtxSkip: ");
-    DTRACE_CABAC_V(ctxSkip);
-    DTRACE_CABAC_T("\tuiSymbol: ");
-    DTRACE_CABAC_V(symbol);
-    DTRACE_CABAC_T("\n");
 }
 
 void SBac::codeMergeFlag(TComDataCU* cu, uint32_t absPartIdx)
@@ -1804,15 +1764,6 @@
     const uint32_t symbol = cu->getMergeFlag(absPartIdx) ? 1 : 0;
 
     encodeBin(symbol, m_contextModels[OFF_MERGE_FLAG_EXT_CTX]);
-
-    DTRACE_CABAC_VL(g_nSymbolCounter++);
-    DTRACE_CABAC_T("\tMergeFlag: ");
-    DTRACE_CABAC_V(symbol);
-    DTRACE_CABAC_T("\tAddress: ");
-    DTRACE_CABAC_V(cu->getAddr());
-    DTRACE_CABAC_T("\tuiAbsPartIdx: ");
-    DTRACE_CABAC_V(absPartIdx);
-    DTRACE_CABAC_T("\n");
 }
 
 void SBac::codeMergeIndex(TComDataCU* cu, uint32_t absPartIdx)
@@ -1833,11 +1784,6 @@
             encodeBinsEP(mask, unaryIdx - (unaryIdx == numCand - 1));
         }
     }
-    DTRACE_CABAC_VL(g_nSymbolCounter++);
-    DTRACE_CABAC_T("\tparseMergeIndex()");
-    DTRACE_CABAC_T("\tuiMRGIdx= ");
-    DTRACE_CABAC_V(cu->getMergeIndex(absPartIdx));
-    DTRACE_CABAC_T("\n");
 }
 
 void SBac::codeSplitFlag(TComDataCU* cu, uint32_t absPartIdx, uint32_t depth)
@@ -1850,20 +1796,11 @@
 
     X265_CHECK(ctx < 3, "ctx out of range\n");
     encodeBin(currSplitFlag, m_contextModels[OFF_SPLIT_FLAG_CTX + ctx]);
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tSplitFlag\n")
 }
 
 void SBac::codeTransformSubdivFlag(uint32_t symbol, uint32_t ctx)
 {
     encodeBin(symbol, m_contextModels[OFF_TRANS_SUBDIV_FLAG_CTX + ctx]);
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tparseTransformSubdivFlag()")
-    DTRACE_CABAC_T("\tsymbol=")
-    DTRACE_CABAC_V(symbol)
-    DTRACE_CABAC_T("\tctx=")
-    DTRACE_CABAC_V(ctx)
-    DTRACE_CABAC_T("\n")
 }
 
 void SBac::codeIntraDirLumaAng(TComDataCU* cu, uint32_t absPartIdx, bool isMultiple)
@@ -2066,19 +2003,6 @@
             uint32_t cbf = cu->getCbf(subTUAbsPartIdx, ttype, subTUDepth);
 
             encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + ctx]);
-            DTRACE_CABAC_VL(g_nSymbolCounter++)
-            DTRACE_CABAC_T("\tparseQtCbf()")
-            DTRACE_CABAC_T("\tsub-TU=")
-            DTRACE_CABAC_V(subTU)
-            DTRACE_CABAC_T("\tsymbol=")
-            DTRACE_CABAC_V(cbf)
-            DTRACE_CABAC_T("\tctx=")
-            DTRACE_CABAC_V(ctx)
-            DTRACE_CABAC_T("\tetype=")
-            DTRACE_CABAC_V(ttype)
-            DTRACE_CABAC_T("\tuiAbsPartIdx=")
-            DTRACE_CABAC_V(subTUAbsPartIdx)
-            DTRACE_CABAC_T("\n")
         }
     }
     else
@@ -2086,17 +2010,6 @@
         uint32_t cbf = cu->getCbf(absPartIdx, ttype, lowestTUDepth);
 
         encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + ctx]);
-        DTRACE_CABAC_VL(g_nSymbolCounter++)
-        DTRACE_CABAC_T("\tparseQtCbf()")
-        DTRACE_CABAC_T("\tsymbol=")
-        DTRACE_CABAC_V(cbf)
-        DTRACE_CABAC_T("\tctx=")
-        DTRACE_CABAC_V(ctx)
-        DTRACE_CABAC_T("\tetype=")
-        DTRACE_CABAC_V(ttype)
-        DTRACE_CABAC_T("\tuiAbsPartIdx=")
-        DTRACE_CABAC_V(absPartIdx)
-        DTRACE_CABAC_T("\n")
     }
 }
 
@@ -2105,18 +2018,6 @@
     uint32_t ctx = cu->getCtxQtCbf(ttype, trDepth);
     uint32_t cbf = cu->getCbf(absPartIdx, ttype, trDepth);
     encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + ctx]);
-
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tparseQtCbf()")
-    DTRACE_CABAC_T("\tsymbol=")
-    DTRACE_CABAC_V(cbf)
-    DTRACE_CABAC_T("\tctx=")
-    DTRACE_CABAC_V(ctx)
-    DTRACE_CABAC_T("\tetype=")
-    DTRACE_CABAC_V(ttype)
-    DTRACE_CABAC_T("\tuiAbsPartIdx=")
-    DTRACE_CABAC_V(absPartIdx)
-    DTRACE_CABAC_T("\n")
 }
 
 void SBac::codeTransformSkipFlags(TComDataCU* cu, uint32_t absPartIdx, uint32_t trSize, TextType ttype)
@@ -2128,17 +2029,6 @@
 
     uint32_t useTransformSkip = cu->getTransformSkip(absPartIdx, ttype);
     encodeBin(useTransformSkip, m_contextModels[OFF_TRANSFORMSKIP_FLAG_CTX + (ttype ? NUM_TRANSFORMSKIP_FLAG_CTX : 0)]);
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tparseTransformSkip()");
-    DTRACE_CABAC_T("\tsymbol=")
-    DTRACE_CABAC_V(useTransformSkip)
-    DTRACE_CABAC_T("\tAddr=")
-    DTRACE_CABAC_V(cu->getAddr())
-    DTRACE_CABAC_T("\tetype=")
-    DTRACE_CABAC_V(ttype)
-    DTRACE_CABAC_T("\tuiAbsPartIdx=")
-    DTRACE_CABAC_V(absPartIdx)
-    DTRACE_CABAC_T("\n")
 }
 
 void SBac::codeQtRootCbf(TComDataCU* cu, uint32_t absPartIdx)
@@ -2147,15 +2037,6 @@
     uint32_t ctx = 0;
 
     encodeBin(cbf, m_contextModels[OFF_QT_ROOT_CBF_CTX + ctx]);
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tparseQtRootCbf()")
-    DTRACE_CABAC_T("\tsymbol=")
-    DTRACE_CABAC_V(cbf)
-    DTRACE_CABAC_T("\tctx=")
-    DTRACE_CABAC_V(ctx)
-    DTRACE_CABAC_T("\tuiAbsPartIdx=")
-    DTRACE_CABAC_V(absPartIdx)
-    DTRACE_CABAC_T("\n")
 }
 
 void SBac::codeQtCbfZero(TComDataCU* cu, TextType ttype, uint32_t trDepth)
@@ -2236,37 +2117,11 @@
 void SBac::codeCoeffNxN(TComDataCU* cu, coeff_t* coeff, uint32_t absPartIdx, uint32_t log2TrSize, TextType ttype)
 {
     uint32_t trSize = 1 << log2TrSize;
-#if ENC_DEC_TRACE
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tparseCoeffNxN()\teType=")
-    DTRACE_CABAC_V(ttype)
-    DTRACE_CABAC_T("\twidth=")
-    DTRACE_CABAC_V(trSize)
-    DTRACE_CABAC_T("\theight=")
-    DTRACE_CABAC_V(trSize)
-    DTRACE_CABAC_T("\tabspartidx=")
-    DTRACE_CABAC_V(absPartIdx)
-    DTRACE_CABAC_T("\ttoCU-X=")
-    DTRACE_CABAC_V(cu->getCUPelX())
-    DTRACE_CABAC_T("\ttoCU-Y=")
-    DTRACE_CABAC_V(cu->getCUPelY())
-    DTRACE_CABAC_T("\tCU-addr=")
-    DTRACE_CABAC_V(cu->getAddr())
-    DTRACE_CABAC_T("\tinCU-X=")
-    DTRACE_CABAC_V(g_rasterToPelX[g_zscanToRaster[absPartIdx]])
-    DTRACE_CABAC_T("\tinCU-Y=")
-    DTRACE_CABAC_V(g_rasterToPelY[g_zscanToRaster[absPartIdx]])
-    DTRACE_CABAC_T("\tpredmode=")
-    DTRACE_CABAC_V(cu->getPredictionMode(absPartIdx))
-    DTRACE_CABAC_T("\n")
-#endif // if ENC_DEC_TRACE
 
     // compute number of significant coefficients
     uint32_t numSig = primitives.count_nonzero(coeff, (1 << (log2TrSize << 1)));
 
-#if CHECKED_BUILD || _DEBUG
     X265_CHECK(numSig > 0, "cbf check fail\n");
-#endif
 
     bool beValid;
     if (cu->getCUTransquantBypass(absPartIdx))
@@ -2714,13 +2569,6 @@
 /** Encode bin */
 void SBac::encodeBin(uint32_t binValue, ContextModel &ctxModel)
 {
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tstate=")
-    DTRACE_CABAC_V((ctxModel.m_state << 1) + sbacGetMps(ctxModel.m_state))
-    DTRACE_CABAC_T("\tsymbol=")
-    DTRACE_CABAC_V(binValue)
-    DTRACE_CABAC_T("\n")
-
     uint32_t mstate = ctxModel.m_state;
 
     ctxModel.m_state = sbacNext(mstate, binValue);
@@ -2771,11 +2619,6 @@
 /** Encode equiprobable bin */
 void SBac::encodeBinEP(uint32_t binValue)
 {
-    DTRACE_CABAC_VL(g_nSymbolCounter++)
-    DTRACE_CABAC_T("\tEPsymbol=")
-    DTRACE_CABAC_V(binValue)
-    DTRACE_CABAC_T("\n")
-
     if (m_bIsCounter)
     {
         m_fracBits += 32768;
@@ -2799,14 +2642,6 @@
         return;
     }
 
-    for (int i = 0; i < numBins; i++)
-    {
-        DTRACE_CABAC_VL(g_nSymbolCounter++)
-        DTRACE_CABAC_T("\tEPsymbol=")
-        DTRACE_CABAC_V((binValues >> (numBins - 1 - i)) & 1)
-        DTRACE_CABAC_T("\n")
-    }
-
     while (numBins > 8)
     {
         numBins -= 8;
diff -r cbfe2ac89d41 -r 64dc40d52519 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -602,15 +602,6 @@
 
 void FrameEncoder::encodeSlice()
 {
-#if ENC_DEC_TRACE
-    g_bJustDoIt = g_bEncDecTraceEnable;
-    DTRACE_CABAC_VL(g_nSymbolCounter++);
-    DTRACE_CABAC_T("\tPOC: ");
-    DTRACE_CABAC_V(m_frame->getPOC());
-    DTRACE_CABAC_T("\n");
-    g_bJustDoIt = g_bEncDecTraceDisable;
-#endif
-
     TComSlice* slice = m_frame->getSlice();
     const uint32_t widthInLCUs = m_frame->getPicSym()->getFrameWidthInCU();
     const uint32_t lastCUAddr = (slice->getSliceCurEndCUAddr() + m_frame->getNumPartInCU() - 1) / m_frame->getNumPartInCU();
@@ -667,18 +658,11 @@
             }
         }
 
-#if ENC_DEC_TRACE
-        g_bJustDoIt = g_bEncDecTraceEnable;
-#endif
-        
+        // 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);
 
-#if ENC_DEC_TRACE
-        g_bJustDoIt = g_bEncDecTraceDisable;
-#endif
-
         // 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 cbfe2ac89d41 -r 64dc40d52519 source/encoder/sei.cpp
--- a/source/encoder/sei.cpp	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/sei.cpp	Thu Jul 10 13:59:19 2014 -0500
@@ -28,35 +28,17 @@
 
 using namespace x265;
 
-#if ENC_DEC_TRACE
-#define LOG(string) fprintf(g_hTrace, string)
-#else
-#define LOG(string)
-#endif
-
-/**
- * marshal a single SEI message sei, storing the marshalled representation
- * in bitstream bs.
- */
+/* marshal a single SEI message sei, storing the marshalled representation
+ * in bitstream bs */
 void SEI::write(Bitstream& bs, TComSPS& sps)
 {
-    /* disable logging while we measure the SEI */
-#if ENC_DEC_TRACE
-    bool traceEnable = g_HLSTraceEnable;
-    g_HLSTraceEnable = false;
-#endif
+    BitCounter count;
+    m_bitIf = &count;
 
-    BitCounter count;
-    setBitstream(&count);
+    /* virtual writeSEI method, write to bit counter */
     writeSEI(sps);
 
-#if ENC_DEC_TRACE
-    g_HLSTraceEnable = traceEnable;
-#endif
-
-    LOG("=========== SEI message ===========\n");
-
-    setBitstream(&bs);
+    m_bitIf = &bs;
     uint32_t type = payloadType();
     for (; type >= 0xff; type -= 0xff)
         WRITE_CODE(0xff, 8, "payload_type");
@@ -68,13 +50,13 @@
         WRITE_CODE(0xff, 8, "payload_size");
     WRITE_CODE(payloadSize, 8, "payload_size");
 
-    /* virtual writeSEI method */
+    /* virtual writeSEI method, write to bs */
     writeSEI(sps);
 }
 
 void SEI::writeByteAlign()
 {
-    // TODO: bs.writeByteAlignment()
+    // TODO: expose bs.writeByteAlignment() as virtual function
     if (m_bitIf->getNumberOfWrittenBits() % 8 != 0)
     {
         WRITE_FLAG(1, "bit_equal_to_one");
diff -r cbfe2ac89d41 -r 64dc40d52519 source/encoder/sei.h
--- a/source/encoder/sei.h	Thu Jul 10 01:33:35 2014 -0500
+++ b/source/encoder/sei.h	Thu Jul 10 13:59:19 2014 -0500
@@ -27,7 +27,6 @@
 #include "common.h"
 #include "bitstream.h"
 #include "TLibCommon/TComSlice.h"
-#include "TLibEncoder/SyntaxElementWriter.h"
 
 namespace x265 {
 // private namespace
@@ -81,12 +80,6 @@
     void writeByteAlign();
 };
 
-#if ENC_DEC_TRACE
-#define LOG(string) fprintf(g_hTrace, string)
-#else
-#define LOG(string)
-#endif
-
 class SEIDecodedPictureHash : public SEI
 {
 public:
@@ -104,9 +97,7 @@
 
     void write(Bitstream& bs, TComSPS&)
     {
-        setBitstream(&bs);
-
-        LOG("=========== Decoded picture hash SEI message ===========\n");
+        m_bitIf = &bs;
 
         WRITE_CODE(DECODED_PICTURE_HASH, 8, "payload_type");
 
@@ -161,7 +152,6 @@
 
     void writeSEI(TComSPS&)
     {
-        LOG("=========== Active Parameter sets SEI message ===========\n");
         WRITE_CODE(m_activeVPSId,     4,   "active_vps_id");
         WRITE_FLAG(m_fullRandomAccessFlag, "full_random_access_flag");
         WRITE_FLAG(m_noParamSetUpdateFlag, "no_param_set_update_flag");
@@ -205,8 +195,6 @@
         TComVUI *vui = sps.getVuiParameters();
         TComHRD *hrd = vui->getHrdParameters();
 
-        LOG("=========== Buffering period SEI message ===========\n");
-
         WRITE_UVLC(m_bpSeqParameterSetId, "bp_seq_parameter_set_id");
         if (!hrd->getSubPicHrdParamsPresentFlag())
         {
@@ -256,8 +244,6 @@
 
     void writeSEI(TComSPS& sps)
     {
-        LOG("=========== Picture timing SEI message ===========\n");
-
         TComVUI *vui = sps.getVuiParameters();
         TComHRD *hrd = vui->getHrdParameters();
 
@@ -290,7 +276,6 @@
 
     void writeSEI(TComSPS&)
     {
-        LOG("=========== Recovery point SEI message ===========\n");
         WRITE_SVLC(m_recoveryPocCnt,    "recovery_poc_cnt");
         WRITE_FLAG(m_exactMatchingFlag, "exact_matching_flag");
         WRITE_FLAG(m_brokenLinkFlag,    "broken_link_flag");
@@ -299,6 +284,4 @@
 };
 }
 
-#undef LOG
-
 #endif // ifndef X265_SEI_H


More information about the x265-devel mailing list