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

Last change on this file since 887 was 872, checked in by tech, 11 years ago

Merged HTM-10.0-dev0@871. (MV-HEVC 7 HLS)

File size: 5.1 KB
RevLine 
[608]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*
[872]6* Copyright (c) 2010-2014, ITU/ISO/IEC
[608]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  xReadCode (length, rValue);
51#if H_MV_ENC_DEC_TRAC
[622]52  if ( g_disableHLSTrace || !g_HLSTraceEnable )
[608]53  {
54    return; 
55  }
56#endif
57  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
58  if (length < 10)
59  {
[655]60    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
[608]61  }
62  else
63  {
[655]64    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
[608]65  }
66  fflush ( g_hTrace );
67}
68
69Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
70{
71  xReadUvlc (rValue);
72#if H_MV_ENC_DEC_TRAC
[622]73  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
[608]74  {
75    return; 
76  }
77#endif
78  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
[655]79  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); 
[608]80  fflush ( g_hTrace );
81}
82
83Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
84{
85  xReadSvlc(rValue);
86#if H_MV_ENC_DEC_TRAC
[622]87  if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
[608]88  {
89    return; 
90  }
91#endif
92  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
93  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue ); 
94  fflush ( g_hTrace );
95}
96
97Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
98{
99  xReadFlag(rValue);
100#if H_MV_ENC_DEC_TRAC
[622]101  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
[608]102  {
103    return; 
104  }
105#endif
106  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
107  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue ); 
108  fflush ( g_hTrace );
109}
110
111#endif
112
113
114// ====================================================================================================================
115// Protected member functions
116// ====================================================================================================================
117
118Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
119{
120  assert ( uiLength > 0 );
121  m_pcBitstream->read (uiLength, ruiCode);
122}
123
124Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
125{
126  UInt uiVal = 0;
127  UInt uiCode = 0;
128  UInt uiLength;
129  m_pcBitstream->read( 1, uiCode );
130
131  if( 0 == uiCode )
132  {
133    uiLength = 0;
134
135    while( ! ( uiCode & 1 ))
136    {
137      m_pcBitstream->read( 1, uiCode );
138      uiLength++;
139    }
140
141    m_pcBitstream->read( uiLength, uiVal );
142
143    uiVal += (1 << uiLength)-1;
144  }
145
146  ruiVal = uiVal;
147}
148
149Void SyntaxElementParser::xReadSvlc( Int& riVal)
150{
151  UInt uiBits = 0;
152  m_pcBitstream->read( 1, uiBits );
153  if( 0 == uiBits )
154  {
155    UInt uiLength = 0;
156
157    while( ! ( uiBits & 1 ))
158    {
159      m_pcBitstream->read( 1, uiBits );
160      uiLength++;
161    }
162
163    m_pcBitstream->read( uiLength, uiBits );
164
165    uiBits += (1 << uiLength);
166    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
167  }
168  else
169  {
170    riVal = 0;
171  }
172}
173
174Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
175{
176  m_pcBitstream->read( 1, ruiCode );
177}
178
179
180//! \}
181
Note: See TracBrowser for help on using the repository browser.