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/TLibEncoder/TEncBinCoderCABAC.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. 
    5  *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     4 * granted under this license.
     5 *
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3838#include "TEncBinCoderCABAC.h"
    3939#include "TLibCommon/TComRom.h"
    40 
     40#include "TLibCommon/Debug.h"
    4141
    4242//! \ingroup TLibEncoder
     
    7474  m_numBufferedBytes = 0;
    7575  m_bufferedByte     = 0xff;
     76#if FAST_BIT_EST
     77  m_fracBits         = 0;
     78#endif
    7679}
    7780
     
    100103      m_pcTComBitIf->write( 0xff, 8 );
    101104      m_numBufferedBytes--;
    102     }   
     105    }
    103106  }
    104107  m_pcTComBitIf->write( m_uiLow >> 8, 24 - m_bitsLeft );
     
    143146}
    144147
    145 Void TEncBinCABAC::copyState( TEncBinIf* pcTEncBinIf )
    146 {
    147   TEncBinCABAC* pcTEncBinCABAC = pcTEncBinIf->getTEncBinCABAC();
     148Void TEncBinCABAC::copyState( const TEncBinIf* pcTEncBinIf )
     149{
     150  const TEncBinCABAC* pcTEncBinCABAC = pcTEncBinIf->getTEncBinCABAC();
    148151  m_uiLow           = pcTEncBinCABAC->m_uiLow;
    149152  m_uiRange         = pcTEncBinCABAC->m_uiRange;
     
    153156#if FAST_BIT_EST
    154157  m_fracBits = pcTEncBinCABAC->m_fracBits;
     158  D_PRINT_INDENT(g_traceEncFracBits,  "CopyState " + n2s(m_fracBits) );   
    155159#endif
    156160}
     
    167171  }
    168172#if FAST_BIT_EST
     173  D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits Before" + n2s(m_fracBits) );
    169174  m_fracBits &= 32767;
     175  D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits " + n2s(m_fracBits) ); 
    170176#endif
    171177}
     
    184190Void TEncBinCABAC::encodeBin( UInt binValue, ContextModel &rcCtxModel )
    185191{
    186   {
    187 #if !H_MV
    188     DTRACE_CABAC_VL( g_nSymbolCounter++ )
    189     DTRACE_CABAC_T( "\tstate=" )
    190     DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() )
    191     DTRACE_CABAC_T( "\tsymbol=" )
    192     DTRACE_CABAC_V( binValue )
    193     DTRACE_CABAC_T( "\n" )
    194 #endif
    195   }
     192#if !NH_MV
     193  //{
     194  //  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     195  //  DTRACE_CABAC_T( "\tstate=" )
     196  //  DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() )
     197  //  DTRACE_CABAC_T( "\tsymbol=" )
     198  //  DTRACE_CABAC_V( binValue )
     199  //  DTRACE_CABAC_T( "\n" )
     200  //}
     201#endif
     202#if DEBUG_CABAC_BINS
     203  const UInt startingRange = m_uiRange;
     204#endif
     205
    196206  m_uiBinsCoded += m_binCountIncrement;
    197207  rcCtxModel.setBinsCoded( 1 );
    198  
     208
    199209  UInt  uiLPS   = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) & 3 ];
    200210  m_uiRange    -= uiLPS;
    201  
     211
    202212  if( binValue != rcCtxModel.getMps() )
    203213  {
     
    206216    m_uiRange   = uiLPS << numBits;
    207217    rcCtxModel.updateLPS();
    208    
    209218    m_bitsLeft -= numBits;
     219    testAndWriteOut();
    210220  }
    211221  else
    212222  {
    213223    rcCtxModel.updateMPS();
    214     if ( m_uiRange >= 256 )
    215     {
    216       return;
    217     }
    218    
    219     m_uiLow <<= 1;
    220     m_uiRange <<= 1;
    221     m_bitsLeft--;
    222   }
    223  
    224   testAndWriteOut();
     224
     225    if ( m_uiRange < 256 )
     226    {
     227      m_uiLow <<= 1;
     228      m_uiRange <<= 1;
     229      m_bitsLeft--;
     230      testAndWriteOut();
     231    }
     232  }
     233
     234#if DEBUG_CABAC_BINS
     235  if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine)
     236  {
     237    std::cout << g_debugCounter << ": coding bin value " << binValue << ", range = [" << startingRange << "->" << m_uiRange << "]\n";
     238  }
     239
     240  if (g_debugCounter >= debugCabacBinTargetLine)
     241  {
     242    Char breakPointThis;
     243    breakPointThis = 7;
     244  }
     245  if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow))
     246  {
     247    exit(0);
     248  }
     249
     250  g_debugCounter++;
     251#endif
    225252}
    226253
     
    232259Void TEncBinCABAC::encodeBinEP( UInt binValue )
    233260{
    234   {
    235 #if !H_MV
     261  if (false)
     262  {
     263#if !NH_MV
    236264    DTRACE_CABAC_VL( g_nSymbolCounter++ )
    237265    DTRACE_CABAC_T( "\tEPsymbol=" )
     
    240268#endif
    241269  }
     270
    242271  m_uiBinsCoded += m_binCountIncrement;
     272
     273  if (m_uiRange == 256)
     274  {
     275    encodeAlignedBinsEP(binValue, 1);
     276    return;
     277  }
     278
    243279  m_uiLow <<= 1;
    244280  if( binValue )
     
    247283  }
    248284  m_bitsLeft--;
    249  
     285
    250286  testAndWriteOut();
    251287}
     
    260296{
    261297  m_uiBinsCoded += numBins & -m_binCountIncrement;
    262  
    263   for ( Int i = 0; i < numBins; i++ )
    264   {
    265 #if !H_MV
    266     DTRACE_CABAC_VL( g_nSymbolCounter++ )
    267     DTRACE_CABAC_T( "\tEPsymbol=" )
    268     DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 )
    269     DTRACE_CABAC_T( "\n" )
    270 #endif
    271   }
    272  
     298
     299  if (false)
     300  {
     301    for ( Int i = 0; i < numBins; i++ )
     302    {
     303#if !NH_MV
     304      DTRACE_CABAC_VL( g_nSymbolCounter++ )
     305      DTRACE_CABAC_T( "\tEPsymbol=" )
     306      DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 )
     307      DTRACE_CABAC_T( "\n" )
     308#endif
     309    }
     310  }
     311
     312  if (m_uiRange == 256)
     313  {
     314    encodeAlignedBinsEP(binValues, numBins);
     315    return;
     316  }
     317
    273318  while ( numBins > 8 )
    274319  {
    275320    numBins -= 8;
    276     UInt pattern = binValues >> numBins; 
     321    UInt pattern = binValues >> numBins;
    277322    m_uiLow <<= 8;
    278323    m_uiLow += m_uiRange * pattern;
    279324    binValues -= pattern << numBins;
    280325    m_bitsLeft -= 8;
    281    
     326
    282327    testAndWriteOut();
    283328  }
    284  
     329
    285330  m_uiLow <<= numBins;
    286331  m_uiLow += m_uiRange * binValues;
    287332  m_bitsLeft -= numBins;
    288  
     333
    289334  testAndWriteOut();
     335}
     336
     337Void TEncBinCABAC::align()
     338{
     339  m_uiRange = 256;
     340}
     341
     342Void TEncBinCABAC::encodeAlignedBinsEP( UInt binValues, Int numBins )
     343{
     344  Int binsRemaining = numBins;
     345
     346  assert(m_uiRange == 256); //aligned encode only works when range = 256
     347
     348  while (binsRemaining > 0)
     349  {
     350    const UInt binsToCode = std::min<UInt>(binsRemaining, 8); //code bytes if able to take advantage of the system's byte-write function
     351    const UInt binMask    = (1 << binsToCode) - 1;
     352
     353    const UInt newBins = (binValues >> (binsRemaining - binsToCode)) & binMask;
     354
     355    //The process of encoding an EP bin is the same as that of coding a normal
     356    //bin where the symbol ranges for 1 and 0 are both half the range:
     357    //
     358    //  low = (low + range/2) << 1       (to encode a 1)
     359    //  low =  low            << 1       (to encode a 0)
     360    //
     361    //  i.e.
     362    //  low = (low + (bin * range/2)) << 1
     363    //
     364    //  which is equivalent to:
     365    //
     366    //  low = (low << 1) + (bin * range)
     367    //
     368    //  this can be generalised for multiple bins, producing the following expression:
     369    //
     370    m_uiLow = (m_uiLow << binsToCode) + (newBins << 8); //range is known to be 256
     371
     372    binsRemaining -= binsToCode;
     373    m_bitsLeft    -= binsToCode;
     374
     375    testAndWriteOut();
     376  }
    290377}
    291378
     
    314401    m_uiLow   <<= 1;
    315402    m_uiRange <<= 1;
    316     m_bitsLeft--;   
    317   }
    318  
     403    m_bitsLeft--;
     404  }
     405
    319406  testAndWriteOut();
    320407}
     
    336423  m_bitsLeft += 8;
    337424  m_uiLow &= 0xffffffffu >> m_bitsLeft;
    338  
     425
    339426  if ( leadByte == 0xff )
    340427  {
     
    349436      m_bufferedByte = leadByte & 0xff;
    350437      m_pcTComBitIf->write( byte, 8 );
    351      
     438
    352439      byte = ( 0xff + carry ) & 0xff;
    353440      while ( m_numBufferedBytes > 1 )
     
    361448      m_numBufferedBytes = 1;
    362449      m_bufferedByte = leadByte;
    363     }     
    364   }   
     450    }
     451  }
    365452}
    366453
Note: See TracChangeset for help on using the changeset viewer.