Changeset 56 in 3DVCSoftware for trunk/source/App/TAppExtractor


Ignore:
Timestamp:
11 May 2012, 21:20:17 (13 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

Location:
trunk/source/App/TAppExtractor
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/App/TAppExtractor/TAppExtrCfg.cpp

    r42 r56  
    4040#include <string>
    4141#include "TAppExtrCfg.h"
    42 #include "../../App/TAppCommon/program_options_lite.h"
     42#include "../../Lib/TAppCommon/program_options_lite.h"
    4343#include <stdio.h>
    4444#include <stdlib.h>
  • trunk/source/App/TAppExtractor/TAppExtrTop.cpp

    r42 r56  
    3636*/
    3737
     38#include "TAppExtrTop.h"
     39#include "../../Lib/TLibDecoder/AnnexBread.h"
     40#include <fstream>
    3841#include <list>
    3942#include <stdio.h>
    4043#include <fcntl.h>
    4144#include <assert.h>
    42 
    43 #include "TAppExtrTop.h"
    44 
    45 // ====================================================================================================================
    46 // Local constants
    47 // ====================================================================================================================
    48 
    49 /// initial bitstream buffer size
    50 /// should be large enough for parsing SPS
    51 /// resized as a function of picture size after parsing SPS
    52 #define BITS_BUF_SIZE 65536
    5345
    5446// ====================================================================================================================
     
    6052}
    6153
    62 Void TAppExtrTop::create()
     54TAppExtrTop::~TAppExtrTop()
    6355{
    64   m_apcInputBitstream  = new TComBitstream;
    65   m_apcInputBitstream->create( BITS_BUF_SIZE );
    66 
    67   if ( m_pchOutputBitstreamFile )
    68   {
    69      m_apcOutputBitstream  = new TComBitstream;
    70      m_apcOutputBitstream->create( BITS_BUF_SIZE );
    71   }
    72   else
    73   {
    74      m_apcOutputBitstream  = NULL;
    75   }
    76 }
    77 
    78 Void TAppExtrTop::destroy()
    79 {
    80   if ( m_apcInputBitstream )
    81   {
    82     m_apcInputBitstream->destroy();
    83     delete m_apcInputBitstream;
    84     m_apcInputBitstream = NULL;
    85   }
    86 
    87   if ( m_apcOutputBitstream )
    88   {
    89     m_apcOutputBitstream->destroy();
    90     delete m_apcOutputBitstream;
    91     m_apcOutputBitstream = NULL;
    92   }
    9356}
    9457
     
    9861
    9962/**
    100  - create internal class
    101  - initialize internal class
    10263 - until the end of the bitstream, call extraction function in TExtrTop class
    103  - delete allocated buffers
    104  - destroy internal class
    105  .
    10664 */
    10765Void TAppExtrTop::extract()
    10866{
    109   TComBitstream*      pcInputBitstream = m_apcInputBitstream;
    110   TComBitstream*      pcOutputBitstream = m_apcOutputBitstream;
    11167
    112   // create & initialize internal classes
    113   xCreateExtrLib();
    114   xInitExtrLib  ();
     68  ifstream inputBitstreamFile( m_pchInputBitstreamFile, ifstream::in | ifstream::binary );
     69  if( inputBitstreamFile.fail() )
     70  {
     71    fprintf( stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchInputBitstreamFile );
     72    exit( EXIT_FAILURE );
     73  }
    11574
    116   // main extractor loop
    117   Bool resizedBitstreamBuffer = false;
     75  fstream outputBitstreamFile;
     76  if( m_pchOutputBitstreamFile )
     77  {
     78    outputBitstreamFile.open( m_pchOutputBitstreamFile, fstream::binary | fstream::out );
     79    if( outputBitstreamFile.fail() )
     80    {
     81      fprintf( stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchOutputBitstreamFile );
     82      exit( EXIT_FAILURE );
     83    }
     84  }
    11885
    119   while ( !m_cTVideoIOInputBitstreamFile.readBits( pcInputBitstream ) )
     86  InputByteStream inputBytestream( inputBitstreamFile );
     87
     88  Bool bEndOfFile = false;
     89  while( !bEndOfFile )
    12090  {
    121     // decide whether to extract packet or not
    122     if ( m_cTExtrTop.extract( pcInputBitstream, m_suiExtractLayerIds ) && pcOutputBitstream )
     91    streampos location = inputBitstreamFile.tellg();
     92    AnnexBStats stats = AnnexBStats();
     93    vector<uint8_t> nalUnit;
     94    InputNALUnit nalu;
     95    bEndOfFile = byteStreamNALUnit( inputBytestream, nalUnit, stats );
     96
     97    // handle NAL unit
     98    if( nalUnit.empty() )
    12399    {
    124        xCopyInputPacketIntoOutput();
    125        m_cTVideoIOOutputBitstreamFile.writeBits( pcOutputBitstream );
     100      /* this can happen if the following occur:
     101       *  - empty input file
     102       *  - two back-to-back start_code_prefixes
     103       *  - start_code_prefix immediately followed by EOF
     104       */
     105      fprintf( stderr, "Warning: Attempt to decode an empty NAL unit\n" );
    126106    }
     107    else
     108    {
     109      read( nalu, nalUnit );
    127110
    128     if ( !resizedBitstreamBuffer )
    129     {
    130       TComSPS *sps = m_cTExtrTop.getFirstSPS();
    131       if ( sps )
     111      // decide whether to extract packet or not
     112      if ( m_cTExtrTop.extract( nalu, m_suiExtractLayerIds ) && outputBitstreamFile.is_open() )
    132113      {
    133         pcInputBitstream->destroy();
    134         pcInputBitstream->create(sps->getWidth() * sps->getHeight() * 2);
    135         if ( pcOutputBitstream )
     114        inputBitstreamFile.clear();
     115
     116        streampos location2 = inputBitstreamFile.tellg();
     117        inputBitstreamFile.seekg( location );
     118
     119        do
    136120        {
    137            pcOutputBitstream->destroy();
    138            pcOutputBitstream->create(sps->getWidth() * sps->getHeight() * 2);
    139         }
    140         resizedBitstreamBuffer = true;
     121          outputBitstreamFile.put( inputBitstreamFile.get() );
     122        } while( inputBitstreamFile.tellg() != location2 );
    141123      }
    142124    }
    143125  }
    144126
     127  inputBitstreamFile.close();
     128  outputBitstreamFile.close();
     129
    145130  // write SPS info file
    146131  if ( m_pchSpsInfoFile )
    147132  {
    148     m_cTExtrTop.dumpSpsInfo( m_cSpsInfoFileHandle );
     133    fstream cSpsInfoFileHandle( m_pchSpsInfoFile, fstream::binary | fstream::out );
     134
     135    if( cSpsInfoFileHandle.fail() )
     136    {
     137      fprintf( stderr, "\nfailed writing SPS info file\n" );
     138      exit( EXIT_FAILURE );
     139    }
     140
     141    m_cTExtrTop.dumpSpsInfo( cSpsInfoFileHandle );
     142
     143    cSpsInfoFileHandle.close();
    149144  }
    150145  m_cTExtrTop.dumpSpsInfo( std::cout );
    151  
    152   // destroy internal classes
    153   xDestroyExtrLib();
    154146}
    155 
    156 // ====================================================================================================================
    157 // Protected member functions
    158 // ====================================================================================================================
    159 
    160 Void TAppExtrTop::xCreateExtrLib()
    161 {
    162   // open bitstream files
    163   m_cTVideoIOInputBitstreamFile.openBits( m_pchInputBitstreamFile, false);  // read mode
    164   if ( m_pchOutputBitstreamFile )
    165   {
    166      m_cTVideoIOOutputBitstreamFile.openBits( m_pchOutputBitstreamFile, true);  // write mode
    167   }
    168 
    169   // open text file
    170   if ( m_pchSpsInfoFile )
    171   {
    172      m_cSpsInfoFileHandle.open( m_pchSpsInfoFile, ios::binary | ios::out );
    173 
    174     if( m_cSpsInfoFileHandle.fail() )
    175     {
    176       printf("\nfailed writing SPS info file\n");
    177       exit(0);
    178     }
    179   }
    180 
    181   // create extractor class
    182   m_cTExtrTop.create();
    183 }
    184 
    185 Void TAppExtrTop::xDestroyExtrLib()
    186 {
    187   // close bitstream files
    188   m_cTVideoIOInputBitstreamFile.closeBits();
    189   if ( m_pchOutputBitstreamFile )
    190   {
    191      m_cTVideoIOOutputBitstreamFile.closeBits();
    192   }
    193 
    194   // open text file
    195   if ( m_pchSpsInfoFile )
    196   {
    197      m_cSpsInfoFileHandle.close();
    198   }
    199 
    200   // destroy extractor class
    201   m_cTExtrTop.destroy();
    202 }
    203 
    204 Void TAppExtrTop::xInitExtrLib()
    205 {
    206   // initialize extractor class
    207   m_cTExtrTop.init();
    208 }
    209 
    210 Void TAppExtrTop::xCopyInputPacketIntoOutput()
    211 {
    212   UInt  uiNumBytes = m_apcInputBitstream->reinitParsing();
    213   UInt  uiByteCount;
    214   UInt  uiByte;
    215 
    216   assert( m_apcOutputBitstream );
    217 
    218   m_apcOutputBitstream->rewindStreamPacket();
    219   m_apcOutputBitstream->resetBits();
    220 
    221   for ( uiByteCount = 0; uiByteCount < uiNumBytes; uiByteCount++ )
    222   {
    223     m_apcInputBitstream->read( 8, uiByte );
    224     m_apcOutputBitstream->write( uiByte, 8 );
    225   }
    226 
    227   m_apcOutputBitstream->flushBuffer();
    228 }
  • trunk/source/App/TAppExtractor/TAppExtrTop.h

    r42 r56  
    4343#endif // _MSC_VER > 1000
    4444
    45 #include "../../Lib/TLibVideoIO/TVideoIOBits.h"
    46 #include "../../Lib/TLibCommon/TComBitStream.h"
    4745#include "../../Lib/TLibExtractor/TExtrTop.h"
    4846#include "TAppExtrCfg.h"
     
    5755private:
    5856  // class interface
    59   TExtrTop                        m_cTExtrTop;                    ///< extractor class
    60   TComBitstream*                  m_apcInputBitstream;            ///< bitstream class
    61   TComBitstream*                  m_apcOutputBitstream;           ///< bitstream class
    62   TVideoIOBitsStartCode           m_cTVideoIOInputBitstreamFile;  ///< file I/O class
    63   TVideoIOBitsStartCode           m_cTVideoIOOutputBitstreamFile; ///< file I/O class
    64   std::fstream                    m_cSpsInfoFileHandle;           ///< file handle
     57  TExtrTop                       m_cTExtrTop;         ///< extractor class
    6558
    6659public:
    6760  TAppExtrTop();
    68   virtual ~TAppExtrTop() {}
     61  virtual ~TAppExtrTop();
    6962 
    70   Void  create                     (); ///< create internal members
    71   Void  destroy                    (); ///< destroy internal members
    72   Void  extract                    (); ///< main extraction function
    73  
    74 protected:
    75   Void  xCreateExtrLib             (); ///< create internal classes
    76   Void  xDestroyExtrLib            (); ///< destroy internal classes
    77   Void  xInitExtrLib               (); ///< initialize extractor class
    78 
    79   Void  xCopyInputPacketIntoOutput ();
     63  Void  extract                  ();                  ///< main extraction function
    8064};
    8165
  • trunk/source/App/TAppExtractor/extrmain.cpp

    r42 r56  
    3939#include <stdio.h>
    4040#include <time.h>
    41 #include "../../Lib/TLibCommon/CommonDef.h"
    4241#include "TAppExtrTop.h"
    4342
     
    5251  // print information
    5352  fprintf( stdout, "\n" );
    54   fprintf( stdout, "HM %s based Multiview Video plus Depth Coder: Extractor Version [%s]", HM_VERSION, NV_VERSION );
     53  fprintf( stdout, "3D-HTM Software: Extractor Version [%s] based on HM Version [%s]", HM_VERSION, NV_VERSION );
    5554  fprintf( stdout, NVM_ONOS );
    5655  fprintf( stdout, NVM_COMPILEDBY );
     
    6362    return EXIT_FAILURE;
    6463  }
    65 
    66   // create application extractor class
    67   cTAppExtrTop.create();
    6864
    6965  // starting time
     
    7874  printf("\n Total Time: %12.3f sec.\n", dResult);
    7975
    80   // destroy application extractor class
    81   cTAppExtrTop.destroy();
    82 
    8376  return EXIT_SUCCESS;
    8477}
Note: See TracChangeset for help on using the changeset viewer.