1 // Created on: 2007-04-15
2 // Created by: Alexey MORENOV & Alexander GRIGORIEV
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #ifndef __OPENGL_AVIWRITER_H
22 #define __OPENGL_AVIWRITER_H
27 #include <InterfaceGraphic_WNT.hxx>
30 #include <TCollection_AsciiString.hxx>
33 * Class providing the API to record AVI files using a codec installed in the
34 * system -- Only on Windows NT/2k/XP/Vista platform under MS Visual Studio.
35 * The following tasks are supported:
38 * <li> Creation of AVI data stream: launched by the constructor.<br>
39 * The constructor accepts the filename, FOURCC video code and the frame rate
40 * setting as parameters.<br>
41 * The default codec name used here is MPG4. To use a different codec, pass
42 * its FOURCC value as the input parameter for dwCodec.
45 * <li>pass mmioFOURCC('D','I','V','X') to use DIVX codec, or</li>
46 * <li>pass mmioFOURCC('I','V','5','0') to use IV50 codec etc...</li>
48 * Also, you can pass just 0 to avoid the codecs altogether. In that case,
49 * the frames would be saved as they are without any compression; However,
50 * the output movie file size would be very huge in that case.
52 * Finally, make sure you have the codec installed on the machine before
53 * passing its Fourcc here.
56 * Start the recording: call the method StartRecording(). This method should be
57 * called at least once; execution of the constructor does not begin the
61 * Stop the recording: call the method StopRecording(). Can be omitted if the
62 * next to execute would be the destructor.
65 * Close the AVI file and exit the process of recording. This is done
66 * automatically by the destructor.
70 class OpenGl_AVIWriter
75 * Constructor. Initializes the internal data structures, prepares for the
76 * creation of an AVI stream when the first frame is ready to be captured.
78 * Name of the output movie file to create.
80 * FourCC of the Video Codec to be used for compression
82 * The Frames Per Second (FPS) setting to be used for the movie
84 Standard_EXPORT OpenGl_AVIWriter(const char * theFileName,
85 DWORD theCodec = mmioFOURCC('M','P','G','4'),
86 Standard_Integer theFrameRate = 25);
89 * Destructor: closes the movie file and flushes all the frames
91 Standard_EXPORT ~OpenGl_AVIWriter ();
94 * Begin the recording.
96 Standard_EXPORT void StartRecording(const HANDLE hWin = NULL);
99 * Stop the recording (can be restarted using StartRecording()).
101 Standard_EXPORT void StopRecording ();
104 * Query the state of recording.
106 inline Standard_Boolean IsRecording () const { return myIsAllowRecord; }
109 * Returns the last error message, if any.
111 inline Standard_EXPORT const TCollection_AsciiString&
112 GetLastErrorMessage() const
116 * Get the instance of AVI Writer class.
118 static Standard_EXPORT OpenGl_AVIWriter *
122 * Get the Window handle that contains the actual OpenGl context.
124 inline HANDLE HWindow () const
125 { return myhWindow; }
127 /// Inserts the given HBitmap into the movie as a new Frame at the end.
128 HRESULT AppendNewFrame(HBITMAP hBitmap);
130 /// Inserts the given bitmap bits into the movie as a new Frame at the end.
131 /// The width, height and nBitsPerPixel are the width, height and bits per pixel
132 /// of the bitmap pointed to by the input pBits.
133 HRESULT AppendNewFrame(int nWidth,
143 static OpenGl_AVIWriter * MyAVIWriterInstance;
144 Standard_Boolean myIsAllowRecord;
152 HANDLE myhWindow; // window containing the OGL context
153 LPVOID mylpBits; // Useful to hold the bitmap content if any
154 LONG mylSample; // Keeps track of the current Frame Index
156 PAVISTREAM mypAviStream;
157 PAVISTREAM mypAviCompressedStream;
158 AVISTREAMINFO myAviStreamInfo;
159 AVICOMPRESSOPTIONS myAviCompressOptions;
160 char * myFileName; // Holds the Output Movie File Name
161 TCollection_AsciiString myErrMsg; // Holds the Last Error Message, if any
163 int myAppendFuncSelector; //0=Dummy 1=FirstTime 2=Usual
165 HRESULT AppendFrameFirstTime(HBITMAP );
166 HRESULT AppendFrameUsual(HBITMAP);
167 HRESULT AppendDummy(HBITMAP);
168 HRESULT (OpenGl_AVIWriter::*pAppendFrame[3])(HBITMAP hBitmap);
170 HRESULT AppendFrameBitsFirstTime(int, int, LPVOID,int );
171 HRESULT AppendFrameBitsUsual(int, int, LPVOID,int );
172 HRESULT AppendDummyBits(int, int, LPVOID,int );
173 HRESULT (OpenGl_AVIWriter::*pAppendFrameBits[3])(int, int, LPVOID, int);
175 /// Takes care of creating the memory, streams, compression options etc.
176 /// required for the movie
177 HRESULT InitMovieCreation(int nFrameWidth,int nFrameHeight,int nBitsPerPixel);
179 /// Takes care of releasing the memory and movie related handles
180 void ReleaseMemory();
182 /// Sets the Error Message
183 void SetErrorMessage(const char * theErrMsg);
186 Standard_EXPORT void OpenGl_AVIWriter_AVIWriter(void * pp,
191 Standard_EXPORT Standard_Boolean OpenGl_AVIWriter_AllowWriting(void * hWin);