HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2017, 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 xTraceAccessUnitDelimiter ()
52 {
53  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
54 }
55 
56 Void xTraceFillerData ()
57 {
58  fprintf( g_hTrace, "=========== Filler Data ===========\n");
59 }
60 
61 #endif
62 
63 
64 
65 #if DECODER_PARTIAL_CONFORMANCE_CHECK!=0
66 
67 Void SyntaxElementParser::xReadSCodeChk ( UInt length, Int& val, const TChar *pSymbolName, const Int minValIncl, const Int maxValIncl )
68 {
69  READ_SCODE(length, val, pSymbolName);
70  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
71 }
72 
73 Void SyntaxElementParser::xReadCodeChk ( UInt length, UInt& val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
74 {
75  READ_CODE(length, val, pSymbolName);
76  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
77 }
78 
79 Void SyntaxElementParser::xReadUvlcChk ( UInt& val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
80 {
81  READ_UVLC(val, pSymbolName);
82  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
83 }
84 
85 Void SyntaxElementParser::xReadSvlcChk ( Int& val, const TChar *pSymbolName, const Int minValIncl, const Int maxValIncl )
86 {
87  READ_SVLC(val, pSymbolName);
88  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
89 }
90 
91 Void SyntaxElementParser::xReadFlagChk ( UInt& val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
92 {
93  READ_FLAG(val, pSymbolName);
94  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
95 }
96 #endif
97 
98 // ====================================================================================================================
99 // Protected member functions
100 // ====================================================================================================================
101 #if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
102 Void SyntaxElementParser::xReadSCode (UInt uiLength, Int& rValue, const TChar *pSymbolName)
103 #else
105 #endif
106 {
107  UInt val;
108  assert ( uiLength > 0 );
109  m_pcBitstream->read (uiLength, val);
110  if((val & (1 << (uiLength-1))) == 0)
111  {
112  rValue = val;
113  }
114  else
115  {
116  val &= (1<< (uiLength-1)) - 1;
117  rValue = ~val + 1;
118  }
119 
120 #if RExt__DECODER_DEBUG_BIT_STATISTICS
121  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, rValue);
122 #endif
123 #if ENC_DEC_TRACE
124  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
125  if (uiLength < 10)
126  {
127  fprintf( g_hTrace, "%-50s i(%d) : %d\n", pSymbolName, uiLength, rValue );
128  }
129  else
130  {
131  fprintf( g_hTrace, "%-50s i(%d) : %d\n", pSymbolName, uiLength, rValue );
132  }
133  fflush ( g_hTrace );
134 #endif
135 }
136 
137 #if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
138 Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& rValue, const TChar *pSymbolName)
139 #else
141 #endif
142 {
143  assert ( uiLength > 0 );
144  m_pcBitstream->read (uiLength, rValue);
145 #if RExt__DECODER_DEBUG_BIT_STATISTICS
146  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, rValue);
147 #endif
148 #if ENC_DEC_TRACE
149  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
150  if (uiLength < 10)
151  {
152  fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, uiLength, rValue );
153  }
154  else
155  {
156  fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, uiLength, rValue );
157  }
158  fflush ( g_hTrace );
159 #endif
160 }
161 
162 
163 #if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
164 Void SyntaxElementParser::xReadUvlc( UInt& rValue, const TChar *pSymbolName)
165 #else
167 #endif
168 {
169  UInt uiVal = 0;
170  UInt uiCode = 0;
171  UInt uiLength;
172  m_pcBitstream->read( 1, uiCode );
173 #if RExt__DECODER_DEBUG_BIT_STATISTICS
174  UInt totalLen=1;
175 #endif
176 
177  if( 0 == uiCode )
178  {
179  uiLength = 0;
180 
181  while( ! ( uiCode & 1 ))
182  {
183  m_pcBitstream->read( 1, uiCode );
184  uiLength++;
185  }
186 
187  m_pcBitstream->read( uiLength, uiVal );
188 
189  uiVal += (1 << uiLength)-1;
190 #if RExt__DECODER_DEBUG_BIT_STATISTICS
191  totalLen+=uiLength+uiLength;
192 #endif
193  }
194 
195  rValue = uiVal;
196 #if RExt__DECODER_DEBUG_BIT_STATISTICS
197  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
198 #endif
199 
200 #if ENC_DEC_TRACE
201  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
202  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
203  fflush ( g_hTrace );
204 #endif
205 }
206 
207 #if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
208 Void SyntaxElementParser::xReadSvlc( Int& rValue, const TChar *pSymbolName)
209 #else
211 #endif
212 {
213  UInt uiBits = 0;
214  m_pcBitstream->read( 1, uiBits );
215 #if RExt__DECODER_DEBUG_BIT_STATISTICS
216  UInt totalLen=1;
217 #endif
218  if( 0 == uiBits )
219  {
220  UInt uiLength = 0;
221 
222  while( ! ( uiBits & 1 ))
223  {
224  m_pcBitstream->read( 1, uiBits );
225  uiLength++;
226  }
227 
228  m_pcBitstream->read( uiLength, uiBits );
229 
230  uiBits += (1 << uiLength);
231  rValue = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
232 #if RExt__DECODER_DEBUG_BIT_STATISTICS
233  totalLen+=uiLength+uiLength;
234 #endif
235  }
236  else
237  {
238  rValue = 0;
239  }
240 #if RExt__DECODER_DEBUG_BIT_STATISTICS
241  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
242 #endif
243 
244 #if ENC_DEC_TRACE
245  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
246  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
247  fflush ( g_hTrace );
248 #endif
249 
250 }
251 
252 #if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
253 Void SyntaxElementParser::xReadFlag (UInt& rValue, const TChar *pSymbolName)
254 #else
256 #endif
257 {
258  m_pcBitstream->read( 1, rValue );
259 #if RExt__DECODER_DEBUG_BIT_STATISTICS
260  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(rValue));
261 #endif
262 
263 #if ENC_DEC_TRACE
264  fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ );
265  fprintf( g_hTrace, "%-50s u(1) : %d\n", pSymbolName, rValue );
266  fflush ( g_hTrace );
267 #endif
268 }
269 
271 {
272  UInt bit;
273  READ_FLAG( bit, "rbsp_stop_one_bit");
274  assert (bit==1);
275  Int cnt = 0;
277  {
278  READ_FLAG( bit, "rbsp_alignment_zero_bit");
279  assert (bit==0);
280  cnt++;
281  }
282  assert(cnt<8);
283 }
284 
286 {
287  setBitstream(bs);
288 
289 #if ENC_DEC_TRACE
290  xTraceAccessUnitDelimiter();
291 #endif
292 
293  READ_CODE (3, picType, "pic_type");
295 }
296 
298 {
299  setBitstream(bs);
300 #if ENC_DEC_TRACE
301  xTraceFillerData();
302 #endif
303  UInt ffByte;
304  fdSize = 0;
305  while( m_pcBitstream->getNumBitsLeft() >8 )
306  {
307  READ_CODE (8, ffByte, "ff_byte");
308  assert (ffByte==0xff);
309  fdSize++;
310  }
312 }
313 
314 
316 
Void parseAccessUnitDelimiter(TComInputBitstream *bs, UInt &picType)
UInt getNumBitsUntilByteAligned()
#define READ_CODE(length, code, name)
Defines version information, constants and small in-line functions.
void Void
Definition: TypeDef.h:203
global variables &amp; functions (header)
#define READ_SVLC(code, name)
unsigned int UInt
Definition: TypeDef.h:212
Void xReadCode(UInt length, UInt &val)
char TChar
Definition: TypeDef.h:206
TComInputBitstream * m_pcBitstream
static Void checkRange(const T &, const TChar *, const T &, const T &)
Void parseFillerData(TComInputBitstream *bs, UInt &fdSize)
Parsing functionality high level syntax.
Void setBitstream(TComInputBitstream *p)
class for handling bitstream (header)
#define READ_SCODE(length, code, name)
#define READ_FLAG(code, name)
#define READ_UVLC(code, name)
Void xReadSCode(UInt length, Int &val)
int Int
Definition: TypeDef.h:211
static Void IncrementStatisticEP(const TComCodingStatisticsClassType &stat, const Int numBits, const Int value)