0023316: OpenGl package can not be compiled on RedHat40-64
[occt.git] / src / OpenGl / OpenGl_AVIWriter.hxx
1 // Created on: 2007-04-15
2 // Created by: Alexey MORENOV & Alexander GRIGORIEV
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21 #ifndef __OPENGL_AVIWRITER_H
22 #define __OPENGL_AVIWRITER_H
23
24 #ifdef WNT
25 #define THIS void 
26
27 #include <InterfaceGraphic_WNT.hxx>
28 #include <stdlib.h>
29 #include <vfw.h>
30 #include <TCollection_AsciiString.hxx>
31
32 /**
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:
36  * <ol>
37  *
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.
43  * For example,
44  * <ul>
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>
47  * </ul>
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.
51  * <br>
52  * Finally, make sure you have the codec installed on the machine before
53  * passing its Fourcc here.
54  * </li>
55  * <li>
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
58  * process.
59  * </li>
60  * <li>
61  * Stop the recording: call the method StopRecording(). Can be omitted if the
62  * next to execute would be the destructor.
63  * </li>
64  * <li>
65  * Close the AVI file and exit the process of recording. This is done
66  * automatically by the destructor.
67  * </li>
68  * </ol>
69  */
70 class OpenGl_AVIWriter
71 {
72 public:
73
74   /**
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.
77    * @param theFileName
78    *   Name of the output movie file to create.
79    * @param theCodec
80    *   FourCC of the Video Codec to be used for compression
81    * @param theFrameRate
82    *   The Frames Per Second (FPS) setting to be used for the movie
83    */
84   Standard_EXPORT OpenGl_AVIWriter(const char * theFileName, 
85                                    DWORD theCodec = mmioFOURCC('M','P','G','4'),
86                                    Standard_Integer theFrameRate = 25);
87
88   /**
89    * Destructor: closes the movie file and flushes all the frames
90    */
91   Standard_EXPORT ~OpenGl_AVIWriter     ();
92
93   /**
94    * Begin the recording.
95    */
96   Standard_EXPORT void    StartRecording(const HANDLE hWin = NULL);
97
98   /**
99    * Stop the recording (can be restarted using StartRecording()).
100    */
101   Standard_EXPORT void    StopRecording ();
102
103   /**
104    * Query the state of recording.
105    */
106   inline Standard_Boolean IsRecording   () const { return myIsAllowRecord; }
107
108   /**
109    * Returns the last error message, if any.
110    */
111   inline Standard_EXPORT const TCollection_AsciiString&
112                           GetLastErrorMessage() const
113   { return myErrMsg; }
114
115   /**
116    * Get the instance of AVI Writer class.
117    */ 
118   static Standard_EXPORT OpenGl_AVIWriter *
119                           GetInstance   ();
120
121   /**
122    * Get the Window handle that contains the actual OpenGl context.
123    */
124   inline HANDLE           HWindow () const
125   { return myhWindow; }
126
127   /// Inserts the given HBitmap into the movie as a new Frame at the end.
128   HRESULT         AppendNewFrame(HBITMAP hBitmap);
129
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,
134                                  int nHeight,
135                                  LPVOID pBits,
136                                  int nBitsPerPixel);
137
138 private:
139
140   void call_avi();
141
142 private:
143   static OpenGl_AVIWriter       * MyAVIWriterInstance;
144   Standard_Boolean                myIsAllowRecord;
145
146   BYTE                          * mypBits;
147   UINT                            myWidth;
148   UINT                            myHeight;
149
150   HDC                   myhAviDC;
151   HANDLE                myhHeap;
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
155   PAVIFILE              mypAviFile;
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
162
163   int                   myAppendFuncSelector;  //0=Dummy 1=FirstTime 2=Usual
164
165   HRESULT               AppendFrameFirstTime(HBITMAP );
166   HRESULT               AppendFrameUsual(HBITMAP);
167   HRESULT               AppendDummy(HBITMAP);
168   HRESULT       (OpenGl_AVIWriter::*pAppendFrame[3])(HBITMAP hBitmap);
169
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);
174
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);
178
179   /// Takes care of releasing the memory and movie related handles
180   void ReleaseMemory();
181
182   /// Sets the Error Message
183   void SetErrorMessage(const char * theErrMsg);
184 };
185
186 Standard_EXPORT void OpenGl_AVIWriter_AVIWriter(void * pp,
187                                                 int  nWidth,
188                                                 int  nHeight,
189                                                 int  nBitsPerPixel);
190
191 Standard_EXPORT Standard_Boolean OpenGl_AVIWriter_AllowWriting(void * hWin);
192
193 #endif // WNT
194 #endif