mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] update rtc module
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
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)});
|
||||
(unsigned char *)map_result.pData)},
|
||||
id_);
|
||||
}
|
||||
|
||||
d3d11_device_context_->Unmap(d3d11_texture_mapped_.get(), 0);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -71,7 +71,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
remote_action.d = i;
|
||||
if (props->connection_status_ == ConnectionStatus::Connected) {
|
||||
SendDataFrame(props->peer_, (const char*)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), props->data_label_.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
remote_action.type = ControlType::audio_capture;
|
||||
remote_action.a = props->audio_capture_button_pressed_;
|
||||
SendDataFrame(props->peer_, (const char*)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), props->data_label_.c_str());
|
||||
}
|
||||
}
|
||||
if (!props->audio_capture_button_pressed_) {
|
||||
|
||||
@@ -142,6 +142,8 @@ int Render::ConnectTo(const std::string &remote_id, const char *password,
|
||||
memcpy(&props->params_, ¶ms_, sizeof(Params));
|
||||
props->params_.user_id = props->local_id_.c_str();
|
||||
props->peer_ = CreatePeer(&props->params_);
|
||||
AddAudioStream(props->peer_, props->audio_label_.c_str());
|
||||
AddDataStream(props->peer_, props->data_label_.c_str());
|
||||
|
||||
if (props->peer_) {
|
||||
LOG_INFO("[{}] Create peer instance successful", props->local_id_);
|
||||
|
||||
@@ -194,7 +194,9 @@ int Render::StartScreenCapturer() {
|
||||
.count();
|
||||
|
||||
int screen_capturer_init_ret = screen_capturer_->Init(
|
||||
60, [this](unsigned char* data, int size, int width, int height) -> void {
|
||||
60,
|
||||
[this](unsigned char* data, int size, int width, int height,
|
||||
int display_id) -> void {
|
||||
auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
@@ -206,7 +208,9 @@ int Render::StartScreenCapturer() {
|
||||
frame.width = width;
|
||||
frame.height = height;
|
||||
frame.captured_timestamp = GetSystemTimeMicros(peer_);
|
||||
SendVideoFrame(peer_, &frame);
|
||||
SendVideoFrame(peer_, &frame,
|
||||
display_id == 0 ? video_primary_label_.c_str()
|
||||
: video_secondary_label_.c_str());
|
||||
last_frame_time_ = now_time;
|
||||
}
|
||||
});
|
||||
@@ -239,7 +243,7 @@ int Render::StartSpeakerCapturer() {
|
||||
speaker_capturer_ = (SpeakerCapturer*)speaker_capturer_factory_->Create();
|
||||
int speaker_capturer_init_ret = speaker_capturer_->Init(
|
||||
[this](unsigned char* data, size_t size) -> void {
|
||||
SendAudioFrame(peer_, (const char*)data, size);
|
||||
SendAudioFrame(peer_, (const char*)data, size, audio_label_.c_str());
|
||||
});
|
||||
|
||||
if (0 != speaker_capturer_init_ret) {
|
||||
@@ -359,10 +363,10 @@ int Render::CreateConnectionPeer() {
|
||||
LOG_INFO("Create peer [{}] instance failed", client_id_);
|
||||
}
|
||||
|
||||
AddVideoStream(peer_, "primrey");
|
||||
AddVideoStream(peer_, "second");
|
||||
AddAudioStream(peer_, "audio");
|
||||
AddDataStream(peer_, "data");
|
||||
AddVideoStream(peer_, video_primary_label_.c_str());
|
||||
AddVideoStream(peer_, video_secondary_label_.c_str());
|
||||
AddAudioStream(peer_, audio_label_.c_str());
|
||||
AddDataStream(peer_, data_label_.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -844,7 +848,7 @@ void Render::MainLoop() {
|
||||
memcpy(&remote_action.i.host_name, host_name.data(), host_name.size());
|
||||
remote_action.i.host_name_size = host_name.size();
|
||||
int ret = SendDataFrame(peer_, (const char*)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), data_label_.c_str());
|
||||
if (0 == ret) {
|
||||
host_info_sent_ = true;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class Render {
|
||||
struct SubStreamWindowProperties {
|
||||
Params params_;
|
||||
PeerPtr *peer_ = nullptr;
|
||||
std::string audio_label_ = "control_audio";
|
||||
std::string data_label_ = "control_data";
|
||||
std::string local_id_ = "";
|
||||
std::string remote_id_ = "";
|
||||
bool exit_ = false;
|
||||
@@ -373,6 +375,10 @@ class Render {
|
||||
bool signal_connected_ = false;
|
||||
PeerPtr *peer_ = nullptr;
|
||||
PeerPtr *peer_reserved_ = nullptr;
|
||||
std::string video_primary_label_ = "primary_display";
|
||||
std::string video_secondary_label_ = "secondary_display";
|
||||
std::string audio_label_ = "audio";
|
||||
std::string data_label_ = "data";
|
||||
Params params_;
|
||||
SDL_AudioDeviceID input_dev_;
|
||||
SDL_AudioDeviceID output_dev_;
|
||||
|
||||
@@ -29,7 +29,7 @@ int Render::SendKeyCommand(int key_code, bool is_down) {
|
||||
auto props = client_properties_[controlled_remote_id_];
|
||||
if (props->connection_status_ == ConnectionStatus::Connected) {
|
||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), props->data_label_.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
||||
remote_action.m.flag = MouseFlag::move;
|
||||
}
|
||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), props->data_label_.c_str());
|
||||
} else if (SDL_MOUSEWHEEL == event.type &&
|
||||
last_mouse_event.button.x >= props->stream_render_rect_.x &&
|
||||
last_mouse_event.button.x <= props->stream_render_rect_.x +
|
||||
@@ -128,7 +128,7 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
||||
render_height;
|
||||
|
||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||
sizeof(remote_action));
|
||||
sizeof(remote_action), props->data_label_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,8 @@ void Render::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
|
||||
for (auto it : render->client_properties_) {
|
||||
auto props = it.second;
|
||||
if (props->connection_status_ == ConnectionStatus::Connected) {
|
||||
SendAudioFrame(props->peer_, (const char *)stream, len);
|
||||
SendAudioFrame(props->peer_, (const char *)stream, len,
|
||||
render->audio_label_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
thirdparty/projectx
vendored
2
thirdparty/projectx
vendored
Submodule thirdparty/projectx updated: 6e2ca7dc96...364abfd8da
Reference in New Issue
Block a user