Ticket #994: entry_point_offset_wpp_hm-9.1.patch

File entry_point_offset_wpp_hm-9.1.patch, 9.5 KB (added by kiranmisra, 11 years ago)

Proposed patch for substream entry point information

  • Lib/TLibCommon/TComBitStream.h

     
    162162class TComInputBitstream
    163163{
    164164  std::vector<uint8_t> *m_fifo; /// FIFO for storage of complete bytes
     165  std::vector<UInt> m_emulationPreventionByteLocation;
    165166
    166167protected:
    167168  UInt m_fifo_idx; /// Read index into m_fifo
     
    205206  Void                deleteFifo(); // Delete internal fifo of bitstream.
    206207  UInt  getNumBitsRead() { return m_numBitsRead; }
    207208  Void readByteAlignment();
     209
     210  Void      pushEmulationPreventionByteLocation ( UInt pos )                  { m_emulationPreventionByteLocation.push_back( pos ); }
     211  UInt      numEmulationPreventionBytesRead     ()                            { return m_emulationPreventionByteLocation.size();    }
     212  std::vector<UInt>  getEmulationPreventionByteLocation  ()                   { return m_emulationPreventionByteLocation;           }
     213  UInt      getEmulationPreventionByteLocation  ( UInt idx )                  { return m_emulationPreventionByteLocation[ idx ];    }
     214  Void      clearEmulationPreventionByteLocation()                            { m_emulationPreventionByteLocation.clear();          }
     215  Void      setEmulationPreventionByteLocation  ( std::vector<UInt> vec )     { m_emulationPreventionByteLocation = vec;            }
    208216};
    209217
    210218//! \}
  • Lib/TLibDecoder/NALread.cpp

     
    5858  UInt zeroCount = 0;
    5959  vector<uint8_t>::iterator it_read, it_write;
    6060
    61   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++)
     61  UInt pos = 0;
     62  pcBitstream->clearEmulationPreventionByteLocation();
     63  for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++)
    6264  {
    6365    assert(zeroCount < 2 || *it_read >= 0x03);
    6466    if (zeroCount == 2 && *it_read == 0x03)
    6567    {
     68      pcBitstream->pushEmulationPreventionByteLocation( pos );
     69      pos++;
    6670      it_read++;
    6771      zeroCount = 0;
    6872      if (it_read == nalUnitBuf.end())
     
    144148#endif
    145149 
    146150  nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
     151  nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
    147152  delete pcBitstream;
    148153  readNalUnitHeader(nalu);
    149154}
  • Lib/TLibDecoder/TDecCAVLC.cpp

     
    13371337    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
    13381338
    13391339  }
    1340     if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     1340
     1341  UInt *entryPointOffset          = NULL;
     1342  UInt numEntryPointOffsets, offsetLenMinus1;
     1343  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     1344  {
     1345    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     1346    if (numEntryPointOffsets>0)
    13411347    {
    1342       UInt *entryPointOffset          = NULL;
    1343       UInt numEntryPointOffsets, offsetLenMinus1;
     1348      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
     1349    }
     1350    entryPointOffset = new UInt[numEntryPointOffsets];
     1351    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     1352    {
     1353      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
     1354      entryPointOffset[ idx ] = uiCode;
     1355    }
     1356  }
     1357  else
     1358  {
     1359    rpcSlice->setNumEntryPointOffsets ( 0 );
     1360  }
    13441361
    1345       READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
    1346       if (numEntryPointOffsets>0)
    1347       {
    1348         READ_UVLC(offsetLenMinus1, "offset_len_minus1");
    1349       }
    1350       entryPointOffset = new UInt[numEntryPointOffsets];
    1351       for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    1352       {
    1353         READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
    1354         entryPointOffset[ idx ] = uiCode;
    1355       }
     1362  if(pps->getSliceHeaderExtensionPresentFlag())
     1363  {
     1364    READ_UVLC(uiCode,"slice_header_extension_length");
     1365    for(Int i=0; i<uiCode; i++)
     1366    {
     1367      UInt ignore;
     1368      READ_CODE(8,ignore,"slice_header_extension_data_byte");
     1369    }
     1370  }
     1371  m_pcBitstream->readByteAlignment();
    13561372
    1357       if ( pps->getTilesEnabledFlag() )
    1358       {
    1359         rpcSlice->setTileLocationCount( numEntryPointOffsets );
     1373  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     1374  {
     1375    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
     1376    Int  curEntryPointOffset     = 0;
     1377    Int  prevEntryPointOffset    = 0;
     1378    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     1379    {
     1380      curEntryPointOffset += entryPointOffset[ idx ];
    13601381
    1361         UInt prevPos = 0;
    1362         for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    1363         {
    1364           rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
    1365           prevPos += entryPointOffset[ idx ];
    1366         }
    1367       }
    1368       else if ( pps->getEntropyCodingSyncEnabledFlag() )
     1382      Int emulationPreventionByteCount = 0;
     1383      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    13691384      {
    1370       Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
    1371         rpcSlice->allocSubstreamSizes(numSubstreams);
    1372         UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
    1373         for (Int idx=0; idx<numSubstreams-1; idx++)
     1385        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
     1386             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
    13741387        {
    1375           if ( idx < numEntryPointOffsets )
    1376           {
    1377             pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    1378           }
    1379           else
    1380           {
    1381             pSubstreamSizes[ idx ] = 0;
    1382           }
     1388          emulationPreventionByteCount++;
    13831389        }
    13841390      }
    13851391
    1386       if (entryPointOffset)
     1392      entryPointOffset[ idx ] -= emulationPreventionByteCount;
     1393      prevEntryPointOffset = curEntryPointOffset;
     1394    }
     1395
     1396    if ( pps->getTilesEnabledFlag() )
     1397    {
     1398      rpcSlice->setTileLocationCount( numEntryPointOffsets );
     1399
     1400      UInt prevPos = 0;
     1401      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    13871402      {
    1388         delete [] entryPointOffset;
     1403        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
     1404        prevPos += entryPointOffset[ idx ];
    13891405      }
    13901406    }
    1391     else
     1407    else if ( pps->getEntropyCodingSyncEnabledFlag() )
    13921408    {
    1393       rpcSlice->setNumEntryPointOffsets ( 0 );
     1409      Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
     1410      rpcSlice->allocSubstreamSizes(numSubstreams);
     1411      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
     1412      for (Int idx=0; idx<numSubstreams-1; idx++)
     1413      {
     1414        if ( idx < numEntryPointOffsets )
     1415        {
     1416          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
     1417        }
     1418        else
     1419        {
     1420          pSubstreamSizes[ idx ] = 0;
     1421        }
     1422      }
    13941423    }
    13951424
    1396   if(pps->getSliceHeaderExtensionPresentFlag())
    1397   {
    1398     READ_UVLC(uiCode,"slice_header_extension_length");
    1399     for(Int i=0; i<uiCode; i++)
     1425    if (entryPointOffset)
    14001426    {
    1401       UInt ignore;
    1402       READ_CODE(8,ignore,"slice_header_extension_data_byte");
     1427      delete [] entryPointOffset;
    14031428    }
    14041429  }
    1405   m_pcBitstream->readByteAlignment();
     1430
    14061431  return;
    14071432}
    14081433 
  • Lib/TLibEncoder/TEncGOP.cpp

     
    11581158              }
    11591159              if (ui+1 < pcSlice->getPPS()->getNumSubstreams())
    11601160              {
    1161                 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits();
     1161
     1162                UInt uiCounter = 0;
     1163                vector<uint8_t>& rbsp   = pcSubstreamsOut[ui].getFIFO();
     1164                for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
     1165                {
     1166                  /* 1) find the next emulated 00 00 {00,01,02,03}
     1167                   * 2a) if not found, write all remaining bytes out, stop.
     1168                   * 2b) otherwise, write all non-emulated bytes out
     1169                   * 3) insert emulation_prevention_three_byte
     1170                   */
     1171                  vector<uint8_t>::iterator found = it;
     1172                  do
     1173                  {
     1174                    /* NB, end()-1, prevents finding a trailing two byte sequence */
     1175                    found = search_n(found, rbsp.end()-1, 2, 0);
     1176                    found++;
     1177                    /* if not found, found == end, otherwise found = second zero byte */
     1178                    if (found == rbsp.end())
     1179                    {
     1180                      break;
     1181                    }
     1182                    if (*(++found) <= 3)
     1183                    {
     1184                      break;
     1185                    }
     1186                  } while (true);
     1187                  it = found;
     1188                  if (found != rbsp.end())
     1189                  {
     1190                    it++;
     1191                    uiCounter++;
     1192                  }
     1193                }
     1194                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (uiCounter<<3);
    11621195              }
    11631196            }
    11641197