1 // Created on: 2007-04-15
2 // Created by: Alexey MORENOV & Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef __OPENGL_AVIWRITER_H
17 #define __OPENGL_AVIWRITER_H
22 #include <InterfaceGraphic.hxx>
25 #include <TCollection_AsciiString.hxx>
28 * Class providing the API to record AVI files using a codec installed in the
29 * system -- Only on Windows NT/2k/XP/Vista platform under MS Visual Studio.
30 * The following tasks are supported:
33 * <li>Creation of AVI data stream: launched by the constructor.
34 * The constructor accepts the filename, FOURCC video code and the frame rate
35 * setting as parameters.
36 * The default codec name used here is MPG4. To use a different codec, pass
37 * its FOURCC value as the input parameter for dwCodec.
40 * <li>pass mmioFOURCC('D','I','V','X') to use DIVX codec, or</li>
41 * <li>pass mmioFOURCC('I','V','5','0') to use IV50 codec etc...</li>
43 * Also, you can pass just 0 to avoid the codecs altogether. In that case,
44 * the frames would be saved as they are without any compression; However,
45 * the output movie file size would be very huge in that case.
47 * Finally, make sure you have the codec installed on the machine before
48 * passing its Fourcc here.
51 * Start the recording: call the method StartRecording(). This method should be
52 * called at least once; execution of the constructor does not begin the
56 * Stop the recording: call the method StopRecording(). Can be omitted if the
57 * next to execute would be the destructor.
60 * Close the AVI file and exit the process of recording. This is done
61 * automatically by the destructor.
65 class OpenGl_AVIWriter
70 * Constructor. Initializes the internal data structures, prepares for the
71 * creation of an AVI stream when the first frame is ready to be captured.
73 * Name of the output movie file to create.
75 * FourCC of the Video Codec to be used for compression
77 * The Frames Per Second (FPS) setting to be used for the movie
79 Standard_EXPORT OpenGl_AVIWriter(const char * theFileName,
80 DWORD theCodec = mmioFOURCC('M','P','G','4'),
81 Standard_Integer theFrameRate = 25);
84 * Destructor: closes the movie file and flushes all the frames
86 Standard_EXPORT ~OpenGl_AVIWriter ();
89 * Begin the recording.
91 Standard_EXPORT void StartRecording(const HANDLE hWin = NULL);
94 * Stop the recording (can be restarted using StartRecording()).
96 Standard_EXPORT void StopRecording ();
99 * Query the state of recording.
101 inline Standard_Boolean IsRecording () const { return myIsAllowRecord; }
104 * Returns the last error message, if any.
106 inline Standard_EXPORT const TCollection_AsciiString&
107 GetLastErrorMessage() const
111 * Get the instance of AVI Writer class.
113 static Standard_EXPORT OpenGl_AVIWriter *
117 * Get the Window handle that contains the actual OpenGl context.
119 inline HANDLE HWindow () const
120 { return myhWindow; }
122 /// Inserts the given HBitmap into the movie as a new Frame at the end.
123 HRESULT AppendNewFrame(HBITMAP hBitmap);
125 /// Inserts the given bitmap bits into the movie as a new Frame at the end.
126 /// The width, height and nBitsPerPixel are the width, height and bits per pixel
127 /// of the bitmap pointed to by the input pBits.
128 HRESULT AppendNewFrame(int nWidth,
138 static OpenGl_AVIWriter * MyAVIWriterInstance;
139 Standard_Boolean myIsAllowRecord;
147 HANDLE myhWindow; // window containing the OGL context
148 LPVOID mylpBits; // Useful to hold the bitmap content if any
149 LONG mylSample; // Keeps track of the current Frame Index
151 PAVISTREAM mypAviStream;
152 PAVISTREAM mypAviCompressedStream;
153 AVISTREAMINFO myAviStreamInfo;
154 AVICOMPRESSOPTIONS myAviCompressOptions;
155 char * myFileName; // Holds the Output Movie File Name
156 TCollection_AsciiString myErrMsg; // Holds the Last Error Message, if any
158 int myAppendFuncSelector; //0=Dummy 1=FirstTime 2=Usual
160 HRESULT AppendFrameFirstTime(HBITMAP );
161 HRESULT AppendFrameUsual(HBITMAP);
162 HRESULT AppendDummy(HBITMAP);
163 HRESULT (OpenGl_AVIWriter::*pAppendFrame[3])(HBITMAP hBitmap);
165 HRESULT AppendFrameBitsFirstTime(int, int, LPVOID,int );
166 HRESULT AppendFrameBitsUsual(int, int, LPVOID,int );
167 HRESULT AppendDummyBits(int, int, LPVOID,int );
168 HRESULT (OpenGl_AVIWriter::*pAppendFrameBits[3])(int, int, LPVOID, int);
170 /// Takes care of creating the memory, streams, compression options etc.
171 /// required for the movie
172 HRESULT InitMovieCreation(int nFrameWidth,int nFrameHeight,int nBitsPerPixel);
174 /// Takes care of releasing the memory and movie related handles
175 void ReleaseMemory();
177 /// Sets the Error Message
178 void SetErrorMessage(const char * theErrMsg);
181 Standard_EXPORT void OpenGl_AVIWriter_AVIWriter(void * pp,
186 Standard_EXPORT Standard_Boolean OpenGl_AVIWriter_AllowWriting(void * hWin);