0027606: Visualization - view is blocking when MSAA has been overridden in graphics...
[occt.git] / src / OpenGl / OpenGl_AVIWriter.hxx
1 // Created on: 2007-04-15
2 // Created by: Alexey MORENOV & Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef __OPENGL_AVIWRITER_H
17 #define __OPENGL_AVIWRITER_H
18
19 #ifdef _MSC_VER
20 #define THIS void 
21
22 #include <InterfaceGraphic.hxx>
23 #include <stdlib.h>
24 #include <vfw.h>
25 #include <TCollection_AsciiString.hxx>
26
27 /**
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:
31  * <ol>
32  *
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.
38  * For example,
39  * <ul>
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>
42  * </ul>
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.
46  *
47  * Finally, make sure you have the codec installed on the machine before
48  * passing its Fourcc here.
49  * </li>
50  * <li>
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
53  * process.
54  * </li>
55  * <li>
56  * Stop the recording: call the method StopRecording(). Can be omitted if the
57  * next to execute would be the destructor.
58  * </li>
59  * <li>
60  * Close the AVI file and exit the process of recording. This is done
61  * automatically by the destructor.
62  * </li>
63  * </ol>
64  */
65 class OpenGl_AVIWriter
66 {
67 public:
68
69   /**
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.
72    * @param theFileName
73    *   Name of the output movie file to create.
74    * @param theCodec
75    *   FourCC of the Video Codec to be used for compression
76    * @param theFrameRate
77    *   The Frames Per Second (FPS) setting to be used for the movie
78    */
79   Standard_EXPORT OpenGl_AVIWriter(const char * theFileName, 
80                                    DWORD theCodec = mmioFOURCC('M','P','G','4'),
81                                    Standard_Integer theFrameRate = 25);
82
83   /**
84    * Destructor: closes the movie file and flushes all the frames
85    */
86   Standard_EXPORT ~OpenGl_AVIWriter     ();
87
88   /**
89    * Begin the recording.
90    */
91   Standard_EXPORT void    StartRecording(const HANDLE hWin = NULL);
92
93   /**
94    * Stop the recording (can be restarted using StartRecording()).
95    */
96   Standard_EXPORT void    StopRecording ();
97
98   /**
99    * Query the state of recording.
100    */
101   inline Standard_Boolean IsRecording   () const { return myIsAllowRecord; }
102
103   /**
104    * Returns the last error message, if any.
105    */
106   inline Standard_EXPORT const TCollection_AsciiString&
107                           GetLastErrorMessage() const
108   { return myErrMsg; }
109
110   /**
111    * Get the instance of AVI Writer class.
112    */ 
113   static Standard_EXPORT OpenGl_AVIWriter *
114                           GetInstance   ();
115
116   /**
117    * Get the Window handle that contains the actual OpenGl context.
118    */
119   inline HANDLE           HWindow () const
120   { return myhWindow; }
121
122   /// Inserts the given HBitmap into the movie as a new Frame at the end.
123   HRESULT         AppendNewFrame(HBITMAP hBitmap);
124
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,
129                                  int nHeight,
130                                  LPVOID pBits,
131                                  int nBitsPerPixel);
132
133 private:
134
135   void call_avi();
136
137 private:
138   static OpenGl_AVIWriter       * MyAVIWriterInstance;
139   Standard_Boolean                myIsAllowRecord;
140
141   BYTE                          * mypBits;
142   UINT                            myWidth;
143   UINT                            myHeight;
144
145   HDC                   myhAviDC;
146   HANDLE                myhHeap;
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
150   PAVIFILE              mypAviFile;
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
157
158   int                   myAppendFuncSelector;  //0=Dummy 1=FirstTime 2=Usual
159
160   HRESULT               AppendFrameFirstTime(HBITMAP );
161   HRESULT               AppendFrameUsual(HBITMAP);
162   HRESULT               AppendDummy(HBITMAP);
163   HRESULT       (OpenGl_AVIWriter::*pAppendFrame[3])(HBITMAP hBitmap);
164
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);
169
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);
173
174   /// Takes care of releasing the memory and movie related handles
175   void ReleaseMemory();
176
177   /// Sets the Error Message
178   void SetErrorMessage(const char * theErrMsg);
179 };
180
181 Standard_EXPORT void OpenGl_AVIWriter_AVIWriter(void * pp,
182                                                 int  nWidth,
183                                                 int  nHeight,
184                                                 int  nBitsPerPixel);
185
186 Standard_EXPORT Standard_Boolean OpenGl_AVIWriter_AllowWriting(void * hWin);
187
188 #endif // _MSC_VER
189 #endif