Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoMPEGRenderer.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : C. HUFSCHMITT (Jul 2001)
22**=======================================================================*/
23/*=======================================================================
24** Modified by : Tristan Mehamli (Nov 2009)
25**=======================================================================*/
26
27#ifndef _SO_MPEGRENDERER_
28#define _SO_MPEGRENDERER_
29
30#include <Inventor/nodes/SoSeparator.h>
31#include <Inventor/actions/SoGLRenderAction.h>
32#include <Inventor/helpers/SbGlContextHelper.h>
33#include <Inventor/SbBasic.h>
34#include <Inventor/SbColor.h>
35
36#include <Inventor/STL/list>
37
38class TGSMPEG;
39class SbThreadSignal;
40class SbThreadMutex;
41
42/*----------------------------------------------------------------------------*/
126{
127public:
128
133
138
153
165 SbBool openFile( const char* filename, unsigned int numFrames = 10000 );
166
170 void closeFile();
171
175 void setFilePointer( FILE* fp );
176
180 FILE* getFilePointer() const;
181
194 void setSize( const SbVec2s& size );
195
201
205 void setComponents( const Components components );
206
211
215 virtual void setSceneGraph( SoNode* node );
216
221
230 void setBackgroundColor( const SbColor& c );
231
236
244
249
262 void setCompressionRate( float value );
263
267 float getCompressionRate() const;
268
284 void setBitPerSec( float mbps );
285
296 void setNumFramesPerSecond( float num );
297
302
312 void addFrame( const unsigned char* frame );
313
326 void setShareContext( const SbGLShareContext shareCxt );
327
332
339 virtual void record();
340
344 virtual void pause();
345
349 virtual void stop();
350
355
359 void setViewerIsIdle( bool isIdle );
360 bool isViewerIdle() const { return m_viewerIsIdle; };
361
362 /*----------------------------------------------------------------------------*/
363 private:
368 void computeRate( double curVwrFPS );
369
373 void addIdleFrame();
374
378 int getNumFrameToEncode();
379
380private:
381 SoMPEGRenderer& operator =( const SoMPEGRenderer& a );
382 // Share context
383 SbGLShareContext m_glShareContext;
384
385private:
386 // Encoding Task that "loops" until there is no more frame to encode.
387 void encodeTask(void);
388 // main method for the recording thread.
389 static void* encodeCB( void* data );
390 // Streamed buffers stack.
391 static std::list<unsigned char*>* m_frameStack;
392 // Synchronization between app thread and encoding thread.
393 static SbThreadMutex* m_stackMutex; // Used when accessing the stack.
394 SbThread* m_stackThread;
395 // Frame size in pixel.
396 SbVec2s m_Size;
397 // Component number for one frame, frame rate, frame number in m_frameStack.
398 int m_frameSize, m_recFrameRate, m_frameCount;
399 // Real frame rate (according to viewer FPS).
400 double m_rate;
401 // Backgroung color.
402 SbColor m_BgColor;
403 // Render action set by setGLRenderAction.
404 SoGLRenderAction* m_ra, *m_defaultRenderAction;
405 // MPEG algorithm.
406 TGSMPEG* m_mpeg;
407 // Current scene graph to render.
408 SoNode* m_SceneGraph;
409 // Number of component for one frame.
410 Components m_numComponents;
411 // True if the scene do not change.
412 bool m_viewerIsIdle;
413 // True if a file is opened, true if recording.
414 SbBool m_hasFileOpened, m_isRecording;
415
416 // Name of the current opened file.
417 SbString m_openedFile;
418 // True if openFile displayed a warning to indicate that a thread
419 // is encoding on this file.
420 SbBool m_openedFileWarningDisplayed;
421};/*----------------------------------------------------------------------------*/
422
423#endif /* _SO_MPEGRENDERER_ */
424
425
Color vector class.
Definition SbColor.h:82
Class encapsulating information about an OpenGL context: a handle on an OpenGL context and its id.
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable thread ...
Definition SbThread.h:65
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable signal ...
2D vector class.
Definition SbVec.h:700
Renders a scene graph using Open Inventor's Render Engine.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Base class for g...
SoMPEGRenderer()
Constructor.
void addFrame(const unsigned char *frame)
Low level method to add a new frame to the MPEG output from a buffer of unsigned characters.
SbBool isRecording() const
Returns true if this renderer is recording.
float getCompressionRate() const
Returns the compression rate.
virtual ~SoMPEGRenderer()
Destructor.
void setFilePointer(FILE *fp)
Sets the file pointer for the MPEG output.
int getNumFramesPerSecond()
Gets the number of frames per second to be encoded in the MPEG output.
void setShareContext(const SbGLShareContext shareCxt)
Sets the OpenGL context to be shared by the SoMPEGRenderer.
void setGLRenderAction(SoGLRenderAction *ra)
Sets the GL Render action used to generate each frame.
void setCompressionRate(float value)
Compression rate of the MPEG output.
SoGLRenderAction * getGLRenderAction() const
Gets the GL Render action used to generate each frame.
Components
Components.
@ LUMINANCE_TRANSPARENCY
Luminance transparency.
@ LUMINANCE
Luminance.
@ RGB_TRANSPARENCY
RGB and Alpha channel.
SbVec2s getSize() const
Gets the frame pixel size.
SoNode * getSceneGraph() const
Gets the scene graph used for generating frames in the MPEG output.
virtual void setSceneGraph(SoNode *node)
Sets the scene graph used for generating frames in the MPEG output.
FILE * getFilePointer() const
Gets the MPEG file pointer.
virtual void pause()
Pauses the recording.
virtual void record()
Starts the recording.
SbColor getBackgroundColor() const
Gets the background color for rendering each frame.
void setNumFramesPerSecond(float num)
Sets the number of frames per second encoded in the MPEG output.
virtual void stop()
Stops the recording and closes the opened file.
SoMPEGRenderer::Components getComponents() const
Returns the number of color components of the frames recorded.
bool isViewerIdle() const
const SbGLShareContext getShareContext() const
Gets the OpenGL context shared by this object.
void setSize(const SbVec2s &size)
Sets the frame pixel size.
void setBackgroundColor(const SbColor &c)
Sets the background color for rendering each frame.
void setComponents(const Components components)
Set the number of color components of the frames recorded.
SbBool openFile(const char *filename, unsigned int numFrames=10000)
Specifies the MPEG output file name.
void setViewerIsIdle(bool isIdle)
Tells the recorder that the viewer is idle.
void setBitPerSec(float mbps)
This method allows the user to specify a fixed bit rate.
void closeFile()
Closes the MPEG file previously opened with the openFile() method.
Abstract base class for all database nodes.
Definition SoNode.h:145
int SbBool
Boolean type.
Definition SbBase.h:87