Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
r1179 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 37 37 38 38 #include "TDecBinCoderCABAC.h" 39 #include "../TLibCommon/TComRom.h" 39 #include "TLibCommon/Debug.h" 40 #if RExt__DECODER_DEBUG_BIT_STATISTICS 41 #include "TLibCommon/TComCodingStatistics.h" 42 #endif 40 43 41 44 //! \ingroup TLibDecoder … … 67 70 { 68 71 assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 ); 72 #if RExt__DECODER_DEBUG_BIT_STATISTICS 73 TComCodingStatistics::UpdateCABACStat(STATS__CABAC_INITIALISATION, 512, 510, 0); 74 #endif 69 75 m_uiRange = 510; 70 76 m_bitsNeeded = -8; … … 89 95 */ 90 96 Void 91 TDecBinCABAC::copyState( TDecBinIf* pcTDecBinIf )92 { 93 TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();97 TDecBinCABAC::copyState( const TDecBinIf* pcTDecBinIf ) 98 { 99 const TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC(); 94 100 m_uiRange = pcTDecBinCABAC->m_uiRange; 95 101 m_uiValue = pcTDecBinCABAC->m_uiValue; … … 98 104 99 105 100 Void 101 TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel ) 102 { 106 107 #if RExt__DECODER_DEBUG_BIT_STATISTICS 108 Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel, const TComCodingStatisticsClassType &whichStat ) 109 #else 110 Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel ) 111 #endif 112 { 113 #if DEBUG_CABAC_BINS 114 const UInt startingRange = m_uiRange; 115 #endif 116 103 117 UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) - 4 ]; 104 118 m_uiRange -= uiLPS; 105 119 UInt scaledRange = m_uiRange << 7; 106 120 107 121 if( m_uiValue < scaledRange ) 108 122 { 109 123 // MPS path 110 124 ruiBin = rcCtxModel.getMps(); 125 #if RExt__DECODER_DEBUG_BIT_STATISTICS 126 TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, m_uiRange, Int(ruiBin)); 127 #endif 111 128 rcCtxModel.updateMPS(); 112 113 if ( scaledRange >= ( 256 << 7 ) ) 114 { 115 return; 116 } 117 118 m_uiRange = scaledRange >> 6; 119 m_uiValue += m_uiValue; 120 121 if ( ++m_bitsNeeded == 0 ) 122 { 123 m_bitsNeeded = -8; 124 m_uiValue += m_pcTComBitstream->readByte(); 129 130 if ( scaledRange < ( 256 << 7 ) ) 131 { 132 m_uiRange = scaledRange >> 6; 133 m_uiValue += m_uiValue; 134 135 if ( ++m_bitsNeeded == 0 ) 136 { 137 m_bitsNeeded = -8; 138 m_uiValue += m_pcTComBitstream->readByte(); 139 } 125 140 } 126 141 } … … 128 143 { 129 144 // LPS path 145 ruiBin = 1 - rcCtxModel.getMps(); 146 #if RExt__DECODER_DEBUG_BIT_STATISTICS 147 TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, uiLPS, Int(ruiBin)); 148 #endif 130 149 Int numBits = TComCABACTables::sm_aucRenormTable[ uiLPS >> 3 ]; 131 150 m_uiValue = ( m_uiValue - scaledRange ) << numBits; 132 151 m_uiRange = uiLPS << numBits; 133 ruiBin = 1 - rcCtxModel.getMps();134 152 rcCtxModel.updateLPS(); 135 153 136 154 m_bitsNeeded += numBits; 137 155 138 156 if ( m_bitsNeeded >= 0 ) 139 157 { … … 142 160 } 143 161 } 144 } 145 146 Void 147 TDecBinCABAC::decodeBinEP( UInt& ruiBin ) 148 { 162 163 #if DEBUG_CABAC_BINS 164 if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine) 165 { 166 std::cout << g_debugCounter << ": coding bin value " << ruiBin << ", range = [" << startingRange << "->" << m_uiRange << "]\n"; 167 } 168 169 if (g_debugCounter >= debugCabacBinTargetLine) 170 { 171 Char breakPointThis; 172 breakPointThis = 7; 173 } 174 if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow)) 175 { 176 exit(0); 177 } 178 g_debugCounter++; 179 #endif 180 } 181 182 183 #if RExt__DECODER_DEBUG_BIT_STATISTICS 184 Void TDecBinCABAC::decodeBinEP( UInt& ruiBin, const TComCodingStatisticsClassType &whichStat ) 185 #else 186 Void TDecBinCABAC::decodeBinEP( UInt& ruiBin ) 187 #endif 188 { 189 if (m_uiRange == 256) 190 { 191 #if RExt__DECODER_DEBUG_BIT_STATISTICS 192 decodeAlignedBinsEP(ruiBin, 1, whichStat); 193 #else 194 decodeAlignedBinsEP(ruiBin, 1); 195 #endif 196 return; 197 } 198 149 199 m_uiValue += m_uiValue; 150 200 151 201 if ( ++m_bitsNeeded >= 0 ) 152 202 { … … 154 204 m_uiValue += m_pcTComBitstream->readByte(); 155 205 } 156 206 157 207 ruiBin = 0; 158 208 UInt scaledRange = m_uiRange << 7; … … 162 212 m_uiValue -= scaledRange; 163 213 } 164 } 165 214 #if RExt__DECODER_DEBUG_BIT_STATISTICS 215 TComCodingStatistics::IncrementStatisticEP(whichStat, 1, Int(ruiBin)); 216 #endif 217 } 218 219 #if RExt__DECODER_DEBUG_BIT_STATISTICS 220 Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins, const TComCodingStatisticsClassType &whichStat ) 221 #else 166 222 Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins ) 167 { 223 #endif 224 { 225 if (m_uiRange == 256) 226 { 227 #if RExt__DECODER_DEBUG_BIT_STATISTICS 228 decodeAlignedBinsEP(ruiBin, numBins, whichStat); 229 #else 230 decodeAlignedBinsEP(ruiBin, numBins); 231 #endif 232 return; 233 } 234 168 235 UInt bins = 0; 169 236 #if RExt__DECODER_DEBUG_BIT_STATISTICS 237 Int origNumBins=numBins; 238 #endif 170 239 while ( numBins > 8 ) 171 240 { 172 241 m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) ); 173 242 174 243 UInt scaledRange = m_uiRange << 15; 175 244 for ( Int i = 0; i < 8; i++ ) … … 185 254 numBins -= 8; 186 255 } 187 256 188 257 m_bitsNeeded += numBins; 189 258 m_uiValue <<= numBins; 190 259 191 260 if ( m_bitsNeeded >= 0 ) 192 261 { … … 194 263 m_bitsNeeded -= 8; 195 264 } 196 265 197 266 UInt scaledRange = m_uiRange << ( numBins + 7 ); 198 267 for ( Int i = 0; i < numBins; i++ ) … … 206 275 } 207 276 } 208 277 209 278 ruiBin = bins; 279 #if RExt__DECODER_DEBUG_BIT_STATISTICS 280 TComCodingStatistics::IncrementStatisticEP(whichStat, origNumBins, Int(ruiBin)); 281 #endif 282 } 283 284 Void TDecBinCABAC::align() 285 { 286 #if RExt__DECODER_DEBUG_BIT_STATISTICS 287 TComCodingStatistics::UpdateCABACStat(STATS__CABAC_EP_BIT_ALIGNMENT, m_uiRange, 256, 0); 288 #endif 289 m_uiRange = 256; 290 } 291 292 #if RExt__DECODER_DEBUG_BIT_STATISTICS 293 Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins, const class TComCodingStatisticsClassType &whichStat ) 294 #else 295 Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins ) 296 #endif 297 { 298 Int binsRemaining = numBins; 299 ruiBins = 0; 300 301 assert(m_uiRange == 256); //aligned decode only works when range = 256 302 303 while (binsRemaining > 0) 304 { 305 const UInt binsToRead = std::min<UInt>(binsRemaining, 8); //read bytes if able to take advantage of the system's byte-read function 306 const UInt binMask = (1 << binsToRead) - 1; 307 308 //The MSB of m_uiValue is known to be 0 because range is 256. Therefore: 309 // > The comparison against the symbol range of 128 is simply a test on the next-most-significant bit 310 // > "Subtracting" the symbol range if the decoded bin is 1 simply involves clearing that bit. 311 // 312 //As a result, the required bins are simply the <binsToRead> next-most-significant bits of m_uiValue 313 //(m_uiValue is stored MSB-aligned in a 16-bit buffer - hence the shift of 15) 314 // 315 // m_uiValue = |0|V|V|V|V|V|V|V|V|B|B|B|B|B|B|B| (V = usable bit, B = potential buffered bit (buffer refills when m_bitsNeeded >= 0)) 316 // 317 const UInt newBins = (m_uiValue >> (15 - binsToRead)) & binMask; 318 319 ruiBins = (ruiBins << binsToRead) | newBins; 320 m_uiValue = (m_uiValue << binsToRead) & 0x7FFF; 321 322 binsRemaining -= binsToRead; 323 m_bitsNeeded += binsToRead; 324 325 if (m_bitsNeeded >= 0) 326 { 327 m_uiValue |= m_pcTComBitstream->readByte() << m_bitsNeeded; 328 m_bitsNeeded -= 8; 329 } 330 } 331 332 #if RExt__DECODER_DEBUG_BIT_STATISTICS 333 TComCodingStatistics::IncrementStatisticEP(whichStat, numBins, Int(ruiBins)); 334 #endif 210 335 } 211 336 … … 218 343 { 219 344 ruiBin = 1; 345 #if RExt__DECODER_DEBUG_BIT_STATISTICS 346 TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, 2, ruiBin); 347 TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, -m_bitsNeeded, 0); 348 #endif 220 349 } 221 350 else 222 351 { 223 352 ruiBin = 0; 353 #if RExt__DECODER_DEBUG_BIT_STATISTICS 354 TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, m_uiRange, ruiBin); 355 #endif 224 356 if ( scaledRange < ( 256 << 7 ) ) 225 357 { 226 358 m_uiRange = scaledRange >> 6; 227 359 m_uiValue += m_uiValue; 228 360 229 361 if ( ++m_bitsNeeded == 0 ) 230 362 { 231 363 m_bitsNeeded = -8; 232 m_uiValue += m_pcTComBitstream->readByte(); 364 m_uiValue += m_pcTComBitstream->readByte(); 233 365 } 234 366 } … … 245 377 assert ( uiLength > 0 ); 246 378 m_pcTComBitstream->read (uiLength, ruiCode); 379 #if RExt__DECODER_DEBUG_BIT_STATISTICS 380 TComCodingStatistics::IncrementStatisticEP(STATS__CABAC_PCM_CODE_BITS, uiLength, ruiCode); 381 #endif 247 382 } 248 383 //! \}
Note: See TracChangeset for help on using the changeset viewer.