source: SHVCSoftware/branches/SHM-upgrade/source/Lib/TLibDecoder/SyntaxElementParser.cpp @ 918

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

update make file, add TAppDecoderAnalyser and TLibDecoderAnalyser

  • Property svn:eol-style set to native
File size: 7.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-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  xReadString(buSize, pValue, rLength);
110  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
111  fprintf( g_hTrace, "%-50s st(v=%d)  : %s\n", pSymbolName, rLength, pValue );
112  fflush ( g_hTrace );
113}
114#endif
115
116#endif
117
118
119// ====================================================================================================================
120// Protected member functions
121// ====================================================================================================================
122#if RExt__DECODER_DEBUG_BIT_STATISTICS
123Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
124#else
125Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
126#endif
127{
128  assert ( uiLength > 0 );
129  m_pcBitstream->read (uiLength, ruiCode);
130#if RExt__DECODER_DEBUG_BIT_STATISTICS
131  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
132#endif
133}
134
135#if RExt__DECODER_DEBUG_BIT_STATISTICS
136Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
137#else
138Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
139#endif
140{
141  UInt uiVal = 0;
142  UInt uiCode = 0;
143  UInt uiLength;
144  m_pcBitstream->read( 1, uiCode );
145#if RExt__DECODER_DEBUG_BIT_STATISTICS
146  UInt totalLen=1;
147#endif
148
149  if( 0 == uiCode )
150  {
151    uiLength = 0;
152
153    while( ! ( uiCode & 1 ))
154    {
155      m_pcBitstream->read( 1, uiCode );
156      uiLength++;
157    }
158
159    m_pcBitstream->read( uiLength, uiVal );
160
161    uiVal += (1 << uiLength)-1;
162#if RExt__DECODER_DEBUG_BIT_STATISTICS
163    totalLen+=uiLength+uiLength;
164#endif
165  }
166
167  ruiVal = uiVal;
168#if RExt__DECODER_DEBUG_BIT_STATISTICS
169  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
170#endif
171}
172
173#if RExt__DECODER_DEBUG_BIT_STATISTICS
174Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
175#else
176Void SyntaxElementParser::xReadSvlc( Int& riVal)
177#endif
178{
179  UInt uiBits = 0;
180  m_pcBitstream->read( 1, uiBits );
181#if RExt__DECODER_DEBUG_BIT_STATISTICS
182  UInt totalLen=1;
183#endif
184  if( 0 == uiBits )
185  {
186    UInt uiLength = 0;
187
188    while( ! ( uiBits & 1 ))
189    {
190      m_pcBitstream->read( 1, uiBits );
191      uiLength++;
192    }
193
194    m_pcBitstream->read( uiLength, uiBits );
195
196    uiBits += (1 << uiLength);
197    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
198#if RExt__DECODER_DEBUG_BIT_STATISTICS
199    totalLen+=uiLength+uiLength;
200#endif
201  }
202  else
203  {
204    riVal = 0;
205  }
206#if RExt__DECODER_DEBUG_BIT_STATISTICS
207  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
208#endif
209}
210
211#if RExt__DECODER_DEBUG_BIT_STATISTICS
212Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
213#else
214Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
215#endif
216{
217  m_pcBitstream->read( 1, ruiCode );
218#if RExt__DECODER_DEBUG_BIT_STATISTICS
219  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
220#endif
221}
222
223#if Q0096_OVERLAY_SEI
224#if RExt__DECODER_DEBUG_BIT_STATISTICS
225Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength, const Char *pSymbolName)
226#else
227Void  SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength)
228#endif
229{
230  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position
231  assert ( bufSize > 1 ); //last byte always used for null-termination
232  UInt val;
233  UInt i;
234  for (i=0 ; i<bufSize ; ++i ) 
235  {
236    m_pcBitstream->readByte( val );
237    pVal[i] = val;
238    if ( val == 0)
239    {
240      break;
241    }
242  }
243  rLength = i;
244  assert( pVal[rLength] == 0 );
245}
246#endif
247
248//! \}
249
Note: See TracBrowser for help on using the repository browser.