Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibDecoder/NALread.cpp


Ignore:
Timestamp:
16 Apr 2013, 06:39:31 (12 years ago)
Author:
seregin
Message:

copy from HM-10.0-dev-SHM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/NALread.cpp

    r2 r125  
    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 *
     
    3232 */
    3333
     34/**
     35 \file     NALread.cpp
     36 \brief    reading funtionality for NAL units
     37 */
     38
     39
    3440#include <vector>
    3541#include <algorithm>
     
    4450//! \ingroup TLibDecoder
    4551//! \{
    46 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *pcBitstream)
     52static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, Bool isVclNalUnit)
    4753{
    48   unsigned zeroCount = 0;
     54  UInt zeroCount = 0;
    4955  vector<uint8_t>::iterator it_read, it_write;
    5056
    5157  for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++)
    5258  {
     59    assert(zeroCount < 2 || *it_read >= 0x03);
    5360    if (zeroCount == 2 && *it_read == 0x03)
    5461    {
    5562      it_read++;
    5663      zeroCount = 0;
     64      if (it_read == nalUnitBuf.end())
     65      {
     66        break;
     67      }
    5768    }
    5869    zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0;
    5970    *it_write = *it_read;
     71  }
     72  assert(zeroCount == 0);
     73 
     74  if (isVclNalUnit)
     75  {
     76    // Remove cabac_zero_word from payload if present
     77    Int n = 0;
     78   
     79    while (it_write[-1] == 0x00)
     80    {
     81      it_write--;
     82      n++;
     83    }
     84   
     85    if (n > 0)
     86    {
     87      printf("\nDetected %d instances of cabac_zero_word", n/2);     
     88    }
    6089  }
    6190
     
    6392}
    6493
    65 #if NAL_UNIT_HEADER
    6694Void readNalUnitHeader(InputNALUnit& nalu)
    6795{
    6896  TComInputBitstream& bs = *nalu.m_Bitstream;
    6997
    70   bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
     98  Bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
    7199  assert(forbidden_zero_bit == 0);
    72100  nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
     101  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
    73102#if SVC_EXTENSION
    74   nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
    75103  nalu.m_layerId = nalu.m_reservedZero6Bits;
    76104#else
    77 #if TARGET_DECLAYERID_SET
    78   nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
    79105  assert(nalu.m_reservedZero6Bits == 0);
    80 #else
    81   unsigned reserved_one_6bits = bs.read(6);       // nuh_reserved_zero_6bits
    82   assert(reserved_one_6bits == 0);
    83 #endif
    84106#endif
    85107  nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
     
    87109  if ( nalu.m_temporalId )
    88110  {
    89 #if NAL_UNIT_TYPES_J1003_D7
    90111    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
    91112         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
     
    98119         && nalu.m_nalUnitType != NAL_UNIT_EOS
    99120         && nalu.m_nalUnitType != NAL_UNIT_EOB );
    100 #else
    101     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
    102          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRANT
    103          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
    104          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
    105          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR
    106          && nalu.m_nalUnitType != NAL_UNIT_VPS
    107          && nalu.m_nalUnitType != NAL_UNIT_SPS );
    108 #endif
    109121  }
    110122  else
    111123  {
    112 #if NAL_UNIT_TYPES_J1003_D7
    113124    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA
    114125         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    115126         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
    116127         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
    117 #else
    118     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA );
    119 #endif
    120128  }
    121129}
    122 #endif
    123130/**
    124131 * create a NALunit structure with given header values and storage for
     
    129136  /* perform anti-emulation prevention */
    130137  TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
    131   convertPayloadToRBSP(nalUnitBuf, pcBitstream);
    132 
     138  convertPayloadToRBSP(nalUnitBuf, (nalUnitBuf[0] & 64) == 0);
     139 
    133140  nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
    134141  delete pcBitstream;
    135 #if NAL_UNIT_HEADER
    136142  readNalUnitHeader(nalu);
    137 #else
    138   TComInputBitstream& bs = *nalu.m_Bitstream;
    139 
    140   bool forbidden_zero_bit = bs.read(1);
    141   assert(forbidden_zero_bit == 0);
    142 #if !REMOVE_NAL_REF_FLAG
    143   nalu.m_nalRefFlag  = (bs.read(1) != 0 );
    144 #endif
    145   nalu.m_nalUnitType = (NalUnitType) bs.read(6);
    146 #if REMOVE_NAL_REF_FLAG
    147   unsigned reserved_one_6bits = bs.read(6);
    148   assert(reserved_one_6bits == 0);
    149 #endif
    150 #if TEMPORAL_ID_PLUS1
    151   nalu.m_temporalId = bs.read(3) - 1;
    152 #if !REMOVE_NAL_REF_FLAG
    153   unsigned reserved_one_5bits = bs.read(5);
    154   assert(reserved_one_5bits == 0);
    155 #endif
    156 #else
    157   nalu.m_temporalId = bs.read(3);
    158   unsigned reserved_one_5bits = bs.read(5);
    159 #if SVC_EXTENSION
    160   assert(reserved_one_5bits >= 1);
    161   nalu.m_layerId = reserved_one_5bits - 1;
    162 #else
    163   assert(reserved_one_5bits == 1);
    164 #endif
    165 #endif
    166 
    167   if ( nalu.m_temporalId )
    168   {
    169 #if NAL_UNIT_TYPES_J1003_D7
    170     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
    171          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
    172          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
    173          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR
    174          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
    175          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA );
    176 #else
    177     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
    178          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRANT
    179          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
    180          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
    181          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR );
    182 #endif
    183   }
    184 #endif
    185143}
    186144//! \}
Note: See TracChangeset for help on using the changeset viewer.