[refactor] add namespace 'crossdesk' to codebase

This commit is contained in:
dijunkun
2025-10-27 21:09:39 +08:00
parent 3b34c26555
commit 401bfe4483
68 changed files with 313 additions and 606 deletions

View File

@@ -6,6 +6,8 @@
#include "libyuv.h"
#include "rd_log.h"
namespace crossdesk {
ScreenCapturerX11::ScreenCapturerX11() {}
ScreenCapturerX11::~ScreenCapturerX11() { Destroy(); }
@@ -171,4 +173,5 @@ void ScreenCapturerX11::OnFrame() {
}
XDestroyImage(image);
}
}
} // namespace crossdesk

View File

@@ -20,6 +20,8 @@
#include "screen_capturer.h"
namespace crossdesk {
class ScreenCapturerX11 : public ScreenCapturer {
public:
ScreenCapturerX11();
@@ -60,5 +62,5 @@ class ScreenCapturerX11 : public ScreenCapturer {
std::vector<uint8_t> y_plane_;
std::vector<uint8_t> uv_plane_;
};
} // namespace crossdesk
#endif

View File

@@ -2,6 +2,8 @@
#include "rd_log.h"
namespace crossdesk {
ScreenCapturerSck::ScreenCapturerSck() {}
ScreenCapturerSck::~ScreenCapturerSck() {}
@@ -70,4 +72,5 @@ std::vector<DisplayInfo> ScreenCapturerSck::GetDisplayInfoList() {
void ScreenCapturerSck::OnFrame() {}
void ScreenCapturerSck::CleanUp() {}
void ScreenCapturerSck::CleanUp() {}
} // namespace crossdesk

View File

@@ -16,6 +16,8 @@
#include "screen_capturer.h"
namespace crossdesk {
class ScreenCapturerSck : public ScreenCapturer {
public:
ScreenCapturerSck();
@@ -55,5 +57,5 @@ class ScreenCapturerSck : public ScreenCapturer {
private:
std::unique_ptr<ScreenCapturer> screen_capturer_sck_impl_;
};
} // namespace crossdesk
#endif

View File

@@ -22,9 +22,12 @@
#include "display_info.h"
#include "rd_log.h"
static const int kFullDesktopScreenId = -1;
using namespace crossdesk;
class ScreenCapturerSckImpl;
static const int kFullDesktopScreenId = -1;
// The ScreenCaptureKit API was available in macOS 12.3, but full-screen capture
// was reported to be broken before macOS 13 - see http://crbug.com/40234870.
// Also, the `SCContentFilter` fields `contentRect` and `pointPixelScale` were
@@ -424,10 +427,6 @@ void ScreenCapturerSckImpl::StartOrReconfigureCapturer() {
[SCShareableContent getShareableContentWithCompletionHandler:handler];
}
std::unique_ptr<ScreenCapturer> ScreenCapturerSck::CreateScreenCapturerSck() {
return std::make_unique<ScreenCapturerSckImpl>();
}
@implementation SckHelper {
// This lock is to prevent the capturer being destroyed while an instance
// method is still running on another thread.
@@ -485,4 +484,8 @@ std::unique_ptr<ScreenCapturer> ScreenCapturerSck::CreateScreenCapturerSck() {
_capturer = nullptr;
}
@end
@end
std::unique_ptr<ScreenCapturer> ScreenCapturerSck::CreateScreenCapturerSck() {
return std::make_unique<ScreenCapturerSckImpl>();
}

View File

@@ -11,6 +11,8 @@
#include "display_info.h"
namespace crossdesk {
class ScreenCapturer {
public:
typedef std::function<void(unsigned char*, int, int, int, const char*)>
@@ -30,5 +32,5 @@ class ScreenCapturer {
virtual std::vector<DisplayInfo> GetDisplayInfoList() = 0;
virtual int SwitchTo(int monitor_index) = 0;
};
} // namespace crossdesk
#endif

View File

@@ -16,6 +16,8 @@
#include "screen_capturer_sck.h"
#endif
namespace crossdesk {
class ScreenCapturerFactory {
public:
virtual ~ScreenCapturerFactory() {}
@@ -34,5 +36,5 @@ class ScreenCapturerFactory {
#endif
}
};
} // namespace crossdesk
#endif

View File

@@ -10,9 +10,11 @@
#include "libyuv.h"
#include "rd_log.h"
namespace crossdesk {
static std::vector<DisplayInfo> gs_display_list;
std::string WideToUtf8(const wchar_t *wideStr) {
std::string WideToUtf8(const wchar_t* wideStr) {
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, nullptr, 0,
nullptr, nullptr);
std::string result(size_needed, 0);
@@ -31,14 +33,14 @@ BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, [[maybe_unused]] HDC hdc,
if (monitor_info_.dwFlags & MONITORINFOF_PRIMARY) {
gs_display_list.insert(
gs_display_list.begin(),
{(void *)hmonitor, WideToUtf8(monitor_info_.szDevice),
{(void*)hmonitor, WideToUtf8(monitor_info_.szDevice),
(monitor_info_.dwFlags & MONITORINFOF_PRIMARY) ? true : false,
monitor_info_.rcMonitor.left, monitor_info_.rcMonitor.top,
monitor_info_.rcMonitor.right, monitor_info_.rcMonitor.bottom});
*(HMONITOR *)data = hmonitor;
*(HMONITOR*)data = hmonitor;
} else {
gs_display_list.push_back(DisplayInfo(
(void *)hmonitor, WideToUtf8(monitor_info_.szDevice),
(void*)hmonitor, WideToUtf8(monitor_info_.szDevice),
(monitor_info_.dwFlags & MONITORINFOF_PRIMARY) ? true : false,
monitor_info_.rcMonitor.left, monitor_info_.rcMonitor.top,
monitor_info_.rcMonitor.right, monitor_info_.rcMonitor.bottom));
@@ -81,7 +83,7 @@ bool ScreenCapturerWgc::IsWgcSupported() {
/* no contract for IGraphicsCaptureItemInterop, verify 10.0.18362.0 */
return winrt::Windows::Foundation::Metadata::ApiInformation::
IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", 8);
} catch (const winrt::hresult_error &) {
} catch (const winrt::hresult_error&) {
return false;
} catch (...) {
return false;
@@ -115,7 +117,7 @@ int ScreenCapturerWgc::Init(const int fps, cb_desktop_data cb) {
}
for (int i = 0; i < display_info_list_.size(); i++) {
const auto &display = display_info_list_[i];
const auto& display = display_info_list_[i];
LOG_INFO(
"index: {}, display name: {}, is primary: {}, bounds: ({}, {}) - "
"({}, {})",
@@ -243,16 +245,16 @@ int ScreenCapturerWgc::SwitchTo(int monitor_index) {
return 0;
}
void ScreenCapturerWgc::OnFrame(const WgcSession::wgc_session_frame &frame,
void ScreenCapturerWgc::OnFrame(const WgcSession::wgc_session_frame& frame,
int id) {
if (on_data_) {
if (!nv12_frame_) {
nv12_frame_ = new unsigned char[frame.width * frame.height * 3 / 2];
}
libyuv::ARGBToNV12((const uint8_t *)frame.data, frame.width * 4,
(uint8_t *)nv12_frame_, frame.width,
(uint8_t *)(nv12_frame_ + frame.width * frame.height),
libyuv::ARGBToNV12((const uint8_t*)frame.data, frame.width * 4,
(uint8_t*)nv12_frame_, frame.width,
(uint8_t*)(nv12_frame_ + frame.width * frame.height),
frame.width, frame.width, frame.height);
on_data_(nv12_frame_, frame.width * frame.height * 3 / 2, frame.width,
@@ -262,7 +264,7 @@ void ScreenCapturerWgc::OnFrame(const WgcSession::wgc_session_frame &frame,
void ScreenCapturerWgc::CleanUp() {
if (inited_) {
for (auto &session : sessions_) {
for (auto& session : sessions_) {
if (session.session_) {
session.session_->Stop();
}
@@ -270,3 +272,4 @@ void ScreenCapturerWgc::CleanUp() {
sessions_.clear();
}
}
} // namespace crossdesk

View File

@@ -11,6 +11,8 @@
#include "wgc_session.h"
#include "wgc_session_impl.h"
namespace crossdesk {
class ScreenCapturerWgc : public ScreenCapturer,
public WgcSession::wgc_session_observer {
public:
@@ -64,5 +66,5 @@ class ScreenCapturerWgc : public ScreenCapturer,
unsigned char* nv12_frame_ = nullptr;
unsigned char* nv12_frame_scaled_ = nullptr;
};
} // namespace crossdesk
#endif

View File

@@ -3,6 +3,8 @@
#include <Windows.h>
namespace crossdesk {
class WgcSession {
public:
struct wgc_session_frame {
@@ -10,13 +12,13 @@ class WgcSession {
unsigned int height;
unsigned int row_pitch;
const unsigned char *data;
const unsigned char* data;
};
class wgc_session_observer {
public:
virtual ~wgc_session_observer() {}
virtual void OnFrame(const wgc_session_frame &frame, int id) = 0;
virtual void OnFrame(const wgc_session_frame& frame, int id) = 0;
};
public:
@@ -25,7 +27,7 @@ class WgcSession {
virtual int Initialize(HWND hwnd) = 0;
virtual int Initialize(HMONITOR hmonitor) = 0;
virtual void RegisterObserver(wgc_session_observer *observer) = 0;
virtual void RegisterObserver(wgc_session_observer* observer) = 0;
virtual int Start() = 0;
virtual int Stop() = 0;
@@ -33,7 +35,7 @@ class WgcSession {
virtual int Pause() = 0;
virtual int Resume() = 0;
virtual ~WgcSession(){};
virtual ~WgcSession() {};
};
} // namespace crossdesk
#endif

View File

@@ -18,9 +18,11 @@
throw winrt::hresult_error(RO_E_CLOSED); \
}
namespace crossdesk {
extern "C" {
HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice(
::IDXGIDevice *dxgiDevice, ::IInspectable **graphicsDevice);
::IDXGIDevice* dxgiDevice, ::IInspectable** graphicsDevice);
}
WgcSessionImpl::WgcSessionImpl(int id) : id_(id) {}
@@ -48,7 +50,7 @@ int WgcSessionImpl::Initialize(HMONITOR hmonitor) {
return Initialize();
}
void WgcSessionImpl::RegisterObserver(wgc_session_observer *observer) {
void WgcSessionImpl::RegisterObserver(wgc_session_observer* observer) {
std::lock_guard locker(lock_);
observer_ = observer;
}
@@ -175,7 +177,7 @@ auto WgcSessionImpl::CreateCaptureItemForWindow(HWND hwnd) {
interop_factory->CreateForWindow(
hwnd,
winrt::guid_of<ABI::Windows::Graphics::Capture::IGraphicsCaptureItem>(),
reinterpret_cast<void **>(winrt::put_abi(item)));
reinterpret_cast<void**>(winrt::put_abi(item)));
return item;
}
@@ -187,7 +189,7 @@ auto WgcSessionImpl::CreateCaptureItemForMonitor(HMONITOR hmonitor) {
interop_factory->CreateForMonitor(
hmonitor,
winrt::guid_of<ABI::Windows::Graphics::Capture::IGraphicsCaptureItem>(),
reinterpret_cast<void **>(winrt::put_abi(item)));
reinterpret_cast<void**>(winrt::put_abi(item)));
return item;
}
@@ -216,8 +218,8 @@ HRESULT WgcSessionImpl::CreateMappedTexture(
}
void WgcSessionImpl::OnFrame(
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &sender,
[[maybe_unused]] winrt::Windows::Foundation::IInspectable const &args) {
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const& sender,
[[maybe_unused]] winrt::Windows::Foundation::IInspectable const& args) {
std::lock_guard locker(lock_);
auto is_new_size = false;
@@ -268,8 +270,8 @@ void WgcSessionImpl::OnFrame(
wgc_session_frame{static_cast<unsigned int>(frame_size.Width),
static_cast<unsigned int>(frame_size.Height),
map_result.RowPitch,
const_cast<const unsigned char *>(
(unsigned char *)map_result.pData)},
const_cast<const unsigned char*>(
(unsigned char*)map_result.pData)},
id_);
}
@@ -286,8 +288,8 @@ void WgcSessionImpl::OnFrame(
}
void WgcSessionImpl::OnClosed(
winrt::Windows::Graphics::Capture::GraphicsCaptureItem const &,
winrt::Windows::Foundation::IInspectable const &) {
winrt::Windows::Graphics::Capture::GraphicsCaptureItem const&,
winrt::Windows::Foundation::IInspectable const&) {
OutputDebugStringW(L"WgcSessionImpl::OnClosed");
}
@@ -375,4 +377,5 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param,
// ::CloseWindow(hwnd_);
// ::DestroyWindow(hwnd_);
// }
// }
} // namespace crossdesk

View File

@@ -10,15 +10,17 @@
#include "wgc_session.h"
namespace crossdesk {
class WgcSessionImpl : public WgcSession {
struct __declspec(uuid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1"))
IDirect3DDxgiInterfaceAccess : ::IUnknown {
virtual HRESULT __stdcall GetInterface(GUID const &id, void **object) = 0;
IDirect3DDxgiInterfaceAccess : ::IUnknown {
virtual HRESULT __stdcall GetInterface(GUID const& id, void** object) = 0;
};
template <typename T>
inline auto GetDXGIInterfaceFromObject(
winrt::Windows::Foundation::IInspectable const &object) {
winrt::Windows::Foundation::IInspectable const& object) {
auto access = object.as<IDirect3DDxgiInterfaceAccess>();
winrt::com_ptr<T> result;
winrt::check_hresult(
@@ -44,7 +46,7 @@ class WgcSessionImpl : public WgcSession {
int Initialize(HWND hwnd) override;
int Initialize(HMONITOR hmonitor) override;
void RegisterObserver(wgc_session_observer *observer) override;
void RegisterObserver(wgc_session_observer* observer) override;
int Start() override;
int Stop() override;
@@ -60,11 +62,11 @@ class WgcSessionImpl : public WgcSession {
HRESULT CreateMappedTexture(winrt::com_ptr<ID3D11Texture2D> src_texture,
unsigned int width = 0, unsigned int height = 0);
void OnFrame(
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const
&sender,
winrt::Windows::Foundation::IInspectable const &args);
void OnClosed(winrt::Windows::Graphics::Capture::GraphicsCaptureItem const &,
winrt::Windows::Foundation::IInspectable const &);
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const&
sender,
winrt::Windows::Foundation::IInspectable const& args);
void OnClosed(winrt::Windows::Graphics::Capture::GraphicsCaptureItem const&,
winrt::Windows::Foundation::IInspectable const&);
int Initialize();
void CleanUp();
@@ -78,7 +80,7 @@ class WgcSessionImpl : public WgcSession {
bool is_running_ = false;
bool is_paused_ = false;
wgc_session_observer *observer_ = nullptr;
wgc_session_observer* observer_ = nullptr;
// wgc
winrt::Windows::Graphics::Capture::GraphicsCaptureItem capture_item_{nullptr};
@@ -113,5 +115,5 @@ class WgcSessionImpl : public WgcSession {
// access->GetInterface(winrt::guid_of<T>(), result.put_void()));
// return result;
// }
} // namespace crossdesk
#endif