[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 |
---|
[1313] | 4 | * granted under this license. |
---|
[608] | 5 | * |
---|
[1179] | 6 | * Copyright (c) 2010-2015, 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" |
---|
[1313] | 45 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 46 | #include "TLibCommon/TComCodingStatistics.h" |
---|
| 47 | #endif |
---|
[608] | 48 | |
---|
| 49 | #if ENC_DEC_TRACE |
---|
| 50 | |
---|
| 51 | Void SyntaxElementParser::xReadCodeTr (UInt length, UInt& rValue, const Char *pSymbolName) |
---|
| 52 | { |
---|
[1313] | 53 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 54 | xReadCode (length, rValue, pSymbolName); |
---|
| 55 | #else |
---|
[608] | 56 | xReadCode (length, rValue); |
---|
[1313] | 57 | #endif |
---|
[608] | 58 | #if H_MV_ENC_DEC_TRAC |
---|
[622] | 59 | if ( g_disableHLSTrace || !g_HLSTraceEnable ) |
---|
[608] | 60 | { |
---|
| 61 | return; |
---|
| 62 | } |
---|
[1179] | 63 | if ( !g_disableNumbering ) |
---|
| 64 | { |
---|
[1313] | 65 | incSymbolCounter(); |
---|
| 66 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter ); |
---|
[1179] | 67 | } |
---|
[1313] | 68 | #else |
---|
| 69 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
[1179] | 70 | #endif |
---|
[608] | 71 | if (length < 10) |
---|
| 72 | { |
---|
[1313] | 73 | fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); |
---|
[608] | 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
[1313] | 77 | fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); |
---|
[608] | 78 | } |
---|
| 79 | fflush ( g_hTrace ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | Void SyntaxElementParser::xReadUvlcTr (UInt& rValue, const Char *pSymbolName) |
---|
| 83 | { |
---|
[1313] | 84 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 85 | xReadUvlc (rValue, pSymbolName); |
---|
| 86 | #else |
---|
[608] | 87 | xReadUvlc (rValue); |
---|
[1313] | 88 | #endif |
---|
[608] | 89 | #if H_MV_ENC_DEC_TRAC |
---|
[1313] | 90 | if ( g_disableHLSTrace || !g_HLSTraceEnable ) |
---|
[608] | 91 | { |
---|
| 92 | return; |
---|
| 93 | } |
---|
[1179] | 94 | if ( !g_disableNumbering ) |
---|
| 95 | { |
---|
[1313] | 96 | incSymbolCounter(); |
---|
| 97 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter ); |
---|
| 98 | } |
---|
| 99 | #else |
---|
[608] | 100 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
[1179] | 101 | #endif |
---|
[1313] | 102 | fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); |
---|
[608] | 103 | fflush ( g_hTrace ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | Void SyntaxElementParser::xReadSvlcTr (Int& rValue, const Char *pSymbolName) |
---|
| 107 | { |
---|
[1313] | 108 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 109 | xReadSvlc (rValue, pSymbolName); |
---|
| 110 | #else |
---|
| 111 | xReadSvlc (rValue); |
---|
| 112 | #endif |
---|
[608] | 113 | #if H_MV_ENC_DEC_TRAC |
---|
[1313] | 114 | if ( g_disableHLSTrace || !g_HLSTraceEnable ) |
---|
[608] | 115 | { |
---|
| 116 | return; |
---|
| 117 | } |
---|
[1179] | 118 | if ( !g_disableNumbering ) |
---|
[1313] | 119 | { |
---|
| 120 | incSymbolCounter(); |
---|
| 121 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter ); |
---|
[1179] | 122 | } |
---|
[1313] | 123 | #else |
---|
| 124 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
[1179] | 125 | #endif |
---|
[1313] | 126 | fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue ); |
---|
[608] | 127 | fflush ( g_hTrace ); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | Void SyntaxElementParser::xReadFlagTr (UInt& rValue, const Char *pSymbolName) |
---|
| 131 | { |
---|
[1313] | 132 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 133 | xReadFlag (rValue, pSymbolName); |
---|
| 134 | #else |
---|
| 135 | xReadFlag (rValue); |
---|
| 136 | #endif |
---|
[608] | 137 | #if H_MV_ENC_DEC_TRAC |
---|
[1313] | 138 | if ( g_disableHLSTrace || !g_HLSTraceEnable ) |
---|
[608] | 139 | { |
---|
| 140 | return; |
---|
| 141 | } |
---|
[1179] | 142 | if ( !g_disableNumbering ) |
---|
| 143 | { |
---|
[1313] | 144 | incSymbolCounter(); |
---|
| 145 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter ); |
---|
| 146 | } |
---|
| 147 | #else |
---|
[608] | 148 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
[1179] | 149 | #endif |
---|
[1313] | 150 | fprintf( g_hTrace, "%-50s u(1) : %d\n", pSymbolName, rValue ); |
---|
[608] | 151 | fflush ( g_hTrace ); |
---|
| 152 | } |
---|
| 153 | |
---|
[1342] | 154 | Void SyntaxElementParser::xReadStringTr (UInt buSize, UChar *pValue, UInt& rLength, const Char *pSymbolName) |
---|
| 155 | { |
---|
| 156 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 157 | xReadString (buSize, pValue, rLength, pSymbolName); |
---|
| 158 | #else |
---|
| 159 | xReadString(buSize, pValue, rLength); |
---|
| 160 | #endif |
---|
| 161 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
| 162 | fprintf( g_hTrace, "%-50s st(v=%d) : %s\n", pSymbolName, rLength, pValue ); |
---|
| 163 | fflush ( g_hTrace ); |
---|
| 164 | } |
---|
| 165 | |
---|
[1313] | 166 | Void xTraceAccessUnitDelimiter () |
---|
| 167 | { |
---|
| 168 | fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n"); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | Void xTraceFillerData () |
---|
| 172 | { |
---|
| 173 | fprintf( g_hTrace, "=========== Filler Data ===========\n"); |
---|
| 174 | } |
---|
| 175 | |
---|
[608] | 176 | #endif |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | // ==================================================================================================================== |
---|
| 180 | // Protected member functions |
---|
| 181 | // ==================================================================================================================== |
---|
[1313] | 182 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 183 | Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode, const Char *pSymbolName) |
---|
| 184 | #else |
---|
[608] | 185 | Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode) |
---|
[1313] | 186 | #endif |
---|
[608] | 187 | { |
---|
| 188 | assert ( uiLength > 0 ); |
---|
| 189 | m_pcBitstream->read (uiLength, ruiCode); |
---|
[1313] | 190 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 191 | TComCodingStatistics::IncrementStatisticEP(pSymbolName, uiLength, ruiCode); |
---|
| 192 | #endif |
---|
[608] | 193 | } |
---|
| 194 | |
---|
[1313] | 195 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 196 | Void SyntaxElementParser::xReadUvlc( UInt& ruiVal, const Char *pSymbolName) |
---|
| 197 | #else |
---|
[608] | 198 | Void SyntaxElementParser::xReadUvlc( UInt& ruiVal) |
---|
[1313] | 199 | #endif |
---|
[608] | 200 | { |
---|
| 201 | UInt uiVal = 0; |
---|
| 202 | UInt uiCode = 0; |
---|
| 203 | UInt uiLength; |
---|
| 204 | m_pcBitstream->read( 1, uiCode ); |
---|
[1313] | 205 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 206 | UInt totalLen=1; |
---|
| 207 | #endif |
---|
[608] | 208 | |
---|
| 209 | if( 0 == uiCode ) |
---|
| 210 | { |
---|
| 211 | uiLength = 0; |
---|
| 212 | |
---|
| 213 | while( ! ( uiCode & 1 )) |
---|
| 214 | { |
---|
| 215 | m_pcBitstream->read( 1, uiCode ); |
---|
| 216 | uiLength++; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | m_pcBitstream->read( uiLength, uiVal ); |
---|
| 220 | |
---|
| 221 | uiVal += (1 << uiLength)-1; |
---|
[1313] | 222 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 223 | totalLen+=uiLength+uiLength; |
---|
| 224 | #endif |
---|
[608] | 225 | } |
---|
| 226 | |
---|
| 227 | ruiVal = uiVal; |
---|
[1313] | 228 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 229 | TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), ruiVal); |
---|
| 230 | #endif |
---|
[608] | 231 | } |
---|
| 232 | |
---|
[1313] | 233 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 234 | Void SyntaxElementParser::xReadSvlc( Int& riVal, const Char *pSymbolName) |
---|
| 235 | #else |
---|
[608] | 236 | Void SyntaxElementParser::xReadSvlc( Int& riVal) |
---|
[1313] | 237 | #endif |
---|
[608] | 238 | { |
---|
| 239 | UInt uiBits = 0; |
---|
| 240 | m_pcBitstream->read( 1, uiBits ); |
---|
[1313] | 241 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 242 | UInt totalLen=1; |
---|
| 243 | #endif |
---|
[608] | 244 | if( 0 == uiBits ) |
---|
| 245 | { |
---|
| 246 | UInt uiLength = 0; |
---|
| 247 | |
---|
| 248 | while( ! ( uiBits & 1 )) |
---|
| 249 | { |
---|
| 250 | m_pcBitstream->read( 1, uiBits ); |
---|
| 251 | uiLength++; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | m_pcBitstream->read( uiLength, uiBits ); |
---|
| 255 | |
---|
| 256 | uiBits += (1 << uiLength); |
---|
| 257 | riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1); |
---|
[1313] | 258 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 259 | totalLen+=uiLength+uiLength; |
---|
| 260 | #endif |
---|
[608] | 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | riVal = 0; |
---|
| 265 | } |
---|
[1313] | 266 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 267 | TComCodingStatistics::IncrementStatisticEP(pSymbolName, Int(totalLen), riVal); |
---|
| 268 | #endif |
---|
[608] | 269 | } |
---|
| 270 | |
---|
[1313] | 271 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 272 | Void SyntaxElementParser::xReadFlag (UInt& ruiCode, const Char *pSymbolName) |
---|
| 273 | #else |
---|
[608] | 274 | Void SyntaxElementParser::xReadFlag (UInt& ruiCode) |
---|
[1313] | 275 | #endif |
---|
[608] | 276 | { |
---|
| 277 | m_pcBitstream->read( 1, ruiCode ); |
---|
[1313] | 278 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 279 | TComCodingStatistics::IncrementStatisticEP(pSymbolName, 1, Int(ruiCode)); |
---|
| 280 | #endif |
---|
[608] | 281 | } |
---|
| 282 | |
---|
[1342] | 283 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 284 | Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength, const Char *pSymbolName) |
---|
| 285 | #else |
---|
| 286 | Void SyntaxElementParser::xReadString (UInt bufSize, UChar *pVal, UInt& rLength) |
---|
| 287 | #endif |
---|
| 288 | { |
---|
| 289 | assert( m_pcBitstream->getNumBitsRead() % 8 == 0 ); //always start reading at a byte-aligned position |
---|
| 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 | |
---|
[1313] | 305 | Void SyntaxElementParser::xReadRbspTrailingBits() |
---|
| 306 | { |
---|
| 307 | UInt bit; |
---|
| 308 | READ_FLAG( bit, "rbsp_stop_one_bit"); |
---|
| 309 | assert (bit==1); |
---|
| 310 | Int cnt = 0; |
---|
| 311 | while (m_pcBitstream->getNumBitsUntilByteAligned()) |
---|
| 312 | { |
---|
| 313 | READ_FLAG( bit, "rbsp_alignment_zero_bit"); |
---|
| 314 | assert (bit==0); |
---|
| 315 | cnt++; |
---|
| 316 | } |
---|
| 317 | assert(cnt<8); |
---|
| 318 | } |
---|
[608] | 319 | |
---|
[1313] | 320 | Void AUDReader::parseAccessUnitDelimiter(TComInputBitstream* bs, UInt &picType) |
---|
| 321 | { |
---|
| 322 | setBitstream(bs); |
---|
| 323 | |
---|
| 324 | #if ENC_DEC_TRACE |
---|
| 325 | xTraceAccessUnitDelimiter(); |
---|
| 326 | #endif |
---|
| 327 | |
---|
| 328 | READ_CODE (3, picType, "pic_type"); |
---|
| 329 | xReadRbspTrailingBits(); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | Void FDReader::parseFillerData(TComInputBitstream* bs, UInt &fdSize) |
---|
| 333 | { |
---|
| 334 | setBitstream(bs); |
---|
| 335 | #if ENC_DEC_TRACE |
---|
| 336 | xTraceFillerData(); |
---|
| 337 | #endif |
---|
| 338 | UInt ffByte; |
---|
| 339 | fdSize = 0; |
---|
| 340 | while( m_pcBitstream->getNumBitsLeft() >8 ) |
---|
| 341 | { |
---|
| 342 | READ_CODE (8, ffByte, "ff_byte"); |
---|
| 343 | assert (ffByte==0xff); |
---|
| 344 | fdSize++; |
---|
| 345 | } |
---|
| 346 | xReadRbspTrailingBits(); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | |
---|
[608] | 350 | //! \} |
---|
| 351 | |
---|