Changeset 56 in 3DVCSoftware for trunk/source/App/TAppExtractor
- Timestamp:
- 11 May 2012, 21:20:17 (13 years ago)
- Location:
- trunk/source/App/TAppExtractor
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/App/TAppExtractor/TAppExtrCfg.cpp
r42 r56 40 40 #include <string> 41 41 #include "TAppExtrCfg.h" 42 #include "../../ App/TAppCommon/program_options_lite.h"42 #include "../../Lib/TAppCommon/program_options_lite.h" 43 43 #include <stdio.h> 44 44 #include <stdlib.h> -
trunk/source/App/TAppExtractor/TAppExtrTop.cpp
r42 r56 36 36 */ 37 37 38 #include "TAppExtrTop.h" 39 #include "../../Lib/TLibDecoder/AnnexBread.h" 40 #include <fstream> 38 41 #include <list> 39 42 #include <stdio.h> 40 43 #include <fcntl.h> 41 44 #include <assert.h> 42 43 #include "TAppExtrTop.h"44 45 // ====================================================================================================================46 // Local constants47 // ====================================================================================================================48 49 /// initial bitstream buffer size50 /// should be large enough for parsing SPS51 /// resized as a function of picture size after parsing SPS52 #define BITS_BUF_SIZE 6553653 45 54 46 // ==================================================================================================================== … … 60 52 } 61 53 62 Void TAppExtrTop::create()54 TAppExtrTop::~TAppExtrTop() 63 55 { 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 else73 {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 }93 56 } 94 57 … … 98 61 99 62 /** 100 - create internal class101 - initialize internal class102 63 - until the end of the bitstream, call extraction function in TExtrTop class 103 - delete allocated buffers104 - destroy internal class105 .106 64 */ 107 65 Void TAppExtrTop::extract() 108 66 { 109 TComBitstream* pcInputBitstream = m_apcInputBitstream;110 TComBitstream* pcOutputBitstream = m_apcOutputBitstream;111 67 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 } 115 74 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 } 118 85 119 while ( !m_cTVideoIOInputBitstreamFile.readBits( pcInputBitstream ) ) 86 InputByteStream inputBytestream( inputBitstreamFile ); 87 88 Bool bEndOfFile = false; 89 while( !bEndOfFile ) 120 90 { 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() ) 123 99 { 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" ); 126 106 } 107 else 108 { 109 read( nalu, nalUnit ); 127 110 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() ) 132 113 { 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 136 120 { 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 ); 141 123 } 142 124 } 143 125 } 144 126 127 inputBitstreamFile.close(); 128 outputBitstreamFile.close(); 129 145 130 // write SPS info file 146 131 if ( m_pchSpsInfoFile ) 147 132 { 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(); 149 144 } 150 145 m_cTExtrTop.dumpSpsInfo( std::cout ); 151 152 // destroy internal classes153 xDestroyExtrLib();154 146 } 155 156 // ====================================================================================================================157 // Protected member functions158 // ====================================================================================================================159 160 Void TAppExtrTop::xCreateExtrLib()161 {162 // open bitstream files163 m_cTVideoIOInputBitstreamFile.openBits( m_pchInputBitstreamFile, false); // read mode164 if ( m_pchOutputBitstreamFile )165 {166 m_cTVideoIOOutputBitstreamFile.openBits( m_pchOutputBitstreamFile, true); // write mode167 }168 169 // open text file170 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 class182 m_cTExtrTop.create();183 }184 185 Void TAppExtrTop::xDestroyExtrLib()186 {187 // close bitstream files188 m_cTVideoIOInputBitstreamFile.closeBits();189 if ( m_pchOutputBitstreamFile )190 {191 m_cTVideoIOOutputBitstreamFile.closeBits();192 }193 194 // open text file195 if ( m_pchSpsInfoFile )196 {197 m_cSpsInfoFileHandle.close();198 }199 200 // destroy extractor class201 m_cTExtrTop.destroy();202 }203 204 Void TAppExtrTop::xInitExtrLib()205 {206 // initialize extractor class207 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 43 43 #endif // _MSC_VER > 1000 44 44 45 #include "../../Lib/TLibVideoIO/TVideoIOBits.h"46 #include "../../Lib/TLibCommon/TComBitStream.h"47 45 #include "../../Lib/TLibExtractor/TExtrTop.h" 48 46 #include "TAppExtrCfg.h" … … 57 55 private: 58 56 // 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 65 58 66 59 public: 67 60 TAppExtrTop(); 68 virtual ~TAppExtrTop() {}61 virtual ~TAppExtrTop(); 69 62 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 80 64 }; 81 65 -
trunk/source/App/TAppExtractor/extrmain.cpp
r42 r56 39 39 #include <stdio.h> 40 40 #include <time.h> 41 #include "../../Lib/TLibCommon/CommonDef.h"42 41 #include "TAppExtrTop.h" 43 42 … … 52 51 // print information 53 52 fprintf( stdout, "\n" ); 54 fprintf( stdout, " HM %s based Multiview Video plus Depth Coder: ExtractorVersion [%s]", HM_VERSION, NV_VERSION );53 fprintf( stdout, "3D-HTM Software: Extractor Version [%s] based on HM Version [%s]", HM_VERSION, NV_VERSION ); 55 54 fprintf( stdout, NVM_ONOS ); 56 55 fprintf( stdout, NVM_COMPILEDBY ); … … 63 62 return EXIT_FAILURE; 64 63 } 65 66 // create application extractor class67 cTAppExtrTop.create();68 64 69 65 // starting time … … 78 74 printf("\n Total Time: %12.3f sec.\n", dResult); 79 75 80 // destroy application extractor class81 cTAppExtrTop.destroy();82 83 76 return EXIT_SUCCESS; 84 77 }
Note: See TracChangeset for help on using the changeset viewer.