[feat] update rtc module

This commit is contained in:
dijunkun
2025-05-13 21:47:05 +08:00
parent 6fe46f6181
commit e6e237279c
12 changed files with 46 additions and 28 deletions

View File

@@ -11,7 +11,8 @@
class ScreenCapturer {
public:
typedef std::function<void(unsigned char*, int, int, int)> cb_desktop_data;
typedef std::function<void(unsigned char*, int, int, int, int)>
cb_desktop_data;
class DisplayInfo {
public:

View File

@@ -123,7 +123,7 @@ int ScreenCapturerWgc::Init(const int fps, cb_desktop_data cb) {
display.top, display.right, display.bottom);
sessions_.push_back(
{std::make_unique<WgcSessionImpl>(), false, false, false});
{std::make_unique<WgcSessionImpl>(i), false, false, false});
sessions_.back().session_->RegisterObserver(this);
error = sessions_.back().session_->Initialize((HMONITOR)display.handle);
if (error != 0) {
@@ -242,7 +242,8 @@ 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];
@@ -254,7 +255,7 @@ void ScreenCapturerWgc::OnFrame(const WgcSession::wgc_session_frame &frame) {
frame.width, frame.width, frame.height);
on_data_(nv12_frame_, frame.width * frame.height * 3 / 2, frame.width,
frame.height);
frame.height, id);
}
}

View File

@@ -32,7 +32,7 @@ class ScreenCapturerWgc : public ScreenCapturer,
int SwitchTo(int monitor_index);
void OnFrame(const WgcSession::wgc_session_frame &frame);
void OnFrame(const WgcSession::wgc_session_frame &frame, int id);
protected:
void CleanUp();

View File

@@ -16,7 +16,7 @@ class WgcSession {
class wgc_session_observer {
public:
virtual ~wgc_session_observer() {}
virtual void OnFrame(const wgc_session_frame &frame) = 0;
virtual void OnFrame(const wgc_session_frame &frame, int id) = 0;
};
public:

View File

@@ -23,7 +23,7 @@ HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice(
::IDXGIDevice *dxgiDevice, ::IInspectable **graphicsDevice);
}
WgcSessionImpl::WgcSessionImpl() {}
WgcSessionImpl::WgcSessionImpl(int id) : id_(id) {}
WgcSessionImpl::~WgcSessionImpl() {
Stop();
@@ -264,11 +264,13 @@ void WgcSessionImpl::OnFrame(
// copy data from map_result.pData
if (map_result.pData && observer_) {
observer_->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)});
observer_->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)},
id_);
}
d3d11_device_context_->Unmap(d3d11_texture_mapped_.get(), 0);

View File

@@ -35,7 +35,7 @@ class WgcSessionImpl : public WgcSession {
} target_{0};
public:
WgcSessionImpl();
WgcSessionImpl(int id);
~WgcSessionImpl() override;
public:
@@ -72,6 +72,7 @@ class WgcSessionImpl : public WgcSession {
// void message_func();
private:
int id_ = -1;
std::mutex lock_;
bool is_initialized_ = false;
bool is_running_ = false;