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


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

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

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5555  m_fifo = new vector<uint8_t>;
    5656  clear();
    57   m_puiTileMarkerLocation     = new UInt[MAX_MARKER_PER_NALU];
    58   m_uiTileMarkerLocationCount = 0;
    5957}
    6058
     
    6260{
    6361  delete m_fifo;
    64   delete [] m_puiTileMarkerLocation;
    6562}
    6663
     
    7168  m_held_bits = 0;
    7269  m_num_held_bits = 0;
    73   m_puiTileMarkerLocation     = new UInt[MAX_MARKER_PER_NALU];
    74   m_uiTileMarkerLocationCount = 0;
    7570  m_numBitsRead = 0;
    7671}
     
    7873TComInputBitstream::~TComInputBitstream()
    7974{
    80   delete [] m_puiTileMarkerLocation;
    8175}
    8276
     
    8579// ====================================================================================================================
    8680
    87 char* TComOutputBitstream::getByteStream() const
    88 {
    89   return (char*) &m_fifo->front();
    90 }
    91 
    92 unsigned int TComOutputBitstream::getByteStreamLength()
    93 {
    94   return unsigned(m_fifo->size());
     81Char* TComOutputBitstream::getByteStream() const
     82{
     83  return (Char*) &m_fifo->front();
     84}
     85
     86UInt TComOutputBitstream::getByteStreamLength()
     87{
     88  return UInt(m_fifo->size());
    9589}
    9690
     
    10094  m_held_bits = 0;
    10195  m_num_held_bits = 0;
    102   m_uiTileMarkerLocationCount = 0;
    10396}
    10497
     
    10699{
    107100  assert( uiNumberOfBits <= 32 );
     101  assert( uiNumberOfBits == 32 || (uiBits & (~0 << uiNumberOfBits)) == 0 );
    108102
    109103  /* any modulo 8 remainder of num_total_bits cannot be written this time,
    110104   * and will be held until next time. */
    111   unsigned num_total_bits = uiNumberOfBits + m_num_held_bits;
    112   unsigned next_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;
    113107
    114108  /* form a byte aligned word (write_bits), by concatenating any held bits
     
    118112   * len(H)=7, len(V)=2: ... ---- HHHH HHHV . V000 0000, next_num_held_bits=1
    119113   * 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);
    121115
    122116  if (!(num_total_bits >> 3))
     
    131125
    132126  /* topword serves to justify held_bits to align with the msb of uiBits */
    133   unsigned topword = (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);
    135129
    136130  switch (num_total_bits >> 3)
     
    148142Void TComOutputBitstream::writeAlignOne()
    149143{
    150   unsigned int num_bits = getNumBitsUntilByteAligned();
     144  UInt num_bits = getNumBitsUntilByteAligned();
    151145  write((1 << num_bits) - 1, num_bits);
    152146  return;
     
    156150{
    157151  if (0 == m_num_held_bits)
     152  {
    158153    return;
     154  }
    159155  m_fifo->push_back(m_held_bits);
    160156  m_held_bits = 0;
     
    182178}
    183179
     180Void TComOutputBitstream::writeByteAlignment()
     181{
     182  write( 1, 1);
     183  writeAlignZero();
     184}
     185
     186Int 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
    184218/**
    185219 * read #uiNumberOfBits# from bitstream without updating the bitstream
     
    192226Void TComInputBitstream::pseudoRead ( UInt uiNumberOfBits, UInt& ruiBits )
    193227{
    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   unsigned num_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());
    199233  read(num_bits_to_read, ruiBits);
    200234  ruiBits <<= (uiNumberOfBits - num_bits_to_read);
     
    213247
    214248  /* NB, bits are extracted from the MSB of each byte. */
    215   unsigned retval = 0;
     249  UInt retval = 0;
    216250  if (uiNumberOfBits <= m_num_held_bits)
    217251  {
     
    243277   * n=5,  len(H)=1, load 1byte,  shift_down=1+3
    244278   */
    245   unsigned aligned_word = 0;
    246   unsigned num_bytes_to_load = (uiNumberOfBits - 1) >> 3;
     279  UInt aligned_word = 0;
     280  UInt num_bytes_to_load = (uiNumberOfBits - 1) >> 3;
    247281  assert(m_fifo_idx + num_bytes_to_load < m_fifo->size());
    248282
     
    256290
    257291  /* resolve remainder bits */
    258   unsigned next_num_held_bits = (32 - uiNumberOfBits) % 8;
     292  UInt next_num_held_bits = (32 - uiNumberOfBits) % 8;
    259293
    260294  /* copy required part of aligned_word into retval */
     
    272306 * into this at byte position pos.
    273307 */
    274 void TComOutputBitstream::insertAt(const TComOutputBitstream& src, unsigned pos)
    275 {
    276   unsigned src_bits = src.getNumberOfWrittenBits();
     308void TComOutputBitstream::insertAt(const TComOutputBitstream& src, UInt pos)
     309{
     310  UInt src_bits = src.getNumberOfWrittenBits();
    277311  assert(0 == src_bits % 8);
    278312
     
    298332  this->m_num_held_bits             = src.m_num_held_bits;
    299333  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   }
    305334
    306335  return *this;
     
    330359    buf->push_back(uiByte);
    331360  }
    332 #if !OL_FLUSH_ALIGN
    333   buf->push_back(0); // The final chunk might not start byte aligned.
    334 #endif
    335361  return new TComInputBitstream(buf);
    336362}
     
    345371}
    346372
     373Void 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
    347388//! \}
Note: See TracChangeset for help on using the changeset viewer.