Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComBitStream.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComBitStream.cpp
r1179 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 53 53 TComOutputBitstream::TComOutputBitstream() 54 54 { 55 m_fifo = new vector<uint8_t>;56 55 clear(); 57 56 } … … 59 58 TComOutputBitstream::~TComOutputBitstream() 60 59 { 61 delete m_fifo; 62 } 63 64 TComInputBitstream::TComInputBitstream(std::vector<uint8_t>* buf) 65 { 66 m_fifo = buf; 67 m_fifo_idx = 0; 68 m_held_bits = 0; 69 m_num_held_bits = 0; 70 m_numBitsRead = 0; 71 } 72 73 TComInputBitstream::~TComInputBitstream() 74 { 75 } 60 } 61 62 63 TComInputBitstream::TComInputBitstream() 64 : m_fifo() 65 , m_emulationPreventionByteLocation() 66 , m_fifo_idx(0) 67 , m_num_held_bits(0) 68 , m_held_bits(0) 69 , m_numBitsRead(0) 70 { } 71 72 TComInputBitstream::TComInputBitstream(const TComInputBitstream &src) 73 : m_fifo(src.m_fifo) 74 , m_emulationPreventionByteLocation(src.m_emulationPreventionByteLocation) 75 , m_fifo_idx(src.m_fifo_idx) 76 , m_num_held_bits(src.m_num_held_bits) 77 , m_held_bits(src.m_held_bits) 78 , m_numBitsRead(src.m_numBitsRead) 79 { } 76 80 77 81 // ==================================================================================================================== … … 79 83 // ==================================================================================================================== 80 84 85 Void TComInputBitstream::resetToStart() 86 { 87 m_fifo_idx=0; 88 m_num_held_bits=0; 89 m_held_bits=0; 90 m_numBitsRead=0; 91 } 92 81 93 Char* TComOutputBitstream::getByteStream() const 82 94 { 83 return (Char*) &m_fifo ->front();95 return (Char*) &m_fifo.front(); 84 96 } 85 97 86 98 UInt TComOutputBitstream::getByteStreamLength() 87 99 { 88 return UInt(m_fifo ->size());89 } 90 91 void TComOutputBitstream::clear()92 { 93 m_fifo ->clear();100 return UInt(m_fifo.size()); 101 } 102 103 Void TComOutputBitstream::clear() 104 { 105 m_fifo.clear(); 94 106 m_held_bits = 0; 95 107 m_num_held_bits = 0; … … 130 142 switch (num_total_bits >> 3) 131 143 { 132 case 4: m_fifo ->push_back(write_bits >> 24);133 case 3: m_fifo ->push_back(write_bits >> 16);134 case 2: m_fifo ->push_back(write_bits >> 8);135 case 1: m_fifo ->push_back(write_bits);144 case 4: m_fifo.push_back(write_bits >> 24); 145 case 3: m_fifo.push_back(write_bits >> 16); 146 case 2: m_fifo.push_back(write_bits >> 8); 147 case 1: m_fifo.push_back(write_bits); 136 148 } 137 149 … … 153 165 return; 154 166 } 155 m_fifo ->push_back(m_held_bits);167 m_fifo.push_back(m_held_bits); 156 168 m_held_bits = 0; 157 169 m_num_held_bits = 0; … … 217 229 218 230 /** 219 * read #uiNumberOfBits#from bitstream without updating the bitstream220 * state, storing the result in #ruiBits#.231 * read uiNumberOfBits from bitstream without updating the bitstream 232 * state, storing the result in ruiBits. 221 233 * 222 * If reading #uiNumberOfBits#would overrun the bitstream buffer,223 * the bits ream is effectively padded with sufficient zero-bits to234 * If reading uiNumberOfBits would overrun the bitstream buffer, 235 * the bitstream is effectively padded with sufficient zero-bits to 224 236 * avoid the overrun. 225 237 */ … … 243 255 { 244 256 assert( uiNumberOfBits <= 32 ); 245 257 246 258 m_numBitsRead += uiNumberOfBits; 247 259 … … 279 291 UInt aligned_word = 0; 280 292 UInt num_bytes_to_load = (uiNumberOfBits - 1) >> 3; 281 assert(m_fifo_idx + num_bytes_to_load < m_fifo ->size());293 assert(m_fifo_idx + num_bytes_to_load < m_fifo.size()); 282 294 283 295 switch (num_bytes_to_load) 284 296 { 285 case 3: aligned_word = (*m_fifo)[m_fifo_idx++] << 24;286 case 2: aligned_word |= (*m_fifo)[m_fifo_idx++] << 16;287 case 1: aligned_word |= (*m_fifo)[m_fifo_idx++] << 8;288 case 0: aligned_word |= (*m_fifo)[m_fifo_idx++];297 case 3: aligned_word = m_fifo[m_fifo_idx++] << 24; 298 case 2: aligned_word |= m_fifo[m_fifo_idx++] << 16; 299 case 1: aligned_word |= m_fifo[m_fifo_idx++] << 8; 300 case 0: aligned_word |= m_fifo[m_fifo_idx++]; 289 301 } 290 302 … … 306 318 * into this at byte position pos. 307 319 */ 308 void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos)320 Void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos) 309 321 { 310 322 UInt src_bits = src.getNumberOfWrittenBits(); 311 323 assert(0 == src_bits % 8); 312 324 313 vector<uint8_t>::iterator at = this->m_fifo->begin() + pos; 314 this->m_fifo->insert(at, src.m_fifo->begin(), src.m_fifo->end()); 315 } 316 317 Void TComInputBitstream::readOutTrailingBits () 318 { 325 vector<uint8_t>::iterator at = m_fifo.begin() + pos; 326 m_fifo.insert(at, src.m_fifo.begin(), src.m_fifo.end()); 327 } 328 329 UInt TComInputBitstream::readOutTrailingBits () 330 { 331 UInt count=0; 319 332 UInt uiBits = 0; 320 333 321 334 while ( ( getNumBitsLeft() > 0 ) && (getNumBitsUntilByteAligned()!=0) ) 322 335 { 336 count++; 323 337 read ( 1, uiBits ); 324 338 } 325 } 326 327 TComOutputBitstream& TComOutputBitstream::operator= (const TComOutputBitstream& src) 328 { 329 vector<uint8_t>::iterator at = this->m_fifo->begin(); 330 this->m_fifo->insert(at, src.m_fifo->begin(), src.m_fifo->end()); 331 332 this->m_num_held_bits = src.m_num_held_bits; 333 this->m_held_bits = src.m_held_bits; 334 335 return *this; 336 } 339 return count; 340 } 341 // 342 //TComOutputBitstream& TComOutputBitstream::operator= (const TComOutputBitstream& src) 343 //{ 344 // vector<uint8_t>::iterator at = m_fifo.begin(); 345 // m_fifo.insert(at, src.m_fifo.begin(), src.m_fifo.end()); 346 // 347 // m_num_held_bits = src.m_num_held_bits; 348 // m_held_bits = src.m_held_bits; 349 // 350 // return *this; 351 //} 337 352 338 353 /** 339 - extract substream from the current bitstream 340 . 341 \param pcBitstream bitstream which contains substreams 354 Extract substream from the current bitstream. 355 342 356 \param uiNumBits number of bits to transfer 343 357 */ … … 345 359 { 346 360 UInt uiNumBytes = uiNumBits/8; 347 std::vector<uint8_t>* buf = new std::vector<uint8_t>; 348 UInt uiByte; 361 TComInputBitstream *pResult = new TComInputBitstream; 362 363 std::vector<uint8_t> &buf = pResult->getFifo(); 364 buf.reserve((uiNumBits+7)>>3); 365 366 if (m_num_held_bits == 0) 367 { 368 std::size_t currentOutputBufferSize=buf.size(); 369 const UInt uiNumBytesToReadFromFifo = std::min<UInt>(uiNumBytes, (UInt)m_fifo.size() - m_fifo_idx); 370 buf.resize(currentOutputBufferSize+uiNumBytes); 371 memcpy(&(buf[currentOutputBufferSize]), &(m_fifo[m_fifo_idx]), uiNumBytesToReadFromFifo); m_fifo_idx+=uiNumBytesToReadFromFifo; 372 if (uiNumBytesToReadFromFifo != uiNumBytes) 373 { 374 memset(&(buf[currentOutputBufferSize+uiNumBytesToReadFromFifo]), 0, uiNumBytes - uiNumBytesToReadFromFifo); 375 } 376 } 377 else 378 { 349 379 for (UInt ui = 0; ui < uiNumBytes; ui++) 350 380 { 381 UInt uiByte; 351 382 read(8, uiByte); 352 buf->push_back(uiByte); 383 buf.push_back(uiByte); 384 } 353 385 } 354 386 if (uiNumBits&0x7) 355 387 { 356 uiByte = 0;388 UInt uiByte = 0; 357 389 read(uiNumBits&0x7, uiByte); 358 390 uiByte <<= 8-(uiNumBits&0x7); 359 buf->push_back(uiByte); 360 } 361 return new TComInputBitstream(buf); 362 } 363 364 /** 365 - delete internal fifo 366 */ 367 Void TComInputBitstream::deleteFifo() 368 { 369 delete m_fifo; 370 m_fifo = NULL; 371 } 372 373 Void TComInputBitstream::readByteAlignment() 391 buf.push_back(uiByte); 392 } 393 return pResult; 394 } 395 396 UInt TComInputBitstream::readByteAlignment() 374 397 { 375 398 UInt code = 0; … … 384 407 assert(code == 0); 385 408 } 409 return numBits+1; 386 410 } 387 411
Note: See TracChangeset for help on using the changeset viewer.