Ignore:
Timestamp:
4 May 2015, 18:38:08 (10 years ago)
Author:
tech
Message:

Update to HM-16.5.
Starting point for further re-activation of 3D-tools.

Includes:

active:

  • MV-HEVC
  • 3D-HLS (apart from DLT)
  • VSO

inactive:

  • remaining 3D-HEVC tools.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-14.1-update-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp

    r1179 r1200  
    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;
     
    184187Void TEncBinCABAC::encodeBin( UInt binValue, ContextModel &rcCtxModel )
    185188{
    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   }
     189#if !NH_MV
     190  //{
     191  //  DTRACE_CABAC_VL( g_nSymbolCounter++ )
     192  //  DTRACE_CABAC_T( "\tstate=" )
     193  //  DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() )
     194  //  DTRACE_CABAC_T( "\tsymbol=" )
     195  //  DTRACE_CABAC_V( binValue )
     196  //  DTRACE_CABAC_T( "\n" )
     197  //}
     198#endif
     199#if DEBUG_CABAC_BINS
     200  const UInt startingRange = m_uiRange;
     201#endif
     202
    196203  m_uiBinsCoded += m_binCountIncrement;
    197204  rcCtxModel.setBinsCoded( 1 );
    198  
     205
    199206  UInt  uiLPS   = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) & 3 ];
    200207  m_uiRange    -= uiLPS;
    201  
     208
    202209  if( binValue != rcCtxModel.getMps() )
    203210  {
     
    206213    m_uiRange   = uiLPS << numBits;
    207214    rcCtxModel.updateLPS();
    208    
    209215    m_bitsLeft -= numBits;
     216    testAndWriteOut();
    210217  }
    211218  else
    212219  {
    213220    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();
     221
     222    if ( m_uiRange < 256 )
     223    {
     224      m_uiLow <<= 1;
     225      m_uiRange <<= 1;
     226      m_bitsLeft--;
     227      testAndWriteOut();
     228    }
     229  }
     230
     231#if DEBUG_CABAC_BINS
     232  if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine)
     233  {
     234    std::cout << g_debugCounter << ": coding bin value " << binValue << ", range = [" << startingRange << "->" << m_uiRange << "]\n";
     235  }
     236
     237  if (g_debugCounter >= debugCabacBinTargetLine)
     238  {
     239    Char breakPointThis;
     240    breakPointThis = 7;
     241  }
     242  if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow))
     243  {
     244    exit(0);
     245  }
     246
     247  g_debugCounter++;
     248#endif
    225249}
    226250
     
    232256Void TEncBinCABAC::encodeBinEP( UInt binValue )
    233257{
    234   {
    235 #if !H_MV
     258  if (false)
     259  {
     260#if !NH_MV
    236261    DTRACE_CABAC_VL( g_nSymbolCounter++ )
    237262    DTRACE_CABAC_T( "\tEPsymbol=" )
     
    240265#endif
    241266  }
     267
    242268  m_uiBinsCoded += m_binCountIncrement;
     269
     270  if (m_uiRange == 256)
     271  {
     272    encodeAlignedBinsEP(binValue, 1);
     273    return;
     274  }
     275
    243276  m_uiLow <<= 1;
    244277  if( binValue )
     
    247280  }
    248281  m_bitsLeft--;
    249  
     282
    250283  testAndWriteOut();
    251284}
     
    260293{
    261294  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  
     295
     296  if (false)
     297  {
     298    for ( Int i = 0; i < numBins; i++ )
     299    {
     300#if !NH_MV
     301      DTRACE_CABAC_VL( g_nSymbolCounter++ )
     302      DTRACE_CABAC_T( "\tEPsymbol=" )
     303      DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 )
     304      DTRACE_CABAC_T( "\n" )
     305#endif
     306    }
     307  }
     308
     309  if (m_uiRange == 256)
     310  {
     311    encodeAlignedBinsEP(binValues, numBins);
     312    return;
     313  }
     314
    273315  while ( numBins > 8 )
    274316  {
    275317    numBins -= 8;
    276     UInt pattern = binValues >> numBins; 
     318    UInt pattern = binValues >> numBins;
    277319    m_uiLow <<= 8;
    278320    m_uiLow += m_uiRange * pattern;
    279321    binValues -= pattern << numBins;
    280322    m_bitsLeft -= 8;
    281    
     323
    282324    testAndWriteOut();
    283325  }
    284  
     326
    285327  m_uiLow <<= numBins;
    286328  m_uiLow += m_uiRange * binValues;
    287329  m_bitsLeft -= numBins;
    288  
     330
    289331  testAndWriteOut();
     332}
     333
     334Void TEncBinCABAC::align()
     335{
     336  m_uiRange = 256;
     337}
     338
     339Void TEncBinCABAC::encodeAlignedBinsEP( UInt binValues, Int numBins )
     340{
     341  Int binsRemaining = numBins;
     342
     343  assert(m_uiRange == 256); //aligned encode only works when range = 256
     344
     345  while (binsRemaining > 0)
     346  {
     347    const UInt binsToCode = std::min<UInt>(binsRemaining, 8); //code bytes if able to take advantage of the system's byte-write function
     348    const UInt binMask    = (1 << binsToCode) - 1;
     349
     350    const UInt newBins = (binValues >> (binsRemaining - binsToCode)) & binMask;
     351
     352    //The process of encoding an EP bin is the same as that of coding a normal
     353    //bin where the symbol ranges for 1 and 0 are both half the range:
     354    //
     355    //  low = (low + range/2) << 1       (to encode a 1)
     356    //  low =  low            << 1       (to encode a 0)
     357    //
     358    //  i.e.
     359    //  low = (low + (bin * range/2)) << 1
     360    //
     361    //  which is equivalent to:
     362    //
     363    //  low = (low << 1) + (bin * range)
     364    //
     365    //  this can be generalised for multiple bins, producing the following expression:
     366    //
     367    m_uiLow = (m_uiLow << binsToCode) + (newBins << 8); //range is known to be 256
     368
     369    binsRemaining -= binsToCode;
     370    m_bitsLeft    -= binsToCode;
     371
     372    testAndWriteOut();
     373  }
    290374}
    291375
     
    314398    m_uiLow   <<= 1;
    315399    m_uiRange <<= 1;
    316     m_bitsLeft--;   
    317   }
    318  
     400    m_bitsLeft--;
     401  }
     402
    319403  testAndWriteOut();
    320404}
     
    336420  m_bitsLeft += 8;
    337421  m_uiLow &= 0xffffffffu >> m_bitsLeft;
    338  
     422
    339423  if ( leadByte == 0xff )
    340424  {
     
    349433      m_bufferedByte = leadByte & 0xff;
    350434      m_pcTComBitIf->write( byte, 8 );
    351      
     435
    352436      byte = ( 0xff + carry ) & 0xff;
    353437      while ( m_numBufferedBytes > 1 )
     
    361445      m_numBufferedBytes = 1;
    362446      m_bufferedByte = leadByte;
    363     }     
    364   }   
     447    }
     448  }
    365449}
    366450
Note: See TracChangeset for help on using the changeset viewer.