Index: trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 1179)
+++ trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 1313)
@@ -2,5 +2,5 @@
 * 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.  
+* granted under this license.
 *
 * Copyright (c) 2010-2015, ITU/ISO/IEC
@@ -43,4 +43,7 @@
 #include "TLibCommon/TComBitStream.h"
 #include "SyntaxElementParser.h"
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+#include "TLibCommon/TComCodingStatistics.h"
+#endif
 
 #if ENC_DEC_TRACE
@@ -48,5 +51,9 @@
 Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
 {
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  xReadCode (length, rValue, pSymbolName);
+#else
   xReadCode (length, rValue);
+#endif
 #if H_MV_ENC_DEC_TRAC
   if ( g_disableHLSTrace || !g_HLSTraceEnable )
@@ -56,26 +63,78 @@
   if ( !g_disableNumbering )
   {
-#endif
+    incSymbolCounter();
+    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
+  }
+#else
+    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
+#endif
+  if (length < 10)
+  {
+    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
+  }
+  else
+  {
+    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
+  }
+  fflush ( g_hTrace );
+}
+
+Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
+{
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  xReadUvlc (rValue, pSymbolName);
+#else
+  xReadUvlc (rValue);
+#endif
+#if H_MV_ENC_DEC_TRAC
+  if ( g_disableHLSTrace || !g_HLSTraceEnable )
+  {
+    return; 
+  }
+  if ( !g_disableNumbering )
+  {
+  incSymbolCounter();
+  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
+  }
+#else
   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
+#endif
+  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
+  fflush ( g_hTrace );
+}
+
+Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
+{
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  xReadSvlc (rValue, pSymbolName);
+#else
+  xReadSvlc (rValue);
+#endif
 #if H_MV_ENC_DEC_TRAC
-  }
-#endif
-
-  if (length < 10)
-  {
-    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
-  }
-  else
-  {
-    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
-  }
+  if ( g_disableHLSTrace || !g_HLSTraceEnable )
+  {
+    return; 
+  }
+  if ( !g_disableNumbering )
+  {  
+    incSymbolCounter();
+    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
+  }
+#else
+    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
+#endif
+  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
   fflush ( g_hTrace );
 }
 
-Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
-{
-  xReadUvlc (rValue);
+Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
+{
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  xReadFlag (rValue, pSymbolName);
+#else
+  xReadFlag (rValue);
+#endif
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
+  if ( g_disableHLSTrace || !g_HLSTraceEnable )
   {
     return; 
@@ -83,50 +142,22 @@
   if ( !g_disableNumbering )
   {
-#endif
+    incSymbolCounter(); 
+    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
+  }
+#else
   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-#if H_MV_ENC_DEC_TRAC
-  }
-#endif
-  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); 
+#endif
+  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
   fflush ( g_hTrace );
 }
 
-Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
-{
-  xReadSvlc(rValue);
-#if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
-  {
-    return; 
-  }
-  if ( !g_disableNumbering )
-  {
-#endif
-  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-#if H_MV_ENC_DEC_TRAC
-  }
-#endif
-
-  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue ); 
-  fflush ( g_hTrace );
-}
-
-Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
-{
-  xReadFlag(rValue);
-#if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
-  {
-    return; 
-  }
-  if ( !g_disableNumbering )
-  {
-#endif
-  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-#if H_MV_ENC_DEC_TRAC
-  }
-#endif
-  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue ); 
-  fflush ( g_hTrace );
+Void  xTraceAccessUnitDelimiter ()
+{
+  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
+}
+
+Void xTraceFillerData ()
+{
+  fprintf( g_hTrace, "=========== Filler Data ===========\n");
 }
 
@@ -137,12 +168,22 @@
 // Protected member functions
 // ====================================================================================================================
-
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
+#else
 Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
+#endif
 {
   assert ( uiLength > 0 );
   m_pcBitstream->read (uiLength, ruiCode);
-}
-
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
+#endif
+}
+
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
+#else
 Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
+#endif
 {
   UInt uiVal = 0;
@@ -150,4 +191,7 @@
   UInt uiLength;
   m_pcBitstream->read( 1, uiCode );
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  UInt totalLen=1;
+#endif
 
   if( 0 == uiCode )
@@ -164,13 +208,26 @@
 
     uiVal += (1 << uiLength)-1;
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+    totalLen+=uiLength+uiLength;
+#endif
   }
 
   ruiVal = uiVal;
-}
-
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
+#endif
+}
+
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
+#else
 Void SyntaxElementParser::xReadSvlc( Int& riVal)
+#endif
 {
   UInt uiBits = 0;
   m_pcBitstream->read( 1, uiBits );
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  UInt totalLen=1;
+#endif
   if( 0 == uiBits )
   {
@@ -187,4 +244,7 @@
     uiBits += (1 << uiLength);
     riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+    totalLen+=uiLength+uiLength;
+#endif
   }
   else
@@ -192,9 +252,63 @@
     riVal = 0;
   }
-}
-
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
+#endif
+}
+
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
+#else
 Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
+#endif
 {
   m_pcBitstream->read( 1, ruiCode );
+#if RExt__DECODER_DEBUG_BIT_STATISTICS
+  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
+#endif
+}
+
+Void SyntaxElementParser::xReadRbspTrailingBits()
+{
+  UInt bit;
+  READ_FLAG( bit, "rbsp_stop_one_bit");
+  assert (bit==1);
+  Int cnt = 0;
+  while (m_pcBitstream->getNumBitsUntilByteAligned())
+  {
+    READ_FLAG( bit, "rbsp_alignment_zero_bit");
+    assert (bit==0);
+    cnt++;
+  }
+  assert(cnt<8);
+}
+
+Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
+{
+  setBitstream(bs);
+
+#if ENC_DEC_TRACE
+  xTraceAccessUnitDelimiter();
+#endif
+
+  READ_CODE (3, picType, "pic_type");
+  xReadRbspTrailingBits();
+}
+
+Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
+{
+  setBitstream(bs);
+#if ENC_DEC_TRACE
+  xTraceFillerData();
+#endif
+  UInt ffByte;
+  fdSize = 0;
+  while( m_pcBitstream->getNumBitsLeft() >8 )
+  {
+    READ_CODE (8, ffByte, "ff_byte");
+    assert (ffByte==0xff);
+    fdSize++;
+  }
+  xReadRbspTrailingBits();
 }
 
