00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : C. HUFSCHMITT (Jul 2001) 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Modified by : Tristan Mehamli (Nov 2009) 00025 **=======================================================================*/ 00026 00027 #ifndef _SO_MPEGRENDERER_ 00028 #define _SO_MPEGRENDERER_ 00029 00030 #include <Inventor/nodes/SoSeparator.h> 00031 #include <Inventor/actions/SoGLRenderAction.h> 00032 #include <Inventor/helpers/SbGlContextHelper.h> 00033 #include <Inventor/SbBasic.h> 00034 00035 #include <Inventor/STL/list> 00036 00037 class TGSMPEG; 00038 class SbThreadSignal; 00039 class SbThreadMutex; 00040 00041 /*----------------------------------------------------------------------------*/ 00125 class SoMPEGRenderer 00126 { 00127 public: 00128 00132 SoMPEGRenderer(); 00133 00137 virtual ~SoMPEGRenderer(); 00138 00140 enum Components 00141 { 00143 LUMINANCE = 1, 00145 LUMINANCE_TRANSPARENCY = 2, 00149 RGB = 3, 00151 RGB_TRANSPARENCY = 4 00152 }; 00153 00165 SbBool openFile( const char* filename, unsigned int numFrames = 10000 ); 00166 00170 void closeFile(); 00171 00175 void setFilePointer( FILE* fp ); 00176 00180 FILE* getFilePointer() const; 00181 00194 void setSize( const SbVec2s& size ); 00195 00200 SbVec2s getSize() const; 00201 00205 void setComponents( const Components components ); 00206 00210 SoMPEGRenderer::Components getComponents() const; 00211 00215 virtual void setSceneGraph( SoNode* node ); 00216 00220 SoNode* getSceneGraph() const; 00221 00230 void setBackgroundColor( const SbColor& c ); 00231 00235 SbColor getBackgroundColor() const; 00236 00243 void setGLRenderAction( SoGLRenderAction* ra ); 00244 00248 SoGLRenderAction* getGLRenderAction() const; 00249 00262 void setCompressionRate( float value ); 00263 00267 float getCompressionRate() const; 00268 00284 void setBitPerSec( float mbps ); 00285 00296 void setNumFramesPerSecond( float num ); 00297 00301 int getNumFramesPerSecond(); 00302 00312 void addFrame( const unsigned char* frame ); 00313 00326 void setShareContext( const SbGLShareContext shareCxt ); 00327 00331 const SbGLShareContext getShareContext() const; 00332 00339 void record(); 00340 00344 void pause(); 00345 00349 void stop(); 00350 00354 SbBool isRecording() const; 00355 00359 void setViewerIsIdle( bool isIdle ); 00360 bool isViewerIdle() const { return m_viewerIsIdle; }; 00361 00362 /*----------------------------------------------------------------------------*/ 00363 private: 00368 void computeRate( double curVwrFPS ); 00369 00373 void addIdleFrame(); 00374 00378 int getNumFrameToEncode(); 00379 00380 private: 00381 SoMPEGRenderer& operator =( const SoMPEGRenderer& a ); 00382 // Share context 00383 SbGLShareContext m_glShareContext; 00384 00385 private: 00386 // Encoding Task that "loops" until there is no more frame to encode. 00387 void encodeTask(void); 00388 // main method for the recording thread. 00389 static void* encodeCB( void* data ); 00390 // Streamed buffers stack. 00391 static std::list<unsigned char*>* m_frameStack; 00392 // Synchronization between app thread and encoding thread. 00393 static SbThreadMutex* m_stackMutex; // Used when accessing the stack. 00394 SbThread* m_stackThread; 00395 // Frame size in pixel. 00396 SbVec2s m_Size; 00397 // Component number for one frame, frame rate, frame number in m_frameStack. 00398 int m_frameSize, m_recFrameRate, m_frameCount; 00399 // Real frame rate (according to viewer FPS). 00400 double m_rate; 00401 // Backgroung color. 00402 SbColor m_BgColor; 00403 // Render action set by setGLRenderAction. 00404 SoGLRenderAction* m_ra, *m_defaultRenderAction; 00405 // MPEG algorithm. 00406 TGSMPEG* m_mpeg; 00407 // Current scene graph to render. 00408 SoNode* m_SceneGraph; 00409 // Number of component for one frame. 00410 Components m_numComponents; 00411 // True if the scene do not change. 00412 bool m_viewerIsIdle; 00413 // True if a file is opened, true if recording. 00414 SbBool m_hasFileOpened, m_isRecording; 00415 00416 // Name of the current opened file. 00417 SbString m_openedFile; 00418 // True if openFile displayed a warning to indicate that a thread 00419 // is encoding on this file. 00420 SbBool m_openedFileWarningDisplayed; 00421 };/*----------------------------------------------------------------------------*/ 00422 00423 #endif /* _SO_MPEGRENDERER_ */ 00424 00425 00426