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

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

replaced Char with TChar

  • Property svn:eol-style set to native
File size: 8.4 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
[1442]51Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const TChar *pSymbolName)
[313]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
[1442]70Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const TChar *pSymbolName)
[313]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
[1442]82Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const TChar *pSymbolName)
[313]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
[1442]94Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const TChar *pSymbolName)
[313]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
[1351]106Void  xTraceAccessUnitDelimiter ()
107{
108  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
109}
110
111Void xTraceFillerData ()
112{
113  fprintf( g_hTrace, "=========== Filler Data ===========\n");
114}
115
[912]116#if Q0096_OVERLAY_SEI
[1457]117Void SyntaxElementParser::xReadStringTr( UInt buSize, UChar *pValue, UInt& rLength, const TChar *pSymbolName )
[912]118{
[1042]119#if RExt__DECODER_DEBUG_BIT_STATISTICS
120  xReadString(buSize, pValue, rLength, pSymbolName);
121#else
[912]122  xReadString(buSize, pValue, rLength);
[1042]123#endif
[912]124  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
125  fprintf( g_hTrace, "%-50s st(v=%d)  : %s\n", pSymbolName, rLength, pValue );
126  fflush ( g_hTrace );
127}
[313]128#endif
129
[912]130#endif
[313]131
[912]132
[313]133// ====================================================================================================================
134// Protected member functions
135// ====================================================================================================================
[1029]136#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1442]137Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const TChar *pSymbolName)
[1029]138#else
[313]139Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
[1029]140#endif
[313]141{
142  assert ( uiLength > 0 );
143  m_pcBitstream->read (uiLength, ruiCode);
[1029]144#if RExt__DECODER_DEBUG_BIT_STATISTICS
145  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
146#endif
[313]147}
148
[1029]149#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1442]150Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const TChar *pSymbolName)
[1029]151#else
[313]152Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
[1029]153#endif
[313]154{
155  UInt uiVal = 0;
156  UInt uiCode = 0;
157  UInt uiLength;
158  m_pcBitstream->read( 1, uiCode );
[1029]159#if RExt__DECODER_DEBUG_BIT_STATISTICS
160  UInt totalLen=1;
161#endif
[313]162
163  if( 0 == uiCode )
164  {
165    uiLength = 0;
166
167    while( ! ( uiCode & 1 ))
168    {
169      m_pcBitstream->read( 1, uiCode );
170      uiLength++;
171    }
172
173    m_pcBitstream->read( uiLength, uiVal );
174
175    uiVal += (1 << uiLength)-1;
[1029]176#if RExt__DECODER_DEBUG_BIT_STATISTICS
177    totalLen+=uiLength+uiLength;
178#endif
[313]179  }
180
181  ruiVal = uiVal;
[1029]182#if RExt__DECODER_DEBUG_BIT_STATISTICS
183  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
184#endif
[313]185}
186
[1029]187#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1442]188Void SyntaxElementParser::xReadSvlc( Int& riVal, const TChar *pSymbolName)
[1029]189#else
[313]190Void SyntaxElementParser::xReadSvlc( Int& riVal)
[1029]191#endif
[313]192{
193  UInt uiBits = 0;
194  m_pcBitstream->read( 1, uiBits );
[1029]195#if RExt__DECODER_DEBUG_BIT_STATISTICS
196  UInt totalLen=1;
197#endif
[313]198  if( 0 == uiBits )
199  {
200    UInt uiLength = 0;
201
202    while( ! ( uiBits & 1 ))
203    {
204      m_pcBitstream->read( 1, uiBits );
205      uiLength++;
206    }
207
208    m_pcBitstream->read( uiLength, uiBits );
209
210    uiBits += (1 << uiLength);
211    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
[1029]212#if RExt__DECODER_DEBUG_BIT_STATISTICS
213    totalLen+=uiLength+uiLength;
214#endif
[313]215  }
216  else
217  {
218    riVal = 0;
219  }
[1029]220#if RExt__DECODER_DEBUG_BIT_STATISTICS
221  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
222#endif
[313]223}
224
[1029]225#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1442]226Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const TChar *pSymbolName)
[1029]227#else
[313]228Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
[1029]229#endif
[313]230{
231  m_pcBitstream->read( 1, ruiCode );
[1029]232#if RExt__DECODER_DEBUG_BIT_STATISTICS
233  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
234#endif
[313]235}
236
[1351]237Void SyntaxElementParser::xReadRbspTrailingBits()
238{
239  UInt bit;
240  READ_FLAG( bit, "rbsp_stop_one_bit");
241  assert (bit==1);
242  Int cnt = 0;
243  while (m_pcBitstream->getNumBitsUntilByteAligned())
244  {
245    READ_FLAG( bit, "rbsp_alignment_zero_bit");
246    assert (bit==0);
247    cnt++;
248  }
249  assert(cnt<8);
250}
251
252Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
253{
254  setBitstream(bs);
255
256#if ENC_DEC_TRACE
257  xTraceAccessUnitDelimiter();
258#endif
259
260  READ_CODE (3, picType, "pic_type");
261  xReadRbspTrailingBits();
262}
263
264Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
265{
266  setBitstream(bs);
267#if ENC_DEC_TRACE
268  xTraceFillerData();
269#endif
270  UInt ffByte;
271  fdSize = 0;
272  while( m_pcBitstream->getNumBitsLeft() >8 )
273  {
274    READ_CODE (8, ffByte, "ff_byte");
275    assert (ffByte==0xff);
276    fdSize++;
277  }
278  xReadRbspTrailingBits();
279}
280
[912]281#if Q0096_OVERLAY_SEI
[1029]282#if RExt__DECODER_DEBUG_BIT_STATISTICS
[1442]283Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength, const TChar *pSymbolName)
[1029]284#else
285Void  SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength)
286#endif
[912]287{
288  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position
289  assert ( bufSize > 1 ); //last byte always used for null-termination
290  UInt val;
291  UInt i;
292  for (i=0 ; i<bufSize ; ++i ) 
293  {
294    m_pcBitstream->readByte( val );
295    pVal[i] = val;
296    if ( val == 0)
297    {
298      break;
299    }
300  }
301  rLength = i;
302  assert( pVal[rLength] == 0 );
303}
304#endif
[313]305
306//! \}
307
Note: See TracBrowser for help on using the repository browser.