Ticket #582: removeflushcode.patch

File removeflushcode.patch, 9.5 KB (added by gordon, 12 years ago)
  • source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp

     
    6464Void
    6565TDecBinCABAC::start()
    6666{
    67 #if OL_FLUSH_ALIGN
    6867  assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
    69 #endif
    70  
    7168  m_uiRange    = 510;
    7269  m_bitsNeeded = -8;
    73   m_uiValue    = m_pcTComBitstream->readByte() << 8;
    74 #if !OL_FLUSH_ALIGN
    75   m_uiLastByte = m_pcTComBitstream->readByte();
    76   m_uiValue   |= m_uiLastByte;
    77 #else
     70  m_uiValue    = (m_pcTComBitstream->readByte() << 8);
    7871  m_uiValue   |= m_pcTComBitstream->readByte();
    79 #endif
    8072}
    8173
    8274Void
     
    8779Void
    8880TDecBinCABAC::flush()
    8981{
    90 #if OL_FLUSH_ALIGN
    9182  while (m_pcTComBitstream->getNumBitsLeft() > 0 && m_pcTComBitstream->getNumBitsUntilByteAligned() != 0)
    9283  {
    9384    UInt uiBits;
    9485    m_pcTComBitstream->read ( 1, uiBits );
    9586  }
    9687  start();
    97 #else
    98   m_uiRange    = 510;
    99   Int iExtra = 16+m_bitsNeeded+1; // m_bitsNeeded is -ve: iExtra is many bits to read to make up 16.
    100   UInt uiExtraBits;
    101   m_pcTComBitstream->read(iExtra, uiExtraBits);
    102   m_uiValue = (m_uiLastByte << iExtra) | uiExtraBits;
    103   m_uiValue &= 0xffff;
    104   m_uiLastByte = m_uiValue;
    105   m_uiLastByte &= 0xff;
    106   m_bitsNeeded = -8;
    107 #endif // OL_FLUSH_ALIGN
    10888}
    10989
    11090/**
     
    11999  m_uiRange   = pcTDecBinCABAC->m_uiRange;
    120100  m_uiValue   = pcTDecBinCABAC->m_uiValue;
    121101  m_bitsNeeded= pcTDecBinCABAC->m_bitsNeeded;
    122 #if !OL_FLUSH_ALIGN
    123   m_uiLastByte= pcTDecBinCABAC->m_uiLastByte;
    124 #endif
    125102}
    126103
    127104
     
    149126    if ( ++m_bitsNeeded == 0 )
    150127    {
    151128      m_bitsNeeded = -8;
    152 #if !OL_FLUSH_ALIGN
    153       m_uiLastByte = m_pcTComBitstream->readByte();
    154       m_uiValue += m_uiLastByte;   
    155 #else
    156129      m_uiValue += m_pcTComBitstream->readByte();     
    157 #endif
    158130    }
    159131  }
    160132  else
     
    170142   
    171143    if ( m_bitsNeeded >= 0 )
    172144    {
    173 #if !OL_FLUSH_ALIGN
    174       m_uiLastByte = m_pcTComBitstream->readByte();
    175       m_uiValue += m_uiLastByte << m_bitsNeeded;
    176 #else
    177145      m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
    178 #endif
    179146      m_bitsNeeded -= 8;
    180147    }
    181148  }
     
    189156  if ( ++m_bitsNeeded >= 0 )
    190157  {
    191158    m_bitsNeeded = -8;
    192 #if !OL_FLUSH_ALIGN
    193     m_uiLastByte = m_pcTComBitstream->readByte();
    194     m_uiValue += m_uiLastByte;
    195 #else
    196159    m_uiValue += m_pcTComBitstream->readByte();
    197 #endif
    198160  }
    199161 
    200162  ruiBin = 0;
     
    212174 
    213175  while ( numBins > 8 )
    214176  {
    215 #if !OL_FLUSH_ALIGN
    216     m_uiLastByte = m_pcTComBitstream->readByte();
    217     m_uiValue = ( m_uiValue << 8 ) + ( m_uiLastByte << ( 8 + m_bitsNeeded ) );
    218 #else
    219177    m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
    220 #endif
    221178   
    222179    UInt scaledRange = m_uiRange << 15;
    223180    for ( Int i = 0; i < 8; i++ )
     
    238195 
    239196  if ( m_bitsNeeded >= 0 )
    240197  {
    241 #if !OL_FLUSH_ALIGN
    242     m_uiLastByte = m_pcTComBitstream->readByte();
    243     m_uiValue += m_uiLastByte << m_bitsNeeded;
    244 #else
    245198    m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
    246 #endif
    247199    m_bitsNeeded -= 8;
    248200  }
    249201 
     
    282234      if ( ++m_bitsNeeded == 0 )
    283235      {
    284236        m_bitsNeeded = -8;
    285 #if !OL_FLUSH_ALIGN
    286         m_uiLastByte = m_pcTComBitstream->readByte();
    287         m_uiValue += m_uiLastByte;   
    288 #else
    289237        m_uiValue += m_pcTComBitstream->readByte();     
    290 #endif
    291238      }
    292239    }
    293240  }
     
    319266    if ( ++m_bitsNeeded >= 0 )
    320267    {
    321268      m_bitsNeeded = -8;
    322 #if !OL_FLUSH_ALIGN
    323       m_uiLastByte = m_pcTComBitstream->readByte();
    324       m_uiValue += m_uiLastByte;
    325 #else
    326269      m_uiValue += m_pcTComBitstream->readByte();
    327 #endif
    328270    }
    329271    bit = ((m_uiValue&128)>>7);
    330272    numSubseqIPCM++;
  • source/Lib/TLibDecoder/TDecBinCoderCABAC.h

     
    6969 
    7070  Void  copyState         ( TDecBinIf* pcTDecBinIf );
    7171  TDecBinCABAC* getTDecBinCABAC()  { return this; }
    72 #if !OL_FLUSH_ALIGN
    73   Int   getBitsReadAhead() { return -m_bitsNeeded; }
    74 #endif
    7572
    7673private:
    7774  TComInputBitstream* m_pcTComBitstream;
    7875  UInt                m_uiRange;
    7976  UInt                m_uiValue;
    80 #if !OL_FLUSH_ALIGN
    81   UInt                m_uiLastByte;
    82 #endif
    8377  Int                 m_bitsNeeded;
    8478};
    8579
  • source/Lib/TLibDecoder/TDecSbac.cpp

     
    181181  UInt uiBit;
    182182  m_pcTDecBinIf->decodeBinTrm(uiBit);
    183183  m_pcTDecBinIf->finish(); 
    184 #if !OL_FLUSH_ALIGN
    185   // Account for misaligned CABAC.
    186   Int iCABACReadAhead = m_pcTDecBinIf->getBitsReadAhead();
    187   iCABACReadAhead--;
    188   Int iStreamBits = 8-m_pcBitstream->getNumBitsUntilByteAligned();
    189   if (iCABACReadAhead >= iStreamBits)
    190   {
    191     // Misaligned CABAC has read into the 1st byte of the next tile.
    192     // Back up a byte prior to alignment.
    193     m_pcBitstream->backupByte();
    194   }
    195 #endif
    196184  m_pcBitstream->readOutTrailingBits();
    197185  m_cCUSplitFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG );
    198186  m_cCUSkipFlagSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG );
  • source/Lib/TLibDecoder/TDecBinCoder.h

     
    6969
    7070  virtual Void  copyState         ( TDecBinIf* pcTDecBinIf )                  = 0;
    7171  virtual TDecBinCABAC*   getTDecBinCABAC   ()  { return 0; }
    72 #if !OL_FLUSH_ALIGN
    73   virtual Int   getBitsReadAhead() { return 0; }
    74 #endif
    7572};
    7673
    7774//! \}
  • source/Lib/TLibCommon/TComBitStream.cpp

     
    347347    uiByte <<= 8-(uiNumBits&0x7);
    348348    buf->push_back(uiByte);
    349349  }
    350 #if !OL_FLUSH_ALIGN
    351   buf->push_back(0); // The final chunk might not start byte aligned.
    352 #endif
    353350  return new TComInputBitstream(buf);
    354351}
    355352
  • source/Lib/TLibCommon/TypeDef.h

     
    201201                                                    // this should be done with encoder only decision
    202202                                                    // but because of the absence of reference frame management, the related code was hard coded currently
    203203
    204 #define OL_FLUSH_ALIGN 0    // Align flush to byte boundary.  This preserves byte operations in CABAC (faster) but at the expense of an average
    205                             // of 4 bits per flush.
    206                             // Setting to 0 will slow cabac by an as yet unknown amount.
    207                             // This is here just to perform timing tests -- OL_FLUSH_ALIGN should be 0 for WPP.
    208 
    209204#define RVM_VCEGAM10_M 4
    210205
    211206#define PLANAR_IDX             0
  • source/Lib/TLibCommon/TComBitStream.h

     
    198198  // interface for decoding
    199199  Void        pseudoRead      ( UInt uiNumberOfBits, UInt& ruiBits );
    200200  Void        read            ( UInt uiNumberOfBits, UInt& ruiBits );
    201 #if !OL_FLUSH_ALIGN
    202201  Void        readByte        ( UInt &ruiBits )
    203202  {
    204     // More expensive, but reads "bytes" that are not aligned.
    205     read(8, ruiBits);
    206   }
    207 #else
    208   Void        readByte        ( UInt &ruiBits )
    209   {
    210203    assert(m_fifo_idx < m_fifo->size());
    211204    ruiBits = (*m_fifo)[m_fifo_idx++];
    212205  }
    213 #endif // !OL_FLUSH_ALIGN
    214206
    215207  Void        readOutTrailingBits ();
    216208  UChar getHeldBits  ()          { return m_held_bits;          }
     
    233225  unsigned getNumBitsLeft() { return 8*((unsigned)m_fifo->size() - m_fifo_idx) + m_num_held_bits; }
    234226  TComInputBitstream *extractSubstream( UInt uiNumBits ); // Read the nominated number of bits, and return as a bitstream.
    235227  Void                deleteFifo(); // Delete internal fifo of bitstream.
    236 #if !OL_FLUSH_ALIGN
    237   Void                backupByte() { m_fifo_idx--; }
    238 #endif
    239228  UInt  getNumBitsRead() { return m_numBitsRead; }
    240229#if BYTE_ALIGNMENT
    241230  Void readByteAlignment();
  • source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp

     
    109109  encodeBinTrm(1);
    110110  finish();
    111111  m_pcTComBitIf->write(1, 1);
    112 #if OL_FLUSH_ALIGN
    113112  m_pcTComBitIf->writeAlignZero();
    114 #endif
    115113
    116114  start();
    117115}