From: Max Blaeser <blaeser@ient.rwth-aachen.de>
Date: Tue, 13 Nov 2018 15:25:46 +0100
Subject: [PATCH] Fix output of bit and tool statistics. If
 RExt__DECODER_DEBUG_BIT_STATISTICS and RExt__DECODER_DEBUG_TOOL_STATISTICS
 are enabled, the decoder throws and exception as size of enum
 CodingStatisticsType and the size of the statNames array don't match.
 Further, the order of the enum has to match the order of the labels. Also,
 the bit counter for JVET_L0283_MULTI_REF_LINE was missing.

---
 source/Lib/CommonLib/CodingStatistics.h | 26 +++++++++++++++++---------
 source/Lib/DecoderLib/CABACReader.cpp   |  1 +
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/source/Lib/CommonLib/CodingStatistics.h b/source/Lib/CommonLib/CodingStatistics.h
index a00a49b..c9bf3b3 100644
--- a/source/Lib/CommonLib/CodingStatistics.h
+++ b/source/Lib/CommonLib/CodingStatistics.h
@@ -66,6 +66,8 @@ enum CodingStatisticsType
   STATS__CABAC_BITS__REF_FRM_IDX,
   STATS__CABAC_BITS__MVD,
   STATS__CABAC_BITS__MVD_EP,
+  STATS__CABAC_BITS__AFFINE_FLAG,
+  STATS__CABAC_BITS__AFFINE_TYPE,
   STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG,
   STATS__CABAC_BITS__QT_ROOT_CBF,
   STATS__CABAC_BITS__DELTA_QP_EP,
@@ -76,11 +78,13 @@ enum CodingStatisticsType
   STATS__CABAC_BITS__LAST_SIG_X_Y,
   STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG,
   STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG,
+  STATS__CABAC_BITS__PAR_FLAG,
   STATS__CABAC_BITS__GT1_FLAG,
   STATS__CABAC_BITS__GT2_FLAG,
   STATS__CABAC_BITS__SIGN_BIT,
   STATS__CABAC_BITS__ESCAPE_BITS,
   STATS__CABAC_BITS__SAO,
+  STATS__CABAC_BITS__ALF,
   STATS__CABAC_TRM_BITS,
   STATS__CABAC_FIXED_BITS,
   STATS__CABAC_PCM_ALIGN_BITS,
@@ -93,19 +97,12 @@ enum CodingStatisticsType
   STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS,
   STATS__CABAC_BITS__OTHER,
   STATS__CABAC_BITS__INVALID,
-  STATS__TOOL_TOTAL_FRAME,// This is a special case and is not included in the report.
-  STATS__CABAC_BITS__AFFINE_FLAG,
-  STATS__TOOL_AFF,
-  STATS__CABAC_BITS__AFFINE_TYPE,
-  STATS__CABAC_BITS__PAR_FLAG,
-  STATS__CABAC_BITS__ALF,
   STATS__CABAC_BITS__IMV_FLAG,
 #if JVET_L0646_GBI
   STATS__CABAC_BITS__GBI_IDX,
 #endif
   STATS__CABAC_BITS__EMT_CU_FLAG,
   STATS__CABAC_BITS__EMT_TU_INDEX,
-  STATS__TOOL_EMT,
 #if JVET_L0100_MULTI_HYPOTHESIS_INTRA
   STATS__CABAC_BITS__MH_INTRA_FLAG,
 #endif
@@ -113,6 +110,12 @@ enum CodingStatisticsType
   STATS__CABAC_BITS__TRIANGLE_FLAG,
   STATS__CABAC_BITS__TRIANGLE_INDEX,
 #endif
+#if JVET_L0283_MULTI_REF_LINE
+  STATS__CABAC_BITS__MULTI_REF_LINE,
+#endif
+  STATS__TOOL_TOTAL_FRAME,// This is a special case and is not included in the report.
+  STATS__TOOL_AFF,
+  STATS__TOOL_EMT,
   STATS__TOOL_TOTAL,
   STATS__NUM_STATS
 };
@@ -179,6 +182,8 @@ static inline const char* getName(CodingStatisticsType name)
     "CABAC_EP_BIT_ALIGNMENT",
     "CABAC_BITS__ALIGNED_SIGN_BIT",
     "CABAC_BITS__ALIGNED_ESCAPE_BITS",
+    "CABAC_BITS__OTHER",
+    "CABAC_BITS__INVALID",
     "CABAC_BITS__IMV_FLAG",
 #if JVET_L0646_GBI
     "CABAC_BITS__GBI_IDX",
@@ -192,9 +197,12 @@ static inline const char* getName(CodingStatisticsType name)
     "CABAC_BITS__TRIANGLE_FLAG",
     "CABAC_BITS__TRIANGLE_INDEX",
 #endif
-    "CABAC_BITS__OTHER",
-    "CABAC_BITS__INVALID",
+#if JVET_L0283_MULTI_REF_LINE
+    "CABAC_BITS__MULTI_REF_LINE",
+#endif
     "TOOL_FRAME",
+    "TOOL_AFFINE",
+    "TOOL_EMT",
     "TOOL_TOTAL"
   };
   CHECK( STATS__NUM_STATS != sizeof( statNames ) / sizeof( char* ) || name >= STATS__NUM_STATS, "stats out of range" );
diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp
index 76db0e4..fd58a5a 100644
--- a/source/Lib/DecoderLib/CABACReader.cpp
+++ b/source/Lib/DecoderLib/CABACReader.cpp
@@ -954,6 +954,7 @@ void CABACReader::extend_ref_line(CodingUnit& cu)
     cu.firstPU->multiRefIdx = 0;
     return;
   }
+  RExt__DECODER_DEBUG_BIT_STATISTICS_CREATE_SET(STATS__CABAC_BITS__MULTI_REF_LINE);
 
   const int numBlocks = CU::getNumPUs(cu);
   PredictionUnit* pu = cu.firstPU;
-- 
2.13.1.windows.2

