HEVC Test Model (HM)  HM-16.3
SyntaxElementParser.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 * be used to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
38 
41 #include "TLibCommon/CommonDef.h"
42 #include "TLibCommon/TComRom.h"
44 #include "SyntaxElementParser.h"
45 #if RExt__DECODER_DEBUG_BIT_STATISTICS
47 #endif
48 
49 #if ENC_DEC_TRACE
50 
51 Void SyntaxElementParser::xReadCodeTr (UInt length, UInt& rValue, const Char *pSymbolName)
52 {
53 #if RExt__DECODER_DEBUG_BIT_STATISTICS
54  xReadCode (length, rValue, pSymbolName);
55 #else
56  xReadCode (length, rValue);
57 #endif
58  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
59  if (length < 10)
60  {
61  fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
62  }
63  else
64  {
65  fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
66  }
67  fflush ( g_hTrace );
68 }
69 
70 Void SyntaxElementParser::xReadUvlcTr (UInt& rValue, const Char *pSymbolName)
71 {
72 #if RExt__DECODER_DEBUG_BIT_STATISTICS
73  xReadUvlc (rValue, pSymbolName);
74 #else
75  xReadUvlc (rValue);
76 #endif
77  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
78  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
79  fflush ( g_hTrace );
80 }
81 
82 Void SyntaxElementParser::xReadSvlcTr (Int& rValue, const Char *pSymbolName)
83 {
84 #if RExt__DECODER_DEBUG_BIT_STATISTICS
85  xReadSvlc (rValue, pSymbolName);
86 #else
87  xReadSvlc (rValue);
88 #endif
89  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
90  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
91  fflush ( g_hTrace );
92 }
93 
94 Void SyntaxElementParser::xReadFlagTr (UInt& rValue, const Char *pSymbolName)
95 {
96 #if RExt__DECODER_DEBUG_BIT_STATISTICS
97  xReadFlag (rValue, pSymbolName);
98 #else
99  xReadFlag (rValue);
100 #endif
101  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
102  fprintf( g_hTrace, "%-50s u(1) : %d\n", pSymbolName, rValue );
103  fflush ( g_hTrace );
104 }
105 
106 #endif
107 
108 
109 // ====================================================================================================================
110 // Protected member functions
111 // ====================================================================================================================
112 #if RExt__DECODER_DEBUG_BIT_STATISTICS
113 Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
114 #else
116 #endif
117 {
118  assert ( uiLength > 0 );
119  m_pcBitstream->read (uiLength, ruiCode);
120 #if RExt__DECODER_DEBUG_BIT_STATISTICS
121  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
122 #endif
123 }
124 
125 #if RExt__DECODER_DEBUG_BIT_STATISTICS
126 Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
127 #else
129 #endif
130 {
131  UInt uiVal = 0;
132  UInt uiCode = 0;
133  UInt uiLength;
134  m_pcBitstream->read( 1, uiCode );
135 #if RExt__DECODER_DEBUG_BIT_STATISTICS
136  UInt totalLen=1;
137 #endif
138 
139  if( 0 == uiCode )
140  {
141  uiLength = 0;
142 
143  while( ! ( uiCode & 1 ))
144  {
145  m_pcBitstream->read( 1, uiCode );
146  uiLength++;
147  }
148 
149  m_pcBitstream->read( uiLength, uiVal );
150 
151  uiVal += (1 << uiLength)-1;
152 #if RExt__DECODER_DEBUG_BIT_STATISTICS
153  totalLen+=uiLength+uiLength;
154 #endif
155  }
156 
157  ruiVal = uiVal;
158 #if RExt__DECODER_DEBUG_BIT_STATISTICS
159  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
160 #endif
161 }
162 
163 #if RExt__DECODER_DEBUG_BIT_STATISTICS
164 Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
165 #else
167 #endif
168 {
169  UInt uiBits = 0;
170  m_pcBitstream->read( 1, uiBits );
171 #if RExt__DECODER_DEBUG_BIT_STATISTICS
172  UInt totalLen=1;
173 #endif
174  if( 0 == uiBits )
175  {
176  UInt uiLength = 0;
177 
178  while( ! ( uiBits & 1 ))
179  {
180  m_pcBitstream->read( 1, uiBits );
181  uiLength++;
182  }
183 
184  m_pcBitstream->read( uiLength, uiBits );
185 
186  uiBits += (1 << uiLength);
187  riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
188 #if RExt__DECODER_DEBUG_BIT_STATISTICS
189  totalLen+=uiLength+uiLength;
190 #endif
191  }
192  else
193  {
194  riVal = 0;
195  }
196 #if RExt__DECODER_DEBUG_BIT_STATISTICS
197  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
198 #endif
199 }
200 
201 #if RExt__DECODER_DEBUG_BIT_STATISTICS
202 Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
203 #else
205 #endif
206 {
207  m_pcBitstream->read( 1, ruiCode );
208 #if RExt__DECODER_DEBUG_BIT_STATISTICS
209  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
210 #endif
211 }
212 
214 
Defines constants, macros and tool parameters.
void Void
Definition: TypeDef.h:285
Void xReadCode(UInt length, UInt &val)
global variables & functions (header)
char Char
Definition: TypeDef.h:291
unsigned int UInt
Definition: TypeDef.h:297
UInt64 g_nSymbolCounter
Definition: TComRom.cpp:566
FILE * g_hTrace
Definition: TComRom.cpp:561
Void xReadFlagTr(UInt &rValue, const Char *pSymbolName)
Parsing functionality high level syntax.
class for handling bitstream (header)
Void xReadCodeTr(UInt length, UInt &rValue, const Char *pSymbolName)
Void xReadUvlcTr(UInt &rValue, const Char *pSymbolName)
int Int
Definition: TypeDef.h:296
static Void IncrementStatisticEP(const TComCodingStatisticsClassType &stat, const Int numBits, const Int value)
Void xReadSvlcTr(Int &rValue, const Char *pSymbolName)