source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp @ 1313

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

File size: 8.4 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-2015, 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#if H_MV_ENC_DEC_TRAC
59  if ( g_disableHLSTrace || !g_HLSTraceEnable )
60  {
61    return; 
62  }
63  if ( !g_disableNumbering )
64  {
65    incSymbolCounter();
66    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
67  }
68#else
69    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
70#endif
71  if (length < 10)
72  {
73    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
74  }
75  else
76  {
77    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
78  }
79  fflush ( g_hTrace );
80}
81
82Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
83{
84#if RExt__DECODER_DEBUG_BIT_STATISTICS
85  xReadUvlc (rValue, pSymbolName);
86#else
87  xReadUvlc (rValue);
88#endif
89#if H_MV_ENC_DEC_TRAC
90  if ( g_disableHLSTrace || !g_HLSTraceEnable )
91  {
92    return; 
93  }
94  if ( !g_disableNumbering )
95  {
96  incSymbolCounter();
97  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
98  }
99#else
100  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
101#endif
102  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
103  fflush ( g_hTrace );
104}
105
106Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
107{
108#if RExt__DECODER_DEBUG_BIT_STATISTICS
109  xReadSvlc (rValue, pSymbolName);
110#else
111  xReadSvlc (rValue);
112#endif
113#if H_MV_ENC_DEC_TRAC
114  if ( g_disableHLSTrace || !g_HLSTraceEnable )
115  {
116    return; 
117  }
118  if ( !g_disableNumbering )
119  { 
120    incSymbolCounter();
121    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
122  }
123#else
124    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
125#endif
126  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue );
127  fflush ( g_hTrace );
128}
129
130Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
131{
132#if RExt__DECODER_DEBUG_BIT_STATISTICS
133  xReadFlag (rValue, pSymbolName);
134#else
135  xReadFlag (rValue);
136#endif
137#if H_MV_ENC_DEC_TRAC
138  if ( g_disableHLSTrace || !g_HLSTraceEnable )
139  {
140    return; 
141  }
142  if ( !g_disableNumbering )
143  {
144    incSymbolCounter(); 
145    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
146  }
147#else
148  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
149#endif
150  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue );
151  fflush ( g_hTrace );
152}
153
154Void  xTraceAccessUnitDelimiter ()
155{
156  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
157}
158
159Void xTraceFillerData ()
160{
161  fprintf( g_hTrace, "=========== Filler Data ===========\n");
162}
163
164#endif
165
166
167// ====================================================================================================================
168// Protected member functions
169// ====================================================================================================================
170#if RExt__DECODER_DEBUG_BIT_STATISTICS
171Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName)
172#else
173Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
174#endif
175{
176  assert ( uiLength > 0 );
177  m_pcBitstream->read (uiLength, ruiCode);
178#if RExt__DECODER_DEBUG_BIT_STATISTICS
179  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
180#endif
181}
182
183#if RExt__DECODER_DEBUG_BIT_STATISTICS
184Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName)
185#else
186Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
187#endif
188{
189  UInt uiVal = 0;
190  UInt uiCode = 0;
191  UInt uiLength;
192  m_pcBitstream->read( 1, uiCode );
193#if RExt__DECODER_DEBUG_BIT_STATISTICS
194  UInt totalLen=1;
195#endif
196
197  if( 0 == uiCode )
198  {
199    uiLength = 0;
200
201    while( ! ( uiCode & 1 ))
202    {
203      m_pcBitstream->read( 1, uiCode );
204      uiLength++;
205    }
206
207    m_pcBitstream->read( uiLength, uiVal );
208
209    uiVal += (1 << uiLength)-1;
210#if RExt__DECODER_DEBUG_BIT_STATISTICS
211    totalLen+=uiLength+uiLength;
212#endif
213  }
214
215  ruiVal = uiVal;
216#if RExt__DECODER_DEBUG_BIT_STATISTICS
217  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
218#endif
219}
220
221#if RExt__DECODER_DEBUG_BIT_STATISTICS
222Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName)
223#else
224Void SyntaxElementParser::xReadSvlc( Int& riVal)
225#endif
226{
227  UInt uiBits = 0;
228  m_pcBitstream->read( 1, uiBits );
229#if RExt__DECODER_DEBUG_BIT_STATISTICS
230  UInt totalLen=1;
231#endif
232  if( 0 == uiBits )
233  {
234    UInt uiLength = 0;
235
236    while( ! ( uiBits & 1 ))
237    {
238      m_pcBitstream->read( 1, uiBits );
239      uiLength++;
240    }
241
242    m_pcBitstream->read( uiLength, uiBits );
243
244    uiBits += (1 << uiLength);
245    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
246#if RExt__DECODER_DEBUG_BIT_STATISTICS
247    totalLen+=uiLength+uiLength;
248#endif
249  }
250  else
251  {
252    riVal = 0;
253  }
254#if RExt__DECODER_DEBUG_BIT_STATISTICS
255  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
256#endif
257}
258
259#if RExt__DECODER_DEBUG_BIT_STATISTICS
260Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName)
261#else
262Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
263#endif
264{
265  m_pcBitstream->read( 1, ruiCode );
266#if RExt__DECODER_DEBUG_BIT_STATISTICS
267  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
268#endif
269}
270
271Void SyntaxElementParser::xReadRbspTrailingBits()
272{
273  UInt bit;
274  READ_FLAG( bit, "rbsp_stop_one_bit");
275  assert (bit==1);
276  Int cnt = 0;
277  while (m_pcBitstream->getNumBitsUntilByteAligned())
278  {
279    READ_FLAG( bit, "rbsp_alignment_zero_bit");
280    assert (bit==0);
281    cnt++;
282  }
283  assert(cnt<8);
284}
285
286Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
287{
288  setBitstream(bs);
289
290#if ENC_DEC_TRACE
291  xTraceAccessUnitDelimiter();
292#endif
293
294  READ_CODE (3, picType, "pic_type");
295  xReadRbspTrailingBits();
296}
297
298Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
299{
300  setBitstream(bs);
301#if ENC_DEC_TRACE
302  xTraceFillerData();
303#endif
304  UInt ffByte;
305  fdSize = 0;
306  while( m_pcBitstream->getNumBitsLeft() >8 )
307  {
308    READ_CODE (8, ffByte, "ff_byte");
309    assert (ffByte==0xff);
310    fdSize++;
311  }
312  xReadRbspTrailingBits();
313}
314
315
316//! \}
317
Note: See TracBrowser for help on using the repository browser.