WgcCapturer.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "WgcCapturer.h"
  2. namespace avrecorder {
  3. namespace video {
  4. WgcCapturer::WgcCapturer() { _app = new App; }
  5. WgcCapturer::~WgcCapturer() { close(); if (_app) { delete _app; _app = nullptr; } }
  6. bool WgcCapturer::open(const CaptureTarget& target, int width, int height) {
  7. #ifdef PLATFORM_WINDOWS
  8. close();
  9. if (!_app) _app = new App;
  10. if (target.type == CaptureTargetType::Window) {
  11. return _app->StartCaptureWindow(target.hwnd, width, height);
  12. } else if (target.type == CaptureTargetType::Monitor) {
  13. // 这里只做简单示例,实际应根据 monitorIdx 获取 HMONITOR
  14. return _app->StartCaptureMonitor(nullptr, width, height);
  15. }
  16. return false;
  17. #else
  18. return false;
  19. #endif
  20. }
  21. void WgcCapturer::close() {
  22. #ifdef PLATFORM_WINDOWS
  23. if (_app) _app->Close();
  24. #endif
  25. }
  26. AVFrame* WgcCapturer::getFrame() {
  27. #ifdef PLATFORM_WINDOWS
  28. return _app ? _app->GetFrame() : nullptr;
  29. #else
  30. return nullptr;
  31. #endif
  32. }
  33. void WgcCapturer::setDrawCursor(bool enable) {
  34. #ifdef PLATFORM_WINDOWS
  35. if (_app) _app->SetDrawCursor(enable);
  36. #endif
  37. }
  38. } // namespace video
  39. } // namespace avrecorder