source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/SyntaxElementParser.cpp @ 1259

Last change on this file since 1259 was 1259, checked in by seregin, 9 years ago

port rev 4256

  • Property svn:eol-style set to native
File size: 7.3 KB
RevLine 
[313]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
[1029]4* granted under this license.
[313]5*
[1259]6* Copyright (c) 2010-2015, ITU/ISO/IEC
[313]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"
[1029]45#if RExt__DECODER_DEBUG_BIT_STATISTICS
46#include "TLibCommon/TComCodingStatistics.h"
47#endif
[313]48
49#if ENC_DEC_TRACE
50
51Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
52{
[1029]53#if RExt__DECODER_DEBUG_BIT_STATISTICS
54  xReadCode (length, rValue, pSymbolName);
55#else
[313]56  xReadCode (length, rValue);
[1029]57#endif
[313]58  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
59  if (length < 10)
60  {
[1029]61    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
[313]62  }
63  else
64  {
[1246]65    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
[313]66  }
67  fflush ( g_hTrace );
68}
69
70Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
71{
[1029]72#if RExt__DECODER_DEBUG_BIT_STATISTICS
73  xReadUvlc (rValue, pSymbolName);
74#else
[313]75  xReadUvlc (rValue);
[1029]76#endif
[313]77  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1029]78  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
[313]79  fflush ( g_hTrace );
80}
81
82Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
83{
[1029]84#if RExt__DECODER_DEBUG_BIT_STATISTICS
85  xReadSvlc (rValue, pSymbolName);
86#else
87  xReadSvlc (rValue);
88#endif
[313]89  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1029]90  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
[313]91  fflush ( g_hTrace );
92}
93
94Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
95{
[1029]96#if RExt__DECODER_DEBUG_BIT_STATISTICS
97  xReadFlag (rValue, pSymbolName);
98#else
99  xReadFlag (rValue);
100#endif
[313]101  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[1029]102  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
[313]103  fflush ( g_hTrace );
104}
105
[912]106#if Q0096_OVERLAY_SEI
107Void  SyntaxElementParser::xReadStringTr        (UInt buSize, UChar *pValue, UInt& rLength, const Char *pSymbolName)
108{
[1042]109#if RExt__DECODER_DEBUG_BIT_STATISTICS
110  xReadString(buSize, pValue, rLength, pSymbolName);
111#else
[912]112  xReadString(buSize, pValue, rLength);
[1042]113#endif
[912]114  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
115  fprintf( g_hTrace, "%-50s st(v=%d)  : %s\n", pSymbolName, rLength, pValue );
116  fflush ( g_hTrace );
117}
[313]118#endif
119
[912]120#endif
[313]121
[912]122
[313]123// ====================================================================================================================
124// Protected member functions
125// ====================================================================================================================
[1029]126#if RExt__DECODER_DEBUG_BIT_STATISTICS
127Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
128#else
[313]129Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
[1029]130#endif
[313]131{
132  assert ( uiLength > 0 );
133  m_pcBitstream->read (uiLength, ruiCode);
[1029]134#if RExt__DECODER_DEBUG_BIT_STATISTICS
135  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
136#endif
[313]137}
138
[1029]139#if RExt__DECODER_DEBUG_BIT_STATISTICS
140Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
141#else
[313]142Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
[1029]143#endif
[313]144{
145  UInt uiVal = 0;
146  UInt uiCode = 0;
147  UInt uiLength;
148  m_pcBitstream->read( 1, uiCode );
[1029]149#if RExt__DECODER_DEBUG_BIT_STATISTICS
150  UInt totalLen=1;
151#endif
[313]152
153  if( 0 == uiCode )
154  {
155    uiLength = 0;
156
157    while( ! ( uiCode & 1 ))
158    {
159      m_pcBitstream->read( 1, uiCode );
160      uiLength++;
161    }
162
163    m_pcBitstream->read( uiLength, uiVal );
164
165    uiVal += (1 << uiLength)-1;
[1029]166#if RExt__DECODER_DEBUG_BIT_STATISTICS
167    totalLen+=uiLength+uiLength;
168#endif
[313]169  }
170
171  ruiVal = uiVal;
[1029]172#if RExt__DECODER_DEBUG_BIT_STATISTICS
173  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
174#endif
[313]175}
176
[1029]177#if RExt__DECODER_DEBUG_BIT_STATISTICS
178Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
179#else
[313]180Void SyntaxElementParser::xReadSvlc( Int& riVal)
[1029]181#endif
[313]182{
183  UInt uiBits = 0;
184  m_pcBitstream->read( 1, uiBits );
[1029]185#if RExt__DECODER_DEBUG_BIT_STATISTICS
186  UInt totalLen=1;
187#endif
[313]188  if( 0 == uiBits )
189  {
190    UInt uiLength = 0;
191
192    while( ! ( uiBits & 1 ))
193    {
194      m_pcBitstream->read( 1, uiBits );
195      uiLength++;
196    }
197
198    m_pcBitstream->read( uiLength, uiBits );
199
200    uiBits += (1 << uiLength);
201    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
[1029]202#if RExt__DECODER_DEBUG_BIT_STATISTICS
203    totalLen+=uiLength+uiLength;
204#endif
[313]205  }
206  else
207  {
208    riVal = 0;
209  }
[1029]210#if RExt__DECODER_DEBUG_BIT_STATISTICS
211  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
212#endif
[313]213}
214
[1029]215#if RExt__DECODER_DEBUG_BIT_STATISTICS
216Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
217#else
[313]218Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
[1029]219#endif
[313]220{
221  m_pcBitstream->read( 1, ruiCode );
[1029]222#if RExt__DECODER_DEBUG_BIT_STATISTICS
223  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
224#endif
[313]225}
226
[912]227#if Q0096_OVERLAY_SEI
[1029]228#if RExt__DECODER_DEBUG_BIT_STATISTICS
229Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength, const Char *pSymbolName)
230#else
231Void  SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength)
232#endif
[912]233{
234  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position
235  assert ( bufSize > 1 ); //last byte always used for null-termination
236  UInt val;
237  UInt i;
238  for (i=0 ; i<bufSize ; ++i ) 
239  {
240    m_pcBitstream->readByte( val );
241    pVal[i] = val;
242    if ( val == 0)
243    {
244      break;
245    }
246  }
247  rLength = i;
248  assert( pVal[rLength] == 0 );
249}
250#endif
[313]251
252//! \}
253
Note: See TracBrowser for help on using the repository browser.