Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737
    3838#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
    4043
    4144//! \ingroup TLibDecoder
     
    6770{
    6871  assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
     72#if RExt__DECODER_DEBUG_BIT_STATISTICS
     73  TComCodingStatistics::UpdateCABACStat(STATS__CABAC_INITIALISATION, 512, 510, 0);
     74#endif
    6975  m_uiRange    = 510;
    7076  m_bitsNeeded = -8;
     
    8995 */
    9096Void
    91 TDecBinCABAC::copyState( TDecBinIf* pcTDecBinIf )
    92 {
    93   TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
     97TDecBinCABAC::copyState( const TDecBinIf* pcTDecBinIf )
     98{
     99  const TDecBinCABAC* pcTDecBinCABAC = pcTDecBinIf->getTDecBinCABAC();
    94100  m_uiRange   = pcTDecBinCABAC->m_uiRange;
    95101  m_uiValue   = pcTDecBinCABAC->m_uiValue;
     
    98104
    99105
    100 Void
    101 TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel )
    102 {
     106
     107#if RExt__DECODER_DEBUG_BIT_STATISTICS
     108Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel, const TComCodingStatisticsClassType &whichStat )
     109#else
     110Void TDecBinCABAC::decodeBin( UInt& ruiBin, ContextModel &rcCtxModel )
     111#endif
     112{
     113#if DEBUG_CABAC_BINS
     114  const UInt startingRange = m_uiRange;
     115#endif
     116
    103117  UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) - 4 ];
    104118  m_uiRange -= uiLPS;
    105119  UInt scaledRange = m_uiRange << 7;
    106  
     120
    107121  if( m_uiValue < scaledRange )
    108122  {
    109123    // MPS path
    110124    ruiBin = rcCtxModel.getMps();
     125#if RExt__DECODER_DEBUG_BIT_STATISTICS
     126    TComCodingStatistics::UpdateCABACStat(whichStat, m_uiRange+uiLPS, m_uiRange, Int(ruiBin));
     127#endif
    111128    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      }
    125140    }
    126141  }
     
    128143  {
    129144    // 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
    130149    Int numBits = TComCABACTables::sm_aucRenormTable[ uiLPS >> 3 ];
    131150    m_uiValue   = ( m_uiValue - scaledRange ) << numBits;
    132151    m_uiRange   = uiLPS << numBits;
    133     ruiBin      = 1 - rcCtxModel.getMps();
    134152    rcCtxModel.updateLPS();
    135    
     153
    136154    m_bitsNeeded += numBits;
    137    
     155
    138156    if ( m_bitsNeeded >= 0 )
    139157    {
     
    142160    }
    143161  }
    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
     184Void TDecBinCABAC::decodeBinEP( UInt& ruiBin, const TComCodingStatisticsClassType &whichStat )
     185#else
     186Void 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
    149199  m_uiValue += m_uiValue;
    150  
     200
    151201  if ( ++m_bitsNeeded >= 0 )
    152202  {
     
    154204    m_uiValue += m_pcTComBitstream->readByte();
    155205  }
    156  
     206
    157207  ruiBin = 0;
    158208  UInt scaledRange = m_uiRange << 7;
     
    162212    m_uiValue -= scaledRange;
    163213  }
    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
     220Void TDecBinCABAC::decodeBinsEP( UInt& ruiBin, Int numBins, const TComCodingStatisticsClassType &whichStat )
     221#else
    166222Void 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
    168235  UInt bins = 0;
    169  
     236#if RExt__DECODER_DEBUG_BIT_STATISTICS
     237  Int origNumBins=numBins;
     238#endif
    170239  while ( numBins > 8 )
    171240  {
    172241    m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
    173    
     242
    174243    UInt scaledRange = m_uiRange << 15;
    175244    for ( Int i = 0; i < 8; i++ )
     
    185254    numBins -= 8;
    186255  }
    187  
     256
    188257  m_bitsNeeded += numBins;
    189258  m_uiValue <<= numBins;
    190  
     259
    191260  if ( m_bitsNeeded >= 0 )
    192261  {
     
    194263    m_bitsNeeded -= 8;
    195264  }
    196  
     265
    197266  UInt scaledRange = m_uiRange << ( numBins + 7 );
    198267  for ( Int i = 0; i < numBins; i++ )
     
    206275    }
    207276  }
    208  
     277
    209278  ruiBin = bins;
     279#if RExt__DECODER_DEBUG_BIT_STATISTICS
     280  TComCodingStatistics::IncrementStatisticEP(whichStat, origNumBins, Int(ruiBin));
     281#endif
     282}
     283
     284Void 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
     293Void TDecBinCABAC::decodeAlignedBinsEP( UInt& ruiBins, Int numBins, const class TComCodingStatisticsClassType &whichStat )
     294#else
     295Void 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
    210335}
    211336
     
    218343  {
    219344    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
    220349  }
    221350  else
    222351  {
    223352    ruiBin = 0;
     353#if RExt__DECODER_DEBUG_BIT_STATISTICS
     354    TComCodingStatistics::UpdateCABACStat(STATS__CABAC_TRM_BITS, m_uiRange+2, m_uiRange, ruiBin);
     355#endif
    224356    if ( scaledRange < ( 256 << 7 ) )
    225357    {
    226358      m_uiRange = scaledRange >> 6;
    227359      m_uiValue += m_uiValue;
    228      
     360
    229361      if ( ++m_bitsNeeded == 0 )
    230362      {
    231363        m_bitsNeeded = -8;
    232         m_uiValue += m_pcTComBitstream->readByte();     
     364        m_uiValue += m_pcTComBitstream->readByte();
    233365      }
    234366    }
     
    245377  assert ( uiLength > 0 );
    246378  m_pcTComBitstream->read (uiLength, ruiCode);
     379#if RExt__DECODER_DEBUG_BIT_STATISTICS
     380  TComCodingStatistics::IncrementStatisticEP(STATS__CABAC_PCM_CODE_BITS, uiLength, ruiCode);
     381#endif
    247382}
    248383//! \}
Note: See TracChangeset for help on using the changeset viewer.