Ticket #582: removeflushcode.patch
File removeflushcode.patch, 9.5 KB (added by gordon, 11 years ago) |
---|
-
source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
64 64 Void 65 65 TDecBinCABAC::start() 66 66 { 67 #if OL_FLUSH_ALIGN68 67 assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 ); 69 #endif70 71 68 m_uiRange = 510; 72 69 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); 78 71 m_uiValue |= m_pcTComBitstream->readByte(); 79 #endif80 72 } 81 73 82 74 Void … … 87 79 Void 88 80 TDecBinCABAC::flush() 89 81 { 90 #if OL_FLUSH_ALIGN91 82 while (m_pcTComBitstream->getNumBitsLeft() > 0 && m_pcTComBitstream->getNumBitsUntilByteAligned() != 0) 92 83 { 93 84 UInt uiBits; 94 85 m_pcTComBitstream->read ( 1, uiBits ); 95 86 } 96 87 start(); 97 #else98 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_ALIGN108 88 } 109 89 110 90 /** … … 119 99 m_uiRange = pcTDecBinCABAC->m_uiRange; 120 100 m_uiValue = pcTDecBinCABAC->m_uiValue; 121 101 m_bitsNeeded= pcTDecBinCABAC->m_bitsNeeded; 122 #if !OL_FLUSH_ALIGN123 m_uiLastByte= pcTDecBinCABAC->m_uiLastByte;124 #endif125 102 } 126 103 127 104 … … 149 126 if ( ++m_bitsNeeded == 0 ) 150 127 { 151 128 m_bitsNeeded = -8; 152 #if !OL_FLUSH_ALIGN153 m_uiLastByte = m_pcTComBitstream->readByte();154 m_uiValue += m_uiLastByte;155 #else156 129 m_uiValue += m_pcTComBitstream->readByte(); 157 #endif158 130 } 159 131 } 160 132 else … … 170 142 171 143 if ( m_bitsNeeded >= 0 ) 172 144 { 173 #if !OL_FLUSH_ALIGN174 m_uiLastByte = m_pcTComBitstream->readByte();175 m_uiValue += m_uiLastByte << m_bitsNeeded;176 #else177 145 m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded; 178 #endif179 146 m_bitsNeeded -= 8; 180 147 } 181 148 } … … 189 156 if ( ++m_bitsNeeded >= 0 ) 190 157 { 191 158 m_bitsNeeded = -8; 192 #if !OL_FLUSH_ALIGN193 m_uiLastByte = m_pcTComBitstream->readByte();194 m_uiValue += m_uiLastByte;195 #else196 159 m_uiValue += m_pcTComBitstream->readByte(); 197 #endif198 160 } 199 161 200 162 ruiBin = 0; … … 212 174 213 175 while ( numBins > 8 ) 214 176 { 215 #if !OL_FLUSH_ALIGN216 m_uiLastByte = m_pcTComBitstream->readByte();217 m_uiValue = ( m_uiValue << 8 ) + ( m_uiLastByte << ( 8 + m_bitsNeeded ) );218 #else219 177 m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) ); 220 #endif221 178 222 179 UInt scaledRange = m_uiRange << 15; 223 180 for ( Int i = 0; i < 8; i++ ) … … 238 195 239 196 if ( m_bitsNeeded >= 0 ) 240 197 { 241 #if !OL_FLUSH_ALIGN242 m_uiLastByte = m_pcTComBitstream->readByte();243 m_uiValue += m_uiLastByte << m_bitsNeeded;244 #else245 198 m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded; 246 #endif247 199 m_bitsNeeded -= 8; 248 200 } 249 201 … … 282 234 if ( ++m_bitsNeeded == 0 ) 283 235 { 284 236 m_bitsNeeded = -8; 285 #if !OL_FLUSH_ALIGN286 m_uiLastByte = m_pcTComBitstream->readByte();287 m_uiValue += m_uiLastByte;288 #else289 237 m_uiValue += m_pcTComBitstream->readByte(); 290 #endif291 238 } 292 239 } 293 240 } … … 319 266 if ( ++m_bitsNeeded >= 0 ) 320 267 { 321 268 m_bitsNeeded = -8; 322 #if !OL_FLUSH_ALIGN323 m_uiLastByte = m_pcTComBitstream->readByte();324 m_uiValue += m_uiLastByte;325 #else326 269 m_uiValue += m_pcTComBitstream->readByte(); 327 #endif328 270 } 329 271 bit = ((m_uiValue&128)>>7); 330 272 numSubseqIPCM++; -
source/Lib/TLibDecoder/TDecBinCoderCABAC.h
69 69 70 70 Void copyState ( TDecBinIf* pcTDecBinIf ); 71 71 TDecBinCABAC* getTDecBinCABAC() { return this; } 72 #if !OL_FLUSH_ALIGN73 Int getBitsReadAhead() { return -m_bitsNeeded; }74 #endif75 72 76 73 private: 77 74 TComInputBitstream* m_pcTComBitstream; 78 75 UInt m_uiRange; 79 76 UInt m_uiValue; 80 #if !OL_FLUSH_ALIGN81 UInt m_uiLastByte;82 #endif83 77 Int m_bitsNeeded; 84 78 }; 85 79 -
source/Lib/TLibDecoder/TDecSbac.cpp
181 181 UInt uiBit; 182 182 m_pcTDecBinIf->decodeBinTrm(uiBit); 183 183 m_pcTDecBinIf->finish(); 184 #if !OL_FLUSH_ALIGN185 // 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 #endif196 184 m_pcBitstream->readOutTrailingBits(); 197 185 m_cCUSplitFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SPLIT_FLAG ); 198 186 m_cCUSkipFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_SKIP_FLAG ); -
source/Lib/TLibDecoder/TDecBinCoder.h
69 69 70 70 virtual Void copyState ( TDecBinIf* pcTDecBinIf ) = 0; 71 71 virtual TDecBinCABAC* getTDecBinCABAC () { return 0; } 72 #if !OL_FLUSH_ALIGN73 virtual Int getBitsReadAhead() { return 0; }74 #endif75 72 }; 76 73 77 74 //! \} -
source/Lib/TLibCommon/TComBitStream.cpp
347 347 uiByte <<= 8-(uiNumBits&0x7); 348 348 buf->push_back(uiByte); 349 349 } 350 #if !OL_FLUSH_ALIGN351 buf->push_back(0); // The final chunk might not start byte aligned.352 #endif353 350 return new TComInputBitstream(buf); 354 351 } 355 352 -
source/Lib/TLibCommon/TypeDef.h
201 201 // this should be done with encoder only decision 202 202 // but because of the absence of reference frame management, the related code was hard coded currently 203 203 204 #define OL_FLUSH_ALIGN 0 // Align flush to byte boundary. This preserves byte operations in CABAC (faster) but at the expense of an average205 // 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 209 204 #define RVM_VCEGAM10_M 4 210 205 211 206 #define PLANAR_IDX 0 -
source/Lib/TLibCommon/TComBitStream.h
198 198 // interface for decoding 199 199 Void pseudoRead ( UInt uiNumberOfBits, UInt& ruiBits ); 200 200 Void read ( UInt uiNumberOfBits, UInt& ruiBits ); 201 #if !OL_FLUSH_ALIGN202 201 Void readByte ( UInt &ruiBits ) 203 202 { 204 // More expensive, but reads "bytes" that are not aligned.205 read(8, ruiBits);206 }207 #else208 Void readByte ( UInt &ruiBits )209 {210 203 assert(m_fifo_idx < m_fifo->size()); 211 204 ruiBits = (*m_fifo)[m_fifo_idx++]; 212 205 } 213 #endif // !OL_FLUSH_ALIGN214 206 215 207 Void readOutTrailingBits (); 216 208 UChar getHeldBits () { return m_held_bits; } … … 233 225 unsigned getNumBitsLeft() { return 8*((unsigned)m_fifo->size() - m_fifo_idx) + m_num_held_bits; } 234 226 TComInputBitstream *extractSubstream( UInt uiNumBits ); // Read the nominated number of bits, and return as a bitstream. 235 227 Void deleteFifo(); // Delete internal fifo of bitstream. 236 #if !OL_FLUSH_ALIGN237 Void backupByte() { m_fifo_idx--; }238 #endif239 228 UInt getNumBitsRead() { return m_numBitsRead; } 240 229 #if BYTE_ALIGNMENT 241 230 Void readByteAlignment(); -
source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
109 109 encodeBinTrm(1); 110 110 finish(); 111 111 m_pcTComBitIf->write(1, 1); 112 #if OL_FLUSH_ALIGN113 112 m_pcTComBitIf->writeAlignZero(); 114 #endif115 113 116 114 start(); 117 115 }