My Project
MoviePlatform.h
1 #pragma once
2 #include <vector>
3 #include "IAttributeFields.h"
4 #include "IMovieCodec.h"
5 #include <mutex>
6 namespace ParaEngine
7 {
8  using namespace std;
9 
11  {
18  };
19 
22  {
23  public:
24  CMoviePlatform(void);
25  virtual ~CMoviePlatform(void);
26  static CMoviePlatform& GetSingleton();
27 
28  void Cleanup();
29 
31  IMovieCodec* GetMovieCodec(bool bCreateIfNotExist = true);
32 
33  public:
35  // implementation of IAttributeFields
36 
38  virtual int GetAttributeClassID(){ return ATTRIBUTE_CLASSID_MoviePlatform; }
40  virtual const char* GetAttributeClassName(){ static const char name[] = "MoviePlatform"; return name; }
42  virtual const char* GetAttributeClassDescription(){ static const char desc[] = ""; return desc; }
44  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
45 
46  ATTRIBUTE_METHOD1(CMoviePlatform, video_encode_example_s, const char*) { cls->video_encode_example(p1); return S_OK; }
47 
48  ATTRIBUTE_METHOD1(CMoviePlatform, GetCodec_s, int*) { *p1 = cls->GetCodec(); return S_OK; }
49  ATTRIBUTE_METHOD1(CMoviePlatform, SetCodec_s, int) { cls->SetCodec(p1); return S_OK; }
50 
51  ATTRIBUTE_METHOD1(CMoviePlatform, GetMarginLeft_s, int*) { *p1 = cls->MarginLeft(); return S_OK; }
52  ATTRIBUTE_METHOD1(CMoviePlatform, SetMarginLeft_s, int) { cls->MarginLeft(p1); return S_OK; }
53 
54  ATTRIBUTE_METHOD1(CMoviePlatform, GetMarginTop_s, int*) { *p1 = cls->MarginTop(); return S_OK; }
55  ATTRIBUTE_METHOD1(CMoviePlatform, SetMarginTop_s, int) { cls->MarginTop(p1); return S_OK; }
56 
57  ATTRIBUTE_METHOD1(CMoviePlatform, GetMarginRight_s, int*) { *p1 = cls->MarginRight(); return S_OK; }
58  ATTRIBUTE_METHOD1(CMoviePlatform, SetMarginRight_s, int) { cls->MarginRight(p1); return S_OK; }
59 
60  ATTRIBUTE_METHOD1(CMoviePlatform, GetMarginBottom_s, int*) { *p1 = cls->MarginBottom(); return S_OK; }
61  ATTRIBUTE_METHOD1(CMoviePlatform, SetMarginBottom_s, int) { cls->MarginBottom(p1); return S_OK; }
62 
63  ATTRIBUTE_METHOD1(CMoviePlatform, HasMoviePlugin_s, bool*) { *p1 = cls->HasMoviePlugin(); return S_OK; }
64 
65  ATTRIBUTE_METHOD1(CMoviePlatform, GetRecordingFPS_s, int*) { *p1 = cls->GetRecordingFPS(); return S_OK; }
66  ATTRIBUTE_METHOD1(CMoviePlatform, SetRecordingFPS_s, int) { cls->SetRecordingFPS(p1); return S_OK; }
67 
68  ATTRIBUTE_METHOD1(CMoviePlatform, GetVideoBitRate_s, int*) { *p1 = cls->GetVideoBitRate(); return S_OK; }
69  ATTRIBUTE_METHOD1(CMoviePlatform, SetVideoBitRate_s, int) { cls->SetVideoBitRate(p1); return S_OK; }
70 
71  ATTRIBUTE_METHOD1(CMoviePlatform, IsCaptureMic_s, bool*) { *p1 = cls->IsCaptureMic(); return S_OK; }
72  ATTRIBUTE_METHOD1(CMoviePlatform, SetCaptureMic_s, bool) { cls->SetCaptureMic(p1); return S_OK; }
73 
74  ATTRIBUTE_METHOD1(CMoviePlatform, IsCaptureAudio_s, bool*) { *p1 = cls->IsCaptureAudio(); return S_OK; }
75  ATTRIBUTE_METHOD1(CMoviePlatform, SetCaptureAudio_s, bool) { cls->SetCaptureAudio(p1); return S_OK; }
76 
77  ATTRIBUTE_METHOD1(CMoviePlatform, GetStereoCaptureMode_s, int*) { *p1 = cls->GetStereoCaptureMode(); return S_OK; }
78  ATTRIBUTE_METHOD1(CMoviePlatform, SetStereoCaptureMode_s, int) { cls->SetStereoCaptureMode((MOVIE_CAPTURE_MODE)p1); return S_OK; }
79 
80  ATTRIBUTE_METHOD1(CMoviePlatform, GetStereoEyeSeparation_s, float*) { *p1 = cls->GetStereoEyeSeparation(); return S_OK; }
81  ATTRIBUTE_METHOD1(CMoviePlatform, SetStereoEyeSeparation_s, float) { cls->SetStereoEyeSeparation(p1); return S_OK; }
82  public:
84  void video_encode_example(const char *filename, int codec_id = 0);
85 
87  virtual void SetCodec(int nCodec);
88 
90  virtual int GetCodec();
91  public:
92  typedef std::function<void(bool, std::vector<BYTE>& base64)> screenshot_callback;
93 
94  public:
96  void CleanUp();
97 
99  void SetCaptureGUI(bool bGUI){m_bCaptureGUI = bGUI;}
101  bool CaptureGUI(){return m_bCaptureGUI;};
102 
104  void SetMovieName(string name){m_sMovieName = name;}
106  string GetMovieName(){return m_sMovieName;}
107 
109  int GetScreenWidth(){return m_nScreenWidth;}
111  int GetScreenHeight(){return m_nScreenHeight;}
112 
113  void SetVideoBitRate(int nRate);
114  int GetVideoBitRate();
115 
119  void SetMovieScreenSize(int nWidth, int nHeight);
121  void GetMovieScreenSize(int* nWidth, int* nHeight);
122 
124  string GetMovieFileName();
125 
127  void BeginCaptureFrame();
128  void EndCaptureFrame();
130  //
131  // screen capture and movie setting
132  //
134 
136  bool BeginCapture(const string& sFileName);
138  bool EndCapture();
140  void PauseCapture();
142  void ResumeCapture();
145  bool IsInCaptureSession();
147  bool IsRecording();
148 
151  bool SetCaptureTarget();
154  bool UnsetCaptureTarget();
158  void RenderCaptured();
159 
163  void SaveCapturedFrame(int nMode=0);
164 
167  bool TakeScreenShot(const string& filename);
168 
176  void TakeScreenShot_Async(const string& filename, bool bEncode = false, int width = -1, int height = -1, screenshot_callback callback = nullptr);
186  bool TakeScreenShot_FromGDI(const string& filename, std::vector<BYTE>& outBase64Buffers, bool bEncode = false, int width = -1, int height = -1);
198  int CaptureBitmapBuffer(HWND nHwnd, int& outFileHeaderSize, int& outInfoHeaderSize, std::vector<BYTE>& outBuffers, bool bCaptureMouse = false, int nLeft = 0, int nTop = 0, int width = 0, int height = 0);
199 
205  bool TakeScreenShot(const string& filename, int width, int height);
206 
213  bool ResizeImage(const string& filename, int width, int height, const string& destFilename);
214 
221  bool GetImageInfo(const string& filename, int* width, int* height, int* nFileSize);
222 
223  HRESULT InvalidateDeviceObjects(); // called just before device is Reset
224  HRESULT RestoreDeviceObjects(); // called when device is restored
225 
228  void EnableCodecSelection(bool bEnable);
229  bool IsCodecSelectionEnabled();
230 
231 
233  void SetRecordingFPS(int nFPS);
234 
236  int GetRecordingFPS();
237 
246  void SetStereoCaptureMode(MOVIE_CAPTURE_MODE nMode = MOVIE_CAPTURE_MODE_NORMAL);
247 
256  MOVIE_CAPTURE_MODE GetStereoCaptureMode();
257 
261  void SetStereoEyeSeparation(float fDist);
262 
266  float GetStereoEyeSeparation();
267 
271  int GetCurrentFrameNumber();
272 
274  void FrameCaptureFFMPEG();
275 
276  void FrameCaptureDX(IMovieCodec* pMovieCodec);
277 
279  bool HasMoviePlugin();
280 
281  void SetCaptureAudio(bool bEnable);
282  bool IsCaptureAudio();
283 
284  void SetCaptureMic(bool bEnable);
285  bool IsCaptureMic();
286 
287  bool IsUseGDI() const;
288  void SetUseGDI(bool val);
289 
290  private:
291  IMovieCodec* m_pMovieCodec;
292  string m_sMovieName;
293  string m_beginningStr;
294  string m_endingStr;
295  float m_fLastRefreshInterval;
296 
297  std::vector<std::function<void()>> m_functionsToPerform;
298  std::mutex m_performMutex;
299 
300 #ifdef USE_DIRECTX_RENDERER
301  LPDIRECT3DTEXTURE9 m_pCaptureTexture;
302  LPDIRECT3DSURFACE9 m_pCaptureSurface;
303  LPDIRECT3DSURFACE9 m_pBackBufferSurface;
304  LPDIRECT3DSURFACE9 m_pOldDepthStencilSurface, m_pDepthStencilSurface;
305  LPDIRECT3DSURFACE9 m_pOffScreenSurface;
306  HDC m_CompatibleHDC;
307  HBITMAP m_BitmapHandle;
308 #endif
309 
310  bool m_bUseGDI;
312  MOVIE_RECORDING_STATE m_recorderState;
314  bool m_bCaptureGUI;
316  bool m_bRenderBorder;
318  bool m_bUseWaterMark;
320  int m_nScreenWidth;
322  int m_nScreenHeight;
323 
324  int m_nMarginLeft;
325  int MarginLeft() const { return m_nMarginLeft; }
326  void MarginLeft(int val) { m_nMarginLeft = val; }
327  int m_nMarginRight;
328  int MarginRight() const { return m_nMarginRight; }
329  void MarginRight(int val) { m_nMarginRight = val; }
330  int m_nMarginTop;
331  int MarginTop() const { return m_nMarginTop; }
332  void MarginTop(int val) { m_nMarginTop = val; }
333  int m_nMarginBottom;
334  int MarginBottom() const { return m_nMarginBottom; }
335  void MarginBottom(int val) { m_nMarginBottom = val; }
336 
338  int m_nRecordingFPS;
341  bool m_bAllowCodecSelection;
342 
344  MOVIE_CAPTURE_MODE m_nStereoCaptureMode;
345 
349  float m_nStereoEyeSeparation;
350 
351 
352  bool m_isLeftEye;
353  };
354 
355 }
for movie capturing
Definition: IMovieCodec.h:17
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void SetMovieName(string name)
set the movie name
Definition: MoviePlatform.h:104
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: MoviePlatform.h:38
recording started but paused
Definition: MoviePlatform.h:15
string GetMovieName()
Get the movie name.
Definition: MoviePlatform.h:106
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: MoviePlatform.h:40
int GetScreenHeight()
clip height in pixel
Definition: MoviePlatform.h:111
MOVIE_RECORDING_STATE
Definition: MoviePlatform.h:10
bool CaptureGUI()
return true if GUI is also captured.
Definition: MoviePlatform.h:101
For managing and rendering the movie.
Definition: MoviePlatform.h:21
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: MoviePlatform.h:42
void SetCaptureGUI(bool bGUI)
set whether GUI is captured.
Definition: MoviePlatform.h:99
int GetScreenWidth()
get the movie screen width and height
Definition: MoviePlatform.h:109
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
MOVIE_CAPTURE_MODE
Video capture mode.
Definition: IMovieCodec.h:6
recording
Definition: MoviePlatform.h:13
recording stopped
Definition: MoviePlatform.h:17