Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComBitStream.cpp


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComBitStream.cpp

    r1179 r1313  
    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. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5353TComOutputBitstream::TComOutputBitstream()
    5454{
    55   m_fifo = new vector<uint8_t>;
    5655  clear();
    5756}
     
    5958TComOutputBitstream::~TComOutputBitstream()
    6059{
    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
     63TComInputBitstream::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
     72TComInputBitstream::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{ }
    7680
    7781// ====================================================================================================================
     
    7983// ====================================================================================================================
    8084
     85Void 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
    8193Char* TComOutputBitstream::getByteStream() const
    8294{
    83   return (Char*) &m_fifo->front();
     95  return (Char*) &m_fifo.front();
    8496}
    8597
    8698UInt TComOutputBitstream::getByteStreamLength()
    8799{
    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
     103Void TComOutputBitstream::clear()
     104{
     105  m_fifo.clear();
    94106  m_held_bits = 0;
    95107  m_num_held_bits = 0;
     
    130142  switch (num_total_bits >> 3)
    131143  {
    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);
    136148  }
    137149
     
    153165    return;
    154166  }
    155   m_fifo->push_back(m_held_bits);
     167  m_fifo.push_back(m_held_bits);
    156168  m_held_bits = 0;
    157169  m_num_held_bits = 0;
     
    217229
    218230/**
    219  * read #uiNumberOfBits# from bitstream without updating the bitstream
    220  * state, storing the result in #ruiBits#.
     231 * read uiNumberOfBits from bitstream without updating the bitstream
     232 * state, storing the result in ruiBits.
    221233 *
    222  * If reading #uiNumberOfBits# would overrun the bitstream buffer,
    223  * the bitsream is effectively padded with sufficient zero-bits to
     234 * If reading uiNumberOfBits would overrun the bitstream buffer,
     235 * the bitstream is effectively padded with sufficient zero-bits to
    224236 * avoid the overrun.
    225237 */
     
    243255{
    244256  assert( uiNumberOfBits <= 32 );
    245  
     257
    246258  m_numBitsRead += uiNumberOfBits;
    247259
     
    279291  UInt aligned_word = 0;
    280292  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());
    282294
    283295  switch (num_bytes_to_load)
    284296  {
    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++];
    289301  }
    290302
     
    306318 * into this at byte position pos.
    307319 */
    308 void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos)
     320Void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos)
    309321{
    310322  UInt src_bits = src.getNumberOfWrittenBits();
    311323  assert(0 == src_bits % 8);
    312324
    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
     329UInt TComInputBitstream::readOutTrailingBits ()
     330{
     331  UInt count=0;
    319332  UInt uiBits = 0;
    320333
    321334  while ( ( getNumBitsLeft() > 0 ) && (getNumBitsUntilByteAligned()!=0) )
    322335  {
     336    count++;
    323337    read ( 1, uiBits );
    324338  }
    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//}
    337352
    338353/**
    339  - extract substream from the current bitstream
    340  .
    341  \param  pcBitstream  bitstream which contains substreams
     354 Extract substream from the current bitstream.
     355
    342356 \param  uiNumBits    number of bits to transfer
    343357 */
     
    345359{
    346360  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  {
    349379  for (UInt ui = 0; ui < uiNumBytes; ui++)
    350380  {
     381      UInt uiByte;
    351382    read(8, uiByte);
    352     buf->push_back(uiByte);
     383      buf.push_back(uiByte);
     384    }
    353385  }
    354386  if (uiNumBits&0x7)
    355387  {
    356     uiByte = 0;
     388    UInt uiByte = 0;
    357389    read(uiNumBits&0x7, uiByte);
    358390    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
     396UInt TComInputBitstream::readByteAlignment()
    374397{
    375398  UInt code = 0;
     
    384407    assert(code == 0);
    385408  }
     409  return numBits+1;
    386410}
    387411
Note: See TracChangeset for help on using the changeset viewer.