Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/NALread.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/TLibDecoder/NALread.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 *
     
    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, TComInputBitstream *bitstream, Bool isVclNalUnit)
    4753{
    48   unsigned zeroCount = 0;
     54  UInt zeroCount = 0;
    4955  vector<uint8_t>::iterator it_read, it_write;
    5056
    51   UInt *auiStoredTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU];
    52   // Remove tile markers and note the bitstream location
    53   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++ )
     57  UInt pos = 0;
     58  bitstream->clearEmulationPreventionByteLocation();
     59  for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++)
    5460  {
    55     Bool bTileMarkerFound = false;
    56     if ( ( it_read - nalUnitBuf.begin() ) < ( nalUnitBuf.size() - 2 ) )
    57     {
    58       if ( (*(it_read) == 0x00) && (*(it_read+1) == 0x00) && (*(it_read+2) == 0x02) ) // tile marker detected
    59       {
    60         it_read += 2;
    61         UInt uiDistance  = (UInt) (it_write - nalUnitBuf.begin());
    62         UInt uiCount     = pcBitstream->getTileMarkerLocationCount();
    63         bTileMarkerFound = true;
    64         pcBitstream->setTileMarkerLocation( uiCount, uiDistance );
    65         auiStoredTileMarkerLocation[uiCount] = uiDistance;
    66         pcBitstream->setTileMarkerLocationCount( uiCount + 1 );
    67        
    68       }
    69     }
    70 
    71     if (!bTileMarkerFound)
    72     {
    73       *it_write = *it_read;
    74       it_write++;
    75     }
    76   }
    77   nalUnitBuf.resize(it_write - nalUnitBuf.begin());
    78 
    79   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++)
    80   {
     61    assert(zeroCount < 2 || *it_read >= 0x03);
    8162    if (zeroCount == 2 && *it_read == 0x03)
    8263    {
    83       // update tile marker location
    84       UInt uiDistance = (UInt) (it_read - nalUnitBuf.begin());
    85       for (UInt uiIdx=0; uiIdx<pcBitstream->getTileMarkerLocationCount(); uiIdx++)
    86       {
    87         if (auiStoredTileMarkerLocation[ uiIdx ] >= uiDistance)
    88         {
    89           pcBitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation( uiIdx )-1 );
    90         }
    91       }
     64      bitstream->pushEmulationPreventionByteLocation( pos );
     65      pos++;
    9266      it_read++;
    9367      zeroCount = 0;
     68      if (it_read == nalUnitBuf.end())
     69      {
     70        break;
     71      }
    9472    }
    9573    zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0;
    9674    *it_write = *it_read;
    9775  }
     76  assert(zeroCount == 0);
     77 
     78  if (isVclNalUnit)
     79  {
     80    // Remove cabac_zero_word from payload if present
     81    Int n = 0;
     82   
     83    while (it_write[-1] == 0x00)
     84    {
     85      it_write--;
     86      n++;
     87    }
     88   
     89    if (n > 0)
     90    {
     91      printf("\nDetected %d instances of cabac_zero_word", n/2);     
     92    }
     93  }
    9894
    9995  nalUnitBuf.resize(it_write - nalUnitBuf.begin());
    100   delete [] auiStoredTileMarkerLocation;
    10196}
    10297
     98Void readNalUnitHeader(InputNALUnit& nalu)
     99{
     100  TComInputBitstream& bs = *nalu.m_Bitstream;
     101
     102  Bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
     103  assert(forbidden_zero_bit == 0);
     104  nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
     105#if H_MV
     106  nalu.m_layerId = bs.read(6);                 // layerId
     107#else
     108  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
     109  assert(nalu.m_reservedZero6Bits == 0);
     110#endif
     111  nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
     112
     113  if ( nalu.m_temporalId )
     114  {
     115    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
     116         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
     117         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
     118         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
     119         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
     120         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
     121         && nalu.m_nalUnitType != NAL_UNIT_VPS
     122         && nalu.m_nalUnitType != NAL_UNIT_SPS
     123         && nalu.m_nalUnitType != NAL_UNIT_EOS
     124         && nalu.m_nalUnitType != NAL_UNIT_EOB );
     125  }
     126  else
     127  {
     128    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
     129         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
     130         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
     131         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
     132  }
     133}
    103134/**
    104135 * create a NALunit structure with given header values and storage for
     
    109140  /* perform anti-emulation prevention */
    110141  TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
    111   convertPayloadToRBSP(nalUnitBuf, pcBitstream);
    112 
     142  convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0);
     143 
    113144  nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
    114   // copy the tile marker location information
    115   nalu.m_Bitstream->setTileMarkerLocationCount( pcBitstream->getTileMarkerLocationCount() );
    116   for (UInt uiIdx=0; uiIdx < nalu.m_Bitstream->getTileMarkerLocationCount(); uiIdx++)
    117   {
    118     nalu.m_Bitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation(uiIdx) );
    119   }
     145  nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
    120146  delete pcBitstream;
    121   TComInputBitstream& bs = *nalu.m_Bitstream;
    122 
    123   bool forbidden_zero_bit = bs.read(1);
    124   assert(forbidden_zero_bit == 0);
    125 
    126   nalu.m_nalRefFlag  = (bs.read(1) != 0 );
    127   nalu.m_nalUnitType = (NalUnitType) bs.read(6);
    128 
    129 #if QC_MVHEVC_B0046
    130   //nalu.m_layerId    = bs.read(6);
    131   nalu.m_layerId    = bs.read(5);
    132   nalu.m_temporalId = bs.read(3) - 1;
    133 #else
    134   nalu.m_temporalId = bs.read(3);
    135  //  unsigned reserved_one_5bits = bs.read(5);
    136  //  assert(reserved_one_5bits == 1);
    137 #if VIDYO_VPS_INTEGRATION
    138   nalu.m_layerId  = bs.read(5) - 1;
    139 #else
    140   nalu.m_viewId   = bs.read(4)-1;
    141   nalu.m_isDepth  = bs.read(1);
    142 #endif
    143   if ( nalu.m_temporalId )
    144   {
    145 #if QC_REM_IDV_B0046
    146     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR);
    147 #else
    148     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDV );
    149 #endif
    150   }
    151 #endif
     147  readNalUnitHeader(nalu);
    152148}
    153149//! \}
Note: See TracChangeset for help on using the changeset viewer.