Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComBitStream.cpp
- Timestamp:
- 1 Sep 2013, 22:47:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComBitStream.cpp
r296 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 55 55 m_fifo = new vector<uint8_t>; 56 56 clear(); 57 m_puiTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU];58 m_uiTileMarkerLocationCount = 0;59 57 } 60 58 … … 62 60 { 63 61 delete m_fifo; 64 delete [] m_puiTileMarkerLocation;65 62 } 66 63 … … 71 68 m_held_bits = 0; 72 69 m_num_held_bits = 0; 73 m_puiTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU];74 m_uiTileMarkerLocationCount = 0;75 70 m_numBitsRead = 0; 76 71 } … … 78 73 TComInputBitstream::~TComInputBitstream() 79 74 { 80 delete [] m_puiTileMarkerLocation;81 75 } 82 76 … … 85 79 // ==================================================================================================================== 86 80 87 char* TComOutputBitstream::getByteStream() const88 { 89 return ( char*) &m_fifo->front();90 } 91 92 unsigned int TComOutputBitstream::getByteStreamLength()93 { 94 return unsigned(m_fifo->size());81 Char* TComOutputBitstream::getByteStream() const 82 { 83 return (Char*) &m_fifo->front(); 84 } 85 86 UInt TComOutputBitstream::getByteStreamLength() 87 { 88 return UInt(m_fifo->size()); 95 89 } 96 90 … … 100 94 m_held_bits = 0; 101 95 m_num_held_bits = 0; 102 m_uiTileMarkerLocationCount = 0;103 96 } 104 97 … … 106 99 { 107 100 assert( uiNumberOfBits <= 32 ); 101 assert( uiNumberOfBits == 32 || (uiBits & (~0 << uiNumberOfBits)) == 0 ); 108 102 109 103 /* any modulo 8 remainder of num_total_bits cannot be written this time, 110 104 * and will be held until next time. */ 111 unsignednum_total_bits = uiNumberOfBits + m_num_held_bits;112 unsignednext_num_held_bits = num_total_bits % 8;105 UInt num_total_bits = uiNumberOfBits + m_num_held_bits; 106 UInt next_num_held_bits = num_total_bits % 8; 113 107 114 108 /* form a byte aligned word (write_bits), by concatenating any held bits … … 118 112 * len(H)=7, len(V)=2: ... ---- HHHH HHHV . V000 0000, next_num_held_bits=1 119 113 * if total_bits < 8, the value of v_ is not used */ 120 unsigned char next_held_bits = uiBits << (8 - next_num_held_bits);114 UChar next_held_bits = uiBits << (8 - next_num_held_bits); 121 115 122 116 if (!(num_total_bits >> 3)) … … 131 125 132 126 /* topword serves to justify held_bits to align with the msb of uiBits */ 133 unsignedtopword = (uiNumberOfBits - next_num_held_bits) & ~((1 << 3) -1);134 unsigned int write_bits = (m_held_bits << topword) | (uiBits >> next_num_held_bits);127 UInt topword = (uiNumberOfBits - next_num_held_bits) & ~((1 << 3) -1); 128 UInt write_bits = (m_held_bits << topword) | (uiBits >> next_num_held_bits); 135 129 136 130 switch (num_total_bits >> 3) … … 148 142 Void TComOutputBitstream::writeAlignOne() 149 143 { 150 unsigned int num_bits = getNumBitsUntilByteAligned();144 UInt num_bits = getNumBitsUntilByteAligned(); 151 145 write((1 << num_bits) - 1, num_bits); 152 146 return; … … 156 150 { 157 151 if (0 == m_num_held_bits) 152 { 158 153 return; 154 } 159 155 m_fifo->push_back(m_held_bits); 160 156 m_held_bits = 0; … … 182 178 } 183 179 180 Void TComOutputBitstream::writeByteAlignment() 181 { 182 write( 1, 1); 183 writeAlignZero(); 184 } 185 186 Int TComOutputBitstream::countStartCodeEmulations() 187 { 188 UInt cnt = 0; 189 vector<uint8_t>& rbsp = getFIFO(); 190 for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();) 191 { 192 vector<uint8_t>::iterator found = it; 193 do 194 { 195 // find the next emulated 00 00 {00,01,02,03} 196 // NB, end()-1, prevents finding a trailing two byte sequence 197 found = search_n(found, rbsp.end()-1, 2, 0); 198 found++; 199 // if not found, found == end, otherwise found = second zero byte 200 if (found == rbsp.end()) 201 { 202 break; 203 } 204 if (*(++found) <= 3) 205 { 206 break; 207 } 208 } while (true); 209 it = found; 210 if (found != rbsp.end()) 211 { 212 cnt++; 213 } 214 } 215 return cnt; 216 } 217 184 218 /** 185 219 * read #uiNumberOfBits# from bitstream without updating the bitstream … … 192 226 Void TComInputBitstream::pseudoRead ( UInt uiNumberOfBits, UInt& ruiBits ) 193 227 { 194 unsigned int saved_num_held_bits = m_num_held_bits;195 unsigned char saved_held_bits = m_held_bits;196 unsigned int saved_fifo_idx = m_fifo_idx;197 198 unsignednum_bits_to_read = min(uiNumberOfBits, getNumBitsLeft());228 UInt saved_num_held_bits = m_num_held_bits; 229 UChar saved_held_bits = m_held_bits; 230 UInt saved_fifo_idx = m_fifo_idx; 231 232 UInt num_bits_to_read = min(uiNumberOfBits, getNumBitsLeft()); 199 233 read(num_bits_to_read, ruiBits); 200 234 ruiBits <<= (uiNumberOfBits - num_bits_to_read); … … 213 247 214 248 /* NB, bits are extracted from the MSB of each byte. */ 215 unsignedretval = 0;249 UInt retval = 0; 216 250 if (uiNumberOfBits <= m_num_held_bits) 217 251 { … … 243 277 * n=5, len(H)=1, load 1byte, shift_down=1+3 244 278 */ 245 unsignedaligned_word = 0;246 unsignednum_bytes_to_load = (uiNumberOfBits - 1) >> 3;279 UInt aligned_word = 0; 280 UInt num_bytes_to_load = (uiNumberOfBits - 1) >> 3; 247 281 assert(m_fifo_idx + num_bytes_to_load < m_fifo->size()); 248 282 … … 256 290 257 291 /* resolve remainder bits */ 258 unsignednext_num_held_bits = (32 - uiNumberOfBits) % 8;292 UInt next_num_held_bits = (32 - uiNumberOfBits) % 8; 259 293 260 294 /* copy required part of aligned_word into retval */ … … 272 306 * into this at byte position pos. 273 307 */ 274 void TComOutputBitstream::insertAt(const TComOutputBitstream& src, unsignedpos)275 { 276 unsignedsrc_bits = src.getNumberOfWrittenBits();308 void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos) 309 { 310 UInt src_bits = src.getNumberOfWrittenBits(); 277 311 assert(0 == src_bits % 8); 278 312 … … 298 332 this->m_num_held_bits = src.m_num_held_bits; 299 333 this->m_held_bits = src.m_held_bits; 300 this->m_uiTileMarkerLocationCount = src.m_uiTileMarkerLocationCount;301 for (Int uiIdx=0; uiIdx<m_uiTileMarkerLocationCount; uiIdx++)302 {303 this->m_puiTileMarkerLocation[uiIdx] = src.m_puiTileMarkerLocation[uiIdx];304 }305 334 306 335 return *this; … … 330 359 buf->push_back(uiByte); 331 360 } 332 #if !OL_FLUSH_ALIGN333 buf->push_back(0); // The final chunk might not start byte aligned.334 #endif335 361 return new TComInputBitstream(buf); 336 362 } … … 345 371 } 346 372 373 Void TComInputBitstream::readByteAlignment() 374 { 375 UInt code = 0; 376 read( 1, code ); 377 assert(code == 1); 378 379 UInt numBits = getNumBitsUntilByteAligned(); 380 if(numBits) 381 { 382 assert(numBits <= getNumBitsLeft()); 383 read( numBits, code ); 384 assert(code == 0); 385 } 386 } 387 347 388 //! \}
Note: See TracChangeset for help on using the changeset viewer.