Index: trunk/source/App/TAppExtractor/TAppExtrCfg.cpp
===================================================================
--- trunk/source/App/TAppExtractor/TAppExtrCfg.cpp	(revision 42)
+++ trunk/source/App/TAppExtractor/TAppExtrCfg.cpp	(revision 56)
@@ -40,5 +40,5 @@
 #include <string>
 #include "TAppExtrCfg.h"
-#include "../../App/TAppCommon/program_options_lite.h"
+#include "../../Lib/TAppCommon/program_options_lite.h"
 #include <stdio.h>
 #include <stdlib.h>
Index: trunk/source/App/TAppExtractor/TAppExtrTop.cpp
===================================================================
--- trunk/source/App/TAppExtractor/TAppExtrTop.cpp	(revision 42)
+++ trunk/source/App/TAppExtractor/TAppExtrTop.cpp	(revision 56)
@@ -36,19 +36,11 @@
 */
 
+#include "TAppExtrTop.h"
+#include "../../Lib/TLibDecoder/AnnexBread.h"
+#include <fstream>
 #include <list>
 #include <stdio.h>
 #include <fcntl.h>
 #include <assert.h>
-
-#include "TAppExtrTop.h"
-
-// ====================================================================================================================
-// Local constants
-// ====================================================================================================================
-
-/// initial bitstream buffer size
-/// should be large enough for parsing SPS
-/// resized as a function of picture size after parsing SPS
-#define BITS_BUF_SIZE 65536
 
 // ====================================================================================================================
@@ -60,35 +52,6 @@
 }
 
-Void TAppExtrTop::create()
+TAppExtrTop::~TAppExtrTop()
 {
-  m_apcInputBitstream  = new TComBitstream;
-  m_apcInputBitstream->create( BITS_BUF_SIZE );
-
-  if ( m_pchOutputBitstreamFile )
-  {
-     m_apcOutputBitstream  = new TComBitstream;
-     m_apcOutputBitstream->create( BITS_BUF_SIZE );
-  }
-  else
-  {
-     m_apcOutputBitstream  = NULL;
-  }
-}
-
-Void TAppExtrTop::destroy()
-{
-  if ( m_apcInputBitstream )
-  {
-    m_apcInputBitstream->destroy();
-    delete m_apcInputBitstream;
-    m_apcInputBitstream = NULL;
-  }
-
-  if ( m_apcOutputBitstream )
-  {
-    m_apcOutputBitstream->destroy();
-    delete m_apcOutputBitstream;
-    m_apcOutputBitstream = NULL;
-  }
 }
 
@@ -98,131 +61,86 @@
 
 /**
- - create internal class
- - initialize internal class
  - until the end of the bitstream, call extraction function in TExtrTop class
- - delete allocated buffers
- - destroy internal class
- .
  */
 Void TAppExtrTop::extract()
 {
-  TComBitstream*      pcInputBitstream = m_apcInputBitstream;
-  TComBitstream*      pcOutputBitstream = m_apcOutputBitstream;
 
-  // create & initialize internal classes
-  xCreateExtrLib();
-  xInitExtrLib  ();
+  ifstream inputBitstreamFile( m_pchInputBitstreamFile, ifstream::in | ifstream::binary );
+  if( inputBitstreamFile.fail() )
+  {
+    fprintf( stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchInputBitstreamFile );
+    exit( EXIT_FAILURE );
+  }
 
-  // main extractor loop
-  Bool resizedBitstreamBuffer = false;
+  fstream outputBitstreamFile;
+  if( m_pchOutputBitstreamFile )
+  {
+    outputBitstreamFile.open( m_pchOutputBitstreamFile, fstream::binary | fstream::out );
+    if( outputBitstreamFile.fail() )
+    {
+      fprintf( stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchOutputBitstreamFile );
+      exit( EXIT_FAILURE );
+    }
+  }
 
-  while ( !m_cTVideoIOInputBitstreamFile.readBits( pcInputBitstream ) )
+  InputByteStream inputBytestream( inputBitstreamFile );
+
+  Bool bEndOfFile = false;
+  while( !bEndOfFile )
   {
-    // decide whether to extract packet or not
-    if ( m_cTExtrTop.extract( pcInputBitstream, m_suiExtractLayerIds ) && pcOutputBitstream )
+    streampos location = inputBitstreamFile.tellg();
+    AnnexBStats stats = AnnexBStats();
+    vector<uint8_t> nalUnit;
+    InputNALUnit nalu;
+    bEndOfFile = byteStreamNALUnit( inputBytestream, nalUnit, stats );
+
+    // handle NAL unit
+    if( nalUnit.empty() )
     {
-       xCopyInputPacketIntoOutput();
-       m_cTVideoIOOutputBitstreamFile.writeBits( pcOutputBitstream );
+      /* this can happen if the following occur:
+       *  - empty input file
+       *  - two back-to-back start_code_prefixes
+       *  - start_code_prefix immediately followed by EOF
+       */
+      fprintf( stderr, "Warning: Attempt to decode an empty NAL unit\n" );
     }
+    else
+    {
+      read( nalu, nalUnit );
 
-    if ( !resizedBitstreamBuffer )
-    {
-      TComSPS *sps = m_cTExtrTop.getFirstSPS();
-      if ( sps )
+      // decide whether to extract packet or not
+      if ( m_cTExtrTop.extract( nalu, m_suiExtractLayerIds ) && outputBitstreamFile.is_open() )
       {
-        pcInputBitstream->destroy();
-        pcInputBitstream->create(sps->getWidth() * sps->getHeight() * 2);
-        if ( pcOutputBitstream )
+        inputBitstreamFile.clear();
+
+        streampos location2 = inputBitstreamFile.tellg();
+        inputBitstreamFile.seekg( location );
+
+        do
         {
-           pcOutputBitstream->destroy();
-           pcOutputBitstream->create(sps->getWidth() * sps->getHeight() * 2);
-        }
-        resizedBitstreamBuffer = true;
+          outputBitstreamFile.put( inputBitstreamFile.get() );
+        } while( inputBitstreamFile.tellg() != location2 );
       }
     }
   }
 
+  inputBitstreamFile.close();
+  outputBitstreamFile.close();
+
   // write SPS info file
   if ( m_pchSpsInfoFile )
   {
-    m_cTExtrTop.dumpSpsInfo( m_cSpsInfoFileHandle );
+    fstream cSpsInfoFileHandle( m_pchSpsInfoFile, fstream::binary | fstream::out );
+
+    if( cSpsInfoFileHandle.fail() )
+    {
+      fprintf( stderr, "\nfailed writing SPS info file\n" );
+      exit( EXIT_FAILURE );
+    }
+
+    m_cTExtrTop.dumpSpsInfo( cSpsInfoFileHandle );
+
+    cSpsInfoFileHandle.close();
   }
   m_cTExtrTop.dumpSpsInfo( std::cout );
-  
-  // destroy internal classes
-  xDestroyExtrLib();
 }
-
-// ====================================================================================================================
-// Protected member functions
-// ====================================================================================================================
-
-Void TAppExtrTop::xCreateExtrLib()
-{
-  // open bitstream files
-  m_cTVideoIOInputBitstreamFile.openBits( m_pchInputBitstreamFile, false);  // read mode
-  if ( m_pchOutputBitstreamFile )
-  {
-     m_cTVideoIOOutputBitstreamFile.openBits( m_pchOutputBitstreamFile, true);  // write mode
-  }
-
-  // open text file
-  if ( m_pchSpsInfoFile )
-  {
-     m_cSpsInfoFileHandle.open( m_pchSpsInfoFile, ios::binary | ios::out );
-
-    if( m_cSpsInfoFileHandle.fail() )
-    {
-      printf("\nfailed writing SPS info file\n");
-      exit(0);
-    }
-  }
-
-  // create extractor class
-  m_cTExtrTop.create();
-}
-
-Void TAppExtrTop::xDestroyExtrLib()
-{
-  // close bitstream files
-  m_cTVideoIOInputBitstreamFile.closeBits();
-  if ( m_pchOutputBitstreamFile )
-  {
-     m_cTVideoIOOutputBitstreamFile.closeBits();
-  }
-
-  // open text file
-  if ( m_pchSpsInfoFile )
-  {
-     m_cSpsInfoFileHandle.close();
-  }
-
-  // destroy extractor class
-  m_cTExtrTop.destroy();
-}
-
-Void TAppExtrTop::xInitExtrLib()
-{
-  // initialize extractor class
-  m_cTExtrTop.init();
-}
-
-Void TAppExtrTop::xCopyInputPacketIntoOutput()
-{
-  UInt  uiNumBytes = m_apcInputBitstream->reinitParsing();
-  UInt  uiByteCount;
-  UInt  uiByte;
-
-  assert( m_apcOutputBitstream );
-
-  m_apcOutputBitstream->rewindStreamPacket();
-  m_apcOutputBitstream->resetBits();
-
-  for ( uiByteCount = 0; uiByteCount < uiNumBytes; uiByteCount++ )
-  {
-    m_apcInputBitstream->read( 8, uiByte );
-    m_apcOutputBitstream->write( uiByte, 8 );
-  }
-
-  m_apcOutputBitstream->flushBuffer();
-}
Index: trunk/source/App/TAppExtractor/TAppExtrTop.h
===================================================================
--- trunk/source/App/TAppExtractor/TAppExtrTop.h	(revision 42)
+++ trunk/source/App/TAppExtractor/TAppExtrTop.h	(revision 56)
@@ -43,6 +43,4 @@
 #endif // _MSC_VER > 1000
 
-#include "../../Lib/TLibVideoIO/TVideoIOBits.h"
-#include "../../Lib/TLibCommon/TComBitStream.h"
 #include "../../Lib/TLibExtractor/TExtrTop.h"
 #include "TAppExtrCfg.h"
@@ -57,25 +55,11 @@
 private:
   // class interface
-  TExtrTop                        m_cTExtrTop;                    ///< extractor class
-  TComBitstream*                  m_apcInputBitstream;            ///< bitstream class
-  TComBitstream*                  m_apcOutputBitstream;           ///< bitstream class
-  TVideoIOBitsStartCode           m_cTVideoIOInputBitstreamFile;  ///< file I/O class
-  TVideoIOBitsStartCode           m_cTVideoIOOutputBitstreamFile; ///< file I/O class
-  std::fstream                    m_cSpsInfoFileHandle;           ///< file handle
+  TExtrTop                       m_cTExtrTop;         ///< extractor class
 
 public:
   TAppExtrTop();
-  virtual ~TAppExtrTop() {}
+  virtual ~TAppExtrTop();
   
-  Void  create                     (); ///< create internal members
-  Void  destroy                    (); ///< destroy internal members
-  Void  extract                    (); ///< main extraction function
-  
-protected:
-  Void  xCreateExtrLib             (); ///< create internal classes
-  Void  xDestroyExtrLib            (); ///< destroy internal classes
-  Void  xInitExtrLib               (); ///< initialize extractor class
-
-  Void  xCopyInputPacketIntoOutput ();
+  Void  extract                  ();                  ///< main extraction function
 };
 
Index: trunk/source/App/TAppExtractor/extrmain.cpp
===================================================================
--- trunk/source/App/TAppExtractor/extrmain.cpp	(revision 42)
+++ trunk/source/App/TAppExtractor/extrmain.cpp	(revision 56)
@@ -39,5 +39,4 @@
 #include <stdio.h>
 #include <time.h>
-#include "../../Lib/TLibCommon/CommonDef.h"
 #include "TAppExtrTop.h"
 
@@ -52,5 +51,5 @@
   // print information
   fprintf( stdout, "\n" );
-  fprintf( stdout, "HM %s based Multiview Video plus Depth Coder: Extractor Version [%s]", HM_VERSION, NV_VERSION );
+  fprintf( stdout, "3D-HTM Software: Extractor Version [%s] based on HM Version [%s]", HM_VERSION, NV_VERSION );
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
@@ -63,7 +62,4 @@
     return EXIT_FAILURE;
   }
-
-  // create application extractor class
-  cTAppExtrTop.create();
 
   // starting time
@@ -78,7 +74,4 @@
   printf("\n Total Time: %12.3f sec.\n", dResult);
 
-  // destroy application extractor class
-  cTAppExtrTop.destroy();
-
   return EXIT_SUCCESS;
 }
