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-2014 BY FEI S.A.S, *** 00017 *** MERIGNAC, 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 /*----------------------------------------------------------------------------*/ 00124 class SoMPEGRenderer 00125 { 00126 public: 00127 00131 SoMPEGRenderer(); 00132 00136 virtual ~SoMPEGRenderer(); 00137 00139 enum Components 00140 { 00142 LUMINANCE = 1, 00144 LUMINANCE_TRANSPARENCY = 2, 00148 RGB = 3, 00150 RGB_TRANSPARENCY = 4 00151 }; 00152 00164 SbBool openFile( const char* filename, unsigned int numFrames = 10000 ); 00165 00169 void closeFile(); 00170 00174 void setFilePointer( FILE* fp ); 00175 00179 FILE* getFilePointer() const; 00180 00193 void setSize( const SbVec2s& size ); 00194 00199 SbVec2s getSize() const; 00200 00204 void setComponents( const Components components ); 00205 00209 SoMPEGRenderer::Components getComponents() const; 00210 00214 virtual void setSceneGraph( SoNode* node ); 00215 00219 SoNode* getSceneGraph() const; 00220 00229 void setBackgroundColor( const SbColor& c ); 00230 00234 SbColor getBackgroundColor() const; 00235 00242 void setGLRenderAction( SoGLRenderAction* ra ); 00243 00247 SoGLRenderAction* getGLRenderAction() const; 00248 00261 void setCompressionRate( float value ); 00262 00266 float getCompressionRate() const; 00267 00283 void setBitPerSec( float mbps ); 00284 00295 void setNumFramesPerSecond( float num ); 00296 00300 int getNumFramesPerSecond(); 00301 00311 void addFrame( const unsigned char* frame ); 00312 00325 void setShareContext( const SbGLShareContext shareCxt ); 00326 00330 const SbGLShareContext getShareContext() const; 00331 00338 virtual void record(); 00339 00343 virtual void pause(); 00344 00348 virtual void stop(); 00349 00353 SbBool isRecording() const; 00354 00358 void setViewerIsIdle( bool isIdle ); 00359 bool isViewerIdle() const { return m_viewerIsIdle; }; 00360 00361 /*----------------------------------------------------------------------------*/ 00362 private: 00367 void computeRate( double curVwrFPS ); 00368 00372 void addIdleFrame(); 00373 00377 int getNumFrameToEncode(); 00378 00379 private: 00380 SoMPEGRenderer& operator =( const SoMPEGRenderer& a ); 00381 // Share context 00382 SbGLShareContext m_glShareContext; 00383 00384 private: 00385 // Encoding Task that "loops" until there is no more frame to encode. 00386 void encodeTask(void); 00387 // main method for the recording thread. 00388 static void* encodeCB( void* data ); 00389 // Streamed buffers stack. 00390 static std::list<unsigned char*>* m_frameStack; 00391 // Synchronization between app thread and encoding thread. 00392 static SbThreadMutex* m_stackMutex; // Used when accessing the stack. 00393 SbThread* m_stackThread; 00394 // Frame size in pixel. 00395 SbVec2s m_Size; 00396 // Component number for one frame, frame rate, frame number in m_frameStack. 00397 int m_frameSize, m_recFrameRate, m_frameCount; 00398 // Real frame rate (according to viewer FPS). 00399 double m_rate; 00400 // Backgroung color. 00401 SbColor m_BgColor; 00402 // Render action set by setGLRenderAction. 00403 SoGLRenderAction* m_ra, *m_defaultRenderAction; 00404 // MPEG algorithm. 00405 TGSMPEG* m_mpeg; 00406 // Current scene graph to render. 00407 SoNode* m_SceneGraph; 00408 // Number of component for one frame. 00409 Components m_numComponents; 00410 // True if the scene do not change. 00411 bool m_viewerIsIdle; 00412 // True if a file is opened, true if recording. 00413 SbBool m_hasFileOpened, m_isRecording; 00414 00415 // Name of the current opened file. 00416 SbString m_openedFile; 00417 // True if openFile displayed a warning to indicate that a thread 00418 // is encoding on this file. 00419 SbBool m_openedFileWarningDisplayed; 00420 };/*----------------------------------------------------------------------------*/ 00421 00422 #endif /* _SO_MPEGRENDERER_ */ 00423 00424 00425