mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] update rtc module
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user