source: 3DVCSoftware/branches/HTM-14.1-update-dev2-Orange/source/Lib/TLibDecoder/SyntaxElementParser.cpp

Last change on this file 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
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-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
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  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#if H_MV_ENC_DEC_TRAC
59  if ( g_disableHLSTrace || !g_HLSTraceEnable )
60  {
61    return; 
62  }
63  if ( !g_disableNumbering )
64  {
65#endif
66  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
67#if H_MV_ENC_DEC_TRAC
68  }
69#endif
70  if (length < 10)
71  {
72    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
73  }
74  else
75  {
76    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
77  }
78  fflush ( g_hTrace );
79}
80
81Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
82{
83#if RExt__DECODER_DEBUG_BIT_STATISTICS
84  xReadUvlc (rValue, pSymbolName);
85#else
86  xReadUvlc (rValue);
87#endif
88#if H_MV_ENC_DEC_TRAC
89  if ( g_disableHLSTrace || !g_HLSTraceEnable )
90  {
91    return; 
92  }
93  if ( !g_disableNumbering )
94  {
95#endif
96  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
97#if H_MV_ENC_DEC_TRAC
98  }
99#endif
100  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
101  fflush ( g_hTrace );
102}
103
104Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
105{
106#if RExt__DECODER_DEBUG_BIT_STATISTICS
107  xReadSvlc (rValue, pSymbolName);
108#else
109  xReadSvlc (rValue);
110#endif
111#if H_MV_ENC_DEC_TRAC
112  if ( g_disableHLSTrace || !g_HLSTraceEnable )
113  {
114    return; 
115  }
116  if ( !g_disableNumbering )
117  {
118#endif
119  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
120#if H_MV_ENC_DEC_TRAC
121  }
122#endif
123  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
124  fflush ( g_hTrace );
125}
126
127Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
128{
129#if RExt__DECODER_DEBUG_BIT_STATISTICS
130  xReadFlag (rValue, pSymbolName);
131#else
132  xReadFlag (rValue);
133#endif
134#if H_MV_ENC_DEC_TRAC
135  if ( g_disableHLSTrace || !g_HLSTraceEnable )
136  {
137    return; 
138  }
139  if ( !g_disableNumbering )
140  {
141#endif
142  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
143#if H_MV_ENC_DEC_TRAC
144  }
145#endif
146  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
147  fflush ( g_hTrace );
148}
149
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
160#endif
161
162
163// ====================================================================================================================
164// Protected member functions
165// ====================================================================================================================
166#if RExt__DECODER_DEBUG_BIT_STATISTICS
167Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
168#else
169Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
170#endif
171{
172  assert ( uiLength > 0 );
173  m_pcBitstream->read (uiLength, ruiCode);
174#if RExt__DECODER_DEBUG_BIT_STATISTICS
175  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
176#endif
177}
178
179#if RExt__DECODER_DEBUG_BIT_STATISTICS
180Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
181#else
182Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
183#endif
184{
185  UInt uiVal = 0;
186  UInt uiCode = 0;
187  UInt uiLength;
188  m_pcBitstream->read( 1, uiCode );
189#if RExt__DECODER_DEBUG_BIT_STATISTICS
190  UInt totalLen=1;
191#endif
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;
206#if RExt__DECODER_DEBUG_BIT_STATISTICS
207    totalLen+=uiLength+uiLength;
208#endif
209  }
210
211  ruiVal = uiVal;
212#if RExt__DECODER_DEBUG_BIT_STATISTICS
213  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
214#endif
215}
216
217#if RExt__DECODER_DEBUG_BIT_STATISTICS
218Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
219#else
220Void SyntaxElementParser::xReadSvlc( Int& riVal)
221#endif
222{
223  UInt uiBits = 0;
224  m_pcBitstream->read( 1, uiBits );
225#if RExt__DECODER_DEBUG_BIT_STATISTICS
226  UInt totalLen=1;
227#endif
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);
242#if RExt__DECODER_DEBUG_BIT_STATISTICS
243    totalLen+=uiLength+uiLength;
244#endif
245  }
246  else
247  {
248    riVal = 0;
249  }
250#if RExt__DECODER_DEBUG_BIT_STATISTICS
251  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
252#endif
253}
254
255#if RExt__DECODER_DEBUG_BIT_STATISTICS
256Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
257#else
258Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
259#endif
260{
261  m_pcBitstream->read( 1, ruiCode );
262#if RExt__DECODER_DEBUG_BIT_STATISTICS
263  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
264#endif
265}
266
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}
281
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
312//! \}
313
Note: See TracBrowser for help on using the repository browser.