1 // File: OpenGl_AVIWriter.hxx
2 // Created: 15.04.07 12:53
3 // Author: Alexey MORENOV & Alexander GRIGORIEV
4 // Copyright: Open CASCADE 2007
6 #ifndef __OPENGL_AVIWRITER_H
7 #define __OPENGL_AVIWRITER_H
12 #include <InterfaceGraphic_WNT.hxx>
15 #include <TCollection_AsciiString.hxx>
18 * Class providing the API to record AVI files using a codec installed in the
19 * system -- Only on Windows NT/2k/XP/Vista platform under MS Visual Studio.
20 * The following tasks are supported:
23 * <li> Creation of AVI data stream: launched by the constructor.<br>
24 * The constructor accepts the filename, FOURCC video code and the frame rate
25 * setting as parameters.<br>
26 * The default codec name used here is MPG4. To use a different codec, pass
27 * its FOURCC value as the input parameter for dwCodec.
30 * <li>pass mmioFOURCC('D','I','V','X') to use DIVX codec, or</li>
31 * <li>pass mmioFOURCC('I','V','5','0') to use IV50 codec etc...</li>
33 * Also, you can pass just 0 to avoid the codecs altogether. In that case,
34 * the frames would be saved as they are without any compression; However,
35 * the output movie file size would be very huge in that case.
37 * Finally, make sure you have the codec installed on the machine before
38 * passing its Fourcc here.
41 * Start the recording: call the method StartRecording(). This method should be
42 * called at least once; execution of the constructor does not begin the
46 * Stop the recording: call the method StopRecording(). Can be omitted if the
47 * next to execute would be the destructor.
50 * Close the AVI file and exit the process of recording. This is done
51 * automatically by the destructor.
55 class OpenGl_AVIWriter
60 * Constructor. Initializes the internal data structures, prepares for the
61 * creation of an AVI stream when the first frame is ready to be captured.
63 * Name of the output movie file to create.
65 * FourCC of the Video Codec to be used for compression
67 * The Frames Per Second (FPS) setting to be used for the movie
69 Standard_EXPORT OpenGl_AVIWriter(const char * theFileName,
70 DWORD theCodec = mmioFOURCC('M','P','G','4'),
71 Standard_Integer theFrameRate = 25);
74 * Destructor: closes the movie file and flushes all the frames
76 Standard_EXPORT ~OpenGl_AVIWriter ();
79 * Begin the recording.
81 Standard_EXPORT void StartRecording(const HANDLE hWin = NULL);
84 * Stop the recording (can be restarted using StartRecording()).
86 Standard_EXPORT void StopRecording ();
89 * Query the state of recording.
91 inline Standard_Boolean IsRecording () const { return myIsAllowRecord; }
94 * Returns the last error message, if any.
96 inline Standard_EXPORT const TCollection_AsciiString&
97 GetLastErrorMessage() const
101 * Get the instance of AVI Writer class.
103 static Standard_EXPORT OpenGl_AVIWriter *
107 * Get the Window handle that contains the actual OpenGl context.
109 inline HANDLE HWindow () const
110 { return myhWindow; }
112 /// Inserts the given HBitmap into the movie as a new Frame at the end.
113 HRESULT AppendNewFrame(HBITMAP hBitmap);
115 /// Inserts the given bitmap bits into the movie as a new Frame at the end.
116 /// The width, height and nBitsPerPixel are the width, height and bits per pixel
117 /// of the bitmap pointed to by the input pBits.
118 HRESULT AppendNewFrame(int nWidth,
128 static OpenGl_AVIWriter * MyAVIWriterInstance;
129 Standard_Boolean myIsAllowRecord;
137 HANDLE myhWindow; // window containing the OGL context
138 LPVOID mylpBits; // Useful to hold the bitmap content if any
139 LONG mylSample; // Keeps track of the current Frame Index
141 PAVISTREAM mypAviStream;
142 PAVISTREAM mypAviCompressedStream;
143 AVISTREAMINFO myAviStreamInfo;
144 AVICOMPRESSOPTIONS myAviCompressOptions;
145 char * myFileName; // Holds the Output Movie File Name
146 TCollection_AsciiString myErrMsg; // Holds the Last Error Message, if any
148 int myAppendFuncSelector; //0=Dummy 1=FirstTime 2=Usual
150 HRESULT AppendFrameFirstTime(HBITMAP );
151 HRESULT AppendFrameUsual(HBITMAP);
152 HRESULT AppendDummy(HBITMAP);
153 HRESULT (OpenGl_AVIWriter::*pAppendFrame[3])(HBITMAP hBitmap);
155 HRESULT AppendFrameBitsFirstTime(int, int, LPVOID,int );
156 HRESULT AppendFrameBitsUsual(int, int, LPVOID,int );
157 HRESULT AppendDummyBits(int, int, LPVOID,int );
158 HRESULT (OpenGl_AVIWriter::*pAppendFrameBits[3])(int, int, LPVOID, int);
160 /// Takes care of creating the memory, streams, compression options etc.
161 /// required for the movie
162 HRESULT InitMovieCreation(int nFrameWidth,int nFrameHeight,int nBitsPerPixel);
164 /// Takes care of releasing the memory and movie related handles
165 void ReleaseMemory();
167 /// Sets the Error Message
168 void SetErrorMessage(const char * theErrMsg);
171 Standard_EXPORT void OpenGl_AVIWriter_AVIWriter(void * pp,
176 Standard_EXPORT Standard_Boolean OpenGl_AVIWriter_AllowWriting(void * hWin);