| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "WgcCapturer.h"
- namespace avrecorder {
- namespace video {
- WgcCapturer::WgcCapturer() { _app = new App; }
- WgcCapturer::~WgcCapturer() { close(); if (_app) { delete _app; _app = nullptr; } }
- bool WgcCapturer::open(const CaptureTarget& target, int width, int height) {
- #ifdef PLATFORM_WINDOWS
- close();
- if (!_app) _app = new App;
- if (target.type == CaptureTargetType::Window) {
- return _app->StartCaptureWindow(target.hwnd, width, height);
- } else if (target.type == CaptureTargetType::Monitor) {
- // 这里只做简单示例,实际应根据 monitorIdx 获取 HMONITOR
- return _app->StartCaptureMonitor(nullptr, width, height);
- }
- return false;
- #else
- return false;
- #endif
- }
- void WgcCapturer::close() {
- #ifdef PLATFORM_WINDOWS
- if (_app) _app->Close();
- #endif
- }
- AVFrame* WgcCapturer::getFrame() {
- #ifdef PLATFORM_WINDOWS
- return _app ? _app->GetFrame() : nullptr;
- #else
- return nullptr;
- #endif
- }
- void WgcCapturer::setDrawCursor(bool enable) {
- #ifdef PLATFORM_WINDOWS
- if (_app) _app->SetDrawCursor(enable);
- #endif
- }
- } // namespace video
- } // namespace avrecorder
|