diff --git a/src/screen_capturer/screen_capturer.h b/src/screen_capturer/screen_capturer.h index 922ca40..7ed08ac 100644 --- a/src/screen_capturer/screen_capturer.h +++ b/src/screen_capturer/screen_capturer.h @@ -11,7 +11,8 @@ class ScreenCapturer { public: - typedef std::function cb_desktop_data; + typedef std::function + cb_desktop_data; class DisplayInfo { public: diff --git a/src/screen_capturer/windows/screen_capturer_wgc.cpp b/src/screen_capturer/windows/screen_capturer_wgc.cpp index 6c8e57b..fb652af 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.cpp +++ b/src/screen_capturer/windows/screen_capturer_wgc.cpp @@ -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(), false, false, false}); + {std::make_unique(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); } } diff --git a/src/screen_capturer/windows/screen_capturer_wgc.h b/src/screen_capturer/windows/screen_capturer_wgc.h index c434679..64263a8 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.h +++ b/src/screen_capturer/windows/screen_capturer_wgc.h @@ -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(); diff --git a/src/screen_capturer/windows/wgc_session.h b/src/screen_capturer/windows/wgc_session.h index 261c2b1..404373a 100644 --- a/src/screen_capturer/windows/wgc_session.h +++ b/src/screen_capturer/windows/wgc_session.h @@ -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: diff --git a/src/screen_capturer/windows/wgc_session_impl.cpp b/src/screen_capturer/windows/wgc_session_impl.cpp index 3a5c9ee..c6f778f 100644 --- a/src/screen_capturer/windows/wgc_session_impl.cpp +++ b/src/screen_capturer/windows/wgc_session_impl.cpp @@ -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(frame_size.Width), - static_cast(frame_size.Height), map_result.RowPitch, - const_cast( - (unsigned char *)map_result.pData)}); + observer_->OnFrame( + wgc_session_frame{static_cast(frame_size.Width), + static_cast(frame_size.Height), + map_result.RowPitch, + const_cast( + (unsigned char *)map_result.pData)}, + id_); } d3d11_device_context_->Unmap(d3d11_texture_mapped_.get(), 0); diff --git a/src/screen_capturer/windows/wgc_session_impl.h b/src/screen_capturer/windows/wgc_session_impl.h index f3c622c..99a0954 100644 --- a/src/screen_capturer/windows/wgc_session_impl.h +++ b/src/screen_capturer/windows/wgc_session_impl.h @@ -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; diff --git a/src/single_window/control_bar.cpp b/src/single_window/control_bar.cpp index d9ffe77..a831a42 100644 --- a/src/single_window/control_bar.cpp +++ b/src/single_window/control_bar.cpp @@ -71,7 +71,7 @@ int Render::ControlBar(std::shared_ptr& 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& 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_) { diff --git a/src/single_window/remote_peer_window.cpp b/src/single_window/remote_peer_window.cpp index 1fb539f..3932062 100644 --- a/src/single_window/remote_peer_window.cpp +++ b/src/single_window/remote_peer_window.cpp @@ -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_); diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index ec56d13..59ea0f6 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -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::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; } diff --git a/src/single_window/render.h b/src/single_window/render.h index 6387d2d..78a2653 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -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_; diff --git a/src/single_window/render_callback_func.cpp b/src/single_window/render_callback_func.cpp index c54b9a1..2f1845a 100644 --- a/src/single_window/render_callback_func.cpp +++ b/src/single_window/render_callback_func.cpp @@ -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()); } } diff --git a/thirdparty/projectx b/thirdparty/projectx index 6e2ca7d..364abfd 160000 --- a/thirdparty/projectx +++ b/thirdparty/projectx @@ -1 +1 @@ -Subproject commit 6e2ca7dc969c48ff6d6efee634846d94d504a049 +Subproject commit 364abfd8da2ba35f0b4d6d901ff9d3508ff08f29