source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp

Last change on this file was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

File size: 12.3 KB
Line 
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
34/** \file     SyntaxElementParser.cpp
35    \brief    Parsing functionality high level syntax
36*/
37
38//! \ingroup TLibDecoder
39//! \{
40
41#include "TLibCommon/CommonDef.h"
42#include "TLibCommon/TComRom.h"
43#include "TLibCommon/TComBitStream.h"
44#include "SyntaxElementParser.h"
45#if RExt__DECODER_DEBUG_BIT_STATISTICS
46#include "TLibCommon/TComCodingStatistics.h"
47#endif
48
49#if ENC_DEC_TRACE
50
51Void  xTraceAccessUnitDelimiter ()
52{
53  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
54}
55
56Void xTraceFillerData ()
57{
58  fprintf( g_hTrace, "=========== Filler Data ===========\n");
59}
60
61#endif
62
63#if DECODER_PARTIAL_CONFORMANCE_CHECK!=0
64Void SyntaxElementParser::xReadCodeChk ( UInt   length, UInt& val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
65{
66  READ_CODE(length, val, pSymbolName);
67  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
68}
69#if NH_MV
70
71Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const TChar *pSymbolName)
72{
73#if RExt__DECODER_DEBUG_BIT_STATISTICS
74  xReadCode (length, rValue, pSymbolName);
75#else
76  xReadCode (length, rValue);
77#endif
78#if NH_MV_ENC_DEC_TRAC
79  if ( g_disableHLSTrace || !g_HLSTraceEnable )
80  {
81    return; 
82  }
83  if ( !g_disableNumbering )
84  {
85    incSymbolCounter();
86    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
87  }
88#else
89    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
90#endif
91  if (length < 10)
92  {
93    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
94  }
95  else
96  {
97    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
98  }
99  fflush ( g_hTrace );
100}
101
102Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const TChar *pSymbolName)
103{
104#if RExt__DECODER_DEBUG_BIT_STATISTICS
105  xReadUvlc (rValue, pSymbolName);
106#else
107  xReadUvlc (rValue);
108#endif
109#if NH_MV_ENC_DEC_TRAC
110  if ( g_disableHLSTrace || !g_HLSTraceEnable )
111  {
112    return; 
113  }
114  if ( !g_disableNumbering )
115  {
116  incSymbolCounter();
117  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
118  }
119#else
120  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
121#endif
122  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
123  fflush ( g_hTrace );
124}
125
126Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const TChar *pSymbolName)
127{
128#if RExt__DECODER_DEBUG_BIT_STATISTICS
129  xReadSvlc (rValue, pSymbolName);
130#else
131  xReadSvlc (rValue);
132#endif
133#if NH_MV_ENC_DEC_TRAC
134  if ( g_disableHLSTrace || !g_HLSTraceEnable )
135  {
136    return; 
137  }
138  if ( !g_disableNumbering )
139  { 
140    incSymbolCounter();
141    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
142  }
143#else
144    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
145#endif
146  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
147  fflush ( g_hTrace );
148}
149
150Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const TChar *pSymbolName)
151{
152#if RExt__DECODER_DEBUG_BIT_STATISTICS
153  xReadFlag (rValue, pSymbolName);
154#else
155  xReadFlag (rValue);
156#endif
157#if NH_MV_ENC_DEC_TRAC
158  if ( g_disableHLSTrace || !g_HLSTraceEnable )
159  {
160    return; 
161  }
162  if ( !g_disableNumbering )
163  {
164    incSymbolCounter(); 
165    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
166  }
167#else
168  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
169#endif
170  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
171  fflush ( g_hTrace );
172}
173
174#if NH_MV
175Void  SyntaxElementParser::xReadStringTr        (UInt buSize, UChar *pValue, UInt& rLength, const TChar *pSymbolName)
176{
177#if RExt__DECODER_DEBUG_BIT_STATISTICS
178  xReadString (buSize, pValue, rLength, pSymbolName);
179#else
180  xReadString(buSize, pValue, rLength);
181#endif 
182  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
183  fprintf( g_hTrace, "%-50s st(v=%d)  : %s\n", pSymbolName, rLength, pValue ); 
184  fflush ( g_hTrace );
185}
186#endif
187Void  xTraceAccessUnitDelimiter ()
188{
189  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
190}
191
192Void xTraceFillerData ()
193{
194  fprintf( g_hTrace, "=========== Filler Data ===========\n");
195}
196
197
198// ====================================================================================================================
199// Protected member functions
200// ====================================================================================================================
201#if RExt__DECODER_DEBUG_BIT_STATISTICS
202Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const TChar *pSymbolName)
203#else
204Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
205#endif
206{
207  assert ( uiLength > 0 );
208  m_pcBitstream->read (uiLength, ruiCode);
209#if RExt__DECODER_DEBUG_BIT_STATISTICS
210  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
211#endif
212}
213
214#else
215
216Void SyntaxElementParser::xReadUvlcChk ( UInt&  val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
217{
218  READ_UVLC(val, pSymbolName);
219  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
220}
221
222Void SyntaxElementParser::xReadSvlcChk ( Int&   val, const TChar *pSymbolName, const Int  minValIncl, const Int  maxValIncl )
223{
224  READ_SVLC(val, pSymbolName);
225  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
226}
227
228Void SyntaxElementParser::xReadFlagChk ( UInt&  val, const TChar *pSymbolName, const UInt minValIncl, const UInt maxValIncl )
229{
230  READ_FLAG(val, pSymbolName);
231  TDecConformanceCheck::checkRange(val, pSymbolName, minValIncl, maxValIncl);
232}
233#endif
234#endif
235
236// ====================================================================================================================
237// Protected member functions
238// ====================================================================================================================
239#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
240Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& rValue, const TChar *pSymbolName)
241#else
242Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& rValue)
243#endif
244{
245  assert ( uiLength > 0 );
246  m_pcBitstream->read (uiLength, rValue);
247#if RExt__DECODER_DEBUG_BIT_STATISTICS
248  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, rValue);
249#endif
250#if ENC_DEC_TRACE
251  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
252  if (uiLength < 10)
253  {
254    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, uiLength, rValue );
255  }
256  else
257  {
258    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, uiLength, rValue );
259  }
260  fflush ( g_hTrace );
261#endif
262}
263
264
265#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
266Void SyntaxElementParser::xReadUvlc( UInt& rValue, const TChar *pSymbolName)
267#else
268Void SyntaxElementParser::xReadUvlc( UInt& rValue)
269#endif
270{
271  UInt uiVal = 0;
272  UInt uiCode = 0;
273  UInt uiLength;
274  m_pcBitstream->read( 1, uiCode );
275#if RExt__DECODER_DEBUG_BIT_STATISTICS
276  UInt totalLen=1;
277#endif
278
279  if( 0 == uiCode )
280  {
281    uiLength = 0;
282
283    while( ! ( uiCode & 1 ))
284    {
285      m_pcBitstream->read( 1, uiCode );
286      uiLength++;
287    }
288
289    m_pcBitstream->read( uiLength, uiVal );
290
291    uiVal += (1 << uiLength)-1;
292#if RExt__DECODER_DEBUG_BIT_STATISTICS
293    totalLen+=uiLength+uiLength;
294#endif
295  }
296
297  rValue = uiVal;
298#if RExt__DECODER_DEBUG_BIT_STATISTICS
299  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
300#endif
301
302#if ENC_DEC_TRACE
303  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
304  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
305  fflush ( g_hTrace );
306#endif
307}
308
309#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
310Void SyntaxElementParser::xReadSvlc( Int& rValue, const TChar *pSymbolName)
311#else
312Void SyntaxElementParser::xReadSvlc( Int& rValue)
313#endif
314{
315  UInt uiBits = 0;
316  m_pcBitstream->read( 1, uiBits );
317#if RExt__DECODER_DEBUG_BIT_STATISTICS
318  UInt totalLen=1;
319#endif
320  if( 0 == uiBits )
321  {
322    UInt uiLength = 0;
323
324    while( ! ( uiBits & 1 ))
325    {
326      m_pcBitstream->read( 1, uiBits );
327      uiLength++;
328    }
329
330    m_pcBitstream->read( uiLength, uiBits );
331
332    uiBits += (1 << uiLength);
333    rValue = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
334#if RExt__DECODER_DEBUG_BIT_STATISTICS
335    totalLen+=uiLength+uiLength;
336#endif
337  }
338  else
339  {
340    rValue = 0;
341  }
342#if RExt__DECODER_DEBUG_BIT_STATISTICS
343  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
344#endif
345
346#if ENC_DEC_TRACE
347  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
348  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
349  fflush ( g_hTrace );
350#endif
351
352}
353
354#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
355Void SyntaxElementParser::xReadFlag (UInt& rValue, const TChar *pSymbolName)
356#else
357Void SyntaxElementParser::xReadFlag (UInt& rValue)
358#endif
359{
360  m_pcBitstream->read( 1, rValue );
361#if RExt__DECODER_DEBUG_BIT_STATISTICS
362  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(rValue));
363#endif
364
365#if ENC_DEC_TRACE
366  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
367  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
368  fflush ( g_hTrace );
369#endif
370}
371
372#if NH_MV
373#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
374Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength, const TChar *pSymbolName)
375#else
376Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength )
377#endif
378{
379  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position 
380  UInt val;
381  UInt i;
382  for (i=0 ; i<bufSize ; ++i ) 
383  {
384    m_pcBitstream->readByte( val );
385    pVal[i] = val;
386    if ( val == 0)
387    {
388      break;
389    }
390  }
391  rLength = i;
392  assert( pVal[rLength] == 0 ); 
393}
394#endif
395
396Void SyntaxElementParser::xReadRbspTrailingBits()
397{
398  UInt bit;
399  READ_FLAG( bit, "rbsp_stop_one_bit");
400  assert (bit==1);
401  Int cnt = 0;
402  while (m_pcBitstream->getNumBitsUntilByteAligned())
403  {
404    READ_FLAG( bit, "rbsp_alignment_zero_bit");
405    assert (bit==0);
406    cnt++;
407  }
408  assert(cnt<8);
409}
410
411Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
412{
413  setBitstream(bs);
414
415#if ENC_DEC_TRACE
416  xTraceAccessUnitDelimiter();
417#endif
418
419  READ_CODE (3, picType, "pic_type");
420  xReadRbspTrailingBits();
421}
422
423Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
424{
425  setBitstream(bs);
426#if ENC_DEC_TRACE
427  xTraceFillerData();
428#endif
429  UInt ffByte;
430  fdSize = 0;
431  while( m_pcBitstream->getNumBitsLeft() >8 )
432  {
433    READ_CODE (8, ffByte, "ff_byte");
434    assert (ffByte==0xff);
435    fdSize++;
436  }
437  xReadRbspTrailingBits();
438}
439
440
441//! \}
442
Note: See TracBrowser for help on using the repository browser.