source: 3DVCSoftware/branches/HTM-14.1-update-dev0/source/Lib/TLibDecoder/SyntaxElementParser.cpp @ 1417

Last change on this file since 1417 was 1200, checked in by tech, 10 years ago

Update to HM-16.5.
Starting point for further re-activation of 3D-tools.

Includes:

active:

  • MV-HEVC
  • 3D-HLS (apart from DLT)
  • VSO

inactive:

  • remaining 3D-HEVC tools.
File size: 8.2 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
[1200]4* granted under this license.
[608]5*
[1179]6* Copyright (c) 2010-2015, 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"
[1200]45#if RExt__DECODER_DEBUG_BIT_STATISTICS
46#include "TLibCommon/TComCodingStatistics.h"
47#endif
[608]48
49#if ENC_DEC_TRACE
50
51Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
52{
[1200]53#if RExt__DECODER_DEBUG_BIT_STATISTICS
54  xReadCode (length, rValue, pSymbolName);
55#else
[608]56  xReadCode (length, rValue);
[1200]57#endif
[608]58#if H_MV_ENC_DEC_TRAC
[622]59  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]60  {
61    return; 
62  }
[1179]63  if ( !g_disableNumbering )
64  {
[608]65#endif
66  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]67#if H_MV_ENC_DEC_TRAC
68  }
69#endif
[608]70  if (length < 10)
71  {
[1200]72    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
[608]73  }
74  else
75  {
[1200]76    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
[608]77  }
78  fflush ( g_hTrace );
79}
80
81Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
82{
[1200]83#if RExt__DECODER_DEBUG_BIT_STATISTICS
84  xReadUvlc (rValue, pSymbolName);
85#else
[608]86  xReadUvlc (rValue);
[1200]87#endif
[608]88#if H_MV_ENC_DEC_TRAC
[1200]89  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]90  {
91    return; 
92  }
[1179]93  if ( !g_disableNumbering )
94  {
[608]95#endif
96  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]97#if H_MV_ENC_DEC_TRAC
98  }
99#endif
[1200]100  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
[608]101  fflush ( g_hTrace );
102}
103
104Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
105{
[1200]106#if RExt__DECODER_DEBUG_BIT_STATISTICS
107  xReadSvlc (rValue, pSymbolName);
108#else
109  xReadSvlc (rValue);
110#endif
[608]111#if H_MV_ENC_DEC_TRAC
[1200]112  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]113  {
114    return; 
115  }
[1179]116  if ( !g_disableNumbering )
117  {
[608]118#endif
119  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]120#if H_MV_ENC_DEC_TRAC
121  }
122#endif
[1200]123  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
[608]124  fflush ( g_hTrace );
125}
126
127Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
128{
[1200]129#if RExt__DECODER_DEBUG_BIT_STATISTICS
130  xReadFlag (rValue, pSymbolName);
131#else
132  xReadFlag (rValue);
133#endif
[608]134#if H_MV_ENC_DEC_TRAC
[1200]135  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]136  {
137    return; 
138  }
[1179]139  if ( !g_disableNumbering )
140  {
[608]141#endif
142  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1179]143#if H_MV_ENC_DEC_TRAC
144  }
145#endif
[1200]146  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
[608]147  fflush ( g_hTrace );
148}
149
[1200]150Void  xTraceAccessUnitDelimiter ()
151{
152  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
153}
154
155Void xTraceFillerData ()
156{
157  fprintf( g_hTrace, "=========== Filler Data ===========\n");
158}
159
[608]160#endif
161
162
163// ====================================================================================================================
164// Protected member functions
165// ====================================================================================================================
[1200]166#if RExt__DECODER_DEBUG_BIT_STATISTICS
167Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
168#else
[608]169Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
[1200]170#endif
[608]171{
172  assert ( uiLength > 0 );
173  m_pcBitstream->read (uiLength, ruiCode);
[1200]174#if RExt__DECODER_DEBUG_BIT_STATISTICS
175  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
176#endif
[608]177}
178
[1200]179#if RExt__DECODER_DEBUG_BIT_STATISTICS
180Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
181#else
[608]182Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
[1200]183#endif
[608]184{
185  UInt uiVal = 0;
186  UInt uiCode = 0;
187  UInt uiLength;
188  m_pcBitstream->read( 1, uiCode );
[1200]189#if RExt__DECODER_DEBUG_BIT_STATISTICS
190  UInt totalLen=1;
191#endif
[608]192
193  if( 0 == uiCode )
194  {
195    uiLength = 0;
196
197    while( ! ( uiCode & 1 ))
198    {
199      m_pcBitstream->read( 1, uiCode );
200      uiLength++;
201    }
202
203    m_pcBitstream->read( uiLength, uiVal );
204
205    uiVal += (1 << uiLength)-1;
[1200]206#if RExt__DECODER_DEBUG_BIT_STATISTICS
207    totalLen+=uiLength+uiLength;
208#endif
[608]209  }
210
211  ruiVal = uiVal;
[1200]212#if RExt__DECODER_DEBUG_BIT_STATISTICS
213  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
214#endif
[608]215}
216
[1200]217#if RExt__DECODER_DEBUG_BIT_STATISTICS
218Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
219#else
[608]220Void SyntaxElementParser::xReadSvlc( Int& riVal)
[1200]221#endif
[608]222{
223  UInt uiBits = 0;
224  m_pcBitstream->read( 1, uiBits );
[1200]225#if RExt__DECODER_DEBUG_BIT_STATISTICS
226  UInt totalLen=1;
227#endif
[608]228  if( 0 == uiBits )
229  {
230    UInt uiLength = 0;
231
232    while( ! ( uiBits & 1 ))
233    {
234      m_pcBitstream->read( 1, uiBits );
235      uiLength++;
236    }
237
238    m_pcBitstream->read( uiLength, uiBits );
239
240    uiBits += (1 << uiLength);
241    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
[1200]242#if RExt__DECODER_DEBUG_BIT_STATISTICS
243    totalLen+=uiLength+uiLength;
244#endif
[608]245  }
246  else
247  {
248    riVal = 0;
249  }
[1200]250#if RExt__DECODER_DEBUG_BIT_STATISTICS
251  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
252#endif
[608]253}
254
[1200]255#if RExt__DECODER_DEBUG_BIT_STATISTICS
256Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
257#else
[608]258Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
[1200]259#endif
[608]260{
261  m_pcBitstream->read( 1, ruiCode );
[1200]262#if RExt__DECODER_DEBUG_BIT_STATISTICS
263  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
264#endif
[608]265}
266
[1200]267Void SyntaxElementParser::xReadRbspTrailingBits()
268{
269  UInt bit;
270  READ_FLAG( bit, "rbsp_stop_one_bit");
271  assert (bit==1);
272  Int cnt = 0;
273  while (m_pcBitstream->getNumBitsUntilByteAligned())
274  {
275    READ_FLAG( bit, "rbsp_alignment_zero_bit");
276    assert (bit==0);
277    cnt++;
278  }
279  assert(cnt<8);
280}
[608]281
[1200]282Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
283{
284  setBitstream(bs);
285
286#if ENC_DEC_TRACE
287  xTraceAccessUnitDelimiter();
288#endif
289
290  READ_CODE (3, picType, "pic_type");
291  xReadRbspTrailingBits();
292}
293
294Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
295{
296  setBitstream(bs);
297#if ENC_DEC_TRACE
298  xTraceFillerData();
299#endif
300  UInt ffByte;
301  fdSize = 0;
302  while( m_pcBitstream->getNumBitsLeft() >8 )
303  {
304    READ_CODE (8, ffByte, "ff_byte");
305    assert (ffByte==0xff);
306    fdSize++;
307  }
308  xReadRbspTrailingBits();
309}
310
311
[608]312//! \}
313
Note: See TracBrowser for help on using the repository browser.