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
RevLine 
[608]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
[1313]4* granted under this license.
[608]5*
[1413]6* Copyright (c) 2010-2017, ITU/ISO/IEC
[608]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"
[1313]45#if RExt__DECODER_DEBUG_BIT_STATISTICS
46#include "TLibCommon/TComCodingStatistics.h"
47#endif
[608]48
49#if ENC_DEC_TRACE
50
[1413]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
[1386]71Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const TChar *pSymbolName)
[608]72{
[1313]73#if RExt__DECODER_DEBUG_BIT_STATISTICS
74  xReadCode (length, rValue, pSymbolName);
75#else
[608]76  xReadCode (length, rValue);
[1313]77#endif
[1386]78#if NH_MV_ENC_DEC_TRAC
[622]79  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]80  {
81    return; 
82  }
[1179]83  if ( !g_disableNumbering )
84  {
[1313]85    incSymbolCounter();
86    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
[1179]87  }
[1313]88#else
89    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]90#endif
[608]91  if (length < 10)
92  {
[1313]93    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
[608]94  }
95  else
96  {
[1313]97    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
[608]98  }
99  fflush ( g_hTrace );
100}
101
[1386]102Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const TChar *pSymbolName)
[608]103{
[1313]104#if RExt__DECODER_DEBUG_BIT_STATISTICS
105  xReadUvlc (rValue, pSymbolName);
106#else
[608]107  xReadUvlc (rValue);
[1313]108#endif
[1386]109#if NH_MV_ENC_DEC_TRAC
[1313]110  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]111  {
112    return; 
113  }
[1179]114  if ( !g_disableNumbering )
115  {
[1313]116  incSymbolCounter();
117  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
118  }
119#else
[608]120  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]121#endif
[1313]122  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
[608]123  fflush ( g_hTrace );
124}
125
[1386]126Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const TChar *pSymbolName)
[608]127{
[1313]128#if RExt__DECODER_DEBUG_BIT_STATISTICS
129  xReadSvlc (rValue, pSymbolName);
130#else
131  xReadSvlc (rValue);
132#endif
[1386]133#if NH_MV_ENC_DEC_TRAC
[1313]134  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]135  {
136    return; 
137  }
[1179]138  if ( !g_disableNumbering )
[1313]139  { 
140    incSymbolCounter();
141    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
[1179]142  }
[1313]143#else
144    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]145#endif
[1313]146  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
[608]147  fflush ( g_hTrace );
148}
149
[1386]150Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const TChar *pSymbolName)
[608]151{
[1313]152#if RExt__DECODER_DEBUG_BIT_STATISTICS
153  xReadFlag (rValue, pSymbolName);
154#else
155  xReadFlag (rValue);
156#endif
[1386]157#if NH_MV_ENC_DEC_TRAC
[1313]158  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]159  {
160    return; 
161  }
[1179]162  if ( !g_disableNumbering )
163  {
[1313]164    incSymbolCounter(); 
165    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
166  }
167#else
[608]168  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]169#endif
[1313]170  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
[608]171  fflush ( g_hTrace );
172}
173
[1386]174#if NH_MV
175Void  SyntaxElementParser::xReadStringTr        (UInt buSize, UChar *pValue, UInt& rLength, const TChar *pSymbolName)
[1356]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}
[1386]186#endif
[1313]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
[608]197
198// ====================================================================================================================
199// Protected member functions
200// ====================================================================================================================
[1313]201#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1386]202Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const TChar *pSymbolName)
[1313]203#else
[608]204Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
[1313]205#endif
[608]206{
207  assert ( uiLength > 0 );
208  m_pcBitstream->read (uiLength, ruiCode);
[1313]209#if RExt__DECODER_DEBUG_BIT_STATISTICS
210  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
211#endif
[608]212}
213
[1413]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);
[1313]247#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1413]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)
[1313]267#else
[1413]268Void SyntaxElementParser::xReadUvlc( UInt& rValue)
[1313]269#endif
[608]270{
271  UInt uiVal = 0;
272  UInt uiCode = 0;
273  UInt uiLength;
274  m_pcBitstream->read( 1, uiCode );
[1313]275#if RExt__DECODER_DEBUG_BIT_STATISTICS
276  UInt totalLen=1;
277#endif
[608]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;
[1313]292#if RExt__DECODER_DEBUG_BIT_STATISTICS
293    totalLen+=uiLength+uiLength;
294#endif
[608]295  }
296
[1413]297  rValue = uiVal;
[1313]298#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1413]299  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
[1313]300#endif
[1413]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
[608]307}
308
[1413]309#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
310Void SyntaxElementParser::xReadSvlc( Int& rValue, const TChar *pSymbolName)
[1313]311#else
[1413]312Void SyntaxElementParser::xReadSvlc( Int& rValue)
[1313]313#endif
[608]314{
315  UInt uiBits = 0;
316  m_pcBitstream->read( 1, uiBits );
[1313]317#if RExt__DECODER_DEBUG_BIT_STATISTICS
318  UInt totalLen=1;
319#endif
[608]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);
[1413]333    rValue = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
[1313]334#if RExt__DECODER_DEBUG_BIT_STATISTICS
335    totalLen+=uiLength+uiLength;
336#endif
[608]337  }
338  else
339  {
[1413]340    rValue = 0;
[608]341  }
[1313]342#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1413]343  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), rValue);
[1313]344#endif
[1413]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
[608]352}
353
[1413]354#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
355Void SyntaxElementParser::xReadFlag (UInt& rValue, const TChar *pSymbolName)
[1313]356#else
[1413]357Void SyntaxElementParser::xReadFlag (UInt& rValue)
[1313]358#endif
[608]359{
[1413]360  m_pcBitstream->read( 1, rValue );
[1313]361#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1413]362  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(rValue));
[1313]363#endif
[1413]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
[608]370}
371
[1386]372#if NH_MV
[1413]373#if RExt__DECODER_DEBUG_BIT_STATISTICS || ENC_DEC_TRACE
[1386]374Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength, const TChar *pSymbolName)
[1356]375#else
[1413]376Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength )
[1356]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}
[1386]394#endif
[1356]395
[1313]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}
[608]410
[1313]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
[608]441//! \}
442
Note: See TracBrowser for help on using the repository browser.