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

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

Merged 15.1-dev1@1381.

File size: 9.5 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 TChar *pSymbolName)
52{
53#if RExt__DECODER_DEBUG_BIT_STATISTICS
54  xReadCode (length, rValue, pSymbolName);
55#else
56  xReadCode (length, rValue);
57#endif
58#if NH_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 TChar *pSymbolName)
83{
84#if RExt__DECODER_DEBUG_BIT_STATISTICS
85  xReadUvlc (rValue, pSymbolName);
86#else
87  xReadUvlc (rValue);
88#endif
89#if NH_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 TChar *pSymbolName)
107{
108#if RExt__DECODER_DEBUG_BIT_STATISTICS
109  xReadSvlc (rValue, pSymbolName);
110#else
111  xReadSvlc (rValue);
112#endif
113#if NH_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 TChar *pSymbolName)
131{
132#if RExt__DECODER_DEBUG_BIT_STATISTICS
133  xReadFlag (rValue, pSymbolName);
134#else
135  xReadFlag (rValue);
136#endif
137#if NH_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
154#if NH_MV
155Void  SyntaxElementParser::xReadStringTr        (UInt buSize, UChar *pValue, UInt& rLength, const TChar *pSymbolName)
156{
157#if RExt__DECODER_DEBUG_BIT_STATISTICS
158  xReadString (buSize, pValue, rLength, pSymbolName);
159#else
160  xReadString(buSize, pValue, rLength);
161#endif 
162  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
163  fprintf( g_hTrace, "%-50s st(v=%d)  : %s\n", pSymbolName, rLength, pValue ); 
164  fflush ( g_hTrace );
165}
166#endif
167Void  xTraceAccessUnitDelimiter ()
168{
169  fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n");
170}
171
172Void xTraceFillerData ()
173{
174  fprintf( g_hTrace, "=========== Filler Data ===========\n");
175}
176
177#endif
178
179
180// ====================================================================================================================
181// Protected member functions
182// ====================================================================================================================
183#if RExt__DECODER_DEBUG_BIT_STATISTICS
184Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const TChar *pSymbolName)
185#else
186Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
187#endif
188{
189  assert ( uiLength > 0 );
190  m_pcBitstream->read (uiLength, ruiCode);
191#if RExt__DECODER_DEBUG_BIT_STATISTICS
192  TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode);
193#endif
194}
195
196#if RExt__DECODER_DEBUG_BIT_STATISTICS
197Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const TChar *pSymbolName)
198#else
199Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
200#endif
201{
202  UInt uiVal = 0;
203  UInt uiCode = 0;
204  UInt uiLength;
205  m_pcBitstream->read( 1, uiCode );
206#if RExt__DECODER_DEBUG_BIT_STATISTICS
207  UInt totalLen=1;
208#endif
209
210  if( 0 == uiCode )
211  {
212    uiLength = 0;
213
214    while( ! ( uiCode & 1 ))
215    {
216      m_pcBitstream->read( 1, uiCode );
217      uiLength++;
218    }
219
220    m_pcBitstream->read( uiLength, uiVal );
221
222    uiVal += (1 << uiLength)-1;
223#if RExt__DECODER_DEBUG_BIT_STATISTICS
224    totalLen+=uiLength+uiLength;
225#endif
226  }
227
228  ruiVal = uiVal;
229#if RExt__DECODER_DEBUG_BIT_STATISTICS
230  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal);
231#endif
232}
233
234#if RExt__DECODER_DEBUG_BIT_STATISTICS
235Void SyntaxElementParser::xReadSvlc( Int& riVal, const TChar *pSymbolName)
236#else
237Void SyntaxElementParser::xReadSvlc( Int& riVal)
238#endif
239{
240  UInt uiBits = 0;
241  m_pcBitstream->read( 1, uiBits );
242#if RExt__DECODER_DEBUG_BIT_STATISTICS
243  UInt totalLen=1;
244#endif
245  if( 0 == uiBits )
246  {
247    UInt uiLength = 0;
248
249    while( ! ( uiBits & 1 ))
250    {
251      m_pcBitstream->read( 1, uiBits );
252      uiLength++;
253    }
254
255    m_pcBitstream->read( uiLength, uiBits );
256
257    uiBits += (1 << uiLength);
258    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
259#if RExt__DECODER_DEBUG_BIT_STATISTICS
260    totalLen+=uiLength+uiLength;
261#endif
262  }
263  else
264  {
265    riVal = 0;
266  }
267#if RExt__DECODER_DEBUG_BIT_STATISTICS
268  TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal);
269#endif
270}
271
272#if RExt__DECODER_DEBUG_BIT_STATISTICS
273Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const TChar *pSymbolName)
274#else
275Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
276#endif
277{
278  m_pcBitstream->read( 1, ruiCode );
279#if RExt__DECODER_DEBUG_BIT_STATISTICS
280  TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode));
281#endif
282}
283
284#if NH_MV
285#if RExt__DECODER_DEBUG_BIT_STATISTICS
286Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength, const TChar *pSymbolName)
287#else
288Void  SyntaxElementParser::xReadString  (UInt bufSize, UChar *pVal, UInt& rLength)
289#endif
290{
291  assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position 
292  UInt val;
293  UInt i;
294  for (i=0 ; i<bufSize ; ++i ) 
295  {
296    m_pcBitstream->readByte( val );
297    pVal[i] = val;
298    if ( val == 0)
299    {
300      break;
301    }
302  }
303  rLength = i;
304  assert( pVal[rLength] == 0 ); 
305}
306#endif
307
308Void SyntaxElementParser::xReadRbspTrailingBits()
309{
310  UInt bit;
311  READ_FLAG( bit, "rbsp_stop_one_bit");
312  assert (bit==1);
313  Int cnt = 0;
314  while (m_pcBitstream->getNumBitsUntilByteAligned())
315  {
316    READ_FLAG( bit, "rbsp_alignment_zero_bit");
317    assert (bit==0);
318    cnt++;
319  }
320  assert(cnt<8);
321}
322
323Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType)
324{
325  setBitstream(bs);
326
327#if ENC_DEC_TRACE
328  xTraceAccessUnitDelimiter();
329#endif
330
331  READ_CODE (3, picType, "pic_type");
332  xReadRbspTrailingBits();
333}
334
335Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize)
336{
337  setBitstream(bs);
338#if ENC_DEC_TRACE
339  xTraceFillerData();
340#endif
341  UInt ffByte;
342  fdSize = 0;
343  while( m_pcBitstream->getNumBitsLeft() >8 )
344  {
345    READ_CODE (8, ffByte, "ff_byte");
346    assert (ffByte==0xff);
347    fdSize++;
348  }
349  xReadRbspTrailingBits();
350}
351
352
353//! \}
354
Note: See TracBrowser for help on using the repository browser.