VideoCaptureView.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
  2. // (“Fluent UI”)。该示例仅供参考,
  3. // 用以补充《Microsoft 基础类参考》和
  4. // MFC C++ 库软件随附的相关电子文档。
  5. // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
  6. // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
  7. // https://go.microsoft.com/fwlink/?LinkId=238214.
  8. //
  9. // 版权所有(C) Microsoft Corporation
  10. // 保留所有权利。
  11. // VideoCaptureView.h: CVideoCaptureView 类的接口
  12. //
  13. #pragma once
  14. #include "VideoCaptureDoc.h"
  15. #include "MemoryClient.h"
  16. typedef struct __CAPTURE_INFO__
  17. {
  18. // 是否是jpg;
  19. BOOL bIsJPG;
  20. // 持续时间;
  21. int nKeepTime;
  22. // 每秒抓取张数;
  23. int nCaputerCount;
  24. // 保存路径;
  25. TCHAR szSaveDir[MAX_PATH];
  26. // 文件名前缀;
  27. TCHAR szPrefix[64];
  28. // 是否自动命名;
  29. BOOL IsAutoName;
  30. // 是否单张截图;
  31. BOOL bSingle;
  32. }CaptureInfo, *pCaptureInfo;
  33. class CVideoCaptureView : public CView
  34. {
  35. protected: // 仅从序列化创建
  36. CVideoCaptureView() noexcept;
  37. DECLARE_DYNCREATE(CVideoCaptureView)
  38. // 特性
  39. public:
  40. CVideoCaptureDoc* GetDocument() const;
  41. // 操作
  42. public:
  43. // 重写
  44. public:
  45. virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
  46. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  47. protected:
  48. virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
  49. virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
  50. virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
  51. // 实现
  52. public:
  53. virtual ~CVideoCaptureView();
  54. #ifdef _DEBUG
  55. virtual void AssertValid() const;
  56. virtual void Dump(CDumpContext& dc) const;
  57. #endif
  58. public:
  59. // 设备句柄;
  60. PVOID m_hVideoDevice;
  61. // 是否有信号;
  62. BOOL m_bNoSignal;
  63. // 是否在录频;
  64. BOOL m_bIsRecord;
  65. // 录频格式;
  66. BOOL m_bIsMp4; // FALSE= AVI
  67. //////////////////////////////////////////////////////////////////////////
  68. // VIDEO PROPERTIES
  69. // 是否支持GPU;
  70. BOOL m_bSupportGPU;
  71. // 视频流宽度;
  72. ULONG m_nVideoWidth;
  73. // 视频流高度;
  74. ULONG m_nVideoHeight;
  75. BOOL m_bVideoIsInterleaved;
  76. double m_dVideoFrameRate;
  77. BOOL m_bVideoDeinterlaceEnable;
  78. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// AUDIO PROPERTIES
  79. ULONG m_nAudioChannels;
  80. ULONG m_nAudioBitsPerSample;
  81. ULONG m_nAudioSampleFrequency;
  82. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QUALITY PROPERTIES
  83. ULONG m_nSharpness;
  84. ULONG m_nSaturation;
  85. ULONG m_nHue;
  86. ULONG m_nConstrast;
  87. ULONG m_nBrightness;
  88. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RECORD & FILE PROPERTIES
  89. // 截图路径;
  90. CString m_strSnapshotPath;
  91. //
  92. CString m_strFormatChangedOutput;
  93. // 垂直镜像;
  94. BOOL m_bVertically;
  95. // 水平镜像;
  96. BOOL m_bHoriontal;
  97. // 程序退出;
  98. BOOL m_bAppQuit;
  99. public:
  100. // 初始化设备;
  101. BOOL HwInitialize();
  102. // 释放设备;
  103. BOOL HwUninitialize();
  104. // 单次截图;
  105. void CaptureSingleImage(LPTSTR lpszFileName, BOOL bIsJPG = TRUE);
  106. // 单次截图并自动命名;
  107. std::string CaptureSingleImageAutoName(LPCTSTR lpszDir, BOOL bIsJPG = TRUE);
  108. // 连续截图;//默认持续1000ms;
  109. void CaptureMultiImage(LPCTSTR lpszDir, LPCTSTR lpszPrefix, BOOL bIsJPG, int nDurationTime = 1000);
  110. //////////////////////////////////////////////////////////////////////////
  111. // ->预览截图;
  112. CaptureInfo m_CaptureInfo;
  113. BOOL m_bCaptureImage;
  114. std::mutex m_mut_cpature;
  115. std::condition_variable m_capture_cond;
  116. // 单次截图;
  117. void CaptureSingleImageEx(LPTSTR lpszFileName, BOOL bIsJPG = TRUE);
  118. // 单次截图并自动命名;
  119. std::string CaptureSingleImageAutoNameEx(LPCTSTR lpszDir, BOOL bIsJPG = TRUE);
  120. // 连续截图;//默认持续1000ms;
  121. void CaptureMultiImageEx(LPCTSTR lpszDir, LPCTSTR lpszPrefix, BOOL bIsJPG, int nDurationTime = 1000);
  122. // 截图;
  123. BOOL SaveImageByCaptureInfo(const CaptureInfo &capInfo);
  124. // 截图线程;
  125. BYTE* m_pBuffer;
  126. DWORD m_dwBufferLen;
  127. std::mutex m_mut_thread;
  128. std::condition_variable m_thread_cond; //使用std::condition_variable等待数据
  129. static void CaptureImageThread(CVideoCaptureView *pView);
  130. // 录屏;
  131. void StartRecord(DWORD dwDuration, LPCTSTR lpSavePath);
  132. void StopRecord();
  133. protected:
  134. // 生成的消息映射函数
  135. protected:
  136. afx_msg void OnFilePrintPreview();
  137. afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  138. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  139. DECLARE_MESSAGE_MAP()
  140. public:
  141. void SetRibbonStatusBarText(CString strText, int uId);
  142. friend class CMemoryClient;
  143. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  144. afx_msg void OnTimer(UINT_PTR nIDEvent);
  145. afx_msg void OnCutBmp();
  146. afx_msg void OnCutJpg();
  147. afx_msg void OnStartRecord();
  148. afx_msg void OnStopRecord();
  149. afx_msg void OnCheckVertically();
  150. afx_msg void OnCheckHoriontal();
  151. afx_msg void OnUpdateCheckVertically(CCmdUI* pCmdUI);
  152. afx_msg void OnUpdateCheckHoriontal(CCmdUI* pCmdUI);
  153. afx_msg void OnTraymenuReconnect();
  154. afx_msg void OnCheckSuportGpu();
  155. afx_msg void OnCheckFormatMp4();
  156. afx_msg void OnCheckFormatAvi();
  157. afx_msg void OnUpdateCheckSuportGpu(CCmdUI* pCmdUI);
  158. afx_msg void OnUpdateCheckFormatMp4(CCmdUI* pCmdUI);
  159. afx_msg void OnUpdateCheckFormatAvi(CCmdUI* pCmdUI);
  160. afx_msg void OnUpdateStartRecord(CCmdUI* pCmdUI);
  161. afx_msg void OnUpdateStopRecord(CCmdUI* pCmdUI);
  162. };
  163. #ifndef _DEBUG // VideoCaptureView.cpp 中的调试版本
  164. inline CVideoCaptureDoc* CVideoCaptureView::GetDocument() const
  165. { return reinterpret_cast<CVideoCaptureDoc*>(m_pDocument); }
  166. #endif