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

Last change on this file since 1165 was 1042, checked in by seregin, 10 years ago

fix compiler error, ticket #71

  • Property svn:eol-style set to native
File size: 7.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-2014, 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  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
59  if (length < 10)
60  {
61    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
62  }
63  else
64  {
65    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
66  }
67  fflush ( g_hTrace );
68}
69
70Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
71{
72#if RExt__DECODER_DEBUG_BIT_STATISTICS
73  xReadUvlc (rValue, pSymbolName);
74#else
75  xReadUvlc (rValue);
76#endif
77  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
78  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
79  fflush ( g_hTrace );
80}
81
82Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
83{
84#if RExt__DECODER_DEBUG_BIT_STATISTICS
85  xReadSvlc (rValue, pSymbolName);
86#else
87  xReadSvlc (rValue);
88#endif
89  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
90  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
91  fflush ( g_hTrace );
92}
93
94Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
95{
96#if RExt__DECODER_DEBUG_BIT_STATISTICS
97  xReadFlag (rValue, pSymbolName);
98#else
99  xReadFlag (rValue);
100#endif
101  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
102  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
103  fflush ( g_hTrace );
104}
105
106#if Q0096_OVERLAY_SEI
107Void  SyntaxElementParser::xReadStringTr        (UInt buSize, UChar *pValue, UInt& rLength, const Char *pSymbolName)
108{
109#if RExt__DECODER_DEBUG_BIT_STATISTICS
110  xReadString(buSize, pValue, rLength, pSymbolName);
111#else
112  xReadString(buSize, pValue, rLength);
113#endif
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}
118#endif
119
120#endif
121
122
123// ====================================================================================================================
124// Protected member functions
125// ====================================================================================================================
126#if RExt__DECODER_DEBUG_BIT_STATISTICS
127Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
128#else
129Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
130#endif
131{
132  assert ( uiLength > 0 );
133  m_pcBitstream->read (uiLength, ruiCode);
134#if RExt__DECODER_DEBUG_BIT_STATISTICS
135  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
136#endif
137}
138
139#if RExt__DECODER_DEBUG_BIT_STATISTICS
140Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
141#else
142Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
143#endif
144{
145  UInt uiVal = 0;
146  UInt uiCode = 0;
147  UInt uiLength;
148  m_pcBitstream->read( 1, uiCode );
149#if RExt__DECODER_DEBUG_BIT_STATISTICS
150  UInt totalLen=1;
151#endif
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;
166#if RExt__DECODER_DEBUG_BIT_STATISTICS
167    totalLen+=uiLength+uiLength;
168#endif
169  }
170
171  ruiVal = uiVal;
172#if RExt__DECODER_DEBUG_BIT_STATISTICS
173  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
174#endif
175}
176
177#if RExt__DECODER_DEBUG_BIT_STATISTICS
178Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
179#else
180Void SyntaxElementParser::xReadSvlc( Int& riVal)
181#endif
182{
183  UInt uiBits = 0;
184  m_pcBitstream->read( 1, uiBits );
185#if RExt__DECODER_DEBUG_BIT_STATISTICS
186  UInt totalLen=1;
187#endif
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);
202#if RExt__DECODER_DEBUG_BIT_STATISTICS
203    totalLen+=uiLength+uiLength;
204#endif
205  }
206  else
207  {
208    riVal = 0;
209  }
210#if RExt__DECODER_DEBUG_BIT_STATISTICS
211  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
212#endif
213}
214
215#if RExt__DECODER_DEBUG_BIT_STATISTICS
216Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
217#else
218Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
219#endif
220{
221  m_pcBitstream->read( 1, ruiCode );
222#if RExt__DECODER_DEBUG_BIT_STATISTICS
223  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
224#endif
225}
226
227#if Q0096_OVERLAY_SEI
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
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
251
252//! \}
253
Note: See TracBrowser for help on using the repository browser.