Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/NALwrite.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/TLibEncoder/NALwrite.cpp

    r1179 r1313  
    44 * 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 *
     
    5353  bsNALUHeader.write(0,1);                    // forbidden_zero_bit
    5454  bsNALUHeader.write(nalu.m_nalUnitType, 6);  // nal_unit_type
    55 #if H_MV
    56   bsNALUHeader.write(nalu.m_layerId, 6);      // layerId       
     55#if NH_MV
     56  bsNALUHeader.write(nalu.m_nuhLayerId, 6);      // layerId       
    5757#else
    58   bsNALUHeader.write(nalu.m_reservedZero6Bits, 6);                   // nuh_reserved_zero_6bits
     58  bsNALUHeader.write(nalu.m_nuhLayerId, 6);   // nuh_layer_id
    5959#endif
    6060  bsNALUHeader.write(nalu.m_temporalId+1, 3); // nuh_temporal_id_plus1
     
    6666 * emulation as required.  nalu.m_RBSPayload must be byte aligned.
    6767 */
    68 void write(ostream& out, OutputNALUnit& nalu)
     68Void write(ostream& out, OutputNALUnit& nalu)
    6969{
    7070  writeNalUnitHeader(out, nalu);
     
    9191  vector<uint8_t>& rbsp   = nalu.m_Bitstream.getFIFO();
    9292
    93   if (rbsp.size() == 0)
     93  vector<uint8_t> outputBuffer;
     94  outputBuffer.resize(rbsp.size()*2+1); //there can never be enough emulation_prevention_three_bytes to require this much space
     95  std::size_t outputAmount = 0;
     96  Int         zeroCount    = 0;
     97  for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end(); it++)
    9498  {
    95     return;
     99    const uint8_t v=(*it);
     100    if (zeroCount==2 && v<=3)
     101    {
     102      outputBuffer[outputAmount++]=emulation_prevention_three_byte[0];
     103      zeroCount=0;
     104    }
     105
     106    if (v==0)
     107    {
     108      zeroCount++;
     109    }
     110    else
     111    {
     112      zeroCount=0;
     113    }
     114    outputBuffer[outputAmount++]=v;
    96115  }
    97 
    98   for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
    99   {
    100     /* 1) find the next emulated 00 00 {00,01,02,03}
    101      * 2a) if not found, write all remaining bytes out, stop.
    102      * 2b) otherwise, write all non-emulated bytes out
    103      * 3) insert emulation_prevention_three_byte
    104      */
    105     vector<uint8_t>::iterator found = it;
    106     do
    107     {
    108       /* NB, end()-1, prevents finding a trailing two byte sequence */
    109       found = search_n(found, rbsp.end()-1, 2, 0);
    110       found++;
    111       /* if not found, found == end, otherwise found = second zero byte */
    112       if (found == rbsp.end())
    113         break;
    114       if (*(++found) <= 3)
    115         break;
    116     } while (true);
    117 
    118     it = found;
    119     if (found != rbsp.end())
    120     {
    121       it = rbsp.insert(found, emulation_prevention_three_byte[0]);
    122     }
    123   }
    124 
    125   out.write((Char*)&(*rbsp.begin()), rbsp.end() - rbsp.begin());
    126116
    127117  /* 7.4.1.1
     
    130120   * to 0x03 is appended to the end of the data.
    131121   */
    132   if (rbsp.back() == 0x00)
     122  if (zeroCount>0)
    133123  {
    134     out.write(emulation_prevention_three_byte, 1);
     124    outputBuffer[outputAmount++]=emulation_prevention_three_byte[0];
    135125  }
    136 }
    137 
    138 /**
    139  * Write rbsp_trailing_bits to bs causing it to become byte-aligned
    140  */
    141 void writeRBSPTrailingBits(TComOutputBitstream& bs)
    142 {
    143   bs.write( 1, 1 );
    144   bs.writeAlignZero();
    145 }
    146 
    147 /**
    148  * Copy NALU from naluSrc to naluDest
    149  */
    150 void copyNaluData(OutputNALUnit& naluDest, const OutputNALUnit& naluSrc)
    151 {
    152   naluDest.m_nalUnitType = naluSrc.m_nalUnitType;
    153 #if H_MV
    154   naluDest.m_layerId  = naluSrc.m_layerId;
    155 #else
    156   naluDest.m_reservedZero6Bits  = naluSrc.m_reservedZero6Bits;
    157 #endif
    158   naluDest.m_temporalId  = naluSrc.m_temporalId;
    159   naluDest.m_Bitstream   = naluSrc.m_Bitstream;
     126  out.write((Char*)&(*outputBuffer.begin()), outputAmount);
    160127}
    161128
Note: See TracChangeset for help on using the changeset viewer.