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

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

initial porting

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